blob: ff462f0330bab911962fb6a00da18be7a1b3b6dd [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
17//Package adaptercoreont provides the utility for onu devices, flows and statistics
18package adaptercoreont
19
20import (
21 "context"
22 //"errors"
23 //"sync"
24 //"time"
25
26 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
27
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)
34
35/*
36OpenOmciAgentDefaults = {
37 'mib-synchronizer': {
38 'state-machine': MibSynchronizer, # Implements the MIB synchronization state machine
39 'database': MibDbVolatileDict, # Implements volatile ME MIB database
40 # 'database': MibDbExternal, # Implements persistent ME MIB database
41 'advertise-events': True, # Advertise events on OpenOMCI event bus
42 'audit-delay': 60, # Time to wait between MIB audits. 0 to disable audits.
43 'tasks': {
44 'mib-upload': MibUploadTask,
45 'mib-template': MibTemplateTask,
46 'get-mds': GetMdsTask,
47 'mib-audit': GetMdsTask,
48 'mib-resync': MibResyncTask,
49 'mib-reconcile': MibReconcileTask
50 }
51 },
52 'omci-capabilities': {
53 'state-machine': OnuOmciCapabilities, # Implements OMCI capabilities state machine
54 'advertise-events': False, # Advertise events on OpenOMCI event bus
55 'tasks': {
56 'get-capabilities': OnuCapabilitiesTask # Get supported ME and Commands
57 }
58 },
59 'performance-intervals': {
60 'state-machine': PerformanceIntervals, # Implements PM Intervals State machine
61 'advertise-events': False, # Advertise events on OpenOMCI event bus
62 'tasks': {
63 'sync-time': SyncTimeTask,
64 'collect-data': IntervalDataTask,
65 'create-pm': OmciCreatePMRequest,
66 'delete-pm': OmciDeletePMRequest,
67 },
68 },
69 'alarm-synchronizer': {
70 'state-machine': AlarmSynchronizer, # Implements the Alarm sync state machine
71 'database': AlarmDbExternal, # For any State storage needs
72 'advertise-events': True, # Advertise events on OpenOMCI event bus
73 'tasks': {
74 'alarm-resync': AlarmResyncTask
75 }
76 },
77 'image_downloader': {
78 'state-machine': ImageDownloadeSTM,
79 'advertise-event': True,
80 'tasks': {
81 'download-file': FileDownloadTask
82 }
83 },
84 'image_upgrader': {
85 'state-machine': OmciSoftwareImageDownloadSTM,
86 'advertise-event': True,
87 'tasks': {
88 'omci_upgrade_task': OmciSwImageUpgradeTask
89 }
90 }
91 # 'image_activator': {
92 # 'state-machine': OmciSoftwareImageActivateSTM,
93 # 'advertise-event': True,
94 # }
95}
96*/
97
98//OpenOMCIAgent structure holds the ONU core information
99type OpenOMCIAgent struct {
100 coreProxy adapterif.CoreProxy
101 adapterProxy adapterif.AdapterProxy
102 started bool
103 deviceEntries map[string]*OnuDeviceEntry
104 mibDbClass func() error
105}
106
107//NewOpenOMCIAgent returns a new instance of OpenOMCIAgent
108func NewOpenOMCIAgent(ctx context.Context,
109 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy) *OpenOMCIAgent {
110 log.Info("init-openOmciAgent")
111 var openomciagent OpenOMCIAgent
112 openomciagent.started = false
113 openomciagent.coreProxy = coreProxy
114 openomciagent.adapterProxy = adapterProxy
115 openomciagent.deviceEntries = make(map[string]*OnuDeviceEntry)
116 return &openomciagent
117}
118
119//Start starts (logs) the omci agent
120func (oo *OpenOMCIAgent) Start(ctx context.Context) error {
121 log.Info("starting-openOmciAgent")
122 //TODO .....
123 //mib_db.start()
124 oo.started = true
125 log.Info("openOmciAgent-started")
126 return nil
127}
128
129//Stop terminates the session
130func (oo *OpenOMCIAgent) Stop(ctx context.Context) error {
131 log.Info("stopping-openOmciAgent")
132 oo.started = false
133 //oo.exitChannel <- 1
134 log.Info("openOmciAgent-stopped")
135 return nil
136}
137
138//
139//Add a new ONU to be managed.
140
141//To provide vendor-specific or custom Managed Entities, create your own Entity
142// ID to class mapping dictionary.
143
144//Since ONU devices can be added at any time (even during Device Handler
145// startup), the ONU device handler is responsible for calling start()/stop()
146// for this object.
147
148//:param device_id: (str) Device ID of ONU to add
149//:param core_proxy: (CoreProxy) Remote API to VOLTHA core
150//:param adapter_proxy: (AdapterProxy) Remote API to other adapters via VOLTHA core
151//:param custom_me_map: (dict) Additional/updated ME to add to class map
152//:param support_classes: (dict) State machines and tasks for this ONU
153
154//:return: (OnuDeviceEntry) The ONU device
155//
156func (oo *OpenOMCIAgent) Add_device(ctx context.Context, device_id string,
157 dh *DeviceHandler) (*OnuDeviceEntry, error) {
158 log.Info("openOmciAgent-adding-deviceEntry")
159
160 deviceEntry := oo.GetDevice(device_id)
161 if deviceEntry == nil {
162 /* costum_me_map in python code seems always to be None,
163 we omit that here first (declaration unclear) -> todo at Adapter specialization ...*/
164 /* also no 'clock' argument - usage open ...*/
165 /* and no alarm_db yet (oo.alarm_db) */
166 deviceEntry = NewOnuDeviceEntry(ctx, device_id, dh, oo.coreProxy, oo.adapterProxy,
167 oo.mibDbClass, nil)
168 oo.deviceEntries[device_id] = deviceEntry
169 log.Infow("openOmciAgent-OnuDeviceEntry-added", log.Fields{"for deviceId": device_id})
170 } else {
171 log.Infow("openOmciAgent-OnuDeviceEntry-add: Device already exists", log.Fields{"for deviceId": device_id})
172 }
173 // might be updated with some error handling !!!
174 return deviceEntry, nil
175}
176
177// Get ONU device entry for a specific Id
178func (oo *OpenOMCIAgent) GetDevice(device_id string) *OnuDeviceEntry {
179 if _, exist := oo.deviceEntries[device_id]; !exist {
180 return nil
181 } else {
182 return oo.deviceEntries[device_id]
183 }
184}