blob: 255af1d74fde626218e8eeff0556029b609b2286 [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"
28 "github.com/opencord/voltha-lib-go/v3/pkg/kafka"
29 "github.com/opencord/voltha-lib-go/v3/pkg/log"
30 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"
33
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000034 "test.internal/openadapter/internal/pkg/config"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000035)
36
37//OpenONUAC structure holds the ONU core information
38type OpenONUAC struct {
39 deviceHandlers map[string]*DeviceHandler
40 coreProxy adapterif.CoreProxy
41 adapterProxy adapterif.AdapterProxy
42 eventProxy adapterif.EventProxy
43 kafkaICProxy kafka.InterContainerProxy
44 config *config.AdapterFlags
45 numOnus int
46 KVStoreHost string
47 KVStorePort int
48 KVStoreType string
49 exitChannel chan int
50 HeartbeatCheckInterval time.Duration
51 HeartbeatFailReportInterval time.Duration
52 //GrpcTimeoutInterval time.Duration
53 lockDeviceHandlersMap sync.RWMutex
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000054 pSupportedFsms *OmciDeviceFsms
Holger Hildebrandtfa074992020-03-27 15:42:06 +000055}
56
57//NewOpenONUAC returns a new instance of OpenONU_AC
58func NewOpenONUAC(ctx context.Context, kafkaICProxy kafka.InterContainerProxy,
59 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
60 eventProxy adapterif.EventProxy, cfg *config.AdapterFlags) *OpenONUAC {
61 var openOnuAc OpenONUAC
62 openOnuAc.exitChannel = make(chan int, 1)
63 openOnuAc.deviceHandlers = make(map[string]*DeviceHandler)
64 openOnuAc.kafkaICProxy = kafkaICProxy
65 openOnuAc.config = cfg
66 openOnuAc.numOnus = cfg.OnuNumber
67 openOnuAc.coreProxy = coreProxy
68 openOnuAc.adapterProxy = adapterProxy
69 openOnuAc.eventProxy = eventProxy
70 openOnuAc.KVStoreHost = cfg.KVStoreHost
71 openOnuAc.KVStorePort = cfg.KVStorePort
72 openOnuAc.KVStoreType = cfg.KVStoreType
73 openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
74 openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
75 //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
76 openOnuAc.lockDeviceHandlersMap = sync.RWMutex{}
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000077
78 openOnuAc.pSupportedFsms = &OmciDeviceFsms{
79 "mib-synchronizer": {
80 //mibSyncFsm, // Implements the MIB synchronization state machine
81 MibDbVolatileDictImpl, // Implements volatile ME MIB database
82 true, // Advertise events on OpenOMCI event bus
83 cMibAuditDelayImpl, // Time to wait between MIB audits. 0 to disable audits.
84 // map[string]func() error{
85 // "mib-upload": onuDeviceEntry.MibUploadTask,
86 // "mib-template": onuDeviceEntry.MibTemplateTask,
87 // "get-mds": onuDeviceEntry.GetMdsTask,
88 // "mib-audit": onuDeviceEntry.GetMdsTask,
89 // "mib-resync": onuDeviceEntry.MibResyncTask,
90 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
91 // },
92 },
93 }
94
Holger Hildebrandtfa074992020-03-27 15:42:06 +000095 return &openOnuAc
96}
97
98//Start starts (logs) the adapter
99func (oo *OpenONUAC) Start(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000100 logger.Info("starting-openonu-adapter")
101 logger.Info("openonu-adapter-started")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000102 return nil
103}
104
105//Stop terminates the session
106func (oo *OpenONUAC) Stop(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000107 logger.Info("stopping-device-manager")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000108 oo.exitChannel <- 1
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000109 logger.Info("device-manager-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000110 return nil
111}
112
113func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *DeviceHandler) {
114 oo.lockDeviceHandlersMap.Lock()
115 defer oo.lockDeviceHandlersMap.Unlock()
116 if _, exist := oo.deviceHandlers[agent.deviceID]; !exist {
117 oo.deviceHandlers[agent.deviceID] = agent
118 oo.deviceHandlers[agent.deviceID].Start(ctx)
119 }
120}
121
122func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *DeviceHandler) {
123 oo.lockDeviceHandlersMap.Lock()
124 defer oo.lockDeviceHandlersMap.Unlock()
125 delete(oo.deviceHandlers, agent.deviceID)
126}
127
128func (oo *OpenONUAC) getDeviceHandler(deviceID string) *DeviceHandler {
129 oo.lockDeviceHandlersMap.Lock()
130 defer oo.lockDeviceHandlersMap.Unlock()
131 if agent, ok := oo.deviceHandlers[deviceID]; ok {
132 return agent
133 }
134 return nil
135}
136
137// Adapter interface required methods ############## begin #########
138// #################################################################
139
140// for original content compare: (needs according deviceHandler methods)
141// /voltha-openolt-adapter/adaptercore/openolt.go
142
143// Adopt_device creates a new device handler if not present already and then adopts the device
144func (oo *OpenONUAC) Adopt_device(device *voltha.Device) error {
145 if device == nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000146 logger.Warn("voltha-device-is-nil")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000147 return errors.New("nil-device")
148 }
149 ctx := context.Background()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000150 logger.Infow("adopt-device", log.Fields{"deviceId": device.Id})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000151 var handler *DeviceHandler
152 if handler = oo.getDeviceHandler(device.Id); handler == nil {
153 handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
154 oo.addDeviceHandlerToMap(ctx, handler)
155 go handler.AdoptDevice(ctx, device)
156 // Launch the creation of the device topic
157 // go oo.createDeviceTopic(device)
158 }
159 return nil
160}
161
162//Get_ofp_device_info returns OFP information for the given device
163func (oo *OpenONUAC) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000164 logger.Errorw("device-handler-not-set", log.Fields{"deviceId": device.Id})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000165 return nil, errors.New("device-handler-not-set")
166}
167
168//Get_ofp_port_info returns OFP port information for the given device
169func (oo *OpenONUAC) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) {
Holger Hildebrandt24d51952020-05-04 14:03:42 +0000170 //this method expects a return value to be sent to the core
171 // and internal processing should not take that long
172 // so it makes no sense to try to work asynchronously here
173 logger.Infow("get-ofp-port-info started", log.Fields{"deviceId": device.Id, "portNo": portNo})
174 // basically the same code as in openOlt.go - unify???
175 if handler := oo.getDeviceHandler(device.Id); handler != nil {
176 return handler.GetOfpPortInfo(device, portNo)
177 // error treatment might be more sophisticated, but indeed it would be logged within handler
178 }
179 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found for deviceId %s", device.Id))
180 //return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000181}
182
183//Process_inter_adapter_message sends messages to a target device (between adapters)
184func (oo *OpenONUAC) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000185 logger.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000186 "msgProxyDeviceId": msg.Header.ProxyDeviceId, "msgToDeviceId": msg.Header.ToDeviceId})
187
188 targetDevice := msg.Header.ToDeviceId
189 //ToDeviceId should address an DeviceHandler instance
190 if handler := oo.getDeviceHandler(targetDevice); handler != nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000191 go handler.ProcessInterAdapterMessage(msg)
192 // error treatment might be more sophisticated
193 // by now let's just accept the message on 'communication layer'
194 // message content problems have to be evaluated then in the handler
195 // and are by now not reported to the calling party (to force what reaction there?)
196 return nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000197 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000198 logger.Warn("no handler found for received Inter-Proxy-message 'ToDeviceId'")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000199 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice))
200}
201
202//Adapter_descriptor not implemented
203func (oo *OpenONUAC) Adapter_descriptor() error {
204 return errors.New("unImplemented")
205}
206
207//Device_types unimplemented
208func (oo *OpenONUAC) Device_types() (*voltha.DeviceTypes, error) {
209 return nil, errors.New("unImplemented")
210}
211
212//Health returns unimplemented
213func (oo *OpenONUAC) Health() (*voltha.HealthStatus, error) {
214 return nil, errors.New("unImplemented")
215}
216
217//Reconcile_device unimplemented
218func (oo *OpenONUAC) Reconcile_device(device *voltha.Device) error {
219 return errors.New("unImplemented")
220}
221
222//Abandon_device unimplemented
223func (oo *OpenONUAC) Abandon_device(device *voltha.Device) error {
224 return errors.New("unImplemented")
225}
226
227//Disable_device disables the given device
228func (oo *OpenONUAC) Disable_device(device *voltha.Device) error {
ozgecanetsiafce57b12020-05-25 14:39:35 +0300229 logger.Debug("Disable_device", device.Id)
230 if handler := oo.getDeviceHandler(device.Id); handler != nil {
231 go handler.DisableDevice(device)
232 return nil
233 }
234 logger.Warn("no handler found for reenable device 'device.Id'")
235 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000236}
237
238//Reenable_device enables the olt device after disable
239func (oo *OpenONUAC) Reenable_device(device *voltha.Device) error {
ozgecanetsiafce57b12020-05-25 14:39:35 +0300240 logger.Debug("Reenable_device", device.Id)
241 if handler := oo.getDeviceHandler(device.Id); handler != nil {
242 go handler.ReenableDevice(device)
243 return nil
244 }
245 logger.Warn("no handler found for reenable device 'device.Id'")
246 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000247}
248
249//Reboot_device reboots the given device
250func (oo *OpenONUAC) Reboot_device(device *voltha.Device) error {
251 return errors.New("unImplemented")
252}
253
254//Self_test_device unimplented
255func (oo *OpenONUAC) Self_test_device(device *voltha.Device) error {
256 return errors.New("unImplemented")
257}
258
259//Delete_device unimplemented
260func (oo *OpenONUAC) Delete_device(device *voltha.Device) error {
261 return errors.New("unImplemented")
262}
263
264//Get_device_details unimplemented
265func (oo *OpenONUAC) Get_device_details(device *voltha.Device) error {
266 return errors.New("unImplemented")
267}
268
269//Update_flows_bulk returns
270func (oo *OpenONUAC) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error {
271 return errors.New("unImplemented")
272}
273
274//Update_flows_incrementally updates (add/remove) the flows on a given device
275func (oo *OpenONUAC) Update_flows_incrementally(device *voltha.Device, flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error {
276 return errors.New("unImplemented")
277}
278
279//Update_pm_config returns PmConfigs nil or error
280func (oo *OpenONUAC) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
281 return errors.New("unImplemented")
282}
283
284//Receive_packet_out sends packet out to the device
285func (oo *OpenONUAC) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
286 return errors.New("unImplemented")
287}
288
289//Suppress_event unimplemented
290func (oo *OpenONUAC) Suppress_event(filter *voltha.EventFilter) error {
291 return errors.New("unImplemented")
292}
293
294//Unsuppress_event unimplemented
295func (oo *OpenONUAC) Unsuppress_event(filter *voltha.EventFilter) error {
296 return errors.New("unImplemented")
297}
298
299//Download_image unimplemented
300func (oo *OpenONUAC) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
301 return nil, errors.New("unImplemented")
302}
303
304//Get_image_download_status unimplemented
305func (oo *OpenONUAC) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
306 return nil, errors.New("unImplemented")
307}
308
309//Cancel_image_download unimplemented
310func (oo *OpenONUAC) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
311 return nil, errors.New("unImplemented")
312}
313
314//Activate_image_update unimplemented
315func (oo *OpenONUAC) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
316 return nil, errors.New("unImplemented")
317}
318
319//Revert_image_update unimplemented
320func (oo *OpenONUAC) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
321 return nil, errors.New("unImplemented")
322}
323
324// Enable_port to Enable PON/NNI interface
325func (oo *OpenONUAC) Enable_port(deviceID string, port *voltha.Port) error {
326 return errors.New("unImplemented")
327}
328
329// Disable_port to Disable pon/nni interface
330func (oo *OpenONUAC) Disable_port(deviceID string, port *voltha.Port) error {
331 return errors.New("unImplemented")
332}
333
334// enableDisablePort to Disable pon or Enable PON interface
335func (oo *OpenONUAC) enableDisablePort(deviceID string, port *voltha.Port, enablePort bool) error {
336 return errors.New("unImplemented")
337}
338
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000339//needed for if update >= 3.1.x
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700340func (oo *OpenONUAC) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error {
341 return errors.New("unImplemented")
342}
343
344func (oo *OpenONUAC) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
345 return nil, errors.New("unImplemented")
346}
347
Matteo Scandolod132c0e2020-04-24 17:06:25 -0700348func (oo *OpenONUAC) Get_ext_value(deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) {
349 return nil, errors.New("unImplemented")
350}
351
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000352// Adapter interface required methods ################ end #########
353// #################################################################