blob: d7e5b5a0605b5f66d9cc57ca3c6e3ffa1d9a533d [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)
Gamze Abakac2c32a62021-03-11 11:44:18 +0000186 handler.adapterPreviouslyConnected = true
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530187 oo.addDeviceHandlerToMap(handler)
188 handler.transitionMap = NewTransitionMap(handler)
npujarec5762e2020-01-01 14:08:48 +0530189 handler.transitionMap.Handle(ctx, DeviceInit)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530190 }
191 return nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400192}
193
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700194//Abandon_device unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000195func (oo *OpenOLT) Abandon_device(ctx context.Context, device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530196 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400197}
198
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700199//Disable_device disables the given device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000200func (oo *OpenOLT) Disable_device(ctx context.Context, device *voltha.Device) error {
divyadesai3af43e12020-08-18 07:10:54 +0000201 logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400202 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000203 return handler.DisableDevice(ctx, device)
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400204 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000205 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400206}
207
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700208//Reenable_device enables the olt device after disable
Neha Sharma96b7bf22020-06-15 10:37:32 +0000209func (oo *OpenOLT) Reenable_device(ctx context.Context, device *voltha.Device) error {
divyadesai3af43e12020-08-18 07:10:54 +0000210 logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400211 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000212 return handler.ReenableDevice(ctx, device)
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400213 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000214 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400215}
216
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700217//Reboot_device reboots the given device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000218func (oo *OpenOLT) Reboot_device(ctx context.Context, device *voltha.Device) error {
divyadesai3af43e12020-08-18 07:10:54 +0000219 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400220 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000221 return handler.RebootDevice(ctx, device)
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400222 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000223 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400224}
225
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700226//Self_test_device unimplented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000227func (oo *OpenOLT) Self_test_device(ctx context.Context, device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530228 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400229}
230
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700231//Delete_device unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000232func (oo *OpenOLT) Delete_device(ctx context.Context, device *voltha.Device) error {
divyadesai3af43e12020-08-18 07:10:54 +0000233 logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400234 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530235 if err := handler.DeleteDevice(ctx, device); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000236 logger.Errorw(ctx, "failed-to-handle-delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400237 }
238 oo.deleteDeviceHandlerToMap(handler)
239 return nil
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//Get_device_details unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000245func (oo *OpenOLT) Get_device_details(ctx context.Context, device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530246 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400247}
248
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700249//Update_flows_bulk returns
Neha Sharma96b7bf22020-06-15 10:37:32 +0000250func (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 +0530251 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400252}
253
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700254//Update_flows_incrementally updates (add/remove) the flows on a given device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000255func (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 -0700256 logger.Infow(ctx, "Update_flows_incrementally", log.Fields{"device-id": device.Id, "flows": flows, "flowMetadata": flowMetadata})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400257 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530258 return handler.UpdateFlowsIncrementally(ctx, device, flows, groups, flowMetadata)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400259 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000260 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//Update_pm_config returns PmConfigs nil or error
Neha Sharma96b7bf22020-06-15 10:37:32 +0000264func (oo *OpenOLT) Update_pm_config(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
265 logger.Debugw(ctx, "Update_pm_config", log.Fields{"device-id": device.Id, "pm-configs": pmConfigs})
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000266 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000267 handler.UpdatePmConfig(ctx, pmConfigs)
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000268 return nil
269 }
270 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400271}
272
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700273//Receive_packet_out sends packet out to the device
Neha Sharma96b7bf22020-06-15 10:37:32 +0000274func (oo *OpenOLT) Receive_packet_out(ctx context.Context, deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
divyadesai3af43e12020-08-18 07:10:54 +0000275 logger.Debugw(ctx, "Receive_packet_out", log.Fields{"device-id": deviceID, "egress_port_no": egressPortNo, "pkt": packet})
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700276 if handler := oo.getDeviceHandler(deviceID); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530277 return handler.PacketOut(ctx, egressPortNo, packet)
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400278 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000279 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400280}
281
Devmalya Pauldd23a992019-11-14 07:06:31 +0000282//Suppress_event unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000283func (oo *OpenOLT) Suppress_event(ctx context.Context, filter *voltha.EventFilter) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530284 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400285}
286
Devmalya Pauldd23a992019-11-14 07:06:31 +0000287//Unsuppress_event unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000288func (oo *OpenOLT) Unsuppress_event(ctx context.Context, filter *voltha.EventFilter) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530289 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400290}
291
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700292//Download_image unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000293func (oo *OpenOLT) Download_image(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//Get_image_download_status unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000298func (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 +0530299 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400300}
301
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700302//Cancel_image_download unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000303func (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 +0530304 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400305}
306
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700307//Activate_image_update unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000308func (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 +0530309 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400310}
311
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700312//Revert_image_update unimplemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000313func (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 +0530314 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400315}
kesavand39e0aa32020-01-28 20:58:50 -0500316
317// Enable_port to Enable PON/NNI interface
Neha Sharma96b7bf22020-06-15 10:37:32 +0000318func (oo *OpenOLT) Enable_port(ctx context.Context, deviceID string, port *voltha.Port) error {
divyadesai3af43e12020-08-18 07:10:54 +0000319 logger.Infow(ctx, "Enable_port", log.Fields{"device-id": deviceID, "port": port})
Neha Sharma96b7bf22020-06-15 10:37:32 +0000320 return oo.enableDisablePort(ctx, deviceID, port, true)
kesavand39e0aa32020-01-28 20:58:50 -0500321}
322
323// Disable_port to Disable pon/nni interface
Neha Sharma96b7bf22020-06-15 10:37:32 +0000324func (oo *OpenOLT) Disable_port(ctx context.Context, deviceID string, port *voltha.Port) error {
divyadesai3af43e12020-08-18 07:10:54 +0000325 logger.Infow(ctx, "Disable_port", log.Fields{"device-id": deviceID, "port": port})
Neha Sharma96b7bf22020-06-15 10:37:32 +0000326 return oo.enableDisablePort(ctx, deviceID, port, false)
kesavand39e0aa32020-01-28 20:58:50 -0500327}
328
329// enableDisablePort to Disable pon or Enable PON interface
Neha Sharma96b7bf22020-06-15 10:37:32 +0000330func (oo *OpenOLT) enableDisablePort(ctx context.Context, deviceID string, port *voltha.Port, enablePort bool) error {
divyadesai3af43e12020-08-18 07:10:54 +0000331 logger.Infow(ctx, "enableDisablePort", log.Fields{"device-id": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500332 if port == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530333 return olterrors.NewErrInvalidValue(log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800334 "reason": "port cannot be nil",
335 "device-id": deviceID,
Girish Kumarf26e4882020-03-05 06:49:10 +0000336 "port": nil}, nil)
kesavand39e0aa32020-01-28 20:58:50 -0500337 }
338 if handler := oo.getDeviceHandler(deviceID); handler != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000339 logger.Debugw(ctx, "Enable_Disable_Port", log.Fields{"device-id": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500340 if enablePort {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000341 if err := handler.EnablePort(ctx, port); err != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000342 return olterrors.NewErrAdapter("error-occurred-during-enable-port", log.Fields{"device-id": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500343 }
344 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000345 if err := handler.DisablePort(ctx, port); err != nil {
divyadesai3af43e12020-08-18 07:10:54 +0000346 return olterrors.NewErrAdapter("error-occurred-during-disable-port", log.Fields{"device-id": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500347 }
348 }
349 }
350 return nil
351}
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500352
353//Child_device_lost deletes the ONU and its references from PONResources
Girish Gowdraa0870562021-03-11 14:30:14 -0800354func (oo *OpenOLT) Child_device_lost(ctx context.Context, childDevice *voltha.Device) error {
355 logger.Infow(ctx, "Child-device-lost", log.Fields{"parent-device-id": childDevice.ParentId, "child-device-id": childDevice.Id})
356 if handler := oo.getDeviceHandler(childDevice.ParentId); handler != nil {
357 return handler.ChildDeviceLost(ctx, childDevice.ParentPortNo, childDevice.ProxyAddress.OnuId, childDevice.SerialNumber)
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500358 }
Girish Gowdraa0870562021-03-11 14:30:14 -0800359 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": childDevice.ParentId}, nil).Log()
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500360}
Scott Baker24f83e22020-03-30 16:14:28 -0700361
362//Start_omci_test not implemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000363func (oo *OpenOLT) Start_omci_test(ctx context.Context, device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
Scott Baker24f83e22020-03-30 16:14:28 -0700364 return nil, olterrors.ErrNotImplemented
365}
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800366
Andrea Campanella9931ad62020-04-28 15:11:06 +0200367//Get_ext_value retrieves a value on a particular ONU
Neha Sharma96b7bf22020-06-15 10:37:32 +0000368func (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 -0800369 var err error
370 resp := new(voltha.ReturnValues)
Girish Kumara1ea2aa2020-08-19 18:14:22 +0000371 logger.Infow(ctx, "Get_ext_value", log.Fields{"device-id": deviceID, "onu-id": device.Id})
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800372 if handler := oo.getDeviceHandler(deviceID); handler != nil {
Neha Sharma8f4e4322020-08-06 10:51:53 +0000373 if resp, err = handler.getExtValue(ctx, device, valueparam); err != nil {
Girish Kumara1ea2aa2020-08-19 18:14:22 +0000374 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 -0800375 "error": err})
376 return nil, err
377 }
378 }
379 return resp, nil
380}
kesavand62126212021-01-12 04:56:06 -0500381
382//Single_get_value_request handles get uni status on ONU and ondemand metric on OLT
383func (oo *OpenOLT) Single_get_value_request(ctx context.Context, request extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
384 logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request})
385
386 errResp := func(status extension.GetValueResponse_Status,
387 reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse {
388 return &extension.SingleGetValueResponse{
389 Response: &extension.GetValueResponse{
390 Status: status,
391 ErrReason: reason,
392 },
393 }
394 }
395 if handler := oo.getDeviceHandler(request.TargetId); handler != nil {
396 switch reqType := request.GetRequest().GetRequest().(type) {
397 case *extension.GetValueRequest_OltPortInfo:
398 return handler.getOltPortCounters(ctx, reqType.OltPortInfo), nil
399 default:
400 return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_UNSUPPORTED), nil
401 }
402 }
403
404 logger.Infow(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
405 return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE_ID), nil
406}