blob: 9a01ae3f8e01b669d8a8388e46762cb3e9b19b99 [file] [log] [blame]
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +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 adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
19
20import (
Holger Hildebrandt2fb70892020-10-28 11:53:18 +000021 "bytes"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000022 "context"
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000023 "encoding/hex"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000024 "encoding/json"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000025 "errors"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000026 "fmt"
27 "strconv"
mpagenko3af1f032020-06-10 08:53:41 +000028 "strings"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000029
30 "github.com/looplab/fsm"
31
32 //"sync"
divyadesaibbed37c2020-08-28 13:35:20 +053033 "time"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000034
dbainbri4d3a0dc2020-12-02 00:33:42 +000035 //"github.com/opencord/voltha-lib-go/v4/pkg/kafka"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000036 "github.com/opencord/omci-lib-go"
37 me "github.com/opencord/omci-lib-go/generated"
dbainbri4d3a0dc2020-12-02 00:33:42 +000038 "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore"
39 "github.com/opencord/voltha-lib-go/v4/pkg/log"
40 //ic "github.com/opencord/voltha-protos/v4/go/inter_container"
41 //"github.com/opencord/voltha-protos/v4/go/openflow_13"
42 //"github.com/opencord/voltha-protos/v4/go/voltha"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000043)
44
mpagenko01499812021-03-25 10:37:12 +000045type sLastTxMeParameter struct {
46 lastTxMessageType omci.MessageType
47 pLastTxMeInstance *me.ManagedEntity
48 repeatCount uint8
49}
50
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000051var supportedClassIds = []me.ClassID{
52 me.CardholderClassID, // 5
53 me.CircuitPackClassID, // 6
54 me.SoftwareImageClassID, // 7
55 me.PhysicalPathTerminationPointEthernetUniClassID, // 11
56 me.OltGClassID, // 131
57 me.OnuPowerSheddingClassID, // 133
58 me.IpHostConfigDataClassID, // 134
59 me.OnuGClassID, // 256
60 me.Onu2GClassID, // 257
61 me.TContClassID, // 262
62 me.AniGClassID, // 263
63 me.UniGClassID, // 264
64 me.PriorityQueueClassID, // 277
65 me.TrafficSchedulerClassID, // 278
66 me.VirtualEthernetInterfacePointClassID, // 329
67 me.EnhancedSecurityControlClassID, // 332
68 me.OnuDynamicPowerManagementControlClassID, // 336
69 // 347 // definitions for ME "IPv6 host config data" are currently missing in omci-lib-go!
70}
71
72var fsmMsg TestMessageType
73
dbainbri4d3a0dc2020-12-02 00:33:42 +000074func (oo *OnuDeviceEntry) enterStartingState(ctx context.Context, e *fsm.Event) {
75 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": oo.deviceID})
76 oo.pOnuDB = newOnuDeviceDB(log.WithSpanFromContext(context.TODO(), ctx), oo)
77 go oo.processMibSyncMessages(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000078}
79
dbainbri4d3a0dc2020-12-02 00:33:42 +000080func (oo *OnuDeviceEntry) enterResettingMibState(ctx context.Context, e *fsm.Event) {
81 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibTemplate processing in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000082
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +000083 if !oo.isNewOnu() && !oo.baseDeviceHandler.isReconciling() {
Holger Hildebrandt10d98192021-01-27 15:29:31 +000084 oo.baseDeviceHandler.prepareReconcilingWithActiveAdapter(ctx)
85 oo.devState = DeviceStatusInit
86 }
dbainbri4d3a0dc2020-12-02 00:33:42 +000087 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send mibReset in State": e.FSM.Current(), "device-id": oo.deviceID})
Girish Gowdra0b235842021-03-09 13:06:46 -080088 _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000089 //TODO: needs to handle timeouts
mpagenko01499812021-03-25 10:37:12 +000090 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
91 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
92 oo.lastTxParamStruct.lastTxMessageType = omci.MibResetRequestType
93 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000094}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000095
dbainbri4d3a0dc2020-12-02 00:33:42 +000096func (oo *OnuDeviceEntry) enterGettingVendorAndSerialState(ctx context.Context, e *fsm.Event) {
97 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting VendorId and SerialNumber in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000098 requestedAttributes := me.AttributeValueMap{"VendorId": "", "SerialNumber": 0}
Girish Gowdra0b235842021-03-09 13:06:46 -080099 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.OnuGClassID, onugMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000100 //accept also nil as (error) return value for writing to LastTx
101 // - this avoids misinterpretation of new received OMCI messages
mpagenko01499812021-03-25 10:37:12 +0000102 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
103 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000104}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000105
dbainbri4d3a0dc2020-12-02 00:33:42 +0000106func (oo *OnuDeviceEntry) enterGettingEquipmentIDState(ctx context.Context, e *fsm.Event) {
107 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting EquipmentId in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000108 requestedAttributes := me.AttributeValueMap{"EquipmentId": ""}
Girish Gowdra0b235842021-03-09 13:06:46 -0800109 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.Onu2GClassID, onu2gMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000110 //accept also nil as (error) return value for writing to LastTx
111 // - this avoids misinterpretation of new received OMCI messages
mpagenko01499812021-03-25 10:37:12 +0000112 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
113 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000114}
115
dbainbri4d3a0dc2020-12-02 00:33:42 +0000116func (oo *OnuDeviceEntry) enterGettingFirstSwVersionState(ctx context.Context, e *fsm.Event) {
117 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting IsActive and Version of first SW-image in State": e.FSM.Current(), "device-id": oo.deviceID})
mpagenko15ff4a52021-03-02 10:09:20 +0000118 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Girish Gowdra0b235842021-03-09 13:06:46 -0800119 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, firstSwImageMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000120 //accept also nil as (error) return value for writing to LastTx
121 // - this avoids misinterpretation of new received OMCI messages
mpagenko01499812021-03-25 10:37:12 +0000122 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
123 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000124}
125
dbainbri4d3a0dc2020-12-02 00:33:42 +0000126func (oo *OnuDeviceEntry) enterGettingSecondSwVersionState(ctx context.Context, e *fsm.Event) {
127 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting IsActive and Version of second SW-image in State": e.FSM.Current(), "device-id": oo.deviceID})
mpagenko15ff4a52021-03-02 10:09:20 +0000128 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Girish Gowdra0b235842021-03-09 13:06:46 -0800129 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, secondSwImageMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000130 //accept also nil as (error) return value for writing to LastTx
131 // - this avoids misinterpretation of new received OMCI messages
mpagenko01499812021-03-25 10:37:12 +0000132 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
133 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000134}
135
dbainbri4d3a0dc2020-12-02 00:33:42 +0000136func (oo *OnuDeviceEntry) enterGettingMacAddressState(ctx context.Context, e *fsm.Event) {
137 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting MacAddress in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000138 requestedAttributes := me.AttributeValueMap{"MacAddress": ""}
Girish Gowdra0b235842021-03-09 13:06:46 -0800139 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.IpHostConfigDataClassID, ipHostConfigDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000140 //accept also nil as (error) return value for writing to LastTx
141 // - this avoids misinterpretation of new received OMCI messages
mpagenko01499812021-03-25 10:37:12 +0000142 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
143 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000144}
145
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000146func (oo *OnuDeviceEntry) enterGettingMibTemplateState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000147
mpagenko15ff4a52021-03-02 10:09:20 +0000148 if oo.onuSwImageIndications.activeEntityEntry.valid {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000149 oo.sOnuPersistentData.PersActiveSwVersion = oo.onuSwImageIndications.activeEntityEntry.version
mpagenko15ff4a52021-03-02 10:09:20 +0000150 } else {
151 logger.Errorw(ctx, "get-mib-template: no active SW version found, working with empty SW version, which might be untrustworthy",
152 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000153 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000154 if oo.getMibFromTemplate(ctx) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000155 logger.Debug(ctx, "MibSync FSM - valid MEs stored from template")
156 oo.pOnuDB.logMeDb(ctx)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000157 fsmMsg = LoadMibTemplateOk
158 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000159 logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000160 fsmMsg = LoadMibTemplateFailed
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000161
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000162 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
163 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
164 if mibTemplateIsGenerated {
165 logger.Debugw(ctx,
166 "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map",
167 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
168 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
169 }
170 }
171 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
172 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000173 mibSyncMsg := Message{
174 Type: TestMsg,
175 Data: TestMessage{
176 TestMessageVal: fsmMsg,
177 },
178 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000179 oo.pMibUploadFsm.commChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000180}
181
dbainbri4d3a0dc2020-12-02 00:33:42 +0000182func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
183 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send MibUpload in State": e.FSM.Current(), "device-id": oo.deviceID})
Girish Gowdra0b235842021-03-09 13:06:46 -0800184 _ = oo.PDevOmciCC.sendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000185 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
186 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
187 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadRequestType
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000188}
189
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000190func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000191 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID})
192 oo.transferSystemEvent(ctx, MibDatabaseSync)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000193 go func() {
194 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
195 }()
196}
197
198func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
199 oo.sOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix())
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000200 if oo.mibAuditInterval > 0 {
201 logger.Debugw(ctx, "MibSync FSM", log.Fields{"trigger next Audit in State": e.FSM.Current(), "oo.mibAuditInterval": oo.mibAuditInterval, "device-id": oo.deviceID})
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000202 go func() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000203 time.Sleep(oo.mibAuditInterval)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000204 if err := oo.pMibUploadFsm.pFsm.Event(ulEvAuditMib); err != nil {
205 logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err})
206 }
207 }()
208 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000209}
210
dbainbri4d3a0dc2020-12-02 00:33:42 +0000211func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
212 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start GetMds processing in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000213 oo.requestMdsValue(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000214}
215
dbainbri4d3a0dc2020-12-02 00:33:42 +0000216func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
217 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
218 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000219 // TODOs:
220 // VOL-3805 - Provide exclusive OMCI channel for one FSM
221 // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go
222 // VOL-3792 - Support periodical audit via mib resync
223 // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000224}
225
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000226func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) {
227 logger.Debugw(ctx, "MibSync FSM",
228 log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID})
229
230 if oo.getMibFromTemplate(ctx) {
231 oo.baseDeviceHandler.startReconciling(ctx, true)
232 oo.baseDeviceHandler.addAllUniPorts(ctx)
233 oo.baseDeviceHandler.setDeviceReason(drInitialMibDownloaded)
234 oo.baseDeviceHandler.ReadyForSpecificOmciConfig = true
235 // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm
236
237 oo.baseDeviceHandler.reconcileDeviceTechProf(ctx)
238 if oo.baseDeviceHandler.isReconciling() {
239 oo.baseDeviceHandler.reconcileDeviceFlowConfig(ctx)
240 }
241 // set admin state independent of reconciling state after tp/flow reconcilement
242 if oo.sOnuPersistentData.PersUniDisableDone {
243 oo.baseDeviceHandler.disableUniPortStateUpdate(ctx)
244 oo.baseDeviceHandler.setDeviceReason(drOmciAdminLock)
245 } else {
246 oo.baseDeviceHandler.enableUniPortStateUpdate(ctx)
247 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000248 go func() {
Holger Hildebrandt1b8f4ad2021-03-25 15:53:51 +0000249 // Stopping reconcilement has to be delayed as in multi-ONU/multi-flow environment
250 // the parallel processing to rebuild the adapter internal flow data could still be
251 // running here. It will take only a few milliseconds until the corresponding threads
252 // will be finished as no OMCI-config is done in this use case.
253 // TODO: The timer approach should be replaced by a more sophisticated solution using
254 // a real interaction between this routine and the threads configuring the flow data
255 // after imminent release VOLTHA v2.7
256 time.Sleep(100 * time.Millisecond)
257 oo.baseDeviceHandler.stopReconciling(ctx)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000258 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
259 }()
260
261 } else {
262 logger.Debugw(ctx, "MibSync FSM",
263 log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID})
264 go func() {
265 //switch to reconciling with OMCI config
266 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
267 }()
268 }
269}
270
dbainbri4d3a0dc2020-12-02 00:33:42 +0000271func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000272 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibAudit processing in State": e.FSM.Current(), "device-id": oo.deviceID})
mpagenkof1fc3862021-02-16 10:09:52 +0000273 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000274 oo.requestMdsValue(ctx)
275 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000276 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Configuration is ongoing or missing - skip auditing!": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000277 go func() {
278 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
279 }()
280 }
281}
282
283func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
284 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start retest MdsValue processing in State": e.FSM.Current(), "device-id": oo.deviceID})
mpagenkof1fc3862021-02-16 10:09:52 +0000285 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000286 oo.requestMdsValue(ctx)
287 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000288 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Configuration is ongoing or missing - skip re-auditing!": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000289 go func() {
290 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
291 }()
292 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000293}
294
dbainbri4d3a0dc2020-12-02 00:33:42 +0000295func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
296 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
297 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000298}
299
dbainbri4d3a0dc2020-12-02 00:33:42 +0000300func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
301 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Start routine to process OMCI-messages for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000302loop:
303 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000304 // case <-ctx.Done():
305 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
306 // break loop
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000307 message, ok := <-oo.pMibUploadFsm.commChan
Himani Chawla4d908332020-08-31 12:30:20 +0530308 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000309 logger.Info(ctx, "MibSync Msg", log.Fields{"Message couldn't be read from channel for device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530310 break loop
311 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000312 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000313
Himani Chawla4d908332020-08-31 12:30:20 +0530314 switch message.Type {
315 case TestMsg:
316 msg, _ := message.Data.(TestMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000317 oo.handleTestMsg(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530318 case OMCI:
319 msg, _ := message.Data.(OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000320 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530321 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000322 logger.Warn(ctx, "MibSync Msg", log.Fields{"Unknown message type received for device-id": oo.deviceID, "message.Type": message.Type})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000323 }
324 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000325 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000326 // TODO: only this action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000327 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000328}
329
dbainbri4d3a0dc2020-12-02 00:33:42 +0000330func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000331
dbainbri4d3a0dc2020-12-02 00:33:42 +0000332 logger.Debugw(ctx, "MibSync Msg", log.Fields{"TestMessage received for device-id": oo.deviceID, "msg.TestMessageVal": msg.TestMessageVal})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000333
334 switch msg.TestMessageVal {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000335 case LoadMibTemplateFailed:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000336 _ = oo.pMibUploadFsm.pFsm.Event(ulEvUploadMib)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000337 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000338 case LoadMibTemplateOk:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000339 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000340 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000341 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000342 logger.Warn(ctx, "MibSync Msg", log.Fields{"Unknown message type received for device-id": oo.deviceID, "msg.TestMessageVal": msg.TestMessageVal})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000343 }
344}
345
dbainbri4d3a0dc2020-12-02 00:33:42 +0000346func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg OmciMessage) {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000347 if oo.pMibUploadFsm.pFsm.Is(ulStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530348 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
349 if msgLayer != nil {
350 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
351 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000352 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530353 if msgObj.Result == me.Success {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000354 oo.sOnuPersistentData.PersMibDataSyncAdpt = 0
Himani Chawla4d908332020-08-31 12:30:20 +0530355 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000356 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530357 return
358 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000359 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530360 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000361 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530362 }
363 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000364 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530365 }
366 } else {
mpagenko01499812021-03-25 10:37:12 +0000367 //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset
368 // with Sequence number 0x8000 as last request before - so it may still respond to that
369 // then we may force the ONU to react on the MdsGetRequest with a new message that uses an increased Sequence number
370 if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
371 logger.Debugw(ctx, "MibSync FSM - repeat MdsGetRequest (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
372 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
373 _ = oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
374 me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
375 //TODO: needs extra handling of timeouts
376 oo.lastTxParamStruct.repeatCount = 1
377 return
378 }
379 logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
380 //perhaps some still lingering message from some prior activity, let's wait for the real response
381 return
Himani Chawla4d908332020-08-31 12:30:20 +0530382 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000383 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000384 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530385}
386
dbainbri4d3a0dc2020-12-02 00:33:42 +0000387func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530388 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
389 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000390 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530391 return
392 }
393 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
394 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000395 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530396 return
397 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000398 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530399 /* to be verified / reworked !!! */
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000400 oo.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
401 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800402 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000403 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
404 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
405 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Himani Chawla4d908332020-08-31 12:30:20 +0530406 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000407 logger.Errorw(ctx, "Invalid number of commands received for:", log.Fields{"device-id": oo.deviceID, "uploadNoOfCmds": oo.PDevOmciCC.uploadNoOfCmds})
Himani Chawla4d908332020-08-31 12:30:20 +0530408 //TODO right action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000409 _ = oo.pMibUploadFsm.pFsm.Event(ulEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530410 }
411}
412
dbainbri4d3a0dc2020-12-02 00:33:42 +0000413func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530414 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
Andrea Campanella6515c582020-10-05 11:25:00 +0200415
Holger Hildebrandte2439342020-12-03 16:06:54 +0000416 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000417 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000418 return
419 }
420 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
421 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000422 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000423 return
424 }
425 meName := msgObj.ReportedME.GetName()
426 if meName == "UnknownItuG988ManagedEntity" || meName == "UnknownVendorSpecificManagedEntity" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000427 logger.Debugw(ctx, "MibUploadNextResponse Data for unknown ME received - temporary workaround is to ignore it!",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000428 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj, "meName": meName})
429 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000430 logger.Debugw(ctx, "MibUploadNextResponse Data for:",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000431 log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
Holger Hildebrandt8998b872020-10-05 13:48:39 +0000432 meClassID := msgObj.ReportedME.GetClassID()
433 meEntityID := msgObj.ReportedME.GetEntityID()
434 meAttributes := msgObj.ReportedME.GetAttributeValueMap()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000435 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes)
Himani Chawla4d908332020-08-31 12:30:20 +0530436 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000437 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800438 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000439 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
440 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
441 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Himani Chawla4d908332020-08-31 12:30:20 +0530442 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000443 oo.pOnuDB.logMeDb(ctx)
444 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530445 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000446 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to create and persist the mib template", log.Fields{"error": err, "device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530447 }
448
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000449 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530450 }
451}
452
dbainbri4d3a0dc2020-12-02 00:33:42 +0000453func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000454 var err error = nil
mpagenko01499812021-03-25 10:37:12 +0000455
456 if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType ||
457 oo.lastTxParamStruct.pLastTxMeInstance == nil {
458 //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest
459 // with Sequence number 0x8000 as last request before - so it may still respond to that
460 // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number
461 if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
462 logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
463 _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
464 //TODO: needs extra handling of timeouts
465 oo.lastTxParamStruct.repeatCount = 1
466 return nil
467 }
468 logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
469 //perhaps some still lingering message from some prior activity, let's wait for the real response
470 return nil
471 }
Himani Chawla4d908332020-08-31 12:30:20 +0530472 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000473 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000474 logger.Errorw(ctx, "omci Msg layer could not be detected for GetResponse - handling of MibSyncChan stopped", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000475 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
476 return fmt.Errorf("omci Msg layer could not be detected for GetResponse - handling of MibSyncChan stopped: %s", oo.deviceID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000477 }
478 msgObj, msgOk := msgLayer.(*omci.GetResponse)
479 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000480 logger.Errorw(ctx, "omci Msg layer could not be assigned for GetResponse - handling of MibSyncChan stopped", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000481 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
482 return fmt.Errorf("omci Msg layer could not be assigned for GetResponse - handling of MibSyncChan stopped: %s", oo.deviceID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000483 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000484 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000485 if msgObj.Result == me.Success {
mpagenko01499812021-03-25 10:37:12 +0000486 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
487 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000488 meAttributes := msgObj.Attributes
mpagenko01499812021-03-25 10:37:12 +0000489 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000490 logger.Debugf(ctx, "MibSync FSM - GetResponse Data for %s", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000491 switch meInstance {
492 case "OnuG":
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000493 oo.sOnuPersistentData.PersVendorID = trimStringFromInterface(meAttributes["VendorId"])
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000494 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
495 if onugSerialNumberLen == len(snBytes) {
496 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
497 snNumberPart := hex.EncodeToString(snBytes[4:])
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000498 oo.sOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000499 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-G - VendorId/SerialNumber", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000500 "onuDeviceEntry.vendorID": oo.sOnuPersistentData.PersVendorID, "onuDeviceEntry.serialNumber": oo.sOnuPersistentData.PersSerialNumber})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000501 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000502 logger.Infow(ctx, "MibSync FSM - SerialNumber has wrong length - fill serialNumber with zeros", log.Fields{"device-id": oo.deviceID, "length": len(snBytes)})
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000503 oo.sOnuPersistentData.PersSerialNumber = cEmptySerialNumberString
Himani Chawla4d908332020-08-31 12:30:20 +0530504 }
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000505 // trigger retrieval of EquipmentId
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000506 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000507 return nil
508 case "Onu2G":
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000509 oo.sOnuPersistentData.PersEquipmentID = trimStringFromInterface(meAttributes["EquipmentId"])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000510 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000511 "onuDeviceEntry.equipmentID": oo.sOnuPersistentData.PersEquipmentID})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000512 // trigger retrieval of 1st SW-image info
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000513 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000514 return nil
515 case "SoftwareImage":
mpagenko15ff4a52021-03-02 10:09:20 +0000516 if entityID > secondSwImageMeID {
517 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
518 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
519 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
520 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000521 }
mpagenko15ff4a52021-03-02 10:09:20 +0000522 // need to use function for go lint complexity
523 oo.handleSwImageIndications(ctx, entityID, meAttributes)
524 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000525 case "IpHostConfigData":
526 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
527 if omciMacAddressLen == len(macBytes) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000528 oo.sOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000529 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000530 "macAddress": oo.sOnuPersistentData.PersMacAddress})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000531 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000532 logger.Infow(ctx, "MibSync FSM - MacAddress wrong length - fill macAddress with zeros", log.Fields{"device-id": oo.deviceID, "length": len(macBytes)})
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000533 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000534 }
535 // trigger retrieval of mib template
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000536 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000537 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000538 case "OnuData":
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000539 oo.checkMdsValue(ctx, meAttributes["MibDataSync"].(uint8))
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000540 return nil
Himani Chawla4d908332020-08-31 12:30:20 +0530541 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800542 } else {
543 logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000544 }
Himani Chawla4d908332020-08-31 12:30:20 +0530545 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000546 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000547 return nil
548 }
Himani Chawla4d908332020-08-31 12:30:20 +0530549 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000550 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000551 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000552 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530553}
554
mpagenko15ff4a52021-03-02 10:09:20 +0000555func (oo *OnuDeviceEntry) handleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) {
556 imageIsCommitted := meAttributes["IsCommitted"].(uint8)
557 imageIsActive := meAttributes["IsActive"].(uint8)
558 imageVersion := trimStringFromInterface(meAttributes["Version"])
559 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
560 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000561 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.sOnuPersistentData.PersSerialNumber})
mpagenko15ff4a52021-03-02 10:09:20 +0000562 if firstSwImageMeID == entityID {
563 //always accept the state of the first image (2nd image info should not yet be available)
564 if imageIsActive == swIsActive {
565 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
566 oo.onuSwImageIndications.activeEntityEntry.valid = true
567 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
568 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000569 //as the SW version indication may stem from some ONU Down/up event
570 //the complementary image state is to be invalidated
571 // (state of the second image is always expected afterwards or just invalid)
572 oo.onuSwImageIndications.inactiveEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000573 } else {
574 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
575 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
576 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
577 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000578 //as the SW version indication may stem form some ONU Down/up event
579 //the complementary image state is to be invalidated
580 // (state of the second image is always expected afterwards or just invalid)
581 oo.onuSwImageIndications.activeEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000582 }
583 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion)
584 return
585 } else if secondSwImageMeID == entityID {
586 //2nd image info might conflict with first image info, in which case we priorize first image info!
587 if imageIsActive == swIsActive { //2nd image reported to be active
588 if oo.onuSwImageIndications.activeEntityEntry.valid {
589 //conflict exists - state of first image is left active
590 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
591 log.Fields{"device-id": oo.deviceID})
592 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
593 oo.onuSwImageIndications.inactiveEntityEntry.valid = true ////to indicate that at least something has been reported
594 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
595 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
596 } else { //first image inactive, this one active
597 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
598 oo.onuSwImageIndications.activeEntityEntry.valid = true
599 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
600 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
601 }
602 } else { //2nd image reported to be inactive
603 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
604 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
605 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
606 log.Fields{"device-id": oo.deviceID})
607 oo.onuSwImageIndications.activeEntityEntry.entityID = firstSwImageMeID
608 oo.onuSwImageIndications.activeEntityEntry.valid = true //to indicate that at least something has been reported
609 //copy active commit/version from the previously stored inactive position
610 oo.onuSwImageIndications.activeEntityEntry.version = oo.onuSwImageIndications.inactiveEntityEntry.version
611 oo.onuSwImageIndications.activeEntityEntry.isCommitted = oo.onuSwImageIndications.inactiveEntityEntry.isCommitted
612 }
613 //in any case we indicate (and possibly overwrite) the second image indications as inactive
614 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
615 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
616 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
617 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
618 }
619 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress)
620 return
621 }
622}
623
dbainbri4d3a0dc2020-12-02 00:33:42 +0000624func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg OmciMessage) {
625 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200626 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000627 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
628 switch msg.OmciMsg.MessageType {
629 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000630 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000631
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000632 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000633 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530634
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000635 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000636 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000637
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000638 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000639 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000640 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530641
Andrea Campanella6515c582020-10-05 11:25:00 +0200642 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000643 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200644
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000645 }
646}
647
dbainbri4d3a0dc2020-12-02 00:33:42 +0000648func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000649 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000650 logger.Debugf(ctx, "MibSync FSM - erroneous result in GetResponse Data: %s", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.Result)
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000651 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
652 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
mpagenko01499812021-03-25 10:37:12 +0000653 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
654 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
655 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000656 switch meInstance {
657 case "IpHostConfigData":
dbainbri4d3a0dc2020-12-02 00:33:42 +0000658 logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros",
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000659 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000660 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000661 // trigger retrieval of mib template
662 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
663 return nil
664 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000665 logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000666 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
667 }
668 }
669 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000670 logger.Errorf(ctx, "MibSync FSM - erroneous result in GetResponse Data: %s", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.Result)
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000671 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
672 }
673 return err
674}
675
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000676func (oo *OnuDeviceEntry) isNewOnu() bool {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000677 return oo.sOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000678}
679
Himani Chawla6d2ae152020-09-02 13:11:20 +0530680func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000681 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530682 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000683 return true
684 }
685 }
686 return false
687}
688
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000689func trimStringFromInterface(input interface{}) string {
690 ifBytes, _ := me.InterfaceToOctets(input)
691 return fmt.Sprintf("%s", bytes.Trim(ifBytes, "\x00"))
692}
693
dbainbri4d3a0dc2020-12-02 00:33:42 +0000694func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
695 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000696 return errors.New("not_implemented")
697}
698
Himani Chawla6d2ae152020-09-02 13:11:20 +0530699// createAndPersistMibTemplate method creates a mib template for the device id when operator enables the ONU device for the first time.
divyadesaibbed37c2020-08-28 13:35:20 +0530700// We are creating a placeholder for "SerialNumber" for ME Class ID 6 and 256 and "MacAddress" for ME Class ID 134 in the template
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000701// and then storing the template into etcd "service/voltha/omci_mibs/go_templates/verdor_id/equipment_id/software_version" path.
dbainbri4d3a0dc2020-12-02 00:33:42 +0000702func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
703 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000704 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530705
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000706 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
707 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
708 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000709 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000710 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
711 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
712 return nil
713 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000714 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000715 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
716 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000717 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000718 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
719 }
720 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = true
721 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
722
723 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +0530724 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000725 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +0530726 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
727
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000728 firstLevelMap := oo.pOnuDB.meDb
divyadesaibbed37c2020-08-28 13:35:20 +0530729 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000730 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +0530731 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530732
733 secondLevelMap := make(map[string]interface{})
734 for secondLevelKey, secondLevelValue := range firstLevelValue {
735 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +0530736 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530737 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +0530738 thirdLevelMap["InstanceId"] = entityID
739 secondLevelMap[entityID] = thirdLevelMap
740 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +0530741 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
742 delete(forthLevelMap, "SerialNumber")
743 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
744
745 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530746 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +0530747 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
748 delete(forthLevelMap, "MacAddress")
749 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
750 }
751 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530752 secondLevelMap["ClassId"] = classID
753 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +0530754 }
755 mibTemplate, err := json.Marshal(&templateMap)
756 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000757 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000758 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
759 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
760 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530761 return err
762 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000763 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +0530764 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000765 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to store template in etcd", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000766 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
767 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
768 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530769 return err
770 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000771 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530772 return nil
773}
774
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000775func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
776 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
777 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
778 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
Girish Gowdra0b235842021-03-09 13:06:46 -0800779 me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000780 //accept also nil as (error) return value for writing to LastTx
781 // - this avoids misinterpretation of new received OMCI messages
mpagenko01499812021-03-25 10:37:12 +0000782 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
783 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
784 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000785}
786
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000787func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
788 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
789 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.sOnuPersistentData.PersMibDataSyncAdpt})
790
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000791 mdsValuesAreEqual := oo.sOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000792 if oo.pMibUploadFsm.pFsm.Is(ulStAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000793 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000794 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
795 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
796 } else {
797 logger.Warnw(ctx, "MibSync FSM - mib audit - MDS check failed for the first time!", log.Fields{"device-id": oo.deviceID})
798 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
799 }
800 } else if oo.pMibUploadFsm.pFsm.Is(ulStReAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000801 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000802 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
803 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
804 } else {
805 logger.Errorw(ctx, "MibSync FSM - mib audit - MDS check failed for the second time!", log.Fields{"device-id": oo.deviceID})
806 //TODO: send new event notification "MDS counter mismatch" to the core
807 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
808 }
809 } else if oo.pMibUploadFsm.pFsm.Is(ulStExaminingMds) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000810 if mdsValuesAreEqual && mibDataSyncOnu != 0 {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000811 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
812 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
813 } else {
814 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
815 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
816 }
817 } else {
818 logger.Warnw(ctx, "wrong state for MDS evaluation!", log.Fields{"state": oo.pMibUploadFsm.pFsm.Current(), "device-id": oo.deviceID})
819 }
820}
mpagenko15ff4a52021-03-02 10:09:20 +0000821
822//GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
823func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
824 if oo.onuSwImageIndications.activeEntityEntry.valid {
825 return oo.onuSwImageIndications.activeEntityEntry.entityID, nil
826 }
827 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
828}
829
830//GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
831func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
832 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
833 return oo.onuSwImageIndications.inactiveEntityEntry.entityID, nil
834 }
835 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
836}
837
838//IsImageToBeCommitted returns true if the active image is still uncommitted
839func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
840 if oo.onuSwImageIndications.activeEntityEntry.valid {
841 if oo.onuSwImageIndications.activeEntityEntry.entityID == aImageID {
842 if oo.onuSwImageIndications.activeEntityEntry.isCommitted == swIsUncommitted {
843 return true
844 }
845 }
846 }
847 return false //all other case are treated as 'nothing to commit
848}
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000849func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool {
850
851 oo.mibTemplatePath = oo.buildMibTemplatePath()
852 logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath)})
853
854 restoredFromMibTemplate := false
855 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
856 if err == nil {
857 if Value != nil {
858 logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value)
859
860 // swap out tokens with specific data
861 mibTmpString, _ := kvstore.ToString(Value.Value)
862 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.sOnuPersistentData.PersSerialNumber, -1)
863 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.sOnuPersistentData.PersMacAddress, -1)
864 mibTmpBytes := []byte(mibTmpString)
865 logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes)
866
867 var firstLevelMap map[string]interface{}
868 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
869 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
870 } else {
871 for firstLevelKey, firstLevelValue := range firstLevelMap {
872 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
873 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
874 meClassID := me.ClassID(uint16ValidNumber)
875 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
876 if isSupportedClassID(meClassID) {
877 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
878 secondLevelMap := firstLevelValue.(map[string]interface{})
879 for secondLevelKey, secondLevelValue := range secondLevelMap {
880 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
881 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
882 meEntityID := uint16(uint16ValidNumber)
883 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
884 thirdLevelMap := secondLevelValue.(map[string]interface{})
885 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
886 if thirdLevelKey == "Attributes" {
887 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
888 attributesMap := thirdLevelValue.(map[string]interface{})
889 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
890 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
891 restoredFromMibTemplate = true
892 }
893 }
894 }
895 }
896 }
897 }
898 }
899 }
900 } else {
901 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
902 }
903 } else {
904 logger.Errorf(ctx, "Get from kvstore operation failed for path",
905 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
906 }
907 return restoredFromMibTemplate
908}