blob: 343937511d7fea13b4897dbe4208079e05834c13 [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
Girish Gowdra50e56422021-06-01 16:46:04 -070034 //"github.com/opencord/voltha-lib-go/v5/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"
Girish Gowdra50e56422021-06-01 16:46:04 -070037 "github.com/opencord/voltha-lib-go/v5/pkg/db/kvstore"
38 "github.com/opencord/voltha-lib-go/v5/pkg/log"
dbainbri4d3a0dc2020-12-02 00:33:42 +000039 //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
Holger Hildebrandt05011352021-06-15 09:40:24 +0000215 oo.mutexOnuSwImageIndications.RLock()
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()
Holger Hildebrandt05011352021-06-15 09:40:24 +0000220 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000221 } else {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000222 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000223 logger.Errorw(ctx, "get-mib-template: no active SW version found, working with empty SW version, which might be untrustworthy",
224 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000225 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000226 if oo.getMibFromTemplate(ctx) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000227 logger.Debug(ctx, "MibSync FSM - valid MEs stored from template")
228 oo.pOnuDB.logMeDb(ctx)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000229 fsmMsg = LoadMibTemplateOk
230 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000231 logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000232 fsmMsg = LoadMibTemplateFailed
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000233
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000234 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
235 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
236 if mibTemplateIsGenerated {
237 logger.Debugw(ctx,
238 "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map",
239 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
240 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
241 }
242 }
243 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
244 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000245 mibSyncMsg := Message{
246 Type: TestMsg,
247 Data: TestMessage{
248 TestMessageVal: fsmMsg,
249 },
250 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000251 oo.pMibUploadFsm.commChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000252}
253
dbainbri4d3a0dc2020-12-02 00:33:42 +0000254func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
255 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 -0800256 _ = oo.PDevOmciCC.sendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000257 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
258 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000259 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000260 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000261 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000262}
263
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000264func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000265 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID})
266 oo.transferSystemEvent(ctx, MibDatabaseSync)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000267 go func() {
268 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
269 }()
270}
271
272func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000273 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000274 oo.sOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix())
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000275 oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000276 if oo.mibAuditInterval > 0 {
277 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 +0000278 go func() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000279 time.Sleep(oo.mibAuditInterval)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000280 if err := oo.pMibUploadFsm.pFsm.Event(ulEvAuditMib); err != nil {
281 logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err})
282 }
283 }()
284 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000285}
286
dbainbri4d3a0dc2020-12-02 00:33:42 +0000287func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
288 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 +0000289 oo.requestMdsValue(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000290}
291
dbainbri4d3a0dc2020-12-02 00:33:42 +0000292func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
293 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
294 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000295 // TODOs:
296 // VOL-3805 - Provide exclusive OMCI channel for one FSM
297 // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go
298 // VOL-3792 - Support periodical audit via mib resync
299 // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000300}
301
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000302func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) {
303 logger.Debugw(ctx, "MibSync FSM",
304 log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID})
305
306 if oo.getMibFromTemplate(ctx) {
307 oo.baseDeviceHandler.startReconciling(ctx, true)
308 oo.baseDeviceHandler.addAllUniPorts(ctx)
309 oo.baseDeviceHandler.setDeviceReason(drInitialMibDownloaded)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000310 oo.baseDeviceHandler.setReadyForOmciConfig(true)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000311
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000312 if !oo.baseDeviceHandler.getCollectorIsRunning() {
313 // Start PM collector routine
314 go oo.baseDeviceHandler.startCollector(ctx)
315 }
316 if !oo.baseDeviceHandler.getAlarmManagerIsRunning(ctx) {
317 go oo.baseDeviceHandler.startAlarmManager(ctx)
318 }
319 // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000320 oo.baseDeviceHandler.reconcileDeviceTechProf(ctx)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000321
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000322 // start go routine with select() on reconciling flow channel before
323 // starting flow reconciling process to prevent loss of any signal
Holger Hildebrandt6be98372022-01-06 14:49:08 +0000324 syncChannel := make(chan struct{})
325 go func(aSyncChannel chan struct{}) {
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000326 // In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until
327 // we get a signal that the processing of the last step to rebuild the adapter internal
328 // flow data is finished.
Holger Hildebrandt6be98372022-01-06 14:49:08 +0000329 aSyncChannel <- struct{}{}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000330 select {
331 case success := <-oo.baseDeviceHandler.chReconcilingFlowsFinished:
332 if success {
333 logger.Debugw(ctx, "reconciling flows has been finished in time",
334 log.Fields{"device-id": oo.deviceID})
Girish Gowdra50e56422021-06-01 16:46:04 -0700335 oo.baseDeviceHandler.stopReconciling(ctx, true)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000336 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000337
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000338 } else {
339 logger.Debugw(ctx, "wait for reconciling flows aborted",
340 log.Fields{"device-id": oo.deviceID})
341 oo.baseDeviceHandler.setReconcilingFlows(false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000342 }
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000343 case <-time.After(500 * time.Millisecond):
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000344 logger.Errorw(ctx, "timeout waiting for reconciling flows to be finished!",
345 log.Fields{"device-id": oo.deviceID})
346 oo.baseDeviceHandler.setReconcilingFlows(false)
347 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
348 }
Holger Hildebrandt6be98372022-01-06 14:49:08 +0000349 }(syncChannel)
350 // block further processing until the above Go routine has really started
351 // and is ready to receive values from chReconcilingFlowsFinished
352 <-syncChannel
353
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000354 oo.baseDeviceHandler.reconcileDeviceFlowConfig(ctx)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000355
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000356 oo.mutexPersOnuConfig.RLock()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000357 if oo.sOnuPersistentData.PersUniDisableDone {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000358 oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000359 oo.baseDeviceHandler.disableUniPortStateUpdate(ctx)
360 oo.baseDeviceHandler.setDeviceReason(drOmciAdminLock)
361 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000362 oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000363 oo.baseDeviceHandler.enableUniPortStateUpdate(ctx)
364 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000365 } else {
366 logger.Debugw(ctx, "MibSync FSM",
367 log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID})
368 go func() {
369 //switch to reconciling with OMCI config
370 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
371 }()
372 }
373}
374
dbainbri4d3a0dc2020-12-02 00:33:42 +0000375func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000376 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 +0000377 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000378 oo.requestMdsValue(ctx)
379 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000380 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 +0000381 go func() {
382 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
383 }()
384 }
385}
386
387func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
388 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 +0000389 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000390 oo.requestMdsValue(ctx)
391 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000392 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 +0000393 go func() {
394 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
395 }()
396 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000397}
398
dbainbri4d3a0dc2020-12-02 00:33:42 +0000399func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
400 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
401 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000402}
403
dbainbri4d3a0dc2020-12-02 00:33:42 +0000404func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
405 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 +0000406loop:
407 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000408 // case <-ctx.Done():
409 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
410 // break loop
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000411 message, ok := <-oo.pMibUploadFsm.commChan
Himani Chawla4d908332020-08-31 12:30:20 +0530412 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000413 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 +0530414 break loop
415 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000416 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000417
Himani Chawla4d908332020-08-31 12:30:20 +0530418 switch message.Type {
419 case TestMsg:
420 msg, _ := message.Data.(TestMessage)
Holger Hildebrandtddc4fbd2022-02-04 14:10:36 +0000421 if msg.TestMessageVal == AbortMessageProcessing {
422 logger.Debugw(ctx, "MibSync Msg abort ProcessMsg", log.Fields{"for device-id": oo.deviceID})
423 break loop
424 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000425 oo.handleTestMsg(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530426 case OMCI:
427 msg, _ := message.Data.(OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000428 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530429 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000430 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 +0000431 }
432 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000433 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000434 // TODO: only this action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000435 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000436}
437
dbainbri4d3a0dc2020-12-02 00:33:42 +0000438func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000439
dbainbri4d3a0dc2020-12-02 00:33:42 +0000440 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 +0000441
442 switch msg.TestMessageVal {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000443 case LoadMibTemplateFailed:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000444 _ = oo.pMibUploadFsm.pFsm.Event(ulEvUploadMib)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000445 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000446 case LoadMibTemplateOk:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000447 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000448 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000449 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000450 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 +0000451 }
452}
453
dbainbri4d3a0dc2020-12-02 00:33:42 +0000454func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg OmciMessage) {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000455 if oo.pMibUploadFsm.pFsm.Is(ulStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530456 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
457 if msgLayer != nil {
458 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
459 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000460 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530461 if msgObj.Result == me.Success {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000462 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000463 oo.sOnuPersistentData.PersMibDataSyncAdpt = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000464 oo.mutexPersOnuConfig.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530465 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000466 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530467 return
468 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000469 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530470 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000471 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530472 }
473 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000474 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530475 }
476 } else {
mpagenko01499812021-03-25 10:37:12 +0000477 //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset
478 // with Sequence number 0x8000 as last request before - so it may still respond to that
479 // 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 +0000480 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000481 if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
482 logger.Debugw(ctx, "MibSync FSM - repeat MdsGetRequest (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
483 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
ozgecanetsiab36ed572021-04-01 10:38:48 +0300484 _, err := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
mpagenko01499812021-03-25 10:37:12 +0000485 me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300486 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000487 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300488 logger.Errorw(ctx, "ONUData get failed, aborting MibSync", log.Fields{"device-id": oo.deviceID})
ozgecanetsia29111002021-05-04 22:20:26 +0300489 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300490 return
491 }
mpagenko01499812021-03-25 10:37:12 +0000492 //TODO: needs extra handling of timeouts
493 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000494 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000495 return
496 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000497 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000498 logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
499 //perhaps some still lingering message from some prior activity, let's wait for the real response
500 return
Himani Chawla4d908332020-08-31 12:30:20 +0530501 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000502 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000503 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530504}
505
dbainbri4d3a0dc2020-12-02 00:33:42 +0000506func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530507 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
508 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000509 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530510 return
511 }
512 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
513 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000514 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530515 return
516 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000517 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530518 /* to be verified / reworked !!! */
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000519 oo.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
520 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800521 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000522 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
523 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000524 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000525 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000526 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530527 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000528 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 +0530529 //TODO right action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000530 _ = oo.pMibUploadFsm.pFsm.Event(ulEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530531 }
532}
533
dbainbri4d3a0dc2020-12-02 00:33:42 +0000534func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530535 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
Andrea Campanella6515c582020-10-05 11:25:00 +0200536
Holger Hildebrandte2439342020-12-03 16:06:54 +0000537 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000538 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000539 return
540 }
541 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
542 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000543 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000544 return
545 }
546 meName := msgObj.ReportedME.GetName()
547 if meName == "UnknownItuG988ManagedEntity" || meName == "UnknownVendorSpecificManagedEntity" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000548 logger.Debugw(ctx, "MibUploadNextResponse Data for unknown ME received - temporary workaround is to ignore it!",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000549 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj, "meName": meName})
550 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000551 logger.Debugw(ctx, "MibUploadNextResponse Data for:",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000552 log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
Holger Hildebrandt8998b872020-10-05 13:48:39 +0000553 meClassID := msgObj.ReportedME.GetClassID()
554 meEntityID := msgObj.ReportedME.GetEntityID()
555 meAttributes := msgObj.ReportedME.GetAttributeValueMap()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000556 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes)
Himani Chawla4d908332020-08-31 12:30:20 +0530557 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000558 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800559 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000560 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
561 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000562 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000563 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000564 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530565 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000566 oo.pOnuDB.logMeDb(ctx)
567 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530568 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000569 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 +0530570 }
571
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000572 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530573 }
574}
575
dbainbri4d3a0dc2020-12-02 00:33:42 +0000576func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000577 var err error = nil
mpagenko01499812021-03-25 10:37:12 +0000578
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000579 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000580 if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType ||
581 oo.lastTxParamStruct.pLastTxMeInstance == nil {
582 //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest
583 // with Sequence number 0x8000 as last request before - so it may still respond to that
584 // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number
585 if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
586 logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
587 _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
588 //TODO: needs extra handling of timeouts
589 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000590 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000591 return nil
592 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000593 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000594 logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
595 //perhaps some still lingering message from some prior activity, let's wait for the real response
596 return nil
597 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000598 oo.mutexLastTxParamStruct.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530599 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000600 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000601 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 +0000602 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
603 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 +0000604 }
605 msgObj, msgOk := msgLayer.(*omci.GetResponse)
606 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000607 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 +0000608 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
609 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 +0000610 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000611 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000612 if msgObj.Result == me.Success {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000613 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000614 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
615 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000616 meAttributes := msgObj.Attributes
mpagenko01499812021-03-25 10:37:12 +0000617 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000618 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 +0000619 switch meInstance {
620 case "OnuG":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000621 oo.mutexLastTxParamStruct.RUnlock()
622 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000623 oo.sOnuPersistentData.PersVendorID = TrimStringFromMeOctet(meAttributes["VendorId"])
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000624 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
625 if onugSerialNumberLen == len(snBytes) {
626 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
627 snNumberPart := hex.EncodeToString(snBytes[4:])
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000628 oo.sOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000629 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 +0000630 "onuDeviceEntry.vendorID": oo.sOnuPersistentData.PersVendorID, "onuDeviceEntry.serialNumber": oo.sOnuPersistentData.PersSerialNumber})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000631 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000632 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 +0000633 oo.sOnuPersistentData.PersSerialNumber = cEmptySerialNumberString
Himani Chawla4d908332020-08-31 12:30:20 +0530634 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000635 oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000636 // trigger retrieval of EquipmentId
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000637 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000638 return nil
639 case "Onu2G":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000640 oo.mutexLastTxParamStruct.RUnlock()
641 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000642 oo.sOnuPersistentData.PersEquipmentID = TrimStringFromMeOctet(meAttributes["EquipmentId"])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000643 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000644 "onuDeviceEntry.equipmentID": oo.sOnuPersistentData.PersEquipmentID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000645 oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000646 // trigger retrieval of 1st SW-image info
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000647 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000648 return nil
649 case "SoftwareImage":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000650 oo.mutexLastTxParamStruct.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000651 if entityID > secondSwImageMeID {
652 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
653 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
654 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
655 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000656 }
mpagenko15ff4a52021-03-02 10:09:20 +0000657 // need to use function for go lint complexity
658 oo.handleSwImageIndications(ctx, entityID, meAttributes)
659 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000660 case "IpHostConfigData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000661 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000662 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000663 oo.mutexPersOnuConfig.Lock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000664 if omciMacAddressLen == len(macBytes) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000665 oo.sOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000666 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000667 "macAddress": oo.sOnuPersistentData.PersMacAddress})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000668 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000669 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 +0000670 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000671 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000672 oo.mutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000673 // trigger retrieval of mib template
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000674 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000675 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000676 case "OnuData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000677 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000678 oo.checkMdsValue(ctx, meAttributes["MibDataSync"].(uint8))
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000679 return nil
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000680 default:
681 oo.mutexLastTxParamStruct.RUnlock()
682 logger.Warnw(ctx, "Unsupported ME name received!",
683 log.Fields{"ME name": meInstance, "device-id": oo.deviceID})
684
Himani Chawla4d908332020-08-31 12:30:20 +0530685 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800686 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000687 oo.mutexLastTxParamStruct.RUnlock()
688 logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ",
689 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000690 }
Himani Chawla4d908332020-08-31 12:30:20 +0530691 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000692 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000693 return nil
694 }
Himani Chawla4d908332020-08-31 12:30:20 +0530695 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000696 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000697 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000698 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530699}
700
mpagenko15ff4a52021-03-02 10:09:20 +0000701func (oo *OnuDeviceEntry) handleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) {
702 imageIsCommitted := meAttributes["IsCommitted"].(uint8)
703 imageIsActive := meAttributes["IsActive"].(uint8)
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000704 imageVersion := TrimStringFromMeOctet(meAttributes["Version"])
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000705 oo.mutexPersOnuConfig.RLock()
mpagenko15ff4a52021-03-02 10:09:20 +0000706 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
707 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000708 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.sOnuPersistentData.PersSerialNumber})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000709 oo.mutexPersOnuConfig.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000710 if firstSwImageMeID == entityID {
711 //always accept the state of the first image (2nd image info should not yet be available)
Holger Hildebrandt05011352021-06-15 09:40:24 +0000712 oo.mutexOnuSwImageIndications.Lock()
mpagenko15ff4a52021-03-02 10:09:20 +0000713 if imageIsActive == swIsActive {
714 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
715 oo.onuSwImageIndications.activeEntityEntry.valid = true
716 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
717 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000718 //as the SW version indication may stem from some ONU Down/up event
719 //the complementary image state is to be invalidated
720 // (state of the second image is always expected afterwards or just invalid)
721 oo.onuSwImageIndications.inactiveEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000722 } else {
723 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
724 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
725 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
726 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000727 //as the SW version indication may stem form some ONU Down/up event
728 //the complementary image state is to be invalidated
729 // (state of the second image is always expected afterwards or just invalid)
730 oo.onuSwImageIndications.activeEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000731 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000732 oo.mutexOnuSwImageIndications.Unlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000733 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion)
734 return
735 } else if secondSwImageMeID == entityID {
736 //2nd image info might conflict with first image info, in which case we priorize first image info!
Holger Hildebrandt05011352021-06-15 09:40:24 +0000737 oo.mutexOnuSwImageIndications.Lock()
mpagenko15ff4a52021-03-02 10:09:20 +0000738 if imageIsActive == swIsActive { //2nd image reported to be active
739 if oo.onuSwImageIndications.activeEntityEntry.valid {
740 //conflict exists - state of first image is left active
741 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
742 log.Fields{"device-id": oo.deviceID})
743 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
744 oo.onuSwImageIndications.inactiveEntityEntry.valid = true ////to indicate that at least something has been reported
745 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
746 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
747 } else { //first image inactive, this one active
748 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
749 oo.onuSwImageIndications.activeEntityEntry.valid = true
750 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
751 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
752 }
753 } else { //2nd image reported to be inactive
754 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
755 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
756 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
757 log.Fields{"device-id": oo.deviceID})
758 oo.onuSwImageIndications.activeEntityEntry.entityID = firstSwImageMeID
759 oo.onuSwImageIndications.activeEntityEntry.valid = true //to indicate that at least something has been reported
760 //copy active commit/version from the previously stored inactive position
761 oo.onuSwImageIndications.activeEntityEntry.version = oo.onuSwImageIndications.inactiveEntityEntry.version
762 oo.onuSwImageIndications.activeEntityEntry.isCommitted = oo.onuSwImageIndications.inactiveEntityEntry.isCommitted
763 }
764 //in any case we indicate (and possibly overwrite) the second image indications as inactive
765 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
766 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
767 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
768 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
769 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000770 oo.mutexOnuSwImageIndications.Unlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000771 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress)
772 return
773 }
774}
775
dbainbri4d3a0dc2020-12-02 00:33:42 +0000776func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg OmciMessage) {
777 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200778 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000779 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
780 switch msg.OmciMsg.MessageType {
781 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000782 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000783
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000784 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000785 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530786
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000787 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000788 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000789
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000790 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000791 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000792 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530793
Andrea Campanella6515c582020-10-05 11:25:00 +0200794 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000795 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200796
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000797 }
798}
799
dbainbri4d3a0dc2020-12-02 00:33:42 +0000800func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000801 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000802 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 +0000803 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
804 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000805 oo.mutexLastTxParamStruct.RLock()
806 if oo.lastTxParamStruct.pLastTxMeInstance != nil {
807 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
808 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
809 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
810 switch meInstance {
811 case "IpHostConfigData":
812 oo.mutexLastTxParamStruct.RUnlock()
813 logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros",
814 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
815 oo.mutexPersOnuConfig.Lock()
816 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
817 oo.mutexPersOnuConfig.Unlock()
818 // trigger retrieval of mib template
819 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
820 return nil
821 default:
822 oo.mutexLastTxParamStruct.RUnlock()
823 logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
824 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
825 }
826 } else {
827 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000828 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000829 } else {
830 oo.mutexLastTxParamStruct.RUnlock()
831 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000832 }
833 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000834 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 +0000835 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
836 }
837 return err
838}
839
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000840func (oo *OnuDeviceEntry) isNewOnu() bool {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000841 oo.mutexPersOnuConfig.RLock()
842 defer oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000843 return oo.sOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000844}
845
Himani Chawla6d2ae152020-09-02 13:11:20 +0530846func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000847 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530848 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000849 return true
850 }
851 }
852 return false
853}
854
dbainbri4d3a0dc2020-12-02 00:33:42 +0000855func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
856 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000857 return errors.New("not_implemented")
858}
859
Himani Chawla6d2ae152020-09-02 13:11:20 +0530860// 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 +0530861// 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 +0000862// 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 +0000863func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
864 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000865 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530866
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000867 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
868 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
869 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000870 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000871 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
872 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
873 return nil
874 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000875 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000876 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
877 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000878 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000879 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
880 }
881 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = true
882 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
883
884 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +0530885 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000886 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +0530887 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
888
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000889 firstLevelMap := oo.pOnuDB.meDb
divyadesaibbed37c2020-08-28 13:35:20 +0530890 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000891 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +0530892 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530893
894 secondLevelMap := make(map[string]interface{})
895 for secondLevelKey, secondLevelValue := range firstLevelValue {
896 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +0530897 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530898 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +0530899 thirdLevelMap["InstanceId"] = entityID
900 secondLevelMap[entityID] = thirdLevelMap
901 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +0530902 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
903 delete(forthLevelMap, "SerialNumber")
904 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
905
906 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530907 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +0530908 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
909 delete(forthLevelMap, "MacAddress")
910 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
911 }
912 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530913 secondLevelMap["ClassId"] = classID
914 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +0530915 }
916 mibTemplate, err := json.Marshal(&templateMap)
917 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000918 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000919 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
920 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
921 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530922 return err
923 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000924 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +0530925 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000926 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 +0000927 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
928 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
929 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530930 return err
931 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000932 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530933 return nil
934}
935
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000936func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
937 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
938 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
ozgecanetsiab36ed572021-04-01 10:38:48 +0300939 meInstance, err := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
Girish Gowdra0b235842021-03-09 13:06:46 -0800940 me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000941 //accept also nil as (error) return value for writing to LastTx
942 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300943 if err != nil {
944 logger.Errorw(ctx, "ONUData get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
945 pMibUlFsm := oo.pMibUploadFsm
946 if pMibUlFsm != nil {
947 go func(a_pAFsm *AdapterFsm) {
ozgecanetsia29111002021-05-04 22:20:26 +0300948 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300949 }(pMibUlFsm)
950 }
951 return
952 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000953 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000954 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
955 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
956 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000957 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000958}
959
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000960func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000961 oo.mutexPersOnuConfig.RLock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000962 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
963 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.sOnuPersistentData.PersMibDataSyncAdpt})
964
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000965 mdsValuesAreEqual := oo.sOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000966 oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000967 if oo.pMibUploadFsm.pFsm.Is(ulStAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000968 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000969 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
970 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
971 } else {
972 logger.Warnw(ctx, "MibSync FSM - mib audit - MDS check failed for the first time!", log.Fields{"device-id": oo.deviceID})
973 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
974 }
975 } else if oo.pMibUploadFsm.pFsm.Is(ulStReAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000976 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000977 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
978 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
979 } else {
980 logger.Errorw(ctx, "MibSync FSM - mib audit - MDS check failed for the second time!", log.Fields{"device-id": oo.deviceID})
981 //TODO: send new event notification "MDS counter mismatch" to the core
982 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
983 }
984 } else if oo.pMibUploadFsm.pFsm.Is(ulStExaminingMds) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000985 if mdsValuesAreEqual && mibDataSyncOnu != 0 {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000986 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
987 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
988 } else {
989 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
990 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
991 }
992 } else {
993 logger.Warnw(ctx, "wrong state for MDS evaluation!", log.Fields{"state": oo.pMibUploadFsm.pFsm.Current(), "device-id": oo.deviceID})
994 }
995}
mpagenko15ff4a52021-03-02 10:09:20 +0000996
997//GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
998func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000999 oo.mutexOnuSwImageIndications.RLock()
mpagenko15ff4a52021-03-02 10:09:20 +00001000 if oo.onuSwImageIndications.activeEntityEntry.valid {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001001 value := oo.onuSwImageIndications.activeEntityEntry.entityID
1002 oo.mutexOnuSwImageIndications.RUnlock()
1003 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +00001004 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001005 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001006 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
1007}
1008
1009//GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
1010func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001011 oo.mutexOnuSwImageIndications.RLock()
mpagenko15ff4a52021-03-02 10:09:20 +00001012 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001013 value := oo.onuSwImageIndications.inactiveEntityEntry.entityID
1014 oo.mutexOnuSwImageIndications.RUnlock()
1015 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +00001016 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001017 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001018 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
1019}
1020
1021//IsImageToBeCommitted returns true if the active image is still uncommitted
1022func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001023 oo.mutexOnuSwImageIndications.RLock()
mpagenko15ff4a52021-03-02 10:09:20 +00001024 if oo.onuSwImageIndications.activeEntityEntry.valid {
1025 if oo.onuSwImageIndications.activeEntityEntry.entityID == aImageID {
1026 if oo.onuSwImageIndications.activeEntityEntry.isCommitted == swIsUncommitted {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001027 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001028 return true
1029 }
1030 }
1031 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001032 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001033 return false //all other case are treated as 'nothing to commit
1034}
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001035func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool {
1036
1037 oo.mibTemplatePath = oo.buildMibTemplatePath()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +00001038 logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath),
1039 "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001040
1041 restoredFromMibTemplate := false
1042 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
1043 if err == nil {
1044 if Value != nil {
1045 logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value)
1046
1047 // swap out tokens with specific data
1048 mibTmpString, _ := kvstore.ToString(Value.Value)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001049 oo.mutexPersOnuConfig.RLock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001050 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.sOnuPersistentData.PersSerialNumber, -1)
1051 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.sOnuPersistentData.PersMacAddress, -1)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001052 oo.mutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001053 mibTmpBytes := []byte(mibTmpString)
1054 logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes)
1055
1056 var firstLevelMap map[string]interface{}
1057 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
1058 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
1059 } else {
1060 for firstLevelKey, firstLevelValue := range firstLevelMap {
1061 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
1062 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
1063 meClassID := me.ClassID(uint16ValidNumber)
1064 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
1065 if isSupportedClassID(meClassID) {
1066 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
1067 secondLevelMap := firstLevelValue.(map[string]interface{})
1068 for secondLevelKey, secondLevelValue := range secondLevelMap {
1069 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
1070 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
1071 meEntityID := uint16(uint16ValidNumber)
1072 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
1073 thirdLevelMap := secondLevelValue.(map[string]interface{})
1074 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
1075 if thirdLevelKey == "Attributes" {
1076 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
1077 attributesMap := thirdLevelValue.(map[string]interface{})
1078 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
1079 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
1080 restoredFromMibTemplate = true
1081 }
1082 }
1083 }
1084 }
1085 }
1086 }
1087 }
1088 }
1089 } else {
1090 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1091 }
1092 } else {
1093 logger.Errorf(ctx, "Get from kvstore operation failed for path",
1094 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1095 }
1096 return restoredFromMibTemplate
1097}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001098
1099//CancelProcessing terminates potentially running reconciling processes and stops the FSM
1100func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) {
1101
1102 if oo.baseDeviceHandler.isReconcilingFlows() {
1103 oo.baseDeviceHandler.chReconcilingFlowsFinished <- false
1104 }
1105 if oo.baseDeviceHandler.isReconciling() {
Girish Gowdra50e56422021-06-01 16:46:04 -07001106 oo.baseDeviceHandler.stopReconciling(ctx, false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001107 }
1108 //the MibSync FSM might be active all the ONU-active time,
1109 // hence it must be stopped unconditionally
Holger Hildebrandtddc4fbd2022-02-04 14:10:36 +00001110 pMibUlFsm := oo.pMibUploadFsm
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001111 if pMibUlFsm != nil {
Holger Hildebrandtddc4fbd2022-02-04 14:10:36 +00001112 // abort running message processing
1113 fsmAbortMsg := Message{
1114 Type: TestMsg,
1115 Data: TestMessage{
1116 TestMessageVal: AbortMessageProcessing,
1117 },
1118 }
1119 pMibUlFsm.commChan <- fsmAbortMsg
1120 _ = pMibUlFsm.pFsm.Event(ulEvStop)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001121 }
1122}