blob: 657f2496824a39e677c2567a25c59c5c919ba6c2 [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"
Girish Gowdru0c588b22019-04-23 23:24:56 -040022 "sync"
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053023 "time"
Girish Gowdru0c588b22019-04-23 23:24:56 -040024
Esin Karamanccb714b2019-11-29 15:02:06 +000025 "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"
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053028 "github.com/opencord/voltha-openolt-adapter/config"
Esin Karamanccb714b2019-11-29 15:02:06 +000029 ic "github.com/opencord/voltha-protos/v3/go/inter_container"
30 "github.com/opencord/voltha-protos/v3/go/openflow_13"
31 "github.com/opencord/voltha-protos/v3/go/voltha"
Girish Gowdru0c588b22019-04-23 23:24:56 -040032)
33
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070034//OpenOLT structure holds the OLT information
Girish Gowdru0c588b22019-04-23 23:24:56 -040035type OpenOLT struct {
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053036 deviceHandlers map[string]*DeviceHandler
37 coreProxy adapterif.CoreProxy
38 adapterProxy adapterif.AdapterProxy
39 eventProxy adapterif.EventProxy
npujarec5762e2020-01-01 14:08:48 +053040 kafkaICProxy kafka.InterContainerProxy
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053041 config *config.AdapterFlags
42 numOnus int
43 KVStoreHost string
44 KVStorePort int
45 KVStoreType string
46 exitChannel chan int
47 HeartbeatCheckInterval time.Duration
48 HeartbeatFailReportInterval time.Duration
49 GrpcTimeoutInterval time.Duration
50 lockDeviceHandlersMap sync.RWMutex
Girish Gowdru0c588b22019-04-23 23:24:56 -040051}
52
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070053//NewOpenOLT returns a new instance of OpenOLT
npujarec5762e2020-01-01 14:08:48 +053054func NewOpenOLT(ctx context.Context, kafkaICProxy kafka.InterContainerProxy,
kdarapu381c6902019-07-31 18:23:16 +053055 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053056 eventProxy adapterif.EventProxy, cfg *config.AdapterFlags) *OpenOLT {
Girish Gowdru0c588b22019-04-23 23:24:56 -040057 var openOLT OpenOLT
58 openOLT.exitChannel = make(chan int, 1)
59 openOLT.deviceHandlers = make(map[string]*DeviceHandler)
60 openOLT.kafkaICProxy = kafkaICProxy
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053061 openOLT.config = cfg
62 openOLT.numOnus = cfg.OnuNumber
Girish Gowdru0c588b22019-04-23 23:24:56 -040063 openOLT.coreProxy = coreProxy
64 openOLT.adapterProxy = adapterProxy
Devmalya Paulfb990a52019-07-09 10:01:49 -040065 openOLT.eventProxy = eventProxy
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053066 openOLT.KVStoreHost = cfg.KVStoreHost
67 openOLT.KVStorePort = cfg.KVStorePort
68 openOLT.KVStoreType = cfg.KVStoreType
69 openOLT.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
70 openOLT.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
71 openOLT.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Girish Gowdru0c588b22019-04-23 23:24:56 -040072 openOLT.lockDeviceHandlersMap = sync.RWMutex{}
73 return &openOLT
74}
75
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070076//Start starts (logs) the device manager
Girish Gowdru0c588b22019-04-23 23:24:56 -040077func (oo *OpenOLT) Start(ctx context.Context) error {
78 log.Info("starting-device-manager")
79 log.Info("device-manager-started")
80 return nil
81}
82
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070083//Stop terminates the session
Girish Gowdru0c588b22019-04-23 23:24:56 -040084func (oo *OpenOLT) Stop(ctx context.Context) error {
85 log.Info("stopping-device-manager")
86 oo.exitChannel <- 1
87 log.Info("device-manager-stopped")
88 return nil
89}
90
91func sendResponse(ctx context.Context, ch chan interface{}, result interface{}) {
92 if ctx.Err() == nil {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070093 // Returned response only of the ctx has not been canceled/timeout/etc
Girish Gowdru0c588b22019-04-23 23:24:56 -040094 // Channel is automatically closed when a context is Done
95 ch <- result
96 log.Debugw("sendResponse", log.Fields{"result": result})
97 } else {
98 // Should the transaction be reverted back?
99 log.Debugw("sendResponse-context-error", log.Fields{"context-error": ctx.Err()})
100 }
101}
102
103func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) {
104 oo.lockDeviceHandlersMap.Lock()
105 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700106 if _, exist := oo.deviceHandlers[agent.deviceID]; !exist {
107 oo.deviceHandlers[agent.deviceID] = agent
Girish Gowdru0c588b22019-04-23 23:24:56 -0400108 }
109}
110
111func (oo *OpenOLT) deleteDeviceHandlerToMap(agent *DeviceHandler) {
112 oo.lockDeviceHandlersMap.Lock()
113 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700114 delete(oo.deviceHandlers, agent.deviceID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400115}
116
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700117func (oo *OpenOLT) getDeviceHandler(deviceID string) *DeviceHandler {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400118 oo.lockDeviceHandlersMap.Lock()
119 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700120 if agent, ok := oo.deviceHandlers[deviceID]; ok {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400121 return agent
122 }
123 return nil
124}
125
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700126//createDeviceTopic returns
Girish Gowdru0c588b22019-04-23 23:24:56 -0400127func (oo *OpenOLT) createDeviceTopic(device *voltha.Device) error {
128 log.Infow("create-device-topic", log.Fields{"deviceId": device.Id})
npujarec5762e2020-01-01 14:08:48 +0530129 defaultTopic := oo.kafkaICProxy.GetDefaultTopic()
130 deviceTopic := kafka.Topic{Name: defaultTopic.Name + "_" + device.Id}
Girish Gowdru0c588b22019-04-23 23:24:56 -0400131 // TODO for the offset
132 if err := oo.kafkaICProxy.SubscribeWithDefaultRequestHandler(deviceTopic, 0); err != nil {
133 log.Infow("create-device-topic-failed", log.Fields{"deviceId": device.Id, "error": err})
134 return err
135 }
136 return nil
137}
138
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700139// Adopt_device creates a new device handler if not present already and then adopts the device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400140func (oo *OpenOLT) Adopt_device(device *voltha.Device) error {
npujarec5762e2020-01-01 14:08:48 +0530141 ctx := context.Background()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400142 if device == nil {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800143 return NewErrInvalidValue(log.Fields{"device": nil}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400144 }
145 log.Infow("adopt-device", log.Fields{"deviceId": device.Id})
146 var handler *DeviceHandler
147 if handler = oo.getDeviceHandler(device.Id); handler == nil {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400148 handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400149 oo.addDeviceHandlerToMap(handler)
npujarec5762e2020-01-01 14:08:48 +0530150 go handler.AdoptDevice(ctx, device)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400151 // Launch the creation of the device topic
152 // go oo.createDeviceTopic(device)
153 }
154 return nil
155}
156
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700157//Get_ofp_device_info returns OFP information for the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400158func (oo *OpenOLT) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) {
159 log.Infow("Get_ofp_device_info", log.Fields{"deviceId": device.Id})
160 if handler := oo.getDeviceHandler(device.Id); handler != nil {
161 return handler.GetOfpDeviceInfo(device)
162 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800163 return nil, NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400164}
165
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700166//Get_ofp_port_info returns OFP port information for the given device
167func (oo *OpenOLT) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400168 log.Infow("Get_ofp_port_info", log.Fields{"deviceId": device.Id})
169 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700170 return handler.GetOfpPortInfo(device, portNo)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400171 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800172 return nil, NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400173}
174
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700175//Process_inter_adapter_message sends messages to a target device (between adapters)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400176func (oo *OpenOLT) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error {
177 log.Infow("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id})
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 Gowdru6a80bbd2019-07-02 07:36:09 -0700184 return handler.ProcessInterAdapterMessage(msg)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400185 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800186 return NewErrNotFound("device-handler", log.Fields{"device-id": targetDevice}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400187}
188
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700189//Adapter_descriptor not implemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400190func (oo *OpenOLT) Adapter_descriptor() error {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800191 return ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400192}
193
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700194//Device_types unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400195func (oo *OpenOLT) Device_types() (*voltha.DeviceTypes, error) {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800196 return nil, ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400197}
198
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700199//Health returns unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400200func (oo *OpenOLT) Health() (*voltha.HealthStatus, error) {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800201 return nil, ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400202}
203
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700204//Reconcile_device unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400205func (oo *OpenOLT) Reconcile_device(device *voltha.Device) error {
npujarec5762e2020-01-01 14:08:48 +0530206 ctx := context.Background()
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530207 if device == nil {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800208 return NewErrInvalidValue(log.Fields{"device": nil}, nil).Log()
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530209 }
210 log.Infow("reconcile-device", log.Fields{"deviceId": device.Id})
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)
npujarec5762e2020-01-01 14:08:48 +0530216 handler.transitionMap.Handle(ctx, DeviceInit)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530217 }
218 return nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400219}
220
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700221//Abandon_device unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400222func (oo *OpenOLT) Abandon_device(device *voltha.Device) error {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800223 return ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400224}
225
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700226//Disable_device disables the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400227func (oo *OpenOLT) Disable_device(device *voltha.Device) error {
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400228 log.Infow("disable-device", log.Fields{"deviceId": device.Id})
229 if handler := oo.getDeviceHandler(device.Id); handler != nil {
230 return handler.DisableDevice(device)
231 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800232 return NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400233}
234
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700235//Reenable_device enables the olt device after disable
Girish Gowdru0c588b22019-04-23 23:24:56 -0400236func (oo *OpenOLT) Reenable_device(device *voltha.Device) error {
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400237 log.Infow("reenable-device", log.Fields{"deviceId": device.Id})
238 if handler := oo.getDeviceHandler(device.Id); handler != nil {
239 return handler.ReenableDevice(device)
240 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800241 return NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400242}
243
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700244//Reboot_device reboots the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400245func (oo *OpenOLT) Reboot_device(device *voltha.Device) error {
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400246 log.Infow("reboot-device", log.Fields{"deviceId": device.Id})
247 if handler := oo.getDeviceHandler(device.Id); handler != nil {
248 return handler.RebootDevice(device)
249 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800250 return NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400251}
252
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700253//Self_test_device unimplented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400254func (oo *OpenOLT) Self_test_device(device *voltha.Device) error {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800255 return ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400256}
257
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700258//Delete_device unimplemented
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400259func (oo *OpenOLT) Delete_device(device *voltha.Device) error {
Devmalya Paul495b94a2019-08-27 19:42:00 -0400260 log.Infow("delete-device", log.Fields{"deviceId": device.Id})
npujarec5762e2020-01-01 14:08:48 +0530261 ctx := context.Background()
Devmalya Paul495b94a2019-08-27 19:42:00 -0400262 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530263 if err := handler.DeleteDevice(ctx, device); err != nil {
Devmalya Paul495b94a2019-08-27 19:42:00 -0400264 log.Errorw("failed-to-handle-delete-device", log.Fields{"device-id": device.Id})
265 }
266 oo.deleteDeviceHandlerToMap(handler)
267 return nil
268 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800269 return NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400270}
271
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700272//Get_device_details unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400273func (oo *OpenOLT) Get_device_details(device *voltha.Device) error {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800274 return ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400275}
276
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700277//Update_flows_bulk returns
Manikkaraj kb1d51442019-07-23 10:41:02 -0400278func (oo *OpenOLT) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800279 return ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400280}
281
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700282//Update_flows_incrementally updates (add/remove) the flows on a given device
Manikkaraj kb1d51442019-07-23 10:41:02 -0400283func (oo *OpenOLT) Update_flows_incrementally(device *voltha.Device, flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error {
284 log.Debugw("Update_flows_incrementally", log.Fields{"deviceId": device.Id, "flows": flows, "flowMetadata": flowMetadata})
npujarec5762e2020-01-01 14:08:48 +0530285 ctx := context.Background()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400286 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530287 return handler.UpdateFlowsIncrementally(ctx, device, flows, groups, flowMetadata)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400288 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800289 return NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400290}
291
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700292//Update_pm_config returns PmConfigs nil or error
293func (oo *OpenOLT) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800294 return ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400295}
296
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700297//Receive_packet_out sends packet out to the device
298func (oo *OpenOLT) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
299 log.Debugw("Receive_packet_out", log.Fields{"deviceId": deviceID, "egress_port_no": egressPortNo, "pkt": packet})
npujarec5762e2020-01-01 14:08:48 +0530300 ctx := context.Background()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700301 if handler := oo.getDeviceHandler(deviceID); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530302 return handler.PacketOut(ctx, egressPortNo, packet)
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400303 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800304 return NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400305}
306
Devmalya Pauldd23a992019-11-14 07:06:31 +0000307//Suppress_event unimplemented
308func (oo *OpenOLT) Suppress_event(filter *voltha.EventFilter) error {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800309 return ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400310}
311
Devmalya Pauldd23a992019-11-14 07:06:31 +0000312//Unsuppress_event unimplemented
313func (oo *OpenOLT) Unsuppress_event(filter *voltha.EventFilter) error {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800314 return ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400315}
316
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700317//Download_image unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400318func (oo *OpenOLT) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800319 return nil, ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400320}
321
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700322//Get_image_download_status unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400323func (oo *OpenOLT) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800324 return nil, ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400325}
326
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700327//Cancel_image_download unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400328func (oo *OpenOLT) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800329 return nil, ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400330}
331
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700332//Activate_image_update unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400333func (oo *OpenOLT) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800334 return nil, ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400335}
336
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700337//Revert_image_update unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400338func (oo *OpenOLT) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800339 return nil, ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400340}
kesavand39e0aa32020-01-28 20:58:50 -0500341
342// Enable_port to Enable PON/NNI interface
343func (oo *OpenOLT) Enable_port(deviceID string, port *voltha.Port) error {
344 log.Infow("Enable_port", log.Fields{"deviceId": deviceID, "port": port})
345 return oo.enableDisablePort(deviceID, port, true)
346}
347
348// Disable_port to Disable pon/nni interface
349func (oo *OpenOLT) Disable_port(deviceID string, port *voltha.Port) error {
350 log.Infow("Disable_port", log.Fields{"deviceId": deviceID, "port": port})
351 return oo.enableDisablePort(deviceID, port, false)
352}
353
354// enableDisablePort to Disable pon or Enable PON interface
355func (oo *OpenOLT) enableDisablePort(deviceID string, port *voltha.Port, enablePort bool) error {
356 log.Infow("enableDisablePort", log.Fields{"deviceId": deviceID, "port": port})
357 if port == nil {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800358 return NewErrInvalidValue(log.Fields{
359 "reason": "port cannot be nil",
360 "device-id": deviceID,
361 "port": nil}, nil).Log()
kesavand39e0aa32020-01-28 20:58:50 -0500362 }
363 if handler := oo.getDeviceHandler(deviceID); handler != nil {
364 log.Debugw("Enable_Disable_Port", log.Fields{"deviceId": deviceID, "port": port})
365 if enablePort {
366 if err := handler.EnablePort(port); err != nil {
367 log.Errorw("error-occurred-during-enable-port", log.Fields{"deviceID": deviceID, "port": port, "error": err})
368 return err
369 }
370 } else {
371 if err := handler.DisablePort(port); err != nil {
372 log.Errorw("error-occurred-during-disable-port", log.Fields{"Device": deviceID, "port": port})
373 return err
374 }
375 }
376 }
377 return nil
378}
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500379
380//Child_device_lost deletes the ONU and its references from PONResources
381func (oo *OpenOLT) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error {
382 log.Infow("Child-device-lost", log.Fields{"parentId": deviceID})
383 ctx := context.Background()
384 if handler := oo.getDeviceHandler(deviceID); handler != nil {
385 return handler.ChildDeviceLost(ctx, pPortNo, onuID)
386 }
387 return NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil).Log()
388}