blob: 93584c2a0dc38943738dac92be44240ae27738eb [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 Hildebrandt0f9b88d2020-04-20 13:33:25 +0000170 logger.Errorw("device-handler-not-set", log.Fields{"deviceId": device.Id})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000171 return nil, errors.New("device-handler-not-set")
172}
173
174//Process_inter_adapter_message sends messages to a target device (between adapters)
175func (oo *OpenONUAC) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000176 logger.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000177 "msgProxyDeviceId": msg.Header.ProxyDeviceId, "msgToDeviceId": msg.Header.ToDeviceId})
178
179 targetDevice := msg.Header.ToDeviceId
180 //ToDeviceId should address an DeviceHandler instance
181 if handler := oo.getDeviceHandler(targetDevice); handler != nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000182 go handler.ProcessInterAdapterMessage(msg)
183 // error treatment might be more sophisticated
184 // by now let's just accept the message on 'communication layer'
185 // message content problems have to be evaluated then in the handler
186 // and are by now not reported to the calling party (to force what reaction there?)
187 return nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000188 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000189 logger.Warn("no handler found for received Inter-Proxy-message 'ToDeviceId'")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000190 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice))
191}
192
193//Adapter_descriptor not implemented
194func (oo *OpenONUAC) Adapter_descriptor() error {
195 return errors.New("unImplemented")
196}
197
198//Device_types unimplemented
199func (oo *OpenONUAC) Device_types() (*voltha.DeviceTypes, error) {
200 return nil, errors.New("unImplemented")
201}
202
203//Health returns unimplemented
204func (oo *OpenONUAC) Health() (*voltha.HealthStatus, error) {
205 return nil, errors.New("unImplemented")
206}
207
208//Reconcile_device unimplemented
209func (oo *OpenONUAC) Reconcile_device(device *voltha.Device) error {
210 return errors.New("unImplemented")
211}
212
213//Abandon_device unimplemented
214func (oo *OpenONUAC) Abandon_device(device *voltha.Device) error {
215 return errors.New("unImplemented")
216}
217
218//Disable_device disables the given device
219func (oo *OpenONUAC) Disable_device(device *voltha.Device) error {
220 return errors.New("unImplemented")
221}
222
223//Reenable_device enables the olt device after disable
224func (oo *OpenONUAC) Reenable_device(device *voltha.Device) error {
225 return errors.New("unImplemented")
226}
227
228//Reboot_device reboots the given device
229func (oo *OpenONUAC) Reboot_device(device *voltha.Device) error {
230 return errors.New("unImplemented")
231}
232
233//Self_test_device unimplented
234func (oo *OpenONUAC) Self_test_device(device *voltha.Device) error {
235 return errors.New("unImplemented")
236}
237
238//Delete_device unimplemented
239func (oo *OpenONUAC) Delete_device(device *voltha.Device) error {
240 return errors.New("unImplemented")
241}
242
243//Get_device_details unimplemented
244func (oo *OpenONUAC) Get_device_details(device *voltha.Device) error {
245 return errors.New("unImplemented")
246}
247
248//Update_flows_bulk returns
249func (oo *OpenONUAC) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error {
250 return errors.New("unImplemented")
251}
252
253//Update_flows_incrementally updates (add/remove) the flows on a given device
254func (oo *OpenONUAC) Update_flows_incrementally(device *voltha.Device, flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error {
255 return errors.New("unImplemented")
256}
257
258//Update_pm_config returns PmConfigs nil or error
259func (oo *OpenONUAC) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
260 return errors.New("unImplemented")
261}
262
263//Receive_packet_out sends packet out to the device
264func (oo *OpenONUAC) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
265 return errors.New("unImplemented")
266}
267
268//Suppress_event unimplemented
269func (oo *OpenONUAC) Suppress_event(filter *voltha.EventFilter) error {
270 return errors.New("unImplemented")
271}
272
273//Unsuppress_event unimplemented
274func (oo *OpenONUAC) Unsuppress_event(filter *voltha.EventFilter) error {
275 return errors.New("unImplemented")
276}
277
278//Download_image unimplemented
279func (oo *OpenONUAC) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
280 return nil, errors.New("unImplemented")
281}
282
283//Get_image_download_status unimplemented
284func (oo *OpenONUAC) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
285 return nil, errors.New("unImplemented")
286}
287
288//Cancel_image_download unimplemented
289func (oo *OpenONUAC) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
290 return nil, errors.New("unImplemented")
291}
292
293//Activate_image_update unimplemented
294func (oo *OpenONUAC) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
295 return nil, errors.New("unImplemented")
296}
297
298//Revert_image_update unimplemented
299func (oo *OpenONUAC) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
300 return nil, errors.New("unImplemented")
301}
302
303// Enable_port to Enable PON/NNI interface
304func (oo *OpenONUAC) Enable_port(deviceID string, port *voltha.Port) error {
305 return errors.New("unImplemented")
306}
307
308// Disable_port to Disable pon/nni interface
309func (oo *OpenONUAC) Disable_port(deviceID string, port *voltha.Port) error {
310 return errors.New("unImplemented")
311}
312
313// enableDisablePort to Disable pon or Enable PON interface
314func (oo *OpenONUAC) enableDisablePort(deviceID string, port *voltha.Port, enablePort bool) error {
315 return errors.New("unImplemented")
316}
317
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000318//needed for if update >= 3.1.x
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700319func (oo *OpenONUAC) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error {
320 return errors.New("unImplemented")
321}
322
323func (oo *OpenONUAC) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
324 return nil, errors.New("unImplemented")
325}
326
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000327// Adapter interface required methods ################ end #########
328// #################################################################