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 { |
| 79 | log.Info("starting-device-manager") |
| 80 | log.Info("device-manager-started") |
| 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 { |
| 86 | log.Info("stopping-device-manager") |
| 87 | oo.exitChannel <- 1 |
| 88 | log.Info("device-manager-stopped") |
| 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 |
| 97 | log.Debugw("sendResponse", log.Fields{"result": result}) |
| 98 | } else { |
| 99 | // Should the transaction be reverted back? |
| 100 | log.Debugw("sendResponse-context-error", log.Fields{"context-error": ctx.Err()}) |
| 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 { |
| 129 | log.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 { |
| 134 | log.Infow("create-device-topic-failed", log.Fields{"deviceId": device.Id, "error": err}) |
| 135 | return err |
| 136 | } |
| 137 | return nil |
| 138 | } |
| 139 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 140 | // 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] | 141 | func (oo *OpenOLT) Adopt_device(device *voltha.Device) error { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 142 | ctx := context.Background() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 143 | if device == nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 144 | return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 145 | } |
| 146 | log.Infow("adopt-device", log.Fields{"deviceId": device.Id}) |
| 147 | var handler *DeviceHandler |
| 148 | if handler = oo.getDeviceHandler(device.Id); handler == nil { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 149 | handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 150 | oo.addDeviceHandlerToMap(handler) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 151 | go handler.AdoptDevice(ctx, device) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 152 | // Launch the creation of the device topic |
| 153 | // go oo.createDeviceTopic(device) |
| 154 | } |
| 155 | return nil |
| 156 | } |
| 157 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 158 | //Get_ofp_device_info returns OFP information for the given device |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 159 | func (oo *OpenOLT) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) { |
| 160 | log.Infow("Get_ofp_device_info", log.Fields{"deviceId": device.Id}) |
| 161 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 162 | return handler.GetOfpDeviceInfo(device) |
| 163 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 164 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 165 | } |
| 166 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 167 | //Get_ofp_port_info returns OFP port information for the given device |
| 168 | func (oo *OpenOLT) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 169 | log.Infow("Get_ofp_port_info", log.Fields{"deviceId": device.Id}) |
| 170 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 171 | return handler.GetOfpPortInfo(device, portNo) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 172 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 173 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 174 | } |
| 175 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 176 | //Process_inter_adapter_message sends messages to a target device (between adapters) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 177 | func (oo *OpenOLT) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error { |
| 178 | log.Infow("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id}) |
| 179 | targetDevice := msg.Header.ProxyDeviceId // Request? |
| 180 | if targetDevice == "" && msg.Header.ToDeviceId != "" { |
| 181 | // Typical response |
| 182 | targetDevice = msg.Header.ToDeviceId |
| 183 | } |
| 184 | if handler := oo.getDeviceHandler(targetDevice); handler != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 185 | return handler.ProcessInterAdapterMessage(msg) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 186 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 187 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": targetDevice}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 188 | } |
| 189 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 190 | //Adapter_descriptor not implemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 191 | func (oo *OpenOLT) Adapter_descriptor() error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 192 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 193 | } |
| 194 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 195 | //Device_types unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 196 | func (oo *OpenOLT) Device_types() (*voltha.DeviceTypes, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 197 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 198 | } |
| 199 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 200 | //Health returns unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 201 | func (oo *OpenOLT) Health() (*voltha.HealthStatus, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 202 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 203 | } |
| 204 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 205 | //Reconcile_device unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 206 | func (oo *OpenOLT) Reconcile_device(device *voltha.Device) error { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 207 | ctx := context.Background() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 208 | if device == nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 209 | return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 210 | } |
| 211 | log.Infow("reconcile-device", log.Fields{"deviceId": device.Id}) |
| 212 | var handler *DeviceHandler |
| 213 | if handler = oo.getDeviceHandler(device.Id); handler == nil { |
| 214 | handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo) |
| 215 | oo.addDeviceHandlerToMap(handler) |
| 216 | handler.transitionMap = NewTransitionMap(handler) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 217 | handler.transitionMap.Handle(ctx, DeviceInit) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 218 | } |
| 219 | return nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 220 | } |
| 221 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 222 | //Abandon_device unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 223 | func (oo *OpenOLT) Abandon_device(device *voltha.Device) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 224 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 225 | } |
| 226 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 227 | //Disable_device disables the given device |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 228 | func (oo *OpenOLT) Disable_device(device *voltha.Device) error { |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 229 | log.Infow("disable-device", log.Fields{"deviceId": device.Id}) |
| 230 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 231 | return handler.DisableDevice(device) |
| 232 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 233 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 234 | } |
| 235 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 236 | //Reenable_device enables the olt device after disable |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 237 | func (oo *OpenOLT) Reenable_device(device *voltha.Device) error { |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 238 | log.Infow("reenable-device", log.Fields{"deviceId": device.Id}) |
| 239 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 240 | return handler.ReenableDevice(device) |
| 241 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 242 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 243 | } |
| 244 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 245 | //Reboot_device reboots the given device |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 246 | func (oo *OpenOLT) Reboot_device(device *voltha.Device) error { |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 247 | log.Infow("reboot-device", log.Fields{"deviceId": device.Id}) |
| 248 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 249 | return handler.RebootDevice(device) |
| 250 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 251 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 252 | } |
| 253 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 254 | //Self_test_device unimplented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 255 | func (oo *OpenOLT) Self_test_device(device *voltha.Device) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 256 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 257 | } |
| 258 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 259 | //Delete_device unimplemented |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 260 | func (oo *OpenOLT) Delete_device(device *voltha.Device) error { |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 261 | log.Infow("delete-device", log.Fields{"deviceId": device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 262 | ctx := context.Background() |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 263 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 264 | if err := handler.DeleteDevice(ctx, device); err != nil { |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 265 | log.Errorw("failed-to-handle-delete-device", log.Fields{"device-id": device.Id}) |
| 266 | } |
| 267 | oo.deleteDeviceHandlerToMap(handler) |
| 268 | return nil |
| 269 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 270 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 273 | //Get_device_details unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 274 | func (oo *OpenOLT) Get_device_details(device *voltha.Device) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 275 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 276 | } |
| 277 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 278 | //Update_flows_bulk returns |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 279 | 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] | 280 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 281 | } |
| 282 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 283 | //Update_flows_incrementally updates (add/remove) the flows on a given device |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 284 | func (oo *OpenOLT) Update_flows_incrementally(device *voltha.Device, flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { |
| 285 | log.Debugw("Update_flows_incrementally", log.Fields{"deviceId": device.Id, "flows": flows, "flowMetadata": flowMetadata}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 286 | ctx := context.Background() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 287 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 288 | return handler.UpdateFlowsIncrementally(ctx, device, flows, groups, flowMetadata) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 289 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 290 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 291 | } |
| 292 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 293 | //Update_pm_config returns PmConfigs nil or error |
| 294 | 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] | 295 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 296 | } |
| 297 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 298 | //Receive_packet_out sends packet out to the device |
| 299 | func (oo *OpenOLT) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error { |
| 300 | log.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] | 301 | ctx := context.Background() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 302 | if handler := oo.getDeviceHandler(deviceID); handler != nil { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 303 | return handler.PacketOut(ctx, egressPortNo, packet) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 304 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 305 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 308 | //Suppress_event unimplemented |
| 309 | func (oo *OpenOLT) Suppress_event(filter *voltha.EventFilter) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 310 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 311 | } |
| 312 | |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 313 | //Unsuppress_event unimplemented |
| 314 | func (oo *OpenOLT) Unsuppress_event(filter *voltha.EventFilter) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 315 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 316 | } |
| 317 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 318 | //Download_image unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 319 | 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] | 320 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 321 | } |
| 322 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 323 | //Get_image_download_status unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 324 | 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] | 325 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 326 | } |
| 327 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 328 | //Cancel_image_download unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 329 | 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] | 330 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 331 | } |
| 332 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 333 | //Activate_image_update unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 334 | 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] | 335 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 336 | } |
| 337 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 338 | //Revert_image_update unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 339 | 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] | 340 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 341 | } |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 342 | |
| 343 | // Enable_port to Enable PON/NNI interface |
| 344 | func (oo *OpenOLT) Enable_port(deviceID string, port *voltha.Port) error { |
| 345 | log.Infow("Enable_port", log.Fields{"deviceId": deviceID, "port": port}) |
| 346 | return oo.enableDisablePort(deviceID, port, true) |
| 347 | } |
| 348 | |
| 349 | // Disable_port to Disable pon/nni interface |
| 350 | func (oo *OpenOLT) Disable_port(deviceID string, port *voltha.Port) error { |
| 351 | log.Infow("Disable_port", log.Fields{"deviceId": deviceID, "port": port}) |
| 352 | return oo.enableDisablePort(deviceID, port, false) |
| 353 | } |
| 354 | |
| 355 | // enableDisablePort to Disable pon or Enable PON interface |
| 356 | func (oo *OpenOLT) enableDisablePort(deviceID string, port *voltha.Port, enablePort bool) error { |
| 357 | log.Infow("enableDisablePort", log.Fields{"deviceId": deviceID, "port": port}) |
| 358 | if port == nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 359 | return olterrors.NewErrInvalidValue(log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 360 | "reason": "port cannot be nil", |
| 361 | "device-id": deviceID, |
| 362 | "port": nil}, nil).Log() |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 363 | } |
| 364 | if handler := oo.getDeviceHandler(deviceID); handler != nil { |
| 365 | log.Debugw("Enable_Disable_Port", log.Fields{"deviceId": deviceID, "port": port}) |
| 366 | if enablePort { |
| 367 | if err := handler.EnablePort(port); err != nil { |
| 368 | log.Errorw("error-occurred-during-enable-port", log.Fields{"deviceID": deviceID, "port": port, "error": err}) |
| 369 | return err |
| 370 | } |
| 371 | } else { |
| 372 | if err := handler.DisablePort(port); err != nil { |
| 373 | log.Errorw("error-occurred-during-disable-port", log.Fields{"Device": deviceID, "port": port}) |
| 374 | return err |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | return nil |
| 379 | } |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 380 | |
| 381 | //Child_device_lost deletes the ONU and its references from PONResources |
| 382 | func (oo *OpenOLT) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error { |
| 383 | log.Infow("Child-device-lost", log.Fields{"parentId": deviceID}) |
| 384 | ctx := context.Background() |
| 385 | if handler := oo.getDeviceHandler(deviceID); handler != nil { |
| 386 | return handler.ChildDeviceLost(ctx, pPortNo, onuID) |
| 387 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 388 | 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] | 389 | } |