blob: 8ae57420a853f23c1d641723f3652e8374c0a650 [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 Hildebrandtbdc5f002021-04-19 14:46:21 +000083 if (!oo.isNewOnu() && !oo.baseDeviceHandler.isReconciling()) || //use case: re-auditing failed
84 oo.baseDeviceHandler.isSkipOnuConfigReconciling() { //use case: reconciling without omci-config failed
Holger Hildebrandt10d98192021-01-27 15:29:31 +000085 oo.baseDeviceHandler.prepareReconcilingWithActiveAdapter(ctx)
86 oo.devState = DeviceStatusInit
87 }
dbainbri4d3a0dc2020-12-02 00:33:42 +000088 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 -080089 _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000090 //TODO: needs to handle timeouts
mpagenko01499812021-03-25 10:37:12 +000091 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
92 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
93 oo.lastTxParamStruct.lastTxMessageType = omci.MibResetRequestType
94 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000095}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000096
dbainbri4d3a0dc2020-12-02 00:33:42 +000097func (oo *OnuDeviceEntry) enterGettingVendorAndSerialState(ctx context.Context, e *fsm.Event) {
98 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 +000099 requestedAttributes := me.AttributeValueMap{"VendorId": "", "SerialNumber": 0}
Girish Gowdra0b235842021-03-09 13:06:46 -0800100 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 +0000101 //accept also nil as (error) return value for writing to LastTx
102 // - this avoids misinterpretation of new received OMCI messages
mpagenko01499812021-03-25 10:37:12 +0000103 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
104 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000105}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000106
dbainbri4d3a0dc2020-12-02 00:33:42 +0000107func (oo *OnuDeviceEntry) enterGettingEquipmentIDState(ctx context.Context, e *fsm.Event) {
108 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 +0000109 requestedAttributes := me.AttributeValueMap{"EquipmentId": ""}
Girish Gowdra0b235842021-03-09 13:06:46 -0800110 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 +0000111 //accept also nil as (error) return value for writing to LastTx
112 // - this avoids misinterpretation of new received OMCI messages
mpagenko01499812021-03-25 10:37:12 +0000113 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
114 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000115}
116
dbainbri4d3a0dc2020-12-02 00:33:42 +0000117func (oo *OnuDeviceEntry) enterGettingFirstSwVersionState(ctx context.Context, e *fsm.Event) {
118 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 +0000119 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Girish Gowdra0b235842021-03-09 13:06:46 -0800120 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 +0000121 //accept also nil as (error) return value for writing to LastTx
122 // - this avoids misinterpretation of new received OMCI messages
mpagenko01499812021-03-25 10:37:12 +0000123 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
124 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000125}
126
dbainbri4d3a0dc2020-12-02 00:33:42 +0000127func (oo *OnuDeviceEntry) enterGettingSecondSwVersionState(ctx context.Context, e *fsm.Event) {
128 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 +0000129 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Girish Gowdra0b235842021-03-09 13:06:46 -0800130 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 +0000131 //accept also nil as (error) return value for writing to LastTx
132 // - this avoids misinterpretation of new received OMCI messages
mpagenko01499812021-03-25 10:37:12 +0000133 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
134 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000135}
136
dbainbri4d3a0dc2020-12-02 00:33:42 +0000137func (oo *OnuDeviceEntry) enterGettingMacAddressState(ctx context.Context, e *fsm.Event) {
138 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 +0000139 requestedAttributes := me.AttributeValueMap{"MacAddress": ""}
Girish Gowdra0b235842021-03-09 13:06:46 -0800140 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 +0000141 //accept also nil as (error) return value for writing to LastTx
142 // - this avoids misinterpretation of new received OMCI messages
mpagenko01499812021-03-25 10:37:12 +0000143 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
144 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000145}
146
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000147func (oo *OnuDeviceEntry) enterGettingMibTemplateState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000148
mpagenko15ff4a52021-03-02 10:09:20 +0000149 if oo.onuSwImageIndications.activeEntityEntry.valid {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000150 oo.sOnuPersistentData.PersActiveSwVersion = oo.onuSwImageIndications.activeEntityEntry.version
mpagenko15ff4a52021-03-02 10:09:20 +0000151 } else {
152 logger.Errorw(ctx, "get-mib-template: no active SW version found, working with empty SW version, which might be untrustworthy",
153 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000154 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000155 if oo.getMibFromTemplate(ctx) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000156 logger.Debug(ctx, "MibSync FSM - valid MEs stored from template")
157 oo.pOnuDB.logMeDb(ctx)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000158 fsmMsg = LoadMibTemplateOk
159 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000160 logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000161 fsmMsg = LoadMibTemplateFailed
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000162
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000163 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
164 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
165 if mibTemplateIsGenerated {
166 logger.Debugw(ctx,
167 "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map",
168 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
169 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
170 }
171 }
172 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
173 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000174 mibSyncMsg := Message{
175 Type: TestMsg,
176 Data: TestMessage{
177 TestMessageVal: fsmMsg,
178 },
179 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000180 oo.pMibUploadFsm.commChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000181}
182
dbainbri4d3a0dc2020-12-02 00:33:42 +0000183func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
184 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 -0800185 _ = oo.PDevOmciCC.sendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000186 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
187 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
188 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadRequestType
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000189}
190
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000191func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000192 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID})
193 oo.transferSystemEvent(ctx, MibDatabaseSync)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000194 go func() {
195 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
196 }()
197}
198
199func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
200 oo.sOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix())
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000201 if oo.mibAuditInterval > 0 {
202 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 +0000203 go func() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000204 time.Sleep(oo.mibAuditInterval)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000205 if err := oo.pMibUploadFsm.pFsm.Event(ulEvAuditMib); err != nil {
206 logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err})
207 }
208 }()
209 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000210}
211
dbainbri4d3a0dc2020-12-02 00:33:42 +0000212func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
213 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 +0000214 oo.requestMdsValue(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000215}
216
dbainbri4d3a0dc2020-12-02 00:33:42 +0000217func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
218 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
219 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000220 // TODOs:
221 // VOL-3805 - Provide exclusive OMCI channel for one FSM
222 // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go
223 // VOL-3792 - Support periodical audit via mib resync
224 // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000225}
226
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000227func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) {
228 logger.Debugw(ctx, "MibSync FSM",
229 log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID})
230
231 if oo.getMibFromTemplate(ctx) {
232 oo.baseDeviceHandler.startReconciling(ctx, true)
233 oo.baseDeviceHandler.addAllUniPorts(ctx)
234 oo.baseDeviceHandler.setDeviceReason(drInitialMibDownloaded)
235 oo.baseDeviceHandler.ReadyForSpecificOmciConfig = true
236 // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm
237
238 oo.baseDeviceHandler.reconcileDeviceTechProf(ctx)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000239
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000240 // start go routine with select() on reconciling flow channel before
241 // starting flow reconciling process to prevent loss of any signal
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000242 go func() {
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000243 // In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until
244 // we get a signal that the processing of the last step to rebuild the adapter internal
245 // flow data is finished.
246 select {
247 case success := <-oo.baseDeviceHandler.chReconcilingFlowsFinished:
248 if success {
249 logger.Debugw(ctx, "reconciling flows has been finished in time",
250 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000251 oo.baseDeviceHandler.stopReconciling(ctx)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000252 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000253
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000254 } else {
255 logger.Debugw(ctx, "wait for reconciling flows aborted",
256 log.Fields{"device-id": oo.deviceID})
257 oo.baseDeviceHandler.setReconcilingFlows(false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000258 }
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000259 case <-time.After(500 * time.Millisecond):
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000260 logger.Errorw(ctx, "timeout waiting for reconciling flows to be finished!",
261 log.Fields{"device-id": oo.deviceID})
262 oo.baseDeviceHandler.setReconcilingFlows(false)
263 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
264 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000265 }()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000266 oo.baseDeviceHandler.reconcileDeviceFlowConfig(ctx)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000267
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000268 if oo.sOnuPersistentData.PersUniDisableDone {
269 oo.baseDeviceHandler.disableUniPortStateUpdate(ctx)
270 oo.baseDeviceHandler.setDeviceReason(drOmciAdminLock)
271 } else {
272 oo.baseDeviceHandler.enableUniPortStateUpdate(ctx)
273 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000274 } else {
275 logger.Debugw(ctx, "MibSync FSM",
276 log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID})
277 go func() {
278 //switch to reconciling with OMCI config
279 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
280 }()
281 }
282}
283
dbainbri4d3a0dc2020-12-02 00:33:42 +0000284func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000285 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 +0000286 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000287 oo.requestMdsValue(ctx)
288 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000289 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 +0000290 go func() {
291 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
292 }()
293 }
294}
295
296func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
297 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 +0000298 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000299 oo.requestMdsValue(ctx)
300 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000301 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 +0000302 go func() {
303 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
304 }()
305 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000306}
307
dbainbri4d3a0dc2020-12-02 00:33:42 +0000308func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
309 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
310 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000311}
312
dbainbri4d3a0dc2020-12-02 00:33:42 +0000313func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
314 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 +0000315loop:
316 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000317 // case <-ctx.Done():
318 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
319 // break loop
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000320 message, ok := <-oo.pMibUploadFsm.commChan
Himani Chawla4d908332020-08-31 12:30:20 +0530321 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000322 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 +0530323 break loop
324 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000325 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000326
Himani Chawla4d908332020-08-31 12:30:20 +0530327 switch message.Type {
328 case TestMsg:
329 msg, _ := message.Data.(TestMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000330 oo.handleTestMsg(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530331 case OMCI:
332 msg, _ := message.Data.(OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000333 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530334 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000335 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 +0000336 }
337 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000338 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000339 // TODO: only this action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000340 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000341}
342
dbainbri4d3a0dc2020-12-02 00:33:42 +0000343func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000344
dbainbri4d3a0dc2020-12-02 00:33:42 +0000345 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 +0000346
347 switch msg.TestMessageVal {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000348 case LoadMibTemplateFailed:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000349 _ = oo.pMibUploadFsm.pFsm.Event(ulEvUploadMib)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000350 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000351 case LoadMibTemplateOk:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000352 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000353 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000354 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000355 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 +0000356 }
357}
358
dbainbri4d3a0dc2020-12-02 00:33:42 +0000359func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg OmciMessage) {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000360 if oo.pMibUploadFsm.pFsm.Is(ulStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530361 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
362 if msgLayer != nil {
363 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
364 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000365 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530366 if msgObj.Result == me.Success {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000367 oo.sOnuPersistentData.PersMibDataSyncAdpt = 0
Himani Chawla4d908332020-08-31 12:30:20 +0530368 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000369 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530370 return
371 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000372 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530373 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000374 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530375 }
376 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000377 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530378 }
379 } else {
mpagenko01499812021-03-25 10:37:12 +0000380 //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset
381 // with Sequence number 0x8000 as last request before - so it may still respond to that
382 // then we may force the ONU to react on the MdsGetRequest with a new message that uses an increased Sequence number
383 if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
384 logger.Debugw(ctx, "MibSync FSM - repeat MdsGetRequest (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
385 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
386 _ = oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
387 me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
388 //TODO: needs extra handling of timeouts
389 oo.lastTxParamStruct.repeatCount = 1
390 return
391 }
392 logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
393 //perhaps some still lingering message from some prior activity, let's wait for the real response
394 return
Himani Chawla4d908332020-08-31 12:30:20 +0530395 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000396 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000397 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530398}
399
dbainbri4d3a0dc2020-12-02 00:33:42 +0000400func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530401 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
402 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000403 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530404 return
405 }
406 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
407 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000408 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530409 return
410 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000411 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530412 /* to be verified / reworked !!! */
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000413 oo.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
414 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800415 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000416 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
417 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
418 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Himani Chawla4d908332020-08-31 12:30:20 +0530419 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000420 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 +0530421 //TODO right action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000422 _ = oo.pMibUploadFsm.pFsm.Event(ulEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530423 }
424}
425
dbainbri4d3a0dc2020-12-02 00:33:42 +0000426func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530427 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
Andrea Campanella6515c582020-10-05 11:25:00 +0200428
Holger Hildebrandte2439342020-12-03 16:06:54 +0000429 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000430 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000431 return
432 }
433 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
434 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000435 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000436 return
437 }
438 meName := msgObj.ReportedME.GetName()
439 if meName == "UnknownItuG988ManagedEntity" || meName == "UnknownVendorSpecificManagedEntity" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000440 logger.Debugw(ctx, "MibUploadNextResponse Data for unknown ME received - temporary workaround is to ignore it!",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000441 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj, "meName": meName})
442 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000443 logger.Debugw(ctx, "MibUploadNextResponse Data for:",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000444 log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
Holger Hildebrandt8998b872020-10-05 13:48:39 +0000445 meClassID := msgObj.ReportedME.GetClassID()
446 meEntityID := msgObj.ReportedME.GetEntityID()
447 meAttributes := msgObj.ReportedME.GetAttributeValueMap()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000448 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes)
Himani Chawla4d908332020-08-31 12:30:20 +0530449 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000450 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800451 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000452 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
453 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
454 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Himani Chawla4d908332020-08-31 12:30:20 +0530455 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000456 oo.pOnuDB.logMeDb(ctx)
457 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530458 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000459 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 +0530460 }
461
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000462 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530463 }
464}
465
dbainbri4d3a0dc2020-12-02 00:33:42 +0000466func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000467 var err error = nil
mpagenko01499812021-03-25 10:37:12 +0000468
469 if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType ||
470 oo.lastTxParamStruct.pLastTxMeInstance == nil {
471 //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest
472 // with Sequence number 0x8000 as last request before - so it may still respond to that
473 // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number
474 if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
475 logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
476 _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
477 //TODO: needs extra handling of timeouts
478 oo.lastTxParamStruct.repeatCount = 1
479 return nil
480 }
481 logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
482 //perhaps some still lingering message from some prior activity, let's wait for the real response
483 return nil
484 }
Himani Chawla4d908332020-08-31 12:30:20 +0530485 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000486 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000487 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 +0000488 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
489 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 +0000490 }
491 msgObj, msgOk := msgLayer.(*omci.GetResponse)
492 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000493 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 +0000494 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
495 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 +0000496 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000497 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000498 if msgObj.Result == me.Success {
mpagenko01499812021-03-25 10:37:12 +0000499 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
500 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000501 meAttributes := msgObj.Attributes
mpagenko01499812021-03-25 10:37:12 +0000502 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000503 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 +0000504 switch meInstance {
505 case "OnuG":
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000506 oo.sOnuPersistentData.PersVendorID = trimStringFromInterface(meAttributes["VendorId"])
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000507 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
508 if onugSerialNumberLen == len(snBytes) {
509 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
510 snNumberPart := hex.EncodeToString(snBytes[4:])
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000511 oo.sOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000512 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 +0000513 "onuDeviceEntry.vendorID": oo.sOnuPersistentData.PersVendorID, "onuDeviceEntry.serialNumber": oo.sOnuPersistentData.PersSerialNumber})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000514 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000515 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 +0000516 oo.sOnuPersistentData.PersSerialNumber = cEmptySerialNumberString
Himani Chawla4d908332020-08-31 12:30:20 +0530517 }
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000518 // trigger retrieval of EquipmentId
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000519 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000520 return nil
521 case "Onu2G":
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000522 oo.sOnuPersistentData.PersEquipmentID = trimStringFromInterface(meAttributes["EquipmentId"])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000523 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000524 "onuDeviceEntry.equipmentID": oo.sOnuPersistentData.PersEquipmentID})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000525 // trigger retrieval of 1st SW-image info
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000526 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000527 return nil
528 case "SoftwareImage":
mpagenko15ff4a52021-03-02 10:09:20 +0000529 if entityID > secondSwImageMeID {
530 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
531 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
532 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
533 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000534 }
mpagenko15ff4a52021-03-02 10:09:20 +0000535 // need to use function for go lint complexity
536 oo.handleSwImageIndications(ctx, entityID, meAttributes)
537 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000538 case "IpHostConfigData":
539 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
540 if omciMacAddressLen == len(macBytes) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000541 oo.sOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000542 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000543 "macAddress": oo.sOnuPersistentData.PersMacAddress})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000544 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000545 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 +0000546 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000547 }
548 // trigger retrieval of mib template
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000549 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000550 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000551 case "OnuData":
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000552 oo.checkMdsValue(ctx, meAttributes["MibDataSync"].(uint8))
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000553 return nil
Himani Chawla4d908332020-08-31 12:30:20 +0530554 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800555 } else {
556 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 +0000557 }
Himani Chawla4d908332020-08-31 12:30:20 +0530558 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000559 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000560 return nil
561 }
Himani Chawla4d908332020-08-31 12:30:20 +0530562 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000563 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000564 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000565 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530566}
567
mpagenko15ff4a52021-03-02 10:09:20 +0000568func (oo *OnuDeviceEntry) handleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) {
569 imageIsCommitted := meAttributes["IsCommitted"].(uint8)
570 imageIsActive := meAttributes["IsActive"].(uint8)
571 imageVersion := trimStringFromInterface(meAttributes["Version"])
572 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
573 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000574 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.sOnuPersistentData.PersSerialNumber})
mpagenko15ff4a52021-03-02 10:09:20 +0000575 if firstSwImageMeID == entityID {
576 //always accept the state of the first image (2nd image info should not yet be available)
577 if imageIsActive == swIsActive {
578 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
579 oo.onuSwImageIndications.activeEntityEntry.valid = true
580 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
581 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000582 //as the SW version indication may stem from some ONU Down/up event
583 //the complementary image state is to be invalidated
584 // (state of the second image is always expected afterwards or just invalid)
585 oo.onuSwImageIndications.inactiveEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000586 } else {
587 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
588 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
589 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
590 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000591 //as the SW version indication may stem form some ONU Down/up event
592 //the complementary image state is to be invalidated
593 // (state of the second image is always expected afterwards or just invalid)
594 oo.onuSwImageIndications.activeEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000595 }
596 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion)
597 return
598 } else if secondSwImageMeID == entityID {
599 //2nd image info might conflict with first image info, in which case we priorize first image info!
600 if imageIsActive == swIsActive { //2nd image reported to be active
601 if oo.onuSwImageIndications.activeEntityEntry.valid {
602 //conflict exists - state of first image is left active
603 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
604 log.Fields{"device-id": oo.deviceID})
605 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
606 oo.onuSwImageIndications.inactiveEntityEntry.valid = true ////to indicate that at least something has been reported
607 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
608 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
609 } else { //first image inactive, this one active
610 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
611 oo.onuSwImageIndications.activeEntityEntry.valid = true
612 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
613 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
614 }
615 } else { //2nd image reported to be inactive
616 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
617 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
618 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
619 log.Fields{"device-id": oo.deviceID})
620 oo.onuSwImageIndications.activeEntityEntry.entityID = firstSwImageMeID
621 oo.onuSwImageIndications.activeEntityEntry.valid = true //to indicate that at least something has been reported
622 //copy active commit/version from the previously stored inactive position
623 oo.onuSwImageIndications.activeEntityEntry.version = oo.onuSwImageIndications.inactiveEntityEntry.version
624 oo.onuSwImageIndications.activeEntityEntry.isCommitted = oo.onuSwImageIndications.inactiveEntityEntry.isCommitted
625 }
626 //in any case we indicate (and possibly overwrite) the second image indications as inactive
627 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
628 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
629 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
630 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
631 }
632 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress)
633 return
634 }
635}
636
dbainbri4d3a0dc2020-12-02 00:33:42 +0000637func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg OmciMessage) {
638 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200639 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000640 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
641 switch msg.OmciMsg.MessageType {
642 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000643 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000644
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000645 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000646 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530647
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000648 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000649 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000650
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000651 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000652 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000653 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530654
Andrea Campanella6515c582020-10-05 11:25:00 +0200655 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000656 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200657
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000658 }
659}
660
dbainbri4d3a0dc2020-12-02 00:33:42 +0000661func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000662 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000663 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 +0000664 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
665 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
mpagenko01499812021-03-25 10:37:12 +0000666 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
667 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
668 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000669 switch meInstance {
670 case "IpHostConfigData":
dbainbri4d3a0dc2020-12-02 00:33:42 +0000671 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 +0000672 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000673 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000674 // trigger retrieval of mib template
675 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
676 return nil
677 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000678 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 +0000679 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
680 }
681 }
682 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000683 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 +0000684 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
685 }
686 return err
687}
688
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000689func (oo *OnuDeviceEntry) isNewOnu() bool {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000690 return oo.sOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000691}
692
Himani Chawla6d2ae152020-09-02 13:11:20 +0530693func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000694 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530695 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000696 return true
697 }
698 }
699 return false
700}
701
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000702func trimStringFromInterface(input interface{}) string {
703 ifBytes, _ := me.InterfaceToOctets(input)
704 return fmt.Sprintf("%s", bytes.Trim(ifBytes, "\x00"))
705}
706
dbainbri4d3a0dc2020-12-02 00:33:42 +0000707func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
708 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000709 return errors.New("not_implemented")
710}
711
Himani Chawla6d2ae152020-09-02 13:11:20 +0530712// 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 +0530713// 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 +0000714// 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 +0000715func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
716 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000717 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530718
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000719 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
720 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
721 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000722 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000723 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
724 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
725 return nil
726 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000727 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000728 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
729 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000730 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000731 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
732 }
733 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = true
734 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
735
736 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +0530737 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000738 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +0530739 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
740
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000741 firstLevelMap := oo.pOnuDB.meDb
divyadesaibbed37c2020-08-28 13:35:20 +0530742 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000743 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +0530744 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530745
746 secondLevelMap := make(map[string]interface{})
747 for secondLevelKey, secondLevelValue := range firstLevelValue {
748 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +0530749 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530750 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +0530751 thirdLevelMap["InstanceId"] = entityID
752 secondLevelMap[entityID] = thirdLevelMap
753 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +0530754 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
755 delete(forthLevelMap, "SerialNumber")
756 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
757
758 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530759 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +0530760 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
761 delete(forthLevelMap, "MacAddress")
762 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
763 }
764 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530765 secondLevelMap["ClassId"] = classID
766 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +0530767 }
768 mibTemplate, err := json.Marshal(&templateMap)
769 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000770 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000771 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
772 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
773 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530774 return err
775 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000776 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +0530777 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000778 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 +0000779 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
780 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
781 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530782 return err
783 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000784 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530785 return nil
786}
787
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000788func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
789 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
790 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
791 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
Girish Gowdra0b235842021-03-09 13:06:46 -0800792 me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000793 //accept also nil as (error) return value for writing to LastTx
794 // - this avoids misinterpretation of new received OMCI messages
mpagenko01499812021-03-25 10:37:12 +0000795 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
796 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
797 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000798}
799
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000800func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
801 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
802 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.sOnuPersistentData.PersMibDataSyncAdpt})
803
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000804 mdsValuesAreEqual := oo.sOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000805 if oo.pMibUploadFsm.pFsm.Is(ulStAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000806 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000807 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
808 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
809 } else {
810 logger.Warnw(ctx, "MibSync FSM - mib audit - MDS check failed for the first time!", log.Fields{"device-id": oo.deviceID})
811 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
812 }
813 } else if oo.pMibUploadFsm.pFsm.Is(ulStReAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000814 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000815 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
816 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
817 } else {
818 logger.Errorw(ctx, "MibSync FSM - mib audit - MDS check failed for the second time!", log.Fields{"device-id": oo.deviceID})
819 //TODO: send new event notification "MDS counter mismatch" to the core
820 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
821 }
822 } else if oo.pMibUploadFsm.pFsm.Is(ulStExaminingMds) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000823 if mdsValuesAreEqual && mibDataSyncOnu != 0 {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000824 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
825 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
826 } else {
827 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
828 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
829 }
830 } else {
831 logger.Warnw(ctx, "wrong state for MDS evaluation!", log.Fields{"state": oo.pMibUploadFsm.pFsm.Current(), "device-id": oo.deviceID})
832 }
833}
mpagenko15ff4a52021-03-02 10:09:20 +0000834
835//GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
836func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
837 if oo.onuSwImageIndications.activeEntityEntry.valid {
838 return oo.onuSwImageIndications.activeEntityEntry.entityID, nil
839 }
840 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
841}
842
843//GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
844func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
845 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
846 return oo.onuSwImageIndications.inactiveEntityEntry.entityID, nil
847 }
848 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
849}
850
851//IsImageToBeCommitted returns true if the active image is still uncommitted
852func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
853 if oo.onuSwImageIndications.activeEntityEntry.valid {
854 if oo.onuSwImageIndications.activeEntityEntry.entityID == aImageID {
855 if oo.onuSwImageIndications.activeEntityEntry.isCommitted == swIsUncommitted {
856 return true
857 }
858 }
859 }
860 return false //all other case are treated as 'nothing to commit
861}
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000862func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool {
863
864 oo.mibTemplatePath = oo.buildMibTemplatePath()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000865 logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath),
866 "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000867
868 restoredFromMibTemplate := false
869 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
870 if err == nil {
871 if Value != nil {
872 logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value)
873
874 // swap out tokens with specific data
875 mibTmpString, _ := kvstore.ToString(Value.Value)
876 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.sOnuPersistentData.PersSerialNumber, -1)
877 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.sOnuPersistentData.PersMacAddress, -1)
878 mibTmpBytes := []byte(mibTmpString)
879 logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes)
880
881 var firstLevelMap map[string]interface{}
882 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
883 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
884 } else {
885 for firstLevelKey, firstLevelValue := range firstLevelMap {
886 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
887 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
888 meClassID := me.ClassID(uint16ValidNumber)
889 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
890 if isSupportedClassID(meClassID) {
891 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
892 secondLevelMap := firstLevelValue.(map[string]interface{})
893 for secondLevelKey, secondLevelValue := range secondLevelMap {
894 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
895 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
896 meEntityID := uint16(uint16ValidNumber)
897 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
898 thirdLevelMap := secondLevelValue.(map[string]interface{})
899 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
900 if thirdLevelKey == "Attributes" {
901 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
902 attributesMap := thirdLevelValue.(map[string]interface{})
903 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
904 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
905 restoredFromMibTemplate = true
906 }
907 }
908 }
909 }
910 }
911 }
912 }
913 }
914 } else {
915 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
916 }
917 } else {
918 logger.Errorf(ctx, "Get from kvstore operation failed for path",
919 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
920 }
921 return restoredFromMibTemplate
922}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000923
924//CancelProcessing terminates potentially running reconciling processes and stops the FSM
925func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) {
926
927 if oo.baseDeviceHandler.isReconcilingFlows() {
928 oo.baseDeviceHandler.chReconcilingFlowsFinished <- false
929 }
930 if oo.baseDeviceHandler.isReconciling() {
931 oo.baseDeviceHandler.chReconcilingFinished <- false
932 }
933 //the MibSync FSM might be active all the ONU-active time,
934 // hence it must be stopped unconditionally
935 pMibUlFsm := oo.pMibUploadFsm.pFsm
936 if pMibUlFsm != nil {
937 _ = pMibUlFsm.Event(ulEvStop)
938 }
939}