blob: 4a25dba869c590698dd9fdf945a20ec8afbdc169 [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 {
Girish Kumar2ad402b2020-03-20 19:45:12 +000077 logger.Info("starting-device-manager")
78 logger.Info("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 {
Girish Kumar2ad402b2020-03-20 19:45:12 +000084 logger.Info("stopping-device-manager")
Girish Gowdru0c588b22019-04-23 23:24:56 -040085 oo.exitChannel <- 1
Girish Kumar2ad402b2020-03-20 19:45:12 +000086 logger.Info("device-manager-stopped")
Girish Gowdru0c588b22019-04-23 23:24:56 -040087 return nil
88}
89
90func sendResponse(ctx context.Context, ch chan interface{}, result interface{}) {
91 if ctx.Err() == nil {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070092 // Returned response only of the ctx has not been canceled/timeout/etc
Girish Gowdru0c588b22019-04-23 23:24:56 -040093 // Channel is automatically closed when a context is Done
94 ch <- result
Girish Kumar2ad402b2020-03-20 19:45:12 +000095 logger.Debugw("sendResponse", log.Fields{"result": result})
Girish Gowdru0c588b22019-04-23 23:24:56 -040096 } else {
97 // Should the transaction be reverted back?
Girish Kumar2ad402b2020-03-20 19:45:12 +000098 logger.Debugw("sendResponse-context-error", log.Fields{"context-error": ctx.Err()})
Girish Gowdru0c588b22019-04-23 23:24:56 -040099 }
100}
101
102func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) {
103 oo.lockDeviceHandlersMap.Lock()
104 defer oo.lockDeviceHandlersMap.Unlock()
Thomas Lee S985938d2020-05-04 11:40:41 +0530105 if _, exist := oo.deviceHandlers[agent.device.Id]; !exist {
106 oo.deviceHandlers[agent.device.Id] = agent
Girish Gowdru0c588b22019-04-23 23:24:56 -0400107 }
108}
109
110func (oo *OpenOLT) deleteDeviceHandlerToMap(agent *DeviceHandler) {
111 oo.lockDeviceHandlersMap.Lock()
112 defer oo.lockDeviceHandlersMap.Unlock()
Thomas Lee S985938d2020-05-04 11:40:41 +0530113 delete(oo.deviceHandlers, agent.device.Id)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400114}
115
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700116func (oo *OpenOLT) getDeviceHandler(deviceID string) *DeviceHandler {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400117 oo.lockDeviceHandlersMap.Lock()
118 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700119 if agent, ok := oo.deviceHandlers[deviceID]; ok {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400120 return agent
121 }
122 return nil
123}
124
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700125//createDeviceTopic returns
Girish Gowdru0c588b22019-04-23 23:24:56 -0400126func (oo *OpenOLT) createDeviceTopic(device *voltha.Device) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000127 logger.Infow("create-device-topic", log.Fields{"deviceId": device.Id})
npujarec5762e2020-01-01 14:08:48 +0530128 defaultTopic := oo.kafkaICProxy.GetDefaultTopic()
129 deviceTopic := kafka.Topic{Name: defaultTopic.Name + "_" + device.Id}
Girish Gowdru0c588b22019-04-23 23:24:56 -0400130 // TODO for the offset
131 if err := oo.kafkaICProxy.SubscribeWithDefaultRequestHandler(deviceTopic, 0); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000132 return olterrors.NewErrAdapter("subscribe-for-device-topic-failed", log.Fields{"device-topic": deviceTopic}, err)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400133 }
134 return nil
135}
136
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700137// Adopt_device creates a new device handler if not present already and then adopts the device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400138func (oo *OpenOLT) Adopt_device(device *voltha.Device) error {
npujarec5762e2020-01-01 14:08:48 +0530139 ctx := context.Background()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400140 if device == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530141 return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400142 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000143 logger.Infow("adopt-device", log.Fields{"deviceId": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400144 var handler *DeviceHandler
145 if handler = oo.getDeviceHandler(device.Id); handler == nil {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400146 handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400147 oo.addDeviceHandlerToMap(handler)
npujarec5762e2020-01-01 14:08:48 +0530148 go handler.AdoptDevice(ctx, device)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400149 // Launch the creation of the device topic
150 // go oo.createDeviceTopic(device)
151 }
152 return nil
153}
154
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700155//Get_ofp_device_info returns OFP information for the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400156func (oo *OpenOLT) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000157 logger.Infow("Get_ofp_device_info", log.Fields{"deviceId": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400158 if handler := oo.getDeviceHandler(device.Id); handler != nil {
159 return handler.GetOfpDeviceInfo(device)
160 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000161 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400162}
163
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700164//Process_inter_adapter_message sends messages to a target device (between adapters)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400165func (oo *OpenOLT) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error {
Andrea Campanella9931ad62020-04-28 15:11:06 +0200166 logger.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400167 targetDevice := msg.Header.ProxyDeviceId // Request?
168 if targetDevice == "" && msg.Header.ToDeviceId != "" {
169 // Typical response
170 targetDevice = msg.Header.ToDeviceId
171 }
172 if handler := oo.getDeviceHandler(targetDevice); handler != nil {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700173 return handler.ProcessInterAdapterMessage(msg)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400174 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000175 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": targetDevice}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400176}
177
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700178//Adapter_descriptor not implemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400179func (oo *OpenOLT) Adapter_descriptor() error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530180 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400181}
182
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700183//Device_types unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400184func (oo *OpenOLT) Device_types() (*voltha.DeviceTypes, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530185 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400186}
187
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700188//Health returns unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400189func (oo *OpenOLT) Health() (*voltha.HealthStatus, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530190 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400191}
192
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700193//Reconcile_device unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400194func (oo *OpenOLT) Reconcile_device(device *voltha.Device) error {
npujarec5762e2020-01-01 14:08:48 +0530195 ctx := context.Background()
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530196 if device == nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000197 return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530198 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000199 logger.Infow("reconcile-device", log.Fields{"deviceId": device.Id})
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530200 var handler *DeviceHandler
201 if handler = oo.getDeviceHandler(device.Id); handler == nil {
202 handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
203 oo.addDeviceHandlerToMap(handler)
204 handler.transitionMap = NewTransitionMap(handler)
npujarec5762e2020-01-01 14:08:48 +0530205 handler.transitionMap.Handle(ctx, DeviceInit)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530206 }
207 return nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400208}
209
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700210//Abandon_device unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400211func (oo *OpenOLT) Abandon_device(device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530212 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400213}
214
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700215//Disable_device disables the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400216func (oo *OpenOLT) Disable_device(device *voltha.Device) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000217 logger.Infow("disable-device", log.Fields{"deviceId": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400218 if handler := oo.getDeviceHandler(device.Id); handler != nil {
219 return handler.DisableDevice(device)
220 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000221 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400222}
223
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700224//Reenable_device enables the olt device after disable
Girish Gowdru0c588b22019-04-23 23:24:56 -0400225func (oo *OpenOLT) Reenable_device(device *voltha.Device) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000226 logger.Infow("reenable-device", log.Fields{"deviceId": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400227 if handler := oo.getDeviceHandler(device.Id); handler != nil {
228 return handler.ReenableDevice(device)
229 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000230 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400231}
232
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700233//Reboot_device reboots the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400234func (oo *OpenOLT) Reboot_device(device *voltha.Device) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000235 logger.Infow("reboot-device", log.Fields{"deviceId": device.Id})
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400236 if handler := oo.getDeviceHandler(device.Id); handler != nil {
237 return handler.RebootDevice(device)
238 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000239 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400240}
241
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700242//Self_test_device unimplented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400243func (oo *OpenOLT) Self_test_device(device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530244 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400245}
246
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700247//Delete_device unimplemented
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400248func (oo *OpenOLT) Delete_device(device *voltha.Device) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000249 logger.Infow("delete-device", log.Fields{"deviceId": device.Id})
npujarec5762e2020-01-01 14:08:48 +0530250 ctx := context.Background()
Devmalya Paul495b94a2019-08-27 19:42:00 -0400251 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530252 if err := handler.DeleteDevice(ctx, device); err != nil {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000253 logger.Errorw("failed-to-handle-delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400254 }
255 oo.deleteDeviceHandlerToMap(handler)
256 return nil
257 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000258 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400259}
260
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700261//Get_device_details unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400262func (oo *OpenOLT) Get_device_details(device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530263 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400264}
265
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700266//Update_flows_bulk returns
Manikkaraj kb1d51442019-07-23 10:41:02 -0400267func (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 +0530268 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400269}
270
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700271//Update_flows_incrementally updates (add/remove) the flows on a given device
Manikkaraj kb1d51442019-07-23 10:41:02 -0400272func (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 +0000273 logger.Debugw("Update_flows_incrementally", log.Fields{"deviceId": device.Id, "flows": flows, "flowMetadata": flowMetadata})
npujarec5762e2020-01-01 14:08:48 +0530274 ctx := context.Background()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400275 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530276 return handler.UpdateFlowsIncrementally(ctx, device, flows, groups, flowMetadata)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400277 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000278 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400279}
280
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700281//Update_pm_config returns PmConfigs nil or error
282func (oo *OpenOLT) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000283 logger.Debugw("Update_pm_config", log.Fields{"device-id": device.Id, "pm-configs": pmConfigs})
284 if handler := oo.getDeviceHandler(device.Id); handler != nil {
285 handler.UpdatePmConfig(pmConfigs)
286 return nil
287 }
288 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400289}
290
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700291//Receive_packet_out sends packet out to the device
292func (oo *OpenOLT) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000293 logger.Debugw("Receive_packet_out", log.Fields{"deviceId": deviceID, "egress_port_no": egressPortNo, "pkt": packet})
npujarec5762e2020-01-01 14:08:48 +0530294 ctx := context.Background()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700295 if handler := oo.getDeviceHandler(deviceID); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530296 return handler.PacketOut(ctx, egressPortNo, packet)
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400297 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000298 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400299}
300
Devmalya Pauldd23a992019-11-14 07:06:31 +0000301//Suppress_event unimplemented
302func (oo *OpenOLT) Suppress_event(filter *voltha.EventFilter) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530303 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400304}
305
Devmalya Pauldd23a992019-11-14 07:06:31 +0000306//Unsuppress_event unimplemented
307func (oo *OpenOLT) Unsuppress_event(filter *voltha.EventFilter) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530308 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400309}
310
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700311//Download_image unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400312func (oo *OpenOLT) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530313 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400314}
315
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700316//Get_image_download_status unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400317func (oo *OpenOLT) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530318 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400319}
320
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700321//Cancel_image_download unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400322func (oo *OpenOLT) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530323 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400324}
325
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700326//Activate_image_update unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400327func (oo *OpenOLT) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530328 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400329}
330
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700331//Revert_image_update unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400332func (oo *OpenOLT) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530333 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400334}
kesavand39e0aa32020-01-28 20:58:50 -0500335
336// Enable_port to Enable PON/NNI interface
337func (oo *OpenOLT) Enable_port(deviceID string, port *voltha.Port) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000338 logger.Infow("Enable_port", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500339 return oo.enableDisablePort(deviceID, port, true)
340}
341
342// Disable_port to Disable pon/nni interface
343func (oo *OpenOLT) Disable_port(deviceID string, port *voltha.Port) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000344 logger.Infow("Disable_port", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500345 return oo.enableDisablePort(deviceID, port, false)
346}
347
348// enableDisablePort to Disable pon or Enable PON interface
349func (oo *OpenOLT) enableDisablePort(deviceID string, port *voltha.Port, enablePort bool) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000350 logger.Infow("enableDisablePort", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500351 if port == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530352 return olterrors.NewErrInvalidValue(log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800353 "reason": "port cannot be nil",
354 "device-id": deviceID,
Girish Kumarf26e4882020-03-05 06:49:10 +0000355 "port": nil}, nil)
kesavand39e0aa32020-01-28 20:58:50 -0500356 }
357 if handler := oo.getDeviceHandler(deviceID); handler != nil {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000358 logger.Debugw("Enable_Disable_Port", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500359 if enablePort {
360 if err := handler.EnablePort(port); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000361 return olterrors.NewErrAdapter("error-occurred-during-enable-port", log.Fields{"deviceID": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500362 }
363 } else {
364 if err := handler.DisablePort(port); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000365 return olterrors.NewErrAdapter("error-occurred-during-disable-port", log.Fields{"deviceID": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500366 }
367 }
368 }
369 return nil
370}
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500371
372//Child_device_lost deletes the ONU and its references from PONResources
373func (oo *OpenOLT) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000374 logger.Infow("Child-device-lost", log.Fields{"parentId": deviceID})
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500375 ctx := context.Background()
376 if handler := oo.getDeviceHandler(deviceID); handler != nil {
377 return handler.ChildDeviceLost(ctx, pPortNo, onuID)
378 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530379 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil).Log()
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500380}
Scott Baker24f83e22020-03-30 16:14:28 -0700381
382//Start_omci_test not implemented
383func (oo *OpenOLT) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
384 return nil, olterrors.ErrNotImplemented
385}
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800386
Andrea Campanella9931ad62020-04-28 15:11:06 +0200387//Get_ext_value retrieves a value on a particular ONU
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800388func (oo *OpenOLT) Get_ext_value(deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) {
389 var err error
390 resp := new(voltha.ReturnValues)
391 log.Infow("Get_ext_value", log.Fields{"device-id": deviceID, "onu-id": device.Id})
392 if handler := oo.getDeviceHandler(deviceID); handler != nil {
393 if resp, err = handler.getExtValue(device, valueparam); err != nil {
394 log.Errorw("error-occurred-during-get-ext-value", log.Fields{"device-id": deviceID, "onu-id": device.Id,
395 "error": err})
396 return nil, err
397 }
398 }
399 return resp, nil
400}