blob: 382984c2c69fb126e66a8006eb3fa964b59d4457 [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"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000022 "errors"
Holger Hildebrandt2ff21f12020-08-13 14:38:02 +000023 "time"
24
ozgecanetsiae11479f2020-07-06 09:44:47 +030025 "github.com/opencord/omci-lib-go"
26 me "github.com/opencord/omci-lib-go/generated"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000027
Holger Hildebrandtfa074992020-03-27 15:42:06 +000028 //"sync"
29 //"time"
30
31 "github.com/looplab/fsm"
32 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000033 "github.com/opencord/voltha-lib-go/v3/pkg/db"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000034
35 //"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
36 "github.com/opencord/voltha-lib-go/v3/pkg/log"
37 //ic "github.com/opencord/voltha-protos/v3/go/inter_container"
38 //"github.com/opencord/voltha-protos/v3/go/openflow_13"
39 //"github.com/opencord/voltha-protos/v3/go/voltha"
40)
41
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000042const (
mpagenko1cc3cb42020-07-27 15:24:38 +000043 // events of MibUpload FSM
44 ulEvStart = "ulEvStart"
45 ulEvResetMib = "ulEvResetMib"
46 ulEvGetVendorAndSerial = "ulEvGetVendorAndSerial"
Himani Chawla4d908332020-08-31 12:30:20 +053047 ulEvGetEquipmentID = "ulEvGetEquipmentId"
mpagenko1cc3cb42020-07-27 15:24:38 +000048 ulEvGetFirstSwVersion = "ulEvGetFirstSwVersion"
49 ulEvGetSecondSwVersion = "ulEvGetSecondSwVersion"
50 ulEvGetMacAddress = "ulEvGetMacAddress"
51 ulEvGetMibTemplate = "ulEvGetMibTemplate"
52 ulEvUploadMib = "ulEvUploadMib"
53 ulEvExamineMds = "ulEvExamineMds"
54 ulEvSuccess = "ulEvSuccess"
55 ulEvMismatch = "ulEvMismatch"
56 ulEvAuditMib = "ulEvAuditMib"
57 ulEvForceResync = "ulEvForceResync"
58 ulEvDiffsFound = "ulEvDiffsFound"
59 ulEvTimeout = "ulEvTimeout"
60 ulEvStop = "ulEvStop"
61)
62const (
63 // states of MibUpload FSM
64 ulStDisabled = "ulStDisabled"
65 ulStStarting = "ulStStarting"
66 ulStResettingMib = "ulStResettingMib"
67 ulStGettingVendorAndSerial = "ulStGettingVendorAndSerial"
Himani Chawla4d908332020-08-31 12:30:20 +053068 ulStGettingEquipmentID = "ulStGettingEquipmentID"
mpagenko1cc3cb42020-07-27 15:24:38 +000069 ulStGettingFirstSwVersion = "ulStGettingFirstSwVersion"
70 ulStGettingSecondSwVersion = "ulStGettingSecondSwVersion"
71 ulStGettingMacAddress = "ulStGettingMacAddress"
72 ulStGettingMibTemplate = "ulStGettingMibTemplate"
73 ulStUploading = "ulStUploading"
74 ulStInSync = "ulStInSync"
75 ulStExaminingMds = "ulStExaminingMds"
76 ulStResynchronizing = "ulStResynchronizing"
77 ulStAuditing = "ulStAuditing"
78 ulStOutOfSync = "ulStOutOfSync"
79)
80
81const (
82 // events of MibDownload FSM
83 dlEvStart = "dlEvStart"
84 dlEvCreateGal = "dlEvCreateGal"
85 dlEvRxGalResp = "dlEvRxGalResp"
86 dlEvRxOnu2gResp = "dlEvRxOnu2gResp"
87 dlEvRxBridgeResp = "dlEvRxBridgeResp"
88 dlEvTimeoutSimple = "dlEvTimeoutSimple"
89 dlEvTimeoutBridge = "dlEvTimeoutBridge"
90 dlEvReset = "dlEvReset"
91 dlEvRestart = "dlEvRestart"
92)
93const (
94 // states of MibDownload FSM
95 dlStDisabled = "dlStDisabled"
96 dlStStarting = "dlStStarting"
97 dlStCreatingGal = "dlStCreatingGal"
98 dlStSettingOnu2g = "dlStSettingOnu2g"
99 dlStBridgeInit = "dlStBridgeInit"
100 dlStDownloaded = "dlStDownloaded"
101 dlStResetting = "dlStResetting"
102)
103
104const (
Holger Hildebrandt2ff21f12020-08-13 14:38:02 +0000105 cBasePathMibTemplateKvStore = "service/voltha/omci_mibs/go_templates"
mpagenkoaf801632020-07-03 10:00:42 +0000106 cSuffixMibTemplateKvStore = "%s/%s/%s"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000107)
108
Himani Chawla6d2ae152020-09-02 13:11:20 +0530109// OnuDeviceEvent - event of interest to Device Adapters and OpenOMCI State Machines
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000110type OnuDeviceEvent int
111
112const (
113 // Events of interest to Device Adapters and OpenOMCI State Machines
Himani Chawla6d2ae152020-09-02 13:11:20 +0530114
115 // DeviceStatusInit - default start state
116 DeviceStatusInit OnuDeviceEvent = 0
117 // MibDatabaseSync - MIB database sync (upload done)
118 MibDatabaseSync OnuDeviceEvent = 1
119 // OmciCapabilitiesDone - OMCI ME and message type capabilities known
120 OmciCapabilitiesDone OnuDeviceEvent = 2
121 // MibDownloadDone - // MIB download done
122 MibDownloadDone OnuDeviceEvent = 3
123 // UniLockStateDone - Uni ports admin set to lock
124 UniLockStateDone OnuDeviceEvent = 4
125 // UniUnlockStateDone - Uni ports admin set to unlock
126 UniUnlockStateDone OnuDeviceEvent = 5
127 // UniAdminStateDone - Uni ports admin set done - general
128 UniAdminStateDone OnuDeviceEvent = 6
129 // PortLinkUp - Port link state change
130 PortLinkUp OnuDeviceEvent = 7
131 // PortLinkDw - Port link state change
132 PortLinkDw OnuDeviceEvent = 8
133 // OmciAniConfigDone - AniSide config according to TechProfile done
134 OmciAniConfigDone OnuDeviceEvent = 9
135 // OmciVlanFilterDone - Omci Vlan config according to flowConfig done
136 OmciVlanFilterDone OnuDeviceEvent = 10
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000137 // Add other events here as needed (alarms separate???)
138)
139
140type activityDescr struct {
Himani Chawla4d908332020-08-31 12:30:20 +0530141 databaseClass func() error
142 //advertiseEvents bool
143 auditDelay uint16
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000144 //tasks map[string]func() error
145}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530146
147// OmciDeviceFsms - FSM event mapping to database class and time to wait between audits
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000148type OmciDeviceFsms map[string]activityDescr
149
Himani Chawla6d2ae152020-09-02 13:11:20 +0530150// AdapterFsm - Adapter FSM details including channel, event and device
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000151type AdapterFsm struct {
152 fsmName string
153 deviceID string
154 commChan chan Message
155 pFsm *fsm.FSM
156}
157
Himani Chawla6d2ae152020-09-02 13:11:20 +0530158//NewAdapterFsm - FSM details including event, device and channel.
159func NewAdapterFsm(aName string, aDeviceID string, aCommChannel chan Message) *AdapterFsm {
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000160 aFsm := &AdapterFsm{
Himani Chawla6d2ae152020-09-02 13:11:20 +0530161 fsmName: aName,
162 deviceID: aDeviceID,
163 commChan: aCommChannel,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000164 }
165 return aFsm
166}
167
168//Start starts (logs) the omci agent
169func (oo *AdapterFsm) logFsmStateChange(e *fsm.Event) {
170 logger.Debugw("FSM state change", log.Fields{"device-id": oo.deviceID, "FSM name": oo.fsmName,
171 "event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst)})
172}
173
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000174//OntDeviceEntry structure holds information about the attached FSM'as and their communication
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000175
176const (
Himani Chawla6d2ae152020-09-02 13:11:20 +0530177 firstSwImageMeID = 0
178 secondSwImageMeID = 1
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000179)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530180const onugMeID = 0
181const onu2gMeID = 0
182const ipHostConfigDataMeID = 1
183const onugSerialNumberLen = 8
184const omciMacAddressLen = 6
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000185
Himani Chawla6d2ae152020-09-02 13:11:20 +0530186type swImages struct {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000187 version string
188 isActive uint8
189}
190
Himani Chawla6d2ae152020-09-02 13:11:20 +0530191// OnuDeviceEntry - ONU device info and FSM events.
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000192type OnuDeviceEntry struct {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000193 deviceID string
Himani Chawla6d2ae152020-09-02 13:11:20 +0530194 baseDeviceHandler *deviceHandler
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000195 coreProxy adapterif.CoreProxy
196 adapterProxy adapterif.AdapterProxy
197 started bool
Himani Chawla6d2ae152020-09-02 13:11:20 +0530198 PDevOmciCC *omciCC
199 pOnuDB *onuDeviceDB
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000200 mibTemplateKVStore *db.Backend
201 vendorID string
202 serialNumber string
203 equipmentID string
Himani Chawla6d2ae152020-09-02 13:11:20 +0530204 swImages [secondSwImageMeID + 1]swImages
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000205 activeSwVersion string
206 macAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000207 //lockDeviceEntries sync.RWMutex
208 mibDbClass func() error
209 supportedFsms OmciDeviceFsms
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000210 devState OnuDeviceEvent
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000211 // for mibUpload
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000212 mibAuditDelay uint16
mpagenko1cc3cb42020-07-27 15:24:38 +0000213 mibDebugLevel string
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000214
215 // for mibUpload
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000216 pMibUploadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
217 // for mibDownload
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000218 pMibDownloadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
219 //remark: general usage of pAdapterFsm would require generalization of commChan usage and internal event setting
220 // within the FSM event procedures
ozgecanetsiae11479f2020-07-06 09:44:47 +0300221 omciMessageReceived chan bool //seperate channel needed by DownloadFsm
222 omciRebootMessageReceivedChannel chan Message // channel needed by Reboot request
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000223}
224
Himani Chawla6d2ae152020-09-02 13:11:20 +0530225//newOnuDeviceEntry returns a new instance of a OnuDeviceEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000226//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530227func newOnuDeviceEntry(ctx context.Context, deviceID string, kVStoreHost string, kVStorePort int, kvStoreType string, deviceHandler *deviceHandler,
Himani Chawla26e555c2020-08-31 12:30:20 +0530228 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
229 supportedFsmsPtr *OmciDeviceFsms) *OnuDeviceEntry {
230 logger.Infow("init-onuDeviceEntry", log.Fields{"device-id": deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000231 var onuDeviceEntry OnuDeviceEntry
232 onuDeviceEntry.started = false
Himani Chawla26e555c2020-08-31 12:30:20 +0530233 onuDeviceEntry.deviceID = deviceID
234 onuDeviceEntry.baseDeviceHandler = deviceHandler
235 onuDeviceEntry.coreProxy = coreProxy
236 onuDeviceEntry.adapterProxy = adapterProxy
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000237 onuDeviceEntry.devState = DeviceStatusInit
ozgecanetsiae11479f2020-07-06 09:44:47 +0300238 onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan Message, 2048)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000239 //openomciagent.lockDeviceHandlersMap = sync.RWMutex{}
240 //OMCI related databases are on a per-agent basis. State machines and tasks
241 //are per ONU Vendor
242 //
243 // MIB Synchronization Database - possible overloading from arguments
Himani Chawla26e555c2020-08-31 12:30:20 +0530244 if supportedFsmsPtr != nil {
245 onuDeviceEntry.supportedFsms = *supportedFsmsPtr
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000246 } else {
247 //var mibSyncFsm = NewMibSynchronizer()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000248 // use some internaö defaults, if not defined from outside
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000249 onuDeviceEntry.supportedFsms = OmciDeviceFsms{
250 "mib-synchronizer": {
251 //mibSyncFsm, // Implements the MIB synchronization state machine
Himani Chawla6d2ae152020-09-02 13:11:20 +0530252 onuDeviceEntry.mibDbVolatileDict, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +0530253 //true, // Advertise events on OpenOMCI event bus
254 60, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000255 // map[string]func() error{
256 // "mib-upload": onuDeviceEntry.MibUploadTask,
257 // "mib-template": onuDeviceEntry.MibTemplateTask,
258 // "get-mds": onuDeviceEntry.GetMdsTask,
259 // "mib-audit": onuDeviceEntry.GetMdsTask,
260 // "mib-resync": onuDeviceEntry.MibResyncTask,
261 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
262 // },
263 },
264 }
265 }
266 onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000267 logger.Debug("access2mibDbClass")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000268 go onuDeviceEntry.mibDbClass()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000269 onuDeviceEntry.mibAuditDelay = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditDelay
270 logger.Debugw("MibAudit is set to", log.Fields{"Delay": onuDeviceEntry.mibAuditDelay})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000271
mpagenko1cc3cb42020-07-27 15:24:38 +0000272 onuDeviceEntry.mibDebugLevel = "normal" //set to "verbose" if you want to have all output, possibly later also per config option!
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000273 // Omci related Mib upload sync state machine
274 mibUploadChan := make(chan Message, 2048)
Himani Chawla26e555c2020-08-31 12:30:20 +0530275 onuDeviceEntry.pMibUploadFsm = NewAdapterFsm("MibUpload", deviceID, mibUploadChan)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000276 onuDeviceEntry.pMibUploadFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000277 ulStDisabled,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000278 fsm.Events{
279
mpagenko1cc3cb42020-07-27 15:24:38 +0000280 {Name: ulEvStart, Src: []string{ulStDisabled}, Dst: ulStStarting},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000281
mpagenko1cc3cb42020-07-27 15:24:38 +0000282 {Name: ulEvResetMib, Src: []string{ulStStarting}, Dst: ulStResettingMib},
283 {Name: ulEvGetVendorAndSerial, Src: []string{ulStResettingMib}, Dst: ulStGettingVendorAndSerial},
Himani Chawla4d908332020-08-31 12:30:20 +0530284 {Name: ulEvGetEquipmentID, Src: []string{ulStGettingVendorAndSerial}, Dst: ulStGettingEquipmentID},
285 {Name: ulEvGetFirstSwVersion, Src: []string{ulStGettingEquipmentID}, Dst: ulStGettingFirstSwVersion},
mpagenko1cc3cb42020-07-27 15:24:38 +0000286 {Name: ulEvGetSecondSwVersion, Src: []string{ulStGettingFirstSwVersion}, Dst: ulStGettingSecondSwVersion},
287 {Name: ulEvGetMacAddress, Src: []string{ulStGettingSecondSwVersion}, Dst: ulStGettingMacAddress},
288 {Name: ulEvGetMibTemplate, Src: []string{ulStGettingMacAddress}, Dst: ulStGettingMibTemplate},
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000289
mpagenko1cc3cb42020-07-27 15:24:38 +0000290 {Name: ulEvUploadMib, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploading},
291 {Name: ulEvExamineMds, Src: []string{ulStStarting}, Dst: ulStExaminingMds},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000292
mpagenko1cc3cb42020-07-27 15:24:38 +0000293 {Name: ulEvSuccess, Src: []string{ulStGettingMibTemplate}, Dst: ulStInSync},
294 {Name: ulEvSuccess, Src: []string{ulStUploading}, Dst: ulStInSync},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000295
mpagenko1cc3cb42020-07-27 15:24:38 +0000296 {Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStInSync},
297 {Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResynchronizing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000298
mpagenko1cc3cb42020-07-27 15:24:38 +0000299 {Name: ulEvAuditMib, Src: []string{ulStInSync}, Dst: ulStAuditing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000300
mpagenko1cc3cb42020-07-27 15:24:38 +0000301 {Name: ulEvSuccess, Src: []string{ulStOutOfSync}, Dst: ulStInSync},
302 {Name: ulEvAuditMib, Src: []string{ulStOutOfSync}, Dst: ulStAuditing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000303
mpagenko1cc3cb42020-07-27 15:24:38 +0000304 {Name: ulEvSuccess, Src: []string{ulStAuditing}, Dst: ulStInSync},
305 {Name: ulEvMismatch, Src: []string{ulStAuditing}, Dst: ulStResynchronizing},
306 {Name: ulEvForceResync, Src: []string{ulStAuditing}, Dst: ulStResynchronizing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000307
mpagenko1cc3cb42020-07-27 15:24:38 +0000308 {Name: ulEvSuccess, Src: []string{ulStResynchronizing}, Dst: ulStInSync},
309 {Name: ulEvDiffsFound, Src: []string{ulStResynchronizing}, Dst: ulStOutOfSync},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000310
Himani Chawla4d908332020-08-31 12:30:20 +0530311 {Name: ulEvTimeout, Src: []string{ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion,
mpagenko1cc3cb42020-07-27 15:24:38 +0000312 ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds,
313 ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStStarting},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000314
Himani Chawla4d908332020-08-31 12:30:20 +0530315 {Name: ulEvStop, Src: []string{ulStStarting, ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion,
mpagenko1cc3cb42020-07-27 15:24:38 +0000316 ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds,
317 ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStDisabled},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000318 },
319
320 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000321 "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibUploadFsm.logFsmStateChange(e) },
322 ("enter_" + ulStStarting): func(e *fsm.Event) { onuDeviceEntry.enterStartingState(e) },
323 ("enter_" + ulStResettingMib): func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(e) },
324 ("enter_" + ulStGettingVendorAndSerial): func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(e) },
Himani Chawla4d908332020-08-31 12:30:20 +0530325 ("enter_" + ulStGettingEquipmentID): func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipmentIDState(e) },
mpagenko1cc3cb42020-07-27 15:24:38 +0000326 ("enter_" + ulStGettingFirstSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(e) },
327 ("enter_" + ulStGettingSecondSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(e) },
328 ("enter_" + ulStGettingMacAddress): func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(e) },
329 ("enter_" + ulStGettingMibTemplate): func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplate(e) },
330 ("enter_" + ulStUploading): func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(e) },
331 ("enter_" + ulStExaminingMds): func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(e) },
332 ("enter_" + ulStResynchronizing): func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(e) },
333 ("enter_" + ulStAuditing): func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(e) },
334 ("enter_" + ulStOutOfSync): func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(e) },
335 ("enter_" + ulStInSync): func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(e) },
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000336 },
337 )
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000338 // Omci related Mib download state machine
339 mibDownloadChan := make(chan Message, 2048)
Himani Chawla26e555c2020-08-31 12:30:20 +0530340 onuDeviceEntry.pMibDownloadFsm = NewAdapterFsm("MibDownload", deviceID, mibDownloadChan)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000341 onuDeviceEntry.pMibDownloadFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000342 dlStDisabled,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000343 fsm.Events{
344
mpagenko1cc3cb42020-07-27 15:24:38 +0000345 {Name: dlEvStart, Src: []string{dlStDisabled}, Dst: dlStStarting},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000346
mpagenko1cc3cb42020-07-27 15:24:38 +0000347 {Name: dlEvCreateGal, Src: []string{dlStStarting}, Dst: dlStCreatingGal},
348 {Name: dlEvRxGalResp, Src: []string{dlStCreatingGal}, Dst: dlStSettingOnu2g},
349 {Name: dlEvRxOnu2gResp, Src: []string{dlStSettingOnu2g}, Dst: dlStBridgeInit},
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000350 // the bridge state is used for multi ME config for alle UNI related ports
351 // maybe such could be reflected in the state machine as well (port number parametrized)
352 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
mpagenko1cc3cb42020-07-27 15:24:38 +0000353 {Name: dlEvRxBridgeResp, Src: []string{dlStBridgeInit}, Dst: dlStDownloaded},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000354
mpagenko1cc3cb42020-07-27 15:24:38 +0000355 {Name: dlEvTimeoutSimple, Src: []string{dlStCreatingGal, dlStSettingOnu2g}, Dst: dlStStarting},
356 {Name: dlEvTimeoutBridge, Src: []string{dlStBridgeInit}, Dst: dlStStarting},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000357
mpagenko1cc3cb42020-07-27 15:24:38 +0000358 {Name: dlEvReset, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g,
359 dlStBridgeInit, dlStDownloaded}, Dst: dlStResetting},
360 // exceptional treatment for all states except dlStResetting
361 {Name: dlEvRestart, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g,
362 dlStBridgeInit, dlStDownloaded, dlStResetting}, Dst: dlStDisabled},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000363 },
364
365 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000366 "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(e) },
367 ("enter_" + dlStStarting): func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(e) },
368 ("enter_" + dlStCreatingGal): func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(e) },
369 ("enter_" + dlStSettingOnu2g): func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(e) },
370 ("enter_" + dlStBridgeInit): func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(e) },
371 ("enter_" + dlStDownloaded): func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(e) },
372 ("enter_" + dlStResetting): func(e *fsm.Event) { onuDeviceEntry.enterResettingState(e) },
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000373 },
374 )
375 if onuDeviceEntry.pMibDownloadFsm == nil || onuDeviceEntry.pMibDownloadFsm.pFsm == nil {
376 logger.Error("MibDownloadFsm could not be instantiated!!")
377 // some specifc error treatment - or waiting for crash ???
378 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000379
Himani Chawla6d2ae152020-09-02 13:11:20 +0530380 onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(cBasePathMibTemplateKvStore)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000381 if onuDeviceEntry.mibTemplateKVStore == nil {
Himani Chawla26e555c2020-08-31 12:30:20 +0530382 logger.Errorw("Failed to setup mibTemplateKVStore", log.Fields{"device-id": deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000383 }
384
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000385 // Alarm Synchronization Database
386 //self._alarm_db = None
387 //self._alarm_database_cls = support_classes['alarm-synchronizer']['database']
388 return &onuDeviceEntry
389}
390
Himani Chawla6d2ae152020-09-02 13:11:20 +0530391//start starts (logs) the omci agent
392func (oo *OnuDeviceEntry) start(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000393 logger.Info("starting-OnuDeviceEntry")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000394
Himani Chawla6d2ae152020-09-02 13:11:20 +0530395 oo.PDevOmciCC = newOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000396 oo.coreProxy, oo.adapterProxy)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000397 if oo.PDevOmciCC == nil {
divyadesai4d299552020-08-18 07:13:49 +0000398 logger.Errorw("Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530399 return errors.New("could not create devOmciCc")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000400 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000401
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000402 oo.started = true
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000403 logger.Info("OnuDeviceEntry-started")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000404 return nil
405}
406
Himani Chawla6d2ae152020-09-02 13:11:20 +0530407//stop terminates the session
408func (oo *OnuDeviceEntry) stop(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000409 logger.Info("stopping-OnuDeviceEntry")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000410 oo.started = false
411 //oo.exitChannel <- 1
mpagenko3af1f032020-06-10 08:53:41 +0000412 // maybe also the omciCC should be stopped here - for now not as no real processing is expected here - maybe needs consolidation
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000413 logger.Info("OnuDeviceEntry-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000414 return nil
415}
416
Himani Chawla6d2ae152020-09-02 13:11:20 +0530417func (oo *OnuDeviceEntry) reboot(ctx context.Context) error {
ozgecanetsiae11479f2020-07-06 09:44:47 +0300418 logger.Info("reboot-OnuDeviceEntry")
419 if err := oo.PDevOmciCC.sendReboot(context.TODO(), ConstDefaultOmciTimeout, true, oo.omciRebootMessageReceivedChannel); err != nil {
divyadesai4d299552020-08-18 07:13:49 +0000420 logger.Errorw("onu didn't reboot", log.Fields{"for device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300421 return err
422 }
423 logger.Info("OnuDeviceEntry-reboot")
424 return nil
425}
426
427func (oo *OnuDeviceEntry) waitForRebootResponse(responseChannel chan Message) error {
428 select {
429 case <-time.After(3 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
430 logger.Warnw("Reboot timeout", log.Fields{"for device-id": oo.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530431 return errors.New("rebootTimeout")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300432 case data := <-responseChannel:
433 switch data.Data.(OmciMessage).OmciMsg.MessageType {
434 case omci.RebootResponseType:
435 {
436 msgLayer := (*data.Data.(OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse)
437 if msgLayer == nil {
Himani Chawla26e555c2020-08-31 12:30:20 +0530438 return errors.New("omci Msg layer could not be detected for RebootResponseType")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300439 }
440 msgObj, msgOk := msgLayer.(*omci.GetResponse)
441 if !msgOk {
Himani Chawla26e555c2020-08-31 12:30:20 +0530442 return errors.New("omci Msg layer could not be assigned for RebootResponseType")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300443 }
divyadesai4d299552020-08-18 07:13:49 +0000444 logger.Debugw("CreateResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300445 if msgObj.Result != me.Success {
446 logger.Errorw("Omci RebootResponseType Error ", log.Fields{"Error": msgObj.Result})
447 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
Himani Chawla26e555c2020-08-31 12:30:20 +0530448 return errors.New("omci RebootResponse Result Error indication")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300449 }
450 return nil
451 }
452 }
453 logger.Warnw("Reboot response error", log.Fields{"for device-id": oo.deviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530454 return errors.New("unexpected OmciResponse type received")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300455 }
456}
457
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000458//Relay the InSync message via Handler to Rw core - Status update
Himani Chawla26e555c2020-08-31 12:30:20 +0530459func (oo *OnuDeviceEntry) transferSystemEvent(devEvent OnuDeviceEvent) {
460 logger.Debugw("relaying system-event", log.Fields{"Event": devEvent})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000461 // decouple the handler transfer from further processing here
462 // TODO!!! check if really no synch is required within the system e.g. to ensure following steps ..
Himani Chawla26e555c2020-08-31 12:30:20 +0530463 if devEvent == MibDatabaseSync {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000464 if oo.devState < MibDatabaseSync { //devState has not been synced yet
465 oo.devState = MibDatabaseSync
Himani Chawla6d2ae152020-09-02 13:11:20 +0530466 go oo.baseDeviceHandler.deviceProcStatusUpdate(devEvent)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000467 //TODO!!! device control: next step: start MIB capability verification from here ?!!!
468 } else {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000469 logger.Debugw("mibinsync-event in some already synced state - ignored", log.Fields{"state": oo.devState})
470 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530471 } else if devEvent == MibDownloadDone {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000472 if oo.devState < MibDownloadDone { //devState has not been synced yet
473 oo.devState = MibDownloadDone
Himani Chawla6d2ae152020-09-02 13:11:20 +0530474 go oo.baseDeviceHandler.deviceProcStatusUpdate(devEvent)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000475 } else {
476 logger.Debugw("mibdownloaddone-event was already seen - ignored", log.Fields{"state": oo.devState})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000477 }
478 } else {
Himani Chawla26e555c2020-08-31 12:30:20 +0530479 logger.Warnw("device-event not yet handled", log.Fields{"state": devEvent})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000480 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000481}