blob: 4c937209f5d4faf77890bf1d8d90c66ccedb59f9 [file] [log] [blame]
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001/*
2 * Copyright 2020-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000017//Package mib provides the utilities for managing the onu mib
18package 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,
125 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000126 //accept also nil as (error) return value for writing to LastTx
127 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300128 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000129 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300130 logger.Errorw(ctx, "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,
149 requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
150 //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,
173 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
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,
229 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
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,
253 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
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,
277 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
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 Hildebrandtbe523842021-03-10 10:47:18 +0000309 if oo.getMibFromTemplate(ctx) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000310 logger.Debug(ctx, "MibSync FSM - valid MEs stored from template")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000311 oo.pOnuDB.LogMeDb(ctx)
312 fsmMsg = cmn.LoadMibTemplateOk
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000313 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000314 logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000315 fsmMsg = cmn.LoadMibTemplateFailed
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000316
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000317 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
318 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); exist {
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000319 if mibTemplateIsGenerated {
320 logger.Debugw(ctx,
321 "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map",
322 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000323 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000324 }
325 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000326 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000327 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000328 mibSyncMsg := cmn.Message{
329 Type: cmn.TestMsg,
330 Data: cmn.TestMessage{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000331 TestMessageVal: fsmMsg,
332 },
333 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000334 oo.PMibUploadFsm.CommChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000335}
336
dbainbri4d3a0dc2020-12-02 00:33:42 +0000337func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
338 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 +0000339 _ = oo.PDevOmciCC.SendMibUpload(log.WithSpanFromContext(context.TODO(), ctx),
340 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.GetPersIsExtOmciSupported())
mpagenko01499812021-03-25 10:37:12 +0000341 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
342 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000343 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000344 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000345 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000346}
347
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000348func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000349 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 +0000350 oo.transferSystemEvent(ctx, cmn.MibDatabaseSync)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000351 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000352 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000353 }()
354}
355
356func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000357 oo.MutexPersOnuConfig.Lock()
358 oo.SOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix())
359 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000360 if oo.mibAuditInterval > 0 {
361 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 +0000362 go func() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000363 time.Sleep(oo.mibAuditInterval)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000364 if err := oo.PMibUploadFsm.PFsm.Event(UlEvAuditMib); err != nil {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000365 logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err})
366 }
367 }()
368 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000369}
370
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000371func (oo *OnuDeviceEntry) enterVerifyingAndStoringTPsState(ctx context.Context, e *fsm.Event) {
372 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start verifying and storing TPs in State": e.FSM.Current(), "device-id": oo.deviceID})
373
Holger Hildebrandt80f57762022-02-16 10:03:24 +0000374 if oo.getAllStoredTpInstFromParentAdapter(ctx) {
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000375 logger.Debugw(ctx, "MibSync FSM", log.Fields{"reconciling - verifying TPs successful": e.FSM.Current(), "device-id": oo.deviceID})
376 go func() {
377 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
378 }()
379 } else {
380 logger.Debugw(ctx, "MibSync FSM", log.Fields{"reconciling - verifying TPs not successful": e.FSM.Current(), "device-id": oo.deviceID})
381 oo.baseDeviceHandler.SetReconcilingReasonUpdate(true)
382 go func() {
383 if err := oo.baseDeviceHandler.StorePersistentData(ctx); err != nil {
384 logger.Warnw(ctx, "reconciling - store persistent data error - continue for now as there will be additional write attempts",
385 log.Fields{"device-id": oo.deviceID, "err": err})
386 }
387 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
388 }()
389 }
390}
391
dbainbri4d3a0dc2020-12-02 00:33:42 +0000392func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
393 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start GetMds processing in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000394 oo.requestMdsValue(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000395}
396
dbainbri4d3a0dc2020-12-02 00:33:42 +0000397func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
398 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
399 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000400 // TODOs:
401 // VOL-3805 - Provide exclusive OMCI channel for one FSM
402 // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go
403 // VOL-3792 - Support periodical audit via mib resync
404 // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000405}
406
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000407func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) {
408 logger.Debugw(ctx, "MibSync FSM",
409 log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID})
410
411 if oo.getMibFromTemplate(ctx) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000412 oo.baseDeviceHandler.StartReconciling(ctx, true)
413 oo.baseDeviceHandler.AddAllUniPorts(ctx)
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000414 _ = oo.baseDeviceHandler.ReasonUpdate(ctx, cmn.DrInitialMibDownloaded, oo.baseDeviceHandler.IsReconcilingReasonUpdate())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000415 oo.baseDeviceHandler.SetReadyForOmciConfig(true)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000416
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000417 if !oo.baseDeviceHandler.GetCollectorIsRunning() {
Girish Gowdraf7d82d02022-04-26 16:18:35 -0700418 var waitForOmciProcess sync.WaitGroup
419 waitForOmciProcess.Add(1)
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000420 // Start PM collector routine
Girish Gowdraf7d82d02022-04-26 16:18:35 -0700421 go oo.baseDeviceHandler.StartCollector(ctx, &waitForOmciProcess)
422 waitForOmciProcess.Wait()
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000423 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000424 if !oo.baseDeviceHandler.GetAlarmManagerIsRunning(ctx) {
425 go oo.baseDeviceHandler.StartAlarmManager(ctx)
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000426 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700427
428 for _, uniPort := range *oo.baseDeviceHandler.GetUniEntityMap() {
429 // only if this port was enabled for use by the operator at startup
430 if (1<<uniPort.UniID)&oo.baseDeviceHandler.GetUniPortMask() == (1 << uniPort.UniID) {
431 if !oo.baseDeviceHandler.GetFlowMonitoringIsRunning(uniPort.UniID) {
432 go oo.baseDeviceHandler.PerOnuFlowHandlerRoutine(uniPort.UniID)
433 }
434 }
435 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000436 oo.MutexPersOnuConfig.RLock()
437 if oo.SOnuPersistentData.PersUniDisableDone {
438 oo.MutexPersOnuConfig.RUnlock()
439 oo.baseDeviceHandler.DisableUniPortStateUpdate(ctx)
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000440 _ = oo.baseDeviceHandler.ReasonUpdate(ctx, cmn.DrOmciAdminLock, oo.baseDeviceHandler.IsReconcilingReasonUpdate())
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000441 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000442 oo.MutexPersOnuConfig.RUnlock()
443 oo.baseDeviceHandler.EnableUniPortStateUpdate(ctx)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000444 }
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000445
446 // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm
447
448 if oo.baseDeviceHandler.ReconcileDeviceTechProf(ctx) {
449 // start go routine with select() on reconciling flow channel before
450 // starting flow reconciling process to prevent loss of any signal
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +0000451 syncChannel := make(chan struct{})
452 go func(aSyncChannel chan struct{}) {
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000453 // In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until
454 // we get a signal that the processing of the last step to rebuild the adapter internal
455 // flow data is finished.
456 expiry := oo.baseDeviceHandler.GetReconcileExpiryVlanConfigAbort()
457 oo.setReconcilingFlows(true)
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +0000458 aSyncChannel <- struct{}{}
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000459 select {
460 case success := <-oo.chReconcilingFlowsFinished:
461 if success {
462 logger.Debugw(ctx, "reconciling flows has been finished in time",
463 log.Fields{"device-id": oo.deviceID})
464 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
465
466 } else {
467 logger.Debugw(ctx, "wait for reconciling flows aborted",
468 log.Fields{"device-id": oo.deviceID})
469 }
470 case <-time.After(expiry):
471 logger.Errorw(ctx, "timeout waiting for reconciling flows to be finished!",
472 log.Fields{"device-id": oo.deviceID, "expiry": expiry})
473 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
474 }
475 oo.setReconcilingFlows(false)
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +0000476 }(syncChannel)
477 // block further processing until the above Go routine has really started
478 // and is ready to receive values from chReconcilingFlowsFinished
479 <-syncChannel
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000480 oo.baseDeviceHandler.ReconcileDeviceFlowConfig(ctx)
481 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000482 } else {
483 logger.Debugw(ctx, "MibSync FSM",
484 log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID})
485 go func() {
486 //switch to reconciling with OMCI config
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000487 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000488 }()
489 }
490}
491
dbainbri4d3a0dc2020-12-02 00:33:42 +0000492func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000493 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 +0000494 if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000495 oo.requestMdsValue(ctx)
496 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000497 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 +0000498 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000499 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000500 }()
501 }
502}
503
504func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
505 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 +0000506 if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000507 oo.requestMdsValue(ctx)
508 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000509 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 +0000510 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000511 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000512 }()
513 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000514}
515
dbainbri4d3a0dc2020-12-02 00:33:42 +0000516func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
517 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
518 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000519}
520
dbainbri4d3a0dc2020-12-02 00:33:42 +0000521func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
522 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 -0800523 oo.mutexMibSyncMsgProcessorRunning.Lock()
524 oo.mibSyncMsgProcessorRunning = true
525 oo.mutexMibSyncMsgProcessorRunning.Unlock()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000526loop:
527 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000528 // case <-ctx.Done():
529 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
530 // break loop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000531 message, ok := <-oo.PMibUploadFsm.CommChan
Himani Chawla4d908332020-08-31 12:30:20 +0530532 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000533 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 -0800534 oo.mutexMibSyncMsgProcessorRunning.Lock()
535 oo.mibSyncMsgProcessorRunning = false
536 oo.mutexMibSyncMsgProcessorRunning.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530537 break loop
538 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000539 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000540
Himani Chawla4d908332020-08-31 12:30:20 +0530541 switch message.Type {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000542 case cmn.TestMsg:
543 msg, _ := message.Data.(cmn.TestMessage)
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000544 if msg.TestMessageVal == cmn.AbortMessageProcessing {
545 logger.Debugw(ctx, "MibSync Msg abort ProcessMsg", log.Fields{"for device-id": oo.deviceID})
Girish Gowdra37c9d912022-02-08 16:24:57 -0800546 oo.mutexMibSyncMsgProcessorRunning.Lock()
547 oo.mibSyncMsgProcessorRunning = false
548 oo.mutexMibSyncMsgProcessorRunning.Unlock()
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000549 break loop
550 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000551 oo.handleTestMsg(ctx, msg)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000552 case cmn.OMCI:
553 msg, _ := message.Data.(cmn.OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000554 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530555 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000556 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 +0000557 }
558 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000559 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000560 // TODO: only this action?
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000561 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000562}
563
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000564func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg cmn.TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000565
dbainbri4d3a0dc2020-12-02 00:33:42 +0000566 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 +0000567
568 switch msg.TestMessageVal {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000569 case cmn.LoadMibTemplateFailed:
570 _ = oo.PMibUploadFsm.PFsm.Event(UlEvUploadMib)
571 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.PMibUploadFsm.PFsm.Current())})
572 case cmn.LoadMibTemplateOk:
573 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
574 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.PMibUploadFsm.PFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000575 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000576 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 +0000577 }
578}
579
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000580func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
581 if oo.PMibUploadFsm.PFsm.Is(UlStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530582 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
583 if msgLayer != nil {
584 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
585 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000586 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530587 if msgObj.Result == me.Success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000588 oo.MutexPersOnuConfig.Lock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000589 oo.SOnuPersistentData.PersMibDataSyncAdpt = cmn.MdsDefaultMib
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000590 oo.MutexPersOnuConfig.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530591 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000592 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530593 return
594 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000595 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530596 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000597 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530598 }
599 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000600 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530601 }
602 } else {
mpagenko01499812021-03-25 10:37:12 +0000603 //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset
604 // with Sequence number 0x8000 as last request before - so it may still respond to that
605 // 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 +0000606 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000607 if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
608 logger.Debugw(ctx, "MibSync FSM - repeat MdsGetRequest (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000609 requestedAttributes := me.AttributeValueMap{me.OnuData_MibDataSync: ""}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000610 _, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
611 me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300612 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000613 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300614 logger.Errorw(ctx, "ONUData get failed, aborting MibSync", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000615 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300616 return
617 }
mpagenko01499812021-03-25 10:37:12 +0000618 //TODO: needs extra handling of timeouts
619 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000620 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000621 return
622 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000623 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000624 logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
625 //perhaps some still lingering message from some prior activity, let's wait for the real response
626 return
Himani Chawla4d908332020-08-31 12:30:20 +0530627 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000628 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000629 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530630}
631
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000632func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530633 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
634 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000635 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530636 return
637 }
638 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
639 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000640 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530641 return
642 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000643 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530644 /* to be verified / reworked !!! */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000645 oo.PDevOmciCC.UploadNoOfCmds = msgObj.NumberOfCommands
646 if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds {
Holger Hildebrandt5458d892022-05-31 09:52:06 +0000647 _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx),
648 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.GetPersIsExtOmciSupported())
mpagenko01499812021-03-25 10:37:12 +0000649 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
650 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000651 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000652 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000653 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530654 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000655 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 +0530656 //TODO right action?
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000657 _ = oo.PMibUploadFsm.PFsm.Event(UlEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530658 }
659}
660
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000661func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530662 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
mpagenko7033f4e2021-11-19 18:04:22 +0000663 if msgLayer != nil {
664 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
665 if !msgOk {
666 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
667 return
mpagenko836a1fd2021-11-01 16:12:42 +0000668 }
mpagenko7033f4e2021-11-19 18:04:22 +0000669 meName := msgObj.ReportedME.GetName()
670 meClassID := msgObj.ReportedME.GetClassID()
671 meEntityID := msgObj.ReportedME.GetEntityID()
672
673 logger.Debugw(ctx, "MibUploadNextResponse Data for:", log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
674
675 if meName == devdb.CUnknownItuG988ManagedEntity || meName == devdb.CUnknownVendorSpecificManagedEntity {
Holger Hildebrandt39080022022-03-16 10:03:17 +0000676 logger.Debugw(ctx, "MibUploadNextResponse contains unknown ME", log.Fields{"device-id": oo.deviceID,
677 "Me-Name": devdb.UnknownMeOrAttribName(meName), "Me-ClassId": meClassID, "Me-InstId": meEntityID,
678 "unknown mask": msgObj.ReportedME.GetAttributeMask(), "unknown attributes": msgObj.BaseLayer.Payload})
679 oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.UnknownMeOrAttribName(meName), meClassID, meEntityID,
680 msgObj.ReportedME.GetAttributeMask(), msgObj.BaseLayer.Payload[devdb.CStartUnknownMeAttribsInBaseLayerPayload:])
mpagenko7033f4e2021-11-19 18:04:22 +0000681 } else {
682 //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
683 if unknownAttrLayer := (*msg.OmciPacket).Layer(omci.LayerTypeUnknownAttributes); unknownAttrLayer != nil {
684 logger.Warnw(ctx, "MibUploadNextResponse contains unknown attributes", log.Fields{"device-id": oo.deviceID})
685 if unknownAttributes, ok := unknownAttrLayer.(*omci.UnknownAttributes); ok {
686 // provide a loop over several ME's here already in preparation of OMCI extended message format
687 for _, unknown := range unknownAttributes.Attributes {
688 unknownAttrClassID := unknown.EntityClass // ClassID
689 unknownAttrInst := unknown.EntityInstance // uint16
690 unknownAttrMask := unknown.AttributeMask // ui
691 unknownAttrBlob := unknown.AttributeData // []byte
692 logger.Warnw(ctx, "unknown attributes detected for", log.Fields{"device-id": oo.deviceID,
693 "Me-ClassId": unknownAttrClassID, "Me-InstId": unknownAttrInst, "unknown mask": unknownAttrMask,
694 "unknown attributes": unknownAttrBlob})
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000695 oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.CUnknownAttributesManagedEntity, unknown.EntityClass, unknown.EntityInstance,
696 unknown.AttributeMask, unknown.AttributeData)
mpagenko7033f4e2021-11-19 18:04:22 +0000697 } // for all included ME's with unknown attributes
698 } else {
699 logger.Errorw(ctx, "unknownAttrLayer could not be decoded", log.Fields{"device-id": oo.deviceID})
700 }
701 }
702 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, msgObj.ReportedME.GetAttributeValueMap())
703 }
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000704 if msg.OmciMsg.DeviceIdentifier == omci.ExtendedIdent {
705 for _, additionalME := range msgObj.AdditionalMEs {
706 meName := additionalME.GetName()
707 meClassID := additionalME.GetClassID()
708 meEntityID := additionalME.GetEntityID()
709 attributes := additionalME.GetAttributeValueMap()
710
711 if meName == devdb.CUnknownItuG988ManagedEntity || meName == devdb.CUnknownVendorSpecificManagedEntity {
712 attribMask := additionalME.GetAttributeMask()
713 logger.Debugw(ctx, "MibUploadNextResponse AdditionalData contains unknown ME", log.Fields{"device-id": oo.deviceID,
714 "Me-Name": devdb.UnknownMeOrAttribName(meName), "Me-ClassId": meClassID, "Me-InstId": meEntityID,
715 "unknown mask": attribMask})
716
717 attribValues := make([]byte, 0)
718 for key, value := range attributes {
719 if key != cmn.CGenericManagedEntityIDName {
720 data, err := me.InterfaceToOctets(value)
721 if err != nil {
722 logger.Infow(ctx, "MibUploadNextResponse unknown ME AdditionalData attrib - could not decode", log.Fields{"device-id": oo.deviceID, "key": key})
723 } else {
724 attribValues = append(attribValues[:], data[:]...)
725 logger.Debugw(ctx, "MibUploadNextResponse unknown ME AdditionalData attrib", log.Fields{"device-id": oo.deviceID, "attribValues": attribValues, "data": data, "key": key})
726 }
727 }
728 }
729 oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.UnknownMeOrAttribName(meName), meClassID, meEntityID, attribMask, attribValues)
730 } else {
731 logger.Debugw(ctx, "MibUploadNextResponse AdditionalData for:", log.Fields{"device-id": oo.deviceID, "meName": meName, "meEntityID": meEntityID, "attributes": attributes})
732 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributes)
733 }
734 }
735 }
mpagenko7033f4e2021-11-19 18:04:22 +0000736 } else {
737 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
738 //as long as omci-lib does not support decoding of table attribute as 'unknown/unspecified' attribute
739 // we have to verify, if this failure is from table attribute and try to go forward with ignoring the complete message
740 errLayer := (*msg.OmciPacket).Layer(gopacket.LayerTypeDecodeFailure)
741 if failure, decodeOk := errLayer.(*gopacket.DecodeFailure); decodeOk {
742 errMsg := failure.String()
743 if !strings.Contains(strings.ToLower(errMsg), "table decode") {
744 //something still unexected happened, needs deeper investigation - stop complete MIB upload process (timeout)
745 return
746 }
747 logger.Warnw(ctx, "Decode issue on received MibUploadNextResponse frame - found table attribute(s) (message ignored)",
748 log.Fields{"device-id": oo.deviceID, "issue": errMsg})
749 }
Himani Chawla4d908332020-08-31 12:30:20 +0530750 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000751 if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds {
Holger Hildebrandt5458d892022-05-31 09:52:06 +0000752 _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx),
753 oo.baseDeviceHandler.GetOmciTimeout(), true, oo.GetPersIsExtOmciSupported())
mpagenko01499812021-03-25 10:37:12 +0000754 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
755 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000756 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000757 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000758 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530759 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000760 oo.pOnuDB.LogMeDb(ctx)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000761 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530762 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000763 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 +0530764 }
765
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000766 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530767 }
768}
769
Girish Gowdra21bbf052022-02-17 16:08:22 -0800770// nolint: gocyclo
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000771func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg cmn.OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000772 var err error = nil
mpagenko01499812021-03-25 10:37:12 +0000773
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000774 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000775 if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType ||
776 oo.lastTxParamStruct.pLastTxMeInstance == nil {
777 //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest
778 // with Sequence number 0x8000 as last request before - so it may still respond to that
779 // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number
780 if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
781 logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000782 _ = oo.PDevOmciCC.SendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000783 //TODO: needs extra handling of timeouts
784 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000785 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000786 return nil
787 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000788 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000789 logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
790 //perhaps some still lingering message from some prior activity, let's wait for the real response
791 return nil
792 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000793 oo.mutexLastTxParamStruct.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530794 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000795 if msgLayer == nil {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000796 logger.Errorw(ctx, "omci Msg layer could not be detected for GetResponse - handling of MibSyncChan stopped",
797 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000798 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000799 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 +0000800 }
801 msgObj, msgOk := msgLayer.(*omci.GetResponse)
802 if !msgOk {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000803 logger.Errorw(ctx, "omci Msg layer could not be assigned for GetResponse - handling of MibSyncChan stopped",
804 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000805 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000806 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 +0000807 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000808 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000809 if msgObj.Result == me.Success {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000810 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000811 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
812 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000813 meAttributes := msgObj.Attributes
mpagenko01499812021-03-25 10:37:12 +0000814 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000815 logger.Debugf(ctx, "MibSync FSM - GetResponse Data for %s",
816 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000817 switch meInstance {
818 case "OnuG":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000819 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000820 return oo.handleOmciGetResponseOnuG(ctx, meAttributes)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000821 case "Onu2G":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000822 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000823 var equipmentID string
824 if onu2GEquipmentID, ok := meAttributes[me.Onu2G_EquipmentId]; ok {
825 equipmentID = cmn.TrimStringFromMeOctet(onu2GEquipmentID)
826 if equipmentID == "" {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000827 logger.Infow(ctx,
828 "MibSync FSM - optional attribute EquipmentID is empty in Onu2G instance - fill with appropriate value",
829 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000830 equipmentID = cEmptyEquipIDString
831 }
832 } else {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000833 logger.Infow(ctx,
834 "MibSync FSM - optional attribute EquipmentID not present in Onu2G instance - fill with appropriate value",
835 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000836 equipmentID = cNotPresentEquipIDString
837 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000838 oo.MutexPersOnuConfig.Lock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000839 oo.SOnuPersistentData.PersEquipmentID = equipmentID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000840 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000841 "onuDeviceEntry.equipmentID": oo.SOnuPersistentData.PersEquipmentID})
842 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000843
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000844 var omccVersion uint8
845 if onu2GOmccVersion, ok := meAttributes[me.Onu2G_OpticalNetworkUnitManagementAndControlChannelOmccVersion]; ok {
846 oo.MutexPersOnuConfig.Lock()
847 omccVersion = onu2GOmccVersion.(uint8)
848 if _, ok := omccVersionSupportsExtendedOmciFormat[omccVersion]; ok {
849 oo.SOnuPersistentData.PersIsExtOmciSupported = omccVersionSupportsExtendedOmciFormat[omccVersion]
Holger Hildebrandtc572e622022-06-22 09:19:17 +0000850 if oo.SOnuPersistentData.PersIsExtOmciSupported && !oo.baseDeviceHandler.GetExtendedOmciSupportEnabled() {
851 logger.Infow(ctx, "MibSync FSM - ONU supports extended OMCI, but support is disabled in the adapter: reset flag",
852 log.Fields{"device-id": oo.deviceID})
853 oo.SOnuPersistentData.PersIsExtOmciSupported = false
854 }
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000855 } else {
856 logger.Infow(ctx, "MibSync FSM - unknown OMCC version in Onu2G instance - disable extended OMCI support",
857 log.Fields{"device-id": oo.deviceID})
858 oo.SOnuPersistentData.PersIsExtOmciSupported = false
859 }
860 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - OMCC version", log.Fields{"device-id": oo.deviceID,
861 "omccVersion": omccVersion, "isExtOmciSupported": oo.SOnuPersistentData.PersIsExtOmciSupported})
862 oo.MutexPersOnuConfig.Unlock()
863 } else {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000864 logger.Errorw(ctx,
865 "MibSync FSM - mandatory attribute OMCC version not present in Onu2G instance - handling of MibSyncChan stopped!",
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000866 log.Fields{"device-id": oo.deviceID})
867 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000868 return fmt.Errorf(
869 "mibSync FSM - mandatory attribute OMCC version not present in Onu2G instance - handling of MibSyncChan stopped: %s",
870 oo.deviceID)
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000871 }
872 oo.MutexPersOnuConfig.RLock()
873 if oo.SOnuPersistentData.PersIsExtOmciSupported {
874 oo.MutexPersOnuConfig.RUnlock()
875 // trigger test of OMCI extended msg format
876 _ = oo.PMibUploadFsm.PFsm.Event(UlEvTestExtOmciSupport)
877 return nil
878 }
879 oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000880 // trigger retrieval of 1st SW-image info
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000881 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000882 return nil
883 case "SoftwareImage":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000884 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000885 if entityID > cmn.SecondSwImageMeID {
mpagenko15ff4a52021-03-02 10:09:20 +0000886 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
887 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
888 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
889 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000890 }
mpagenko15ff4a52021-03-02 10:09:20 +0000891 // need to use function for go lint complexity
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000892 if !oo.HandleSwImageIndications(ctx, entityID, meAttributes) {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000893 logger.Errorw(ctx,
894 "MibSync FSM - Not all mandatory attributes present in in SoftwareImage instance - handling of MibSyncChan stopped!",
895 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000896 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000897 return fmt.Errorf(
898 "mibSync FSM - Not all mandatory attributes present in in SoftwareImage instance - handling of MibSyncChan stopped: %s",
899 oo.deviceID)
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000900 }
mpagenko15ff4a52021-03-02 10:09:20 +0000901 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000902 case "IpHostConfigData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000903 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000904 oo.MutexPersOnuConfig.Lock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000905 if ipHostConfigMacAddress, ok := meAttributes[me.IpHostConfigData_MacAddress]; ok {
Girish Gowdra21bbf052022-02-17 16:08:22 -0800906 macBytes, _ := me.InterfaceToOctets(ipHostConfigMacAddress)
907 if cmn.OmciMacAddressLen == len(macBytes) {
908 oo.SOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:])
909 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
910 "macAddress": oo.SOnuPersistentData.PersMacAddress})
911 } else {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000912 logger.Infow(ctx, "MibSync FSM - MacAddress wrong length - fill macAddress with zeros",
913 log.Fields{"device-id": oo.deviceID, "length": len(macBytes)})
Girish Gowdra21bbf052022-02-17 16:08:22 -0800914 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
915 }
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000916 } else {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000917 // since ONU creates instances of this ME automatically only when IP host services are available,
918 // processing continues here despite the error
919 logger.Infow(ctx, "MibSync FSM - MacAddress attribute not present in IpHostConfigData instance - fill macAddress with zeros",
920 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000921 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000922 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000923 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000924 // trigger retrieval of mib template
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000925 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000926 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000927 case "OnuData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000928 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000929 if onuDataMibDataSync, ok := meAttributes[me.OnuData_MibDataSync]; ok {
930 oo.checkMdsValue(ctx, onuDataMibDataSync.(uint8))
931 } else {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000932 logger.Errorw(ctx, "MibSync FSM - MibDataSync attribute not present in OnuData instance - handling of MibSyncChan stopped!",
933 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000934 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +0000935 return fmt.Errorf("mibSync FSM - VendorId attribute not present in OnuG instance - handling of MibSyncChan stopped: %s",
936 oo.deviceID)
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000937 }
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000938 return nil
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000939 default:
940 oo.mutexLastTxParamStruct.RUnlock()
941 logger.Warnw(ctx, "Unsupported ME name received!",
942 log.Fields{"ME name": meInstance, "device-id": oo.deviceID})
943
Himani Chawla4d908332020-08-31 12:30:20 +0530944 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800945 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000946 oo.mutexLastTxParamStruct.RUnlock()
947 logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ",
948 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000949 }
Himani Chawla4d908332020-08-31 12:30:20 +0530950 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000951 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000952 return nil
953 }
Himani Chawla4d908332020-08-31 12:30:20 +0530954 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000955 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000956 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000957 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530958}
959
Holger Hildebrandt94688c72021-12-17 12:13:02 +0000960//HandleSwImageIndications updates onuSwImageIndications with the ONU data just received
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000961func (oo *OnuDeviceEntry) HandleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) bool {
962
963 var imageVersion string
964 var imageIsCommitted, imageIsActive uint8
965
966 allMandAttribsPresent := false
967 if softwareImageIsCommitted, ok := meAttributes[me.SoftwareImage_IsCommitted]; ok {
968 if softwareImageIsActiveimage, ok := meAttributes[me.SoftwareImage_IsActive]; ok {
969 if softwareImageVersion, ok := meAttributes[me.SoftwareImage_Version]; ok {
970 imageVersion = cmn.TrimStringFromMeOctet(softwareImageVersion)
971 imageIsActive = softwareImageIsActiveimage.(uint8)
972 imageIsCommitted = softwareImageIsCommitted.(uint8)
973 allMandAttribsPresent = true
974 }
975 }
976 }
977 if !allMandAttribsPresent {
978 logger.Errorw(ctx, "MibSync FSM - Not all mandatory attributes present in SoftwareImage instance - skip processing!", log.Fields{"device-id": oo.deviceID})
979 return allMandAttribsPresent
980 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000981 oo.MutexPersOnuConfig.RLock()
mpagenko15ff4a52021-03-02 10:09:20 +0000982 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
983 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000984 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.SOnuPersistentData.PersSerialNumber})
985 oo.MutexPersOnuConfig.RUnlock()
986 if cmn.FirstSwImageMeID == entityID {
mpagenko15ff4a52021-03-02 10:09:20 +0000987 //always accept the state of the first image (2nd image info should not yet be available)
Holger Hildebrandt05011352021-06-15 09:40:24 +0000988 oo.mutexOnuSwImageIndications.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000989 if imageIsActive == cmn.SwIsActive {
990 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID
991 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true
992 oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion
993 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000994 //as the SW version indication may stem from some ONU Down/up event
995 //the complementary image state is to be invalidated
996 // (state of the second image is always expected afterwards or just invalid)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000997 oo.onuSwImageIndications.InActiveEntityEntry.Valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000998 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000999 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
1000 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true
1001 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
1002 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +00001003 //as the SW version indication may stem form some ONU Down/up event
1004 //the complementary image state is to be invalidated
1005 // (state of the second image is always expected afterwards or just invalid)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001006 oo.onuSwImageIndications.ActiveEntityEntry.Valid = false
mpagenko15ff4a52021-03-02 10:09:20 +00001007 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001008 oo.mutexOnuSwImageIndications.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001009 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetSecondSwVersion)
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +00001010 return allMandAttribsPresent
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001011 } else if cmn.SecondSwImageMeID == entityID {
mpagenko15ff4a52021-03-02 10:09:20 +00001012 //2nd image info might conflict with first image info, in which case we priorize first image info!
Holger Hildebrandt05011352021-06-15 09:40:24 +00001013 oo.mutexOnuSwImageIndications.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001014 if imageIsActive == cmn.SwIsActive { //2nd image reported to be active
1015 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
mpagenko15ff4a52021-03-02 10:09:20 +00001016 //conflict exists - state of first image is left active
1017 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
1018 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001019 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
1020 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true ////to indicate that at least something has been reported
1021 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
1022 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +00001023 } else { //first image inactive, this one active
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001024 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID
1025 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true
1026 oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion
1027 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +00001028 }
1029 } else { //2nd image reported to be inactive
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001030 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
mpagenko15ff4a52021-03-02 10:09:20 +00001031 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
1032 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
1033 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001034 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = cmn.FirstSwImageMeID
1035 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true //to indicate that at least something has been reported
mpagenko15ff4a52021-03-02 10:09:20 +00001036 //copy active commit/version from the previously stored inactive position
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001037 oo.onuSwImageIndications.ActiveEntityEntry.Version = oo.onuSwImageIndications.InActiveEntityEntry.Version
1038 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +00001039 }
1040 //in any case we indicate (and possibly overwrite) the second image indications as inactive
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001041 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
1042 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true
1043 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
1044 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +00001045 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001046 oo.mutexOnuSwImageIndications.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001047 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMacAddress)
mpagenko15ff4a52021-03-02 10:09:20 +00001048 }
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +00001049 return allMandAttribsPresent
mpagenko15ff4a52021-03-02 10:09:20 +00001050}
1051
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001052func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001053 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +02001054 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001055 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
1056 switch msg.OmciMsg.MessageType {
1057 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +00001058 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001059
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001060 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +00001061 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +05301062
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001063 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +00001064 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001065
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001066 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001067 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +00001068 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +05301069
Andrea Campanella6515c582020-10-05 11:25:00 +02001070 default:
Holger Hildebrandtabfef032022-02-25 12:40:20 +00001071 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"device-id": oo.deviceID, "msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +02001072
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001073 }
1074}
1075
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +00001076func (oo *OnuDeviceEntry) handleOmciGetResponseOnuG(ctx context.Context, meAttributes me.AttributeValueMap) error {
1077 currentState := oo.PMibUploadFsm.PFsm.Current()
1078 if currentState == UlStGettingVendorAndSerial {
1079 if onuGVendorID, ok := meAttributes[me.OnuG_VendorId]; ok {
1080 vendorID := cmn.TrimStringFromMeOctet(onuGVendorID)
1081 if vendorID == "" {
1082 logger.Infow(ctx,
1083 "MibSync FSM - mandatory attribute VendorId is empty in OnuG instance - fill with appropriate value",
1084 log.Fields{"device-id": oo.deviceID})
1085 vendorID = cEmptyVendorIDString
1086 }
1087 oo.MutexPersOnuConfig.Lock()
1088 oo.SOnuPersistentData.PersVendorID = vendorID
1089 oo.MutexPersOnuConfig.Unlock()
1090 } else {
1091 logger.Errorw(ctx,
1092 "MibSync FSM - mandatory attribute VendorId not present in OnuG instance - handling of MibSyncChan stopped!",
1093 log.Fields{"device-id": oo.deviceID})
1094 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
1095 return fmt.Errorf(
1096 "mibSync FSM - mandatory attribute VendorId not present in OnuG instance - handling of MibSyncChan stopped: %s",
1097 oo.deviceID)
1098 }
1099 if onuGSerialNumber, ok := meAttributes[me.OnuG_SerialNumber]; ok {
1100 oo.MutexPersOnuConfig.Lock()
1101 snBytes, _ := me.InterfaceToOctets(onuGSerialNumber)
1102 if cmn.OnugSerialNumberLen == len(snBytes) {
1103 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
1104 snNumberPart := hex.EncodeToString(snBytes[4:])
1105 oo.SOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart
1106 } else {
1107 logger.Infow(ctx, "MibSync FSM - SerialNumber has wrong length - fill serialNumber with zeros",
1108 log.Fields{"device-id": oo.deviceID, "length": len(snBytes)})
1109 oo.SOnuPersistentData.PersSerialNumber = cEmptySerialNumberString
1110 }
1111 oo.MutexPersOnuConfig.Unlock()
1112 } else {
1113 logger.Errorw(ctx,
1114 "MibSync FSM - mandatory attribute SerialNumber not present in OnuG instance - handling of MibSyncChan stopped!",
1115 log.Fields{"device-id": oo.deviceID})
1116 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
1117 return fmt.Errorf(
1118 "mibSync FSM - mandatory attribute SerialNumber not present in OnuG instance - handling of MibSyncChan stopped: %s",
1119 oo.deviceID)
1120 }
1121 oo.MutexPersOnuConfig.Lock()
1122 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-G - VendorId/SerialNumber", log.Fields{"device-id": oo.deviceID,
1123 "onuDeviceEntry.vendorID": oo.SOnuPersistentData.PersVendorID,
1124 "onuDeviceEntry.serialNumber": oo.SOnuPersistentData.PersSerialNumber})
1125 oo.MutexPersOnuConfig.Unlock()
1126 // trigger retrieval of Version
1127 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetVersion)
1128 return nil
1129 } else if currentState == UlStGettingVersion {
1130 if onuGVersion, ok := meAttributes[me.OnuG_Version]; ok {
1131 version := cmn.TrimStringFromMeOctet(onuGVersion)
1132 if version == "" {
1133 logger.Infow(ctx, "MibSync FSM - mandatory attribute Version is empty in OnuG instance - fill with appropriate value",
1134 log.Fields{"device-id": oo.deviceID})
1135 version = cEmptyVersionString
1136 }
1137 oo.MutexPersOnuConfig.Lock()
1138 oo.SOnuPersistentData.PersVersion = version
1139 oo.MutexPersOnuConfig.Unlock()
1140 } else {
1141 logger.Errorw(ctx,
1142 "MibSync FSM - mandatory attribute Version not present in OnuG instance - handling of MibSyncChan stopped!",
1143 log.Fields{"device-id": oo.deviceID})
1144 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
1145 return fmt.Errorf(
1146 "mibSync FSM - mandatory attribute Version not present in OnuG instance - handling of MibSyncChan stopped: %s",
1147 oo.deviceID)
1148 }
1149 oo.MutexPersOnuConfig.Lock()
1150 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-G - Version", log.Fields{"device-id": oo.deviceID,
1151 "onuDeviceEntry.version": oo.SOnuPersistentData.PersVersion})
1152 oo.MutexPersOnuConfig.Unlock()
1153 // trigger retrieval of EquipmentId and OMCC version
1154 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetEquipIDAndOmcc)
1155 return nil
1156 } else {
1157 logger.Errorw(ctx, "MibSync FSM - wrong state OnuG response processing - handling of MibSyncChan stopped!",
1158 log.Fields{"currentState": currentState, "device-id": oo.deviceID})
1159 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
1160 return fmt.Errorf("mibSync FSM - wrong state OnuG response processing - handling of MibSyncChan stopped: %s",
1161 oo.deviceID)
1162 }
1163}
1164
dbainbri4d3a0dc2020-12-02 00:33:42 +00001165func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +00001166 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +00001167 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 +00001168 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
1169 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001170 oo.mutexLastTxParamStruct.RLock()
1171 if oo.lastTxParamStruct.pLastTxMeInstance != nil {
1172 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
1173 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
1174 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
1175 switch meInstance {
1176 case "IpHostConfigData":
1177 oo.mutexLastTxParamStruct.RUnlock()
1178 logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros",
1179 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001180 oo.MutexPersOnuConfig.Lock()
1181 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
1182 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001183 // trigger retrieval of mib template
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001184 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001185 return nil
1186 default:
1187 oo.mutexLastTxParamStruct.RUnlock()
1188 logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
1189 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
1190 }
1191 } else {
1192 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt80129db2020-11-23 10:49:32 +00001193 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001194 } else {
1195 oo.mutexLastTxParamStruct.RUnlock()
1196 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt80129db2020-11-23 10:49:32 +00001197 }
1198 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001199 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 +00001200 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
1201 }
1202 return err
1203}
1204
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001205// IsNewOnu - TODO: add comment
1206func (oo *OnuDeviceEntry) IsNewOnu() bool {
1207 oo.MutexPersOnuConfig.RLock()
1208 defer oo.MutexPersOnuConfig.RUnlock()
1209 return oo.SOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +00001210}
1211
Himani Chawla6d2ae152020-09-02 13:11:20 +05301212func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001213 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +05301214 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001215 return true
1216 }
1217 }
1218 return false
1219}
1220
dbainbri4d3a0dc2020-12-02 00:33:42 +00001221func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
1222 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001223 return errors.New("not_implemented")
1224}
1225
Himani Chawla6d2ae152020-09-02 13:11:20 +05301226// 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 +05301227// 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 +00001228// 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 +00001229func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
1230 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001231 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +05301232
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001233 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
1234 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); exist {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001235 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001236 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001237 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001238 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001239 return nil
1240 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001241 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001242 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1243 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001244 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001245 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1246 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001247 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, true)
1248 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001249
1250 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +05301251 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001252 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +05301253 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
1254
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001255 firstLevelMap := oo.pOnuDB.MeDb
divyadesaibbed37c2020-08-28 13:35:20 +05301256 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001257 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +05301258 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +05301259
1260 secondLevelMap := make(map[string]interface{})
1261 for secondLevelKey, secondLevelValue := range firstLevelValue {
Holger Hildebrandt8998ed52022-03-23 09:52:37 +00001262 // ManagedEntityId is already key of secondLevelMap - remove this redundant attribute from secondLevelValue
1263 delete(secondLevelValue, cmn.CGenericManagedEntityIDName)
divyadesaibbed37c2020-08-28 13:35:20 +05301264 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +05301265 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +05301266 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +05301267 secondLevelMap[entityID] = thirdLevelMap
1268 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +05301269 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
1270 delete(forthLevelMap, "SerialNumber")
1271 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
1272
1273 }
Himani Chawla26e555c2020-08-31 12:30:20 +05301274 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +05301275 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
1276 delete(forthLevelMap, "MacAddress")
1277 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
1278 }
1279 }
Himani Chawla26e555c2020-08-31 12:30:20 +05301280 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +05301281 }
Holger Hildebrandt39080022022-03-16 10:03:17 +00001282 unknownMeAndAttribMap := oo.pOnuDB.UnknownMeAndAttribDb
1283 for unknownMeAndAttribMapKey := range unknownMeAndAttribMap {
1284 templateMap[string(unknownMeAndAttribMapKey)] = unknownMeAndAttribMap[unknownMeAndAttribMapKey]
Holger Hildebrandtf3c7a182021-11-17 13:42:08 +00001285 }
divyadesaibbed37c2020-08-28 13:35:20 +05301286 mibTemplate, err := json.Marshal(&templateMap)
1287 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001288 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001289 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
1290 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
1291 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
divyadesaibbed37c2020-08-28 13:35:20 +05301292 return err
1293 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001294 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +05301295 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001296 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 +00001297 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
1298 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
1299 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
divyadesaibbed37c2020-08-28 13:35:20 +05301300 return err
1301 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001302 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +05301303 return nil
1304}
1305
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +00001306func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
1307 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001308 requestedAttributes := me.AttributeValueMap{me.OnuData_MibDataSync: ""}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001309 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
1310 me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +00001311 //accept also nil as (error) return value for writing to LastTx
1312 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +03001313 if err != nil {
1314 logger.Errorw(ctx, "ONUData get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001315 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001316 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001317 go func(a_pAFsm *cmn.AdapterFsm) {
1318 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001319 }(pMibUlFsm)
1320 }
1321 return
1322 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001323 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +00001324 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
1325 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
1326 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001327 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +00001328}
1329
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001330func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001331 oo.MutexPersOnuConfig.RLock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001332 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001333 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.SOnuPersistentData.PersMibDataSyncAdpt})
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001334
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001335 mdsValuesAreEqual := oo.SOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
1336 oo.MutexPersOnuConfig.RUnlock()
1337 if oo.PMibUploadFsm.PFsm.Is(UlStAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001338 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001339 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001340 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001341 } else {
1342 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 +00001343 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001344 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001345 } else if oo.PMibUploadFsm.PFsm.Is(UlStReAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001346 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001347 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001348 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001349 } else {
Holger Hildebrandt80f57762022-02-16 10:03:24 +00001350 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 +00001351 log.Fields{"device-id": oo.deviceID})
1352 oo.SendOnuDeviceEvent(ctx, cmn.OnuMibAuditFailureMds, cmn.OnuMibAuditFailureMdsDesc)
Holger Hildebrandt80f57762022-02-16 10:03:24 +00001353 // To reconcile ONU with active adapter later on, we have to retrieve TP instances from parent adapter.
1354 // In the present use case inconsistencies between TP pathes stored in kv store and TP instances retrieved
1355 // should not occur. Nevertheless, the respective code is inserted to catch the unlikely case.
1356 if !oo.getAllStoredTpInstFromParentAdapter(ctx) {
1357 logger.Debugw(ctx, "MibSync FSM - mib reaudit - inconsistencies between TP pathes stored in kv and parent adapter instances",
1358 log.Fields{"device-id": oo.deviceID})
1359 oo.baseDeviceHandler.SetReconcilingReasonUpdate(true)
1360 go func() {
1361 if err := oo.baseDeviceHandler.StorePersistentData(ctx); err != nil {
1362 logger.Warnw(ctx,
1363 "MibSync FSM - mib reaudit - store persistent data error - continue for now as there will be additional write attempts",
1364 log.Fields{"device-id": oo.deviceID, "err": err})
1365 }
1366 }()
1367 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001368 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001369 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001370 } else if oo.PMibUploadFsm.PFsm.Is(UlStExaminingMds) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001371 if mdsValuesAreEqual && mibDataSyncOnu != 0 {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001372 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001373 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001374 } else {
1375 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001376 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001377 }
1378 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001379 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 +00001380 }
1381}
mpagenko15ff4a52021-03-02 10:09:20 +00001382
1383//GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
1384func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001385 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001386 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
1387 value := oo.onuSwImageIndications.ActiveEntityEntry.EntityID
Holger Hildebrandt05011352021-06-15 09:40:24 +00001388 oo.mutexOnuSwImageIndications.RUnlock()
1389 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +00001390 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001391 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001392 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
1393}
1394
1395//GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
1396func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001397 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001398 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
1399 value := oo.onuSwImageIndications.InActiveEntityEntry.EntityID
Holger Hildebrandt05011352021-06-15 09:40:24 +00001400 oo.mutexOnuSwImageIndications.RUnlock()
1401 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +00001402 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001403 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001404 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
1405}
1406
1407//IsImageToBeCommitted returns true if the active image is still uncommitted
1408func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001409 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001410 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
1411 if oo.onuSwImageIndications.ActiveEntityEntry.EntityID == aImageID {
1412 if oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted == cmn.SwIsUncommitted {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001413 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001414 return true
1415 }
1416 }
1417 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001418 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001419 return false //all other case are treated as 'nothing to commit
1420}
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001421func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool {
1422
1423 oo.mibTemplatePath = oo.buildMibTemplatePath()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +00001424 logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath),
1425 "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001426
1427 restoredFromMibTemplate := false
1428 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
1429 if err == nil {
1430 if Value != nil {
1431 logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value)
1432
1433 // swap out tokens with specific data
1434 mibTmpString, _ := kvstore.ToString(Value.Value)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001435 oo.MutexPersOnuConfig.RLock()
1436 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.SOnuPersistentData.PersSerialNumber, -1)
1437 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.SOnuPersistentData.PersMacAddress, -1)
1438 oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001439 mibTmpBytes := []byte(mibTmpString)
1440 logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes)
1441
1442 var firstLevelMap map[string]interface{}
1443 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
1444 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
1445 } else {
1446 for firstLevelKey, firstLevelValue := range firstLevelMap {
1447 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
1448 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
1449 meClassID := me.ClassID(uint16ValidNumber)
1450 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
1451 if isSupportedClassID(meClassID) {
1452 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
1453 secondLevelMap := firstLevelValue.(map[string]interface{})
1454 for secondLevelKey, secondLevelValue := range secondLevelMap {
1455 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
1456 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
1457 meEntityID := uint16(uint16ValidNumber)
1458 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
1459 thirdLevelMap := secondLevelValue.(map[string]interface{})
1460 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
1461 if thirdLevelKey == "Attributes" {
1462 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
1463 attributesMap := thirdLevelValue.(map[string]interface{})
1464 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
1465 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
1466 restoredFromMibTemplate = true
1467 }
1468 }
1469 }
1470 }
1471 }
1472 }
1473 }
1474 }
1475 } else {
1476 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1477 }
1478 } else {
1479 logger.Errorf(ctx, "Get from kvstore operation failed for path",
1480 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1481 }
1482 return restoredFromMibTemplate
1483}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001484
Holger Hildebrandt80f57762022-02-16 10:03:24 +00001485func (oo *OnuDeviceEntry) getAllStoredTpInstFromParentAdapter(ctx context.Context) bool {
1486
1487 allTpInstPresent := true
1488 oo.MutexPersOnuConfig.Lock()
1489 oo.MutexReconciledTpInstances.Lock()
1490 for indexUni, uniData := range oo.SOnuPersistentData.PersUniConfig {
1491 uniID := uniData.PersUniID
1492 oo.ReconciledTpInstances[uniID] = make(map[uint8]inter_adapter.TechProfileDownloadMessage)
1493 for tpID, tpPath := range uniData.PersTpPathMap {
1494 if tpPath != "" {
1495 // Request the TP instance from the openolt adapter
1496 iaTechTpInst, err := oo.baseDeviceHandler.GetTechProfileInstanceFromParentAdapter(ctx, uniID, tpPath)
1497 if err == nil && iaTechTpInst != nil {
1498 logger.Debugw(ctx, "reconciling - store Tp instance", log.Fields{"uniID": uniID, "tpID": tpID,
1499 "*iaTechTpInst": iaTechTpInst, "device-id": oo.deviceID})
1500 oo.ReconciledTpInstances[uniID][tpID] = *iaTechTpInst
1501 } else {
1502 // During the absence of the ONU adapter there seem to have been TP specific configurations!
1503 // The no longer available TP and the associated flows must be deleted from the ONU KV store
1504 // and after a MIB reset a new reconciling attempt with OMCI configuration must be started.
1505 allTpInstPresent = false
1506 logger.Infow(ctx, "reconciling - can't get tp instance - delete tp and associated flows",
1507 log.Fields{"tp-id": tpID, "tpPath": tpPath, "uni-id": uniID, "device-id": oo.deviceID, "err": err})
1508 delete(oo.SOnuPersistentData.PersUniConfig[indexUni].PersTpPathMap, tpID)
1509 flowSlice := oo.SOnuPersistentData.PersUniConfig[indexUni].PersFlowParams
1510 for indexFlow, flowData := range flowSlice {
1511 if flowData.VlanRuleParams.TpID == tpID {
1512 if len(flowSlice) == 1 {
1513 flowSlice = []cmn.UniVlanFlowParams{}
1514 } else {
1515 flowSlice = append(flowSlice[:indexFlow], flowSlice[indexFlow+1:]...)
1516 }
1517 oo.SOnuPersistentData.PersUniConfig[indexUni].PersFlowParams = flowSlice
1518 }
1519 }
1520 }
1521 }
1522 }
1523 }
1524 oo.MutexReconciledTpInstances.Unlock()
1525 oo.MutexPersOnuConfig.Unlock()
1526 return allTpInstPresent
1527}
1528
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001529//CancelProcessing terminates potentially running reconciling processes and stops the FSM
1530func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) {
Holger Hildebrandt12609a12022-03-25 13:23:25 +00001531 logger.Debugw(ctx, "CancelProcessing entered", log.Fields{"device-id": oo.deviceID})
mpagenko101ac942021-11-16 15:01:29 +00001532 if oo.isReconcilingFlows() {
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +00001533 oo.SendChReconcilingFlowsFinished(ctx, false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001534 }
1535 //the MibSync FSM might be active all the ONU-active time,
1536 // hence it must be stopped unconditionally
Girish Gowdra37c9d912022-02-08 16:24:57 -08001537 oo.mutexMibSyncMsgProcessorRunning.RLock()
1538 defer oo.mutexMibSyncMsgProcessorRunning.RUnlock()
1539 if oo.mibSyncMsgProcessorRunning {
1540 pMibUlFsm := oo.PMibUploadFsm
1541 if pMibUlFsm != nil {
1542 // abort running message processing
1543 fsmAbortMsg := cmn.Message{
1544 Type: cmn.TestMsg,
1545 Data: cmn.TestMessage{
1546 TestMessageVal: cmn.AbortMessageProcessing,
1547 },
1548 }
1549 pMibUlFsm.CommChan <- fsmAbortMsg
1550 _ = pMibUlFsm.PFsm.Event(UlEvStop)
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001551 }
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001552 }
1553}