blob: 1cd7585459d32acbd18f30167b4c9dc5130ec20b [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 {
229 return errors.New("unImplemented")
230}
231
232//Reenable_device enables the olt device after disable
233func (oo *OpenONUAC) Reenable_device(device *voltha.Device) error {
234 return errors.New("unImplemented")
235}
236
237//Reboot_device reboots the given device
238func (oo *OpenONUAC) Reboot_device(device *voltha.Device) error {
239 return errors.New("unImplemented")
240}
241
242//Self_test_device unimplented
243func (oo *OpenONUAC) Self_test_device(device *voltha.Device) error {
244 return errors.New("unImplemented")
245}
246
247//Delete_device unimplemented
248func (oo *OpenONUAC) Delete_device(device *voltha.Device) error {
249 return errors.New("unImplemented")
250}
251
252//Get_device_details unimplemented
253func (oo *OpenONUAC) Get_device_details(device *voltha.Device) error {
254 return errors.New("unImplemented")
255}
256
257//Update_flows_bulk returns
258func (oo *OpenONUAC) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error {
259 return errors.New("unImplemented")
260}
261
262//Update_flows_incrementally updates (add/remove) the flows on a given device
263func (oo *OpenONUAC) Update_flows_incrementally(device *voltha.Device, flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error {
264 return errors.New("unImplemented")
265}
266
267//Update_pm_config returns PmConfigs nil or error
268func (oo *OpenONUAC) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
269 return errors.New("unImplemented")
270}
271
272//Receive_packet_out sends packet out to the device
273func (oo *OpenONUAC) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
274 return errors.New("unImplemented")
275}
276
277//Suppress_event unimplemented
278func (oo *OpenONUAC) Suppress_event(filter *voltha.EventFilter) error {
279 return errors.New("unImplemented")
280}
281
282//Unsuppress_event unimplemented
283func (oo *OpenONUAC) Unsuppress_event(filter *voltha.EventFilter) error {
284 return errors.New("unImplemented")
285}
286
287//Download_image unimplemented
288func (oo *OpenONUAC) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
289 return nil, errors.New("unImplemented")
290}
291
292//Get_image_download_status unimplemented
293func (oo *OpenONUAC) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
294 return nil, errors.New("unImplemented")
295}
296
297//Cancel_image_download unimplemented
298func (oo *OpenONUAC) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
299 return nil, errors.New("unImplemented")
300}
301
302//Activate_image_update unimplemented
303func (oo *OpenONUAC) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
304 return nil, errors.New("unImplemented")
305}
306
307//Revert_image_update unimplemented
308func (oo *OpenONUAC) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
309 return nil, errors.New("unImplemented")
310}
311
312// Enable_port to Enable PON/NNI interface
313func (oo *OpenONUAC) Enable_port(deviceID string, port *voltha.Port) error {
314 return errors.New("unImplemented")
315}
316
317// Disable_port to Disable pon/nni interface
318func (oo *OpenONUAC) Disable_port(deviceID string, port *voltha.Port) error {
319 return errors.New("unImplemented")
320}
321
322// enableDisablePort to Disable pon or Enable PON interface
323func (oo *OpenONUAC) enableDisablePort(deviceID string, port *voltha.Port, enablePort bool) error {
324 return errors.New("unImplemented")
325}
326
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000327//needed for if update >= 3.1.x
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700328func (oo *OpenONUAC) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error {
329 return errors.New("unImplemented")
330}
331
332func (oo *OpenONUAC) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
333 return nil, errors.New("unImplemented")
334}
335
Matteo Scandolod132c0e2020-04-24 17:06:25 -0700336func (oo *OpenONUAC) Get_ext_value(deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) {
337 return nil, errors.New("unImplemented")
338}
339
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000340// Adapter interface required methods ################ end #########
341// #################################################################