blob: 837dadb0bcf0492bec929cf82316e2d6eacfab01 [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 //"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
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000043 MibDownloadDone OnuDeviceEvent = 3 // MIB database sync (upload done)
44 PortLinkUp OnuDeviceEvent = 4 // Port link state change
45 PortLinkDw OnuDeviceEvent = 5 // Port link state change
Holger Hildebrandtfa074992020-03-27 15:42:06 +000046 // Add other events here as needed (alarms separate???)
47)
48
49type activityDescr struct {
50 databaseClass func() error
51 advertiseEvents bool
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000052 auditDelay uint16
Holger Hildebrandtfa074992020-03-27 15:42:06 +000053 //tasks map[string]func() error
54}
55type OmciDeviceFsms map[string]activityDescr
56
57//OntDeviceEntry structure holds information about the attached FSM'as and their communication
58type OnuDeviceEntry struct {
59 deviceID string
60 baseDeviceHandler *DeviceHandler
61 coreProxy adapterif.CoreProxy
62 adapterProxy adapterif.AdapterProxy
63 started bool
64 PDevOmciCC *OmciCC
65 //lockDeviceEntries sync.RWMutex
66 mibDbClass func() error
67 supportedFsms OmciDeviceFsms
68 MibSyncFsm *fsm.FSM
69 MibSyncChan chan Message
70 devState OnuDeviceEvent
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000071 mibAuditDelay uint16
Holger Hildebrandtfa074992020-03-27 15:42:06 +000072}
73
74//OnuDeviceEntry returns a new instance of a OnuDeviceEntry
75//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
76func NewOnuDeviceEntry(ctx context.Context,
77 device_id string, device_Handler *DeviceHandler,
78 core_proxy adapterif.CoreProxy, adapter_proxy adapterif.AdapterProxy,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000079 supported_Fsms_Ptr *OmciDeviceFsms) *OnuDeviceEntry {
80 logger.Infow("init-onuDeviceEntry", log.Fields{"deviceId": device_id})
Holger Hildebrandtfa074992020-03-27 15:42:06 +000081 var onuDeviceEntry OnuDeviceEntry
82 onuDeviceEntry.started = false
83 onuDeviceEntry.deviceID = device_id
84 onuDeviceEntry.baseDeviceHandler = device_Handler
85 onuDeviceEntry.coreProxy = core_proxy
86 onuDeviceEntry.adapterProxy = adapter_proxy
87 onuDeviceEntry.devState = DeviceStatusInit
88 //openomciagent.lockDeviceHandlersMap = sync.RWMutex{}
89 //OMCI related databases are on a per-agent basis. State machines and tasks
90 //are per ONU Vendor
91 //
92 // MIB Synchronization Database - possible overloading from arguments
93 if supported_Fsms_Ptr != nil {
94 onuDeviceEntry.supportedFsms = *supported_Fsms_Ptr
95 } else {
96 //var mibSyncFsm = NewMibSynchronizer()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000097 // use some internaƶ defaults, if not defined from outside
Holger Hildebrandtfa074992020-03-27 15:42:06 +000098 onuDeviceEntry.supportedFsms = OmciDeviceFsms{
99 "mib-synchronizer": {
100 //mibSyncFsm, // Implements the MIB synchronization state machine
101 onuDeviceEntry.MibDbVolatileDict, // Implements volatile ME MIB database
102 true, // Advertise events on OpenOMCI event bus
103 60, // Time to wait between MIB audits. 0 to disable audits.
104 // map[string]func() error{
105 // "mib-upload": onuDeviceEntry.MibUploadTask,
106 // "mib-template": onuDeviceEntry.MibTemplateTask,
107 // "get-mds": onuDeviceEntry.GetMdsTask,
108 // "mib-audit": onuDeviceEntry.GetMdsTask,
109 // "mib-resync": onuDeviceEntry.MibResyncTask,
110 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
111 // },
112 },
113 }
114 }
115 onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000116 logger.Debug("access2mibDbClass")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000117 go onuDeviceEntry.mibDbClass()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000118 onuDeviceEntry.mibAuditDelay = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditDelay
119 logger.Debugw("MibAudit is set to", log.Fields{"Delay": onuDeviceEntry.mibAuditDelay})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000120
121 // Omci related Mib sync state machine
122 onuDeviceEntry.MibSyncFsm = fsm.NewFSM(
123 "disabled",
124 fsm.Events{
125
126 {Name: "start", Src: []string{"disabled"}, Dst: "starting"},
127
128 {Name: "load_mib_template", Src: []string{"starting"}, Dst: "loading_mib_template"},
129 {Name: "upload_mib", Src: []string{"loading_mib_template"}, Dst: "uploading"},
130 {Name: "examine_mds", Src: []string{"starting"}, Dst: "examining_mds"},
131
132 {Name: "success", Src: []string{"loading_mib_template"}, Dst: "in_sync"},
133 {Name: "success", Src: []string{"uploading"}, Dst: "in_sync"},
134
135 {Name: "success", Src: []string{"examining_mds"}, Dst: "in_sync"},
136 {Name: "mismatch", Src: []string{"examining_mds"}, Dst: "resynchronizing"},
137
138 {Name: "audit_mib", Src: []string{"in_sync"}, Dst: "auditing"},
139
140 {Name: "success", Src: []string{"out_of_sync"}, Dst: "in_sync"},
141 {Name: "audit_mib", Src: []string{"out_of_sync"}, Dst: "auditing"},
142
143 {Name: "success", Src: []string{"auditing"}, Dst: "in_sync"},
144 {Name: "mismatch", Src: []string{"auditing"}, Dst: "resynchronizing"},
145 {Name: "force_resync", Src: []string{"auditing"}, Dst: "resynchronizing"},
146
147 {Name: "success", Src: []string{"resynchronizing"}, Dst: "in_sync"},
148 {Name: "diffs_found", Src: []string{"resynchronizing"}, Dst: "out_of_sync"},
149
150 {Name: "timeout", Src: []string{"loading_mib_template", "uploading", "resynchronizing", "examining_mds", "in_sync", "out_of_sync", "auditing"}, Dst: "starting"},
151
152 {Name: "stop", Src: []string{"starting", "loading_mib_template", "uploading", "resynchronizing", "examining_mds", "in_sync", "out_of_sync", "auditing"}, Dst: "disabled"},
153 },
154
155 fsm.Callbacks{
156 "enter_state": func(e *fsm.Event) { onuDeviceEntry.logStateChange(e) },
157 "enter_starting": func(e *fsm.Event) { onuDeviceEntry.enterStartingState(e) },
158 "enter_loading_mib_template": func(e *fsm.Event) { onuDeviceEntry.enterLoadingMibTemplateState(e) },
159 "enter_uploading": func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(e) },
160 "enter_examining_mds": func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(e) },
161 "enter_resynchronizing": func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(e) },
162 "enter_auditing": func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(e) },
163 "enter_out_of_sync": func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(e) },
164 "enter_in_sync": func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(e) },
165 },
166 )
167
168 // Alarm Synchronization Database
169 //self._alarm_db = None
170 //self._alarm_database_cls = support_classes['alarm-synchronizer']['database']
171 return &onuDeviceEntry
172}
173
174//Start starts (logs) the omci agent
175func (oo *OnuDeviceEntry) Start(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000176 logger.Info("starting-OnuDeviceEntry")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000177
178 oo.PDevOmciCC = NewOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler,
179 oo.coreProxy, oo.adapterProxy)
180
181 //TODO .....
182 //mib_db.start()
183 oo.started = true
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000184 logger.Info("OnuDeviceEntry-started, but not yet mib_db!!!")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000185 return nil
186}
187
188//Stop terminates the session
189func (oo *OnuDeviceEntry) Stop(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000190 logger.Info("stopping-OnuDeviceEntry")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000191 oo.started = false
192 //oo.exitChannel <- 1
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000193 logger.Info("OnuDeviceEntry-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000194 return nil
195}
196
197//Relay the InSync message via Handler to Rw core - Status update
198func (oo *OnuDeviceEntry) transferSystemEvent(dev_Event OnuDeviceEvent) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000199 logger.Debugw("relaying system-event", log.Fields{"Event": dev_Event})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000200 // decouple the handler transfer from further processing here
201 // TODO!!! check if really no synch is required within the system e.g. to ensure following steps ..
202 if dev_Event == MibDatabaseSync {
203 if oo.devState < MibDatabaseSync { //devState has not been synced yet
204 oo.devState = MibDatabaseSync
205 go oo.baseDeviceHandler.DeviceStateUpdate(dev_Event)
206 //TODO!!! device control: next step: start MIB capability verification from here ?!!!
207 } else {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000208 logger.Debugw("mibinsync-event in some already synced state - ignored", log.Fields{"state": oo.devState})
209 }
210 } else if dev_Event == MibDownloadDone {
211 if oo.devState < MibDownloadDone { //devState has not been synced yet
212 oo.devState = MibDownloadDone
213 go oo.baseDeviceHandler.DeviceStateUpdate(dev_Event)
214 } else {
215 logger.Debugw("mibdownloaddone-event was already seen - ignored", log.Fields{"state": oo.devState})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000216 }
217 } else {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000218 logger.Warnw("device-event not yet handled", log.Fields{"state": dev_Event})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000219 }
220 return nil
221}