blob: 15e8aae6f49982c697202d8b1c65daf081b47e75 [file] [log] [blame]
Girish Gowdru0c588b22019-04-23 23:24:56 -04001/*
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 Gowdru6a80bbd2019-07-02 07:36:09 -070016
17//Package adaptercore provides the utility for olt devices, flows and statistics
Girish Gowdru0c588b22019-04-23 23:24:56 -040018package adaptercore
19
20import (
21 "context"
22 "errors"
23 "fmt"
24 "sync"
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053025 "time"
Girish Gowdru0c588b22019-04-23 23:24:56 -040026
Esin Karamanccb714b2019-11-29 15:02:06 +000027 "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 Laxmeshwarf9942e92020-01-07 15:32:44 +053030 "github.com/opencord/voltha-openolt-adapter/config"
Esin Karamanccb714b2019-11-29 15:02:06 +000031 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 Gowdru0c588b22019-04-23 23:24:56 -040034)
35
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070036//OpenOLT structure holds the OLT information
Girish Gowdru0c588b22019-04-23 23:24:56 -040037type OpenOLT struct {
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053038 deviceHandlers map[string]*DeviceHandler
39 coreProxy adapterif.CoreProxy
40 adapterProxy adapterif.AdapterProxy
41 eventProxy adapterif.EventProxy
npujarec5762e2020-01-01 14:08:48 +053042 kafkaICProxy kafka.InterContainerProxy
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053043 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 Gowdru0c588b22019-04-23 23:24:56 -040053}
54
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070055//NewOpenOLT returns a new instance of OpenOLT
npujarec5762e2020-01-01 14:08:48 +053056func NewOpenOLT(ctx context.Context, kafkaICProxy kafka.InterContainerProxy,
kdarapu381c6902019-07-31 18:23:16 +053057 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053058 eventProxy adapterif.EventProxy, cfg *config.AdapterFlags) *OpenOLT {
Girish Gowdru0c588b22019-04-23 23:24:56 -040059 var openOLT OpenOLT
60 openOLT.exitChannel = make(chan int, 1)
61 openOLT.deviceHandlers = make(map[string]*DeviceHandler)
62 openOLT.kafkaICProxy = kafkaICProxy
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053063 openOLT.config = cfg
64 openOLT.numOnus = cfg.OnuNumber
Girish Gowdru0c588b22019-04-23 23:24:56 -040065 openOLT.coreProxy = coreProxy
66 openOLT.adapterProxy = adapterProxy
Devmalya Paulfb990a52019-07-09 10:01:49 -040067 openOLT.eventProxy = eventProxy
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053068 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 Gowdru0c588b22019-04-23 23:24:56 -040074 openOLT.lockDeviceHandlersMap = sync.RWMutex{}
75 return &openOLT
76}
77
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070078//Start starts (logs) the device manager
Girish Gowdru0c588b22019-04-23 23:24:56 -040079func (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 Gowdru6a80bbd2019-07-02 07:36:09 -070085//Stop terminates the session
Girish Gowdru0c588b22019-04-23 23:24:56 -040086func (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
93func sendResponse(ctx context.Context, ch chan interface{}, result interface{}) {
94 if ctx.Err() == nil {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070095 // Returned response only of the ctx has not been canceled/timeout/etc
Girish Gowdru0c588b22019-04-23 23:24:56 -040096 // 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
105func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) {
106 oo.lockDeviceHandlersMap.Lock()
107 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700108 if _, exist := oo.deviceHandlers[agent.deviceID]; !exist {
109 oo.deviceHandlers[agent.deviceID] = agent
Girish Gowdru0c588b22019-04-23 23:24:56 -0400110 }
111}
112
113func (oo *OpenOLT) deleteDeviceHandlerToMap(agent *DeviceHandler) {
114 oo.lockDeviceHandlersMap.Lock()
115 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700116 delete(oo.deviceHandlers, agent.deviceID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400117}
118
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700119func (oo *OpenOLT) getDeviceHandler(deviceID string) *DeviceHandler {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400120 oo.lockDeviceHandlersMap.Lock()
121 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700122 if agent, ok := oo.deviceHandlers[deviceID]; ok {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400123 return agent
124 }
125 return nil
126}
127
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700128//createDeviceTopic returns
Girish Gowdru0c588b22019-04-23 23:24:56 -0400129func (oo *OpenOLT) createDeviceTopic(device *voltha.Device) error {
130 log.Infow("create-device-topic", log.Fields{"deviceId": device.Id})
npujarec5762e2020-01-01 14:08:48 +0530131 defaultTopic := oo.kafkaICProxy.GetDefaultTopic()
132 deviceTopic := kafka.Topic{Name: defaultTopic.Name + "_" + device.Id}
Girish Gowdru0c588b22019-04-23 23:24:56 -0400133 // 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 Gowdru6a80bbd2019-07-02 07:36:09 -0700141// Adopt_device creates a new device handler if not present already and then adopts the device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400142func (oo *OpenOLT) Adopt_device(device *voltha.Device) error {
npujarec5762e2020-01-01 14:08:48 +0530143 ctx := context.Background()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400144 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 Paulfb990a52019-07-09 10:01:49 -0400151 handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400152 oo.addDeviceHandlerToMap(handler)
npujarec5762e2020-01-01 14:08:48 +0530153 go handler.AdoptDevice(ctx, device)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400154 // Launch the creation of the device topic
155 // go oo.createDeviceTopic(device)
156 }
157 return nil
158}
159
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700160//Get_ofp_device_info returns OFP information for the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400161func (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 Gowdru6a80bbd2019-07-02 07:36:09 -0700170//Get_ofp_port_info returns OFP port information for the given device
171func (oo *OpenOLT) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400172 log.Infow("Get_ofp_port_info", log.Fields{"deviceId": device.Id})
173 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700174 return handler.GetOfpPortInfo(device, portNo)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400175 }
176 log.Errorw("device-handler-not-set", log.Fields{"deviceId": device.Id})
177 return nil, errors.New("device-handler-not-set")
178}
179
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700180//Process_inter_adapter_message sends messages to a target device (between adapters)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400181func (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 Gowdru6a80bbd2019-07-02 07:36:09 -0700189 return handler.ProcessInterAdapterMessage(msg)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400190 }
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700191 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice))
Girish Gowdru0c588b22019-04-23 23:24:56 -0400192}
193
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700194//Adapter_descriptor not implemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400195func (oo *OpenOLT) Adapter_descriptor() error {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700196 return errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400197}
198
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700199//Device_types unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400200func (oo *OpenOLT) Device_types() (*voltha.DeviceTypes, error) {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700201 return nil, errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400202}
203
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700204//Health returns unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400205func (oo *OpenOLT) Health() (*voltha.HealthStatus, error) {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700206 return nil, errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400207}
208
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700209//Reconcile_device unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400210func (oo *OpenOLT) Reconcile_device(device *voltha.Device) error {
npujarec5762e2020-01-01 14:08:48 +0530211 ctx := context.Background()
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530212 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)
npujarec5762e2020-01-01 14:08:48 +0530222 handler.transitionMap.Handle(ctx, DeviceInit)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530223 }
224 return nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400225}
226
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700227//Abandon_device unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400228func (oo *OpenOLT) Abandon_device(device *voltha.Device) error {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700229 return errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400230}
231
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700232//Disable_device disables the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400233func (oo *OpenOLT) Disable_device(device *voltha.Device) error {
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400234 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 Gowdru0c588b22019-04-23 23:24:56 -0400240}
241
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700242//Reenable_device enables the olt device after disable
Girish Gowdru0c588b22019-04-23 23:24:56 -0400243func (oo *OpenOLT) Reenable_device(device *voltha.Device) error {
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400244 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 Gowdru0c588b22019-04-23 23:24:56 -0400250}
251
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700252//Reboot_device reboots the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400253func (oo *OpenOLT) Reboot_device(device *voltha.Device) error {
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400254 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 Gowdru0c588b22019-04-23 23:24:56 -0400261}
262
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700263//Self_test_device unimplented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400264func (oo *OpenOLT) Self_test_device(device *voltha.Device) error {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700265 return errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400266}
267
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700268//Delete_device unimplemented
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400269func (oo *OpenOLT) Delete_device(device *voltha.Device) error {
Devmalya Paul495b94a2019-08-27 19:42:00 -0400270 log.Infow("delete-device", log.Fields{"deviceId": device.Id})
npujarec5762e2020-01-01 14:08:48 +0530271 ctx := context.Background()
Devmalya Paul495b94a2019-08-27 19:42:00 -0400272 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530273 if err := handler.DeleteDevice(ctx, device); err != nil {
Devmalya Paul495b94a2019-08-27 19:42:00 -0400274 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 Gowdru0c588b22019-04-23 23:24:56 -0400281}
282
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700283//Get_device_details unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400284func (oo *OpenOLT) Get_device_details(device *voltha.Device) error {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700285 return errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400286}
287
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700288//Update_flows_bulk returns
Manikkaraj kb1d51442019-07-23 10:41:02 -0400289func (oo *OpenOLT) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700290 return errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400291}
292
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700293//Update_flows_incrementally updates (add/remove) the flows on a given device
Manikkaraj kb1d51442019-07-23 10:41:02 -0400294func (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})
npujarec5762e2020-01-01 14:08:48 +0530296 ctx := context.Background()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400297 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530298 return handler.UpdateFlowsIncrementally(ctx, device, flows, groups, flowMetadata)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400299 }
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 Gowdru6a80bbd2019-07-02 07:36:09 -0700304//Update_pm_config returns PmConfigs nil or error
305func (oo *OpenOLT) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
306 return errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400307}
308
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700309//Receive_packet_out sends packet out to the device
310func (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})
npujarec5762e2020-01-01 14:08:48 +0530312 ctx := context.Background()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700313 if handler := oo.getDeviceHandler(deviceID); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530314 return handler.PacketOut(ctx, egressPortNo, packet)
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400315 }
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700316 log.Errorw("Receive_packet_out failed-device-handler-not-set", log.Fields{"deviceId": deviceID, "egressport": egressPortNo, "packet": packet})
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400317 return errors.New("device-handler-not-set")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400318}
319
Devmalya Pauldd23a992019-11-14 07:06:31 +0000320//Suppress_event unimplemented
321func (oo *OpenOLT) Suppress_event(filter *voltha.EventFilter) error {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700322 return errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400323}
324
Devmalya Pauldd23a992019-11-14 07:06:31 +0000325//Unsuppress_event unimplemented
326func (oo *OpenOLT) Unsuppress_event(filter *voltha.EventFilter) error {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700327 return errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400328}
329
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700330//Download_image unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400331func (oo *OpenOLT) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700332 return nil, errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400333}
334
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700335//Get_image_download_status unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400336func (oo *OpenOLT) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700337 return nil, errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400338}
339
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700340//Cancel_image_download unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400341func (oo *OpenOLT) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700342 return nil, errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400343}
344
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700345//Activate_image_update unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400346func (oo *OpenOLT) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700347 return nil, errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400348}
349
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700350//Revert_image_update unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400351func (oo *OpenOLT) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700352 return nil, errors.New("unImplemented")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400353}
kesavand39e0aa32020-01-28 20:58:50 -0500354
355// Enable_port to Enable PON/NNI interface
356func (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
362func (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
368func (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}