blob: 702a1a26f70a5f0dc0f3b3e0846d7ba6ff9c1eca [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
Neha Sharma3f221ae2020-04-29 19:02:12 +000044 KVStoreAddress string
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053045 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
Neha Sharma3f221ae2020-04-29 19:02:12 +000066 openOLT.KVStoreAddress = cfg.KVStoreAddress
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053067 openOLT.KVStoreType = cfg.KVStoreType
68 openOLT.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
69 openOLT.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
70 openOLT.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Girish Gowdru0c588b22019-04-23 23:24:56 -040071 openOLT.lockDeviceHandlersMap = sync.RWMutex{}
72 return &openOLT
73}
74
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070075//Start starts (logs) the device manager
Girish Gowdru0c588b22019-04-23 23:24:56 -040076func (oo *OpenOLT) Start(ctx context.Context) error {
Neha Sharma96b7bf22020-06-15 10:37:32 +000077 logger.Info(ctx, "starting-device-manager")
78 logger.Info(ctx, "device-manager-started")
Girish Gowdru0c588b22019-04-23 23:24:56 -040079 return nil
80}
81
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070082//Stop terminates the session
Girish Gowdru0c588b22019-04-23 23:24:56 -040083func (oo *OpenOLT) Stop(ctx context.Context) error {
Neha Sharma96b7bf22020-06-15 10:37:32 +000084 logger.Info(ctx, "stopping-device-manager")
Girish Gowdru0c588b22019-04-23 23:24:56 -040085 oo.exitChannel <- 1
Neha Sharma96b7bf22020-06-15 10:37:32 +000086 logger.Info(ctx, "device-manager-stopped")
Girish Gowdru0c588b22019-04-23 23:24:56 -040087 return nil
88}
89
Girish Gowdru0c588b22019-04-23 23:24:56 -040090func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) {
91 oo.lockDeviceHandlersMap.Lock()
92 defer oo.lockDeviceHandlersMap.Unlock()
Thomas Lee S985938d2020-05-04 11:40:41 +053093 if _, exist := oo.deviceHandlers[agent.device.Id]; !exist {
94 oo.deviceHandlers[agent.device.Id] = agent
Girish Gowdru0c588b22019-04-23 23:24:56 -040095 }
96}
97
98func (oo *OpenOLT) deleteDeviceHandlerToMap(agent *DeviceHandler) {
99 oo.lockDeviceHandlersMap.Lock()
100 defer oo.lockDeviceHandlersMap.Unlock()
Thomas Lee S985938d2020-05-04 11:40:41 +0530101 delete(oo.deviceHandlers, agent.device.Id)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400102}
103
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700104func (oo *OpenOLT) getDeviceHandler(deviceID string) *DeviceHandler {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400105 oo.lockDeviceHandlersMap.Lock()
106 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700107 if agent, ok := oo.deviceHandlers[deviceID]; ok {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400108 return agent
109 }
110 return nil
111}
112
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700113// Adopt_device creates a new device handler if not present already and then adopts the device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000114func (oo *OpenOLT) Adopt_device(ctx context.Context, device *voltha.Device) error {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400115 if device == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530116 return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400117 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000118 logger.Infow(ctx, "adopt-device", log.Fields{"deviceId": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400119 var handler *DeviceHandler
120 if handler = oo.getDeviceHandler(device.Id); handler == nil {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400121 handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400122 oo.addDeviceHandlerToMap(handler)
npujarec5762e2020-01-01 14:08:48 +0530123 go handler.AdoptDevice(ctx, device)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400124 // Launch the creation of the device topic
125 // go oo.createDeviceTopic(device)
126 }
127 return nil
128}
129
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700130//Get_ofp_device_info returns OFP information for the given device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000131func (oo *OpenOLT) Get_ofp_device_info(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) {
132 logger.Infow(ctx, "Get_ofp_device_info", log.Fields{"deviceId": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400133 if handler := oo.getDeviceHandler(device.Id); handler != nil {
134 return handler.GetOfpDeviceInfo(device)
135 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000136 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400137}
138
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700139//Process_inter_adapter_message sends messages to a target device (between adapters)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000140func (oo *OpenOLT) Process_inter_adapter_message(ctx context.Context, msg *ic.InterAdapterMessage) error {
141 logger.Debugw(ctx, "Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400142 targetDevice := msg.Header.ProxyDeviceId // Request?
143 if targetDevice == "" && msg.Header.ToDeviceId != "" {
144 // Typical response
145 targetDevice = msg.Header.ToDeviceId
146 }
147 if handler := oo.getDeviceHandler(targetDevice); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000148 return handler.ProcessInterAdapterMessage(ctx, msg)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400149 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000150 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": targetDevice}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400151}
152
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700153//Adapter_descriptor not implemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000154func (oo *OpenOLT) Adapter_descriptor(ctx context.Context) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530155 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400156}
157
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700158//Device_types unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000159func (oo *OpenOLT) Device_types(ctx context.Context) (*voltha.DeviceTypes, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530160 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400161}
162
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700163//Health returns unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000164func (oo *OpenOLT) Health(ctx context.Context) (*voltha.HealthStatus, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530165 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400166}
167
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700168//Reconcile_device unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000169func (oo *OpenOLT) Reconcile_device(ctx context.Context, device *voltha.Device) error {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530170 if device == nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000171 return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530172 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000173 logger.Infow(ctx, "reconcile-device", log.Fields{"deviceId": device.Id})
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530174 var handler *DeviceHandler
175 if handler = oo.getDeviceHandler(device.Id); handler == nil {
176 handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
177 oo.addDeviceHandlerToMap(handler)
178 handler.transitionMap = NewTransitionMap(handler)
npujarec5762e2020-01-01 14:08:48 +0530179 handler.transitionMap.Handle(ctx, DeviceInit)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530180 }
181 return nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400182}
183
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700184//Abandon_device unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000185func (oo *OpenOLT) Abandon_device(ctx context.Context, device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530186 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400187}
188
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700189//Disable_device disables the given device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000190func (oo *OpenOLT) Disable_device(ctx context.Context, device *voltha.Device) error {
191 logger.Infow(ctx, "disable-device", log.Fields{"deviceId": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400192 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000193 return handler.DisableDevice(ctx, device)
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400194 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000195 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400196}
197
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700198//Reenable_device enables the olt device after disable
Neha Sharma96b7bf22020-06-15 10:37:32 +0000199func (oo *OpenOLT) Reenable_device(ctx context.Context, device *voltha.Device) error {
200 logger.Infow(ctx, "reenable-device", log.Fields{"deviceId": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400201 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000202 return handler.ReenableDevice(ctx, device)
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400203 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000204 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400205}
206
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700207//Reboot_device reboots the given device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000208func (oo *OpenOLT) Reboot_device(ctx context.Context, device *voltha.Device) error {
209 logger.Infow(ctx, "reboot-device", log.Fields{"deviceId": device.Id})
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400210 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000211 return handler.RebootDevice(ctx, device)
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400212 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000213 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400214}
215
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700216//Self_test_device unimplented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000217func (oo *OpenOLT) Self_test_device(ctx context.Context, device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530218 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400219}
220
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700221//Delete_device unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000222func (oo *OpenOLT) Delete_device(ctx context.Context, device *voltha.Device) error {
223 logger.Infow(ctx, "delete-device", log.Fields{"deviceId": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400224 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530225 if err := handler.DeleteDevice(ctx, device); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000226 logger.Errorw(ctx, "failed-to-handle-delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400227 }
228 oo.deleteDeviceHandlerToMap(handler)
229 return nil
230 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000231 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400232}
233
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700234//Get_device_details unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000235func (oo *OpenOLT) Get_device_details(ctx context.Context, device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530236 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400237}
238
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700239//Update_flows_bulk returns
Neha Sharma96b7bf22020-06-15 10:37:32 +0000240func (oo *OpenOLT) Update_flows_bulk(ctx context.Context, device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530241 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400242}
243
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700244//Update_flows_incrementally updates (add/remove) the flows on a given device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000245func (oo *OpenOLT) Update_flows_incrementally(ctx context.Context, device *voltha.Device, flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error {
246 logger.Debugw(ctx, "Update_flows_incrementally", log.Fields{"deviceId": device.Id, "flows": flows, "flowMetadata": flowMetadata})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400247 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530248 return handler.UpdateFlowsIncrementally(ctx, device, flows, groups, flowMetadata)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400249 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000250 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400251}
252
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700253//Update_pm_config returns PmConfigs nil or error
Neha Sharma96b7bf22020-06-15 10:37:32 +0000254func (oo *OpenOLT) Update_pm_config(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
255 logger.Debugw(ctx, "Update_pm_config", log.Fields{"device-id": device.Id, "pm-configs": pmConfigs})
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000256 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000257 handler.UpdatePmConfig(ctx, pmConfigs)
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000258 return nil
259 }
260 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400261}
262
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700263//Receive_packet_out sends packet out to the device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000264func (oo *OpenOLT) Receive_packet_out(ctx context.Context, deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
265 logger.Debugw(ctx, "Receive_packet_out", log.Fields{"deviceId": deviceID, "egress_port_no": egressPortNo, "pkt": packet})
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700266 if handler := oo.getDeviceHandler(deviceID); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530267 return handler.PacketOut(ctx, egressPortNo, packet)
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400268 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000269 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400270}
271
Devmalya Pauldd23a992019-11-14 07:06:31 +0000272//Suppress_event unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000273func (oo *OpenOLT) Suppress_event(ctx context.Context, filter *voltha.EventFilter) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530274 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400275}
276
Devmalya Pauldd23a992019-11-14 07:06:31 +0000277//Unsuppress_event unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000278func (oo *OpenOLT) Unsuppress_event(ctx context.Context, filter *voltha.EventFilter) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530279 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400280}
281
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700282//Download_image unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000283func (oo *OpenOLT) Download_image(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530284 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400285}
286
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700287//Get_image_download_status unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000288func (oo *OpenOLT) Get_image_download_status(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530289 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400290}
291
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700292//Cancel_image_download unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000293func (oo *OpenOLT) Cancel_image_download(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530294 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400295}
296
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700297//Activate_image_update unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000298func (oo *OpenOLT) Activate_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530299 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400300}
301
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700302//Revert_image_update unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000303func (oo *OpenOLT) Revert_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530304 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400305}
kesavand39e0aa32020-01-28 20:58:50 -0500306
307// Enable_port to Enable PON/NNI interface
Neha Sharma96b7bf22020-06-15 10:37:32 +0000308func (oo *OpenOLT) Enable_port(ctx context.Context, deviceID string, port *voltha.Port) error {
309 logger.Infow(ctx, "Enable_port", log.Fields{"deviceId": deviceID, "port": port})
310 return oo.enableDisablePort(ctx, deviceID, port, true)
kesavand39e0aa32020-01-28 20:58:50 -0500311}
312
313// Disable_port to Disable pon/nni interface
Neha Sharma96b7bf22020-06-15 10:37:32 +0000314func (oo *OpenOLT) Disable_port(ctx context.Context, deviceID string, port *voltha.Port) error {
315 logger.Infow(ctx, "Disable_port", log.Fields{"deviceId": deviceID, "port": port})
316 return oo.enableDisablePort(ctx, deviceID, port, false)
kesavand39e0aa32020-01-28 20:58:50 -0500317}
318
319// enableDisablePort to Disable pon or Enable PON interface
Neha Sharma96b7bf22020-06-15 10:37:32 +0000320func (oo *OpenOLT) enableDisablePort(ctx context.Context, deviceID string, port *voltha.Port, enablePort bool) error {
321 logger.Infow(ctx, "enableDisablePort", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500322 if port == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530323 return olterrors.NewErrInvalidValue(log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800324 "reason": "port cannot be nil",
325 "device-id": deviceID,
Girish Kumarf26e4882020-03-05 06:49:10 +0000326 "port": nil}, nil)
kesavand39e0aa32020-01-28 20:58:50 -0500327 }
328 if handler := oo.getDeviceHandler(deviceID); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000329 logger.Debugw(ctx, "Enable_Disable_Port", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500330 if enablePort {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000331 if err := handler.EnablePort(ctx, port); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000332 return olterrors.NewErrAdapter("error-occurred-during-enable-port", log.Fields{"deviceID": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500333 }
334 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000335 if err := handler.DisablePort(ctx, port); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000336 return olterrors.NewErrAdapter("error-occurred-during-disable-port", log.Fields{"deviceID": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500337 }
338 }
339 }
340 return nil
341}
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500342
343//Child_device_lost deletes the ONU and its references from PONResources
Neha Sharma96b7bf22020-06-15 10:37:32 +0000344func (oo *OpenOLT) Child_device_lost(ctx context.Context, deviceID string, pPortNo uint32, onuID uint32) error {
345 logger.Infow(ctx, "Child-device-lost", log.Fields{"parentId": deviceID})
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500346 if handler := oo.getDeviceHandler(deviceID); handler != nil {
347 return handler.ChildDeviceLost(ctx, pPortNo, onuID)
348 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530349 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil).Log()
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500350}
Scott Baker24f83e22020-03-30 16:14:28 -0700351
352//Start_omci_test not implemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000353func (oo *OpenOLT) Start_omci_test(ctx context.Context, device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
Scott Baker24f83e22020-03-30 16:14:28 -0700354 return nil, olterrors.ErrNotImplemented
355}
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800356
Andrea Campanella9931ad62020-04-28 15:11:06 +0200357//Get_ext_value retrieves a value on a particular ONU
Neha Sharma96b7bf22020-06-15 10:37:32 +0000358func (oo *OpenOLT) Get_ext_value(ctx context.Context, deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) {
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800359 var err error
360 resp := new(voltha.ReturnValues)
361 log.Infow("Get_ext_value", log.Fields{"device-id": deviceID, "onu-id": device.Id})
362 if handler := oo.getDeviceHandler(deviceID); handler != nil {
363 if resp, err = handler.getExtValue(device, valueparam); err != nil {
364 log.Errorw("error-occurred-during-get-ext-value", log.Fields{"device-id": deviceID, "onu-id": device.Id,
365 "error": err})
366 return nil, err
367 }
368 }
369 return resp, nil
370}