blob: 2191a75b137f7d6a1115a44f01f7767c084178d6 [file] [log] [blame]
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001/*
2 * Copyright 2020-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//Package adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
19
20import (
Holger Hildebrandt2fb70892020-10-28 11:53:18 +000021 "bytes"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000022 "context"
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000023 "encoding/hex"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000024 "encoding/json"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000025 "errors"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000026 "fmt"
27 "strconv"
mpagenko3af1f032020-06-10 08:53:41 +000028 "strings"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000029
30 "github.com/looplab/fsm"
31
32 //"sync"
divyadesaibbed37c2020-08-28 13:35:20 +053033 "time"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000034
dbainbri4d3a0dc2020-12-02 00:33:42 +000035 //"github.com/opencord/voltha-lib-go/v4/pkg/kafka"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000036 "github.com/opencord/omci-lib-go"
37 me "github.com/opencord/omci-lib-go/generated"
dbainbri4d3a0dc2020-12-02 00:33:42 +000038 "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore"
39 "github.com/opencord/voltha-lib-go/v4/pkg/log"
40 //ic "github.com/opencord/voltha-protos/v4/go/inter_container"
41 //"github.com/opencord/voltha-protos/v4/go/openflow_13"
42 //"github.com/opencord/voltha-protos/v4/go/voltha"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000043)
44
mpagenko01499812021-03-25 10:37:12 +000045type sLastTxMeParameter struct {
46 lastTxMessageType omci.MessageType
47 pLastTxMeInstance *me.ManagedEntity
48 repeatCount uint8
49}
50
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000051var supportedClassIds = []me.ClassID{
52 me.CardholderClassID, // 5
53 me.CircuitPackClassID, // 6
54 me.SoftwareImageClassID, // 7
55 me.PhysicalPathTerminationPointEthernetUniClassID, // 11
56 me.OltGClassID, // 131
57 me.OnuPowerSheddingClassID, // 133
58 me.IpHostConfigDataClassID, // 134
59 me.OnuGClassID, // 256
60 me.Onu2GClassID, // 257
61 me.TContClassID, // 262
62 me.AniGClassID, // 263
63 me.UniGClassID, // 264
64 me.PriorityQueueClassID, // 277
65 me.TrafficSchedulerClassID, // 278
66 me.VirtualEthernetInterfacePointClassID, // 329
67 me.EnhancedSecurityControlClassID, // 332
68 me.OnuDynamicPowerManagementControlClassID, // 336
69 // 347 // definitions for ME "IPv6 host config data" are currently missing in omci-lib-go!
70}
71
72var fsmMsg TestMessageType
73
dbainbri4d3a0dc2020-12-02 00:33:42 +000074func (oo *OnuDeviceEntry) enterStartingState(ctx context.Context, e *fsm.Event) {
75 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": oo.deviceID})
76 oo.pOnuDB = newOnuDeviceDB(log.WithSpanFromContext(context.TODO(), ctx), oo)
77 go oo.processMibSyncMessages(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000078}
79
dbainbri4d3a0dc2020-12-02 00:33:42 +000080func (oo *OnuDeviceEntry) enterResettingMibState(ctx context.Context, e *fsm.Event) {
81 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibTemplate processing in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000082
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +000083 if (!oo.isNewOnu() && !oo.baseDeviceHandler.isReconciling()) || //use case: re-auditing failed
84 oo.baseDeviceHandler.isSkipOnuConfigReconciling() { //use case: reconciling without omci-config failed
Holger Hildebrandt10d98192021-01-27 15:29:31 +000085 oo.baseDeviceHandler.prepareReconcilingWithActiveAdapter(ctx)
86 oo.devState = DeviceStatusInit
87 }
dbainbri4d3a0dc2020-12-02 00:33:42 +000088 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send mibReset in State": e.FSM.Current(), "device-id": oo.deviceID})
Girish Gowdra0b235842021-03-09 13:06:46 -080089 _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000090 //TODO: needs to handle timeouts
mpagenko01499812021-03-25 10:37:12 +000091 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
92 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
93 oo.lastTxParamStruct.lastTxMessageType = omci.MibResetRequestType
94 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000095}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000096
dbainbri4d3a0dc2020-12-02 00:33:42 +000097func (oo *OnuDeviceEntry) enterGettingVendorAndSerialState(ctx context.Context, e *fsm.Event) {
98 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting VendorId and SerialNumber in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000099 requestedAttributes := me.AttributeValueMap{"VendorId": "", "SerialNumber": 0}
ozgecanetsiab36ed572021-04-01 10:38:48 +0300100 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 +0000101 //accept also nil as (error) return value for writing to LastTx
102 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300103 if err != nil {
104 logger.Errorw(ctx, "ONU-G get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
105 pMibUlFsm := oo.pMibUploadFsm
106 if pMibUlFsm != nil {
107 go func(a_pAFsm *AdapterFsm) {
108 _ = oo.pMibUploadFsm.pFsm.Event(ulEvResetMib)
109 }(pMibUlFsm)
110 }
111 return
112 }
mpagenko01499812021-03-25 10:37:12 +0000113 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
114 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000115}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000116
dbainbri4d3a0dc2020-12-02 00:33:42 +0000117func (oo *OnuDeviceEntry) enterGettingEquipmentIDState(ctx context.Context, e *fsm.Event) {
118 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 +0000119 requestedAttributes := me.AttributeValueMap{"EquipmentId": ""}
ozgecanetsiab36ed572021-04-01 10:38:48 +0300120 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 +0000121 //accept also nil as (error) return value for writing to LastTx
122 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300123 if err != nil {
124 logger.Errorw(ctx, "ONU2-G get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
125 pMibUlFsm := oo.pMibUploadFsm
126 if pMibUlFsm != nil {
127 go func(a_pAFsm *AdapterFsm) {
128 _ = oo.pMibUploadFsm.pFsm.Event(ulEvResetMib)
129 }(pMibUlFsm)
130 }
131 return
132 }
mpagenko01499812021-03-25 10:37:12 +0000133 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
134 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000135}
136
dbainbri4d3a0dc2020-12-02 00:33:42 +0000137func (oo *OnuDeviceEntry) enterGettingFirstSwVersionState(ctx context.Context, e *fsm.Event) {
138 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 +0000139 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
ozgecanetsiab36ed572021-04-01 10:38:48 +0300140 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 +0000141 //accept also nil as (error) return value for writing to LastTx
142 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300143 if err != nil {
144 logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
145 pMibUlFsm := oo.pMibUploadFsm
146 if pMibUlFsm != nil {
147 go func(a_pAFsm *AdapterFsm) {
148 _ = oo.pMibUploadFsm.pFsm.Event(ulEvResetMib)
149 }(pMibUlFsm)
150 }
151 return
152 }
mpagenko01499812021-03-25 10:37:12 +0000153 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
154 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000155}
156
dbainbri4d3a0dc2020-12-02 00:33:42 +0000157func (oo *OnuDeviceEntry) enterGettingSecondSwVersionState(ctx context.Context, e *fsm.Event) {
158 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 +0000159 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
ozgecanetsiab36ed572021-04-01 10:38:48 +0300160 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 +0000161 //accept also nil as (error) return value for writing to LastTx
162 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300163 if err != nil {
164 logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
165 pMibUlFsm := oo.pMibUploadFsm
166 if pMibUlFsm != nil {
167 go func(a_pAFsm *AdapterFsm) {
168 _ = oo.pMibUploadFsm.pFsm.Event(ulEvResetMib)
169 }(pMibUlFsm)
170 }
171 return
172 }
mpagenko01499812021-03-25 10:37:12 +0000173 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
174 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000175}
176
dbainbri4d3a0dc2020-12-02 00:33:42 +0000177func (oo *OnuDeviceEntry) enterGettingMacAddressState(ctx context.Context, e *fsm.Event) {
178 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 +0000179 requestedAttributes := me.AttributeValueMap{"MacAddress": ""}
ozgecanetsiab36ed572021-04-01 10:38:48 +0300180 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 +0000181 //accept also nil as (error) return value for writing to LastTx
182 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300183 if err != nil {
184 logger.Errorw(ctx, "IpHostConfigData get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
185 pMibUlFsm := oo.pMibUploadFsm
186 if pMibUlFsm != nil {
187 go func(a_pAFsm *AdapterFsm) {
188 _ = oo.pMibUploadFsm.pFsm.Event(ulEvResetMib)
189 }(pMibUlFsm)
190 }
191 return
192 }
mpagenko01499812021-03-25 10:37:12 +0000193 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
194 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000195}
196
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000197func (oo *OnuDeviceEntry) enterGettingMibTemplateState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000198
mpagenko15ff4a52021-03-02 10:09:20 +0000199 if oo.onuSwImageIndications.activeEntityEntry.valid {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000200 oo.sOnuPersistentData.PersActiveSwVersion = oo.onuSwImageIndications.activeEntityEntry.version
mpagenko15ff4a52021-03-02 10:09:20 +0000201 } else {
202 logger.Errorw(ctx, "get-mib-template: no active SW version found, working with empty SW version, which might be untrustworthy",
203 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000204 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000205 if oo.getMibFromTemplate(ctx) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000206 logger.Debug(ctx, "MibSync FSM - valid MEs stored from template")
207 oo.pOnuDB.logMeDb(ctx)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000208 fsmMsg = LoadMibTemplateOk
209 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000210 logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000211 fsmMsg = LoadMibTemplateFailed
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000212
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000213 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
214 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
215 if mibTemplateIsGenerated {
216 logger.Debugw(ctx,
217 "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map",
218 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
219 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
220 }
221 }
222 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
223 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000224 mibSyncMsg := Message{
225 Type: TestMsg,
226 Data: TestMessage{
227 TestMessageVal: fsmMsg,
228 },
229 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000230 oo.pMibUploadFsm.commChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000231}
232
dbainbri4d3a0dc2020-12-02 00:33:42 +0000233func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
234 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 -0800235 _ = oo.PDevOmciCC.sendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000236 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
237 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
238 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadRequestType
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000239}
240
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000241func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000242 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID})
243 oo.transferSystemEvent(ctx, MibDatabaseSync)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000244 go func() {
245 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
246 }()
247}
248
249func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
250 oo.sOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix())
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000251 if oo.mibAuditInterval > 0 {
252 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 +0000253 go func() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000254 time.Sleep(oo.mibAuditInterval)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000255 if err := oo.pMibUploadFsm.pFsm.Event(ulEvAuditMib); err != nil {
256 logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err})
257 }
258 }()
259 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000260}
261
dbainbri4d3a0dc2020-12-02 00:33:42 +0000262func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
263 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 +0000264 oo.requestMdsValue(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000265}
266
dbainbri4d3a0dc2020-12-02 00:33:42 +0000267func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
268 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
269 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000270 // TODOs:
271 // VOL-3805 - Provide exclusive OMCI channel for one FSM
272 // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go
273 // VOL-3792 - Support periodical audit via mib resync
274 // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000275}
276
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000277func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) {
278 logger.Debugw(ctx, "MibSync FSM",
279 log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID})
280
281 if oo.getMibFromTemplate(ctx) {
282 oo.baseDeviceHandler.startReconciling(ctx, true)
283 oo.baseDeviceHandler.addAllUniPorts(ctx)
284 oo.baseDeviceHandler.setDeviceReason(drInitialMibDownloaded)
285 oo.baseDeviceHandler.ReadyForSpecificOmciConfig = true
286 // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm
287
288 oo.baseDeviceHandler.reconcileDeviceTechProf(ctx)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000289
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000290 // start go routine with select() on reconciling flow channel before
291 // starting flow reconciling process to prevent loss of any signal
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000292 go func() {
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000293 // In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until
294 // we get a signal that the processing of the last step to rebuild the adapter internal
295 // flow data is finished.
296 select {
297 case success := <-oo.baseDeviceHandler.chReconcilingFlowsFinished:
298 if success {
299 logger.Debugw(ctx, "reconciling flows has been finished in time",
300 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000301 oo.baseDeviceHandler.stopReconciling(ctx)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000302 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000303
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000304 } else {
305 logger.Debugw(ctx, "wait for reconciling flows aborted",
306 log.Fields{"device-id": oo.deviceID})
307 oo.baseDeviceHandler.setReconcilingFlows(false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000308 }
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000309 case <-time.After(500 * time.Millisecond):
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000310 logger.Errorw(ctx, "timeout waiting for reconciling flows to be finished!",
311 log.Fields{"device-id": oo.deviceID})
312 oo.baseDeviceHandler.setReconcilingFlows(false)
313 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
314 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000315 }()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000316 oo.baseDeviceHandler.reconcileDeviceFlowConfig(ctx)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000317
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000318 if oo.sOnuPersistentData.PersUniDisableDone {
319 oo.baseDeviceHandler.disableUniPortStateUpdate(ctx)
320 oo.baseDeviceHandler.setDeviceReason(drOmciAdminLock)
321 } else {
322 oo.baseDeviceHandler.enableUniPortStateUpdate(ctx)
323 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000324 } else {
325 logger.Debugw(ctx, "MibSync FSM",
326 log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID})
327 go func() {
328 //switch to reconciling with OMCI config
329 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
330 }()
331 }
332}
333
dbainbri4d3a0dc2020-12-02 00:33:42 +0000334func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000335 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 +0000336 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000337 oo.requestMdsValue(ctx)
338 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000339 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 +0000340 go func() {
341 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
342 }()
343 }
344}
345
346func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
347 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 +0000348 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000349 oo.requestMdsValue(ctx)
350 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000351 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 +0000352 go func() {
353 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
354 }()
355 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000356}
357
dbainbri4d3a0dc2020-12-02 00:33:42 +0000358func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
359 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
360 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000361}
362
dbainbri4d3a0dc2020-12-02 00:33:42 +0000363func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
364 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 +0000365loop:
366 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000367 // case <-ctx.Done():
368 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
369 // break loop
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000370 message, ok := <-oo.pMibUploadFsm.commChan
Himani Chawla4d908332020-08-31 12:30:20 +0530371 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000372 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 +0530373 break loop
374 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000375 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000376
Himani Chawla4d908332020-08-31 12:30:20 +0530377 switch message.Type {
378 case TestMsg:
379 msg, _ := message.Data.(TestMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000380 oo.handleTestMsg(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530381 case OMCI:
382 msg, _ := message.Data.(OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000383 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530384 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000385 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 +0000386 }
387 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000388 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000389 // TODO: only this action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000390 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000391}
392
dbainbri4d3a0dc2020-12-02 00:33:42 +0000393func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000394
dbainbri4d3a0dc2020-12-02 00:33:42 +0000395 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 +0000396
397 switch msg.TestMessageVal {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000398 case LoadMibTemplateFailed:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000399 _ = oo.pMibUploadFsm.pFsm.Event(ulEvUploadMib)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000400 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000401 case LoadMibTemplateOk:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000402 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000403 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000404 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000405 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 +0000406 }
407}
408
dbainbri4d3a0dc2020-12-02 00:33:42 +0000409func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg OmciMessage) {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000410 if oo.pMibUploadFsm.pFsm.Is(ulStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530411 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
412 if msgLayer != nil {
413 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
414 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000415 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530416 if msgObj.Result == me.Success {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000417 oo.sOnuPersistentData.PersMibDataSyncAdpt = 0
Himani Chawla4d908332020-08-31 12:30:20 +0530418 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000419 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530420 return
421 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000422 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530423 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000424 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530425 }
426 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000427 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530428 }
429 } else {
mpagenko01499812021-03-25 10:37:12 +0000430 //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset
431 // with Sequence number 0x8000 as last request before - so it may still respond to that
432 // then we may force the ONU to react on the MdsGetRequest with a new message that uses an increased Sequence number
433 if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
434 logger.Debugw(ctx, "MibSync FSM - repeat MdsGetRequest (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
435 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
ozgecanetsiab36ed572021-04-01 10:38:48 +0300436 _, err := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
mpagenko01499812021-03-25 10:37:12 +0000437 me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300438 if err != nil {
439 logger.Errorw(ctx, "ONUData get failed, aborting MibSync", log.Fields{"device-id": oo.deviceID})
440 _ = oo.pMibUploadFsm.pFsm.Event(ulEvResetMib)
441 return
442 }
mpagenko01499812021-03-25 10:37:12 +0000443 //TODO: needs extra handling of timeouts
444 oo.lastTxParamStruct.repeatCount = 1
445 return
446 }
447 logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
448 //perhaps some still lingering message from some prior activity, let's wait for the real response
449 return
Himani Chawla4d908332020-08-31 12:30:20 +0530450 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000451 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000452 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530453}
454
dbainbri4d3a0dc2020-12-02 00:33:42 +0000455func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530456 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
457 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000458 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530459 return
460 }
461 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
462 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000463 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530464 return
465 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000466 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530467 /* to be verified / reworked !!! */
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000468 oo.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
469 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800470 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000471 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
472 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
473 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Himani Chawla4d908332020-08-31 12:30:20 +0530474 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000475 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 +0530476 //TODO right action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000477 _ = oo.pMibUploadFsm.pFsm.Event(ulEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530478 }
479}
480
dbainbri4d3a0dc2020-12-02 00:33:42 +0000481func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530482 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
Andrea Campanella6515c582020-10-05 11:25:00 +0200483
Holger Hildebrandte2439342020-12-03 16:06:54 +0000484 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000485 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000486 return
487 }
488 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
489 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000490 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000491 return
492 }
493 meName := msgObj.ReportedME.GetName()
494 if meName == "UnknownItuG988ManagedEntity" || meName == "UnknownVendorSpecificManagedEntity" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000495 logger.Debugw(ctx, "MibUploadNextResponse Data for unknown ME received - temporary workaround is to ignore it!",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000496 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj, "meName": meName})
497 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000498 logger.Debugw(ctx, "MibUploadNextResponse Data for:",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000499 log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
Holger Hildebrandt8998b872020-10-05 13:48:39 +0000500 meClassID := msgObj.ReportedME.GetClassID()
501 meEntityID := msgObj.ReportedME.GetEntityID()
502 meAttributes := msgObj.ReportedME.GetAttributeValueMap()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000503 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes)
Himani Chawla4d908332020-08-31 12:30:20 +0530504 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000505 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
Girish Gowdra0b235842021-03-09 13:06:46 -0800506 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
mpagenko01499812021-03-25 10:37:12 +0000507 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
508 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
509 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Himani Chawla4d908332020-08-31 12:30:20 +0530510 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000511 oo.pOnuDB.logMeDb(ctx)
512 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530513 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000514 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 +0530515 }
516
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000517 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530518 }
519}
520
dbainbri4d3a0dc2020-12-02 00:33:42 +0000521func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000522 var err error = nil
mpagenko01499812021-03-25 10:37:12 +0000523
524 if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType ||
525 oo.lastTxParamStruct.pLastTxMeInstance == nil {
526 //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest
527 // with Sequence number 0x8000 as last request before - so it may still respond to that
528 // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number
529 if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
530 logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
531 _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true)
532 //TODO: needs extra handling of timeouts
533 oo.lastTxParamStruct.repeatCount = 1
534 return nil
535 }
536 logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
537 //perhaps some still lingering message from some prior activity, let's wait for the real response
538 return nil
539 }
Himani Chawla4d908332020-08-31 12:30:20 +0530540 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000541 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000542 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 +0000543 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
544 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 +0000545 }
546 msgObj, msgOk := msgLayer.(*omci.GetResponse)
547 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000548 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 +0000549 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
550 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 +0000551 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000552 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000553 if msgObj.Result == me.Success {
mpagenko01499812021-03-25 10:37:12 +0000554 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
555 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000556 meAttributes := msgObj.Attributes
mpagenko01499812021-03-25 10:37:12 +0000557 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000558 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 +0000559 switch meInstance {
560 case "OnuG":
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000561 oo.sOnuPersistentData.PersVendorID = trimStringFromInterface(meAttributes["VendorId"])
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000562 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
563 if onugSerialNumberLen == len(snBytes) {
564 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
565 snNumberPart := hex.EncodeToString(snBytes[4:])
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000566 oo.sOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000567 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 +0000568 "onuDeviceEntry.vendorID": oo.sOnuPersistentData.PersVendorID, "onuDeviceEntry.serialNumber": oo.sOnuPersistentData.PersSerialNumber})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000569 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000570 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 +0000571 oo.sOnuPersistentData.PersSerialNumber = cEmptySerialNumberString
Himani Chawla4d908332020-08-31 12:30:20 +0530572 }
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000573 // trigger retrieval of EquipmentId
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000574 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000575 return nil
576 case "Onu2G":
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000577 oo.sOnuPersistentData.PersEquipmentID = trimStringFromInterface(meAttributes["EquipmentId"])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000578 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000579 "onuDeviceEntry.equipmentID": oo.sOnuPersistentData.PersEquipmentID})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000580 // trigger retrieval of 1st SW-image info
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000581 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000582 return nil
583 case "SoftwareImage":
mpagenko15ff4a52021-03-02 10:09:20 +0000584 if entityID > secondSwImageMeID {
585 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
586 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
587 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
588 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000589 }
mpagenko15ff4a52021-03-02 10:09:20 +0000590 // need to use function for go lint complexity
591 oo.handleSwImageIndications(ctx, entityID, meAttributes)
592 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000593 case "IpHostConfigData":
594 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
595 if omciMacAddressLen == len(macBytes) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000596 oo.sOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000597 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000598 "macAddress": oo.sOnuPersistentData.PersMacAddress})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000599 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000600 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 +0000601 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000602 }
603 // trigger retrieval of mib template
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000604 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000605 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000606 case "OnuData":
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000607 oo.checkMdsValue(ctx, meAttributes["MibDataSync"].(uint8))
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000608 return nil
Himani Chawla4d908332020-08-31 12:30:20 +0530609 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800610 } else {
611 logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000612 }
Himani Chawla4d908332020-08-31 12:30:20 +0530613 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000614 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000615 return nil
616 }
Himani Chawla4d908332020-08-31 12:30:20 +0530617 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000618 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000619 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000620 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530621}
622
mpagenko15ff4a52021-03-02 10:09:20 +0000623func (oo *OnuDeviceEntry) handleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) {
624 imageIsCommitted := meAttributes["IsCommitted"].(uint8)
625 imageIsActive := meAttributes["IsActive"].(uint8)
626 imageVersion := trimStringFromInterface(meAttributes["Version"])
627 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
628 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000629 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.sOnuPersistentData.PersSerialNumber})
mpagenko15ff4a52021-03-02 10:09:20 +0000630 if firstSwImageMeID == entityID {
631 //always accept the state of the first image (2nd image info should not yet be available)
632 if imageIsActive == swIsActive {
633 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
634 oo.onuSwImageIndications.activeEntityEntry.valid = true
635 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
636 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000637 //as the SW version indication may stem from some ONU Down/up event
638 //the complementary image state is to be invalidated
639 // (state of the second image is always expected afterwards or just invalid)
640 oo.onuSwImageIndications.inactiveEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000641 } else {
642 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
643 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
644 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
645 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000646 //as the SW version indication may stem form some ONU Down/up event
647 //the complementary image state is to be invalidated
648 // (state of the second image is always expected afterwards or just invalid)
649 oo.onuSwImageIndications.activeEntityEntry.valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000650 }
651 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion)
652 return
653 } else if secondSwImageMeID == entityID {
654 //2nd image info might conflict with first image info, in which case we priorize first image info!
655 if imageIsActive == swIsActive { //2nd image reported to be active
656 if oo.onuSwImageIndications.activeEntityEntry.valid {
657 //conflict exists - state of first image is left active
658 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
659 log.Fields{"device-id": oo.deviceID})
660 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
661 oo.onuSwImageIndications.inactiveEntityEntry.valid = true ////to indicate that at least something has been reported
662 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
663 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
664 } else { //first image inactive, this one active
665 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
666 oo.onuSwImageIndications.activeEntityEntry.valid = true
667 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
668 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
669 }
670 } else { //2nd image reported to be inactive
671 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
672 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
673 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
674 log.Fields{"device-id": oo.deviceID})
675 oo.onuSwImageIndications.activeEntityEntry.entityID = firstSwImageMeID
676 oo.onuSwImageIndications.activeEntityEntry.valid = true //to indicate that at least something has been reported
677 //copy active commit/version from the previously stored inactive position
678 oo.onuSwImageIndications.activeEntityEntry.version = oo.onuSwImageIndications.inactiveEntityEntry.version
679 oo.onuSwImageIndications.activeEntityEntry.isCommitted = oo.onuSwImageIndications.inactiveEntityEntry.isCommitted
680 }
681 //in any case we indicate (and possibly overwrite) the second image indications as inactive
682 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
683 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
684 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
685 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
686 }
687 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress)
688 return
689 }
690}
691
dbainbri4d3a0dc2020-12-02 00:33:42 +0000692func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg OmciMessage) {
693 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200694 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000695 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
696 switch msg.OmciMsg.MessageType {
697 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000698 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000699
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000700 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000701 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530702
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000703 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000704 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000705
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000706 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000707 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000708 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530709
Andrea Campanella6515c582020-10-05 11:25:00 +0200710 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000711 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200712
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000713 }
714}
715
dbainbri4d3a0dc2020-12-02 00:33:42 +0000716func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000717 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000718 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 +0000719 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
720 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
mpagenko01499812021-03-25 10:37:12 +0000721 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
722 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
723 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000724 switch meInstance {
725 case "IpHostConfigData":
dbainbri4d3a0dc2020-12-02 00:33:42 +0000726 logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros",
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000727 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000728 oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000729 // trigger retrieval of mib template
730 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
731 return nil
732 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000733 logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000734 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
735 }
736 }
737 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000738 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 +0000739 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
740 }
741 return err
742}
743
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000744func (oo *OnuDeviceEntry) isNewOnu() bool {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000745 return oo.sOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000746}
747
Himani Chawla6d2ae152020-09-02 13:11:20 +0530748func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000749 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530750 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000751 return true
752 }
753 }
754 return false
755}
756
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000757func trimStringFromInterface(input interface{}) string {
758 ifBytes, _ := me.InterfaceToOctets(input)
759 return fmt.Sprintf("%s", bytes.Trim(ifBytes, "\x00"))
760}
761
dbainbri4d3a0dc2020-12-02 00:33:42 +0000762func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
763 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000764 return errors.New("not_implemented")
765}
766
Himani Chawla6d2ae152020-09-02 13:11:20 +0530767// 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 +0530768// 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 +0000769// 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 +0000770func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
771 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000772 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530773
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000774 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
775 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
776 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000777 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000778 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
779 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
780 return nil
781 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000782 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000783 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
784 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000785 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000786 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
787 }
788 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = true
789 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
790
791 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +0530792 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000793 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +0530794 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
795
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000796 firstLevelMap := oo.pOnuDB.meDb
divyadesaibbed37c2020-08-28 13:35:20 +0530797 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000798 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +0530799 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530800
801 secondLevelMap := make(map[string]interface{})
802 for secondLevelKey, secondLevelValue := range firstLevelValue {
803 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +0530804 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530805 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +0530806 thirdLevelMap["InstanceId"] = entityID
807 secondLevelMap[entityID] = thirdLevelMap
808 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +0530809 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
810 delete(forthLevelMap, "SerialNumber")
811 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
812
813 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530814 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +0530815 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
816 delete(forthLevelMap, "MacAddress")
817 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
818 }
819 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530820 secondLevelMap["ClassId"] = classID
821 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +0530822 }
823 mibTemplate, err := json.Marshal(&templateMap)
824 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000825 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000826 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
827 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
828 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530829 return err
830 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000831 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +0530832 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000833 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 +0000834 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
835 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
836 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530837 return err
838 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000839 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530840 return nil
841}
842
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000843func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
844 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
845 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
ozgecanetsiab36ed572021-04-01 10:38:48 +0300846 meInstance, err := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
Girish Gowdra0b235842021-03-09 13:06:46 -0800847 me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000848 //accept also nil as (error) return value for writing to LastTx
849 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300850 if err != nil {
851 logger.Errorw(ctx, "ONUData get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
852 pMibUlFsm := oo.pMibUploadFsm
853 if pMibUlFsm != nil {
854 go func(a_pAFsm *AdapterFsm) {
855 _ = oo.pMibUploadFsm.pFsm.Event(ulEvResetMib)
856 }(pMibUlFsm)
857 }
858 return
859 }
mpagenko01499812021-03-25 10:37:12 +0000860 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
861 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
862 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000863}
864
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000865func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
866 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
867 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.sOnuPersistentData.PersMibDataSyncAdpt})
868
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000869 mdsValuesAreEqual := oo.sOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000870 if oo.pMibUploadFsm.pFsm.Is(ulStAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000871 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000872 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
873 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
874 } else {
875 logger.Warnw(ctx, "MibSync FSM - mib audit - MDS check failed for the first time!", log.Fields{"device-id": oo.deviceID})
876 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
877 }
878 } else if oo.pMibUploadFsm.pFsm.Is(ulStReAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000879 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000880 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
881 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
882 } else {
883 logger.Errorw(ctx, "MibSync FSM - mib audit - MDS check failed for the second time!", log.Fields{"device-id": oo.deviceID})
884 //TODO: send new event notification "MDS counter mismatch" to the core
885 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
886 }
887 } else if oo.pMibUploadFsm.pFsm.Is(ulStExaminingMds) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000888 if mdsValuesAreEqual && mibDataSyncOnu != 0 {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000889 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
890 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
891 } else {
892 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
893 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
894 }
895 } else {
896 logger.Warnw(ctx, "wrong state for MDS evaluation!", log.Fields{"state": oo.pMibUploadFsm.pFsm.Current(), "device-id": oo.deviceID})
897 }
898}
mpagenko15ff4a52021-03-02 10:09:20 +0000899
900//GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
901func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
902 if oo.onuSwImageIndications.activeEntityEntry.valid {
903 return oo.onuSwImageIndications.activeEntityEntry.entityID, nil
904 }
905 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
906}
907
908//GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
909func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
910 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
911 return oo.onuSwImageIndications.inactiveEntityEntry.entityID, nil
912 }
913 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
914}
915
916//IsImageToBeCommitted returns true if the active image is still uncommitted
917func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
918 if oo.onuSwImageIndications.activeEntityEntry.valid {
919 if oo.onuSwImageIndications.activeEntityEntry.entityID == aImageID {
920 if oo.onuSwImageIndications.activeEntityEntry.isCommitted == swIsUncommitted {
921 return true
922 }
923 }
924 }
925 return false //all other case are treated as 'nothing to commit
926}
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000927func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool {
928
929 oo.mibTemplatePath = oo.buildMibTemplatePath()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000930 logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath),
931 "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000932
933 restoredFromMibTemplate := false
934 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
935 if err == nil {
936 if Value != nil {
937 logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value)
938
939 // swap out tokens with specific data
940 mibTmpString, _ := kvstore.ToString(Value.Value)
941 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.sOnuPersistentData.PersSerialNumber, -1)
942 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.sOnuPersistentData.PersMacAddress, -1)
943 mibTmpBytes := []byte(mibTmpString)
944 logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes)
945
946 var firstLevelMap map[string]interface{}
947 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
948 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
949 } else {
950 for firstLevelKey, firstLevelValue := range firstLevelMap {
951 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
952 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
953 meClassID := me.ClassID(uint16ValidNumber)
954 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
955 if isSupportedClassID(meClassID) {
956 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
957 secondLevelMap := firstLevelValue.(map[string]interface{})
958 for secondLevelKey, secondLevelValue := range secondLevelMap {
959 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
960 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
961 meEntityID := uint16(uint16ValidNumber)
962 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
963 thirdLevelMap := secondLevelValue.(map[string]interface{})
964 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
965 if thirdLevelKey == "Attributes" {
966 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
967 attributesMap := thirdLevelValue.(map[string]interface{})
968 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
969 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
970 restoredFromMibTemplate = true
971 }
972 }
973 }
974 }
975 }
976 }
977 }
978 }
979 } else {
980 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
981 }
982 } else {
983 logger.Errorf(ctx, "Get from kvstore operation failed for path",
984 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
985 }
986 return restoredFromMibTemplate
987}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000988
989//CancelProcessing terminates potentially running reconciling processes and stops the FSM
990func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) {
991
992 if oo.baseDeviceHandler.isReconcilingFlows() {
993 oo.baseDeviceHandler.chReconcilingFlowsFinished <- false
994 }
995 if oo.baseDeviceHandler.isReconciling() {
996 oo.baseDeviceHandler.chReconcilingFinished <- false
997 }
998 //the MibSync FSM might be active all the ONU-active time,
999 // hence it must be stopped unconditionally
1000 pMibUlFsm := oo.pMibUploadFsm.pFsm
1001 if pMibUlFsm != nil {
1002 _ = pMibUlFsm.Event(ulEvStop)
1003 }
1004}