blob: 564be6f77813f4d0829a5712839dd33a52c08f7e [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 (
21 "context"
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000022 "encoding/hex"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000023 "encoding/json"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000024 "errors"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000025 "fmt"
26 "strconv"
mpagenko3af1f032020-06-10 08:53:41 +000027 "strings"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000028
29 "github.com/looplab/fsm"
30
31 //"sync"
divyadesaibbed37c2020-08-28 13:35:20 +053032 "time"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000033
dbainbri4d3a0dc2020-12-02 00:33:42 +000034 //"github.com/opencord/voltha-lib-go/v4/pkg/kafka"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000035 "github.com/opencord/omci-lib-go"
36 me "github.com/opencord/omci-lib-go/generated"
dbainbri4d3a0dc2020-12-02 00:33:42 +000037 "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore"
38 "github.com/opencord/voltha-lib-go/v4/pkg/log"
39 //ic "github.com/opencord/voltha-protos/v4/go/inter_container"
40 //"github.com/opencord/voltha-protos/v4/go/openflow_13"
41 //"github.com/opencord/voltha-protos/v4/go/voltha"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000042)
43
mpagenko01499812021-03-25 10:37:12 +000044type sLastTxMeParameter struct {
45 lastTxMessageType omci.MessageType
46 pLastTxMeInstance *me.ManagedEntity
47 repeatCount uint8
48}
49
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000050var supportedClassIds = []me.ClassID{
51 me.CardholderClassID, // 5
52 me.CircuitPackClassID, // 6
53 me.SoftwareImageClassID, // 7
54 me.PhysicalPathTerminationPointEthernetUniClassID, // 11
55 me.OltGClassID, // 131
56 me.OnuPowerSheddingClassID, // 133
57 me.IpHostConfigDataClassID, // 134
58 me.OnuGClassID, // 256
59 me.Onu2GClassID, // 257
60 me.TContClassID, // 262
61 me.AniGClassID, // 263
62 me.UniGClassID, // 264
63 me.PriorityQueueClassID, // 277
64 me.TrafficSchedulerClassID, // 278
65 me.VirtualEthernetInterfacePointClassID, // 329
66 me.EnhancedSecurityControlClassID, // 332
67 me.OnuDynamicPowerManagementControlClassID, // 336
68 // 347 // definitions for ME "IPv6 host config data" are currently missing in omci-lib-go!
69}
70
71var fsmMsg TestMessageType
72
dbainbri4d3a0dc2020-12-02 00:33:42 +000073func (oo *OnuDeviceEntry) enterStartingState(ctx context.Context, e *fsm.Event) {
74 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": oo.deviceID})
75 oo.pOnuDB = newOnuDeviceDB(log.WithSpanFromContext(context.TODO(), ctx), oo)
76 go oo.processMibSyncMessages(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000077}
78
dbainbri4d3a0dc2020-12-02 00:33:42 +000079func (oo *OnuDeviceEntry) enterResettingMibState(ctx context.Context, e *fsm.Event) {
80 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 +000081
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +000082 if (!oo.isNewOnu() && !oo.baseDeviceHandler.isReconciling()) || //use case: re-auditing failed
83 oo.baseDeviceHandler.isSkipOnuConfigReconciling() { //use case: reconciling without omci-config failed
Holger Hildebrandt10d98192021-01-27 15:29:31 +000084 oo.baseDeviceHandler.prepareReconcilingWithActiveAdapter(ctx)
85 oo.devState = DeviceStatusInit
86 }
dbainbri4d3a0dc2020-12-02 00:33:42 +000087 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send mibReset in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000088 oo.mutexLastTxParamStruct.Lock()
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 Hildebrandt0da7e6f2021-05-12 13:08:43 +000095 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000096}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000097
dbainbri4d3a0dc2020-12-02 00:33:42 +000098func (oo *OnuDeviceEntry) enterGettingVendorAndSerialState(ctx context.Context, e *fsm.Event) {
99 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 +0000100 requestedAttributes := me.AttributeValueMap{"VendorId": "", "SerialNumber": 0}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000101 oo.mutexLastTxParamStruct.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300102 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 +0000103 //accept also nil as (error) return value for writing to LastTx
104 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300105 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000106 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300107 logger.Errorw(ctx, "ONU-G get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
108 pMibUlFsm := oo.pMibUploadFsm
109 if pMibUlFsm != nil {
110 go func(a_pAFsm *AdapterFsm) {
ozgecanetsia29111002021-05-04 22:20:26 +0300111 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300112 }(pMibUlFsm)
113 }
114 return
115 }
mpagenko01499812021-03-25 10:37:12 +0000116 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
117 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000118 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000119}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000120
dbainbri4d3a0dc2020-12-02 00:33:42 +0000121func (oo *OnuDeviceEntry) enterGettingEquipmentIDState(ctx context.Context, e *fsm.Event) {
122 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 +0000123 requestedAttributes := me.AttributeValueMap{"EquipmentId": ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000124 oo.mutexLastTxParamStruct.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300125 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 +0000126 //accept also nil as (error) return value for writing to LastTx
127 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300128 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000129 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300130 logger.Errorw(ctx, "ONU2-G get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
131 pMibUlFsm := oo.pMibUploadFsm
132 if pMibUlFsm != nil {
133 go func(a_pAFsm *AdapterFsm) {
ozgecanetsia29111002021-05-04 22:20:26 +0300134 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300135 }(pMibUlFsm)
136 }
137 return
138 }
mpagenko01499812021-03-25 10:37:12 +0000139 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
140 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000141 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000142}
143
dbainbri4d3a0dc2020-12-02 00:33:42 +0000144func (oo *OnuDeviceEntry) enterGettingFirstSwVersionState(ctx context.Context, e *fsm.Event) {
145 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 +0000146 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000147 oo.mutexLastTxParamStruct.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300148 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 +0000149 //accept also nil as (error) return value for writing to LastTx
150 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300151 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000152 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300153 logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
154 pMibUlFsm := oo.pMibUploadFsm
155 if pMibUlFsm != nil {
156 go func(a_pAFsm *AdapterFsm) {
ozgecanetsia29111002021-05-04 22:20:26 +0300157 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300158 }(pMibUlFsm)
159 }
160 return
161 }
mpagenko01499812021-03-25 10:37:12 +0000162 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
163 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000164 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000165}
166
dbainbri4d3a0dc2020-12-02 00:33:42 +0000167func (oo *OnuDeviceEntry) enterGettingSecondSwVersionState(ctx context.Context, e *fsm.Event) {
168 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 +0000169 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000170 oo.mutexLastTxParamStruct.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300171 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 +0000172 //accept also nil as (error) return value for writing to LastTx
173 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300174 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000175 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300176 logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
177 pMibUlFsm := oo.pMibUploadFsm
178 if pMibUlFsm != nil {
179 go func(a_pAFsm *AdapterFsm) {
ozgecanetsia29111002021-05-04 22:20:26 +0300180 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300181 }(pMibUlFsm)
182 }
183 return
184 }
mpagenko01499812021-03-25 10:37:12 +0000185 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
186 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000187 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000188}
189
dbainbri4d3a0dc2020-12-02 00:33:42 +0000190func (oo *OnuDeviceEntry) enterGettingMacAddressState(ctx context.Context, e *fsm.Event) {
191 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 +0000192 requestedAttributes := me.AttributeValueMap{"MacAddress": ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000193 oo.mutexLastTxParamStruct.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300194 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 +0000195 //accept also nil as (error) return value for writing to LastTx
196 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300197 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000198 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300199 logger.Errorw(ctx, "IpHostConfigData get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
200 pMibUlFsm := oo.pMibUploadFsm
201 if pMibUlFsm != nil {
202 go func(a_pAFsm *AdapterFsm) {
ozgecanetsia29111002021-05-04 22:20:26 +0300203 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300204 }(pMibUlFsm)
205 }
206 return
207 }
mpagenko01499812021-03-25 10:37:12 +0000208 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
209 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000210 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000211}
212
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000213func (oo *OnuDeviceEntry) enterGettingMibTemplateState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000214
mpagenko15ff4a52021-03-02 10:09:20 +0000215 if oo.onuSwImageIndications.activeEntityEntry.valid {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000216 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000217 oo.sOnuPersistentData.PersActiveSwVersion = oo.onuSwImageIndications.activeEntityEntry.version
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000218 oo.mutexPersOnuConfig.Unlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000219 } else {
220 logger.Errorw(ctx, "get-mib-template: no active SW version found, working with empty SW version, which might be untrustworthy",
221 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000222 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000223 if oo.getMibFromTemplate(ctx) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000224 logger.Debug(ctx, "MibSync FSM - valid MEs stored from template")
225 oo.pOnuDB.logMeDb(ctx)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000226 fsmMsg = LoadMibTemplateOk
227 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000228 logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000229 fsmMsg = LoadMibTemplateFailed
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000230
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000231 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
232 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
233 if mibTemplateIsGenerated {
234 logger.Debugw(ctx,
235 "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map",
236 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
237 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
238 }
239 }
240 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
241 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000242 mibSyncMsg := Message{
243 Type: TestMsg,
244 Data: TestMessage{
245 TestMessageVal: fsmMsg,
246 },
247 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000248 oo.pMibUploadFsm.commChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000249}
250
dbainbri4d3a0dc2020-12-02 00:33:42 +0000251func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
252 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 -0800253 _ = oo.PDevOmciCC.sendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000254 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
255 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000256 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000257 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000258 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000259}
260
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000261func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000262 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID})
263 oo.transferSystemEvent(ctx, MibDatabaseSync)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000264 go func() {
265 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
266 }()
267}
268
269func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000270 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000271 oo.sOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix())
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000272 oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000273 if oo.mibAuditInterval > 0 {
274 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 +0000275 go func() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000276 time.Sleep(oo.mibAuditInterval)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000277 if err := oo.pMibUploadFsm.pFsm.Event(ulEvAuditMib); err != nil {
278 logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err})
279 }
280 }()
281 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000282}
283
dbainbri4d3a0dc2020-12-02 00:33:42 +0000284func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
285 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 +0000286 oo.requestMdsValue(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000287}
288
dbainbri4d3a0dc2020-12-02 00:33:42 +0000289func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
290 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
291 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000292 // TODOs:
293 // VOL-3805 - Provide exclusive OMCI channel for one FSM
294 // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go
295 // VOL-3792 - Support periodical audit via mib resync
296 // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000297}
298
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000299func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) {
300 logger.Debugw(ctx, "MibSync FSM",
301 log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID})
302
303 if oo.getMibFromTemplate(ctx) {
304 oo.baseDeviceHandler.startReconciling(ctx, true)
305 oo.baseDeviceHandler.addAllUniPorts(ctx)
306 oo.baseDeviceHandler.setDeviceReason(drInitialMibDownloaded)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000307 oo.baseDeviceHandler.setReadyForOmciConfig(true)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000308 // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm
309
310 oo.baseDeviceHandler.reconcileDeviceTechProf(ctx)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000311
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000312 // start go routine with select() on reconciling flow channel before
313 // starting flow reconciling process to prevent loss of any signal
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000314 go func() {
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000315 // In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until
316 // we get a signal that the processing of the last step to rebuild the adapter internal
317 // flow data is finished.
318 select {
319 case success := <-oo.baseDeviceHandler.chReconcilingFlowsFinished:
320 if success {
321 logger.Debugw(ctx, "reconciling flows has been finished in time",
322 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000323 oo.baseDeviceHandler.stopReconciling(ctx)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000324 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000325
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000326 } else {
327 logger.Debugw(ctx, "wait for reconciling flows aborted",
328 log.Fields{"device-id": oo.deviceID})
329 oo.baseDeviceHandler.setReconcilingFlows(false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000330 }
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000331 case <-time.After(500 * time.Millisecond):
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000332 logger.Errorw(ctx, "timeout waiting for reconciling flows to be finished!",
333 log.Fields{"device-id": oo.deviceID})
334 oo.baseDeviceHandler.setReconcilingFlows(false)
335 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
336 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000337 }()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000338 oo.baseDeviceHandler.reconcileDeviceFlowConfig(ctx)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000339
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000340 oo.mutexPersOnuConfig.RLock()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000341 if oo.sOnuPersistentData.PersUniDisableDone {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000342 oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000343 oo.baseDeviceHandler.disableUniPortStateUpdate(ctx)
344 oo.baseDeviceHandler.setDeviceReason(drOmciAdminLock)
345 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000346 oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000347 oo.baseDeviceHandler.enableUniPortStateUpdate(ctx)
348 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000349 } else {
350 logger.Debugw(ctx, "MibSync FSM",
351 log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID})
352 go func() {
353 //switch to reconciling with OMCI config
354 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
355 }()
356 }
357}
358
dbainbri4d3a0dc2020-12-02 00:33:42 +0000359func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000360 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 +0000361 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000362 oo.requestMdsValue(ctx)
363 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000364 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 +0000365 go func() {
366 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
367 }()
368 }
369}
370
371func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
372 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 +0000373 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000374 oo.requestMdsValue(ctx)
375 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000376 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 +0000377 go func() {
378 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
379 }()
380 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000381}
382
dbainbri4d3a0dc2020-12-02 00:33:42 +0000383func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
384 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
385 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000386}
387
dbainbri4d3a0dc2020-12-02 00:33:42 +0000388func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
389 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 +0000390loop:
391 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000392 // case <-ctx.Done():
393 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
394 // break loop
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000395 message, ok := <-oo.pMibUploadFsm.commChan
Himani Chawla4d908332020-08-31 12:30:20 +0530396 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000397 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 +0530398 break loop
399 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000400 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000401
Himani Chawla4d908332020-08-31 12:30:20 +0530402 switch message.Type {
403 case TestMsg:
404 msg, _ := message.Data.(TestMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000405 oo.handleTestMsg(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530406 case OMCI:
407 msg, _ := message.Data.(OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000408 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530409 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000410 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 +0000411 }
412 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000413 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000414 // TODO: only this action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000415 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000416}
417
dbainbri4d3a0dc2020-12-02 00:33:42 +0000418func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000419
dbainbri4d3a0dc2020-12-02 00:33:42 +0000420 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 +0000421
422 switch msg.TestMessageVal {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000423 case LoadMibTemplateFailed:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000424 _ = oo.pMibUploadFsm.pFsm.Event(ulEvUploadMib)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000425 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000426 case LoadMibTemplateOk:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000427 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000428 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000429 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000430 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 +0000431 }
432}
433
dbainbri4d3a0dc2020-12-02 00:33:42 +0000434func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg OmciMessage) {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000435 if oo.pMibUploadFsm.pFsm.Is(ulStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530436 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
437 if msgLayer != nil {
438 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
439 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000440 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530441 if msgObj.Result == me.Success {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000442 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000443 oo.sOnuPersistentData.PersMibDataSyncAdpt = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000444 oo.mutexPersOnuConfig.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530445 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000446 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530447 return
448 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000449 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530450 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000451 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530452 }
453 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000454 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530455 }
456 } else {
mpagenko01499812021-03-25 10:37:12 +0000457 //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset
458 // with Sequence number 0x8000 as last request before - so it may still respond to that
459 // 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 +0000460 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000461 if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
462 logger.Debugw(ctx, "MibSync FSM - repeat MdsGetRequest (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
463 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
ozgecanetsiab36ed572021-04-01 10:38:48 +0300464 _, err := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
mpagenko01499812021-03-25 10:37:12 +0000465 me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300466 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000467 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300468 logger.Errorw(ctx, "ONUData get failed, aborting MibSync", log.Fields{"device-id": oo.deviceID})
ozgecanetsia29111002021-05-04 22:20:26 +0300469 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300470 return
471 }
mpagenko01499812021-03-25 10:37:12 +0000472 //TODO: needs extra handling of timeouts
473 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000474 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000475 return
476 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000477 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000478 logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
479 //perhaps some still lingering message from some prior activity, let's wait for the real response
480 return
Himani Chawla4d908332020-08-31 12:30:20 +0530481 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000482 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000483 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530484}
485
dbainbri4d3a0dc2020-12-02 00:33:42 +0000486func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530487 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
488 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000489 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530490 return
491 }
492 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
493 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000494 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530495 return
496 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000497 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530498 /* to be verified / reworked !!! */
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000499 oo.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
500 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800501 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000502 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
503 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000504 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000505 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000506 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530507 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000508 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 +0530509 //TODO right action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000510 _ = oo.pMibUploadFsm.pFsm.Event(ulEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530511 }
512}
513
dbainbri4d3a0dc2020-12-02 00:33:42 +0000514func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530515 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
Andrea Campanella6515c582020-10-05 11:25:00 +0200516
Holger Hildebrandte2439342020-12-03 16:06:54 +0000517 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000518 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000519 return
520 }
521 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
522 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000523 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000524 return
525 }
526 meName := msgObj.ReportedME.GetName()
527 if meName == "UnknownItuG988ManagedEntity" || meName == "UnknownVendorSpecificManagedEntity" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000528 logger.Debugw(ctx, "MibUploadNextResponse Data for unknown ME received - temporary workaround is to ignore it!",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000529 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj, "meName": meName})
530 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000531 logger.Debugw(ctx, "MibUploadNextResponse Data for:",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000532 log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
Holger Hildebrandt8998b872020-10-05 13:48:39 +0000533 meClassID := msgObj.ReportedME.GetClassID()
534 meEntityID := msgObj.ReportedME.GetEntityID()
535 meAttributes := msgObj.ReportedME.GetAttributeValueMap()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000536 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes)
Himani Chawla4d908332020-08-31 12:30:20 +0530537 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000538 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800539 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000540 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
541 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000542 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000543 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000544 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530545 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000546 oo.pOnuDB.logMeDb(ctx)
547 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530548 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000549 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 +0530550 }
551
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000552 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530553 }
554}
555
dbainbri4d3a0dc2020-12-02 00:33:42 +0000556func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000557 var err error = nil
mpagenko01499812021-03-25 10:37:12 +0000558
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000559 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000560 if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType ||
561 oo.lastTxParamStruct.pLastTxMeInstance == nil {
562 //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest
563 // with Sequence number 0x8000 as last request before - so it may still respond to that
564 // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number
565 if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
566 logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
567 _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
568 //TODO: needs extra handling of timeouts
569 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000570 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000571 return nil
572 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000573 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000574 logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
575 //perhaps some still lingering message from some prior activity, let's wait for the real response
576 return nil
577 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000578 oo.mutexLastTxParamStruct.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530579 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000580 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000581 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 +0000582 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
583 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 +0000584 }
585 msgObj, msgOk := msgLayer.(*omci.GetResponse)
586 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000587 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 +0000588 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
589 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 +0000590 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000591 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000592 if msgObj.Result == me.Success {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000593 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000594 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
595 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000596 meAttributes := msgObj.Attributes
mpagenko01499812021-03-25 10:37:12 +0000597 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000598 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 +0000599 switch meInstance {
600 case "OnuG":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000601 oo.mutexLastTxParamStruct.RUnlock()
602 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000603 oo.sOnuPersistentData.PersVendorID = TrimStringFromMeOctet(meAttributes["VendorId"])
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000604 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
605 if onugSerialNumberLen == len(snBytes) {
606 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
607 snNumberPart := hex.EncodeToString(snBytes[4:])
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000608 oo.sOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000609 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 +0000610 "onuDeviceEntry.vendorID": oo.sOnuPersistentData.PersVendorID, "onuDeviceEntry.serialNumber": oo.sOnuPersistentData.PersSerialNumber})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000611 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000612 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 +0000613 oo.sOnuPersistentData.PersSerialNumber = cEmptySerialNumberString
Himani Chawla4d908332020-08-31 12:30:20 +0530614 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000615 oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000616 // trigger retrieval of EquipmentId
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000617 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000618 return nil
619 case "Onu2G":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000620 oo.mutexLastTxParamStruct.RUnlock()
621 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000622 oo.sOnuPersistentData.PersEquipmentID = TrimStringFromMeOctet(meAttributes["EquipmentId"])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000623 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000624 "onuDeviceEntry.equipmentID": oo.sOnuPersistentData.PersEquipmentID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000625 oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000626 // trigger retrieval of 1st SW-image info
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000627 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000628 return nil
629 case "SoftwareImage":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000630 oo.mutexLastTxParamStruct.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000631 if entityID > secondSwImageMeID {
632 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
633 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
634 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
635 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000636 }
mpagenko15ff4a52021-03-02 10:09:20 +0000637 // need to use function for go lint complexity
638 oo.handleSwImageIndications(ctx, entityID, meAttributes)
639 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000640 case "IpHostConfigData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000641 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000642 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000643 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000644 if omciMacAddressLen == len(macBytes) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000645 oo.sOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000646 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000647 "macAddress": oo.sOnuPersistentData.PersMacAddress})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000648 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000649 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 +0000650 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000651 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000652 oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000653 // trigger retrieval of mib template
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000654 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000655 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000656 case "OnuData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000657 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000658 oo.checkMdsValue(ctx, meAttributes["MibDataSync"].(uint8))
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000659 return nil
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000660 default:
661 oo.mutexLastTxParamStruct.RUnlock()
662 logger.Warnw(ctx, "Unsupported ME name received!",
663 log.Fields{"ME name": meInstance, "device-id": oo.deviceID})
664
Himani Chawla4d908332020-08-31 12:30:20 +0530665 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800666 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000667 oo.mutexLastTxParamStruct.RUnlock()
668 logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ",
669 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000670 }
Himani Chawla4d908332020-08-31 12:30:20 +0530671 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000672 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000673 return nil
674 }
Himani Chawla4d908332020-08-31 12:30:20 +0530675 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000676 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000677 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000678 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530679}
680
mpagenko15ff4a52021-03-02 10:09:20 +0000681func (oo *OnuDeviceEntry) handleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) {
682 imageIsCommitted := meAttributes["IsCommitted"].(uint8)
683 imageIsActive := meAttributes["IsActive"].(uint8)
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000684 imageVersion := TrimStringFromMeOctet(meAttributes["Version"])
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000685 oo.mutexPersOnuConfig.RLock()
mpagenko15ff4a52021-03-02 10:09:20 +0000686 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
687 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000688 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.sOnuPersistentData.PersSerialNumber})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000689 oo.mutexPersOnuConfig.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000690 if firstSwImageMeID == entityID {
691 //always accept the state of the first image (2nd image info should not yet be available)
692 if imageIsActive == swIsActive {
693 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
694 oo.onuSwImageIndications.activeEntityEntry.valid = true
695 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
696 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000697 //as the SW version indication may stem from some ONU Down/up event
698 //the complementary image state is to be invalidated
699 // (state of the second image is always expected afterwards or just invalid)
700 oo.onuSwImageIndications.inactiveEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000701 } else {
702 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
703 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
704 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
705 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000706 //as the SW version indication may stem form some ONU Down/up event
707 //the complementary image state is to be invalidated
708 // (state of the second image is always expected afterwards or just invalid)
709 oo.onuSwImageIndications.activeEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000710 }
711 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion)
712 return
713 } else if secondSwImageMeID == entityID {
714 //2nd image info might conflict with first image info, in which case we priorize first image info!
715 if imageIsActive == swIsActive { //2nd image reported to be active
716 if oo.onuSwImageIndications.activeEntityEntry.valid {
717 //conflict exists - state of first image is left active
718 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
719 log.Fields{"device-id": oo.deviceID})
720 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
721 oo.onuSwImageIndications.inactiveEntityEntry.valid = true ////to indicate that at least something has been reported
722 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
723 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
724 } else { //first image inactive, this one active
725 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
726 oo.onuSwImageIndications.activeEntityEntry.valid = true
727 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
728 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
729 }
730 } else { //2nd image reported to be inactive
731 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
732 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
733 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
734 log.Fields{"device-id": oo.deviceID})
735 oo.onuSwImageIndications.activeEntityEntry.entityID = firstSwImageMeID
736 oo.onuSwImageIndications.activeEntityEntry.valid = true //to indicate that at least something has been reported
737 //copy active commit/version from the previously stored inactive position
738 oo.onuSwImageIndications.activeEntityEntry.version = oo.onuSwImageIndications.inactiveEntityEntry.version
739 oo.onuSwImageIndications.activeEntityEntry.isCommitted = oo.onuSwImageIndications.inactiveEntityEntry.isCommitted
740 }
741 //in any case we indicate (and possibly overwrite) the second image indications as inactive
742 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
743 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
744 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
745 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
746 }
747 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress)
748 return
749 }
750}
751
dbainbri4d3a0dc2020-12-02 00:33:42 +0000752func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg OmciMessage) {
753 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200754 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000755 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
756 switch msg.OmciMsg.MessageType {
757 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000758 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000759
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000760 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000761 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530762
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000763 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000764 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000765
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000766 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000767 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000768 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530769
Andrea Campanella6515c582020-10-05 11:25:00 +0200770 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000771 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200772
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000773 }
774}
775
dbainbri4d3a0dc2020-12-02 00:33:42 +0000776func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000777 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000778 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 +0000779 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
780 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000781 oo.mutexLastTxParamStruct.RLock()
782 if oo.lastTxParamStruct.pLastTxMeInstance != nil {
783 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
784 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
785 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
786 switch meInstance {
787 case "IpHostConfigData":
788 oo.mutexLastTxParamStruct.RUnlock()
789 logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros",
790 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
791 oo.mutexPersOnuConfig.Lock()
792 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
793 oo.mutexPersOnuConfig.Unlock()
794 // trigger retrieval of mib template
795 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
796 return nil
797 default:
798 oo.mutexLastTxParamStruct.RUnlock()
799 logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
800 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
801 }
802 } else {
803 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000804 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000805 } else {
806 oo.mutexLastTxParamStruct.RUnlock()
807 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000808 }
809 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000810 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 +0000811 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
812 }
813 return err
814}
815
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000816func (oo *OnuDeviceEntry) isNewOnu() bool {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000817 oo.mutexPersOnuConfig.RLock()
818 defer oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000819 return oo.sOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000820}
821
Himani Chawla6d2ae152020-09-02 13:11:20 +0530822func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000823 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530824 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000825 return true
826 }
827 }
828 return false
829}
830
dbainbri4d3a0dc2020-12-02 00:33:42 +0000831func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
832 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000833 return errors.New("not_implemented")
834}
835
Himani Chawla6d2ae152020-09-02 13:11:20 +0530836// 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 +0530837// 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 +0000838// 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 +0000839func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
840 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000841 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530842
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000843 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
844 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
845 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000846 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000847 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
848 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
849 return nil
850 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000851 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000852 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
853 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000854 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000855 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
856 }
857 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = true
858 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
859
860 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +0530861 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000862 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +0530863 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
864
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000865 firstLevelMap := oo.pOnuDB.meDb
divyadesaibbed37c2020-08-28 13:35:20 +0530866 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000867 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +0530868 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530869
870 secondLevelMap := make(map[string]interface{})
871 for secondLevelKey, secondLevelValue := range firstLevelValue {
872 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +0530873 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530874 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +0530875 thirdLevelMap["InstanceId"] = entityID
876 secondLevelMap[entityID] = thirdLevelMap
877 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +0530878 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
879 delete(forthLevelMap, "SerialNumber")
880 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
881
882 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530883 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +0530884 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
885 delete(forthLevelMap, "MacAddress")
886 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
887 }
888 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530889 secondLevelMap["ClassId"] = classID
890 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +0530891 }
892 mibTemplate, err := json.Marshal(&templateMap)
893 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000894 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000895 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
896 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
897 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530898 return err
899 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000900 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +0530901 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000902 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 +0000903 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
904 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
905 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530906 return err
907 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000908 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530909 return nil
910}
911
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000912func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
913 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
914 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
ozgecanetsiab36ed572021-04-01 10:38:48 +0300915 meInstance, err := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
Girish Gowdra0b235842021-03-09 13:06:46 -0800916 me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000917 //accept also nil as (error) return value for writing to LastTx
918 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300919 if err != nil {
920 logger.Errorw(ctx, "ONUData get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
921 pMibUlFsm := oo.pMibUploadFsm
922 if pMibUlFsm != nil {
923 go func(a_pAFsm *AdapterFsm) {
ozgecanetsia29111002021-05-04 22:20:26 +0300924 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300925 }(pMibUlFsm)
926 }
927 return
928 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000929 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000930 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
931 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
932 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000933 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000934}
935
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000936func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000937 oo.mutexPersOnuConfig.RLock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000938 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
939 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.sOnuPersistentData.PersMibDataSyncAdpt})
940
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000941 mdsValuesAreEqual := oo.sOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000942 oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000943 if oo.pMibUploadFsm.pFsm.Is(ulStAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000944 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000945 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
946 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
947 } else {
948 logger.Warnw(ctx, "MibSync FSM - mib audit - MDS check failed for the first time!", log.Fields{"device-id": oo.deviceID})
949 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
950 }
951 } else if oo.pMibUploadFsm.pFsm.Is(ulStReAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000952 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000953 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
954 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
955 } else {
956 logger.Errorw(ctx, "MibSync FSM - mib audit - MDS check failed for the second time!", log.Fields{"device-id": oo.deviceID})
957 //TODO: send new event notification "MDS counter mismatch" to the core
958 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
959 }
960 } else if oo.pMibUploadFsm.pFsm.Is(ulStExaminingMds) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000961 if mdsValuesAreEqual && mibDataSyncOnu != 0 {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000962 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
963 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
964 } else {
965 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
966 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
967 }
968 } else {
969 logger.Warnw(ctx, "wrong state for MDS evaluation!", log.Fields{"state": oo.pMibUploadFsm.pFsm.Current(), "device-id": oo.deviceID})
970 }
971}
mpagenko15ff4a52021-03-02 10:09:20 +0000972
973//GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
974func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
975 if oo.onuSwImageIndications.activeEntityEntry.valid {
976 return oo.onuSwImageIndications.activeEntityEntry.entityID, nil
977 }
978 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
979}
980
981//GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
982func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
983 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
984 return oo.onuSwImageIndications.inactiveEntityEntry.entityID, nil
985 }
986 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
987}
988
989//IsImageToBeCommitted returns true if the active image is still uncommitted
990func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
991 if oo.onuSwImageIndications.activeEntityEntry.valid {
992 if oo.onuSwImageIndications.activeEntityEntry.entityID == aImageID {
993 if oo.onuSwImageIndications.activeEntityEntry.isCommitted == swIsUncommitted {
994 return true
995 }
996 }
997 }
998 return false //all other case are treated as 'nothing to commit
999}
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001000func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool {
1001
1002 oo.mibTemplatePath = oo.buildMibTemplatePath()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +00001003 logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath),
1004 "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001005
1006 restoredFromMibTemplate := false
1007 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
1008 if err == nil {
1009 if Value != nil {
1010 logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value)
1011
1012 // swap out tokens with specific data
1013 mibTmpString, _ := kvstore.ToString(Value.Value)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001014 oo.mutexPersOnuConfig.RLock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001015 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.sOnuPersistentData.PersSerialNumber, -1)
1016 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.sOnuPersistentData.PersMacAddress, -1)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001017 oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001018 mibTmpBytes := []byte(mibTmpString)
1019 logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes)
1020
1021 var firstLevelMap map[string]interface{}
1022 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
1023 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
1024 } else {
1025 for firstLevelKey, firstLevelValue := range firstLevelMap {
1026 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
1027 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
1028 meClassID := me.ClassID(uint16ValidNumber)
1029 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
1030 if isSupportedClassID(meClassID) {
1031 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
1032 secondLevelMap := firstLevelValue.(map[string]interface{})
1033 for secondLevelKey, secondLevelValue := range secondLevelMap {
1034 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
1035 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
1036 meEntityID := uint16(uint16ValidNumber)
1037 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
1038 thirdLevelMap := secondLevelValue.(map[string]interface{})
1039 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
1040 if thirdLevelKey == "Attributes" {
1041 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
1042 attributesMap := thirdLevelValue.(map[string]interface{})
1043 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
1044 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
1045 restoredFromMibTemplate = true
1046 }
1047 }
1048 }
1049 }
1050 }
1051 }
1052 }
1053 }
1054 } else {
1055 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1056 }
1057 } else {
1058 logger.Errorf(ctx, "Get from kvstore operation failed for path",
1059 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1060 }
1061 return restoredFromMibTemplate
1062}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001063
1064//CancelProcessing terminates potentially running reconciling processes and stops the FSM
1065func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) {
1066
1067 if oo.baseDeviceHandler.isReconcilingFlows() {
1068 oo.baseDeviceHandler.chReconcilingFlowsFinished <- false
1069 }
1070 if oo.baseDeviceHandler.isReconciling() {
1071 oo.baseDeviceHandler.chReconcilingFinished <- false
1072 }
1073 //the MibSync FSM might be active all the ONU-active time,
1074 // hence it must be stopped unconditionally
1075 pMibUlFsm := oo.pMibUploadFsm.pFsm
1076 if pMibUlFsm != nil {
1077 _ = pMibUlFsm.Event(ulEvStop)
1078 }
1079}