blob: eebed78de60bd3dd06fe785122cbe0b75aebf94a [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
Girish Gowdraa09aeab2020-09-14 16:30:52 -070025 "github.com/opencord/voltha-lib-go/v4/pkg/adapters/adapterif"
Matteo Scandolodfa7a972020-11-06 13:03:40 -080026 conf "github.com/opencord/voltha-lib-go/v4/pkg/config"
Himani Chawlacd407802020-12-10 12:08:59 +053027 "github.com/opencord/voltha-lib-go/v4/pkg/events/eventif"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070028 "github.com/opencord/voltha-lib-go/v4/pkg/kafka"
29 "github.com/opencord/voltha-lib-go/v4/pkg/log"
Scott Bakerdbd960e2020-02-28 08:57:51 -080030 "github.com/opencord/voltha-openolt-adapter/internal/pkg/config"
Thomas Lee S94109f12020-03-03 16:39:29 +053031 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
kesavand62126212021-01-12 04:56:06 -050032 "github.com/opencord/voltha-protos/v4/go/extension"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070033 ic "github.com/opencord/voltha-protos/v4/go/inter_container"
34 "github.com/opencord/voltha-protos/v4/go/openflow_13"
35 "github.com/opencord/voltha-protos/v4/go/voltha"
Girish Gowdru0c588b22019-04-23 23:24:56 -040036)
37
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070038//OpenOLT structure holds the OLT information
Girish Gowdru0c588b22019-04-23 23:24:56 -040039type OpenOLT struct {
Matteo Scandolodfa7a972020-11-06 13:03:40 -080040 configManager *conf.ConfigManager
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053041 deviceHandlers map[string]*DeviceHandler
42 coreProxy adapterif.CoreProxy
43 adapterProxy adapterif.AdapterProxy
Himani Chawlacd407802020-12-10 12:08:59 +053044 eventProxy eventif.EventProxy
npujarec5762e2020-01-01 14:08:48 +053045 kafkaICProxy kafka.InterContainerProxy
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053046 config *config.AdapterFlags
47 numOnus int
Neha Sharma3f221ae2020-04-29 19:02:12 +000048 KVStoreAddress string
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053049 KVStoreType string
50 exitChannel chan int
51 HeartbeatCheckInterval time.Duration
52 HeartbeatFailReportInterval time.Duration
53 GrpcTimeoutInterval time.Duration
54 lockDeviceHandlersMap sync.RWMutex
Gamze Abakafcbd6e72020-12-17 13:25:16 +000055 enableONUStats bool
56 enableGemStats bool
Girish Gowdru0c588b22019-04-23 23:24:56 -040057}
58
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070059//NewOpenOLT returns a new instance of OpenOLT
npujarec5762e2020-01-01 14:08:48 +053060func NewOpenOLT(ctx context.Context, kafkaICProxy kafka.InterContainerProxy,
kdarapu381c6902019-07-31 18:23:16 +053061 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
Himani Chawlacd407802020-12-10 12:08:59 +053062 eventProxy eventif.EventProxy, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenOLT {
Girish Gowdru0c588b22019-04-23 23:24:56 -040063 var openOLT OpenOLT
64 openOLT.exitChannel = make(chan int, 1)
65 openOLT.deviceHandlers = make(map[string]*DeviceHandler)
66 openOLT.kafkaICProxy = kafkaICProxy
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053067 openOLT.config = cfg
68 openOLT.numOnus = cfg.OnuNumber
Girish Gowdru0c588b22019-04-23 23:24:56 -040069 openOLT.coreProxy = coreProxy
70 openOLT.adapterProxy = adapterProxy
Devmalya Paulfb990a52019-07-09 10:01:49 -040071 openOLT.eventProxy = eventProxy
Neha Sharma3f221ae2020-04-29 19:02:12 +000072 openOLT.KVStoreAddress = cfg.KVStoreAddress
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053073 openOLT.KVStoreType = cfg.KVStoreType
74 openOLT.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
75 openOLT.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
76 openOLT.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Girish Gowdru0c588b22019-04-23 23:24:56 -040077 openOLT.lockDeviceHandlersMap = sync.RWMutex{}
Matteo Scandolodfa7a972020-11-06 13:03:40 -080078 openOLT.configManager = cm
Gamze Abakafcbd6e72020-12-17 13:25:16 +000079 openOLT.enableONUStats = cfg.EnableONUStats
80 openOLT.enableGemStats = cfg.EnableGEMStats
Girish Gowdru0c588b22019-04-23 23:24:56 -040081 return &openOLT
82}
83
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070084//Start starts (logs) the device manager
Girish Gowdru0c588b22019-04-23 23:24:56 -040085func (oo *OpenOLT) Start(ctx context.Context) error {
Neha Sharma96b7bf22020-06-15 10:37:32 +000086 logger.Info(ctx, "starting-device-manager")
87 logger.Info(ctx, "device-manager-started")
Girish Gowdru0c588b22019-04-23 23:24:56 -040088 return nil
89}
90
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070091//Stop terminates the session
Girish Gowdru0c588b22019-04-23 23:24:56 -040092func (oo *OpenOLT) Stop(ctx context.Context) error {
Neha Sharma96b7bf22020-06-15 10:37:32 +000093 logger.Info(ctx, "stopping-device-manager")
Girish Gowdru0c588b22019-04-23 23:24:56 -040094 oo.exitChannel <- 1
Neha Sharma96b7bf22020-06-15 10:37:32 +000095 logger.Info(ctx, "device-manager-stopped")
Girish Gowdru0c588b22019-04-23 23:24:56 -040096 return nil
97}
98
Girish Gowdru0c588b22019-04-23 23:24:56 -040099func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) {
100 oo.lockDeviceHandlersMap.Lock()
101 defer oo.lockDeviceHandlersMap.Unlock()
Thomas Lee S985938d2020-05-04 11:40:41 +0530102 if _, exist := oo.deviceHandlers[agent.device.Id]; !exist {
103 oo.deviceHandlers[agent.device.Id] = agent
Girish Gowdru0c588b22019-04-23 23:24:56 -0400104 }
105}
106
107func (oo *OpenOLT) deleteDeviceHandlerToMap(agent *DeviceHandler) {
108 oo.lockDeviceHandlersMap.Lock()
109 defer oo.lockDeviceHandlersMap.Unlock()
Thomas Lee S985938d2020-05-04 11:40:41 +0530110 delete(oo.deviceHandlers, agent.device.Id)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400111}
112
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700113func (oo *OpenOLT) getDeviceHandler(deviceID string) *DeviceHandler {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400114 oo.lockDeviceHandlersMap.Lock()
115 defer oo.lockDeviceHandlersMap.Unlock()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700116 if agent, ok := oo.deviceHandlers[deviceID]; ok {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400117 return agent
118 }
119 return nil
120}
121
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700122// Adopt_device creates a new device handler if not present already and then adopts the device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000123func (oo *OpenOLT) Adopt_device(ctx context.Context, device *voltha.Device) error {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400124 if device == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530125 return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400126 }
divyadesai3af43e12020-08-18 07:10:54 +0000127 logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400128 var handler *DeviceHandler
129 if handler = oo.getDeviceHandler(device.Id); handler == nil {
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800130 handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo, oo.configManager)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400131 oo.addDeviceHandlerToMap(handler)
npujarec5762e2020-01-01 14:08:48 +0530132 go handler.AdoptDevice(ctx, device)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400133 // Launch the creation of the device topic
134 // go oo.createDeviceTopic(device)
135 }
136 return nil
137}
138
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700139//Get_ofp_device_info returns OFP information for the given device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000140func (oo *OpenOLT) Get_ofp_device_info(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) {
divyadesai3af43e12020-08-18 07:10:54 +0000141 logger.Infow(ctx, "Get_ofp_device_info", log.Fields{"device-id": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400142 if handler := oo.getDeviceHandler(device.Id); handler != nil {
143 return handler.GetOfpDeviceInfo(device)
144 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000145 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400146}
147
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700148//Process_inter_adapter_message sends messages to a target device (between adapters)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000149func (oo *OpenOLT) Process_inter_adapter_message(ctx context.Context, msg *ic.InterAdapterMessage) error {
150 logger.Debugw(ctx, "Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400151 targetDevice := msg.Header.ProxyDeviceId // Request?
152 if targetDevice == "" && msg.Header.ToDeviceId != "" {
153 // Typical response
154 targetDevice = msg.Header.ToDeviceId
155 }
156 if handler := oo.getDeviceHandler(targetDevice); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000157 return handler.ProcessInterAdapterMessage(ctx, msg)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400158 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000159 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": targetDevice}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400160}
161
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700162//Adapter_descriptor not implemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000163func (oo *OpenOLT) Adapter_descriptor(ctx context.Context) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530164 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400165}
166
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700167//Device_types unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000168func (oo *OpenOLT) Device_types(ctx context.Context) (*voltha.DeviceTypes, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530169 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400170}
171
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700172//Health returns unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000173func (oo *OpenOLT) Health(ctx context.Context) (*voltha.HealthStatus, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530174 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400175}
176
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700177//Reconcile_device unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000178func (oo *OpenOLT) Reconcile_device(ctx context.Context, device *voltha.Device) error {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530179 if device == nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000180 return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530181 }
divyadesai3af43e12020-08-18 07:10:54 +0000182 logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id})
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530183 var handler *DeviceHandler
184 if handler = oo.getDeviceHandler(device.Id); handler == nil {
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800185 handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo, oo.configManager)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530186 oo.addDeviceHandlerToMap(handler)
187 handler.transitionMap = NewTransitionMap(handler)
npujarec5762e2020-01-01 14:08:48 +0530188 handler.transitionMap.Handle(ctx, DeviceInit)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530189 }
190 return nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400191}
192
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700193//Abandon_device unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000194func (oo *OpenOLT) Abandon_device(ctx context.Context, device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530195 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400196}
197
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700198//Disable_device disables the given device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000199func (oo *OpenOLT) Disable_device(ctx context.Context, device *voltha.Device) error {
divyadesai3af43e12020-08-18 07:10:54 +0000200 logger.Infow(ctx, "disable-device", log.Fields{"device-id": 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.DisableDevice(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//Reenable_device enables the olt device after disable
Neha Sharma96b7bf22020-06-15 10:37:32 +0000208func (oo *OpenOLT) Reenable_device(ctx context.Context, device *voltha.Device) error {
divyadesai3af43e12020-08-18 07:10:54 +0000209 logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400210 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000211 return handler.ReenableDevice(ctx, device)
Girish Gowdru5ba46c92019-04-25 05:00:05 -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//Reboot_device reboots the given device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000217func (oo *OpenOLT) Reboot_device(ctx context.Context, device *voltha.Device) error {
divyadesai3af43e12020-08-18 07:10:54 +0000218 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400219 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000220 return handler.RebootDevice(ctx, device)
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400221 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000222 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400223}
224
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700225//Self_test_device unimplented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000226func (oo *OpenOLT) Self_test_device(ctx context.Context, device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530227 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400228}
229
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700230//Delete_device unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000231func (oo *OpenOLT) Delete_device(ctx context.Context, device *voltha.Device) error {
divyadesai3af43e12020-08-18 07:10:54 +0000232 logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400233 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530234 if err := handler.DeleteDevice(ctx, device); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000235 logger.Errorw(ctx, "failed-to-handle-delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400236 }
237 oo.deleteDeviceHandlerToMap(handler)
238 return nil
239 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000240 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400241}
242
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700243//Get_device_details unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000244func (oo *OpenOLT) Get_device_details(ctx context.Context, device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530245 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400246}
247
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700248//Update_flows_bulk returns
Neha Sharma96b7bf22020-06-15 10:37:32 +0000249func (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 +0530250 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400251}
252
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700253//Update_flows_incrementally updates (add/remove) the flows on a given device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000254func (oo *OpenOLT) Update_flows_incrementally(ctx context.Context, device *voltha.Device, flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error {
Girish Gowdraeb450292020-10-26 10:03:39 -0700255 logger.Infow(ctx, "Update_flows_incrementally", log.Fields{"device-id": device.Id, "flows": flows, "flowMetadata": flowMetadata})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400256 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530257 return handler.UpdateFlowsIncrementally(ctx, device, flows, groups, flowMetadata)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400258 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000259 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400260}
261
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700262//Update_pm_config returns PmConfigs nil or error
Neha Sharma96b7bf22020-06-15 10:37:32 +0000263func (oo *OpenOLT) Update_pm_config(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
264 logger.Debugw(ctx, "Update_pm_config", log.Fields{"device-id": device.Id, "pm-configs": pmConfigs})
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000265 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000266 handler.UpdatePmConfig(ctx, pmConfigs)
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000267 return nil
268 }
269 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//Receive_packet_out sends packet out to the device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000273func (oo *OpenOLT) Receive_packet_out(ctx context.Context, deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
divyadesai3af43e12020-08-18 07:10:54 +0000274 logger.Debugw(ctx, "Receive_packet_out", log.Fields{"device-id": deviceID, "egress_port_no": egressPortNo, "pkt": packet})
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700275 if handler := oo.getDeviceHandler(deviceID); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530276 return handler.PacketOut(ctx, egressPortNo, packet)
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400277 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000278 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400279}
280
Devmalya Pauldd23a992019-11-14 07:06:31 +0000281//Suppress_event unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000282func (oo *OpenOLT) Suppress_event(ctx context.Context, filter *voltha.EventFilter) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530283 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400284}
285
Devmalya Pauldd23a992019-11-14 07:06:31 +0000286//Unsuppress_event unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000287func (oo *OpenOLT) Unsuppress_event(ctx context.Context, filter *voltha.EventFilter) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530288 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400289}
290
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700291//Download_image unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000292func (oo *OpenOLT) Download_image(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530293 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400294}
295
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700296//Get_image_download_status unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000297func (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 +0530298 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400299}
300
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700301//Cancel_image_download unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000302func (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 +0530303 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400304}
305
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700306//Activate_image_update unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000307func (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 +0530308 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400309}
310
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700311//Revert_image_update unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000312func (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 +0530313 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400314}
kesavand39e0aa32020-01-28 20:58:50 -0500315
316// Enable_port to Enable PON/NNI interface
Neha Sharma96b7bf22020-06-15 10:37:32 +0000317func (oo *OpenOLT) Enable_port(ctx context.Context, deviceID string, port *voltha.Port) error {
divyadesai3af43e12020-08-18 07:10:54 +0000318 logger.Infow(ctx, "Enable_port", log.Fields{"device-id": deviceID, "port": port})
Neha Sharma96b7bf22020-06-15 10:37:32 +0000319 return oo.enableDisablePort(ctx, deviceID, port, true)
kesavand39e0aa32020-01-28 20:58:50 -0500320}
321
322// Disable_port to Disable pon/nni interface
Neha Sharma96b7bf22020-06-15 10:37:32 +0000323func (oo *OpenOLT) Disable_port(ctx context.Context, deviceID string, port *voltha.Port) error {
divyadesai3af43e12020-08-18 07:10:54 +0000324 logger.Infow(ctx, "Disable_port", log.Fields{"device-id": deviceID, "port": port})
Neha Sharma96b7bf22020-06-15 10:37:32 +0000325 return oo.enableDisablePort(ctx, deviceID, port, false)
kesavand39e0aa32020-01-28 20:58:50 -0500326}
327
328// enableDisablePort to Disable pon or Enable PON interface
Neha Sharma96b7bf22020-06-15 10:37:32 +0000329func (oo *OpenOLT) enableDisablePort(ctx context.Context, deviceID string, port *voltha.Port, enablePort bool) error {
divyadesai3af43e12020-08-18 07:10:54 +0000330 logger.Infow(ctx, "enableDisablePort", log.Fields{"device-id": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500331 if port == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530332 return olterrors.NewErrInvalidValue(log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800333 "reason": "port cannot be nil",
334 "device-id": deviceID,
Girish Kumarf26e4882020-03-05 06:49:10 +0000335 "port": nil}, nil)
kesavand39e0aa32020-01-28 20:58:50 -0500336 }
337 if handler := oo.getDeviceHandler(deviceID); handler != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000338 logger.Debugw(ctx, "Enable_Disable_Port", log.Fields{"device-id": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500339 if enablePort {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000340 if err := handler.EnablePort(ctx, port); err != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000341 return olterrors.NewErrAdapter("error-occurred-during-enable-port", log.Fields{"device-id": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500342 }
343 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000344 if err := handler.DisablePort(ctx, port); err != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000345 return olterrors.NewErrAdapter("error-occurred-during-disable-port", log.Fields{"device-id": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500346 }
347 }
348 }
349 return nil
350}
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500351
352//Child_device_lost deletes the ONU and its references from PONResources
Neha Sharma96b7bf22020-06-15 10:37:32 +0000353func (oo *OpenOLT) Child_device_lost(ctx context.Context, deviceID string, pPortNo uint32, onuID uint32) error {
divyadesai3af43e12020-08-18 07:10:54 +0000354 logger.Infow(ctx, "Child-device-lost", log.Fields{"parent-device-id": deviceID})
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500355 if handler := oo.getDeviceHandler(deviceID); handler != nil {
356 return handler.ChildDeviceLost(ctx, pPortNo, onuID)
357 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530358 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil).Log()
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500359}
Scott Baker24f83e22020-03-30 16:14:28 -0700360
361//Start_omci_test not implemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000362func (oo *OpenOLT) Start_omci_test(ctx context.Context, device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
Scott Baker24f83e22020-03-30 16:14:28 -0700363 return nil, olterrors.ErrNotImplemented
364}
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800365
Andrea Campanella9931ad62020-04-28 15:11:06 +0200366//Get_ext_value retrieves a value on a particular ONU
Neha Sharma96b7bf22020-06-15 10:37:32 +0000367func (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 -0800368 var err error
369 resp := new(voltha.ReturnValues)
Girish Kumara1ea2aa2020-08-19 18:14:22 +0000370 logger.Infow(ctx, "Get_ext_value", log.Fields{"device-id": deviceID, "onu-id": device.Id})
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800371 if handler := oo.getDeviceHandler(deviceID); handler != nil {
Neha Sharma8f4e4322020-08-06 10:51:53 +0000372 if resp, err = handler.getExtValue(ctx, device, valueparam); err != nil {
Girish Kumara1ea2aa2020-08-19 18:14:22 +0000373 logger.Errorw(ctx, "error-occurred-during-get-ext-value", log.Fields{"device-id": deviceID, "onu-id": device.Id,
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800374 "error": err})
375 return nil, err
376 }
377 }
378 return resp, nil
379}
kesavand62126212021-01-12 04:56:06 -0500380
381//Single_get_value_request handles get uni status on ONU and ondemand metric on OLT
382func (oo *OpenOLT) Single_get_value_request(ctx context.Context, request extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
383 logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request})
384
385 errResp := func(status extension.GetValueResponse_Status,
386 reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse {
387 return &extension.SingleGetValueResponse{
388 Response: &extension.GetValueResponse{
389 Status: status,
390 ErrReason: reason,
391 },
392 }
393 }
394 if handler := oo.getDeviceHandler(request.TargetId); handler != nil {
395 switch reqType := request.GetRequest().GetRequest().(type) {
396 case *extension.GetValueRequest_OltPortInfo:
397 return handler.getOltPortCounters(ctx, reqType.OltPortInfo), nil
398 default:
399 return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_UNSUPPORTED), nil
400 }
401 }
402
403 logger.Infow(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
404 return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE_ID), nil
405}