blob: 335a424a35135dc6bb41143805e2405666175d25 [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 {
Girish Kumar2ad402b2020-03-20 19:45:12 +000079 logger.Info("starting-device-manager")
80 logger.Info("device-manager-started")
Girish Gowdru0c588b22019-04-23 23:24:56 -040081 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 {
Girish Kumar2ad402b2020-03-20 19:45:12 +000086 logger.Info("stopping-device-manager")
Girish Gowdru0c588b22019-04-23 23:24:56 -040087 oo.exitChannel <- 1
Girish Kumar2ad402b2020-03-20 19:45:12 +000088 logger.Info("device-manager-stopped")
Girish Gowdru0c588b22019-04-23 23:24:56 -040089 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
Girish Kumar2ad402b2020-03-20 19:45:12 +000097 logger.Debugw("sendResponse", log.Fields{"result": result})
Girish Gowdru0c588b22019-04-23 23:24:56 -040098 } else {
99 // Should the transaction be reverted back?
Girish Kumar2ad402b2020-03-20 19:45:12 +0000100 logger.Debugw("sendResponse-context-error", log.Fields{"context-error": ctx.Err()})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400101 }
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 {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000129 logger.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 {
Girish Kumarf26e4882020-03-05 06:49:10 +0000134 return olterrors.NewErrAdapter("subscribe-for-device-topic-failed", log.Fields{"device-topic": deviceTopic}, err)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400135 }
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 {
Thomas Lee S94109f12020-03-03 16:39:29 +0530143 return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400144 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000145 logger.Infow("adopt-device", log.Fields{"deviceId": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400146 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) {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000159 logger.Infow("Get_ofp_device_info", log.Fields{"deviceId": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400160 if handler := oo.getDeviceHandler(device.Id); handler != nil {
161 return handler.GetOfpDeviceInfo(device)
162 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000163 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
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 Kumar2ad402b2020-03-20 19:45:12 +0000168 logger.Infow("Get_ofp_port_info", log.Fields{"deviceId": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400169 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 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000172 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
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 {
Andrea Campanella9931ad62020-04-28 15:11:06 +0200177 logger.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400178 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 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000186 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": targetDevice}, nil)
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 {
Thomas Lee S94109f12020-03-03 16:39:29 +0530191 return olterrors.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) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530196 return nil, olterrors.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) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530201 return nil, olterrors.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 {
Girish Kumarf26e4882020-03-05 06:49:10 +0000208 return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530209 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000210 logger.Infow("reconcile-device", log.Fields{"deviceId": device.Id})
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530211 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 {
Thomas Lee S94109f12020-03-03 16:39:29 +0530223 return olterrors.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 Kumar2ad402b2020-03-20 19:45:12 +0000228 logger.Infow("disable-device", log.Fields{"deviceId": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400229 if handler := oo.getDeviceHandler(device.Id); handler != nil {
230 return handler.DisableDevice(device)
231 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000232 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
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 Kumar2ad402b2020-03-20 19:45:12 +0000237 logger.Infow("reenable-device", log.Fields{"deviceId": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400238 if handler := oo.getDeviceHandler(device.Id); handler != nil {
239 return handler.ReenableDevice(device)
240 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000241 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
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 Kumar2ad402b2020-03-20 19:45:12 +0000246 logger.Infow("reboot-device", log.Fields{"deviceId": device.Id})
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400247 if handler := oo.getDeviceHandler(device.Id); handler != nil {
248 return handler.RebootDevice(device)
249 }
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//Self_test_device unimplented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400254func (oo *OpenOLT) Self_test_device(device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530255 return olterrors.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 {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000260 logger.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 {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000264 logger.Errorw("failed-to-handle-delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400265 }
266 oo.deleteDeviceHandlerToMap(handler)
267 return nil
268 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000269 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
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 {
Thomas Lee S94109f12020-03-03 16:39:29 +0530274 return olterrors.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 {
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//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 {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000284 logger.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 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000289 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
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 {
Thomas Lee S94109f12020-03-03 16:39:29 +0530294 return olterrors.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 {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000299 logger.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 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000304 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil)
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 {
Thomas Lee S94109f12020-03-03 16:39:29 +0530309 return olterrors.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 {
Thomas Lee S94109f12020-03-03 16:39:29 +0530314 return olterrors.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) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530319 return nil, olterrors.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) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530324 return nil, olterrors.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) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530329 return nil, olterrors.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) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530334 return nil, olterrors.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) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530339 return nil, olterrors.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 {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000344 logger.Infow("Enable_port", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500345 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 {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000350 logger.Infow("Disable_port", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500351 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 {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000356 logger.Infow("enableDisablePort", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500357 if port == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530358 return olterrors.NewErrInvalidValue(log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800359 "reason": "port cannot be nil",
360 "device-id": deviceID,
Girish Kumarf26e4882020-03-05 06:49:10 +0000361 "port": nil}, nil)
kesavand39e0aa32020-01-28 20:58:50 -0500362 }
363 if handler := oo.getDeviceHandler(deviceID); handler != nil {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000364 logger.Debugw("Enable_Disable_Port", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500365 if enablePort {
366 if err := handler.EnablePort(port); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000367 return olterrors.NewErrAdapter("error-occurred-during-enable-port", log.Fields{"deviceID": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500368 }
369 } else {
370 if err := handler.DisablePort(port); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000371 return olterrors.NewErrAdapter("error-occurred-during-disable-port", log.Fields{"deviceID": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500372 }
373 }
374 }
375 return nil
376}
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500377
378//Child_device_lost deletes the ONU and its references from PONResources
379func (oo *OpenOLT) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000380 logger.Infow("Child-device-lost", log.Fields{"parentId": deviceID})
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500381 ctx := context.Background()
382 if handler := oo.getDeviceHandler(deviceID); handler != nil {
383 return handler.ChildDeviceLost(ctx, pPortNo, onuID)
384 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530385 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil).Log()
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500386}
Scott Baker24f83e22020-03-30 16:14:28 -0700387
388//Start_omci_test not implemented
389func (oo *OpenOLT) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
390 return nil, olterrors.ErrNotImplemented
391}
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800392
Andrea Campanella9931ad62020-04-28 15:11:06 +0200393//Get_ext_value retrieves a value on a particular ONU
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800394func (oo *OpenOLT) Get_ext_value(deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) {
395 var err error
396 resp := new(voltha.ReturnValues)
397 log.Infow("Get_ext_value", log.Fields{"device-id": deviceID, "onu-id": device.Id})
398 if handler := oo.getDeviceHandler(deviceID); handler != nil {
399 if resp, err = handler.getExtValue(device, valueparam); err != nil {
400 log.Errorw("error-occurred-during-get-ext-value", log.Fields{"device-id": deviceID, "onu-id": device.Id,
401 "error": err})
402 return nil, err
403 }
404 }
405 return resp, nil
406}