blob: 3704945ee6294f310eea0b9ceafeaa05dd45f84e [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//Get_ofp_port_info returns OFP port information for the given device
165func (oo *OpenOLT) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000166 logger.Infow("Get_ofp_port_info", log.Fields{"deviceId": device.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400167 if handler := oo.getDeviceHandler(device.Id); handler != nil {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700168 return handler.GetOfpPortInfo(device, portNo)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400169 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000170 return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400171}
172
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700173//Process_inter_adapter_message sends messages to a target device (between adapters)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400174func (oo *OpenOLT) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error {
Andrea Campanella9931ad62020-04-28 15:11:06 +0200175 logger.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400176 targetDevice := msg.Header.ProxyDeviceId // Request?
177 if targetDevice == "" && msg.Header.ToDeviceId != "" {
178 // Typical response
179 targetDevice = msg.Header.ToDeviceId
180 }
181 if handler := oo.getDeviceHandler(targetDevice); handler != nil {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700182 return handler.ProcessInterAdapterMessage(msg)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400183 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000184 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": targetDevice}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400185}
186
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700187//Adapter_descriptor not implemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400188func (oo *OpenOLT) Adapter_descriptor() error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530189 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400190}
191
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700192//Device_types unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400193func (oo *OpenOLT) Device_types() (*voltha.DeviceTypes, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530194 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400195}
196
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700197//Health returns unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400198func (oo *OpenOLT) Health() (*voltha.HealthStatus, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530199 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400200}
201
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700202//Reconcile_device unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400203func (oo *OpenOLT) Reconcile_device(device *voltha.Device) error {
npujarec5762e2020-01-01 14:08:48 +0530204 ctx := context.Background()
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530205 if device == nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000206 return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530207 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000208 logger.Infow("reconcile-device", log.Fields{"deviceId": device.Id})
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530209 var handler *DeviceHandler
210 if handler = oo.getDeviceHandler(device.Id); handler == nil {
211 handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
212 oo.addDeviceHandlerToMap(handler)
213 handler.transitionMap = NewTransitionMap(handler)
npujarec5762e2020-01-01 14:08:48 +0530214 handler.transitionMap.Handle(ctx, DeviceInit)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530215 }
216 return nil
Girish Gowdru0c588b22019-04-23 23:24:56 -0400217}
218
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700219//Abandon_device unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400220func (oo *OpenOLT) Abandon_device(device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530221 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400222}
223
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700224//Disable_device disables the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400225func (oo *OpenOLT) Disable_device(device *voltha.Device) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000226 logger.Infow("disable-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.DisableDevice(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//Reenable_device enables the olt device after disable
Girish Gowdru0c588b22019-04-23 23:24:56 -0400234func (oo *OpenOLT) Reenable_device(device *voltha.Device) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000235 logger.Infow("reenable-device", log.Fields{"deviceId": device.Id})
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400236 if handler := oo.getDeviceHandler(device.Id); handler != nil {
237 return handler.ReenableDevice(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//Reboot_device reboots the given device
Girish Gowdru0c588b22019-04-23 23:24:56 -0400243func (oo *OpenOLT) Reboot_device(device *voltha.Device) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000244 logger.Infow("reboot-device", log.Fields{"deviceId": device.Id})
Girish Gowdru0fe5f7e2019-05-28 05:12:27 -0400245 if handler := oo.getDeviceHandler(device.Id); handler != nil {
246 return handler.RebootDevice(device)
247 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000248 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400249}
250
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700251//Self_test_device unimplented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400252func (oo *OpenOLT) Self_test_device(device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530253 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400254}
255
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700256//Delete_device unimplemented
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400257func (oo *OpenOLT) Delete_device(device *voltha.Device) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000258 logger.Infow("delete-device", log.Fields{"deviceId": device.Id})
npujarec5762e2020-01-01 14:08:48 +0530259 ctx := context.Background()
Devmalya Paul495b94a2019-08-27 19:42:00 -0400260 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530261 if err := handler.DeleteDevice(ctx, device); err != nil {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000262 logger.Errorw("failed-to-handle-delete-device", log.Fields{"device-id": device.Id})
Devmalya Paul495b94a2019-08-27 19:42:00 -0400263 }
264 oo.deleteDeviceHandlerToMap(handler)
265 return nil
266 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000267 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400268}
269
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700270//Get_device_details unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400271func (oo *OpenOLT) Get_device_details(device *voltha.Device) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530272 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400273}
274
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700275//Update_flows_bulk returns
Manikkaraj kb1d51442019-07-23 10:41:02 -0400276func (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 +0530277 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400278}
279
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700280//Update_flows_incrementally updates (add/remove) the flows on a given device
Manikkaraj kb1d51442019-07-23 10:41:02 -0400281func (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 +0000282 logger.Debugw("Update_flows_incrementally", log.Fields{"deviceId": device.Id, "flows": flows, "flowMetadata": flowMetadata})
npujarec5762e2020-01-01 14:08:48 +0530283 ctx := context.Background()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400284 if handler := oo.getDeviceHandler(device.Id); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530285 return handler.UpdateFlowsIncrementally(ctx, device, flows, groups, flowMetadata)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400286 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000287 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400288}
289
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700290//Update_pm_config returns PmConfigs nil or error
291func (oo *OpenOLT) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000292 logger.Debugw("Update_pm_config", log.Fields{"device-id": device.Id, "pm-configs": pmConfigs})
293 if handler := oo.getDeviceHandler(device.Id); handler != nil {
294 handler.UpdatePmConfig(pmConfigs)
295 return nil
296 }
297 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400298}
299
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700300//Receive_packet_out sends packet out to the device
301func (oo *OpenOLT) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000302 logger.Debugw("Receive_packet_out", log.Fields{"deviceId": deviceID, "egress_port_no": egressPortNo, "pkt": packet})
npujarec5762e2020-01-01 14:08:48 +0530303 ctx := context.Background()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700304 if handler := oo.getDeviceHandler(deviceID); handler != nil {
npujarec5762e2020-01-01 14:08:48 +0530305 return handler.PacketOut(ctx, egressPortNo, packet)
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400306 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000307 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400308}
309
Devmalya Pauldd23a992019-11-14 07:06:31 +0000310//Suppress_event unimplemented
311func (oo *OpenOLT) Suppress_event(filter *voltha.EventFilter) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530312 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400313}
314
Devmalya Pauldd23a992019-11-14 07:06:31 +0000315//Unsuppress_event unimplemented
316func (oo *OpenOLT) Unsuppress_event(filter *voltha.EventFilter) error {
Thomas Lee S94109f12020-03-03 16:39:29 +0530317 return olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400318}
319
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700320//Download_image unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400321func (oo *OpenOLT) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530322 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400323}
324
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700325//Get_image_download_status unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400326func (oo *OpenOLT) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530327 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400328}
329
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700330//Cancel_image_download unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400331func (oo *OpenOLT) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530332 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400333}
334
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700335//Activate_image_update unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400336func (oo *OpenOLT) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530337 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400338}
339
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700340//Revert_image_update unimplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400341func (oo *OpenOLT) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530342 return nil, olterrors.ErrNotImplemented
Girish Gowdru0c588b22019-04-23 23:24:56 -0400343}
kesavand39e0aa32020-01-28 20:58:50 -0500344
345// Enable_port to Enable PON/NNI interface
346func (oo *OpenOLT) Enable_port(deviceID string, port *voltha.Port) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000347 logger.Infow("Enable_port", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500348 return oo.enableDisablePort(deviceID, port, true)
349}
350
351// Disable_port to Disable pon/nni interface
352func (oo *OpenOLT) Disable_port(deviceID string, port *voltha.Port) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000353 logger.Infow("Disable_port", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500354 return oo.enableDisablePort(deviceID, port, false)
355}
356
357// enableDisablePort to Disable pon or Enable PON interface
358func (oo *OpenOLT) enableDisablePort(deviceID string, port *voltha.Port, enablePort bool) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000359 logger.Infow("enableDisablePort", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500360 if port == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530361 return olterrors.NewErrInvalidValue(log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800362 "reason": "port cannot be nil",
363 "device-id": deviceID,
Girish Kumarf26e4882020-03-05 06:49:10 +0000364 "port": nil}, nil)
kesavand39e0aa32020-01-28 20:58:50 -0500365 }
366 if handler := oo.getDeviceHandler(deviceID); handler != nil {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000367 logger.Debugw("Enable_Disable_Port", log.Fields{"deviceId": deviceID, "port": port})
kesavand39e0aa32020-01-28 20:58:50 -0500368 if enablePort {
369 if err := handler.EnablePort(port); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000370 return olterrors.NewErrAdapter("error-occurred-during-enable-port", log.Fields{"deviceID": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500371 }
372 } else {
373 if err := handler.DisablePort(port); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000374 return olterrors.NewErrAdapter("error-occurred-during-disable-port", log.Fields{"deviceID": deviceID, "port": port}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500375 }
376 }
377 }
378 return nil
379}
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500380
381//Child_device_lost deletes the ONU and its references from PONResources
382func (oo *OpenOLT) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000383 logger.Infow("Child-device-lost", log.Fields{"parentId": deviceID})
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500384 ctx := context.Background()
385 if handler := oo.getDeviceHandler(deviceID); handler != nil {
386 return handler.ChildDeviceLost(ctx, pPortNo, onuID)
387 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530388 return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil).Log()
Chaitrashree G S1a55b882020-02-04 17:35:35 -0500389}
Scott Baker24f83e22020-03-30 16:14:28 -0700390
391//Start_omci_test not implemented
392func (oo *OpenOLT) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
393 return nil, olterrors.ErrNotImplemented
394}
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800395
Andrea Campanella9931ad62020-04-28 15:11:06 +0200396//Get_ext_value retrieves a value on a particular ONU
Dinesh Belwalkardb587af2020-02-27 15:37:16 -0800397func (oo *OpenOLT) Get_ext_value(deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) {
398 var err error
399 resp := new(voltha.ReturnValues)
400 log.Infow("Get_ext_value", log.Fields{"device-id": deviceID, "onu-id": device.Id})
401 if handler := oo.getDeviceHandler(deviceID); handler != nil {
402 if resp, err = handler.getExtValue(device, valueparam); err != nil {
403 log.Errorw("error-occurred-during-get-ext-value", log.Fields{"device-id": deviceID, "onu-id": device.Id,
404 "error": err})
405 return nil, err
406 }
407 }
408 return resp, nil
409}