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