Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 16 | |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 17 | //Package core provides the utility for olt devices, flows and statistics |
| 18 | package core |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 22 | "sync" |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 23 | "time" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 24 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 25 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif" |
| 26 | "github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 27 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 28 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/config" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 29 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 30 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 31 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 32 | "github.com/opencord/voltha-protos/v3/go/voltha" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 33 | ) |
| 34 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 35 | //OpenOLT structure holds the OLT information |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 36 | type OpenOLT struct { |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 37 | deviceHandlers map[string]*DeviceHandler |
| 38 | coreProxy adapterif.CoreProxy |
| 39 | adapterProxy adapterif.AdapterProxy |
| 40 | eventProxy adapterif.EventProxy |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 41 | kafkaICProxy kafka.InterContainerProxy |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 42 | config *config.AdapterFlags |
| 43 | numOnus int |
| 44 | KVStoreHost string |
| 45 | KVStorePort int |
| 46 | KVStoreType string |
| 47 | exitChannel chan int |
| 48 | HeartbeatCheckInterval time.Duration |
| 49 | HeartbeatFailReportInterval time.Duration |
| 50 | GrpcTimeoutInterval time.Duration |
| 51 | lockDeviceHandlersMap sync.RWMutex |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 52 | } |
| 53 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 54 | //NewOpenOLT returns a new instance of OpenOLT |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 55 | func NewOpenOLT(ctx context.Context, kafkaICProxy kafka.InterContainerProxy, |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 56 | coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy, |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 57 | eventProxy adapterif.EventProxy, cfg *config.AdapterFlags) *OpenOLT { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 58 | var openOLT OpenOLT |
| 59 | openOLT.exitChannel = make(chan int, 1) |
| 60 | openOLT.deviceHandlers = make(map[string]*DeviceHandler) |
| 61 | openOLT.kafkaICProxy = kafkaICProxy |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 62 | openOLT.config = cfg |
| 63 | openOLT.numOnus = cfg.OnuNumber |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 64 | openOLT.coreProxy = coreProxy |
| 65 | openOLT.adapterProxy = adapterProxy |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 66 | openOLT.eventProxy = eventProxy |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 67 | openOLT.KVStoreHost = cfg.KVStoreHost |
| 68 | openOLT.KVStorePort = cfg.KVStorePort |
| 69 | openOLT.KVStoreType = cfg.KVStoreType |
| 70 | openOLT.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval |
| 71 | openOLT.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval |
| 72 | openOLT.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 73 | openOLT.lockDeviceHandlersMap = sync.RWMutex{} |
| 74 | return &openOLT |
| 75 | } |
| 76 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 77 | //Start starts (logs) the device manager |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 78 | func (oo *OpenOLT) Start(ctx context.Context) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 79 | logger.Info("starting-device-manager") |
| 80 | logger.Info("device-manager-started") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 81 | return nil |
| 82 | } |
| 83 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 84 | //Stop terminates the session |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 85 | func (oo *OpenOLT) Stop(ctx context.Context) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 86 | logger.Info("stopping-device-manager") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 87 | oo.exitChannel <- 1 |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 88 | logger.Info("device-manager-stopped") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 89 | return nil |
| 90 | } |
| 91 | |
| 92 | func sendResponse(ctx context.Context, ch chan interface{}, result interface{}) { |
| 93 | if ctx.Err() == nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 94 | // Returned response only of the ctx has not been canceled/timeout/etc |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 95 | // Channel is automatically closed when a context is Done |
| 96 | ch <- result |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 97 | logger.Debugw("sendResponse", log.Fields{"result": result}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 98 | } else { |
| 99 | // Should the transaction be reverted back? |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 100 | logger.Debugw("sendResponse-context-error", log.Fields{"context-error": ctx.Err()}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
| 104 | func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) { |
| 105 | oo.lockDeviceHandlersMap.Lock() |
| 106 | defer oo.lockDeviceHandlersMap.Unlock() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 107 | if _, exist := oo.deviceHandlers[agent.deviceID]; !exist { |
| 108 | oo.deviceHandlers[agent.deviceID] = agent |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | func (oo *OpenOLT) deleteDeviceHandlerToMap(agent *DeviceHandler) { |
| 113 | oo.lockDeviceHandlersMap.Lock() |
| 114 | defer oo.lockDeviceHandlersMap.Unlock() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 115 | delete(oo.deviceHandlers, agent.deviceID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 116 | } |
| 117 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 118 | func (oo *OpenOLT) getDeviceHandler(deviceID string) *DeviceHandler { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 119 | oo.lockDeviceHandlersMap.Lock() |
| 120 | defer oo.lockDeviceHandlersMap.Unlock() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 121 | if agent, ok := oo.deviceHandlers[deviceID]; ok { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 122 | return agent |
| 123 | } |
| 124 | return nil |
| 125 | } |
| 126 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 127 | //createDeviceTopic returns |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 128 | func (oo *OpenOLT) createDeviceTopic(device *voltha.Device) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 129 | logger.Infow("create-device-topic", log.Fields{"deviceId": device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 130 | defaultTopic := oo.kafkaICProxy.GetDefaultTopic() |
| 131 | deviceTopic := kafka.Topic{Name: defaultTopic.Name + "_" + device.Id} |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 132 | // TODO for the offset |
| 133 | if err := oo.kafkaICProxy.SubscribeWithDefaultRequestHandler(deviceTopic, 0); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 134 | return olterrors.NewErrAdapter("subscribe-for-device-topic-failed", log.Fields{"device-topic": deviceTopic}, err) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 135 | } |
| 136 | return nil |
| 137 | } |
| 138 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 139 | // Adopt_device creates a new device handler if not present already and then adopts the device |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 140 | func (oo *OpenOLT) Adopt_device(device *voltha.Device) error { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 141 | ctx := context.Background() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 142 | if device == nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 143 | return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 144 | } |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 145 | logger.Infow("adopt-device", log.Fields{"deviceId": device.Id}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 146 | var handler *DeviceHandler |
| 147 | if handler = oo.getDeviceHandler(device.Id); handler == nil { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 148 | handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 149 | oo.addDeviceHandlerToMap(handler) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 150 | go handler.AdoptDevice(ctx, device) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 151 | // Launch the creation of the device topic |
| 152 | // go oo.createDeviceTopic(device) |
| 153 | } |
| 154 | return nil |
| 155 | } |
| 156 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 157 | //Get_ofp_device_info returns OFP information for the given device |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 158 | func (oo *OpenOLT) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 159 | logger.Infow("Get_ofp_device_info", log.Fields{"deviceId": device.Id}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 160 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 161 | return handler.GetOfpDeviceInfo(device) |
| 162 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 163 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 164 | } |
| 165 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 166 | //Get_ofp_port_info returns OFP port information for the given device |
| 167 | func (oo *OpenOLT) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 168 | logger.Infow("Get_ofp_port_info", log.Fields{"deviceId": device.Id}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 169 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 170 | return handler.GetOfpPortInfo(device, portNo) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 171 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 172 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 173 | } |
| 174 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 175 | //Process_inter_adapter_message sends messages to a target device (between adapters) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 176 | func (oo *OpenOLT) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 177 | logger.Infow("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 178 | targetDevice := msg.Header.ProxyDeviceId // Request? |
| 179 | if targetDevice == "" && msg.Header.ToDeviceId != "" { |
| 180 | // Typical response |
| 181 | targetDevice = msg.Header.ToDeviceId |
| 182 | } |
| 183 | if handler := oo.getDeviceHandler(targetDevice); handler != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 184 | return handler.ProcessInterAdapterMessage(msg) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 185 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 186 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": targetDevice}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 187 | } |
| 188 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 189 | //Adapter_descriptor not implemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 190 | func (oo *OpenOLT) Adapter_descriptor() error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 191 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 192 | } |
| 193 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 194 | //Device_types unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 195 | func (oo *OpenOLT) Device_types() (*voltha.DeviceTypes, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 196 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 197 | } |
| 198 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 199 | //Health returns unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 200 | func (oo *OpenOLT) Health() (*voltha.HealthStatus, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 201 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 202 | } |
| 203 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 204 | //Reconcile_device unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 205 | func (oo *OpenOLT) Reconcile_device(device *voltha.Device) error { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 206 | ctx := context.Background() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 207 | if device == nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 208 | return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 209 | } |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 210 | logger.Infow("reconcile-device", log.Fields{"deviceId": device.Id}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 211 | var handler *DeviceHandler |
| 212 | if handler = oo.getDeviceHandler(device.Id); handler == nil { |
| 213 | handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo) |
| 214 | oo.addDeviceHandlerToMap(handler) |
| 215 | handler.transitionMap = NewTransitionMap(handler) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 216 | handler.transitionMap.Handle(ctx, DeviceInit) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 217 | } |
| 218 | return nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 219 | } |
| 220 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 221 | //Abandon_device unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 222 | func (oo *OpenOLT) Abandon_device(device *voltha.Device) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 223 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 224 | } |
| 225 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 226 | //Disable_device disables the given device |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 227 | func (oo *OpenOLT) Disable_device(device *voltha.Device) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 228 | logger.Infow("disable-device", log.Fields{"deviceId": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 229 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 230 | return handler.DisableDevice(device) |
| 231 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 232 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 233 | } |
| 234 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 235 | //Reenable_device enables the olt device after disable |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 236 | func (oo *OpenOLT) Reenable_device(device *voltha.Device) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 237 | logger.Infow("reenable-device", log.Fields{"deviceId": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 238 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 239 | return handler.ReenableDevice(device) |
| 240 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 241 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 242 | } |
| 243 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 244 | //Reboot_device reboots the given device |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 245 | func (oo *OpenOLT) Reboot_device(device *voltha.Device) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 246 | logger.Infow("reboot-device", log.Fields{"deviceId": device.Id}) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 247 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 248 | return handler.RebootDevice(device) |
| 249 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 250 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 253 | //Self_test_device unimplented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 254 | func (oo *OpenOLT) Self_test_device(device *voltha.Device) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 255 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 256 | } |
| 257 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 258 | //Delete_device unimplemented |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 259 | func (oo *OpenOLT) Delete_device(device *voltha.Device) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 260 | logger.Infow("delete-device", log.Fields{"deviceId": device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 261 | ctx := context.Background() |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 262 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 263 | if err := handler.DeleteDevice(ctx, device); err != nil { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 264 | logger.Errorw("failed-to-handle-delete-device", log.Fields{"device-id": device.Id}) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 265 | } |
| 266 | oo.deleteDeviceHandlerToMap(handler) |
| 267 | return nil |
| 268 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 269 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 270 | } |
| 271 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 272 | //Get_device_details unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 273 | func (oo *OpenOLT) Get_device_details(device *voltha.Device) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 274 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 275 | } |
| 276 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 277 | //Update_flows_bulk returns |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 278 | func (oo *OpenOLT) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 279 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 280 | } |
| 281 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 282 | //Update_flows_incrementally updates (add/remove) the flows on a given device |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 283 | func (oo *OpenOLT) Update_flows_incrementally(device *voltha.Device, flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 284 | logger.Debugw("Update_flows_incrementally", log.Fields{"deviceId": device.Id, "flows": flows, "flowMetadata": flowMetadata}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 285 | ctx := context.Background() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 286 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 287 | return handler.UpdateFlowsIncrementally(ctx, device, flows, groups, flowMetadata) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 288 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 289 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 290 | } |
| 291 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 292 | //Update_pm_config returns PmConfigs nil or error |
| 293 | func (oo *OpenOLT) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 294 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 295 | } |
| 296 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 297 | //Receive_packet_out sends packet out to the device |
| 298 | func (oo *OpenOLT) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 299 | logger.Debugw("Receive_packet_out", log.Fields{"deviceId": deviceID, "egress_port_no": egressPortNo, "pkt": packet}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 300 | ctx := context.Background() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 301 | if handler := oo.getDeviceHandler(deviceID); handler != nil { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 302 | return handler.PacketOut(ctx, egressPortNo, packet) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 303 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 304 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 305 | } |
| 306 | |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 307 | //Suppress_event unimplemented |
| 308 | func (oo *OpenOLT) Suppress_event(filter *voltha.EventFilter) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 309 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 310 | } |
| 311 | |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 312 | //Unsuppress_event unimplemented |
| 313 | func (oo *OpenOLT) Unsuppress_event(filter *voltha.EventFilter) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 314 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 315 | } |
| 316 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 317 | //Download_image unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 318 | func (oo *OpenOLT) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 319 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 320 | } |
| 321 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 322 | //Get_image_download_status unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 323 | func (oo *OpenOLT) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 324 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 325 | } |
| 326 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 327 | //Cancel_image_download unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 328 | func (oo *OpenOLT) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 329 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 330 | } |
| 331 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 332 | //Activate_image_update unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 333 | func (oo *OpenOLT) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 334 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 335 | } |
| 336 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 337 | //Revert_image_update unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 338 | func (oo *OpenOLT) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 339 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 340 | } |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 341 | |
| 342 | // Enable_port to Enable PON/NNI interface |
| 343 | func (oo *OpenOLT) Enable_port(deviceID string, port *voltha.Port) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 344 | logger.Infow("Enable_port", log.Fields{"deviceId": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 345 | return oo.enableDisablePort(deviceID, port, true) |
| 346 | } |
| 347 | |
| 348 | // Disable_port to Disable pon/nni interface |
| 349 | func (oo *OpenOLT) Disable_port(deviceID string, port *voltha.Port) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 350 | logger.Infow("Disable_port", log.Fields{"deviceId": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 351 | return oo.enableDisablePort(deviceID, port, false) |
| 352 | } |
| 353 | |
| 354 | // enableDisablePort to Disable pon or Enable PON interface |
| 355 | func (oo *OpenOLT) enableDisablePort(deviceID string, port *voltha.Port, enablePort bool) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 356 | logger.Infow("enableDisablePort", log.Fields{"deviceId": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 357 | if port == nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 358 | return olterrors.NewErrInvalidValue(log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 359 | "reason": "port cannot be nil", |
| 360 | "device-id": deviceID, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 361 | "port": nil}, nil) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 362 | } |
| 363 | if handler := oo.getDeviceHandler(deviceID); handler != nil { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 364 | logger.Debugw("Enable_Disable_Port", log.Fields{"deviceId": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 365 | if enablePort { |
| 366 | if err := handler.EnablePort(port); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 367 | return olterrors.NewErrAdapter("error-occurred-during-enable-port", log.Fields{"deviceID": deviceID, "port": port}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 368 | } |
| 369 | } else { |
| 370 | if err := handler.DisablePort(port); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 371 | return olterrors.NewErrAdapter("error-occurred-during-disable-port", log.Fields{"deviceID": deviceID, "port": port}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | } |
| 375 | return nil |
| 376 | } |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 377 | |
| 378 | //Child_device_lost deletes the ONU and its references from PONResources |
| 379 | func (oo *OpenOLT) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 380 | logger.Infow("Child-device-lost", log.Fields{"parentId": deviceID}) |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 381 | ctx := context.Background() |
| 382 | if handler := oo.getDeviceHandler(deviceID); handler != nil { |
| 383 | return handler.ChildDeviceLost(ctx, pPortNo, onuID) |
| 384 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 385 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil).Log() |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 386 | } |