blob: a9f095e26d9979963b50e585ad6c6d07a2360eca [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
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000045var supportedClassIds = []me.ClassID{
46 me.CardholderClassID, // 5
47 me.CircuitPackClassID, // 6
48 me.SoftwareImageClassID, // 7
49 me.PhysicalPathTerminationPointEthernetUniClassID, // 11
50 me.OltGClassID, // 131
51 me.OnuPowerSheddingClassID, // 133
52 me.IpHostConfigDataClassID, // 134
53 me.OnuGClassID, // 256
54 me.Onu2GClassID, // 257
55 me.TContClassID, // 262
56 me.AniGClassID, // 263
57 me.UniGClassID, // 264
58 me.PriorityQueueClassID, // 277
59 me.TrafficSchedulerClassID, // 278
60 me.VirtualEthernetInterfacePointClassID, // 329
61 me.EnhancedSecurityControlClassID, // 332
62 me.OnuDynamicPowerManagementControlClassID, // 336
63 // 347 // definitions for ME "IPv6 host config data" are currently missing in omci-lib-go!
64}
65
66var fsmMsg TestMessageType
67
dbainbri4d3a0dc2020-12-02 00:33:42 +000068func (oo *OnuDeviceEntry) enterStartingState(ctx context.Context, e *fsm.Event) {
69 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": oo.deviceID})
70 oo.pOnuDB = newOnuDeviceDB(log.WithSpanFromContext(context.TODO(), ctx), oo)
71 go oo.processMibSyncMessages(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000072}
73
dbainbri4d3a0dc2020-12-02 00:33:42 +000074func (oo *OnuDeviceEntry) enterResettingMibState(ctx context.Context, e *fsm.Event) {
75 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 +000076
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +000077 if !oo.isNewOnu() && !oo.baseDeviceHandler.isReconciling() {
Holger Hildebrandt10d98192021-01-27 15:29:31 +000078 oo.baseDeviceHandler.prepareReconcilingWithActiveAdapter(ctx)
79 oo.devState = DeviceStatusInit
80 }
dbainbri4d3a0dc2020-12-02 00:33:42 +000081 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 -080082 _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000083 //TODO: needs to handle timeouts
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000084}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000085
dbainbri4d3a0dc2020-12-02 00:33:42 +000086func (oo *OnuDeviceEntry) enterGettingVendorAndSerialState(ctx context.Context, e *fsm.Event) {
87 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 +000088 requestedAttributes := me.AttributeValueMap{"VendorId": "", "SerialNumber": 0}
Girish Gowdra0b235842021-03-09 13:06:46 -080089 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 +000090 //accept also nil as (error) return value for writing to LastTx
91 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000092 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000093}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000094
dbainbri4d3a0dc2020-12-02 00:33:42 +000095func (oo *OnuDeviceEntry) enterGettingEquipmentIDState(ctx context.Context, e *fsm.Event) {
96 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 +000097 requestedAttributes := me.AttributeValueMap{"EquipmentId": ""}
Girish Gowdra0b235842021-03-09 13:06:46 -080098 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 +000099 //accept also nil as (error) return value for writing to LastTx
100 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000101 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000102}
103
dbainbri4d3a0dc2020-12-02 00:33:42 +0000104func (oo *OnuDeviceEntry) enterGettingFirstSwVersionState(ctx context.Context, e *fsm.Event) {
105 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 +0000106 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Girish Gowdra0b235842021-03-09 13:06:46 -0800107 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 +0000108 //accept also nil as (error) return value for writing to LastTx
109 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000110 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000111}
112
dbainbri4d3a0dc2020-12-02 00:33:42 +0000113func (oo *OnuDeviceEntry) enterGettingSecondSwVersionState(ctx context.Context, e *fsm.Event) {
114 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 +0000115 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Girish Gowdra0b235842021-03-09 13:06:46 -0800116 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 +0000117 //accept also nil as (error) return value for writing to LastTx
118 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000119 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000120}
121
dbainbri4d3a0dc2020-12-02 00:33:42 +0000122func (oo *OnuDeviceEntry) enterGettingMacAddressState(ctx context.Context, e *fsm.Event) {
123 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 +0000124 requestedAttributes := me.AttributeValueMap{"MacAddress": ""}
Girish Gowdra0b235842021-03-09 13:06:46 -0800125 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 +0000126 //accept also nil as (error) return value for writing to LastTx
127 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000128 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000129}
130
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000131func (oo *OnuDeviceEntry) enterGettingMibTemplateState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000132
mpagenko15ff4a52021-03-02 10:09:20 +0000133 if oo.onuSwImageIndications.activeEntityEntry.valid {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000134 oo.sOnuPersistentData.PersActiveSwVersion = oo.onuSwImageIndications.activeEntityEntry.version
mpagenko15ff4a52021-03-02 10:09:20 +0000135 } else {
136 logger.Errorw(ctx, "get-mib-template: no active SW version found, working with empty SW version, which might be untrustworthy",
137 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000138 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000139 if oo.getMibFromTemplate(ctx) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000140 logger.Debug(ctx, "MibSync FSM - valid MEs stored from template")
141 oo.pOnuDB.logMeDb(ctx)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000142 fsmMsg = LoadMibTemplateOk
143 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000144 logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000145 fsmMsg = LoadMibTemplateFailed
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000146
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000147 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
148 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
149 if mibTemplateIsGenerated {
150 logger.Debugw(ctx,
151 "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map",
152 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
153 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
154 }
155 }
156 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
157 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000158 mibSyncMsg := Message{
159 Type: TestMsg,
160 Data: TestMessage{
161 TestMessageVal: fsmMsg,
162 },
163 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000164 oo.pMibUploadFsm.commChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000165}
166
dbainbri4d3a0dc2020-12-02 00:33:42 +0000167func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
168 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 -0800169 _ = oo.PDevOmciCC.sendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000170}
171
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000172func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000173 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID})
174 oo.transferSystemEvent(ctx, MibDatabaseSync)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000175 go func() {
176 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
177 }()
178}
179
180func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
181 oo.sOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix())
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000182 if oo.mibAuditInterval > 0 {
183 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 +0000184 go func() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000185 time.Sleep(oo.mibAuditInterval)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000186 if err := oo.pMibUploadFsm.pFsm.Event(ulEvAuditMib); err != nil {
187 logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err})
188 }
189 }()
190 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000191}
192
dbainbri4d3a0dc2020-12-02 00:33:42 +0000193func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
194 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 +0000195 oo.requestMdsValue(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000196}
197
dbainbri4d3a0dc2020-12-02 00:33:42 +0000198func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
199 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
200 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000201 // TODOs:
202 // VOL-3805 - Provide exclusive OMCI channel for one FSM
203 // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go
204 // VOL-3792 - Support periodical audit via mib resync
205 // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000206}
207
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000208func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) {
209 logger.Debugw(ctx, "MibSync FSM",
210 log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID})
211
212 if oo.getMibFromTemplate(ctx) {
213 oo.baseDeviceHandler.startReconciling(ctx, true)
214 oo.baseDeviceHandler.addAllUniPorts(ctx)
215 oo.baseDeviceHandler.setDeviceReason(drInitialMibDownloaded)
216 oo.baseDeviceHandler.ReadyForSpecificOmciConfig = true
217 // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm
218
219 oo.baseDeviceHandler.reconcileDeviceTechProf(ctx)
220 if oo.baseDeviceHandler.isReconciling() {
221 oo.baseDeviceHandler.reconcileDeviceFlowConfig(ctx)
222 }
223 // set admin state independent of reconciling state after tp/flow reconcilement
224 if oo.sOnuPersistentData.PersUniDisableDone {
225 oo.baseDeviceHandler.disableUniPortStateUpdate(ctx)
226 oo.baseDeviceHandler.setDeviceReason(drOmciAdminLock)
227 } else {
228 oo.baseDeviceHandler.enableUniPortStateUpdate(ctx)
229 }
230 oo.baseDeviceHandler.stopReconciling(ctx)
231 go func() {
232 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
233 }()
234
235 } else {
236 logger.Debugw(ctx, "MibSync FSM",
237 log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID})
238 go func() {
239 //switch to reconciling with OMCI config
240 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
241 }()
242 }
243}
244
dbainbri4d3a0dc2020-12-02 00:33:42 +0000245func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000246 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 +0000247 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000248 oo.requestMdsValue(ctx)
249 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000250 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 +0000251 go func() {
252 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
253 }()
254 }
255}
256
257func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
258 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 +0000259 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000260 oo.requestMdsValue(ctx)
261 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000262 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 +0000263 go func() {
264 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
265 }()
266 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000267}
268
dbainbri4d3a0dc2020-12-02 00:33:42 +0000269func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
270 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
271 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000272}
273
dbainbri4d3a0dc2020-12-02 00:33:42 +0000274func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
275 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 +0000276loop:
277 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000278 // case <-ctx.Done():
279 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
280 // break loop
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000281 message, ok := <-oo.pMibUploadFsm.commChan
Himani Chawla4d908332020-08-31 12:30:20 +0530282 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000283 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 +0530284 break loop
285 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000286 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000287
Himani Chawla4d908332020-08-31 12:30:20 +0530288 switch message.Type {
289 case TestMsg:
290 msg, _ := message.Data.(TestMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000291 oo.handleTestMsg(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530292 case OMCI:
293 msg, _ := message.Data.(OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000294 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530295 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000296 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 +0000297 }
298 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000299 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000300 // TODO: only this action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000301 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000302}
303
dbainbri4d3a0dc2020-12-02 00:33:42 +0000304func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000305
dbainbri4d3a0dc2020-12-02 00:33:42 +0000306 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 +0000307
308 switch msg.TestMessageVal {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000309 case LoadMibTemplateFailed:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000310 _ = oo.pMibUploadFsm.pFsm.Event(ulEvUploadMib)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000311 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000312 case LoadMibTemplateOk:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000313 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000314 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000315 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000316 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 +0000317 }
318}
319
dbainbri4d3a0dc2020-12-02 00:33:42 +0000320func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg OmciMessage) {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000321 if oo.pMibUploadFsm.pFsm.Is(ulStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530322 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
323 if msgLayer != nil {
324 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
325 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000326 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530327 if msgObj.Result == me.Success {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000328 oo.sOnuPersistentData.PersMibDataSyncAdpt = 0
Himani Chawla4d908332020-08-31 12:30:20 +0530329 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000330 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530331 return
332 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000333 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530334 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000335 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530336 }
337 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000338 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530339 }
340 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000341 logger.Errorw(ctx, "Wrong Omci MibResetResponse received", log.Fields{"in state ": oo.pMibUploadFsm.pFsm.Current,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000342 "device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530343 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000344 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000345 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530346
347}
348
dbainbri4d3a0dc2020-12-02 00:33:42 +0000349func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530350 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
351 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000352 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530353 return
354 }
355 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
356 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000357 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530358 return
359 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000360 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530361 /* to be verified / reworked !!! */
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000362 oo.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
363 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800364 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
Himani Chawla4d908332020-08-31 12:30:20 +0530365 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000366 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 +0530367 //TODO right action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000368 _ = oo.pMibUploadFsm.pFsm.Event(ulEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530369 }
370}
371
dbainbri4d3a0dc2020-12-02 00:33:42 +0000372func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530373 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
Andrea Campanella6515c582020-10-05 11:25:00 +0200374
Holger Hildebrandte2439342020-12-03 16:06:54 +0000375 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000376 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000377 return
378 }
379 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
380 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000381 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000382 return
383 }
384 meName := msgObj.ReportedME.GetName()
385 if meName == "UnknownItuG988ManagedEntity" || meName == "UnknownVendorSpecificManagedEntity" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000386 logger.Debugw(ctx, "MibUploadNextResponse Data for unknown ME received - temporary workaround is to ignore it!",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000387 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj, "meName": meName})
388 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000389 logger.Debugw(ctx, "MibUploadNextResponse Data for:",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000390 log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
Holger Hildebrandt8998b872020-10-05 13:48:39 +0000391 meClassID := msgObj.ReportedME.GetClassID()
392 meEntityID := msgObj.ReportedME.GetEntityID()
393 meAttributes := msgObj.ReportedME.GetAttributeValueMap()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000394 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes)
Himani Chawla4d908332020-08-31 12:30:20 +0530395 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000396 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800397 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
Himani Chawla4d908332020-08-31 12:30:20 +0530398 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000399 oo.pOnuDB.logMeDb(ctx)
400 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530401 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000402 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 +0530403 }
404
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000405 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530406 }
407}
408
dbainbri4d3a0dc2020-12-02 00:33:42 +0000409func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000410 var err error = nil
Himani Chawla4d908332020-08-31 12:30:20 +0530411 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000412 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000413 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 +0000414 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
415 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 +0000416 }
417 msgObj, msgOk := msgLayer.(*omci.GetResponse)
418 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000419 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 +0000420 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
421 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 +0000422 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000423 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000424 if msgObj.Result == me.Success {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000425 entityID := oo.PDevOmciCC.pLastTxMeInstance.GetEntityID()
426 if msgObj.EntityClass == oo.PDevOmciCC.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000427 meAttributes := msgObj.Attributes
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000428 meInstance := oo.PDevOmciCC.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000429 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 +0000430 switch meInstance {
431 case "OnuG":
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000432 oo.sOnuPersistentData.PersVendorID = trimStringFromInterface(meAttributes["VendorId"])
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000433 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
434 if onugSerialNumberLen == len(snBytes) {
435 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
436 snNumberPart := hex.EncodeToString(snBytes[4:])
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000437 oo.sOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000438 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 +0000439 "onuDeviceEntry.vendorID": oo.sOnuPersistentData.PersVendorID, "onuDeviceEntry.serialNumber": oo.sOnuPersistentData.PersSerialNumber})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000440 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000441 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 +0000442 oo.sOnuPersistentData.PersSerialNumber = cEmptySerialNumberString
Himani Chawla4d908332020-08-31 12:30:20 +0530443 }
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000444 // trigger retrieval of EquipmentId
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000445 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000446 return nil
447 case "Onu2G":
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000448 oo.sOnuPersistentData.PersEquipmentID = trimStringFromInterface(meAttributes["EquipmentId"])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000449 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000450 "onuDeviceEntry.equipmentID": oo.sOnuPersistentData.PersEquipmentID})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000451 // trigger retrieval of 1st SW-image info
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000452 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000453 return nil
454 case "SoftwareImage":
mpagenko15ff4a52021-03-02 10:09:20 +0000455 if entityID > secondSwImageMeID {
456 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
457 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
458 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
459 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000460 }
mpagenko15ff4a52021-03-02 10:09:20 +0000461 // need to use function for go lint complexity
462 oo.handleSwImageIndications(ctx, entityID, meAttributes)
463 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000464 case "IpHostConfigData":
465 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
466 if omciMacAddressLen == len(macBytes) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000467 oo.sOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000468 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000469 "macAddress": oo.sOnuPersistentData.PersMacAddress})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000470 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000471 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 +0000472 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000473 }
474 // trigger retrieval of mib template
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000475 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000476 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000477 case "OnuData":
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000478 oo.checkMdsValue(ctx, meAttributes["MibDataSync"].(uint8))
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000479 return nil
Himani Chawla4d908332020-08-31 12:30:20 +0530480 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800481 } else {
482 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 +0000483 }
Himani Chawla4d908332020-08-31 12:30:20 +0530484 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000485 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000486 return nil
487 }
Himani Chawla4d908332020-08-31 12:30:20 +0530488 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000489 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000490 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000491 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530492}
493
mpagenko15ff4a52021-03-02 10:09:20 +0000494func (oo *OnuDeviceEntry) handleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) {
495 imageIsCommitted := meAttributes["IsCommitted"].(uint8)
496 imageIsActive := meAttributes["IsActive"].(uint8)
497 imageVersion := trimStringFromInterface(meAttributes["Version"])
498 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
499 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000500 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.sOnuPersistentData.PersSerialNumber})
mpagenko15ff4a52021-03-02 10:09:20 +0000501 if firstSwImageMeID == entityID {
502 //always accept the state of the first image (2nd image info should not yet be available)
503 if imageIsActive == swIsActive {
504 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
505 oo.onuSwImageIndications.activeEntityEntry.valid = true
506 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
507 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000508 //as the SW version indication may stem from some ONU Down/up event
509 //the complementary image state is to be invalidated
510 // (state of the second image is always expected afterwards or just invalid)
511 oo.onuSwImageIndications.inactiveEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000512 } else {
513 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
514 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
515 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
516 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000517 //as the SW version indication may stem form some ONU Down/up event
518 //the complementary image state is to be invalidated
519 // (state of the second image is always expected afterwards or just invalid)
520 oo.onuSwImageIndications.activeEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000521 }
522 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion)
523 return
524 } else if secondSwImageMeID == entityID {
525 //2nd image info might conflict with first image info, in which case we priorize first image info!
526 if imageIsActive == swIsActive { //2nd image reported to be active
527 if oo.onuSwImageIndications.activeEntityEntry.valid {
528 //conflict exists - state of first image is left active
529 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
530 log.Fields{"device-id": oo.deviceID})
531 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
532 oo.onuSwImageIndications.inactiveEntityEntry.valid = true ////to indicate that at least something has been reported
533 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
534 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
535 } else { //first image inactive, this one active
536 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
537 oo.onuSwImageIndications.activeEntityEntry.valid = true
538 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
539 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
540 }
541 } else { //2nd image reported to be inactive
542 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
543 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
544 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
545 log.Fields{"device-id": oo.deviceID})
546 oo.onuSwImageIndications.activeEntityEntry.entityID = firstSwImageMeID
547 oo.onuSwImageIndications.activeEntityEntry.valid = true //to indicate that at least something has been reported
548 //copy active commit/version from the previously stored inactive position
549 oo.onuSwImageIndications.activeEntityEntry.version = oo.onuSwImageIndications.inactiveEntityEntry.version
550 oo.onuSwImageIndications.activeEntityEntry.isCommitted = oo.onuSwImageIndications.inactiveEntityEntry.isCommitted
551 }
552 //in any case we indicate (and possibly overwrite) the second image indications as inactive
553 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
554 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
555 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
556 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
557 }
558 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress)
559 return
560 }
561}
562
dbainbri4d3a0dc2020-12-02 00:33:42 +0000563func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg OmciMessage) {
564 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200565 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000566 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
567 switch msg.OmciMsg.MessageType {
568 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000569 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000570
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000571 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000572 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530573
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000574 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000575 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000576
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000577 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000578 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000579 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530580
Andrea Campanella6515c582020-10-05 11:25:00 +0200581 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000582 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200583
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000584 }
585}
586
dbainbri4d3a0dc2020-12-02 00:33:42 +0000587func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000588 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000589 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 +0000590 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
591 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
592 entityID := oo.PDevOmciCC.pLastTxMeInstance.GetEntityID()
593 if msgObj.EntityClass == oo.PDevOmciCC.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
594 meInstance := oo.PDevOmciCC.pLastTxMeInstance.GetName()
595 switch meInstance {
596 case "IpHostConfigData":
dbainbri4d3a0dc2020-12-02 00:33:42 +0000597 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 +0000598 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000599 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000600 // trigger retrieval of mib template
601 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
602 return nil
603 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000604 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 +0000605 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
606 }
607 }
608 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000609 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 +0000610 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
611 }
612 return err
613}
614
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000615func (oo *OnuDeviceEntry) isNewOnu() bool {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000616 return oo.sOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000617}
618
Himani Chawla6d2ae152020-09-02 13:11:20 +0530619func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000620 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530621 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000622 return true
623 }
624 }
625 return false
626}
627
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000628func trimStringFromInterface(input interface{}) string {
629 ifBytes, _ := me.InterfaceToOctets(input)
630 return fmt.Sprintf("%s", bytes.Trim(ifBytes, "\x00"))
631}
632
dbainbri4d3a0dc2020-12-02 00:33:42 +0000633func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
634 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000635 return errors.New("not_implemented")
636}
637
Himani Chawla6d2ae152020-09-02 13:11:20 +0530638// 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 +0530639// 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 +0000640// 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 +0000641func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
642 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000643 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530644
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000645 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
646 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
647 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000648 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000649 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
650 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
651 return nil
652 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000653 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000654 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
655 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000656 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000657 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
658 }
659 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = true
660 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
661
662 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +0530663 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000664 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +0530665 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
666
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000667 firstLevelMap := oo.pOnuDB.meDb
divyadesaibbed37c2020-08-28 13:35:20 +0530668 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000669 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +0530670 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530671
672 secondLevelMap := make(map[string]interface{})
673 for secondLevelKey, secondLevelValue := range firstLevelValue {
674 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +0530675 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530676 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +0530677 thirdLevelMap["InstanceId"] = entityID
678 secondLevelMap[entityID] = thirdLevelMap
679 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +0530680 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
681 delete(forthLevelMap, "SerialNumber")
682 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
683
684 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530685 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +0530686 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
687 delete(forthLevelMap, "MacAddress")
688 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
689 }
690 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530691 secondLevelMap["ClassId"] = classID
692 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +0530693 }
694 mibTemplate, err := json.Marshal(&templateMap)
695 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000696 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000697 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
698 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
699 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530700 return err
701 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000702 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +0530703 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000704 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 +0000705 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
706 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
707 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530708 return err
709 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000710 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530711 return nil
712}
713
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000714func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
715 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
716 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
717 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
Girish Gowdra0b235842021-03-09 13:06:46 -0800718 me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000719 //accept also nil as (error) return value for writing to LastTx
720 // - this avoids misinterpretation of new received OMCI messages
721 oo.PDevOmciCC.pLastTxMeInstance = meInstance
722}
723
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000724func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
725 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
726 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.sOnuPersistentData.PersMibDataSyncAdpt})
727
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000728 mdsValuesAreEqual := oo.sOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000729 if oo.pMibUploadFsm.pFsm.Is(ulStAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000730 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000731 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
732 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
733 } else {
734 logger.Warnw(ctx, "MibSync FSM - mib audit - MDS check failed for the first time!", log.Fields{"device-id": oo.deviceID})
735 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
736 }
737 } else if oo.pMibUploadFsm.pFsm.Is(ulStReAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000738 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000739 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
740 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
741 } else {
742 logger.Errorw(ctx, "MibSync FSM - mib audit - MDS check failed for the second time!", log.Fields{"device-id": oo.deviceID})
743 //TODO: send new event notification "MDS counter mismatch" to the core
744 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
745 }
746 } else if oo.pMibUploadFsm.pFsm.Is(ulStExaminingMds) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000747 if mdsValuesAreEqual && mibDataSyncOnu != 0 {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000748 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
749 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
750 } else {
751 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
752 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
753 }
754 } else {
755 logger.Warnw(ctx, "wrong state for MDS evaluation!", log.Fields{"state": oo.pMibUploadFsm.pFsm.Current(), "device-id": oo.deviceID})
756 }
757}
mpagenko15ff4a52021-03-02 10:09:20 +0000758
759//GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
760func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
761 if oo.onuSwImageIndications.activeEntityEntry.valid {
762 return oo.onuSwImageIndications.activeEntityEntry.entityID, nil
763 }
764 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
765}
766
767//GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
768func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
769 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
770 return oo.onuSwImageIndications.inactiveEntityEntry.entityID, nil
771 }
772 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
773}
774
775//IsImageToBeCommitted returns true if the active image is still uncommitted
776func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
777 if oo.onuSwImageIndications.activeEntityEntry.valid {
778 if oo.onuSwImageIndications.activeEntityEntry.entityID == aImageID {
779 if oo.onuSwImageIndications.activeEntityEntry.isCommitted == swIsUncommitted {
780 return true
781 }
782 }
783 }
784 return false //all other case are treated as 'nothing to commit
785}
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000786func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool {
787
788 oo.mibTemplatePath = oo.buildMibTemplatePath()
789 logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath)})
790
791 restoredFromMibTemplate := false
792 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
793 if err == nil {
794 if Value != nil {
795 logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value)
796
797 // swap out tokens with specific data
798 mibTmpString, _ := kvstore.ToString(Value.Value)
799 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.sOnuPersistentData.PersSerialNumber, -1)
800 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.sOnuPersistentData.PersMacAddress, -1)
801 mibTmpBytes := []byte(mibTmpString)
802 logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes)
803
804 var firstLevelMap map[string]interface{}
805 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
806 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
807 } else {
808 for firstLevelKey, firstLevelValue := range firstLevelMap {
809 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
810 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
811 meClassID := me.ClassID(uint16ValidNumber)
812 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
813 if isSupportedClassID(meClassID) {
814 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
815 secondLevelMap := firstLevelValue.(map[string]interface{})
816 for secondLevelKey, secondLevelValue := range secondLevelMap {
817 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
818 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
819 meEntityID := uint16(uint16ValidNumber)
820 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
821 thirdLevelMap := secondLevelValue.(map[string]interface{})
822 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
823 if thirdLevelKey == "Attributes" {
824 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
825 attributesMap := thirdLevelValue.(map[string]interface{})
826 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
827 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
828 restoredFromMibTemplate = true
829 }
830 }
831 }
832 }
833 }
834 }
835 }
836 }
837 } else {
838 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
839 }
840 } else {
841 logger.Errorf(ctx, "Get from kvstore operation failed for path",
842 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
843 }
844 return restoredFromMibTemplate
845}