blob: 39a95847e12bd91debe25a6d2c7ff01b85646c8f [file] [log] [blame]
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001/*
Joey Armstrong89c812c2024-01-12 19:00:20 -05002 * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00003 *
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
nikesh.krishnan1ffb8132023-05-23 03:44:13 +053017// Package mib provides the utilities for managing the onu mib
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000018package mib
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000019
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"
Girish Gowdraf7d82d02022-04-26 16:18:35 -070028 "sync"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000029
30 "github.com/looplab/fsm"
31
divyadesaibbed37c2020-08-28 13:35:20 +053032 "time"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000033
mpagenko7033f4e2021-11-19 18:04:22 +000034 "github.com/google/gopacket"
mpagenko836a1fd2021-11-01 16:12:42 +000035 "github.com/opencord/omci-lib-go/v2"
36 me "github.com/opencord/omci-lib-go/v2/generated"
khenaidoo7d3c5582021-08-11 18:09:44 -040037 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
38 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000039 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
40 devdb "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb"
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +000041 otst "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/omcitst"
Holger Hildebrandt9afc1582021-11-30 16:10:19 +000042 "github.com/opencord/voltha-protos/v5/go/inter_adapter"
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
ozgecanetsia124d9732021-09-16 14:31:57 +030056 me.PhysicalPathTerminationPointPotsUniClassID, // 53
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000057 me.OltGClassID, // 131
58 me.OnuPowerSheddingClassID, // 133
59 me.IpHostConfigDataClassID, // 134
60 me.OnuGClassID, // 256
61 me.Onu2GClassID, // 257
62 me.TContClassID, // 262
63 me.AniGClassID, // 263
64 me.UniGClassID, // 264
65 me.PriorityQueueClassID, // 277
66 me.TrafficSchedulerClassID, // 278
67 me.VirtualEthernetInterfacePointClassID, // 329
68 me.EnhancedSecurityControlClassID, // 332
69 me.OnuDynamicPowerManagementControlClassID, // 336
70 // 347 // definitions for ME "IPv6 host config data" are currently missing in omci-lib-go!
71}
72
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +000073var omccVersionSupportsExtendedOmciFormat = map[uint8]bool{
74 0x80: false,
75 0x81: false,
76 0x82: false,
77 0x83: false,
78 0x84: false,
79 0x85: false,
80 0x86: false,
81 0xA0: false,
82 0xA1: false,
83 0xA2: false,
84 0xA3: false,
85 0x96: true,
86 0xB0: true,
87 0xB1: true,
88 0xB2: true,
89 0xB3: true,
90 0xB4: true,
91}
92
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000093var fsmMsg cmn.TestMessageType
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000094
dbainbri4d3a0dc2020-12-02 00:33:42 +000095func (oo *OnuDeviceEntry) enterStartingState(ctx context.Context, e *fsm.Event) {
96 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000097 oo.pOnuDB = devdb.NewOnuDeviceDB(log.WithSpanFromContext(context.TODO(), ctx), oo.deviceID)
dbainbri4d3a0dc2020-12-02 00:33:42 +000098 go oo.processMibSyncMessages(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000099}
100
dbainbri4d3a0dc2020-12-02 00:33:42 +0000101func (oo *OnuDeviceEntry) enterResettingMibState(ctx context.Context, e *fsm.Event) {
102 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 +0000103
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000104 if (!oo.IsNewOnu() && !oo.baseDeviceHandler.IsReconciling()) || //use case: re-auditing failed
105 oo.baseDeviceHandler.IsSkipOnuConfigReconciling() { //use case: reconciling without omci-config failed
106 oo.baseDeviceHandler.PrepareReconcilingWithActiveAdapter(ctx)
107 oo.devState = cmn.DeviceStatusInit
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000108 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000109 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 +0000110 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000111 _ = oo.PDevOmciCC.SendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000112 //TODO: needs to handle timeouts
mpagenko01499812021-03-25 10:37:12 +0000113 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
114 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
115 oo.lastTxParamStruct.lastTxMessageType = omci.MibResetRequestType
116 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000117 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000118}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000119
dbainbri4d3a0dc2020-12-02 00:33:42 +0000120func (oo *OnuDeviceEntry) enterGettingVendorAndSerialState(ctx context.Context, e *fsm.Event) {
121 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting VendorId and SerialNumber in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000122 requestedAttributes := me.AttributeValueMap{me.OnuG_VendorId: "", me.OnuG_SerialNumber: 0}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000123 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000124 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.OnuGClassID, cmn.OnugMeID, requestedAttributes,
Holger Hildebrandtd930cb22022-06-17 09:24:50 +0000125 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, false)
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, "ONU-G get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000131 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300132 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000133 go func(a_pAFsm *cmn.AdapterFsm) {
134 _ = 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}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000143
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000144func (oo *OnuDeviceEntry) enterGettingVersionState(ctx context.Context, e *fsm.Event) {
145 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting Version in State": e.FSM.Current(), "device-id": oo.deviceID})
146 requestedAttributes := me.AttributeValueMap{me.OnuG_Version: ""}
147 oo.mutexLastTxParamStruct.Lock()
148 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.OnuGClassID, cmn.OnugMeID,
Holger Hildebrandtd930cb22022-06-17 09:24:50 +0000149 requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, false)
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000150 //accept also nil as (error) return value for writing to LastTx
151 // - this avoids misinterpretation of new received OMCI messages
152 if err != nil {
153 oo.mutexLastTxParamStruct.Unlock()
154 logger.Errorw(ctx, "ONU-G get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
155 pMibUlFsm := oo.PMibUploadFsm
156 if pMibUlFsm != nil {
157 go func(a_pAFsm *cmn.AdapterFsm) {
158 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
159 }(pMibUlFsm)
160 }
161 return
162 }
163 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
164 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
165 oo.mutexLastTxParamStruct.Unlock()
166}
167
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000168func (oo *OnuDeviceEntry) enterGettingEquipIDAndOmccVersState(ctx context.Context, e *fsm.Event) {
169 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting EquipmentId and OMCC version in State": e.FSM.Current(), "device-id": oo.deviceID})
170 requestedAttributes := me.AttributeValueMap{me.Onu2G_EquipmentId: "", me.Onu2G_OpticalNetworkUnitManagementAndControlChannelOmccVersion: 0}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000171 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000172 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.Onu2GClassID, cmn.Onu2gMeID, requestedAttributes,
Holger Hildebrandtd930cb22022-06-17 09:24:50 +0000173 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, false)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000174 //accept also nil as (error) return value for writing to LastTx
175 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300176 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000177 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300178 logger.Errorw(ctx, "ONU2-G get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000179 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300180 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000181 go func(a_pAFsm *cmn.AdapterFsm) {
182 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300183 }(pMibUlFsm)
184 }
185 return
186 }
mpagenko01499812021-03-25 10:37:12 +0000187 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
188 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000189 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000190}
191
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000192func (oo *OnuDeviceEntry) enterTestingExtOmciSupportState(ctx context.Context, e *fsm.Event) {
193 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start testing extended OMCI msg in State": e.FSM.Current(), "device-id": oo.deviceID})
194 omciVerify := otst.NewOmciTestRequest(log.WithSpanFromContext(context.TODO(), ctx),
195 oo.deviceID, oo.PDevOmciCC, true, true, true)
196 verifyExec := make(chan bool)
197 omciVerify.PerformOmciTest(log.WithSpanFromContext(context.TODO(), ctx), verifyExec)
198
199 // If verification of test message in extended OMCI format fails, reset ONU capability to OMCI baseline format
200 select {
201 case <-time.After(((cmn.CDefaultRetries+1)*otst.CTestRequestOmciTimeout + 1) * time.Second):
202 logger.Warnw(ctx, "testing extended OMCI msg format timed out - reset to baseline format", log.Fields{"device-id": oo.deviceID})
203 oo.MutexPersOnuConfig.Lock()
204 oo.SOnuPersistentData.PersIsExtOmciSupported = false
205 oo.MutexPersOnuConfig.Unlock()
206 case success := <-verifyExec:
207 if success {
208 logger.Debugw(ctx, "testing extended OMCI msg format succeeded", log.Fields{"device-id": oo.deviceID})
209 } else {
210 logger.Warnw(ctx, "testing extended OMCI msg format failed - reset to baseline format", log.Fields{"device-id": oo.deviceID, "result": success})
211 oo.MutexPersOnuConfig.Lock()
212 oo.SOnuPersistentData.PersIsExtOmciSupported = false
213 oo.MutexPersOnuConfig.Unlock()
214 }
215 }
216 pMibUlFsm := oo.PMibUploadFsm
217 if pMibUlFsm != nil {
218 go func(a_pAFsm *cmn.AdapterFsm) {
219 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetFirstSwVersion)
220 }(pMibUlFsm)
221 }
222}
223
dbainbri4d3a0dc2020-12-02 00:33:42 +0000224func (oo *OnuDeviceEntry) enterGettingFirstSwVersionState(ctx context.Context, e *fsm.Event) {
225 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})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000226 requestedAttributes := me.AttributeValueMap{me.SoftwareImage_IsCommitted: 0, me.SoftwareImage_IsActive: 0, me.SoftwareImage_Version: ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000227 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000228 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, cmn.FirstSwImageMeID, requestedAttributes,
Holger Hildebrandtd930cb22022-06-17 09:24:50 +0000229 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, oo.GetPersIsExtOmciSupported())
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000230 //accept also nil as (error) return value for writing to LastTx
231 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300232 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000233 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300234 logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000235 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300236 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000237 go func(a_pAFsm *cmn.AdapterFsm) {
238 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300239 }(pMibUlFsm)
240 }
241 return
242 }
mpagenko01499812021-03-25 10:37:12 +0000243 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
244 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000245 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000246}
247
dbainbri4d3a0dc2020-12-02 00:33:42 +0000248func (oo *OnuDeviceEntry) enterGettingSecondSwVersionState(ctx context.Context, e *fsm.Event) {
249 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})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000250 requestedAttributes := me.AttributeValueMap{me.SoftwareImage_IsCommitted: 0, me.SoftwareImage_IsActive: 0, me.SoftwareImage_Version: ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000251 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000252 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, cmn.SecondSwImageMeID, requestedAttributes,
Holger Hildebrandtd930cb22022-06-17 09:24:50 +0000253 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, oo.GetPersIsExtOmciSupported())
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000254 //accept also nil as (error) return value for writing to LastTx
255 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300256 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000257 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300258 logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000259 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300260 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000261 go func(a_pAFsm *cmn.AdapterFsm) {
262 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300263 }(pMibUlFsm)
264 }
265 return
266 }
mpagenko01499812021-03-25 10:37:12 +0000267 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
268 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000269 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000270}
271
dbainbri4d3a0dc2020-12-02 00:33:42 +0000272func (oo *OnuDeviceEntry) enterGettingMacAddressState(ctx context.Context, e *fsm.Event) {
273 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting MacAddress in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000274 requestedAttributes := me.AttributeValueMap{me.IpHostConfigData_MacAddress: ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000275 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000276 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.IpHostConfigDataClassID, cmn.IPHostConfigDataMeID, requestedAttributes,
Holger Hildebrandtd930cb22022-06-17 09:24:50 +0000277 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, oo.GetPersIsExtOmciSupported())
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000278 //accept also nil as (error) return value for writing to LastTx
279 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300280 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000281 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300282 logger.Errorw(ctx, "IpHostConfigData get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000283 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300284 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000285 go func(a_pAFsm *cmn.AdapterFsm) {
286 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300287 }(pMibUlFsm)
288 }
289 return
290 }
mpagenko01499812021-03-25 10:37:12 +0000291 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
292 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000293 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000294}
295
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000296func (oo *OnuDeviceEntry) enterGettingMibTemplateState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000297
Holger Hildebrandt05011352021-06-15 09:40:24 +0000298 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000299 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
300 oo.MutexPersOnuConfig.Lock()
301 oo.SOnuPersistentData.PersActiveSwVersion = oo.onuSwImageIndications.ActiveEntityEntry.Version
302 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt05011352021-06-15 09:40:24 +0000303 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000304 } else {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000305 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000306 logger.Errorw(ctx, "get-mib-template: no active SW version found, working with empty SW version, which might be untrustworthy",
307 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000308 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000309
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530310 //create the MIB Template path
311 oo.mibTemplatePath = oo.buildMibTemplatePath()
312
313 if cmnMEDBVal, exist := oo.pOpenOnuAc.FetchEntryFromMibDatabaseMap(ctx, oo.mibTemplatePath); exist {
314 logger.Infow(ctx, "A Common MIB DB Instance exist for this type of ONT", log.Fields{"device-id": oo.deviceID, "mibTemplatePath": oo.mibTemplatePath})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000315 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530316 oo.pOnuDB.CommonMeDb = cmnMEDBVal
317
pnalmas8c2f09d2025-01-02 11:30:03 +0530318 //VOL-5406:If the Instance is present but the MIB templates are cleaned up . Check and create one.
319 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
320 if err == nil {
321 if Value == nil {
322
323 error := oo.createAndPersistMibTemplate(ctx)
324 if error != nil {
325 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to create and persist the mib template", log.Fields{"error": err, "device-id": oo.deviceID})
326 } else {
327 logger.Infow(ctx, "MIB Template created and stored ", log.Fields{"device-id": oo.deviceID, "mibTemplatePath": oo.mibTemplatePath})
328 }
329 }
330 } else {
331 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to create and persist the mib template", log.Fields{"error": err, "device-id": oo.deviceID})
332 }
333
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530334 if cmnMEDBVal.MIBUploadStatus == devdb.Completed {
335 oo.pOnuDB.CommonMeDb.MeDbLock.Lock()
336 oo.updateOnuSpecificEntries(ctx)
337 oo.pOnuDB.CommonMeDb.MeDbLock.Unlock()
338 fsmMsg = cmn.LoadMibTemplateOk
339 } else {
340 logger.Errorw(ctx, "A previous MIB Upload for this type of ONT has failed, request for a MIB UPload", log.Fields{"device-id": oo.deviceID})
341 oo.pOpenOnuAc.ResetEntryFromMibDatabaseMap(ctx, oo.mibTemplatePath)
342 fsmMsg = cmn.LoadMibTemplateFailed
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000343 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000344 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530345
346 } else {
347 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
348 if err == nil && Value != nil {
349 logger.Infow(ctx, "No Common MIB DB instance exist , creating from Template", log.Fields{"device-id": oo.deviceID, "mibTemplatePath": oo.mibTemplatePath})
350 oo.processMibTemplate(ctx, Value)
351 } else {
352 logger.Infow(ctx, "Neither Common MIB DB Instance nor MIB template exist for this type of ONT", log.Fields{"device-id": oo.deviceID, "mibTemplatePath": oo.mibTemplatePath})
353 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
354 cmnMEDBValue, _ := oo.pOpenOnuAc.CreateEntryAtMibDatabaseMap(ctx, oo.mibTemplatePath)
355 oo.pOnuDB.CommonMeDb = cmnMEDBValue
356 oo.pOnuDB.CommonMeDb.MeDbLock.Lock()
357 fsmMsg = cmn.LoadMibTemplateFailed
358
359 }
360
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000361 }
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530362
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000363 mibSyncMsg := cmn.Message{
364 Type: cmn.TestMsg,
365 Data: cmn.TestMessage{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000366 TestMessageVal: fsmMsg,
367 },
368 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000369 oo.PMibUploadFsm.CommChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000370}
371
dbainbri4d3a0dc2020-12-02 00:33:42 +0000372func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
373 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send MibUpload in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt5458d892022-05-31 09:52:06 +0000374 _ = oo.PDevOmciCC.SendMibUpload(log.WithSpanFromContext(context.TODO(), ctx),
375 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.GetPersIsExtOmciSupported())
mpagenko01499812021-03-25 10:37:12 +0000376 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
377 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000378 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000379 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000380 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000381}
382
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000383func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000384 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000385 oo.transferSystemEvent(ctx, cmn.MibDatabaseSync)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000386 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000387 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000388 }()
389}
390
391func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000392 oo.MutexPersOnuConfig.Lock()
393 oo.SOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix())
394 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000395 if oo.mibAuditInterval > 0 {
396 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 +0000397 go func() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000398 time.Sleep(oo.mibAuditInterval)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000399 if err := oo.PMibUploadFsm.PFsm.Event(UlEvAuditMib); err != nil {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000400 logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err})
401 }
402 }()
403 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000404}
405
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000406func (oo *OnuDeviceEntry) enterVerifyingAndStoringTPsState(ctx context.Context, e *fsm.Event) {
407 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start verifying and storing TPs in State": e.FSM.Current(), "device-id": oo.deviceID})
408
Holger Hildebrandt80f57762022-02-16 10:03:24 +0000409 if oo.getAllStoredTpInstFromParentAdapter(ctx) {
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000410 logger.Debugw(ctx, "MibSync FSM", log.Fields{"reconciling - verifying TPs successful": e.FSM.Current(), "device-id": oo.deviceID})
411 go func() {
412 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
413 }()
414 } else {
415 logger.Debugw(ctx, "MibSync FSM", log.Fields{"reconciling - verifying TPs not successful": e.FSM.Current(), "device-id": oo.deviceID})
416 oo.baseDeviceHandler.SetReconcilingReasonUpdate(true)
417 go func() {
418 if err := oo.baseDeviceHandler.StorePersistentData(ctx); err != nil {
419 logger.Warnw(ctx, "reconciling - store persistent data error - continue for now as there will be additional write attempts",
420 log.Fields{"device-id": oo.deviceID, "err": err})
421 }
422 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
423 }()
424 }
425}
426
dbainbri4d3a0dc2020-12-02 00:33:42 +0000427func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
428 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start GetMds processing in State": e.FSM.Current(), "device-id": oo.deviceID})
Praneeth Kumar Nalmas77ab2f32024-04-17 11:14:27 +0530429 oo.pOpenOnuAc.RLockMutexDeviceHandlersMap()
430 dh, _ := oo.pOpenOnuAc.GetDeviceHandler(oo.deviceID)
431 oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
432 if dh.GetSkipOnuConfigEnabled() {
433 go func() {
434 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
435 }()
436 } else {
437 oo.requestMdsValue(ctx)
438 }
439
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000440}
441
dbainbri4d3a0dc2020-12-02 00:33:42 +0000442func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
443 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
444 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000445 // TODOs:
446 // VOL-3805 - Provide exclusive OMCI channel for one FSM
447 // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go
448 // VOL-3792 - Support periodical audit via mib resync
449 // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000450}
451
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000452func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) {
453 logger.Debugw(ctx, "MibSync FSM",
454 log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID})
455
456 if oo.getMibFromTemplate(ctx) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000457 oo.baseDeviceHandler.StartReconciling(ctx, true)
458 oo.baseDeviceHandler.AddAllUniPorts(ctx)
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000459 _ = oo.baseDeviceHandler.ReasonUpdate(ctx, cmn.DrInitialMibDownloaded, oo.baseDeviceHandler.IsReconcilingReasonUpdate())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000460 oo.baseDeviceHandler.SetReadyForOmciConfig(true)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000461
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000462 if !oo.baseDeviceHandler.GetCollectorIsRunning() {
Girish Gowdraf7d82d02022-04-26 16:18:35 -0700463 var waitForOmciProcess sync.WaitGroup
464 waitForOmciProcess.Add(1)
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000465 // Start PM collector routine
Girish Gowdraf7d82d02022-04-26 16:18:35 -0700466 go oo.baseDeviceHandler.StartCollector(ctx, &waitForOmciProcess)
467 waitForOmciProcess.Wait()
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000468 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000469 if !oo.baseDeviceHandler.GetAlarmManagerIsRunning(ctx) {
470 go oo.baseDeviceHandler.StartAlarmManager(ctx)
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000471 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700472
473 for _, uniPort := range *oo.baseDeviceHandler.GetUniEntityMap() {
474 // only if this port was enabled for use by the operator at startup
475 if (1<<uniPort.UniID)&oo.baseDeviceHandler.GetUniPortMask() == (1 << uniPort.UniID) {
476 if !oo.baseDeviceHandler.GetFlowMonitoringIsRunning(uniPort.UniID) {
477 go oo.baseDeviceHandler.PerOnuFlowHandlerRoutine(uniPort.UniID)
478 }
479 }
480 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000481 oo.MutexPersOnuConfig.RLock()
482 if oo.SOnuPersistentData.PersUniDisableDone {
483 oo.MutexPersOnuConfig.RUnlock()
484 oo.baseDeviceHandler.DisableUniPortStateUpdate(ctx)
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000485 _ = oo.baseDeviceHandler.ReasonUpdate(ctx, cmn.DrOmciAdminLock, oo.baseDeviceHandler.IsReconcilingReasonUpdate())
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000486 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000487 oo.MutexPersOnuConfig.RUnlock()
488 oo.baseDeviceHandler.EnableUniPortStateUpdate(ctx)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000489 }
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000490
491 // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm
492
493 if oo.baseDeviceHandler.ReconcileDeviceTechProf(ctx) {
494 // start go routine with select() on reconciling flow channel before
495 // starting flow reconciling process to prevent loss of any signal
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +0000496 syncChannel := make(chan struct{})
497 go func(aSyncChannel chan struct{}) {
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000498 // In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until
499 // we get a signal that the processing of the last step to rebuild the adapter internal
500 // flow data is finished.
501 expiry := oo.baseDeviceHandler.GetReconcileExpiryVlanConfigAbort()
502 oo.setReconcilingFlows(true)
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +0000503 aSyncChannel <- struct{}{}
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000504 select {
505 case success := <-oo.chReconcilingFlowsFinished:
506 if success {
507 logger.Debugw(ctx, "reconciling flows has been finished in time",
508 log.Fields{"device-id": oo.deviceID})
509 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
510
511 } else {
512 logger.Debugw(ctx, "wait for reconciling flows aborted",
513 log.Fields{"device-id": oo.deviceID})
514 }
515 case <-time.After(expiry):
516 logger.Errorw(ctx, "timeout waiting for reconciling flows to be finished!",
517 log.Fields{"device-id": oo.deviceID, "expiry": expiry})
518 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
519 }
520 oo.setReconcilingFlows(false)
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +0000521 }(syncChannel)
522 // block further processing until the above Go routine has really started
523 // and is ready to receive values from chReconcilingFlowsFinished
524 <-syncChannel
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000525 oo.baseDeviceHandler.ReconcileDeviceFlowConfig(ctx)
526 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000527 } else {
528 logger.Debugw(ctx, "MibSync FSM",
529 log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID})
530 go func() {
531 //switch to reconciling with OMCI config
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000532 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000533 }()
534 }
535}
536
dbainbri4d3a0dc2020-12-02 00:33:42 +0000537func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000538 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibAudit processing in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000539 if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000540 oo.requestMdsValue(ctx)
541 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000542 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 +0000543 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000544 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000545 }()
546 }
547}
548
549func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
550 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start retest MdsValue processing in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000551 if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000552 oo.requestMdsValue(ctx)
553 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000554 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 +0000555 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000556 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000557 }()
558 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000559}
560
dbainbri4d3a0dc2020-12-02 00:33:42 +0000561func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
562 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
563 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000564}
565
dbainbri4d3a0dc2020-12-02 00:33:42 +0000566func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
567 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Start routine to process OMCI-messages for device-id": oo.deviceID})
Girish Gowdra37c9d912022-02-08 16:24:57 -0800568 oo.mutexMibSyncMsgProcessorRunning.Lock()
569 oo.mibSyncMsgProcessorRunning = true
570 oo.mutexMibSyncMsgProcessorRunning.Unlock()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000571loop:
572 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000573 // case <-ctx.Done():
574 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
575 // break loop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000576 message, ok := <-oo.PMibUploadFsm.CommChan
Himani Chawla4d908332020-08-31 12:30:20 +0530577 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000578 logger.Info(ctx, "MibSync Msg", log.Fields{"Message couldn't be read from channel for device-id": oo.deviceID})
Girish Gowdra37c9d912022-02-08 16:24:57 -0800579 oo.mutexMibSyncMsgProcessorRunning.Lock()
580 oo.mibSyncMsgProcessorRunning = false
581 oo.mutexMibSyncMsgProcessorRunning.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530582 break loop
583 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000584 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000585
Himani Chawla4d908332020-08-31 12:30:20 +0530586 switch message.Type {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000587 case cmn.TestMsg:
588 msg, _ := message.Data.(cmn.TestMessage)
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000589 if msg.TestMessageVal == cmn.AbortMessageProcessing {
590 logger.Debugw(ctx, "MibSync Msg abort ProcessMsg", log.Fields{"for device-id": oo.deviceID})
Girish Gowdra37c9d912022-02-08 16:24:57 -0800591 oo.mutexMibSyncMsgProcessorRunning.Lock()
592 oo.mibSyncMsgProcessorRunning = false
593 oo.mutexMibSyncMsgProcessorRunning.Unlock()
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000594 break loop
595 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000596 oo.handleTestMsg(ctx, msg)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000597 case cmn.OMCI:
598 msg, _ := message.Data.(cmn.OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000599 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530600 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000601 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 +0000602 }
603 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000604 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000605 // TODO: only this action?
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000606 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000607}
608
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000609func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg cmn.TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000610
dbainbri4d3a0dc2020-12-02 00:33:42 +0000611 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 +0000612
613 switch msg.TestMessageVal {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000614 case cmn.LoadMibTemplateFailed:
615 _ = oo.PMibUploadFsm.PFsm.Event(UlEvUploadMib)
616 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.PMibUploadFsm.PFsm.Current())})
617 case cmn.LoadMibTemplateOk:
618 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
619 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.PMibUploadFsm.PFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000620 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000621 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 +0000622 }
623}
624
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000625func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
626 if oo.PMibUploadFsm.PFsm.Is(UlStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530627 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
628 if msgLayer != nil {
629 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
630 if msgOk {
nikesh.krishnan1ffb8132023-05-23 03:44:13 +0530631 logger.Infow(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530632 if msgObj.Result == me.Success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000633 oo.MutexPersOnuConfig.Lock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000634 oo.SOnuPersistentData.PersMibDataSyncAdpt = cmn.MdsDefaultMib
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000635 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt7e138462023-03-29 12:12:14 +0000636 oo.PDevOmciCC.ResetConfFailMEs()
Himani Chawla4d908332020-08-31 12:30:20 +0530637 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000638 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530639 return
640 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000641 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530642 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000643 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530644 }
645 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000646 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530647 }
648 } else {
mpagenko01499812021-03-25 10:37:12 +0000649 //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset
650 // with Sequence number 0x8000 as last request before - so it may still respond to that
651 // 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 +0000652 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000653 if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
654 logger.Debugw(ctx, "MibSync FSM - repeat MdsGetRequest (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000655 requestedAttributes := me.AttributeValueMap{me.OnuData_MibDataSync: ""}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000656 _, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
Holger Hildebrandtd930cb22022-06-17 09:24:50 +0000657 me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, false)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300658 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000659 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300660 logger.Errorw(ctx, "ONUData get failed, aborting MibSync", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000661 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300662 return
663 }
mpagenko01499812021-03-25 10:37:12 +0000664 //TODO: needs extra handling of timeouts
665 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000666 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000667 return
668 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000669 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000670 logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
671 //perhaps some still lingering message from some prior activity, let's wait for the real response
672 return
Himani Chawla4d908332020-08-31 12:30:20 +0530673 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000674 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000675 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530676}
677
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000678func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530679 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
680 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000681 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530682 return
683 }
684 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
685 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000686 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530687 return
688 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000689 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530690 /* to be verified / reworked !!! */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000691 oo.PDevOmciCC.UploadNoOfCmds = msgObj.NumberOfCommands
692 if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds {
Holger Hildebrandt5458d892022-05-31 09:52:06 +0000693 _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx),
694 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.GetPersIsExtOmciSupported())
mpagenko01499812021-03-25 10:37:12 +0000695 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
696 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000697 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000698 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000699 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530700 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000701 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 +0530702 //TODO right action?
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000703 _ = oo.PMibUploadFsm.PFsm.Event(UlEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530704 }
705}
706
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000707func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530708 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
mpagenko7033f4e2021-11-19 18:04:22 +0000709 if msgLayer != nil {
710 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
711 if !msgOk {
712 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
713 return
mpagenko836a1fd2021-11-01 16:12:42 +0000714 }
mpagenko7033f4e2021-11-19 18:04:22 +0000715 meName := msgObj.ReportedME.GetName()
716 meClassID := msgObj.ReportedME.GetClassID()
717 meEntityID := msgObj.ReportedME.GetEntityID()
718
719 logger.Debugw(ctx, "MibUploadNextResponse Data for:", log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
720
721 if meName == devdb.CUnknownItuG988ManagedEntity || meName == devdb.CUnknownVendorSpecificManagedEntity {
Holger Hildebrandt39080022022-03-16 10:03:17 +0000722 logger.Debugw(ctx, "MibUploadNextResponse contains unknown ME", log.Fields{"device-id": oo.deviceID,
723 "Me-Name": devdb.UnknownMeOrAttribName(meName), "Me-ClassId": meClassID, "Me-InstId": meEntityID,
724 "unknown mask": msgObj.ReportedME.GetAttributeMask(), "unknown attributes": msgObj.BaseLayer.Payload})
725 oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.UnknownMeOrAttribName(meName), meClassID, meEntityID,
726 msgObj.ReportedME.GetAttributeMask(), msgObj.BaseLayer.Payload[devdb.CStartUnknownMeAttribsInBaseLayerPayload:])
mpagenko7033f4e2021-11-19 18:04:22 +0000727 } else {
728 //with relaxed decoding set in the OMCI-LIB we have the chance to detect if there are some unknown attributes appended which we cannot decode
729 if unknownAttrLayer := (*msg.OmciPacket).Layer(omci.LayerTypeUnknownAttributes); unknownAttrLayer != nil {
730 logger.Warnw(ctx, "MibUploadNextResponse contains unknown attributes", log.Fields{"device-id": oo.deviceID})
731 if unknownAttributes, ok := unknownAttrLayer.(*omci.UnknownAttributes); ok {
732 // provide a loop over several ME's here already in preparation of OMCI extended message format
733 for _, unknown := range unknownAttributes.Attributes {
734 unknownAttrClassID := unknown.EntityClass // ClassID
735 unknownAttrInst := unknown.EntityInstance // uint16
736 unknownAttrMask := unknown.AttributeMask // ui
737 unknownAttrBlob := unknown.AttributeData // []byte
738 logger.Warnw(ctx, "unknown attributes detected for", log.Fields{"device-id": oo.deviceID,
739 "Me-ClassId": unknownAttrClassID, "Me-InstId": unknownAttrInst, "unknown mask": unknownAttrMask,
740 "unknown attributes": unknownAttrBlob})
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000741 oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.CUnknownAttributesManagedEntity, unknown.EntityClass, unknown.EntityInstance,
742 unknown.AttributeMask, unknown.AttributeData)
mpagenko7033f4e2021-11-19 18:04:22 +0000743 } // for all included ME's with unknown attributes
744 } else {
745 logger.Errorw(ctx, "unknownAttrLayer could not be decoded", log.Fields{"device-id": oo.deviceID})
746 }
747 }
748 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, msgObj.ReportedME.GetAttributeValueMap())
749 }
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000750 if msg.OmciMsg.DeviceIdentifier == omci.ExtendedIdent {
751 for _, additionalME := range msgObj.AdditionalMEs {
752 meName := additionalME.GetName()
753 meClassID := additionalME.GetClassID()
754 meEntityID := additionalME.GetEntityID()
755 attributes := additionalME.GetAttributeValueMap()
756
757 if meName == devdb.CUnknownItuG988ManagedEntity || meName == devdb.CUnknownVendorSpecificManagedEntity {
758 attribMask := additionalME.GetAttributeMask()
759 logger.Debugw(ctx, "MibUploadNextResponse AdditionalData contains unknown ME", log.Fields{"device-id": oo.deviceID,
760 "Me-Name": devdb.UnknownMeOrAttribName(meName), "Me-ClassId": meClassID, "Me-InstId": meEntityID,
761 "unknown mask": attribMask})
762
763 attribValues := make([]byte, 0)
764 for key, value := range attributes {
765 if key != cmn.CGenericManagedEntityIDName {
766 data, err := me.InterfaceToOctets(value)
767 if err != nil {
768 logger.Infow(ctx, "MibUploadNextResponse unknown ME AdditionalData attrib - could not decode", log.Fields{"device-id": oo.deviceID, "key": key})
769 } else {
770 attribValues = append(attribValues[:], data[:]...)
771 logger.Debugw(ctx, "MibUploadNextResponse unknown ME AdditionalData attrib", log.Fields{"device-id": oo.deviceID, "attribValues": attribValues, "data": data, "key": key})
772 }
773 }
774 }
775 oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.UnknownMeOrAttribName(meName), meClassID, meEntityID, attribMask, attribValues)
776 } else {
777 logger.Debugw(ctx, "MibUploadNextResponse AdditionalData for:", log.Fields{"device-id": oo.deviceID, "meName": meName, "meEntityID": meEntityID, "attributes": attributes})
778 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributes)
779 }
780 }
781 }
mpagenko7033f4e2021-11-19 18:04:22 +0000782 } else {
783 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
784 //as long as omci-lib does not support decoding of table attribute as 'unknown/unspecified' attribute
785 // we have to verify, if this failure is from table attribute and try to go forward with ignoring the complete message
786 errLayer := (*msg.OmciPacket).Layer(gopacket.LayerTypeDecodeFailure)
787 if failure, decodeOk := errLayer.(*gopacket.DecodeFailure); decodeOk {
788 errMsg := failure.String()
789 if !strings.Contains(strings.ToLower(errMsg), "table decode") {
790 //something still unexected happened, needs deeper investigation - stop complete MIB upload process (timeout)
791 return
792 }
793 logger.Warnw(ctx, "Decode issue on received MibUploadNextResponse frame - found table attribute(s) (message ignored)",
794 log.Fields{"device-id": oo.deviceID, "issue": errMsg})
795 }
Himani Chawla4d908332020-08-31 12:30:20 +0530796 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000797 if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds {
Holger Hildebrandt5458d892022-05-31 09:52:06 +0000798 _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx),
799 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.GetPersIsExtOmciSupported())
mpagenko01499812021-03-25 10:37:12 +0000800 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
801 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000802 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000803 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000804 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530805 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000806 oo.pOnuDB.LogMeDb(ctx)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000807 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530808 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000809 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 +0530810 }
811
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +0530812 oo.updateOnuSpecificEntries(ctx)
813 logger.Errorw(ctx, "MibSync - Updtaed the ONU Specific MEs ", log.Fields{"device-id": oo.deviceID})
814
815 cmnMEDB, _ := oo.pOpenOnuAc.FetchEntryFromMibDatabaseMap(ctx, oo.mibTemplatePath)
816 cmnMEDB.MIBUploadStatus = devdb.Completed
817 oo.pOnuDB.CommonMeDb.MeDbLock.Unlock()
818 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, true)
819 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
820
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000821 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530822 }
823}
824
Girish Gowdra21bbf052022-02-17 16:08:22 -0800825// nolint: gocyclo
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000826func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg cmn.OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000827 var err error = nil
mpagenko01499812021-03-25 10:37:12 +0000828
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000829 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000830 if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType ||
831 oo.lastTxParamStruct.pLastTxMeInstance == nil {
832 //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest
833 // with Sequence number 0x8000 as last request before - so it may still respond to that
834 // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number
835 if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
836 logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000837 _ = oo.PDevOmciCC.SendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000838 //TODO: needs extra handling of timeouts
839 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000840 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000841 return nil
842 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000843 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000844 logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
845 //perhaps some still lingering message from some prior activity, let's wait for the real response
846 return nil
847 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000848 oo.mutexLastTxParamStruct.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530849 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000850 if msgLayer == nil {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000851 logger.Errorw(ctx, "omci Msg layer could not be detected for GetResponse - handling of MibSyncChan stopped",
852 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000853 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000854 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 +0000855 }
856 msgObj, msgOk := msgLayer.(*omci.GetResponse)
857 if !msgOk {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000858 logger.Errorw(ctx, "omci Msg layer could not be assigned for GetResponse - handling of MibSyncChan stopped",
859 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000860 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000861 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 +0000862 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000863 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000864 if msgObj.Result == me.Success {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000865 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000866 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
867 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000868 meAttributes := msgObj.Attributes
mpagenko01499812021-03-25 10:37:12 +0000869 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000870 logger.Debugf(ctx, "MibSync FSM - GetResponse Data for %s",
871 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000872 switch meInstance {
873 case "OnuG":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000874 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000875 return oo.handleOmciGetResponseOnuG(ctx, meAttributes)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000876 case "Onu2G":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000877 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000878 var equipmentID string
879 if onu2GEquipmentID, ok := meAttributes[me.Onu2G_EquipmentId]; ok {
880 equipmentID = cmn.TrimStringFromMeOctet(onu2GEquipmentID)
881 if equipmentID == "" {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000882 logger.Infow(ctx,
883 "MibSync FSM - optional attribute EquipmentID is empty in Onu2G instance - fill with appropriate value",
884 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000885 equipmentID = cEmptyEquipIDString
886 }
887 } else {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000888 logger.Infow(ctx,
889 "MibSync FSM - optional attribute EquipmentID not present in Onu2G instance - fill with appropriate value",
890 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000891 equipmentID = cNotPresentEquipIDString
892 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000893 oo.MutexPersOnuConfig.Lock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000894 oo.SOnuPersistentData.PersEquipmentID = equipmentID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000895 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000896 "onuDeviceEntry.equipmentID": oo.SOnuPersistentData.PersEquipmentID})
897 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000898
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000899 var omccVersion uint8
900 if onu2GOmccVersion, ok := meAttributes[me.Onu2G_OpticalNetworkUnitManagementAndControlChannelOmccVersion]; ok {
901 oo.MutexPersOnuConfig.Lock()
902 omccVersion = onu2GOmccVersion.(uint8)
903 if _, ok := omccVersionSupportsExtendedOmciFormat[omccVersion]; ok {
904 oo.SOnuPersistentData.PersIsExtOmciSupported = omccVersionSupportsExtendedOmciFormat[omccVersion]
Holger Hildebrandtc572e622022-06-22 09:19:17 +0000905 if oo.SOnuPersistentData.PersIsExtOmciSupported && !oo.baseDeviceHandler.GetExtendedOmciSupportEnabled() {
906 logger.Infow(ctx, "MibSync FSM - ONU supports extended OMCI, but support is disabled in the adapter: reset flag",
907 log.Fields{"device-id": oo.deviceID})
908 oo.SOnuPersistentData.PersIsExtOmciSupported = false
909 }
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000910 } else {
911 logger.Infow(ctx, "MibSync FSM - unknown OMCC version in Onu2G instance - disable extended OMCI support",
912 log.Fields{"device-id": oo.deviceID})
913 oo.SOnuPersistentData.PersIsExtOmciSupported = false
914 }
915 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - OMCC version", log.Fields{"device-id": oo.deviceID,
916 "omccVersion": omccVersion, "isExtOmciSupported": oo.SOnuPersistentData.PersIsExtOmciSupported})
917 oo.MutexPersOnuConfig.Unlock()
918 } else {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000919 logger.Errorw(ctx,
920 "MibSync FSM - mandatory attribute OMCC version not present in Onu2G instance - handling of MibSyncChan stopped!",
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000921 log.Fields{"device-id": oo.deviceID})
922 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000923 return fmt.Errorf(
924 "mibSync FSM - mandatory attribute OMCC version not present in Onu2G instance - handling of MibSyncChan stopped: %s",
925 oo.deviceID)
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000926 }
927 oo.MutexPersOnuConfig.RLock()
928 if oo.SOnuPersistentData.PersIsExtOmciSupported {
929 oo.MutexPersOnuConfig.RUnlock()
930 // trigger test of OMCI extended msg format
931 _ = oo.PMibUploadFsm.PFsm.Event(UlEvTestExtOmciSupport)
932 return nil
933 }
934 oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000935 // trigger retrieval of 1st SW-image info
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000936 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000937 return nil
938 case "SoftwareImage":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000939 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000940 if entityID > cmn.SecondSwImageMeID {
mpagenko15ff4a52021-03-02 10:09:20 +0000941 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
942 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
943 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
944 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000945 }
mpagenko15ff4a52021-03-02 10:09:20 +0000946 // need to use function for go lint complexity
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000947 if !oo.HandleSwImageIndications(ctx, entityID, meAttributes) {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000948 logger.Errorw(ctx,
949 "MibSync FSM - Not all mandatory attributes present in in SoftwareImage instance - handling of MibSyncChan stopped!",
950 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000951 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000952 return fmt.Errorf(
953 "mibSync FSM - Not all mandatory attributes present in in SoftwareImage instance - handling of MibSyncChan stopped: %s",
954 oo.deviceID)
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000955 }
mpagenko15ff4a52021-03-02 10:09:20 +0000956 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000957 case "IpHostConfigData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000958 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000959 oo.MutexPersOnuConfig.Lock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000960 if ipHostConfigMacAddress, ok := meAttributes[me.IpHostConfigData_MacAddress]; ok {
Girish Gowdra21bbf052022-02-17 16:08:22 -0800961 macBytes, _ := me.InterfaceToOctets(ipHostConfigMacAddress)
962 if cmn.OmciMacAddressLen == len(macBytes) {
963 oo.SOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:])
964 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
965 "macAddress": oo.SOnuPersistentData.PersMacAddress})
966 } else {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000967 logger.Infow(ctx, "MibSync FSM - MacAddress wrong length - fill macAddress with zeros",
968 log.Fields{"device-id": oo.deviceID, "length": len(macBytes)})
Girish Gowdra21bbf052022-02-17 16:08:22 -0800969 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
970 }
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000971 } else {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000972 // since ONU creates instances of this ME automatically only when IP host services are available,
973 // processing continues here despite the error
974 logger.Infow(ctx, "MibSync FSM - MacAddress attribute not present in IpHostConfigData instance - fill macAddress with zeros",
975 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000976 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000977 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000978 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000979 // trigger retrieval of mib template
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000980 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000981 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000982 case "OnuData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000983 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000984 if onuDataMibDataSync, ok := meAttributes[me.OnuData_MibDataSync]; ok {
985 oo.checkMdsValue(ctx, onuDataMibDataSync.(uint8))
986 } else {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000987 logger.Errorw(ctx, "MibSync FSM - MibDataSync attribute not present in OnuData instance - handling of MibSyncChan stopped!",
988 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000989 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000990 return fmt.Errorf("mibSync FSM - VendorId attribute not present in OnuG instance - handling of MibSyncChan stopped: %s",
991 oo.deviceID)
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000992 }
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000993 return nil
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000994 default:
995 oo.mutexLastTxParamStruct.RUnlock()
996 logger.Warnw(ctx, "Unsupported ME name received!",
997 log.Fields{"ME name": meInstance, "device-id": oo.deviceID})
998
Himani Chawla4d908332020-08-31 12:30:20 +0530999 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -08001000 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001001 oo.mutexLastTxParamStruct.RUnlock()
1002 logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ",
1003 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001004 }
Himani Chawla4d908332020-08-31 12:30:20 +05301005 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001006 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +00001007 return nil
1008 }
Himani Chawla4d908332020-08-31 12:30:20 +05301009 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001010 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001011 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001012 return err
Himani Chawla4d908332020-08-31 12:30:20 +05301013}
1014
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301015// HandleSwImageIndications updates onuSwImageIndications with the ONU data just received
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +00001016func (oo *OnuDeviceEntry) HandleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) bool {
1017
1018 var imageVersion string
1019 var imageIsCommitted, imageIsActive uint8
1020
1021 allMandAttribsPresent := false
1022 if softwareImageIsCommitted, ok := meAttributes[me.SoftwareImage_IsCommitted]; ok {
1023 if softwareImageIsActiveimage, ok := meAttributes[me.SoftwareImage_IsActive]; ok {
1024 if softwareImageVersion, ok := meAttributes[me.SoftwareImage_Version]; ok {
1025 imageVersion = cmn.TrimStringFromMeOctet(softwareImageVersion)
1026 imageIsActive = softwareImageIsActiveimage.(uint8)
1027 imageIsCommitted = softwareImageIsCommitted.(uint8)
1028 allMandAttribsPresent = true
1029 }
1030 }
1031 }
1032 if !allMandAttribsPresent {
1033 logger.Errorw(ctx, "MibSync FSM - Not all mandatory attributes present in SoftwareImage instance - skip processing!", log.Fields{"device-id": oo.deviceID})
1034 return allMandAttribsPresent
1035 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001036 oo.MutexPersOnuConfig.RLock()
mpagenko15ff4a52021-03-02 10:09:20 +00001037 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
1038 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001039 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.SOnuPersistentData.PersSerialNumber})
1040 oo.MutexPersOnuConfig.RUnlock()
1041 if cmn.FirstSwImageMeID == entityID {
mpagenko15ff4a52021-03-02 10:09:20 +00001042 //always accept the state of the first image (2nd image info should not yet be available)
Holger Hildebrandt05011352021-06-15 09:40:24 +00001043 oo.mutexOnuSwImageIndications.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001044 if imageIsActive == cmn.SwIsActive {
1045 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID
1046 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true
1047 oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion
1048 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +00001049 //as the SW version indication may stem from some ONU Down/up event
1050 //the complementary image state is to be invalidated
1051 // (state of the second image is always expected afterwards or just invalid)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001052 oo.onuSwImageIndications.InActiveEntityEntry.Valid = false
mpagenko15ff4a52021-03-02 10:09:20 +00001053 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001054 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
1055 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true
1056 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
1057 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +00001058 //as the SW version indication may stem form some ONU Down/up event
1059 //the complementary image state is to be invalidated
1060 // (state of the second image is always expected afterwards or just invalid)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001061 oo.onuSwImageIndications.ActiveEntityEntry.Valid = false
mpagenko15ff4a52021-03-02 10:09:20 +00001062 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001063 oo.mutexOnuSwImageIndications.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001064 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetSecondSwVersion)
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +00001065 return allMandAttribsPresent
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001066 } else if cmn.SecondSwImageMeID == entityID {
mpagenko15ff4a52021-03-02 10:09:20 +00001067 //2nd image info might conflict with first image info, in which case we priorize first image info!
Holger Hildebrandt05011352021-06-15 09:40:24 +00001068 oo.mutexOnuSwImageIndications.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001069 if imageIsActive == cmn.SwIsActive { //2nd image reported to be active
1070 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
mpagenko15ff4a52021-03-02 10:09:20 +00001071 //conflict exists - state of first image is left active
1072 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
1073 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001074 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
1075 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true ////to indicate that at least something has been reported
1076 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
1077 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +00001078 } else { //first image inactive, this one active
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001079 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID
1080 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true
1081 oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion
1082 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +00001083 }
1084 } else { //2nd image reported to be inactive
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001085 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
mpagenko15ff4a52021-03-02 10:09:20 +00001086 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
1087 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
1088 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001089 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = cmn.FirstSwImageMeID
1090 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true //to indicate that at least something has been reported
mpagenko15ff4a52021-03-02 10:09:20 +00001091 //copy active commit/version from the previously stored inactive position
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001092 oo.onuSwImageIndications.ActiveEntityEntry.Version = oo.onuSwImageIndications.InActiveEntityEntry.Version
1093 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +00001094 }
1095 //in any case we indicate (and possibly overwrite) the second image indications as inactive
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001096 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
1097 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true
1098 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
1099 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +00001100 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001101 oo.mutexOnuSwImageIndications.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001102 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMacAddress)
mpagenko15ff4a52021-03-02 10:09:20 +00001103 }
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +00001104 return allMandAttribsPresent
mpagenko15ff4a52021-03-02 10:09:20 +00001105}
1106
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001107func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001108 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +02001109 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001110 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
1111 switch msg.OmciMsg.MessageType {
1112 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +00001113 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001114
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001115 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +00001116 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +05301117
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001118 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +00001119 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001120
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001121 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001122 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +00001123 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +05301124
Andrea Campanella6515c582020-10-05 11:25:00 +02001125 default:
Holger Hildebrandtabfef032022-02-25 12:40:20 +00001126 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"device-id": oo.deviceID, "msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +02001127
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001128 }
1129}
1130
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +00001131func (oo *OnuDeviceEntry) handleOmciGetResponseOnuG(ctx context.Context, meAttributes me.AttributeValueMap) error {
1132 currentState := oo.PMibUploadFsm.PFsm.Current()
1133 if currentState == UlStGettingVendorAndSerial {
1134 if onuGVendorID, ok := meAttributes[me.OnuG_VendorId]; ok {
1135 vendorID := cmn.TrimStringFromMeOctet(onuGVendorID)
1136 if vendorID == "" {
1137 logger.Infow(ctx,
1138 "MibSync FSM - mandatory attribute VendorId is empty in OnuG instance - fill with appropriate value",
1139 log.Fields{"device-id": oo.deviceID})
1140 vendorID = cEmptyVendorIDString
1141 }
1142 oo.MutexPersOnuConfig.Lock()
1143 oo.SOnuPersistentData.PersVendorID = vendorID
1144 oo.MutexPersOnuConfig.Unlock()
1145 } else {
1146 logger.Errorw(ctx,
1147 "MibSync FSM - mandatory attribute VendorId not present in OnuG instance - handling of MibSyncChan stopped!",
1148 log.Fields{"device-id": oo.deviceID})
1149 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
1150 return fmt.Errorf(
1151 "mibSync FSM - mandatory attribute VendorId not present in OnuG instance - handling of MibSyncChan stopped: %s",
1152 oo.deviceID)
1153 }
1154 if onuGSerialNumber, ok := meAttributes[me.OnuG_SerialNumber]; ok {
1155 oo.MutexPersOnuConfig.Lock()
1156 snBytes, _ := me.InterfaceToOctets(onuGSerialNumber)
1157 if cmn.OnugSerialNumberLen == len(snBytes) {
1158 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
1159 snNumberPart := hex.EncodeToString(snBytes[4:])
1160 oo.SOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart
1161 } else {
1162 logger.Infow(ctx, "MibSync FSM - SerialNumber has wrong length - fill serialNumber with zeros",
1163 log.Fields{"device-id": oo.deviceID, "length": len(snBytes)})
1164 oo.SOnuPersistentData.PersSerialNumber = cEmptySerialNumberString
1165 }
1166 oo.MutexPersOnuConfig.Unlock()
1167 } else {
1168 logger.Errorw(ctx,
1169 "MibSync FSM - mandatory attribute SerialNumber not present in OnuG instance - handling of MibSyncChan stopped!",
1170 log.Fields{"device-id": oo.deviceID})
1171 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
1172 return fmt.Errorf(
1173 "mibSync FSM - mandatory attribute SerialNumber not present in OnuG instance - handling of MibSyncChan stopped: %s",
1174 oo.deviceID)
1175 }
1176 oo.MutexPersOnuConfig.Lock()
1177 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-G - VendorId/SerialNumber", log.Fields{"device-id": oo.deviceID,
1178 "onuDeviceEntry.vendorID": oo.SOnuPersistentData.PersVendorID,
1179 "onuDeviceEntry.serialNumber": oo.SOnuPersistentData.PersSerialNumber})
1180 oo.MutexPersOnuConfig.Unlock()
1181 // trigger retrieval of Version
1182 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetVersion)
1183 return nil
1184 } else if currentState == UlStGettingVersion {
1185 if onuGVersion, ok := meAttributes[me.OnuG_Version]; ok {
1186 version := cmn.TrimStringFromMeOctet(onuGVersion)
1187 if version == "" {
1188 logger.Infow(ctx, "MibSync FSM - mandatory attribute Version is empty in OnuG instance - fill with appropriate value",
1189 log.Fields{"device-id": oo.deviceID})
1190 version = cEmptyVersionString
1191 }
1192 oo.MutexPersOnuConfig.Lock()
1193 oo.SOnuPersistentData.PersVersion = version
1194 oo.MutexPersOnuConfig.Unlock()
1195 } else {
1196 logger.Errorw(ctx,
1197 "MibSync FSM - mandatory attribute Version not present in OnuG instance - handling of MibSyncChan stopped!",
1198 log.Fields{"device-id": oo.deviceID})
1199 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
1200 return fmt.Errorf(
1201 "mibSync FSM - mandatory attribute Version not present in OnuG instance - handling of MibSyncChan stopped: %s",
1202 oo.deviceID)
1203 }
1204 oo.MutexPersOnuConfig.Lock()
1205 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-G - Version", log.Fields{"device-id": oo.deviceID,
1206 "onuDeviceEntry.version": oo.SOnuPersistentData.PersVersion})
1207 oo.MutexPersOnuConfig.Unlock()
1208 // trigger retrieval of EquipmentId and OMCC version
1209 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetEquipIDAndOmcc)
1210 return nil
1211 } else {
1212 logger.Errorw(ctx, "MibSync FSM - wrong state OnuG response processing - handling of MibSyncChan stopped!",
1213 log.Fields{"currentState": currentState, "device-id": oo.deviceID})
1214 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
1215 return fmt.Errorf("mibSync FSM - wrong state OnuG response processing - handling of MibSyncChan stopped: %s",
1216 oo.deviceID)
1217 }
1218}
1219
dbainbri4d3a0dc2020-12-02 00:33:42 +00001220func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +00001221 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +00001222 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 +00001223 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
1224 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001225 oo.mutexLastTxParamStruct.RLock()
1226 if oo.lastTxParamStruct.pLastTxMeInstance != nil {
1227 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
1228 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
1229 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
1230 switch meInstance {
1231 case "IpHostConfigData":
1232 oo.mutexLastTxParamStruct.RUnlock()
1233 logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros",
1234 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001235 oo.MutexPersOnuConfig.Lock()
1236 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
1237 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001238 // trigger retrieval of mib template
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001239 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001240 return nil
1241 default:
1242 oo.mutexLastTxParamStruct.RUnlock()
1243 logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
1244 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
1245 }
1246 } else {
1247 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt80129db2020-11-23 10:49:32 +00001248 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001249 } else {
1250 oo.mutexLastTxParamStruct.RUnlock()
1251 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt80129db2020-11-23 10:49:32 +00001252 }
1253 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001254 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 +00001255 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
1256 }
1257 return err
1258}
1259
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001260// IsNewOnu - TODO: add comment
1261func (oo *OnuDeviceEntry) IsNewOnu() bool {
1262 oo.MutexPersOnuConfig.RLock()
1263 defer oo.MutexPersOnuConfig.RUnlock()
1264 return oo.SOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +00001265}
1266
Himani Chawla6d2ae152020-09-02 13:11:20 +05301267func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001268 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +05301269 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001270 return true
1271 }
1272 }
1273 return false
1274}
1275
dbainbri4d3a0dc2020-12-02 00:33:42 +00001276func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
1277 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001278 return errors.New("not_implemented")
1279}
1280
Himani Chawla6d2ae152020-09-02 13:11:20 +05301281// 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 +05301282// 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 +00001283// 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 +00001284func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
1285 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001286 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +05301287
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301288 //Fetch the MEs dependent on serial number and MAC address and add them to onuSpecific ME DB
1289 //Modify the serial number and MAC address with generic content in the common DB.
1290 knownAttributeMEDb := oo.pOnuDB.CommonMeDb.MeDb
1291 for firstLevelKey, firstLevelValue := range knownAttributeMEDb {
1292 classID := strconv.Itoa(int(firstLevelKey))
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001293
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301294 for secondLevelKey, secondLevelValue := range firstLevelValue {
1295 switch classID {
1296 case "6", "256":
1297 if _, exists := secondLevelValue["SerialNumber"]; exists {
1298 oo.pOnuDB.PutOnuSpeficMe(ctx, firstLevelKey, secondLevelKey, secondLevelValue)
1299 secondLevelValue["SerialNumber"] = "%SERIAL_NUMBER%"
1300 }
1301 case "134":
1302 if _, exists := secondLevelValue["MacAddress"]; exists {
1303 oo.pOnuDB.PutOnuSpeficMe(ctx, firstLevelKey, secondLevelKey, secondLevelValue)
1304 secondLevelValue["MacAddress"] = "%MAC_ADDRESS%"
1305 }
1306 }
1307 }
1308 }
1309
1310 //Create the MIB Template
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001311 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +05301312 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001313 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +05301314 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
1315
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301316 firstLevelMap := oo.pOnuDB.CommonMeDb.MeDb
divyadesaibbed37c2020-08-28 13:35:20 +05301317 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001318 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +05301319 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +05301320
1321 secondLevelMap := make(map[string]interface{})
1322 for secondLevelKey, secondLevelValue := range firstLevelValue {
Holger Hildebrandt8998ed52022-03-23 09:52:37 +00001323 // ManagedEntityId is already key of secondLevelMap - remove this redundant attribute from secondLevelValue
1324 delete(secondLevelValue, cmn.CGenericManagedEntityIDName)
divyadesaibbed37c2020-08-28 13:35:20 +05301325 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +05301326 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +05301327 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +05301328 secondLevelMap[entityID] = thirdLevelMap
1329 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +05301330 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
1331 delete(forthLevelMap, "SerialNumber")
1332 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
1333
1334 }
Himani Chawla26e555c2020-08-31 12:30:20 +05301335 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +05301336 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
1337 delete(forthLevelMap, "MacAddress")
1338 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
1339 }
1340 }
Himani Chawla26e555c2020-08-31 12:30:20 +05301341 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +05301342 }
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301343 unknownMeAndAttribMap := oo.pOnuDB.CommonMeDb.UnknownMeAndAttribDb
Holger Hildebrandt39080022022-03-16 10:03:17 +00001344 for unknownMeAndAttribMapKey := range unknownMeAndAttribMap {
1345 templateMap[string(unknownMeAndAttribMapKey)] = unknownMeAndAttribMap[unknownMeAndAttribMapKey]
Holger Hildebrandtf3c7a182021-11-17 13:42:08 +00001346 }
divyadesaibbed37c2020-08-28 13:35:20 +05301347 mibTemplate, err := json.Marshal(&templateMap)
1348 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001349 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001350 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
divyadesaibbed37c2020-08-28 13:35:20 +05301351 return err
1352 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001353 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +05301354 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001355 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to store template in etcd", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001356 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
divyadesaibbed37c2020-08-28 13:35:20 +05301357 return err
1358 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001359 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +05301360 return nil
1361}
1362
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +00001363func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
1364 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001365 requestedAttributes := me.AttributeValueMap{me.OnuData_MibDataSync: ""}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001366 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
Holger Hildebrandtd930cb22022-06-17 09:24:50 +00001367 me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true,
1368 oo.PMibUploadFsm.CommChan, oo.GetPersIsExtOmciSupported())
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +00001369 //accept also nil as (error) return value for writing to LastTx
1370 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +03001371 if err != nil {
1372 logger.Errorw(ctx, "ONUData get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001373 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001374 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001375 go func(a_pAFsm *cmn.AdapterFsm) {
1376 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001377 }(pMibUlFsm)
1378 }
1379 return
1380 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001381 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +00001382 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
1383 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
1384 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001385 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +00001386}
1387
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001388func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001389 oo.MutexPersOnuConfig.RLock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001390 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001391 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.SOnuPersistentData.PersMibDataSyncAdpt})
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001392
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001393 mdsValuesAreEqual := oo.SOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
1394 oo.MutexPersOnuConfig.RUnlock()
1395 if oo.PMibUploadFsm.PFsm.Is(UlStAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001396 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001397 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001398 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001399 } else {
1400 logger.Warnw(ctx, "MibSync FSM - mib audit - MDS check failed for the first time!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001401 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001402 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001403 } else if oo.PMibUploadFsm.PFsm.Is(UlStReAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001404 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001405 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001406 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001407 } else {
Holger Hildebrandt80f57762022-02-16 10:03:24 +00001408 logger.Errorw(ctx, "MibSync FSM - mib reaudit - MDS check failed for the second time - send ONU device event and reconcile!",
Holger Hildebrandtc56febd2022-02-09 13:23:30 +00001409 log.Fields{"device-id": oo.deviceID})
1410 oo.SendOnuDeviceEvent(ctx, cmn.OnuMibAuditFailureMds, cmn.OnuMibAuditFailureMdsDesc)
Holger Hildebrandt80f57762022-02-16 10:03:24 +00001411 // To reconcile ONU with active adapter later on, we have to retrieve TP instances from parent adapter.
1412 // In the present use case inconsistencies between TP pathes stored in kv store and TP instances retrieved
1413 // should not occur. Nevertheless, the respective code is inserted to catch the unlikely case.
1414 if !oo.getAllStoredTpInstFromParentAdapter(ctx) {
1415 logger.Debugw(ctx, "MibSync FSM - mib reaudit - inconsistencies between TP pathes stored in kv and parent adapter instances",
1416 log.Fields{"device-id": oo.deviceID})
1417 oo.baseDeviceHandler.SetReconcilingReasonUpdate(true)
1418 go func() {
1419 if err := oo.baseDeviceHandler.StorePersistentData(ctx); err != nil {
1420 logger.Warnw(ctx,
1421 "MibSync FSM - mib reaudit - store persistent data error - continue for now as there will be additional write attempts",
1422 log.Fields{"device-id": oo.deviceID, "err": err})
1423 }
1424 }()
1425 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001426 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001427 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001428 } else if oo.PMibUploadFsm.PFsm.Is(UlStExaminingMds) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001429 if mdsValuesAreEqual && mibDataSyncOnu != 0 {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001430 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001431 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001432 } else {
1433 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001434 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001435 }
1436 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001437 logger.Warnw(ctx, "wrong state for MDS evaluation!", log.Fields{"state": oo.PMibUploadFsm.PFsm.Current(), "device-id": oo.deviceID})
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001438 }
1439}
mpagenko15ff4a52021-03-02 10:09:20 +00001440
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301441// GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
mpagenko15ff4a52021-03-02 10:09:20 +00001442func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001443 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001444 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
1445 value := oo.onuSwImageIndications.ActiveEntityEntry.EntityID
Holger Hildebrandt05011352021-06-15 09:40:24 +00001446 oo.mutexOnuSwImageIndications.RUnlock()
1447 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +00001448 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001449 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001450 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
1451}
1452
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301453// GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
mpagenko15ff4a52021-03-02 10:09:20 +00001454func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001455 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001456 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
1457 value := oo.onuSwImageIndications.InActiveEntityEntry.EntityID
Holger Hildebrandt05011352021-06-15 09:40:24 +00001458 oo.mutexOnuSwImageIndications.RUnlock()
1459 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +00001460 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001461 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001462 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
1463}
1464
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301465// IsImageToBeCommitted returns true if the active image is still uncommitted
mpagenko15ff4a52021-03-02 10:09:20 +00001466func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001467 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001468 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
1469 if oo.onuSwImageIndications.ActiveEntityEntry.EntityID == aImageID {
1470 if oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted == cmn.SwIsUncommitted {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001471 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001472 return true
1473 }
1474 }
1475 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001476 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001477 return false //all other case are treated as 'nothing to commit
1478}
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001479func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool {
1480
1481 oo.mibTemplatePath = oo.buildMibTemplatePath()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +00001482 logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath),
1483 "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001484
1485 restoredFromMibTemplate := false
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301486 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
1487 defer oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
1488 if meDbValue, ok := oo.pOpenOnuAc.FetchEntryFromMibDatabaseMap(ctx, oo.mibTemplatePath); ok {
1489 logger.Infow(ctx, "Found MIB common DB Instance , copy and use", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1490 oo.pOnuDB.CommonMeDb = meDbValue
1491 oo.updateOnuSpecificEntries(ctx)
1492 restoredFromMibTemplate = true
1493 } else {
1494 //Create a common ME MIB Instance as it doesn't prior exists.
1495 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
1496 //Unmarshal the MIB template and create the entry in the ONU Common Device DB
1497 if err == nil {
1498 if Value != nil {
1499 oo.processMibTemplate(ctx, Value)
1500 restoredFromMibTemplate = true
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001501 } else {
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301502 logger.Infow(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001503 }
1504 } else {
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301505 logger.Errorw(ctx, "Get from kvstore operation failed for path",
1506 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001507 }
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301508
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001509 }
1510 return restoredFromMibTemplate
1511}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001512
Holger Hildebrandt80f57762022-02-16 10:03:24 +00001513func (oo *OnuDeviceEntry) getAllStoredTpInstFromParentAdapter(ctx context.Context) bool {
1514
1515 allTpInstPresent := true
1516 oo.MutexPersOnuConfig.Lock()
1517 oo.MutexReconciledTpInstances.Lock()
1518 for indexUni, uniData := range oo.SOnuPersistentData.PersUniConfig {
1519 uniID := uniData.PersUniID
1520 oo.ReconciledTpInstances[uniID] = make(map[uint8]inter_adapter.TechProfileDownloadMessage)
1521 for tpID, tpPath := range uniData.PersTpPathMap {
1522 if tpPath != "" {
1523 // Request the TP instance from the openolt adapter
1524 iaTechTpInst, err := oo.baseDeviceHandler.GetTechProfileInstanceFromParentAdapter(ctx, uniID, tpPath)
1525 if err == nil && iaTechTpInst != nil {
1526 logger.Debugw(ctx, "reconciling - store Tp instance", log.Fields{"uniID": uniID, "tpID": tpID,
1527 "*iaTechTpInst": iaTechTpInst, "device-id": oo.deviceID})
1528 oo.ReconciledTpInstances[uniID][tpID] = *iaTechTpInst
1529 } else {
1530 // During the absence of the ONU adapter there seem to have been TP specific configurations!
1531 // The no longer available TP and the associated flows must be deleted from the ONU KV store
1532 // and after a MIB reset a new reconciling attempt with OMCI configuration must be started.
1533 allTpInstPresent = false
1534 logger.Infow(ctx, "reconciling - can't get tp instance - delete tp and associated flows",
1535 log.Fields{"tp-id": tpID, "tpPath": tpPath, "uni-id": uniID, "device-id": oo.deviceID, "err": err})
1536 delete(oo.SOnuPersistentData.PersUniConfig[indexUni].PersTpPathMap, tpID)
1537 flowSlice := oo.SOnuPersistentData.PersUniConfig[indexUni].PersFlowParams
1538 for indexFlow, flowData := range flowSlice {
1539 if flowData.VlanRuleParams.TpID == tpID {
1540 if len(flowSlice) == 1 {
1541 flowSlice = []cmn.UniVlanFlowParams{}
1542 } else {
1543 flowSlice = append(flowSlice[:indexFlow], flowSlice[indexFlow+1:]...)
1544 }
1545 oo.SOnuPersistentData.PersUniConfig[indexUni].PersFlowParams = flowSlice
1546 }
1547 }
1548 }
1549 }
1550 }
1551 }
1552 oo.MutexReconciledTpInstances.Unlock()
1553 oo.MutexPersOnuConfig.Unlock()
1554 return allTpInstPresent
1555}
1556
nikesh.krishnan1ffb8132023-05-23 03:44:13 +05301557// CancelProcessing terminates potentially running reconciling processes and stops the FSM
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001558func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) {
Holger Hildebrandt12609a12022-03-25 13:23:25 +00001559 logger.Debugw(ctx, "CancelProcessing entered", log.Fields{"device-id": oo.deviceID})
mpagenko101ac942021-11-16 15:01:29 +00001560 if oo.isReconcilingFlows() {
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +00001561 oo.SendChReconcilingFlowsFinished(ctx, false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001562 }
1563 //the MibSync FSM might be active all the ONU-active time,
1564 // hence it must be stopped unconditionally
Girish Gowdra37c9d912022-02-08 16:24:57 -08001565 oo.mutexMibSyncMsgProcessorRunning.RLock()
1566 defer oo.mutexMibSyncMsgProcessorRunning.RUnlock()
1567 if oo.mibSyncMsgProcessorRunning {
1568 pMibUlFsm := oo.PMibUploadFsm
1569 if pMibUlFsm != nil {
1570 // abort running message processing
1571 fsmAbortMsg := cmn.Message{
1572 Type: cmn.TestMsg,
1573 Data: cmn.TestMessage{
1574 TestMessageVal: cmn.AbortMessageProcessing,
1575 },
1576 }
1577 pMibUlFsm.CommChan <- fsmAbortMsg
1578 _ = pMibUlFsm.PFsm.Event(UlEvStop)
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001579 }
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001580 }
1581}
Praneeth Kumar Nalmas8f8f0c02024-10-22 19:29:09 +05301582
1583// Updates Serial Number and MAC Address in the database
1584func (oo *OnuDeviceEntry) updateOnuSpecificEntries(ctx context.Context) {
1585 knownAttributeMEDb := oo.pOnuDB.CommonMeDb.MeDb
1586
1587 for firstLevelKey, firstLevelValue := range knownAttributeMEDb {
1588 classID := strconv.Itoa(int(firstLevelKey))
1589
1590 for secondLevelKey, secondLevelValue := range firstLevelValue {
1591 switch classID {
1592 case "6", "256":
1593 oo.updateAttribute(ctx, "SerialNumber", secondLevelValue, firstLevelKey, secondLevelKey, oo.SOnuPersistentData.PersSerialNumber)
1594 case "134":
1595 oo.updateAttribute(ctx, "MacAddress", secondLevelValue, firstLevelKey, secondLevelKey, oo.SOnuPersistentData.PersMacAddress)
1596 }
1597 }
1598 }
1599}
1600
1601// Updates a specific attribute in the MIB database
1602func (oo *OnuDeviceEntry) updateAttribute(ctx context.Context, attributeName string, attributesMap me.AttributeValueMap, classID me.ClassID, entityID uint16, newValue interface{}) {
1603 if _, exists := attributesMap[attributeName]; exists {
1604 logger.Infow(ctx, "Updating "+attributeName, log.Fields{"classID": strconv.Itoa(int(classID)), "oldValue": attributesMap[attributeName], "newValue": newValue})
1605 attributeCopy := make(me.AttributeValueMap)
1606 for k, v := range attributesMap {
1607 attributeCopy[k] = v
1608 }
1609 attributeCopy[attributeName] = newValue
1610 oo.pOnuDB.PutOnuSpeficMe(ctx, classID, entityID, attributeCopy)
1611 } else {
1612 logger.Warnw(ctx, attributeName+" key not found", log.Fields{"classID": strconv.Itoa(int(classID))})
1613 }
1614}
1615
1616// Processes the MIB template by replacing tokens and unmarshaling it
1617func (oo *OnuDeviceEntry) processMibTemplate(ctx context.Context, value *kvstore.KVPair) {
1618 mibTmpString, _ := kvstore.ToString(value.Value)
1619 mibTmpString2 := strings.ReplaceAll(mibTmpString, "\x00", "")
1620 mibTmpBytes := []byte(mibTmpString2)
1621
1622 logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes)
1623
1624 var firstLevelMap map[string]interface{}
1625 if err := json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
1626 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
1627 return
1628 }
1629
1630 cmnMEDbValue, _ := oo.pOpenOnuAc.CreateEntryAtMibDatabaseMap(ctx, oo.mibTemplatePath)
1631 oo.populateMibDatabase(ctx, cmnMEDbValue, firstLevelMap)
1632 cmnMEDbValue.MIBUploadStatus = devdb.Completed
1633 oo.pOnuDB.CommonMeDb = cmnMEDbValue
1634}
1635
1636// Populates the MIB database with parsed data
1637func (oo *OnuDeviceEntry) populateMibDatabase(ctx context.Context, cmnMEDbValue *devdb.OnuCmnMEDB, firstLevelMap map[string]interface{}) {
1638 cmnMEDbValue.MeDbLock.Lock()
1639 defer cmnMEDbValue.MeDbLock.Unlock()
1640
1641 logger.Infow(ctx, "Populating MIbDatabase with the template information ", log.Fields{"device-id": oo.deviceID})
1642 for firstLevelKey, firstLevelValue := range firstLevelMap {
1643 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
1644 meClassID := me.ClassID(uint16ValidNumber)
1645 if isSupportedClassID(meClassID) {
1646 secondLevelMap := firstLevelValue.(map[string]interface{})
1647 for secondLevelKey, secondLevelValue := range secondLevelMap {
1648 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
1649 meEntityID := uint16(uint16ValidNumber)
1650 thirdLevelMap := secondLevelValue.(map[string]interface{})
1651 if attributes, exists := thirdLevelMap["Attributes"].(map[string]interface{}); exists {
1652 if _, found := cmnMEDbValue.MeDb[meClassID]; !found {
1653 cmnMEDbValue.MeDb[meClassID] = make(map[uint16]me.AttributeValueMap)
1654 }
1655 if _, found := cmnMEDbValue.MeDb[meClassID][meEntityID]; !found {
1656 cmnMEDbValue.MeDb[meClassID][meEntityID] = make(me.AttributeValueMap)
1657 }
1658 for attrKey, attrValue := range attributes {
1659 cmnMEDbValue.MeDb[meClassID][meEntityID][attrKey] = attrValue
1660 }
1661 }
1662
1663 }
1664 }
1665 }
1666 }
1667 }
1668}