blob: 8636aa7a1843eae90608d6ade1fa2ff0f69d5d38 [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"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000028
29 "github.com/looplab/fsm"
30
divyadesaibbed37c2020-08-28 13:35:20 +053031 "time"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000032
mpagenko7033f4e2021-11-19 18:04:22 +000033 "github.com/google/gopacket"
mpagenko836a1fd2021-11-01 16:12:42 +000034 "github.com/opencord/omci-lib-go/v2"
35 me "github.com/opencord/omci-lib-go/v2/generated"
khenaidoo7d3c5582021-08-11 18:09:44 -040036 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
37 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000038 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
39 devdb "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb"
Holger Hildebrandt9afc1582021-11-30 16:10:19 +000040 "github.com/opencord/voltha-protos/v5/go/inter_adapter"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000041)
42
mpagenko01499812021-03-25 10:37:12 +000043type sLastTxMeParameter struct {
44 lastTxMessageType omci.MessageType
45 pLastTxMeInstance *me.ManagedEntity
46 repeatCount uint8
47}
48
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000049var supportedClassIds = []me.ClassID{
50 me.CardholderClassID, // 5
51 me.CircuitPackClassID, // 6
52 me.SoftwareImageClassID, // 7
53 me.PhysicalPathTerminationPointEthernetUniClassID, // 11
ozgecanetsia124d9732021-09-16 14:31:57 +030054 me.PhysicalPathTerminationPointPotsUniClassID, // 53
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000055 me.OltGClassID, // 131
56 me.OnuPowerSheddingClassID, // 133
57 me.IpHostConfigDataClassID, // 134
58 me.OnuGClassID, // 256
59 me.Onu2GClassID, // 257
60 me.TContClassID, // 262
61 me.AniGClassID, // 263
62 me.UniGClassID, // 264
63 me.PriorityQueueClassID, // 277
64 me.TrafficSchedulerClassID, // 278
65 me.VirtualEthernetInterfacePointClassID, // 329
66 me.EnhancedSecurityControlClassID, // 332
67 me.OnuDynamicPowerManagementControlClassID, // 336
68 // 347 // definitions for ME "IPv6 host config data" are currently missing in omci-lib-go!
69}
70
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000071var fsmMsg cmn.TestMessageType
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000072
dbainbri4d3a0dc2020-12-02 00:33:42 +000073func (oo *OnuDeviceEntry) enterStartingState(ctx context.Context, e *fsm.Event) {
74 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000075 oo.pOnuDB = devdb.NewOnuDeviceDB(log.WithSpanFromContext(context.TODO(), ctx), oo.deviceID)
dbainbri4d3a0dc2020-12-02 00:33:42 +000076 go oo.processMibSyncMessages(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000077}
78
dbainbri4d3a0dc2020-12-02 00:33:42 +000079func (oo *OnuDeviceEntry) enterResettingMibState(ctx context.Context, e *fsm.Event) {
80 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibTemplate processing in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000081
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000082 if (!oo.IsNewOnu() && !oo.baseDeviceHandler.IsReconciling()) || //use case: re-auditing failed
83 oo.baseDeviceHandler.IsSkipOnuConfigReconciling() { //use case: reconciling without omci-config failed
84 oo.baseDeviceHandler.PrepareReconcilingWithActiveAdapter(ctx)
85 oo.devState = cmn.DeviceStatusInit
Holger Hildebrandt10d98192021-01-27 15:29:31 +000086 }
dbainbri4d3a0dc2020-12-02 00:33:42 +000087 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send mibReset in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000088 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000089 _ = oo.PDevOmciCC.SendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000090 //TODO: needs to handle timeouts
mpagenko01499812021-03-25 10:37:12 +000091 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
92 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
93 oo.lastTxParamStruct.lastTxMessageType = omci.MibResetRequestType
94 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000095 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000096}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000097
dbainbri4d3a0dc2020-12-02 00:33:42 +000098func (oo *OnuDeviceEntry) enterGettingVendorAndSerialState(ctx context.Context, e *fsm.Event) {
99 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting VendorId and SerialNumber in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000100 requestedAttributes := me.AttributeValueMap{me.OnuG_VendorId: "", me.OnuG_SerialNumber: 0}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000101 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000102 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.OnuGClassID, cmn.OnugMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000103 //accept also nil as (error) return value for writing to LastTx
104 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300105 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000106 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300107 logger.Errorw(ctx, "ONU-G get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000108 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300109 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000110 go func(a_pAFsm *cmn.AdapterFsm) {
111 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300112 }(pMibUlFsm)
113 }
114 return
115 }
mpagenko01499812021-03-25 10:37:12 +0000116 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
117 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000118 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000119}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000120
dbainbri4d3a0dc2020-12-02 00:33:42 +0000121func (oo *OnuDeviceEntry) enterGettingEquipmentIDState(ctx context.Context, e *fsm.Event) {
122 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting EquipmentId in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000123 requestedAttributes := me.AttributeValueMap{me.Onu2G_EquipmentId: ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000124 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000125 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.Onu2GClassID, cmn.Onu2gMeID, requestedAttributes, 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, "ONU2-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}
143
dbainbri4d3a0dc2020-12-02 00:33:42 +0000144func (oo *OnuDeviceEntry) enterGettingFirstSwVersionState(ctx context.Context, e *fsm.Event) {
145 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting IsActive and Version of first SW-image in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000146 requestedAttributes := me.AttributeValueMap{me.SoftwareImage_IsCommitted: 0, me.SoftwareImage_IsActive: 0, me.SoftwareImage_Version: ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000147 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000148 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, cmn.FirstSwImageMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000149 //accept also nil as (error) return value for writing to LastTx
150 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300151 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000152 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300153 logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000154 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300155 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000156 go func(a_pAFsm *cmn.AdapterFsm) {
157 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300158 }(pMibUlFsm)
159 }
160 return
161 }
mpagenko01499812021-03-25 10:37:12 +0000162 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
163 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000164 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000165}
166
dbainbri4d3a0dc2020-12-02 00:33:42 +0000167func (oo *OnuDeviceEntry) enterGettingSecondSwVersionState(ctx context.Context, e *fsm.Event) {
168 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting IsActive and Version of second SW-image in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000169 requestedAttributes := me.AttributeValueMap{me.SoftwareImage_IsCommitted: 0, me.SoftwareImage_IsActive: 0, me.SoftwareImage_Version: ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000170 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000171 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, cmn.SecondSwImageMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000172 //accept also nil as (error) return value for writing to LastTx
173 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300174 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000175 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300176 logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000177 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300178 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000179 go func(a_pAFsm *cmn.AdapterFsm) {
180 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300181 }(pMibUlFsm)
182 }
183 return
184 }
mpagenko01499812021-03-25 10:37:12 +0000185 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
186 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000187 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000188}
189
dbainbri4d3a0dc2020-12-02 00:33:42 +0000190func (oo *OnuDeviceEntry) enterGettingMacAddressState(ctx context.Context, e *fsm.Event) {
191 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting MacAddress in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000192 requestedAttributes := me.AttributeValueMap{me.IpHostConfigData_MacAddress: ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000193 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000194 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.IpHostConfigDataClassID, cmn.IPHostConfigDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000195 //accept also nil as (error) return value for writing to LastTx
196 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300197 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000198 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300199 logger.Errorw(ctx, "IpHostConfigData get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000200 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300201 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000202 go func(a_pAFsm *cmn.AdapterFsm) {
203 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300204 }(pMibUlFsm)
205 }
206 return
207 }
mpagenko01499812021-03-25 10:37:12 +0000208 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
209 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000210 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000211}
212
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000213func (oo *OnuDeviceEntry) enterGettingMibTemplateState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000214
Holger Hildebrandt05011352021-06-15 09:40:24 +0000215 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000216 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
217 oo.MutexPersOnuConfig.Lock()
218 oo.SOnuPersistentData.PersActiveSwVersion = oo.onuSwImageIndications.ActiveEntityEntry.Version
219 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt05011352021-06-15 09:40:24 +0000220 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000221 } else {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000222 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000223 logger.Errorw(ctx, "get-mib-template: no active SW version found, working with empty SW version, which might be untrustworthy",
224 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000225 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000226 if oo.getMibFromTemplate(ctx) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000227 logger.Debug(ctx, "MibSync FSM - valid MEs stored from template")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000228 oo.pOnuDB.LogMeDb(ctx)
229 fsmMsg = cmn.LoadMibTemplateOk
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000230 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000231 logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000232 fsmMsg = cmn.LoadMibTemplateFailed
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000233
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000234 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
235 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); exist {
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000236 if mibTemplateIsGenerated {
237 logger.Debugw(ctx,
238 "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map",
239 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000240 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000241 }
242 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000243 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000244 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000245 mibSyncMsg := cmn.Message{
246 Type: cmn.TestMsg,
247 Data: cmn.TestMessage{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000248 TestMessageVal: fsmMsg,
249 },
250 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000251 oo.PMibUploadFsm.CommChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000252}
253
dbainbri4d3a0dc2020-12-02 00:33:42 +0000254func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
255 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send MibUpload in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000256 _ = oo.PDevOmciCC.SendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000257 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
258 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000259 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000260 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000261 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000262}
263
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000264func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000265 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000266 oo.transferSystemEvent(ctx, cmn.MibDatabaseSync)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000267 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000268 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000269 }()
270}
271
272func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000273 oo.MutexPersOnuConfig.Lock()
274 oo.SOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix())
275 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000276 if oo.mibAuditInterval > 0 {
277 logger.Debugw(ctx, "MibSync FSM", log.Fields{"trigger next Audit in State": e.FSM.Current(), "oo.mibAuditInterval": oo.mibAuditInterval, "device-id": oo.deviceID})
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000278 go func() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000279 time.Sleep(oo.mibAuditInterval)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000280 if err := oo.PMibUploadFsm.PFsm.Event(UlEvAuditMib); err != nil {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000281 logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err})
282 }
283 }()
284 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000285}
286
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000287func (oo *OnuDeviceEntry) enterVerifyingAndStoringTPsState(ctx context.Context, e *fsm.Event) {
288 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start verifying and storing TPs in State": e.FSM.Current(), "device-id": oo.deviceID})
289
Holger Hildebrandt80f57762022-02-16 10:03:24 +0000290 if oo.getAllStoredTpInstFromParentAdapter(ctx) {
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000291 logger.Debugw(ctx, "MibSync FSM", log.Fields{"reconciling - verifying TPs successful": e.FSM.Current(), "device-id": oo.deviceID})
292 go func() {
293 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
294 }()
295 } else {
296 logger.Debugw(ctx, "MibSync FSM", log.Fields{"reconciling - verifying TPs not successful": e.FSM.Current(), "device-id": oo.deviceID})
297 oo.baseDeviceHandler.SetReconcilingReasonUpdate(true)
298 go func() {
299 if err := oo.baseDeviceHandler.StorePersistentData(ctx); err != nil {
300 logger.Warnw(ctx, "reconciling - store persistent data error - continue for now as there will be additional write attempts",
301 log.Fields{"device-id": oo.deviceID, "err": err})
302 }
303 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
304 }()
305 }
306}
307
dbainbri4d3a0dc2020-12-02 00:33:42 +0000308func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
309 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 +0000310 oo.requestMdsValue(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000311}
312
dbainbri4d3a0dc2020-12-02 00:33:42 +0000313func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
314 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
315 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000316 // TODOs:
317 // VOL-3805 - Provide exclusive OMCI channel for one FSM
318 // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go
319 // VOL-3792 - Support periodical audit via mib resync
320 // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000321}
322
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000323func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) {
324 logger.Debugw(ctx, "MibSync FSM",
325 log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID})
326
327 if oo.getMibFromTemplate(ctx) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000328 oo.baseDeviceHandler.StartReconciling(ctx, true)
329 oo.baseDeviceHandler.AddAllUniPorts(ctx)
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000330 _ = oo.baseDeviceHandler.ReasonUpdate(ctx, cmn.DrInitialMibDownloaded, oo.baseDeviceHandler.IsReconcilingReasonUpdate())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000331 oo.baseDeviceHandler.SetReadyForOmciConfig(true)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000332
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000333 if !oo.baseDeviceHandler.GetCollectorIsRunning() {
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000334 // Start PM collector routine
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000335 go oo.baseDeviceHandler.StartCollector(ctx)
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000336 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000337 if !oo.baseDeviceHandler.GetAlarmManagerIsRunning(ctx) {
338 go oo.baseDeviceHandler.StartAlarmManager(ctx)
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000339 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700340
341 for _, uniPort := range *oo.baseDeviceHandler.GetUniEntityMap() {
342 // only if this port was enabled for use by the operator at startup
343 if (1<<uniPort.UniID)&oo.baseDeviceHandler.GetUniPortMask() == (1 << uniPort.UniID) {
344 if !oo.baseDeviceHandler.GetFlowMonitoringIsRunning(uniPort.UniID) {
345 go oo.baseDeviceHandler.PerOnuFlowHandlerRoutine(uniPort.UniID)
346 }
347 }
348 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000349 oo.MutexPersOnuConfig.RLock()
350 if oo.SOnuPersistentData.PersUniDisableDone {
351 oo.MutexPersOnuConfig.RUnlock()
352 oo.baseDeviceHandler.DisableUniPortStateUpdate(ctx)
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000353 _ = oo.baseDeviceHandler.ReasonUpdate(ctx, cmn.DrOmciAdminLock, oo.baseDeviceHandler.IsReconcilingReasonUpdate())
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000354 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000355 oo.MutexPersOnuConfig.RUnlock()
356 oo.baseDeviceHandler.EnableUniPortStateUpdate(ctx)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000357 }
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000358
359 // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm
360
361 if oo.baseDeviceHandler.ReconcileDeviceTechProf(ctx) {
362 // start go routine with select() on reconciling flow channel before
363 // starting flow reconciling process to prevent loss of any signal
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +0000364 syncChannel := make(chan struct{})
365 go func(aSyncChannel chan struct{}) {
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000366 // In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until
367 // we get a signal that the processing of the last step to rebuild the adapter internal
368 // flow data is finished.
369 expiry := oo.baseDeviceHandler.GetReconcileExpiryVlanConfigAbort()
370 oo.setReconcilingFlows(true)
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +0000371 aSyncChannel <- struct{}{}
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000372 select {
373 case success := <-oo.chReconcilingFlowsFinished:
374 if success {
375 logger.Debugw(ctx, "reconciling flows has been finished in time",
376 log.Fields{"device-id": oo.deviceID})
377 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
378
379 } else {
380 logger.Debugw(ctx, "wait for reconciling flows aborted",
381 log.Fields{"device-id": oo.deviceID})
382 }
383 case <-time.After(expiry):
384 logger.Errorw(ctx, "timeout waiting for reconciling flows to be finished!",
385 log.Fields{"device-id": oo.deviceID, "expiry": expiry})
386 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
387 }
388 oo.setReconcilingFlows(false)
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +0000389 }(syncChannel)
390 // block further processing until the above Go routine has really started
391 // and is ready to receive values from chReconcilingFlowsFinished
392 <-syncChannel
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000393 oo.baseDeviceHandler.ReconcileDeviceFlowConfig(ctx)
394 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000395 } else {
396 logger.Debugw(ctx, "MibSync FSM",
397 log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID})
398 go func() {
399 //switch to reconciling with OMCI config
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000400 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000401 }()
402 }
403}
404
dbainbri4d3a0dc2020-12-02 00:33:42 +0000405func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000406 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 +0000407 if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000408 oo.requestMdsValue(ctx)
409 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000410 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 +0000411 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000412 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000413 }()
414 }
415}
416
417func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
418 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 +0000419 if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000420 oo.requestMdsValue(ctx)
421 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000422 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 +0000423 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000424 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000425 }()
426 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000427}
428
dbainbri4d3a0dc2020-12-02 00:33:42 +0000429func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
430 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
431 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000432}
433
dbainbri4d3a0dc2020-12-02 00:33:42 +0000434func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
435 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 -0800436 oo.mutexMibSyncMsgProcessorRunning.Lock()
437 oo.mibSyncMsgProcessorRunning = true
438 oo.mutexMibSyncMsgProcessorRunning.Unlock()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000439loop:
440 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000441 // case <-ctx.Done():
442 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
443 // break loop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000444 message, ok := <-oo.PMibUploadFsm.CommChan
Himani Chawla4d908332020-08-31 12:30:20 +0530445 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000446 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 -0800447 oo.mutexMibSyncMsgProcessorRunning.Lock()
448 oo.mibSyncMsgProcessorRunning = false
449 oo.mutexMibSyncMsgProcessorRunning.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530450 break loop
451 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000452 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000453
Himani Chawla4d908332020-08-31 12:30:20 +0530454 switch message.Type {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000455 case cmn.TestMsg:
456 msg, _ := message.Data.(cmn.TestMessage)
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000457 if msg.TestMessageVal == cmn.AbortMessageProcessing {
458 logger.Debugw(ctx, "MibSync Msg abort ProcessMsg", log.Fields{"for device-id": oo.deviceID})
Girish Gowdra37c9d912022-02-08 16:24:57 -0800459 oo.mutexMibSyncMsgProcessorRunning.Lock()
460 oo.mibSyncMsgProcessorRunning = false
461 oo.mutexMibSyncMsgProcessorRunning.Unlock()
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000462 break loop
463 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000464 oo.handleTestMsg(ctx, msg)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000465 case cmn.OMCI:
466 msg, _ := message.Data.(cmn.OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000467 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530468 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000469 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 +0000470 }
471 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000472 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000473 // TODO: only this action?
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000474 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000475}
476
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000477func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg cmn.TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000478
dbainbri4d3a0dc2020-12-02 00:33:42 +0000479 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 +0000480
481 switch msg.TestMessageVal {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000482 case cmn.LoadMibTemplateFailed:
483 _ = oo.PMibUploadFsm.PFsm.Event(UlEvUploadMib)
484 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.PMibUploadFsm.PFsm.Current())})
485 case cmn.LoadMibTemplateOk:
486 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
487 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.PMibUploadFsm.PFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000488 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000489 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 +0000490 }
491}
492
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000493func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
494 if oo.PMibUploadFsm.PFsm.Is(UlStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530495 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
496 if msgLayer != nil {
497 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
498 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000499 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530500 if msgObj.Result == me.Success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000501 oo.MutexPersOnuConfig.Lock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000502 oo.SOnuPersistentData.PersMibDataSyncAdpt = cmn.MdsDefaultMib
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000503 oo.MutexPersOnuConfig.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530504 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000505 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530506 return
507 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000508 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530509 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000510 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530511 }
512 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000513 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530514 }
515 } else {
mpagenko01499812021-03-25 10:37:12 +0000516 //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset
517 // with Sequence number 0x8000 as last request before - so it may still respond to that
518 // 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 +0000519 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000520 if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
521 logger.Debugw(ctx, "MibSync FSM - repeat MdsGetRequest (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000522 requestedAttributes := me.AttributeValueMap{me.OnuData_MibDataSync: ""}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000523 _, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
524 me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300525 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000526 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300527 logger.Errorw(ctx, "ONUData get failed, aborting MibSync", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000528 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300529 return
530 }
mpagenko01499812021-03-25 10:37:12 +0000531 //TODO: needs extra handling of timeouts
532 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000533 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000534 return
535 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000536 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000537 logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
538 //perhaps some still lingering message from some prior activity, let's wait for the real response
539 return
Himani Chawla4d908332020-08-31 12:30:20 +0530540 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000541 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000542 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530543}
544
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000545func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530546 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
547 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000548 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530549 return
550 }
551 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
552 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000553 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530554 return
555 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000556 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530557 /* to be verified / reworked !!! */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000558 oo.PDevOmciCC.UploadNoOfCmds = msgObj.NumberOfCommands
559 if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds {
560 _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000561 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
562 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000563 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000564 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000565 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530566 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000567 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 +0530568 //TODO right action?
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000569 _ = oo.PMibUploadFsm.PFsm.Event(UlEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530570 }
571}
572
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000573func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530574 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
Andrea Campanella6515c582020-10-05 11:25:00 +0200575
mpagenko7033f4e2021-11-19 18:04:22 +0000576 if msgLayer != nil {
577 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
578 if !msgOk {
579 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
580 return
mpagenko836a1fd2021-11-01 16:12:42 +0000581 }
mpagenko7033f4e2021-11-19 18:04:22 +0000582 meName := msgObj.ReportedME.GetName()
583 meClassID := msgObj.ReportedME.GetClassID()
584 meEntityID := msgObj.ReportedME.GetEntityID()
585
586 logger.Debugw(ctx, "MibUploadNextResponse Data for:", log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
587
588 if meName == devdb.CUnknownItuG988ManagedEntity || meName == devdb.CUnknownVendorSpecificManagedEntity {
Holger Hildebrandt39080022022-03-16 10:03:17 +0000589 logger.Debugw(ctx, "MibUploadNextResponse contains unknown ME", log.Fields{"device-id": oo.deviceID,
590 "Me-Name": devdb.UnknownMeOrAttribName(meName), "Me-ClassId": meClassID, "Me-InstId": meEntityID,
591 "unknown mask": msgObj.ReportedME.GetAttributeMask(), "unknown attributes": msgObj.BaseLayer.Payload})
592 oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.UnknownMeOrAttribName(meName), meClassID, meEntityID,
593 msgObj.ReportedME.GetAttributeMask(), msgObj.BaseLayer.Payload[devdb.CStartUnknownMeAttribsInBaseLayerPayload:])
mpagenko7033f4e2021-11-19 18:04:22 +0000594 } else {
595 //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
596 if unknownAttrLayer := (*msg.OmciPacket).Layer(omci.LayerTypeUnknownAttributes); unknownAttrLayer != nil {
597 logger.Warnw(ctx, "MibUploadNextResponse contains unknown attributes", log.Fields{"device-id": oo.deviceID})
598 if unknownAttributes, ok := unknownAttrLayer.(*omci.UnknownAttributes); ok {
599 // provide a loop over several ME's here already in preparation of OMCI extended message format
600 for _, unknown := range unknownAttributes.Attributes {
601 unknownAttrClassID := unknown.EntityClass // ClassID
602 unknownAttrInst := unknown.EntityInstance // uint16
603 unknownAttrMask := unknown.AttributeMask // ui
604 unknownAttrBlob := unknown.AttributeData // []byte
605 logger.Warnw(ctx, "unknown attributes detected for", log.Fields{"device-id": oo.deviceID,
606 "Me-ClassId": unknownAttrClassID, "Me-InstId": unknownAttrInst, "unknown mask": unknownAttrMask,
607 "unknown attributes": unknownAttrBlob})
Holger Hildebrandt39080022022-03-16 10:03:17 +0000608 oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.CUnknownAttributesManagedEntity, unknown.EntityClass, unknown.EntityInstance, unknown.AttributeMask, unknown.AttributeData)
mpagenko7033f4e2021-11-19 18:04:22 +0000609 } // for all included ME's with unknown attributes
610 } else {
611 logger.Errorw(ctx, "unknownAttrLayer could not be decoded", log.Fields{"device-id": oo.deviceID})
612 }
613 }
614 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, msgObj.ReportedME.GetAttributeValueMap())
615 }
616 } else {
617 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
618 //as long as omci-lib does not support decoding of table attribute as 'unknown/unspecified' attribute
619 // we have to verify, if this failure is from table attribute and try to go forward with ignoring the complete message
620 errLayer := (*msg.OmciPacket).Layer(gopacket.LayerTypeDecodeFailure)
621 if failure, decodeOk := errLayer.(*gopacket.DecodeFailure); decodeOk {
622 errMsg := failure.String()
623 if !strings.Contains(strings.ToLower(errMsg), "table decode") {
624 //something still unexected happened, needs deeper investigation - stop complete MIB upload process (timeout)
625 return
626 }
627 logger.Warnw(ctx, "Decode issue on received MibUploadNextResponse frame - found table attribute(s) (message ignored)",
628 log.Fields{"device-id": oo.deviceID, "issue": errMsg})
629 }
Himani Chawla4d908332020-08-31 12:30:20 +0530630 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000631 if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds {
632 _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000633 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
634 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000635 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000636 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000637 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530638 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000639 oo.pOnuDB.LogMeDb(ctx)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000640 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530641 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000642 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 +0530643 }
644
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000645 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530646 }
647}
648
Girish Gowdra21bbf052022-02-17 16:08:22 -0800649// nolint: gocyclo
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000650func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg cmn.OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000651 var err error = nil
mpagenko01499812021-03-25 10:37:12 +0000652
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000653 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000654 if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType ||
655 oo.lastTxParamStruct.pLastTxMeInstance == nil {
656 //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest
657 // with Sequence number 0x8000 as last request before - so it may still respond to that
658 // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number
659 if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
660 logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000661 _ = oo.PDevOmciCC.SendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000662 //TODO: needs extra handling of timeouts
663 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000664 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000665 return nil
666 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000667 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000668 logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
669 //perhaps some still lingering message from some prior activity, let's wait for the real response
670 return nil
671 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000672 oo.mutexLastTxParamStruct.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530673 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000674 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000675 logger.Errorw(ctx, "omci Msg layer could not be detected for GetResponse - handling of MibSyncChan stopped", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000676 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000677 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 +0000678 }
679 msgObj, msgOk := msgLayer.(*omci.GetResponse)
680 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000681 logger.Errorw(ctx, "omci Msg layer could not be assigned for GetResponse - handling of MibSyncChan stopped", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000682 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000683 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 +0000684 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000685 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000686 if msgObj.Result == me.Success {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000687 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000688 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
689 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000690 meAttributes := msgObj.Attributes
mpagenko01499812021-03-25 10:37:12 +0000691 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000692 logger.Debugf(ctx, "MibSync FSM - GetResponse Data for %s", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000693 switch meInstance {
694 case "OnuG":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000695 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000696 if onuGVendorID, ok := meAttributes[me.OnuG_VendorId]; ok {
697 vendorID := cmn.TrimStringFromMeOctet(onuGVendorID)
698 if vendorID == "" {
699 logger.Infow(ctx, "MibSync FSM - mandatory attribute VendorId is empty in OnuG instance - fill with appropriate value", log.Fields{"device-id": oo.deviceID})
700 vendorID = cEmptyVendorIDString
701 }
702 oo.MutexPersOnuConfig.Lock()
703 oo.SOnuPersistentData.PersVendorID = vendorID
704 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000705 } else {
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000706 logger.Errorw(ctx, "MibSync FSM - mandatory attribute VendorId not present in OnuG instance - handling of MibSyncChan stopped!",
707 log.Fields{"device-id": oo.deviceID})
708 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
709 return fmt.Errorf("mibSync FSM - mandatory attribute VendorId not present in OnuG instance - handling of MibSyncChan stopped: %s", oo.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530710 }
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000711 if onuGSerialNumber, ok := meAttributes[me.OnuG_SerialNumber]; ok {
712 oo.MutexPersOnuConfig.Lock()
713 snBytes, _ := me.InterfaceToOctets(onuGSerialNumber)
714 if cmn.OnugSerialNumberLen == len(snBytes) {
715 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
716 snNumberPart := hex.EncodeToString(snBytes[4:])
717 oo.SOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart
718 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-G - VendorId/SerialNumber", log.Fields{"device-id": oo.deviceID,
719 "onuDeviceEntry.vendorID": oo.SOnuPersistentData.PersVendorID, "onuDeviceEntry.serialNumber": oo.SOnuPersistentData.PersSerialNumber})
720 } else {
721 logger.Infow(ctx, "MibSync FSM - SerialNumber has wrong length - fill serialNumber with zeros", log.Fields{"device-id": oo.deviceID, "length": len(snBytes)})
722 oo.SOnuPersistentData.PersSerialNumber = cEmptySerialNumberString
723 }
724 oo.MutexPersOnuConfig.Unlock()
725 } else {
726 logger.Errorw(ctx, "MibSync FSM - mandatory attribute SerialNumber not present in OnuG instance - handling of MibSyncChan stopped!",
727 log.Fields{"device-id": oo.deviceID})
728 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
729 return fmt.Errorf("mibSync FSM - mandatory attribute SerialNumber not present in OnuG instance - handling of MibSyncChan stopped: %s", oo.deviceID)
730 }
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000731 // trigger retrieval of EquipmentId
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000732 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000733 return nil
734 case "Onu2G":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000735 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000736 var equipmentID string
737 if onu2GEquipmentID, ok := meAttributes[me.Onu2G_EquipmentId]; ok {
738 equipmentID = cmn.TrimStringFromMeOctet(onu2GEquipmentID)
739 if equipmentID == "" {
740 logger.Infow(ctx, "MibSync FSM - optional attribute EquipmentID is empty in Onu2G instance - fill with appropriate value", log.Fields{"device-id": oo.deviceID})
741 equipmentID = cEmptyEquipIDString
742 }
743 } else {
744 logger.Infow(ctx, "MibSync FSM - optional attribute EquipmentID not present in Onu2G instance - fill with appropriate value", log.Fields{"device-id": oo.deviceID})
745 equipmentID = cNotPresentEquipIDString
746 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000747 oo.MutexPersOnuConfig.Lock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000748 oo.SOnuPersistentData.PersEquipmentID = equipmentID
dbainbri4d3a0dc2020-12-02 00:33:42 +0000749 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000750 "onuDeviceEntry.equipmentID": oo.SOnuPersistentData.PersEquipmentID})
751 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000752
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000753 // trigger retrieval of 1st SW-image info
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000754 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000755 return nil
756 case "SoftwareImage":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000757 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000758 if entityID > cmn.SecondSwImageMeID {
mpagenko15ff4a52021-03-02 10:09:20 +0000759 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
760 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
761 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
762 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000763 }
mpagenko15ff4a52021-03-02 10:09:20 +0000764 // need to use function for go lint complexity
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000765 if !oo.HandleSwImageIndications(ctx, entityID, meAttributes) {
766 logger.Errorw(ctx, "MibSync FSM - Not all mandatory attributes present in in SoftwareImage instance - handling of MibSyncChan stopped!", log.Fields{"device-id": oo.deviceID})
767 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
768 return fmt.Errorf("mibSync FSM - Not all mandatory attributes present in in SoftwareImage instance - handling of MibSyncChan stopped: %s", oo.deviceID)
769 }
mpagenko15ff4a52021-03-02 10:09:20 +0000770 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000771 case "IpHostConfigData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000772 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000773 oo.MutexPersOnuConfig.Lock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000774 if ipHostConfigMacAddress, ok := meAttributes[me.IpHostConfigData_MacAddress]; ok {
Girish Gowdra21bbf052022-02-17 16:08:22 -0800775 macBytes, _ := me.InterfaceToOctets(ipHostConfigMacAddress)
776 if cmn.OmciMacAddressLen == len(macBytes) {
777 oo.SOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:])
778 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
779 "macAddress": oo.SOnuPersistentData.PersMacAddress})
780 } else {
781 logger.Infow(ctx, "MibSync FSM - MacAddress wrong length - fill macAddress with zeros", log.Fields{"device-id": oo.deviceID, "length": len(macBytes)})
782 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
783 }
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000784 } else {
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000785 // since ONU creates instances of this ME automatically only when IP host services are available, processing continues here despite the error
786 logger.Infow(ctx, "MibSync FSM - MacAddress attribute not present in IpHostConfigData instance - fill macAddress with zeros", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000787 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000788 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000789 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000790 // trigger retrieval of mib template
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000791 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000792 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000793 case "OnuData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000794 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000795 if onuDataMibDataSync, ok := meAttributes[me.OnuData_MibDataSync]; ok {
796 oo.checkMdsValue(ctx, onuDataMibDataSync.(uint8))
797 } else {
798 logger.Errorw(ctx, "MibSync FSM - MibDataSync attribute not present in OnuData instance - handling of MibSyncChan stopped!", log.Fields{"device-id": oo.deviceID})
799 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
800 return fmt.Errorf("mibSync FSM - VendorId attribute not present in OnuG instance - handling of MibSyncChan stopped: %s", oo.deviceID)
801 }
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000802 return nil
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000803 default:
804 oo.mutexLastTxParamStruct.RUnlock()
805 logger.Warnw(ctx, "Unsupported ME name received!",
806 log.Fields{"ME name": meInstance, "device-id": oo.deviceID})
807
Himani Chawla4d908332020-08-31 12:30:20 +0530808 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800809 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000810 oo.mutexLastTxParamStruct.RUnlock()
811 logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ",
812 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000813 }
Himani Chawla4d908332020-08-31 12:30:20 +0530814 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000815 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000816 return nil
817 }
Himani Chawla4d908332020-08-31 12:30:20 +0530818 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000819 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000820 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000821 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530822}
823
Holger Hildebrandt94688c72021-12-17 12:13:02 +0000824//HandleSwImageIndications updates onuSwImageIndications with the ONU data just received
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000825func (oo *OnuDeviceEntry) HandleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) bool {
826
827 var imageVersion string
828 var imageIsCommitted, imageIsActive uint8
829
830 allMandAttribsPresent := false
831 if softwareImageIsCommitted, ok := meAttributes[me.SoftwareImage_IsCommitted]; ok {
832 if softwareImageIsActiveimage, ok := meAttributes[me.SoftwareImage_IsActive]; ok {
833 if softwareImageVersion, ok := meAttributes[me.SoftwareImage_Version]; ok {
834 imageVersion = cmn.TrimStringFromMeOctet(softwareImageVersion)
835 imageIsActive = softwareImageIsActiveimage.(uint8)
836 imageIsCommitted = softwareImageIsCommitted.(uint8)
837 allMandAttribsPresent = true
838 }
839 }
840 }
841 if !allMandAttribsPresent {
842 logger.Errorw(ctx, "MibSync FSM - Not all mandatory attributes present in SoftwareImage instance - skip processing!", log.Fields{"device-id": oo.deviceID})
843 return allMandAttribsPresent
844 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000845 oo.MutexPersOnuConfig.RLock()
mpagenko15ff4a52021-03-02 10:09:20 +0000846 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
847 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000848 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.SOnuPersistentData.PersSerialNumber})
849 oo.MutexPersOnuConfig.RUnlock()
850 if cmn.FirstSwImageMeID == entityID {
mpagenko15ff4a52021-03-02 10:09:20 +0000851 //always accept the state of the first image (2nd image info should not yet be available)
Holger Hildebrandt05011352021-06-15 09:40:24 +0000852 oo.mutexOnuSwImageIndications.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000853 if imageIsActive == cmn.SwIsActive {
854 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID
855 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true
856 oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion
857 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000858 //as the SW version indication may stem from some ONU Down/up event
859 //the complementary image state is to be invalidated
860 // (state of the second image is always expected afterwards or just invalid)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000861 oo.onuSwImageIndications.InActiveEntityEntry.Valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000862 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000863 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
864 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true
865 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
866 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000867 //as the SW version indication may stem form some ONU Down/up event
868 //the complementary image state is to be invalidated
869 // (state of the second image is always expected afterwards or just invalid)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000870 oo.onuSwImageIndications.ActiveEntityEntry.Valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000871 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000872 oo.mutexOnuSwImageIndications.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000873 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetSecondSwVersion)
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000874 return allMandAttribsPresent
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000875 } else if cmn.SecondSwImageMeID == entityID {
mpagenko15ff4a52021-03-02 10:09:20 +0000876 //2nd image info might conflict with first image info, in which case we priorize first image info!
Holger Hildebrandt05011352021-06-15 09:40:24 +0000877 oo.mutexOnuSwImageIndications.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000878 if imageIsActive == cmn.SwIsActive { //2nd image reported to be active
879 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
mpagenko15ff4a52021-03-02 10:09:20 +0000880 //conflict exists - state of first image is left active
881 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
882 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000883 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
884 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true ////to indicate that at least something has been reported
885 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
886 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000887 } else { //first image inactive, this one active
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000888 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID
889 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true
890 oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion
891 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000892 }
893 } else { //2nd image reported to be inactive
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000894 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
mpagenko15ff4a52021-03-02 10:09:20 +0000895 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
896 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
897 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000898 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = cmn.FirstSwImageMeID
899 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true //to indicate that at least something has been reported
mpagenko15ff4a52021-03-02 10:09:20 +0000900 //copy active commit/version from the previously stored inactive position
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000901 oo.onuSwImageIndications.ActiveEntityEntry.Version = oo.onuSwImageIndications.InActiveEntityEntry.Version
902 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000903 }
904 //in any case we indicate (and possibly overwrite) the second image indications as inactive
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000905 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
906 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true
907 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
908 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000909 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000910 oo.mutexOnuSwImageIndications.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000911 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMacAddress)
mpagenko15ff4a52021-03-02 10:09:20 +0000912 }
Holger Hildebrandtfdb4bba2022-03-10 12:12:59 +0000913 return allMandAttribsPresent
mpagenko15ff4a52021-03-02 10:09:20 +0000914}
915
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000916func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000917 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200918 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000919 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
920 switch msg.OmciMsg.MessageType {
921 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000922 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000923
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000924 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000925 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530926
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000927 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000928 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000929
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000930 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000931 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000932 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530933
Andrea Campanella6515c582020-10-05 11:25:00 +0200934 default:
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000935 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"device-id": oo.deviceID, "msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200936
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000937 }
938}
939
dbainbri4d3a0dc2020-12-02 00:33:42 +0000940func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000941 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000942 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 +0000943 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
944 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000945 oo.mutexLastTxParamStruct.RLock()
946 if oo.lastTxParamStruct.pLastTxMeInstance != nil {
947 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
948 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
949 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
950 switch meInstance {
951 case "IpHostConfigData":
952 oo.mutexLastTxParamStruct.RUnlock()
953 logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros",
954 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000955 oo.MutexPersOnuConfig.Lock()
956 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
957 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000958 // trigger retrieval of mib template
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000959 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000960 return nil
961 default:
962 oo.mutexLastTxParamStruct.RUnlock()
963 logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
964 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
965 }
966 } else {
967 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000968 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000969 } else {
970 oo.mutexLastTxParamStruct.RUnlock()
971 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000972 }
973 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000974 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 +0000975 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
976 }
977 return err
978}
979
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000980// IsNewOnu - TODO: add comment
981func (oo *OnuDeviceEntry) IsNewOnu() bool {
982 oo.MutexPersOnuConfig.RLock()
983 defer oo.MutexPersOnuConfig.RUnlock()
984 return oo.SOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000985}
986
Himani Chawla6d2ae152020-09-02 13:11:20 +0530987func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000988 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530989 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000990 return true
991 }
992 }
993 return false
994}
995
dbainbri4d3a0dc2020-12-02 00:33:42 +0000996func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
997 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000998 return errors.New("not_implemented")
999}
1000
Himani Chawla6d2ae152020-09-02 13:11:20 +05301001// 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 +05301002// 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 +00001003// 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 +00001004func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
1005 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001006 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +05301007
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001008 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
1009 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); exist {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001010 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001011 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001012 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001013 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001014 return nil
1015 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001016 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001017 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1018 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001019 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001020 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1021 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001022 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, true)
1023 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001024
1025 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +05301026 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +00001027 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +05301028 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
1029
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001030 firstLevelMap := oo.pOnuDB.MeDb
divyadesaibbed37c2020-08-28 13:35:20 +05301031 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001032 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +05301033 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +05301034
1035 secondLevelMap := make(map[string]interface{})
1036 for secondLevelKey, secondLevelValue := range firstLevelValue {
Holger Hildebrandt8998ed52022-03-23 09:52:37 +00001037 // ManagedEntityId is already key of secondLevelMap - remove this redundant attribute from secondLevelValue
1038 delete(secondLevelValue, cmn.CGenericManagedEntityIDName)
divyadesaibbed37c2020-08-28 13:35:20 +05301039 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +05301040 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +05301041 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +05301042 secondLevelMap[entityID] = thirdLevelMap
1043 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +05301044 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
1045 delete(forthLevelMap, "SerialNumber")
1046 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
1047
1048 }
Himani Chawla26e555c2020-08-31 12:30:20 +05301049 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +05301050 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
1051 delete(forthLevelMap, "MacAddress")
1052 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
1053 }
1054 }
Himani Chawla26e555c2020-08-31 12:30:20 +05301055 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +05301056 }
Holger Hildebrandt39080022022-03-16 10:03:17 +00001057 unknownMeAndAttribMap := oo.pOnuDB.UnknownMeAndAttribDb
1058 for unknownMeAndAttribMapKey := range unknownMeAndAttribMap {
1059 templateMap[string(unknownMeAndAttribMapKey)] = unknownMeAndAttribMap[unknownMeAndAttribMapKey]
Holger Hildebrandtf3c7a182021-11-17 13:42:08 +00001060 }
divyadesaibbed37c2020-08-28 13:35:20 +05301061 mibTemplate, err := json.Marshal(&templateMap)
1062 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001063 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001064 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
1065 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
1066 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
divyadesaibbed37c2020-08-28 13:35:20 +05301067 return err
1068 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001069 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +05301070 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001071 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 +00001072 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
1073 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
1074 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
divyadesaibbed37c2020-08-28 13:35:20 +05301075 return err
1076 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001077 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +05301078 return nil
1079}
1080
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +00001081func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
1082 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001083 requestedAttributes := me.AttributeValueMap{me.OnuData_MibDataSync: ""}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001084 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
1085 me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +00001086 //accept also nil as (error) return value for writing to LastTx
1087 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +03001088 if err != nil {
1089 logger.Errorw(ctx, "ONUData get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001090 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +03001091 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001092 go func(a_pAFsm *cmn.AdapterFsm) {
1093 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +03001094 }(pMibUlFsm)
1095 }
1096 return
1097 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001098 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +00001099 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
1100 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
1101 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001102 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +00001103}
1104
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001105func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001106 oo.MutexPersOnuConfig.RLock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001107 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001108 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.SOnuPersistentData.PersMibDataSyncAdpt})
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001109
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001110 mdsValuesAreEqual := oo.SOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
1111 oo.MutexPersOnuConfig.RUnlock()
1112 if oo.PMibUploadFsm.PFsm.Is(UlStAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001113 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001114 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001115 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001116 } else {
1117 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 +00001118 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001119 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001120 } else if oo.PMibUploadFsm.PFsm.Is(UlStReAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001121 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001122 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001123 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001124 } else {
Holger Hildebrandt80f57762022-02-16 10:03:24 +00001125 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 +00001126 log.Fields{"device-id": oo.deviceID})
1127 oo.SendOnuDeviceEvent(ctx, cmn.OnuMibAuditFailureMds, cmn.OnuMibAuditFailureMdsDesc)
Holger Hildebrandt80f57762022-02-16 10:03:24 +00001128 // To reconcile ONU with active adapter later on, we have to retrieve TP instances from parent adapter.
1129 // In the present use case inconsistencies between TP pathes stored in kv store and TP instances retrieved
1130 // should not occur. Nevertheless, the respective code is inserted to catch the unlikely case.
1131 if !oo.getAllStoredTpInstFromParentAdapter(ctx) {
1132 logger.Debugw(ctx, "MibSync FSM - mib reaudit - inconsistencies between TP pathes stored in kv and parent adapter instances",
1133 log.Fields{"device-id": oo.deviceID})
1134 oo.baseDeviceHandler.SetReconcilingReasonUpdate(true)
1135 go func() {
1136 if err := oo.baseDeviceHandler.StorePersistentData(ctx); err != nil {
1137 logger.Warnw(ctx,
1138 "MibSync FSM - mib reaudit - store persistent data error - continue for now as there will be additional write attempts",
1139 log.Fields{"device-id": oo.deviceID, "err": err})
1140 }
1141 }()
1142 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001143 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001144 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001145 } else if oo.PMibUploadFsm.PFsm.Is(UlStExaminingMds) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001146 if mdsValuesAreEqual && mibDataSyncOnu != 0 {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001147 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001148 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001149 } else {
1150 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001151 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001152 }
1153 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001154 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 +00001155 }
1156}
mpagenko15ff4a52021-03-02 10:09:20 +00001157
1158//GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
1159func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001160 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001161 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
1162 value := oo.onuSwImageIndications.ActiveEntityEntry.EntityID
Holger Hildebrandt05011352021-06-15 09:40:24 +00001163 oo.mutexOnuSwImageIndications.RUnlock()
1164 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +00001165 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001166 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001167 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
1168}
1169
1170//GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
1171func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001172 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001173 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
1174 value := oo.onuSwImageIndications.InActiveEntityEntry.EntityID
Holger Hildebrandt05011352021-06-15 09:40:24 +00001175 oo.mutexOnuSwImageIndications.RUnlock()
1176 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +00001177 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001178 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001179 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
1180}
1181
1182//IsImageToBeCommitted returns true if the active image is still uncommitted
1183func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001184 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001185 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
1186 if oo.onuSwImageIndications.ActiveEntityEntry.EntityID == aImageID {
1187 if oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted == cmn.SwIsUncommitted {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001188 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001189 return true
1190 }
1191 }
1192 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001193 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001194 return false //all other case are treated as 'nothing to commit
1195}
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001196func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool {
1197
1198 oo.mibTemplatePath = oo.buildMibTemplatePath()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +00001199 logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath),
1200 "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001201
1202 restoredFromMibTemplate := false
1203 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
1204 if err == nil {
1205 if Value != nil {
1206 logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value)
1207
1208 // swap out tokens with specific data
1209 mibTmpString, _ := kvstore.ToString(Value.Value)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001210 oo.MutexPersOnuConfig.RLock()
1211 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.SOnuPersistentData.PersSerialNumber, -1)
1212 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.SOnuPersistentData.PersMacAddress, -1)
1213 oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001214 mibTmpBytes := []byte(mibTmpString)
1215 logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes)
1216
1217 var firstLevelMap map[string]interface{}
1218 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
1219 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
1220 } else {
1221 for firstLevelKey, firstLevelValue := range firstLevelMap {
1222 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
1223 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
1224 meClassID := me.ClassID(uint16ValidNumber)
1225 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
1226 if isSupportedClassID(meClassID) {
1227 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
1228 secondLevelMap := firstLevelValue.(map[string]interface{})
1229 for secondLevelKey, secondLevelValue := range secondLevelMap {
1230 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
1231 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
1232 meEntityID := uint16(uint16ValidNumber)
1233 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
1234 thirdLevelMap := secondLevelValue.(map[string]interface{})
1235 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
1236 if thirdLevelKey == "Attributes" {
1237 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
1238 attributesMap := thirdLevelValue.(map[string]interface{})
1239 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
1240 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
1241 restoredFromMibTemplate = true
1242 }
1243 }
1244 }
1245 }
1246 }
1247 }
1248 }
1249 }
1250 } else {
1251 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1252 }
1253 } else {
1254 logger.Errorf(ctx, "Get from kvstore operation failed for path",
1255 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1256 }
1257 return restoredFromMibTemplate
1258}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001259
Holger Hildebrandt80f57762022-02-16 10:03:24 +00001260func (oo *OnuDeviceEntry) getAllStoredTpInstFromParentAdapter(ctx context.Context) bool {
1261
1262 allTpInstPresent := true
1263 oo.MutexPersOnuConfig.Lock()
1264 oo.MutexReconciledTpInstances.Lock()
1265 for indexUni, uniData := range oo.SOnuPersistentData.PersUniConfig {
1266 uniID := uniData.PersUniID
1267 oo.ReconciledTpInstances[uniID] = make(map[uint8]inter_adapter.TechProfileDownloadMessage)
1268 for tpID, tpPath := range uniData.PersTpPathMap {
1269 if tpPath != "" {
1270 // Request the TP instance from the openolt adapter
1271 iaTechTpInst, err := oo.baseDeviceHandler.GetTechProfileInstanceFromParentAdapter(ctx, uniID, tpPath)
1272 if err == nil && iaTechTpInst != nil {
1273 logger.Debugw(ctx, "reconciling - store Tp instance", log.Fields{"uniID": uniID, "tpID": tpID,
1274 "*iaTechTpInst": iaTechTpInst, "device-id": oo.deviceID})
1275 oo.ReconciledTpInstances[uniID][tpID] = *iaTechTpInst
1276 } else {
1277 // During the absence of the ONU adapter there seem to have been TP specific configurations!
1278 // The no longer available TP and the associated flows must be deleted from the ONU KV store
1279 // and after a MIB reset a new reconciling attempt with OMCI configuration must be started.
1280 allTpInstPresent = false
1281 logger.Infow(ctx, "reconciling - can't get tp instance - delete tp and associated flows",
1282 log.Fields{"tp-id": tpID, "tpPath": tpPath, "uni-id": uniID, "device-id": oo.deviceID, "err": err})
1283 delete(oo.SOnuPersistentData.PersUniConfig[indexUni].PersTpPathMap, tpID)
1284 flowSlice := oo.SOnuPersistentData.PersUniConfig[indexUni].PersFlowParams
1285 for indexFlow, flowData := range flowSlice {
1286 if flowData.VlanRuleParams.TpID == tpID {
1287 if len(flowSlice) == 1 {
1288 flowSlice = []cmn.UniVlanFlowParams{}
1289 } else {
1290 flowSlice = append(flowSlice[:indexFlow], flowSlice[indexFlow+1:]...)
1291 }
1292 oo.SOnuPersistentData.PersUniConfig[indexUni].PersFlowParams = flowSlice
1293 }
1294 }
1295 }
1296 }
1297 }
1298 }
1299 oo.MutexReconciledTpInstances.Unlock()
1300 oo.MutexPersOnuConfig.Unlock()
1301 return allTpInstPresent
1302}
1303
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001304//CancelProcessing terminates potentially running reconciling processes and stops the FSM
1305func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) {
1306
mpagenko101ac942021-11-16 15:01:29 +00001307 if oo.isReconcilingFlows() {
Holger Hildebrandtf2fcdd42021-12-15 11:42:19 +00001308 oo.SendChReconcilingFlowsFinished(ctx, false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001309 }
1310 //the MibSync FSM might be active all the ONU-active time,
1311 // hence it must be stopped unconditionally
Girish Gowdra37c9d912022-02-08 16:24:57 -08001312 oo.mutexMibSyncMsgProcessorRunning.RLock()
1313 defer oo.mutexMibSyncMsgProcessorRunning.RUnlock()
1314 if oo.mibSyncMsgProcessorRunning {
1315 pMibUlFsm := oo.PMibUploadFsm
1316 if pMibUlFsm != nil {
1317 // abort running message processing
1318 fsmAbortMsg := cmn.Message{
1319 Type: cmn.TestMsg,
1320 Data: cmn.TestMessage{
1321 TestMessageVal: cmn.AbortMessageProcessing,
1322 },
1323 }
1324 pMibUlFsm.CommChan <- fsmAbortMsg
1325 _ = pMibUlFsm.PFsm.Event(UlEvStop)
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00001326 }
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001327 }
1328}