blob: fae314407a1623f34f58a0ab1f8420fb8c666a4b [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 {
40 deviceHandlers map[string]*DeviceHandler
41 coreProxy adapterif.CoreProxy
42 adapterProxy adapterif.AdapterProxy
43 eventProxy adapterif.EventProxy
44 kafkaICProxy kafka.InterContainerProxy
mpagenkoaf801632020-07-03 10:00:42 +000045 kvClient kvstore.Client
Holger Hildebrandtfa074992020-03-27 15:42:06 +000046 config *config.AdapterFlags
47 numOnus int
48 KVStoreHost string
49 KVStorePort int
50 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000051 KVStoreTimeout time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +000052 exitChannel chan int
53 HeartbeatCheckInterval time.Duration
54 HeartbeatFailReportInterval time.Duration
55 //GrpcTimeoutInterval time.Duration
56 lockDeviceHandlersMap sync.RWMutex
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000057 pSupportedFsms *OmciDeviceFsms
Holger Hildebrandtfa074992020-03-27 15:42:06 +000058}
59
60//NewOpenONUAC returns a new instance of OpenONU_AC
61func NewOpenONUAC(ctx context.Context, kafkaICProxy kafka.InterContainerProxy,
62 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
mpagenkoaf801632020-07-03 10:00:42 +000063 eventProxy adapterif.EventProxy, kvClient kvstore.Client, cfg *config.AdapterFlags) *OpenONUAC {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000064 var openOnuAc OpenONUAC
65 openOnuAc.exitChannel = make(chan int, 1)
66 openOnuAc.deviceHandlers = make(map[string]*DeviceHandler)
67 openOnuAc.kafkaICProxy = kafkaICProxy
68 openOnuAc.config = cfg
69 openOnuAc.numOnus = cfg.OnuNumber
70 openOnuAc.coreProxy = coreProxy
71 openOnuAc.adapterProxy = adapterProxy
72 openOnuAc.eventProxy = eventProxy
mpagenkoaf801632020-07-03 10:00:42 +000073 openOnuAc.kvClient = kvClient
Holger Hildebrandtfa074992020-03-27 15:42:06 +000074 openOnuAc.KVStoreHost = cfg.KVStoreHost
75 openOnuAc.KVStorePort = cfg.KVStorePort
76 openOnuAc.KVStoreType = cfg.KVStoreType
mpagenkoaf801632020-07-03 10:00:42 +000077 openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout
Holger Hildebrandtfa074992020-03-27 15:42:06 +000078 openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
79 openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
80 //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
81 openOnuAc.lockDeviceHandlersMap = sync.RWMutex{}
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000082
83 openOnuAc.pSupportedFsms = &OmciDeviceFsms{
84 "mib-synchronizer": {
85 //mibSyncFsm, // Implements the MIB synchronization state machine
86 MibDbVolatileDictImpl, // Implements volatile ME MIB database
87 true, // Advertise events on OpenOMCI event bus
88 cMibAuditDelayImpl, // Time to wait between MIB audits. 0 to disable audits.
89 // map[string]func() error{
90 // "mib-upload": onuDeviceEntry.MibUploadTask,
91 // "mib-template": onuDeviceEntry.MibTemplateTask,
92 // "get-mds": onuDeviceEntry.GetMdsTask,
93 // "mib-audit": onuDeviceEntry.GetMdsTask,
94 // "mib-resync": onuDeviceEntry.MibResyncTask,
95 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
96 // },
97 },
98 }
99
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000100 return &openOnuAc
101}
102
103//Start starts (logs) the adapter
104func (oo *OpenONUAC) Start(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000105 logger.Info("starting-openonu-adapter")
106 logger.Info("openonu-adapter-started")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000107 return nil
108}
109
110//Stop terminates the session
111func (oo *OpenONUAC) Stop(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000112 logger.Info("stopping-device-manager")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000113 oo.exitChannel <- 1
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000114 logger.Info("device-manager-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000115 return nil
116}
117
118func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *DeviceHandler) {
119 oo.lockDeviceHandlersMap.Lock()
120 defer oo.lockDeviceHandlersMap.Unlock()
121 if _, exist := oo.deviceHandlers[agent.deviceID]; !exist {
122 oo.deviceHandlers[agent.deviceID] = agent
123 oo.deviceHandlers[agent.deviceID].Start(ctx)
124 }
125}
126
127func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *DeviceHandler) {
128 oo.lockDeviceHandlersMap.Lock()
129 defer oo.lockDeviceHandlersMap.Unlock()
130 delete(oo.deviceHandlers, agent.deviceID)
131}
132
133func (oo *OpenONUAC) getDeviceHandler(deviceID string) *DeviceHandler {
134 oo.lockDeviceHandlersMap.Lock()
135 defer oo.lockDeviceHandlersMap.Unlock()
136 if agent, ok := oo.deviceHandlers[deviceID]; ok {
137 return agent
138 }
139 return nil
140}
141
142// Adapter interface required methods ############## begin #########
143// #################################################################
144
145// for original content compare: (needs according deviceHandler methods)
146// /voltha-openolt-adapter/adaptercore/openolt.go
147
148// Adopt_device creates a new device handler if not present already and then adopts the device
149func (oo *OpenONUAC) Adopt_device(device *voltha.Device) error {
150 if device == nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000151 logger.Warn("voltha-device-is-nil")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000152 return errors.New("nil-device")
153 }
154 ctx := context.Background()
divyadesai4d299552020-08-18 07:13:49 +0000155 logger.Infow("adopt-device", log.Fields{"device-id": device.Id})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000156 var handler *DeviceHandler
157 if handler = oo.getDeviceHandler(device.Id); handler == nil {
158 handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
159 oo.addDeviceHandlerToMap(ctx, handler)
160 go handler.AdoptDevice(ctx, device)
161 // Launch the creation of the device topic
162 // go oo.createDeviceTopic(device)
163 }
164 return nil
165}
166
167//Get_ofp_device_info returns OFP information for the given device
168func (oo *OpenONUAC) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) {
divyadesai4d299552020-08-18 07:13:49 +0000169 logger.Errorw("device-handler-not-set", log.Fields{"device-id": device.Id})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000170 return nil, errors.New("device-handler-not-set")
171}
172
173//Get_ofp_port_info returns OFP port information for the given device
mpagenkoaf801632020-07-03 10:00:42 +0000174//200630: method removed as per [VOL-3202]: OF port info is now to be delivered within UniPort create
175// cmp changes in onu_uni_port.go::CreateVolthaPort()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000176
177//Process_inter_adapter_message sends messages to a target device (between adapters)
178func (oo *OpenONUAC) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000179 logger.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000180 "msgProxyDeviceId": msg.Header.ProxyDeviceId, "msgToDeviceId": msg.Header.ToDeviceId})
181
182 targetDevice := msg.Header.ToDeviceId
183 //ToDeviceId should address an DeviceHandler instance
184 if handler := oo.getDeviceHandler(targetDevice); handler != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000185 /* 200724: modification towards synchronous implementation - possible errors within processing shall be
186 * in the accordingly delayed response, some timing effect might result in Techprofile processing for multiple UNI's
187 */
188 return handler.ProcessInterAdapterMessage(msg)
189 /* so far the processing has been in background with according commented error treatment restrictions:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000190 go handler.ProcessInterAdapterMessage(msg)
191 // error treatment might be more sophisticated
192 // by now let's just accept the message on 'communication layer'
193 // message content problems have to be evaluated then in the handler
194 // and are by now not reported to the calling party (to force what reaction there?)
195 return nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000196 */
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000197 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000198 logger.Warnw("no handler found for received Inter-Proxy-message", log.Fields{
199 "msgToDeviceId": targetDevice})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000200 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice))
201}
202
203//Adapter_descriptor not implemented
204func (oo *OpenONUAC) Adapter_descriptor() error {
205 return errors.New("unImplemented")
206}
207
208//Device_types unimplemented
209func (oo *OpenONUAC) Device_types() (*voltha.DeviceTypes, error) {
210 return nil, errors.New("unImplemented")
211}
212
213//Health returns unimplemented
214func (oo *OpenONUAC) Health() (*voltha.HealthStatus, error) {
215 return nil, errors.New("unImplemented")
216}
217
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000218//Reconcile_device is called once when the adapter needs to re-create device - usually on core restart
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000219func (oo *OpenONUAC) Reconcile_device(device *voltha.Device) error {
divyadesai4d299552020-08-18 07:13:49 +0000220 logger.Debugw("Reconcile_device", log.Fields{"device-id": device.Id})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000221 if handler := oo.getDeviceHandler(device.Id); handler != nil {
222 if err := handler.ReconcileDevice(device); err != nil {
223 return err
224 }
225 } else {
divyadesai4d299552020-08-18 07:13:49 +0000226 logger.Warnw("no handler found for device-reconcilement", log.Fields{"device-id": device.Id})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000227 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
228 }
229 return nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000230}
231
232//Abandon_device unimplemented
233func (oo *OpenONUAC) Abandon_device(device *voltha.Device) error {
234 return errors.New("unImplemented")
235}
236
237//Disable_device disables the given device
238func (oo *OpenONUAC) Disable_device(device *voltha.Device) error {
divyadesai4d299552020-08-18 07:13:49 +0000239 logger.Debugw("Disable_device", log.Fields{"device-id": device.Id})
ozgecanetsiafce57b12020-05-25 14:39:35 +0300240 if handler := oo.getDeviceHandler(device.Id); handler != nil {
241 go handler.DisableDevice(device)
242 return nil
243 }
divyadesai4d299552020-08-18 07:13:49 +0000244 logger.Warnw("no handler found for device-disable", log.Fields{"device-id": device.Id})
ozgecanetsiafce57b12020-05-25 14:39:35 +0300245 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000246}
247
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000248//Reenable_device enables the onu device after disable
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000249func (oo *OpenONUAC) Reenable_device(device *voltha.Device) error {
divyadesai4d299552020-08-18 07:13:49 +0000250 logger.Debugw("Reenable_device", log.Fields{"device-id": device.Id})
ozgecanetsiafce57b12020-05-25 14:39:35 +0300251 if handler := oo.getDeviceHandler(device.Id); handler != nil {
252 go handler.ReenableDevice(device)
253 return nil
254 }
divyadesai4d299552020-08-18 07:13:49 +0000255 logger.Warnw("no handler found for device-reenable", log.Fields{"device-id": device.Id})
ozgecanetsiafce57b12020-05-25 14:39:35 +0300256 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000257}
258
259//Reboot_device reboots the given device
260func (oo *OpenONUAC) Reboot_device(device *voltha.Device) error {
divyadesai4d299552020-08-18 07:13:49 +0000261 logger.Debugw("Reboot-device", log.Fields{"device-id": device.Id})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300262 if handler := oo.getDeviceHandler(device.Id); handler != nil {
263 go handler.RebootDevice(device)
264 return nil
265 }
divyadesai4d299552020-08-18 07:13:49 +0000266 logger.Warnw("no handler found for device-reboot", log.Fields{"device-id": device.Id})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300267 return fmt.Errorf(fmt.Sprintf("handler-not-found-#{device.Id}"))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000268}
269
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000270//Self_test_device unimplemented
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000271func (oo *OpenONUAC) Self_test_device(device *voltha.Device) error {
272 return errors.New("unImplemented")
273}
274
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000275func (oo *OpenONUAC) Delete_device(device *voltha.Device) error {
divyadesai4d299552020-08-18 07:13:49 +0000276 logger.Debugw("Delete_device", log.Fields{"device-id": device.Id})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000277 if handler := oo.getDeviceHandler(device.Id); handler != nil {
278 if err := handler.DeleteDevice(device); err != nil {
279 return err
280 }
281 } else {
divyadesai4d299552020-08-18 07:13:49 +0000282 logger.Warnw("no handler found for device-reconcilement", log.Fields{"device-id": device.Id})
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000283 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
284 }
285 return nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000286}
287
288//Get_device_details unimplemented
289func (oo *OpenONUAC) Get_device_details(device *voltha.Device) error {
290 return errors.New("unImplemented")
291}
292
293//Update_flows_bulk returns
294func (oo *OpenONUAC) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error {
295 return errors.New("unImplemented")
296}
297
298//Update_flows_incrementally updates (add/remove) the flows on a given device
299func (oo *OpenONUAC) Update_flows_incrementally(device *voltha.Device, flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error {
mpagenko3dbcdd22020-07-22 07:38:45 +0000300 // return errors.New("unImplemented")
301 // testwise: just acknowledge to see, if that avoids ongoing TechProfile config sequences ...
302 return nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000303}
304
305//Update_pm_config returns PmConfigs nil or error
306func (oo *OpenONUAC) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
307 return errors.New("unImplemented")
308}
309
310//Receive_packet_out sends packet out to the device
311func (oo *OpenONUAC) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
312 return errors.New("unImplemented")
313}
314
315//Suppress_event unimplemented
316func (oo *OpenONUAC) Suppress_event(filter *voltha.EventFilter) error {
317 return errors.New("unImplemented")
318}
319
320//Unsuppress_event unimplemented
321func (oo *OpenONUAC) Unsuppress_event(filter *voltha.EventFilter) error {
322 return errors.New("unImplemented")
323}
324
325//Download_image unimplemented
326func (oo *OpenONUAC) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
327 return nil, errors.New("unImplemented")
328}
329
330//Get_image_download_status unimplemented
331func (oo *OpenONUAC) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
332 return nil, errors.New("unImplemented")
333}
334
335//Cancel_image_download unimplemented
336func (oo *OpenONUAC) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
337 return nil, errors.New("unImplemented")
338}
339
340//Activate_image_update unimplemented
341func (oo *OpenONUAC) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
342 return nil, errors.New("unImplemented")
343}
344
345//Revert_image_update unimplemented
346func (oo *OpenONUAC) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
347 return nil, errors.New("unImplemented")
348}
349
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000350// Enable_port to Enable PON/NNI interface - seems not to be used/required according to python code
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000351func (oo *OpenONUAC) Enable_port(deviceID string, port *voltha.Port) error {
352 return errors.New("unImplemented")
353}
354
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000355// Disable_port to Disable pon/nni interface - seems not to be used/required according to python code
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000356func (oo *OpenONUAC) Disable_port(deviceID string, port *voltha.Port) error {
357 return errors.New("unImplemented")
358}
359
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000360//needed for if update >= 3.1.x
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700361func (oo *OpenONUAC) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error {
362 return errors.New("unImplemented")
363}
364
365func (oo *OpenONUAC) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
366 return nil, errors.New("unImplemented")
367}
368
Matteo Scandolod132c0e2020-04-24 17:06:25 -0700369func (oo *OpenONUAC) Get_ext_value(deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) {
370 return nil, errors.New("unImplemented")
371}
372
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000373// Adapter interface required methods ################ end #########
374// #################################################################