blob: 946cdc93cada1c78a01d06e3939aea4353a57c2b [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
2 * Copyright 2020-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 */
16
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000017//Package adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
Holger Hildebrandtfa074992020-03-27 15:42:06 +000019
20import (
21 "context"
22 "errors"
23 "fmt"
24 "sync"
25 "time"
26
27 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
mpagenkoaf801632020-07-03 10:00:42 +000028 "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000029 "github.com/opencord/voltha-lib-go/v3/pkg/kafka"
30 "github.com/opencord/voltha-lib-go/v3/pkg/log"
31 ic "github.com/opencord/voltha-protos/v3/go/inter_container"
32 "github.com/opencord/voltha-protos/v3/go/openflow_13"
33 "github.com/opencord/voltha-protos/v3/go/voltha"
34
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000035 "test.internal/openadapter/internal/pkg/config"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000036)
37
38//OpenONUAC structure holds the ONU core information
39type OpenONUAC struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053040 deviceHandlers map[string]*deviceHandler
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +000041 deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000042 lockDeviceHandlersMap sync.RWMutex
Holger Hildebrandtfa074992020-03-27 15:42:06 +000043 coreProxy adapterif.CoreProxy
44 adapterProxy adapterif.AdapterProxy
45 eventProxy adapterif.EventProxy
46 kafkaICProxy kafka.InterContainerProxy
mpagenkoaf801632020-07-03 10:00:42 +000047 kvClient kvstore.Client
Holger Hildebrandtfa074992020-03-27 15:42:06 +000048 config *config.AdapterFlags
49 numOnus int
50 KVStoreHost string
51 KVStorePort int
52 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000053 KVStoreTimeout time.Duration
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000054 mibTemplatesGenerated map[string]bool
55 lockMibTemplateGenerated sync.RWMutex
Holger Hildebrandtfa074992020-03-27 15:42:06 +000056 exitChannel chan int
57 HeartbeatCheckInterval time.Duration
58 HeartbeatFailReportInterval time.Duration
mpagenkodff5dda2020-08-28 11:52:01 +000059 AcceptIncrementalEvto bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000060 //GrpcTimeoutInterval time.Duration
Himani Chawlad96df182020-09-28 11:12:02 +053061 pSupportedFsms *OmciDeviceFsms
62 maxTimeoutInterAdapterComm time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +000063}
64
65//NewOpenONUAC returns a new instance of OpenONU_AC
66func NewOpenONUAC(ctx context.Context, kafkaICProxy kafka.InterContainerProxy,
67 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
mpagenkoaf801632020-07-03 10:00:42 +000068 eventProxy adapterif.EventProxy, kvClient kvstore.Client, cfg *config.AdapterFlags) *OpenONUAC {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000069 var openOnuAc OpenONUAC
70 openOnuAc.exitChannel = make(chan int, 1)
Himani Chawla6d2ae152020-09-02 13:11:20 +053071 openOnuAc.deviceHandlers = make(map[string]*deviceHandler)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +000072 openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000073 openOnuAc.lockDeviceHandlersMap = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +000074 openOnuAc.kafkaICProxy = kafkaICProxy
75 openOnuAc.config = cfg
76 openOnuAc.numOnus = cfg.OnuNumber
77 openOnuAc.coreProxy = coreProxy
78 openOnuAc.adapterProxy = adapterProxy
79 openOnuAc.eventProxy = eventProxy
mpagenkoaf801632020-07-03 10:00:42 +000080 openOnuAc.kvClient = kvClient
Holger Hildebrandtfa074992020-03-27 15:42:06 +000081 openOnuAc.KVStoreHost = cfg.KVStoreHost
82 openOnuAc.KVStorePort = cfg.KVStorePort
83 openOnuAc.KVStoreType = cfg.KVStoreType
mpagenkoaf801632020-07-03 10:00:42 +000084 openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000085 openOnuAc.mibTemplatesGenerated = make(map[string]bool)
86 openOnuAc.lockMibTemplateGenerated = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +000087 openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
88 openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
mpagenkodff5dda2020-08-28 11:52:01 +000089 openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto
Himani Chawlad96df182020-09-28 11:12:02 +053090 openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm
Holger Hildebrandtfa074992020-03-27 15:42:06 +000091 //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000092
93 openOnuAc.pSupportedFsms = &OmciDeviceFsms{
94 "mib-synchronizer": {
95 //mibSyncFsm, // Implements the MIB synchronization state machine
Himani Chawla6d2ae152020-09-02 13:11:20 +053096 mibDbVolatileDictImpl, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +053097 //true, // Advertise events on OpenOMCI event bus
98 cMibAuditDelayImpl, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000099 // map[string]func() error{
100 // "mib-upload": onuDeviceEntry.MibUploadTask,
101 // "mib-template": onuDeviceEntry.MibTemplateTask,
102 // "get-mds": onuDeviceEntry.GetMdsTask,
103 // "mib-audit": onuDeviceEntry.GetMdsTask,
104 // "mib-resync": onuDeviceEntry.MibResyncTask,
105 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
106 // },
107 },
108 }
109
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000110 return &openOnuAc
111}
112
113//Start starts (logs) the adapter
114func (oo *OpenONUAC) Start(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000115 logger.Info("starting-openonu-adapter")
116 logger.Info("openonu-adapter-started")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000117 return nil
118}
119
Himani Chawla6d2ae152020-09-02 13:11:20 +0530120/*
121//stop terminates the session
122func (oo *OpenONUAC) stop(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000123 logger.Info("stopping-device-manager")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000124 oo.exitChannel <- 1
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000125 logger.Info("device-manager-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000126 return nil
127}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530128*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000129
Himani Chawla6d2ae152020-09-02 13:11:20 +0530130func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000131 oo.lockDeviceHandlersMap.Lock()
132 defer oo.lockDeviceHandlersMap.Unlock()
133 if _, exist := oo.deviceHandlers[agent.deviceID]; !exist {
134 oo.deviceHandlers[agent.deviceID] = agent
Himani Chawla6d2ae152020-09-02 13:11:20 +0530135 oo.deviceHandlers[agent.deviceID].start(ctx)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000136 if _, exist := oo.deviceHandlersCreateChan[agent.deviceID]; exist {
137 logger.Debugw("deviceHandler created - trigger processing of pending ONU_IND_REQUEST", log.Fields{"device-id": agent.deviceID})
138 oo.deviceHandlersCreateChan[agent.deviceID] <- true
139 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000140 }
141}
142
Himani Chawla6d2ae152020-09-02 13:11:20 +0530143func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000144 oo.lockDeviceHandlersMap.Lock()
145 defer oo.lockDeviceHandlersMap.Unlock()
146 delete(oo.deviceHandlers, agent.deviceID)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000147 delete(oo.deviceHandlersCreateChan, agent.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000148}
149
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000150//getDeviceHandler gets the ONU deviceHandler and may wait until it is created
151func (oo *OpenONUAC) getDeviceHandler(deviceID string, aWait bool) *deviceHandler {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000152 oo.lockDeviceHandlersMap.Lock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000153 agent, ok := oo.deviceHandlers[deviceID]
154 if aWait && !ok {
155 logger.Debugw("deviceHandler not present - wait for creation or timeout", log.Fields{"device-id": deviceID})
156 if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist {
157 oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1)
158 }
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800159 deviceCreateChan := oo.deviceHandlersCreateChan[deviceID]
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000160 //keep the read sema short to allow for subsequent write
161 oo.lockDeviceHandlersMap.Unlock()
162 // based on concurrent processing the deviceHandler creation may not yet be finished at his point
163 // so it might be needed to wait here for that event with some timeout
164 select {
165 case <-time.After(1 * time.Second): //timer may be discussed ...
166 logger.Warnw("No valid deviceHandler created after max WaitTime", log.Fields{"device-id": deviceID})
167 return nil
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800168 case <-deviceCreateChan:
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000169 logger.Debugw("deviceHandler is ready now - continue", log.Fields{"device-id": deviceID})
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800170 oo.lockDeviceHandlersMap.RLock()
171 defer oo.lockDeviceHandlersMap.RUnlock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000172 return oo.deviceHandlers[deviceID]
173 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000174 }
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000175 oo.lockDeviceHandlersMap.Unlock()
176 return agent
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000177}
178
179// Adapter interface required methods ############## begin #########
180// #################################################################
181
182// for original content compare: (needs according deviceHandler methods)
183// /voltha-openolt-adapter/adaptercore/openolt.go
184
185// Adopt_device creates a new device handler if not present already and then adopts the device
186func (oo *OpenONUAC) Adopt_device(device *voltha.Device) error {
187 if device == nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000188 logger.Warn("voltha-device-is-nil")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000189 return errors.New("nil-device")
190 }
191 ctx := context.Background()
divyadesai4d299552020-08-18 07:13:49 +0000192 logger.Infow("adopt-device", log.Fields{"device-id": device.Id})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530193 var handler *deviceHandler
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000194 if handler = oo.getDeviceHandler(device.Id, false); handler == nil {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530195 handler := newDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000196 oo.addDeviceHandlerToMap(ctx, handler)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530197 go handler.adoptOrReconcileDevice(ctx, device)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000198 // Launch the creation of the device topic
199 // go oo.createDeviceTopic(device)
200 }
201 return nil
202}
203
204//Get_ofp_device_info returns OFP information for the given device
205func (oo *OpenONUAC) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) {
divyadesai4d299552020-08-18 07:13:49 +0000206 logger.Errorw("device-handler-not-set", log.Fields{"device-id": device.Id})
Andrea Campanella6515c582020-10-05 11:25:00 +0200207 return nil, fmt.Errorf("device-handler-not-set %s", device.Id)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000208}
209
210//Get_ofp_port_info returns OFP port information for the given device
mpagenkoaf801632020-07-03 10:00:42 +0000211//200630: method removed as per [VOL-3202]: OF port info is now to be delivered within UniPort create
212// cmp changes in onu_uni_port.go::CreateVolthaPort()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000213
214//Process_inter_adapter_message sends messages to a target device (between adapters)
215func (oo *OpenONUAC) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000216 logger.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id,
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000217 "msgProxyDeviceId": msg.Header.ProxyDeviceId, "msgToDeviceId": msg.Header.ToDeviceId, "Type": msg.Header.Type})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000218
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000219 var waitForDhInstPresent bool
220 //ToDeviceId should address a DeviceHandler instance
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000221 targetDevice := msg.Header.ToDeviceId
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000222 // As a workaround this handling is only required for the OnuIndication with OperState=Up event.
223 // But we live without that further check and use this processing also for OperState down/unreachable events to avoid
224 // the deeper message processing at this stage. Should do no harm on the other events (except for run time)
225 if msg.Header.Type != ic.InterAdapterMessageType_ONU_IND_REQUEST {
226 waitForDhInstPresent = false
227 } else {
228 //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core,
229 //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding
230 //ONU by RPC of Adopt_device()
231 logger.Debugw("ONU_IND_REQUEST - potentially wait until DeviceHandler instance is created", log.Fields{"device-id": targetDevice})
232 waitForDhInstPresent = true
233 }
234 if handler := oo.getDeviceHandler(targetDevice, waitForDhInstPresent); handler != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000235 /* 200724: modification towards synchronous implementation - possible errors within processing shall be
236 * in the accordingly delayed response, some timing effect might result in Techprofile processing for multiple UNI's
237 */
Himani Chawla6d2ae152020-09-02 13:11:20 +0530238 return handler.processInterAdapterMessage(msg)
mpagenko1cc3cb42020-07-27 15:24:38 +0000239 /* so far the processing has been in background with according commented error treatment restrictions:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000240 go handler.ProcessInterAdapterMessage(msg)
241 // error treatment might be more sophisticated
242 // by now let's just accept the message on 'communication layer'
243 // message content problems have to be evaluated then in the handler
244 // and are by now not reported to the calling party (to force what reaction there?)
245 return nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000246 */
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000247 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000248 logger.Warnw("no handler found for received Inter-Proxy-message", log.Fields{
249 "msgToDeviceId": targetDevice})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000250 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice))
251}
252
253//Adapter_descriptor not implemented
254func (oo *OpenONUAC) Adapter_descriptor() error {
255 return errors.New("unImplemented")
256}
257
258//Device_types unimplemented
259func (oo *OpenONUAC) Device_types() (*voltha.DeviceTypes, error) {
260 return nil, errors.New("unImplemented")
261}
262
263//Health returns unimplemented
264func (oo *OpenONUAC) Health() (*voltha.HealthStatus, error) {
265 return nil, errors.New("unImplemented")
266}
267
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000268//Reconcile_device is called once when the adapter needs to re-create device - usually on core restart
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000269func (oo *OpenONUAC) Reconcile_device(device *voltha.Device) error {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000270 if device == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000271 logger.Warn("reconcile-device-voltha-device-is-nil")
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000272 return errors.New("nil-device")
273 }
274 ctx := context.Background()
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000275 logger.Infow("reconcile-device", log.Fields{"device-id": device.Id})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530276 var handler *deviceHandler
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000277 if handler = oo.getDeviceHandler(device.Id, false); handler == nil {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530278 handler := newDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000279 oo.addDeviceHandlerToMap(ctx, handler)
280 handler.device = device
281 handler.reconciling = true
Himani Chawla6d2ae152020-09-02 13:11:20 +0530282 go handler.adoptOrReconcileDevice(ctx, handler.device)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000283 // reconcilement will be continued after onu-device entry is added
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000284 } else {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000285 return fmt.Errorf(fmt.Sprintf("device-already-reconciled-or-active-%s", device.Id))
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000286 }
287 return nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000288}
289
290//Abandon_device unimplemented
291func (oo *OpenONUAC) Abandon_device(device *voltha.Device) error {
292 return errors.New("unImplemented")
293}
294
295//Disable_device disables the given device
296func (oo *OpenONUAC) Disable_device(device *voltha.Device) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000297 logger.Infow("disable-device", log.Fields{"device-id": device.Id})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000298 if handler := oo.getDeviceHandler(device.Id, false); handler != nil {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530299 go handler.disableDevice(device)
ozgecanetsiafce57b12020-05-25 14:39:35 +0300300 return nil
301 }
divyadesai4d299552020-08-18 07:13:49 +0000302 logger.Warnw("no handler found for device-disable", log.Fields{"device-id": device.Id})
ozgecanetsiafce57b12020-05-25 14:39:35 +0300303 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000304}
305
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000306//Reenable_device enables the onu device after disable
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000307func (oo *OpenONUAC) Reenable_device(device *voltha.Device) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000308 logger.Infow("reenable-device", log.Fields{"device-id": device.Id})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000309 if handler := oo.getDeviceHandler(device.Id, false); handler != nil {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530310 go handler.reEnableDevice(device)
ozgecanetsiafce57b12020-05-25 14:39:35 +0300311 return nil
312 }
divyadesai4d299552020-08-18 07:13:49 +0000313 logger.Warnw("no handler found for device-reenable", log.Fields{"device-id": device.Id})
ozgecanetsiafce57b12020-05-25 14:39:35 +0300314 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000315}
316
317//Reboot_device reboots the given device
318func (oo *OpenONUAC) Reboot_device(device *voltha.Device) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000319 logger.Infow("reboot-device", log.Fields{"device-id": device.Id})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000320 if handler := oo.getDeviceHandler(device.Id, false); handler != nil {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530321 go handler.rebootDevice(device)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300322 return nil
323 }
divyadesai4d299552020-08-18 07:13:49 +0000324 logger.Warnw("no handler found for device-reboot", log.Fields{"device-id": device.Id})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300325 return fmt.Errorf(fmt.Sprintf("handler-not-found-#{device.Id}"))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000326}
327
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000328//Self_test_device unimplemented
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000329func (oo *OpenONUAC) Self_test_device(device *voltha.Device) error {
330 return errors.New("unImplemented")
331}
332
Himani Chawla6d2ae152020-09-02 13:11:20 +0530333// Delete_device deletes the given device
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000334func (oo *OpenONUAC) Delete_device(device *voltha.Device) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000335 logger.Infow("delete-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000336 if handler := oo.getDeviceHandler(device.Id, false); handler != nil {
mpagenko2418ab02020-11-12 12:58:06 +0000337 err := handler.deleteDevicePersistencyData()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000338 //don't leave any garbage - even in error case
339 oo.deleteDeviceHandlerToMap(handler)
mpagenko2418ab02020-11-12 12:58:06 +0000340 return err
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000341 }
mpagenko2418ab02020-11-12 12:58:06 +0000342 logger.Warnw("no handler found for device-deletion", log.Fields{"device-id": device.Id})
343 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000344}
345
346//Get_device_details unimplemented
347func (oo *OpenONUAC) Get_device_details(device *voltha.Device) error {
348 return errors.New("unImplemented")
349}
350
351//Update_flows_bulk returns
352func (oo *OpenONUAC) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error {
353 return errors.New("unImplemented")
354}
355
356//Update_flows_incrementally updates (add/remove) the flows on a given device
mpagenkodff5dda2020-08-28 11:52:01 +0000357func (oo *OpenONUAC) Update_flows_incrementally(device *voltha.Device,
358 flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error {
mpagenkofc4f56e2020-11-04 17:17:49 +0000359
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000360 logger.Infow("update-flows-incrementally", log.Fields{"device-id": device.Id})
mpagenkofc4f56e2020-11-04 17:17:49 +0000361 //flow config is relayed to handler even if the device might be in some 'inactive' state
362 // let the handler or related FSM's decide, what to do with the modified flow state info
363 // at least the flow-remove must be done in respect to internal data, while OMCI activity might not be needed here
mpagenkodff5dda2020-08-28 11:52:01 +0000364
365 // For now, there is no support for group changes (as in the actual Py-adapter code)
mpagenkofc4f56e2020-11-04 17:17:49 +0000366 // but processing is continued for flowUpdate possibly also set in the request
mpagenkodff5dda2020-08-28 11:52:01 +0000367 if groups.ToAdd != nil && groups.ToAdd.Items != nil {
mpagenkofc4f56e2020-11-04 17:17:49 +0000368 logger.Warnw("Update-flow-incr: group add not supported (ignored)", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000369 }
370 if groups.ToRemove != nil && groups.ToRemove.Items != nil {
mpagenkofc4f56e2020-11-04 17:17:49 +0000371 logger.Warnw("Update-flow-incr: group remove not supported (ignored)", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000372 }
373 if groups.ToUpdate != nil && groups.ToUpdate.Items != nil {
mpagenkofc4f56e2020-11-04 17:17:49 +0000374 logger.Warnw("Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000375 }
376
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000377 if handler := oo.getDeviceHandler(device.Id, false); handler != nil {
mpagenkodff5dda2020-08-28 11:52:01 +0000378 err := handler.FlowUpdateIncremental(flows, groups, flowMetadata)
379 return err
380 }
mpagenkofc4f56e2020-11-04 17:17:49 +0000381 logger.Warnw("no handler found for incremental flow update", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000382 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000383}
384
385//Update_pm_config returns PmConfigs nil or error
386func (oo *OpenONUAC) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
387 return errors.New("unImplemented")
388}
389
390//Receive_packet_out sends packet out to the device
391func (oo *OpenONUAC) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
392 return errors.New("unImplemented")
393}
394
395//Suppress_event unimplemented
396func (oo *OpenONUAC) Suppress_event(filter *voltha.EventFilter) error {
397 return errors.New("unImplemented")
398}
399
400//Unsuppress_event unimplemented
401func (oo *OpenONUAC) Unsuppress_event(filter *voltha.EventFilter) error {
402 return errors.New("unImplemented")
403}
404
405//Download_image unimplemented
406func (oo *OpenONUAC) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
407 return nil, errors.New("unImplemented")
408}
409
410//Get_image_download_status unimplemented
411func (oo *OpenONUAC) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
412 return nil, errors.New("unImplemented")
413}
414
415//Cancel_image_download unimplemented
416func (oo *OpenONUAC) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
417 return nil, errors.New("unImplemented")
418}
419
420//Activate_image_update unimplemented
421func (oo *OpenONUAC) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
422 return nil, errors.New("unImplemented")
423}
424
425//Revert_image_update unimplemented
426func (oo *OpenONUAC) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
427 return nil, errors.New("unImplemented")
428}
429
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000430// Enable_port to Enable PON/NNI interface - seems not to be used/required according to python code
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000431func (oo *OpenONUAC) Enable_port(deviceID string, port *voltha.Port) error {
432 return errors.New("unImplemented")
433}
434
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000435// Disable_port to Disable pon/nni interface - seems not to be used/required according to python code
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000436func (oo *OpenONUAC) Disable_port(deviceID string, port *voltha.Port) error {
437 return errors.New("unImplemented")
438}
439
Himani Chawla6d2ae152020-09-02 13:11:20 +0530440//Child_device_lost - unimplemented
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000441//needed for if update >= 3.1.x
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700442func (oo *OpenONUAC) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error {
443 return errors.New("unImplemented")
444}
445
Himani Chawla6d2ae152020-09-02 13:11:20 +0530446// Start_omci_test unimplemented
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700447func (oo *OpenONUAC) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
448 return nil, errors.New("unImplemented")
449}
450
Himani Chawla6d2ae152020-09-02 13:11:20 +0530451// Get_ext_value - unimplemented
Matteo Scandolod132c0e2020-04-24 17:06:25 -0700452func (oo *OpenONUAC) Get_ext_value(deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) {
453 return nil, errors.New("unImplemented")
454}
455
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000456// Adapter interface required methods ################ end #########
457// #################################################################