blob: 29e0a2a2e1f43b83f293168decb058d0b30b128d [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})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000089 oo.mutexLastTxParamStruct.Lock()
Girish Gowdra0b235842021-03-09 13:06:46 -080090 _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000091 //TODO: needs to handle timeouts
mpagenko01499812021-03-25 10:37:12 +000092 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
93 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
94 oo.lastTxParamStruct.lastTxMessageType = omci.MibResetRequestType
95 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000096 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000097}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000098
dbainbri4d3a0dc2020-12-02 00:33:42 +000099func (oo *OnuDeviceEntry) enterGettingVendorAndSerialState(ctx context.Context, e *fsm.Event) {
100 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 +0000101 requestedAttributes := me.AttributeValueMap{"VendorId": "", "SerialNumber": 0}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000102 oo.mutexLastTxParamStruct.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300103 meInstance, err := 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 +0000104 //accept also nil as (error) return value for writing to LastTx
105 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300106 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000107 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300108 logger.Errorw(ctx, "ONU-G get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
109 pMibUlFsm := oo.pMibUploadFsm
110 if pMibUlFsm != nil {
111 go func(a_pAFsm *AdapterFsm) {
ozgecanetsia29111002021-05-04 22:20:26 +0300112 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300113 }(pMibUlFsm)
114 }
115 return
116 }
mpagenko01499812021-03-25 10:37:12 +0000117 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
118 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000119 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000120}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000121
dbainbri4d3a0dc2020-12-02 00:33:42 +0000122func (oo *OnuDeviceEntry) enterGettingEquipmentIDState(ctx context.Context, e *fsm.Event) {
123 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 +0000124 requestedAttributes := me.AttributeValueMap{"EquipmentId": ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000125 oo.mutexLastTxParamStruct.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300126 meInstance, err := 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 +0000127 //accept also nil as (error) return value for writing to LastTx
128 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300129 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000130 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300131 logger.Errorw(ctx, "ONU2-G get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
132 pMibUlFsm := oo.pMibUploadFsm
133 if pMibUlFsm != nil {
134 go func(a_pAFsm *AdapterFsm) {
ozgecanetsia29111002021-05-04 22:20:26 +0300135 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300136 }(pMibUlFsm)
137 }
138 return
139 }
mpagenko01499812021-03-25 10:37:12 +0000140 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
141 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000142 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000143}
144
dbainbri4d3a0dc2020-12-02 00:33:42 +0000145func (oo *OnuDeviceEntry) enterGettingFirstSwVersionState(ctx context.Context, e *fsm.Event) {
146 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 +0000147 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000148 oo.mutexLastTxParamStruct.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300149 meInstance, err := 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 +0000150 //accept also nil as (error) return value for writing to LastTx
151 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300152 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000153 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300154 logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
155 pMibUlFsm := oo.pMibUploadFsm
156 if pMibUlFsm != nil {
157 go func(a_pAFsm *AdapterFsm) {
ozgecanetsia29111002021-05-04 22:20:26 +0300158 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300159 }(pMibUlFsm)
160 }
161 return
162 }
mpagenko01499812021-03-25 10:37:12 +0000163 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
164 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000165 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000166}
167
dbainbri4d3a0dc2020-12-02 00:33:42 +0000168func (oo *OnuDeviceEntry) enterGettingSecondSwVersionState(ctx context.Context, e *fsm.Event) {
169 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 +0000170 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000171 oo.mutexLastTxParamStruct.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300172 meInstance, err := 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 +0000173 //accept also nil as (error) return value for writing to LastTx
174 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300175 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000176 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300177 logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
178 pMibUlFsm := oo.pMibUploadFsm
179 if pMibUlFsm != nil {
180 go func(a_pAFsm *AdapterFsm) {
ozgecanetsia29111002021-05-04 22:20:26 +0300181 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300182 }(pMibUlFsm)
183 }
184 return
185 }
mpagenko01499812021-03-25 10:37:12 +0000186 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
187 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000188 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000189}
190
dbainbri4d3a0dc2020-12-02 00:33:42 +0000191func (oo *OnuDeviceEntry) enterGettingMacAddressState(ctx context.Context, e *fsm.Event) {
192 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 +0000193 requestedAttributes := me.AttributeValueMap{"MacAddress": ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000194 oo.mutexLastTxParamStruct.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300195 meInstance, err := 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 +0000196 //accept also nil as (error) return value for writing to LastTx
197 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300198 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000199 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300200 logger.Errorw(ctx, "IpHostConfigData get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
201 pMibUlFsm := oo.pMibUploadFsm
202 if pMibUlFsm != nil {
203 go func(a_pAFsm *AdapterFsm) {
ozgecanetsia29111002021-05-04 22:20:26 +0300204 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300205 }(pMibUlFsm)
206 }
207 return
208 }
mpagenko01499812021-03-25 10:37:12 +0000209 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
210 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000211 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000212}
213
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000214func (oo *OnuDeviceEntry) enterGettingMibTemplateState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000215
mpagenko15ff4a52021-03-02 10:09:20 +0000216 if oo.onuSwImageIndications.activeEntityEntry.valid {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000217 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000218 oo.sOnuPersistentData.PersActiveSwVersion = oo.onuSwImageIndications.activeEntityEntry.version
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000219 oo.mutexPersOnuConfig.Unlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000220 } else {
221 logger.Errorw(ctx, "get-mib-template: no active SW version found, working with empty SW version, which might be untrustworthy",
222 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000223 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000224 if oo.getMibFromTemplate(ctx) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000225 logger.Debug(ctx, "MibSync FSM - valid MEs stored from template")
226 oo.pOnuDB.logMeDb(ctx)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000227 fsmMsg = LoadMibTemplateOk
228 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000229 logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000230 fsmMsg = LoadMibTemplateFailed
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000231
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000232 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
233 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
234 if mibTemplateIsGenerated {
235 logger.Debugw(ctx,
236 "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map",
237 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
238 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
239 }
240 }
241 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
242 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000243 mibSyncMsg := Message{
244 Type: TestMsg,
245 Data: TestMessage{
246 TestMessageVal: fsmMsg,
247 },
248 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000249 oo.pMibUploadFsm.commChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000250}
251
dbainbri4d3a0dc2020-12-02 00:33:42 +0000252func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
253 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 -0800254 _ = oo.PDevOmciCC.sendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000255 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
256 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000257 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000258 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000259 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000260}
261
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000262func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000263 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID})
264 oo.transferSystemEvent(ctx, MibDatabaseSync)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000265 go func() {
266 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
267 }()
268}
269
270func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000271 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000272 oo.sOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix())
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000273 oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000274 if oo.mibAuditInterval > 0 {
275 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 +0000276 go func() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000277 time.Sleep(oo.mibAuditInterval)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000278 if err := oo.pMibUploadFsm.pFsm.Event(ulEvAuditMib); err != nil {
279 logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err})
280 }
281 }()
282 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000283}
284
dbainbri4d3a0dc2020-12-02 00:33:42 +0000285func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
286 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 +0000287 oo.requestMdsValue(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000288}
289
dbainbri4d3a0dc2020-12-02 00:33:42 +0000290func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
291 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
292 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000293 // TODOs:
294 // VOL-3805 - Provide exclusive OMCI channel for one FSM
295 // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go
296 // VOL-3792 - Support periodical audit via mib resync
297 // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000298}
299
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000300func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) {
301 logger.Debugw(ctx, "MibSync FSM",
302 log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID})
303
304 if oo.getMibFromTemplate(ctx) {
305 oo.baseDeviceHandler.startReconciling(ctx, true)
306 oo.baseDeviceHandler.addAllUniPorts(ctx)
307 oo.baseDeviceHandler.setDeviceReason(drInitialMibDownloaded)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000308 oo.baseDeviceHandler.setReadyForOmciConfig(true)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000309 // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm
310
311 oo.baseDeviceHandler.reconcileDeviceTechProf(ctx)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000312
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000313 // start go routine with select() on reconciling flow channel before
314 // starting flow reconciling process to prevent loss of any signal
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000315 go func() {
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000316 // In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until
317 // we get a signal that the processing of the last step to rebuild the adapter internal
318 // flow data is finished.
319 select {
320 case success := <-oo.baseDeviceHandler.chReconcilingFlowsFinished:
321 if success {
322 logger.Debugw(ctx, "reconciling flows has been finished in time",
323 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000324 oo.baseDeviceHandler.stopReconciling(ctx)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000325 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000326
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000327 } else {
328 logger.Debugw(ctx, "wait for reconciling flows aborted",
329 log.Fields{"device-id": oo.deviceID})
330 oo.baseDeviceHandler.setReconcilingFlows(false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000331 }
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000332 case <-time.After(500 * time.Millisecond):
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000333 logger.Errorw(ctx, "timeout waiting for reconciling flows to be finished!",
334 log.Fields{"device-id": oo.deviceID})
335 oo.baseDeviceHandler.setReconcilingFlows(false)
336 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
337 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000338 }()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000339 oo.baseDeviceHandler.reconcileDeviceFlowConfig(ctx)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000340
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000341 oo.mutexPersOnuConfig.RLock()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000342 if oo.sOnuPersistentData.PersUniDisableDone {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000343 oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000344 oo.baseDeviceHandler.disableUniPortStateUpdate(ctx)
345 oo.baseDeviceHandler.setDeviceReason(drOmciAdminLock)
346 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000347 oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000348 oo.baseDeviceHandler.enableUniPortStateUpdate(ctx)
349 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000350 } else {
351 logger.Debugw(ctx, "MibSync FSM",
352 log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID})
353 go func() {
354 //switch to reconciling with OMCI config
355 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
356 }()
357 }
358}
359
dbainbri4d3a0dc2020-12-02 00:33:42 +0000360func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000361 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 +0000362 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000363 oo.requestMdsValue(ctx)
364 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000365 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 +0000366 go func() {
367 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
368 }()
369 }
370}
371
372func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
373 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 +0000374 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000375 oo.requestMdsValue(ctx)
376 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000377 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 +0000378 go func() {
379 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
380 }()
381 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000382}
383
dbainbri4d3a0dc2020-12-02 00:33:42 +0000384func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
385 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
386 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000387}
388
dbainbri4d3a0dc2020-12-02 00:33:42 +0000389func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
390 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 +0000391loop:
392 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000393 // case <-ctx.Done():
394 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
395 // break loop
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000396 message, ok := <-oo.pMibUploadFsm.commChan
Himani Chawla4d908332020-08-31 12:30:20 +0530397 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000398 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 +0530399 break loop
400 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000401 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000402
Himani Chawla4d908332020-08-31 12:30:20 +0530403 switch message.Type {
404 case TestMsg:
405 msg, _ := message.Data.(TestMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000406 oo.handleTestMsg(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530407 case OMCI:
408 msg, _ := message.Data.(OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000409 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530410 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000411 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 +0000412 }
413 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000414 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000415 // TODO: only this action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000416 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000417}
418
dbainbri4d3a0dc2020-12-02 00:33:42 +0000419func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000420
dbainbri4d3a0dc2020-12-02 00:33:42 +0000421 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 +0000422
423 switch msg.TestMessageVal {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000424 case LoadMibTemplateFailed:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000425 _ = oo.pMibUploadFsm.pFsm.Event(ulEvUploadMib)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000426 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000427 case LoadMibTemplateOk:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000428 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000429 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000430 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000431 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 +0000432 }
433}
434
dbainbri4d3a0dc2020-12-02 00:33:42 +0000435func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg OmciMessage) {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000436 if oo.pMibUploadFsm.pFsm.Is(ulStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530437 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
438 if msgLayer != nil {
439 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
440 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000441 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530442 if msgObj.Result == me.Success {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000443 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000444 oo.sOnuPersistentData.PersMibDataSyncAdpt = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000445 oo.mutexPersOnuConfig.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530446 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000447 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530448 return
449 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000450 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530451 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000452 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530453 }
454 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000455 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530456 }
457 } else {
mpagenko01499812021-03-25 10:37:12 +0000458 //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset
459 // with Sequence number 0x8000 as last request before - so it may still respond to that
460 // then we may force the ONU to react on the MdsGetRequest with a new message that uses an increased Sequence number
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000461 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000462 if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
463 logger.Debugw(ctx, "MibSync FSM - repeat MdsGetRequest (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
464 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
ozgecanetsiab36ed572021-04-01 10:38:48 +0300465 _, err := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
mpagenko01499812021-03-25 10:37:12 +0000466 me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300467 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000468 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300469 logger.Errorw(ctx, "ONUData get failed, aborting MibSync", log.Fields{"device-id": oo.deviceID})
ozgecanetsia29111002021-05-04 22:20:26 +0300470 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300471 return
472 }
mpagenko01499812021-03-25 10:37:12 +0000473 //TODO: needs extra handling of timeouts
474 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000475 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000476 return
477 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000478 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000479 logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
480 //perhaps some still lingering message from some prior activity, let's wait for the real response
481 return
Himani Chawla4d908332020-08-31 12:30:20 +0530482 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000483 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000484 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530485}
486
dbainbri4d3a0dc2020-12-02 00:33:42 +0000487func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530488 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
489 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000490 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530491 return
492 }
493 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
494 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000495 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530496 return
497 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000498 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530499 /* to be verified / reworked !!! */
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000500 oo.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
501 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800502 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000503 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
504 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000505 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000506 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000507 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530508 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000509 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 +0530510 //TODO right action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000511 _ = oo.pMibUploadFsm.pFsm.Event(ulEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530512 }
513}
514
dbainbri4d3a0dc2020-12-02 00:33:42 +0000515func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530516 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
Andrea Campanella6515c582020-10-05 11:25:00 +0200517
Holger Hildebrandte2439342020-12-03 16:06:54 +0000518 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000519 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000520 return
521 }
522 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
523 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000524 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000525 return
526 }
527 meName := msgObj.ReportedME.GetName()
528 if meName == "UnknownItuG988ManagedEntity" || meName == "UnknownVendorSpecificManagedEntity" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000529 logger.Debugw(ctx, "MibUploadNextResponse Data for unknown ME received - temporary workaround is to ignore it!",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000530 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj, "meName": meName})
531 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000532 logger.Debugw(ctx, "MibUploadNextResponse Data for:",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000533 log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
Holger Hildebrandt8998b872020-10-05 13:48:39 +0000534 meClassID := msgObj.ReportedME.GetClassID()
535 meEntityID := msgObj.ReportedME.GetEntityID()
536 meAttributes := msgObj.ReportedME.GetAttributeValueMap()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000537 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes)
Himani Chawla4d908332020-08-31 12:30:20 +0530538 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000539 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800540 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000541 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
542 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000543 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000544 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000545 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530546 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000547 oo.pOnuDB.logMeDb(ctx)
548 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530549 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000550 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 +0530551 }
552
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000553 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530554 }
555}
556
dbainbri4d3a0dc2020-12-02 00:33:42 +0000557func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000558 var err error = nil
mpagenko01499812021-03-25 10:37:12 +0000559
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000560 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000561 if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType ||
562 oo.lastTxParamStruct.pLastTxMeInstance == nil {
563 //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest
564 // with Sequence number 0x8000 as last request before - so it may still respond to that
565 // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number
566 if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
567 logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
568 _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
569 //TODO: needs extra handling of timeouts
570 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000571 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000572 return nil
573 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000574 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000575 logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
576 //perhaps some still lingering message from some prior activity, let's wait for the real response
577 return nil
578 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000579 oo.mutexLastTxParamStruct.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530580 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000581 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000582 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 +0000583 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
584 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 +0000585 }
586 msgObj, msgOk := msgLayer.(*omci.GetResponse)
587 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000588 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 +0000589 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
590 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 +0000591 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000592 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000593 if msgObj.Result == me.Success {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000594 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000595 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
596 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000597 meAttributes := msgObj.Attributes
mpagenko01499812021-03-25 10:37:12 +0000598 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000599 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 +0000600 switch meInstance {
601 case "OnuG":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000602 oo.mutexLastTxParamStruct.RUnlock()
603 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000604 oo.sOnuPersistentData.PersVendorID = trimStringFromInterface(meAttributes["VendorId"])
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000605 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
606 if onugSerialNumberLen == len(snBytes) {
607 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
608 snNumberPart := hex.EncodeToString(snBytes[4:])
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000609 oo.sOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000610 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 +0000611 "onuDeviceEntry.vendorID": oo.sOnuPersistentData.PersVendorID, "onuDeviceEntry.serialNumber": oo.sOnuPersistentData.PersSerialNumber})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000612 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000613 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 +0000614 oo.sOnuPersistentData.PersSerialNumber = cEmptySerialNumberString
Himani Chawla4d908332020-08-31 12:30:20 +0530615 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000616 oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000617 // trigger retrieval of EquipmentId
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000618 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000619 return nil
620 case "Onu2G":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000621 oo.mutexLastTxParamStruct.RUnlock()
622 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000623 oo.sOnuPersistentData.PersEquipmentID = trimStringFromInterface(meAttributes["EquipmentId"])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000624 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000625 "onuDeviceEntry.equipmentID": oo.sOnuPersistentData.PersEquipmentID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000626 oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000627 // trigger retrieval of 1st SW-image info
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000628 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000629 return nil
630 case "SoftwareImage":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000631 oo.mutexLastTxParamStruct.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000632 if entityID > secondSwImageMeID {
633 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
634 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
635 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
636 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000637 }
mpagenko15ff4a52021-03-02 10:09:20 +0000638 // need to use function for go lint complexity
639 oo.handleSwImageIndications(ctx, entityID, meAttributes)
640 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000641 case "IpHostConfigData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000642 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000643 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000644 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000645 if omciMacAddressLen == len(macBytes) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000646 oo.sOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000647 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000648 "macAddress": oo.sOnuPersistentData.PersMacAddress})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000649 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000650 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 +0000651 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000652 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000653 oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000654 // trigger retrieval of mib template
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000655 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000656 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000657 case "OnuData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000658 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000659 oo.checkMdsValue(ctx, meAttributes["MibDataSync"].(uint8))
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000660 return nil
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000661 default:
662 oo.mutexLastTxParamStruct.RUnlock()
663 logger.Warnw(ctx, "Unsupported ME name received!",
664 log.Fields{"ME name": meInstance, "device-id": oo.deviceID})
665
Himani Chawla4d908332020-08-31 12:30:20 +0530666 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800667 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000668 oo.mutexLastTxParamStruct.RUnlock()
669 logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ",
670 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000671 }
Himani Chawla4d908332020-08-31 12:30:20 +0530672 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000673 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000674 return nil
675 }
Himani Chawla4d908332020-08-31 12:30:20 +0530676 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000677 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000678 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000679 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530680}
681
mpagenko15ff4a52021-03-02 10:09:20 +0000682func (oo *OnuDeviceEntry) handleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) {
683 imageIsCommitted := meAttributes["IsCommitted"].(uint8)
684 imageIsActive := meAttributes["IsActive"].(uint8)
685 imageVersion := trimStringFromInterface(meAttributes["Version"])
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000686 oo.mutexPersOnuConfig.RLock()
mpagenko15ff4a52021-03-02 10:09:20 +0000687 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
688 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000689 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.sOnuPersistentData.PersSerialNumber})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000690 oo.mutexPersOnuConfig.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000691 if firstSwImageMeID == entityID {
692 //always accept the state of the first image (2nd image info should not yet be available)
693 if imageIsActive == swIsActive {
694 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
695 oo.onuSwImageIndications.activeEntityEntry.valid = true
696 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
697 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000698 //as the SW version indication may stem from some ONU Down/up event
699 //the complementary image state is to be invalidated
700 // (state of the second image is always expected afterwards or just invalid)
701 oo.onuSwImageIndications.inactiveEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000702 } else {
703 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
704 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
705 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
706 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000707 //as the SW version indication may stem form some ONU Down/up event
708 //the complementary image state is to be invalidated
709 // (state of the second image is always expected afterwards or just invalid)
710 oo.onuSwImageIndications.activeEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000711 }
712 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion)
713 return
714 } else if secondSwImageMeID == entityID {
715 //2nd image info might conflict with first image info, in which case we priorize first image info!
716 if imageIsActive == swIsActive { //2nd image reported to be active
717 if oo.onuSwImageIndications.activeEntityEntry.valid {
718 //conflict exists - state of first image is left active
719 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
720 log.Fields{"device-id": oo.deviceID})
721 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
722 oo.onuSwImageIndications.inactiveEntityEntry.valid = true ////to indicate that at least something has been reported
723 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
724 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
725 } else { //first image inactive, this one active
726 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
727 oo.onuSwImageIndications.activeEntityEntry.valid = true
728 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
729 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
730 }
731 } else { //2nd image reported to be inactive
732 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
733 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
734 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
735 log.Fields{"device-id": oo.deviceID})
736 oo.onuSwImageIndications.activeEntityEntry.entityID = firstSwImageMeID
737 oo.onuSwImageIndications.activeEntityEntry.valid = true //to indicate that at least something has been reported
738 //copy active commit/version from the previously stored inactive position
739 oo.onuSwImageIndications.activeEntityEntry.version = oo.onuSwImageIndications.inactiveEntityEntry.version
740 oo.onuSwImageIndications.activeEntityEntry.isCommitted = oo.onuSwImageIndications.inactiveEntityEntry.isCommitted
741 }
742 //in any case we indicate (and possibly overwrite) the second image indications as inactive
743 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
744 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
745 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
746 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
747 }
748 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress)
749 return
750 }
751}
752
dbainbri4d3a0dc2020-12-02 00:33:42 +0000753func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg OmciMessage) {
754 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200755 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000756 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
757 switch msg.OmciMsg.MessageType {
758 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000759 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000760
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000761 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000762 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530763
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000764 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000765 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000766
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000767 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000768 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000769 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530770
Andrea Campanella6515c582020-10-05 11:25:00 +0200771 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000772 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200773
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000774 }
775}
776
dbainbri4d3a0dc2020-12-02 00:33:42 +0000777func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000778 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000779 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 +0000780 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
781 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000782 oo.mutexLastTxParamStruct.RLock()
783 if oo.lastTxParamStruct.pLastTxMeInstance != nil {
784 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
785 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
786 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
787 switch meInstance {
788 case "IpHostConfigData":
789 oo.mutexLastTxParamStruct.RUnlock()
790 logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros",
791 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
792 oo.mutexPersOnuConfig.Lock()
793 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
794 oo.mutexPersOnuConfig.Unlock()
795 // trigger retrieval of mib template
796 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
797 return nil
798 default:
799 oo.mutexLastTxParamStruct.RUnlock()
800 logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
801 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
802 }
803 } else {
804 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000805 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000806 } else {
807 oo.mutexLastTxParamStruct.RUnlock()
808 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000809 }
810 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000811 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 +0000812 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
813 }
814 return err
815}
816
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000817func (oo *OnuDeviceEntry) isNewOnu() bool {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000818 oo.mutexPersOnuConfig.RLock()
819 defer oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000820 return oo.sOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000821}
822
Himani Chawla6d2ae152020-09-02 13:11:20 +0530823func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000824 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530825 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000826 return true
827 }
828 }
829 return false
830}
831
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000832func trimStringFromInterface(input interface{}) string {
833 ifBytes, _ := me.InterfaceToOctets(input)
834 return fmt.Sprintf("%s", bytes.Trim(ifBytes, "\x00"))
835}
836
dbainbri4d3a0dc2020-12-02 00:33:42 +0000837func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
838 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000839 return errors.New("not_implemented")
840}
841
Himani Chawla6d2ae152020-09-02 13:11:20 +0530842// 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 +0530843// 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 +0000844// 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 +0000845func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
846 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000847 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530848
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000849 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
850 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
851 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000852 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000853 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
854 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
855 return nil
856 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000857 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000858 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
859 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000860 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000861 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
862 }
863 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = true
864 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
865
866 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +0530867 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000868 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +0530869 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
870
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000871 firstLevelMap := oo.pOnuDB.meDb
divyadesaibbed37c2020-08-28 13:35:20 +0530872 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000873 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +0530874 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530875
876 secondLevelMap := make(map[string]interface{})
877 for secondLevelKey, secondLevelValue := range firstLevelValue {
878 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +0530879 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530880 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +0530881 thirdLevelMap["InstanceId"] = entityID
882 secondLevelMap[entityID] = thirdLevelMap
883 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +0530884 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
885 delete(forthLevelMap, "SerialNumber")
886 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
887
888 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530889 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +0530890 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
891 delete(forthLevelMap, "MacAddress")
892 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
893 }
894 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530895 secondLevelMap["ClassId"] = classID
896 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +0530897 }
898 mibTemplate, err := json.Marshal(&templateMap)
899 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000900 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000901 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
902 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
903 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530904 return err
905 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000906 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +0530907 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000908 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 +0000909 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
910 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
911 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530912 return err
913 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000914 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530915 return nil
916}
917
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000918func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
919 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
920 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
ozgecanetsiab36ed572021-04-01 10:38:48 +0300921 meInstance, err := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
Girish Gowdra0b235842021-03-09 13:06:46 -0800922 me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000923 //accept also nil as (error) return value for writing to LastTx
924 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300925 if err != nil {
926 logger.Errorw(ctx, "ONUData get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
927 pMibUlFsm := oo.pMibUploadFsm
928 if pMibUlFsm != nil {
929 go func(a_pAFsm *AdapterFsm) {
ozgecanetsia29111002021-05-04 22:20:26 +0300930 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300931 }(pMibUlFsm)
932 }
933 return
934 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000935 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000936 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
937 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
938 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000939 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000940}
941
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000942func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000943 oo.mutexPersOnuConfig.RLock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000944 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
945 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.sOnuPersistentData.PersMibDataSyncAdpt})
946
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000947 mdsValuesAreEqual := oo.sOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000948 oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000949 if oo.pMibUploadFsm.pFsm.Is(ulStAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000950 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000951 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
952 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
953 } else {
954 logger.Warnw(ctx, "MibSync FSM - mib audit - MDS check failed for the first time!", log.Fields{"device-id": oo.deviceID})
955 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
956 }
957 } else if oo.pMibUploadFsm.pFsm.Is(ulStReAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000958 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000959 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
960 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
961 } else {
962 logger.Errorw(ctx, "MibSync FSM - mib audit - MDS check failed for the second time!", log.Fields{"device-id": oo.deviceID})
963 //TODO: send new event notification "MDS counter mismatch" to the core
964 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
965 }
966 } else if oo.pMibUploadFsm.pFsm.Is(ulStExaminingMds) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000967 if mdsValuesAreEqual && mibDataSyncOnu != 0 {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000968 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
969 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
970 } else {
971 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
972 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
973 }
974 } else {
975 logger.Warnw(ctx, "wrong state for MDS evaluation!", log.Fields{"state": oo.pMibUploadFsm.pFsm.Current(), "device-id": oo.deviceID})
976 }
977}
mpagenko15ff4a52021-03-02 10:09:20 +0000978
979//GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
980func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
981 if oo.onuSwImageIndications.activeEntityEntry.valid {
982 return oo.onuSwImageIndications.activeEntityEntry.entityID, nil
983 }
984 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
985}
986
987//GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
988func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
989 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
990 return oo.onuSwImageIndications.inactiveEntityEntry.entityID, nil
991 }
992 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
993}
994
995//IsImageToBeCommitted returns true if the active image is still uncommitted
996func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
997 if oo.onuSwImageIndications.activeEntityEntry.valid {
998 if oo.onuSwImageIndications.activeEntityEntry.entityID == aImageID {
999 if oo.onuSwImageIndications.activeEntityEntry.isCommitted == swIsUncommitted {
1000 return true
1001 }
1002 }
1003 }
1004 return false //all other case are treated as 'nothing to commit
1005}
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001006func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool {
1007
1008 oo.mibTemplatePath = oo.buildMibTemplatePath()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +00001009 logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath),
1010 "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001011
1012 restoredFromMibTemplate := false
1013 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
1014 if err == nil {
1015 if Value != nil {
1016 logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value)
1017
1018 // swap out tokens with specific data
1019 mibTmpString, _ := kvstore.ToString(Value.Value)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001020 oo.mutexPersOnuConfig.RLock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001021 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.sOnuPersistentData.PersSerialNumber, -1)
1022 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.sOnuPersistentData.PersMacAddress, -1)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001023 oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001024 mibTmpBytes := []byte(mibTmpString)
1025 logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes)
1026
1027 var firstLevelMap map[string]interface{}
1028 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
1029 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
1030 } else {
1031 for firstLevelKey, firstLevelValue := range firstLevelMap {
1032 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
1033 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
1034 meClassID := me.ClassID(uint16ValidNumber)
1035 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
1036 if isSupportedClassID(meClassID) {
1037 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
1038 secondLevelMap := firstLevelValue.(map[string]interface{})
1039 for secondLevelKey, secondLevelValue := range secondLevelMap {
1040 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
1041 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
1042 meEntityID := uint16(uint16ValidNumber)
1043 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
1044 thirdLevelMap := secondLevelValue.(map[string]interface{})
1045 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
1046 if thirdLevelKey == "Attributes" {
1047 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
1048 attributesMap := thirdLevelValue.(map[string]interface{})
1049 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
1050 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
1051 restoredFromMibTemplate = true
1052 }
1053 }
1054 }
1055 }
1056 }
1057 }
1058 }
1059 }
1060 } else {
1061 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1062 }
1063 } else {
1064 logger.Errorf(ctx, "Get from kvstore operation failed for path",
1065 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1066 }
1067 return restoredFromMibTemplate
1068}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001069
1070//CancelProcessing terminates potentially running reconciling processes and stops the FSM
1071func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) {
1072
1073 if oo.baseDeviceHandler.isReconcilingFlows() {
1074 oo.baseDeviceHandler.chReconcilingFlowsFinished <- false
1075 }
1076 if oo.baseDeviceHandler.isReconciling() {
1077 oo.baseDeviceHandler.chReconcilingFinished <- false
1078 }
1079 //the MibSync FSM might be active all the ONU-active time,
1080 // hence it must be stopped unconditionally
1081 pMibUlFsm := oo.pMibUploadFsm.pFsm
1082 if pMibUlFsm != nil {
1083 _ = pMibUlFsm.Event(ulEvStop)
1084 }
1085}