blob: dfb056bc46bb8db531c7d444265cce8f3c860ccb [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
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000109type OnuDeviceEvent int
110
111const (
112 // Events of interest to Device Adapters and OpenOMCI State Machines
mpagenkodff5dda2020-08-28 11:52:01 +0000113 DeviceStatusInit OnuDeviceEvent = 0 // OnuDeviceEntry default start state
114 MibDatabaseSync OnuDeviceEvent = 1 // MIB database sync (upload done)
115 OmciCapabilitiesDone OnuDeviceEvent = 2 // OMCI ME and message type capabilities known
116 MibDownloadDone OnuDeviceEvent = 3 // MIB database sync (upload done)
117 UniLockStateDone OnuDeviceEvent = 4 // Uni ports admin set to lock
118 UniUnlockStateDone OnuDeviceEvent = 5 // Uni ports admin set to unlock
119 UniAdminStateDone OnuDeviceEvent = 6 // Uni ports admin set done - general
120 PortLinkUp OnuDeviceEvent = 7 // Port link state change
121 PortLinkDw OnuDeviceEvent = 8 // Port link state change
122 OmciAniConfigDone OnuDeviceEvent = 9 // AniSide config according to TechProfile done
123 OmciVlanFilterDone OnuDeviceEvent = 10 // Omci Vlan config according to flowConfig done
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000124 // Add other events here as needed (alarms separate???)
125)
126
127type activityDescr struct {
Himani Chawla4d908332020-08-31 12:30:20 +0530128 databaseClass func() error
129 //advertiseEvents bool
130 auditDelay uint16
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000131 //tasks map[string]func() error
132}
133type OmciDeviceFsms map[string]activityDescr
134
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000135type AdapterFsm struct {
136 fsmName string
137 deviceID string
138 commChan chan Message
139 pFsm *fsm.FSM
140}
141
142func NewAdapterFsm(a_name string, a_deviceID string, a_commChannel chan Message) *AdapterFsm {
143 aFsm := &AdapterFsm{
144 fsmName: a_name,
145 deviceID: a_deviceID,
146 commChan: a_commChannel,
147 }
148 return aFsm
149}
150
151//Start starts (logs) the omci agent
152func (oo *AdapterFsm) logFsmStateChange(e *fsm.Event) {
153 logger.Debugw("FSM state change", log.Fields{"device-id": oo.deviceID, "FSM name": oo.fsmName,
154 "event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst)})
155}
156
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000157//OntDeviceEntry structure holds information about the attached FSM'as and their communication
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000158
159const (
Himani Chawla4d908332020-08-31 12:30:20 +0530160 FirstSwImageMeID = 0
161 SecondSwImageMeID = 1
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000162)
Himani Chawla4d908332020-08-31 12:30:20 +0530163const OnugMeID = 0
164const Onu2gMeID = 0
165const IPHostConfigDataMeID = 1
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000166const OnugSerialNumberLen = 8
167const OmciMacAddressLen = 6
168
169type SwImages struct {
170 version string
171 isActive uint8
172}
173
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000174type OnuDeviceEntry struct {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000175 deviceID string
176 baseDeviceHandler *DeviceHandler
177 coreProxy adapterif.CoreProxy
178 adapterProxy adapterif.AdapterProxy
179 started bool
180 PDevOmciCC *OmciCC
181 pOnuDB *OnuDeviceDB
182 mibTemplateKVStore *db.Backend
183 vendorID string
184 serialNumber string
185 equipmentID string
Himani Chawla4d908332020-08-31 12:30:20 +0530186 swImages [SecondSwImageMeID + 1]SwImages
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000187 activeSwVersion string
188 macAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000189 //lockDeviceEntries sync.RWMutex
190 mibDbClass func() error
191 supportedFsms OmciDeviceFsms
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000192 devState OnuDeviceEvent
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000193 // for mibUpload
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000194 mibAuditDelay uint16
mpagenko1cc3cb42020-07-27 15:24:38 +0000195 mibDebugLevel string
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000196
197 // for mibUpload
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000198 pMibUploadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
199 // for mibDownload
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000200 pMibDownloadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
201 //remark: general usage of pAdapterFsm would require generalization of commChan usage and internal event setting
202 // within the FSM event procedures
ozgecanetsiae11479f2020-07-06 09:44:47 +0300203 omciMessageReceived chan bool //seperate channel needed by DownloadFsm
204 omciRebootMessageReceivedChannel chan Message // channel needed by Reboot request
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000205}
206
207//OnuDeviceEntry returns a new instance of a OnuDeviceEntry
208//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000209func NewOnuDeviceEntry(ctx context.Context, device_id string, kVStoreHost string, kVStorePort int, kvStoreType string, device_Handler *DeviceHandler,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000210 core_proxy adapterif.CoreProxy, adapter_proxy adapterif.AdapterProxy,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000211 supported_Fsms_Ptr *OmciDeviceFsms) *OnuDeviceEntry {
divyadesai4d299552020-08-18 07:13:49 +0000212 logger.Infow("init-onuDeviceEntry", log.Fields{"device-id": device_id})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000213 var onuDeviceEntry OnuDeviceEntry
214 onuDeviceEntry.started = false
215 onuDeviceEntry.deviceID = device_id
216 onuDeviceEntry.baseDeviceHandler = device_Handler
217 onuDeviceEntry.coreProxy = core_proxy
218 onuDeviceEntry.adapterProxy = adapter_proxy
219 onuDeviceEntry.devState = DeviceStatusInit
ozgecanetsiae11479f2020-07-06 09:44:47 +0300220 onuDeviceEntry.omciRebootMessageReceivedChannel = make(chan Message, 2048)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000221 //openomciagent.lockDeviceHandlersMap = sync.RWMutex{}
222 //OMCI related databases are on a per-agent basis. State machines and tasks
223 //are per ONU Vendor
224 //
225 // MIB Synchronization Database - possible overloading from arguments
226 if supported_Fsms_Ptr != nil {
227 onuDeviceEntry.supportedFsms = *supported_Fsms_Ptr
228 } else {
229 //var mibSyncFsm = NewMibSynchronizer()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000230 // use some internaö defaults, if not defined from outside
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000231 onuDeviceEntry.supportedFsms = OmciDeviceFsms{
232 "mib-synchronizer": {
233 //mibSyncFsm, // Implements the MIB synchronization state machine
234 onuDeviceEntry.MibDbVolatileDict, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +0530235 //true, // Advertise events on OpenOMCI event bus
236 60, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000237 // map[string]func() error{
238 // "mib-upload": onuDeviceEntry.MibUploadTask,
239 // "mib-template": onuDeviceEntry.MibTemplateTask,
240 // "get-mds": onuDeviceEntry.GetMdsTask,
241 // "mib-audit": onuDeviceEntry.GetMdsTask,
242 // "mib-resync": onuDeviceEntry.MibResyncTask,
243 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
244 // },
245 },
246 }
247 }
248 onuDeviceEntry.mibDbClass = onuDeviceEntry.supportedFsms["mib-synchronizer"].databaseClass
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000249 logger.Debug("access2mibDbClass")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000250 go onuDeviceEntry.mibDbClass()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000251 onuDeviceEntry.mibAuditDelay = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditDelay
252 logger.Debugw("MibAudit is set to", log.Fields{"Delay": onuDeviceEntry.mibAuditDelay})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000253
mpagenko1cc3cb42020-07-27 15:24:38 +0000254 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 +0000255 // Omci related Mib upload sync state machine
256 mibUploadChan := make(chan Message, 2048)
257 onuDeviceEntry.pMibUploadFsm = NewAdapterFsm("MibUpload", device_id, mibUploadChan)
258 onuDeviceEntry.pMibUploadFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000259 ulStDisabled,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000260 fsm.Events{
261
mpagenko1cc3cb42020-07-27 15:24:38 +0000262 {Name: ulEvStart, Src: []string{ulStDisabled}, Dst: ulStStarting},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000263
mpagenko1cc3cb42020-07-27 15:24:38 +0000264 {Name: ulEvResetMib, Src: []string{ulStStarting}, Dst: ulStResettingMib},
265 {Name: ulEvGetVendorAndSerial, Src: []string{ulStResettingMib}, Dst: ulStGettingVendorAndSerial},
Himani Chawla4d908332020-08-31 12:30:20 +0530266 {Name: ulEvGetEquipmentID, Src: []string{ulStGettingVendorAndSerial}, Dst: ulStGettingEquipmentID},
267 {Name: ulEvGetFirstSwVersion, Src: []string{ulStGettingEquipmentID}, Dst: ulStGettingFirstSwVersion},
mpagenko1cc3cb42020-07-27 15:24:38 +0000268 {Name: ulEvGetSecondSwVersion, Src: []string{ulStGettingFirstSwVersion}, Dst: ulStGettingSecondSwVersion},
269 {Name: ulEvGetMacAddress, Src: []string{ulStGettingSecondSwVersion}, Dst: ulStGettingMacAddress},
270 {Name: ulEvGetMibTemplate, Src: []string{ulStGettingMacAddress}, Dst: ulStGettingMibTemplate},
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000271
mpagenko1cc3cb42020-07-27 15:24:38 +0000272 {Name: ulEvUploadMib, Src: []string{ulStGettingMibTemplate}, Dst: ulStUploading},
273 {Name: ulEvExamineMds, Src: []string{ulStStarting}, Dst: ulStExaminingMds},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000274
mpagenko1cc3cb42020-07-27 15:24:38 +0000275 {Name: ulEvSuccess, Src: []string{ulStGettingMibTemplate}, Dst: ulStInSync},
276 {Name: ulEvSuccess, Src: []string{ulStUploading}, Dst: ulStInSync},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000277
mpagenko1cc3cb42020-07-27 15:24:38 +0000278 {Name: ulEvSuccess, Src: []string{ulStExaminingMds}, Dst: ulStInSync},
279 {Name: ulEvMismatch, Src: []string{ulStExaminingMds}, Dst: ulStResynchronizing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000280
mpagenko1cc3cb42020-07-27 15:24:38 +0000281 {Name: ulEvAuditMib, Src: []string{ulStInSync}, Dst: ulStAuditing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000282
mpagenko1cc3cb42020-07-27 15:24:38 +0000283 {Name: ulEvSuccess, Src: []string{ulStOutOfSync}, Dst: ulStInSync},
284 {Name: ulEvAuditMib, Src: []string{ulStOutOfSync}, Dst: ulStAuditing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000285
mpagenko1cc3cb42020-07-27 15:24:38 +0000286 {Name: ulEvSuccess, Src: []string{ulStAuditing}, Dst: ulStInSync},
287 {Name: ulEvMismatch, Src: []string{ulStAuditing}, Dst: ulStResynchronizing},
288 {Name: ulEvForceResync, Src: []string{ulStAuditing}, Dst: ulStResynchronizing},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000289
mpagenko1cc3cb42020-07-27 15:24:38 +0000290 {Name: ulEvSuccess, Src: []string{ulStResynchronizing}, Dst: ulStInSync},
291 {Name: ulEvDiffsFound, Src: []string{ulStResynchronizing}, Dst: ulStOutOfSync},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000292
Himani Chawla4d908332020-08-31 12:30:20 +0530293 {Name: ulEvTimeout, Src: []string{ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion,
mpagenko1cc3cb42020-07-27 15:24:38 +0000294 ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds,
295 ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStStarting},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000296
Himani Chawla4d908332020-08-31 12:30:20 +0530297 {Name: ulEvStop, Src: []string{ulStStarting, ulStResettingMib, ulStGettingVendorAndSerial, ulStGettingEquipmentID, ulStGettingFirstSwVersion,
mpagenko1cc3cb42020-07-27 15:24:38 +0000298 ulStGettingSecondSwVersion, ulStGettingMacAddress, ulStGettingMibTemplate, ulStUploading, ulStResynchronizing, ulStExaminingMds,
299 ulStInSync, ulStOutOfSync, ulStAuditing}, Dst: ulStDisabled},
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000300 },
301
302 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000303 "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibUploadFsm.logFsmStateChange(e) },
304 ("enter_" + ulStStarting): func(e *fsm.Event) { onuDeviceEntry.enterStartingState(e) },
305 ("enter_" + ulStResettingMib): func(e *fsm.Event) { onuDeviceEntry.enterResettingMibState(e) },
306 ("enter_" + ulStGettingVendorAndSerial): func(e *fsm.Event) { onuDeviceEntry.enterGettingVendorAndSerialState(e) },
Himani Chawla4d908332020-08-31 12:30:20 +0530307 ("enter_" + ulStGettingEquipmentID): func(e *fsm.Event) { onuDeviceEntry.enterGettingEquipmentIDState(e) },
mpagenko1cc3cb42020-07-27 15:24:38 +0000308 ("enter_" + ulStGettingFirstSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingFirstSwVersionState(e) },
309 ("enter_" + ulStGettingSecondSwVersion): func(e *fsm.Event) { onuDeviceEntry.enterGettingSecondSwVersionState(e) },
310 ("enter_" + ulStGettingMacAddress): func(e *fsm.Event) { onuDeviceEntry.enterGettingMacAddressState(e) },
311 ("enter_" + ulStGettingMibTemplate): func(e *fsm.Event) { onuDeviceEntry.enterGettingMibTemplate(e) },
312 ("enter_" + ulStUploading): func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(e) },
313 ("enter_" + ulStExaminingMds): func(e *fsm.Event) { onuDeviceEntry.enterExaminingMdsState(e) },
314 ("enter_" + ulStResynchronizing): func(e *fsm.Event) { onuDeviceEntry.enterResynchronizingState(e) },
315 ("enter_" + ulStAuditing): func(e *fsm.Event) { onuDeviceEntry.enterAuditingState(e) },
316 ("enter_" + ulStOutOfSync): func(e *fsm.Event) { onuDeviceEntry.enterOutOfSyncState(e) },
317 ("enter_" + ulStInSync): func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(e) },
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000318 },
319 )
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000320 // Omci related Mib download state machine
321 mibDownloadChan := make(chan Message, 2048)
322 onuDeviceEntry.pMibDownloadFsm = NewAdapterFsm("MibDownload", device_id, mibDownloadChan)
323 onuDeviceEntry.pMibDownloadFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000324 dlStDisabled,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000325 fsm.Events{
326
mpagenko1cc3cb42020-07-27 15:24:38 +0000327 {Name: dlEvStart, Src: []string{dlStDisabled}, Dst: dlStStarting},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000328
mpagenko1cc3cb42020-07-27 15:24:38 +0000329 {Name: dlEvCreateGal, Src: []string{dlStStarting}, Dst: dlStCreatingGal},
330 {Name: dlEvRxGalResp, Src: []string{dlStCreatingGal}, Dst: dlStSettingOnu2g},
331 {Name: dlEvRxOnu2gResp, Src: []string{dlStSettingOnu2g}, Dst: dlStBridgeInit},
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000332 // the bridge state is used for multi ME config for alle UNI related ports
333 // maybe such could be reflected in the state machine as well (port number parametrized)
334 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
mpagenko1cc3cb42020-07-27 15:24:38 +0000335 {Name: dlEvRxBridgeResp, Src: []string{dlStBridgeInit}, Dst: dlStDownloaded},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000336
mpagenko1cc3cb42020-07-27 15:24:38 +0000337 {Name: dlEvTimeoutSimple, Src: []string{dlStCreatingGal, dlStSettingOnu2g}, Dst: dlStStarting},
338 {Name: dlEvTimeoutBridge, Src: []string{dlStBridgeInit}, Dst: dlStStarting},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000339
mpagenko1cc3cb42020-07-27 15:24:38 +0000340 {Name: dlEvReset, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g,
341 dlStBridgeInit, dlStDownloaded}, Dst: dlStResetting},
342 // exceptional treatment for all states except dlStResetting
343 {Name: dlEvRestart, Src: []string{dlStStarting, dlStCreatingGal, dlStSettingOnu2g,
344 dlStBridgeInit, dlStDownloaded, dlStResetting}, Dst: dlStDisabled},
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000345 },
346
347 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000348 "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(e) },
349 ("enter_" + dlStStarting): func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(e) },
350 ("enter_" + dlStCreatingGal): func(e *fsm.Event) { onuDeviceEntry.enterCreatingGalState(e) },
351 ("enter_" + dlStSettingOnu2g): func(e *fsm.Event) { onuDeviceEntry.enterSettingOnu2gState(e) },
352 ("enter_" + dlStBridgeInit): func(e *fsm.Event) { onuDeviceEntry.enterBridgeInitState(e) },
353 ("enter_" + dlStDownloaded): func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(e) },
354 ("enter_" + dlStResetting): func(e *fsm.Event) { onuDeviceEntry.enterResettingState(e) },
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000355 },
356 )
357 if onuDeviceEntry.pMibDownloadFsm == nil || onuDeviceEntry.pMibDownloadFsm.pFsm == nil {
358 logger.Error("MibDownloadFsm could not be instantiated!!")
359 // some specifc error treatment - or waiting for crash ???
360 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000361
mpagenkoaf801632020-07-03 10:00:42 +0000362 onuDeviceEntry.mibTemplateKVStore = onuDeviceEntry.baseDeviceHandler.SetBackend(cBasePathMibTemplateKvStore)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000363 if onuDeviceEntry.mibTemplateKVStore == nil {
divyadesai4d299552020-08-18 07:13:49 +0000364 logger.Errorw("Failed to setup mibTemplateKVStore", log.Fields{"device-id": device_id})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000365 }
366
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000367 // Alarm Synchronization Database
368 //self._alarm_db = None
369 //self._alarm_database_cls = support_classes['alarm-synchronizer']['database']
370 return &onuDeviceEntry
371}
372
373//Start starts (logs) the omci agent
374func (oo *OnuDeviceEntry) Start(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000375 logger.Info("starting-OnuDeviceEntry")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000376
377 oo.PDevOmciCC = NewOmciCC(ctx, oo, oo.deviceID, oo.baseDeviceHandler,
378 oo.coreProxy, oo.adapterProxy)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000379 if oo.PDevOmciCC == nil {
divyadesai4d299552020-08-18 07:13:49 +0000380 logger.Errorw("Could not create devOmciCc - abort", log.Fields{"for device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000381 return errors.New("Could not create devOmciCc")
382 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000383
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000384 oo.started = true
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000385 logger.Info("OnuDeviceEntry-started")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000386 return nil
387}
388
389//Stop terminates the session
390func (oo *OnuDeviceEntry) Stop(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000391 logger.Info("stopping-OnuDeviceEntry")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000392 oo.started = false
393 //oo.exitChannel <- 1
mpagenko3af1f032020-06-10 08:53:41 +0000394 // 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 +0000395 logger.Info("OnuDeviceEntry-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000396 return nil
397}
398
ozgecanetsiae11479f2020-07-06 09:44:47 +0300399func (oo *OnuDeviceEntry) Reboot(ctx context.Context) error {
400 logger.Info("reboot-OnuDeviceEntry")
401 if err := oo.PDevOmciCC.sendReboot(context.TODO(), ConstDefaultOmciTimeout, true, oo.omciRebootMessageReceivedChannel); err != nil {
divyadesai4d299552020-08-18 07:13:49 +0000402 logger.Errorw("onu didn't reboot", log.Fields{"for device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300403 return err
404 }
405 logger.Info("OnuDeviceEntry-reboot")
406 return nil
407}
408
409func (oo *OnuDeviceEntry) waitForRebootResponse(responseChannel chan Message) error {
410 select {
411 case <-time.After(3 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
412 logger.Warnw("Reboot timeout", log.Fields{"for device-id": oo.deviceID})
413 return errors.New("RebootTimeout")
414 case data := <-responseChannel:
415 switch data.Data.(OmciMessage).OmciMsg.MessageType {
416 case omci.RebootResponseType:
417 {
418 msgLayer := (*data.Data.(OmciMessage).OmciPacket).Layer(omci.LayerTypeRebootResponse)
419 if msgLayer == nil {
420 return errors.New("Omci Msg layer could not be detected for RebootResponseType")
421 }
422 msgObj, msgOk := msgLayer.(*omci.GetResponse)
423 if !msgOk {
424 return errors.New("Omci Msg layer could not be assigned for RebootResponseType")
425 }
divyadesai4d299552020-08-18 07:13:49 +0000426 logger.Debugw("CreateResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300427 if msgObj.Result != me.Success {
428 logger.Errorw("Omci RebootResponseType Error ", log.Fields{"Error": msgObj.Result})
429 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
430 return errors.New("Omci RebootResponse Result Error indication")
431 }
432 return nil
433 }
434 }
435 logger.Warnw("Reboot response error", log.Fields{"for device-id": oo.deviceID})
436 return errors.New("Unexpected OmciResponse type received")
437 }
438}
439
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000440//Relay the InSync message via Handler to Rw core - Status update
Himani Chawla4d908332020-08-31 12:30:20 +0530441func (oo *OnuDeviceEntry) transferSystemEvent(dev_Event OnuDeviceEvent) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000442 logger.Debugw("relaying system-event", log.Fields{"Event": dev_Event})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000443 // decouple the handler transfer from further processing here
444 // TODO!!! check if really no synch is required within the system e.g. to ensure following steps ..
445 if dev_Event == MibDatabaseSync {
446 if oo.devState < MibDatabaseSync { //devState has not been synced yet
447 oo.devState = MibDatabaseSync
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000448 go oo.baseDeviceHandler.DeviceProcStatusUpdate(dev_Event)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000449 //TODO!!! device control: next step: start MIB capability verification from here ?!!!
450 } else {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000451 logger.Debugw("mibinsync-event in some already synced state - ignored", log.Fields{"state": oo.devState})
452 }
453 } else if dev_Event == MibDownloadDone {
454 if oo.devState < MibDownloadDone { //devState has not been synced yet
455 oo.devState = MibDownloadDone
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000456 go oo.baseDeviceHandler.DeviceProcStatusUpdate(dev_Event)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000457 } else {
458 logger.Debugw("mibdownloaddone-event was already seen - ignored", log.Fields{"state": oo.devState})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000459 }
460 } else {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000461 logger.Warnw("device-event not yet handled", log.Fields{"state": dev_Event})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000462 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000463}