blob: 27b71e236125cd6363358937ad319a1355edaf71 [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/looplab/fsm"
27 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
28
29 //"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)
35
36type OnuDeviceEvent int
37
38const (
39 // Events of interest to Device Adapters and OpenOMCI State Machines
40 DeviceStatusInit OnuDeviceEvent = 0 // OnuDeviceEntry default start state
41 MibDatabaseSync OnuDeviceEvent = 1 // MIB database sync (upload done)
42 OmciCapabilitiesDone OnuDeviceEvent = 2 // OMCI ME and message type capabilities known
43 PortLinkUp OnuDeviceEvent = 3 // Port link state change
44 PortLinkDw OnuDeviceEvent = 4 // Port link state change
45 // Add other events here as needed (alarms separate???)
46)
47
48type activityDescr struct {
49 databaseClass func() error
50 advertiseEvents bool
51 auditDelay int
52 //tasks map[string]func() error
53}
54type OmciDeviceFsms map[string]activityDescr
55
56//OntDeviceEntry structure holds information about the attached FSM'as and their communication
57type OnuDeviceEntry struct {
58 deviceID string
59 baseDeviceHandler *DeviceHandler
60 coreProxy adapterif.CoreProxy
61 adapterProxy adapterif.AdapterProxy
62 started bool
63 PDevOmciCC *OmciCC
64 //lockDeviceEntries sync.RWMutex
65 mibDbClass func() error
66 supportedFsms OmciDeviceFsms
67 MibSyncFsm *fsm.FSM
68 MibSyncChan chan Message
69 devState OnuDeviceEvent
70}
71
72//OnuDeviceEntry returns a new instance of a OnuDeviceEntry
73//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
74func NewOnuDeviceEntry(ctx context.Context,
75 device_id string, device_Handler *DeviceHandler,
76 core_proxy adapterif.CoreProxy, adapter_proxy adapterif.AdapterProxy,
77 mib_db func() error, supported_Fsms_Ptr *OmciDeviceFsms) *OnuDeviceEntry {
78 log.Infow("init-onuDeviceEntry", log.Fields{"deviceId": device_id})
79 var onuDeviceEntry OnuDeviceEntry
80 onuDeviceEntry.started = false
81 onuDeviceEntry.deviceID = device_id
82 onuDeviceEntry.baseDeviceHandler = device_Handler
83 onuDeviceEntry.coreProxy = core_proxy
84 onuDeviceEntry.adapterProxy = adapter_proxy
85 onuDeviceEntry.devState = DeviceStatusInit
86 //openomciagent.lockDeviceHandlersMap = sync.RWMutex{}
87 //OMCI related databases are on a per-agent basis. State machines and tasks
88 //are per ONU Vendor
89 //
90 // MIB Synchronization Database - possible overloading from arguments
91 if supported_Fsms_Ptr != nil {
92 onuDeviceEntry.supportedFsms = *supported_Fsms_Ptr
93 } else {
94 //var mibSyncFsm = NewMibSynchronizer()
95 onuDeviceEntry.supportedFsms = OmciDeviceFsms{
96 "mib-synchronizer": {
97 //mibSyncFsm, // Implements the MIB synchronization state machine
98 onuDeviceEntry.MibDbVolatileDict, // Implements volatile ME MIB database
99 true, // Advertise events on OpenOMCI event bus
100 60, // Time to wait between MIB audits. 0 to disable audits.
101 // map[string]func() error{
102 // "mib-upload": onuDeviceEntry.MibUploadTask,
103 // "mib-template": onuDeviceEntry.MibTemplateTask,
104 // "get-mds": onuDeviceEntry.GetMdsTask,
105 // "mib-audit": onuDeviceEntry.GetMdsTask,
106 // "mib-resync": onuDeviceEntry.MibResyncTask,
107 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
108 // },
109 },
110 }
111 }
112 onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass
113 log.Debug("access2mibDbClass")
114 go onuDeviceEntry.mibDbClass()
115
116 // Omci related Mib sync state machine
117 onuDeviceEntry.MibSyncFsm = fsm.NewFSM(
118 "disabled",
119 fsm.Events{
120
121 {Name: "start", Src: []string{"disabled"}, Dst: "starting"},
122
123 {Name: "load_mib_template", Src: []string{"starting"}, Dst: "loading_mib_template"},
124 {Name: "upload_mib", Src: []string{"loading_mib_template"}, Dst: "uploading"},
125 {Name: "examine_mds", Src: []string{"starting"}, Dst: "examining_mds"},
126
127 {Name: "success", Src: []string{"loading_mib_template"}, Dst: "in_sync"},
128 {Name: "success", Src: []string{"uploading"}, Dst: "in_sync"},
129
130 {Name: "success", Src: []string{"examining_mds"}, Dst: "in_sync"},
131 {Name: "mismatch", Src: []string{"examining_mds"}, Dst: "resynchronizing"},
132
133 {Name: "audit_mib", Src: []string{"in_sync"}, Dst: "auditing"},
134
135 {Name: "success", Src: []string{"out_of_sync"}, Dst: "in_sync"},
136 {Name: "audit_mib", Src: []string{"out_of_sync"}, Dst: "auditing"},
137
138 {Name: "success", Src: []string{"auditing"}, Dst: "in_sync"},
139 {Name: "mismatch", Src: []string{"auditing"}, Dst: "resynchronizing"},
140 {Name: "force_resync", Src: []string{"auditing"}, Dst: "resynchronizing"},
141
142 {Name: "success", Src: []string{"resynchronizing"}, Dst: "in_sync"},
143 {Name: "diffs_found", Src: []string{"resynchronizing"}, Dst: "out_of_sync"},
144
145 {Name: "timeout", Src: []string{"loading_mib_template", "uploading", "resynchronizing", "examining_mds", "in_sync", "out_of_sync", "auditing"}, Dst: "starting"},
146
147 {Name: "stop", Src: []string{"starting", "loading_mib_template", "uploading", "resynchronizing", "examining_mds", "in_sync", "out_of_sync", "auditing"}, Dst: "disabled"},
148 },
149
150 fsm.Callbacks{
151 "enter_state": func(e *fsm.Event) { onuDeviceEntry.logStateChange(e) },
152 "enter_starting": func(e *fsm.Event) { onuDeviceEntry.enterStartingState(e) },
153 "enter_loading_mib_template": func(e *fsm.Event) { onuDeviceEntry.enterLoadingMibTemplateState(e) },
154 "enter_uploading": func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(e) },
155 "enter_examining_mds": func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(e) },
156 "enter_resynchronizing": func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(e) },
157 "enter_auditing": func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(e) },
158 "enter_out_of_sync": func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(e) },
159 "enter_in_sync": func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(e) },
160 },
161 )
162
163 // Alarm Synchronization Database
164 //self._alarm_db = None
165 //self._alarm_database_cls = support_classes['alarm-synchronizer']['database']
166 return &onuDeviceEntry
167}
168
169//Start starts (logs) the omci agent
170func (oo *OnuDeviceEntry) Start(ctx context.Context) error {
171 log.Info("starting-OnuDeviceEntry")
172
173 oo.PDevOmciCC = NewOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler,
174 oo.coreProxy, oo.adapterProxy)
175
176 //TODO .....
177 //mib_db.start()
178 oo.started = true
179 log.Info("OnuDeviceEntry-started, but not yet mib_db!!!")
180 return nil
181}
182
183//Stop terminates the session
184func (oo *OnuDeviceEntry) Stop(ctx context.Context) error {
185 log.Info("stopping-OnuDeviceEntry")
186 oo.started = false
187 //oo.exitChannel <- 1
188 log.Info("OnuDeviceEntry-stopped")
189 return nil
190}
191
192//Relay the InSync message via Handler to Rw core - Status update
193func (oo *OnuDeviceEntry) transferSystemEvent(dev_Event OnuDeviceEvent) error {
194 log.Debugw("relaying system-event", log.Fields{"Event": dev_Event})
195 // decouple the handler transfer from further processing here
196 // TODO!!! check if really no synch is required within the system e.g. to ensure following steps ..
197 if dev_Event == MibDatabaseSync {
198 if oo.devState < MibDatabaseSync { //devState has not been synced yet
199 oo.devState = MibDatabaseSync
200 go oo.baseDeviceHandler.DeviceStateUpdate(dev_Event)
201 //TODO!!! device control: next step: start MIB capability verification from here ?!!!
202 } else {
203 log.Debugw("mib-in-sync-event in some already synced state - ignored", log.Fields{"state": oo.devState})
204 }
205 } else {
206 log.Warnw("device-event not yet handled", log.Fields{"state": dev_Event})
207 }
208 return nil
209}