blob: 8ad7c75c1eea4c5661c56b62f5650038eebcc071 [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
Scott Bakerdbd960e2020-02-28 08:57:51 -080017//Package core provides the utility for olt devices, flows and statistics
18package core
Girish Gowdru0c588b22019-04-23 23:24:56 -040019
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"
Scott Bakerdbd960e2020-02-28 08:57:51 -080028 "github.com/opencord/voltha-openolt-adapter/internal/pkg/config"
Thomas Lee S94109f12020-03-03 16:39:29 +053029 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
Esin Karamanccb714b2019-11-29 15:02:06 +000030 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 Gowdru0c588b22019-04-23 23:24:56 -040033)
34
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070035//OpenOLT structure holds the OLT information
Girish Gowdru0c588b22019-04-23 23:24:56 -040036type OpenOLT struct {
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053037 deviceHandlers map[string]*DeviceHandler
38 coreProxy adapterif.CoreProxy
39 adapterProxy adapterif.AdapterProxy
40 eventProxy adapterif.EventProxy
npujarec5762e2020-01-01 14:08:48 +053041 kafkaICProxy kafka.InterContainerProxy
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053042 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 Gowdru0c588b22019-04-23 23:24:56 -040052}
53
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070054//NewOpenOLT returns a new instance of OpenOLT
npujarec5762e2020-01-01 14:08:48 +053055func NewOpenOLT(ctx context.Context, kafkaICProxy kafka.InterContainerProxy,
kdarapu381c6902019-07-31 18:23:16 +053056 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053057 eventProxy adapterif.EventProxy, cfg *config.AdapterFlags) *OpenOLT {
Girish Gowdru0c588b22019-04-23 23:24:56 -040058 var openOLT OpenOLT
59 openOLT.exitChannel = make(chan int, 1)
60 openOLT.deviceHandlers = make(map[string]*DeviceHandler)
61 openOLT.kafkaICProxy = kafkaICProxy
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053062 openOLT.config = cfg
63 openOLT.numOnus = cfg.OnuNumber
Girish Gowdru0c588b22019-04-23 23:24:56 -040064 openOLT.coreProxy = coreProxy
65 openOLT.adapterProxy = adapterProxy
Devmalya Paulfb990a52019-07-09 10:01:49 -040066 openOLT.eventProxy = eventProxy
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053067 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 Gowdru0c588b22019-04-23 23:24:56 -040073 openOLT.lockDeviceHandlersMap = sync.RWMutex{}
74 return &openOLT
75}
76
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070077//Start starts (logs) the device manager
Girish Gowdru0c588b22019-04-23 23:24:56 -040078func (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 Gowdru6a80bbd2019-07-02 07:36:09 -070084//Stop terminates the session
Girish Gowdru0c588b22019-04-23 23:24:56 -040085func (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
92func sendResponse(ctx context.Context, ch chan interface{}, result interface{}) {
93 if ctx.Err() == nil {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070094 // Returned response only of the ctx has not been canceled/timeout/etc
Girish Gowdru0c588b22019-04-23 23:24:56 -040095 // 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
104func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) {
105 oo.lockDeviceHandlersMap.Lock()
106 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700107 if _, exist := oo.deviceHandlers[agent.deviceID]; !exist {
108 oo.deviceHandlers[agent.deviceID] = agent
Girish Gowdru0c588b22019-04-23 23:24:56 -0400109 }
110}
111
112func (oo *OpenOLT) deleteDeviceHandlerToMap(agent *DeviceHandler) {
113 oo.lockDeviceHandlersMap.Lock()
114 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700115 delete(oo.deviceHandlers, agent.deviceID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400116}
117
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700118func (oo *OpenOLT) getDeviceHandler(deviceID string) *DeviceHandler {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400119 oo.lockDeviceHandlersMap.Lock()
120 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700121 if agent, ok := oo.deviceHandlers[deviceID]; ok {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400122 return agent
123 }
124 return nil
125}
126
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700127//createDeviceTopic returns
Girish Gowdru0c588b22019-04-23 23:24:56 -0400128func (oo *OpenOLT) createDeviceTopic(device *voltha.Device) error {
129 log.Infow("create-device-topic", log.Fields{"deviceId": device.Id})
npujarec5762e2020-01-01 14:08:48 +0530130 defaultTopic := oo.kafkaICProxy.GetDefaultTopic()
131 deviceTopic := kafka.Topic{Name: defaultTopic.Name + "_" + device.Id}
Girish Gowdru0c588b22019-04-23 23:24:56 -0400132 // 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 Gowdru6a80bbd2019-07-02 07:36:09 -0700140// Adopt_device creates a new device handler if not present already and then adopts the device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400141func (oo *OpenOLT) Adopt_device(device *voltha.Device) error {
npujarec5762e2020-01-01 14:08:48 +0530142 ctx := context.Background()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400143 if device == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530144 return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400145 }
146 log.Infow("adopt-device", log.Fields{"deviceId": device.Id})
147 var handler *DeviceHandler
148 if handler = oo.getDeviceHandler(device.Id); handler == nil {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400149 handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400150 oo.addDeviceHandlerToMap(handler)
npujarec5762e2020-01-01 14:08:48 +0530151 go handler.AdoptDevice(ctx, device)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400152 // Launch the creation of the device topic
153 // go oo.createDeviceTopic(device)
154 }
155 return nil
156}
157
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700158//Get_ofp_device_info returns OFP information for the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400159func (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 S94109f12020-03-03 16:39:29 +0530164 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400165}
166
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700167//Get_ofp_port_info returns OFP port information for the given device
168func (oo *OpenOLT) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400169 log.Infow("Get_ofp_port_info", log.Fields{"deviceId": device.Id})
170 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700171 return handler.GetOfpPortInfo(device, portNo)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400172 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530173 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400174}
175
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700176//Process_inter_adapter_message sends messages to a target device (between adapters)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400177func (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 Gowdru6a80bbd2019-07-02 07:36:09 -0700185 return handler.ProcessInterAdapterMessage(msg)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400186 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530187 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": targetDevice}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400188}
189
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700190//Adapter_descriptor not implemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400191func (oo *OpenOLT) Adapter_descriptor() error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530192 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400193}
194
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700195//Device_types unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400196func (oo *OpenOLT) Device_types() (*voltha.DeviceTypes, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530197 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400198}
199
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700200//Health returns unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400201func (oo *OpenOLT) Health() (*voltha.HealthStatus, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530202 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400203}
204
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700205//Reconcile_device unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400206func (oo *OpenOLT) Reconcile_device(device *voltha.Device) error {
npujarec5762e2020-01-01 14:08:48 +0530207 ctx := context.Background()
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530208 if device == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530209 return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log()
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530210 }
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)
npujarec5762e2020-01-01 14:08:48 +0530217 handler.transitionMap.Handle(ctx, DeviceInit)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530218 }
219 return nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400220}
221
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700222//Abandon_device unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400223func (oo *OpenOLT) Abandon_device(device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530224 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400225}
226
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700227//Disable_device disables the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400228func (oo *OpenOLT) Disable_device(device *voltha.Device) error {
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400229 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 S94109f12020-03-03 16:39:29 +0530233 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400234}
235
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700236//Reenable_device enables the olt device after disable
Girish Gowdru0c588b22019-04-23 23:24:56 -0400237func (oo *OpenOLT) Reenable_device(device *voltha.Device) error {
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400238 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 S94109f12020-03-03 16:39:29 +0530242 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400243}
244
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700245//Reboot_device reboots the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400246func (oo *OpenOLT) Reboot_device(device *voltha.Device) error {
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400247 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 S94109f12020-03-03 16:39:29 +0530251 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400252}
253
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700254//Self_test_device unimplented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400255func (oo *OpenOLT) Self_test_device(device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530256 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400257}
258
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700259//Delete_device unimplemented
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400260func (oo *OpenOLT) Delete_device(device *voltha.Device) error {
Devmalya Paul495b94a2019-08-27 19:42:00 -0400261 log.Infow("delete-device", log.Fields{"deviceId": device.Id})
npujarec5762e2020-01-01 14:08:48 +0530262 ctx := context.Background()
Devmalya Paul495b94a2019-08-27 19:42:00 -0400263 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530264 if err := handler.DeleteDevice(ctx, device); err != nil {
Devmalya Paul495b94a2019-08-27 19:42:00 -0400265 log.Errorw("failed-to-handle-delete-device", log.Fields{"device-id": device.Id})
266 }
267 oo.deleteDeviceHandlerToMap(handler)
268 return nil
269 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530270 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400271}
272
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700273//Get_device_details unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400274func (oo *OpenOLT) Get_device_details(device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530275 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400276}
277
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700278//Update_flows_bulk returns
Manikkaraj kb1d51442019-07-23 10:41:02 -0400279func (oo *OpenOLT) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530280 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400281}
282
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700283//Update_flows_incrementally updates (add/remove) the flows on a given device
Manikkaraj kb1d51442019-07-23 10:41:02 -0400284func (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})
npujarec5762e2020-01-01 14:08:48 +0530286 ctx := context.Background()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400287 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530288 return handler.UpdateFlowsIncrementally(ctx, device, flows, groups, flowMetadata)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400289 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530290 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400291}
292
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700293//Update_pm_config returns PmConfigs nil or error
294func (oo *OpenOLT) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530295 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400296}
297
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700298//Receive_packet_out sends packet out to the device
299func (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})
npujarec5762e2020-01-01 14:08:48 +0530301 ctx := context.Background()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700302 if handler := oo.getDeviceHandler(deviceID); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530303 return handler.PacketOut(ctx, egressPortNo, packet)
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400304 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530305 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400306}
307
Devmalya Pauldd23a992019-11-14 07:06:31 +0000308//Suppress_event unimplemented
309func (oo *OpenOLT) Suppress_event(filter *voltha.EventFilter) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530310 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400311}
312
Devmalya Pauldd23a992019-11-14 07:06:31 +0000313//Unsuppress_event unimplemented
314func (oo *OpenOLT) Unsuppress_event(filter *voltha.EventFilter) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530315 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400316}
317
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700318//Download_image unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400319func (oo *OpenOLT) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530320 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400321}
322
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700323//Get_image_download_status unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400324func (oo *OpenOLT) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530325 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400326}
327
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700328//Cancel_image_download unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400329func (oo *OpenOLT) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530330 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400331}
332
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700333//Activate_image_update unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400334func (oo *OpenOLT) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530335 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400336}
337
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700338//Revert_image_update unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400339func (oo *OpenOLT) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530340 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400341}
kesavand39e0aa32020-01-28 20:58:50 -0500342
343// Enable_port to Enable PON/NNI interface
344func (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
350func (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
356func (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 S94109f12020-03-03 16:39:29 +0530359 return olterrors.NewErrInvalidValue(log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800360 "reason": "port cannot be nil",
361 "device-id": deviceID,
362 "port": nil}, nil).Log()
kesavand39e0aa32020-01-28 20:58:50 -0500363 }
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 S1a55b882020-02-04 17:35:35 -0500380
381//Child_device_lost deletes the ONU and its references from PONResources
382func (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 S94109f12020-03-03 16:39:29 +0530388 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil).Log()
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500389}