blob: a26422dd4bed0f16060106e67429b114e70fdb40 [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
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000033 "github.com/opencord/omci-lib-go"
34 me "github.com/opencord/omci-lib-go/generated"
khenaidoo7d3c5582021-08-11 18:09:44 -040035 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
36 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000037 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
38 devdb "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000039)
40
mpagenko01499812021-03-25 10:37:12 +000041type sLastTxMeParameter struct {
42 lastTxMessageType omci.MessageType
43 pLastTxMeInstance *me.ManagedEntity
44 repeatCount uint8
45}
46
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000047var supportedClassIds = []me.ClassID{
48 me.CardholderClassID, // 5
49 me.CircuitPackClassID, // 6
50 me.SoftwareImageClassID, // 7
51 me.PhysicalPathTerminationPointEthernetUniClassID, // 11
ozgecanetsia124d9732021-09-16 14:31:57 +030052 me.PhysicalPathTerminationPointPotsUniClassID, // 53
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000053 me.OltGClassID, // 131
54 me.OnuPowerSheddingClassID, // 133
55 me.IpHostConfigDataClassID, // 134
56 me.OnuGClassID, // 256
57 me.Onu2GClassID, // 257
58 me.TContClassID, // 262
59 me.AniGClassID, // 263
60 me.UniGClassID, // 264
61 me.PriorityQueueClassID, // 277
62 me.TrafficSchedulerClassID, // 278
63 me.VirtualEthernetInterfacePointClassID, // 329
64 me.EnhancedSecurityControlClassID, // 332
65 me.OnuDynamicPowerManagementControlClassID, // 336
66 // 347 // definitions for ME "IPv6 host config data" are currently missing in omci-lib-go!
67}
68
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000069var fsmMsg cmn.TestMessageType
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000070
dbainbri4d3a0dc2020-12-02 00:33:42 +000071func (oo *OnuDeviceEntry) enterStartingState(ctx context.Context, e *fsm.Event) {
72 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 +000073 oo.pOnuDB = devdb.NewOnuDeviceDB(log.WithSpanFromContext(context.TODO(), ctx), oo.deviceID)
dbainbri4d3a0dc2020-12-02 00:33:42 +000074 go oo.processMibSyncMessages(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000075}
76
dbainbri4d3a0dc2020-12-02 00:33:42 +000077func (oo *OnuDeviceEntry) enterResettingMibState(ctx context.Context, e *fsm.Event) {
78 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 +000079
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000080 if (!oo.IsNewOnu() && !oo.baseDeviceHandler.IsReconciling()) || //use case: re-auditing failed
81 oo.baseDeviceHandler.IsSkipOnuConfigReconciling() { //use case: reconciling without omci-config failed
82 oo.baseDeviceHandler.PrepareReconcilingWithActiveAdapter(ctx)
83 oo.devState = cmn.DeviceStatusInit
Holger Hildebrandt10d98192021-01-27 15:29:31 +000084 }
dbainbri4d3a0dc2020-12-02 00:33:42 +000085 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 +000086 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000087 _ = oo.PDevOmciCC.SendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000088 //TODO: needs to handle timeouts
mpagenko01499812021-03-25 10:37:12 +000089 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
90 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
91 oo.lastTxParamStruct.lastTxMessageType = omci.MibResetRequestType
92 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000093 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000094}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000095
dbainbri4d3a0dc2020-12-02 00:33:42 +000096func (oo *OnuDeviceEntry) enterGettingVendorAndSerialState(ctx context.Context, e *fsm.Event) {
97 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting VendorId and SerialNumber in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000098 requestedAttributes := me.AttributeValueMap{"VendorId": "", "SerialNumber": 0}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000099 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000100 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 +0000101 //accept also nil as (error) return value for writing to LastTx
102 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300103 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000104 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300105 logger.Errorw(ctx, "ONU-G get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000106 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300107 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000108 go func(a_pAFsm *cmn.AdapterFsm) {
109 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300110 }(pMibUlFsm)
111 }
112 return
113 }
mpagenko01499812021-03-25 10:37:12 +0000114 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
115 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000116 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000117}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000118
dbainbri4d3a0dc2020-12-02 00:33:42 +0000119func (oo *OnuDeviceEntry) enterGettingEquipmentIDState(ctx context.Context, e *fsm.Event) {
120 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting EquipmentId in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000121 requestedAttributes := me.AttributeValueMap{"EquipmentId": ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000122 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000123 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 +0000124 //accept also nil as (error) return value for writing to LastTx
125 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300126 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000127 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300128 logger.Errorw(ctx, "ONU2-G get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000129 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300130 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000131 go func(a_pAFsm *cmn.AdapterFsm) {
132 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300133 }(pMibUlFsm)
134 }
135 return
136 }
mpagenko01499812021-03-25 10:37:12 +0000137 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
138 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000139 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000140}
141
dbainbri4d3a0dc2020-12-02 00:33:42 +0000142func (oo *OnuDeviceEntry) enterGettingFirstSwVersionState(ctx context.Context, e *fsm.Event) {
143 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting IsActive and Version of first SW-image in State": e.FSM.Current(), "device-id": oo.deviceID})
mpagenko15ff4a52021-03-02 10:09:20 +0000144 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000145 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000146 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 +0000147 //accept also nil as (error) return value for writing to LastTx
148 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300149 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000150 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300151 logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000152 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300153 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000154 go func(a_pAFsm *cmn.AdapterFsm) {
155 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300156 }(pMibUlFsm)
157 }
158 return
159 }
mpagenko01499812021-03-25 10:37:12 +0000160 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
161 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000162 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000163}
164
dbainbri4d3a0dc2020-12-02 00:33:42 +0000165func (oo *OnuDeviceEntry) enterGettingSecondSwVersionState(ctx context.Context, e *fsm.Event) {
166 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting IsActive and Version of second SW-image in State": e.FSM.Current(), "device-id": oo.deviceID})
mpagenko15ff4a52021-03-02 10:09:20 +0000167 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000168 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000169 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 +0000170 //accept also nil as (error) return value for writing to LastTx
171 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300172 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000173 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300174 logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000175 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300176 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000177 go func(a_pAFsm *cmn.AdapterFsm) {
178 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300179 }(pMibUlFsm)
180 }
181 return
182 }
mpagenko01499812021-03-25 10:37:12 +0000183 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
184 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000185 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000186}
187
dbainbri4d3a0dc2020-12-02 00:33:42 +0000188func (oo *OnuDeviceEntry) enterGettingMacAddressState(ctx context.Context, e *fsm.Event) {
189 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting MacAddress in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000190 requestedAttributes := me.AttributeValueMap{"MacAddress": ""}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000191 oo.mutexLastTxParamStruct.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000192 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 +0000193 //accept also nil as (error) return value for writing to LastTx
194 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300195 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000196 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300197 logger.Errorw(ctx, "IpHostConfigData get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000198 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300199 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000200 go func(a_pAFsm *cmn.AdapterFsm) {
201 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300202 }(pMibUlFsm)
203 }
204 return
205 }
mpagenko01499812021-03-25 10:37:12 +0000206 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
207 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000208 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000209}
210
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000211func (oo *OnuDeviceEntry) enterGettingMibTemplateState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000212
Holger Hildebrandt05011352021-06-15 09:40:24 +0000213 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000214 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
215 oo.MutexPersOnuConfig.Lock()
216 oo.SOnuPersistentData.PersActiveSwVersion = oo.onuSwImageIndications.ActiveEntityEntry.Version
217 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt05011352021-06-15 09:40:24 +0000218 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000219 } else {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000220 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000221 logger.Errorw(ctx, "get-mib-template: no active SW version found, working with empty SW version, which might be untrustworthy",
222 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000223 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000224 if oo.getMibFromTemplate(ctx) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000225 logger.Debug(ctx, "MibSync FSM - valid MEs stored from template")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000226 oo.pOnuDB.LogMeDb(ctx)
227 fsmMsg = cmn.LoadMibTemplateOk
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000228 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000229 logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000230 fsmMsg = cmn.LoadMibTemplateFailed
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000231
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000232 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
233 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); exist {
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000234 if mibTemplateIsGenerated {
235 logger.Debugw(ctx,
236 "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map",
237 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000238 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000239 }
240 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000241 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000242 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000243 mibSyncMsg := cmn.Message{
244 Type: cmn.TestMsg,
245 Data: cmn.TestMessage{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000246 TestMessageVal: fsmMsg,
247 },
248 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000249 oo.PMibUploadFsm.CommChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000250}
251
dbainbri4d3a0dc2020-12-02 00:33:42 +0000252func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
253 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 +0000254 _ = oo.PDevOmciCC.SendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000255 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
256 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000257 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000258 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000259 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000260}
261
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000262func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000263 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 +0000264 oo.transferSystemEvent(ctx, cmn.MibDatabaseSync)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000265 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000266 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000267 }()
268}
269
270func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000271 oo.MutexPersOnuConfig.Lock()
272 oo.SOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix())
273 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000274 if oo.mibAuditInterval > 0 {
275 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 +0000276 go func() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000277 time.Sleep(oo.mibAuditInterval)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000278 if err := oo.PMibUploadFsm.PFsm.Event(UlEvAuditMib); err != nil {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000279 logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err})
280 }
281 }()
282 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000283}
284
dbainbri4d3a0dc2020-12-02 00:33:42 +0000285func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
286 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 +0000287 oo.requestMdsValue(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000288}
289
dbainbri4d3a0dc2020-12-02 00:33:42 +0000290func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
291 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
292 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000293 // TODOs:
294 // VOL-3805 - Provide exclusive OMCI channel for one FSM
295 // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go
296 // VOL-3792 - Support periodical audit via mib resync
297 // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000298}
299
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000300func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) {
301 logger.Debugw(ctx, "MibSync FSM",
302 log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID})
303
304 if oo.getMibFromTemplate(ctx) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000305 oo.baseDeviceHandler.StartReconciling(ctx, true)
306 oo.baseDeviceHandler.AddAllUniPorts(ctx)
307 oo.baseDeviceHandler.SetDeviceReason(cmn.DrInitialMibDownloaded)
308 oo.baseDeviceHandler.SetReadyForOmciConfig(true)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000309
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000310 if !oo.baseDeviceHandler.GetCollectorIsRunning() {
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000311 // Start PM collector routine
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000312 go oo.baseDeviceHandler.StartCollector(ctx)
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000313 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000314 if !oo.baseDeviceHandler.GetAlarmManagerIsRunning(ctx) {
315 go oo.baseDeviceHandler.StartAlarmManager(ctx)
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000316 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700317
318 for _, uniPort := range *oo.baseDeviceHandler.GetUniEntityMap() {
319 // only if this port was enabled for use by the operator at startup
320 if (1<<uniPort.UniID)&oo.baseDeviceHandler.GetUniPortMask() == (1 << uniPort.UniID) {
321 if !oo.baseDeviceHandler.GetFlowMonitoringIsRunning(uniPort.UniID) {
322 go oo.baseDeviceHandler.PerOnuFlowHandlerRoutine(uniPort.UniID)
323 }
324 }
325 }
326
Holger Hildebrandtced74e72021-06-10 14:55:53 +0000327 // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000328 oo.baseDeviceHandler.ReconcileDeviceTechProf(ctx)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000329
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000330 // start go routine with select() on reconciling flow channel before
331 // starting flow reconciling process to prevent loss of any signal
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000332 go func() {
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000333 // In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until
334 // we get a signal that the processing of the last step to rebuild the adapter internal
335 // flow data is finished.
336 select {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000337 case success := <-oo.chReconcilingFlowsFinished:
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000338 if success {
339 logger.Debugw(ctx, "reconciling flows has been finished in time",
340 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000341 oo.baseDeviceHandler.StopReconciling(ctx, true)
342 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000343
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000344 } else {
345 logger.Debugw(ctx, "wait for reconciling flows aborted",
346 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000347 oo.SetReconcilingFlows(false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000348 }
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000349 case <-time.After(500 * time.Millisecond):
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000350 logger.Errorw(ctx, "timeout waiting for reconciling flows to be finished!",
351 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000352 oo.SetReconcilingFlows(false)
353 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000354 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000355 }()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000356 oo.baseDeviceHandler.ReconcileDeviceFlowConfig(ctx)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000357
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000358 oo.MutexPersOnuConfig.RLock()
359 if oo.SOnuPersistentData.PersUniDisableDone {
360 oo.MutexPersOnuConfig.RUnlock()
361 oo.baseDeviceHandler.DisableUniPortStateUpdate(ctx)
362 oo.baseDeviceHandler.SetDeviceReason(cmn.DrOmciAdminLock)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000363 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000364 oo.MutexPersOnuConfig.RUnlock()
365 oo.baseDeviceHandler.EnableUniPortStateUpdate(ctx)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000366 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000367 } else {
368 logger.Debugw(ctx, "MibSync FSM",
369 log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID})
370 go func() {
371 //switch to reconciling with OMCI config
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000372 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000373 }()
374 }
375}
376
dbainbri4d3a0dc2020-12-02 00:33:42 +0000377func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000378 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 +0000379 if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000380 oo.requestMdsValue(ctx)
381 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000382 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 +0000383 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000384 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000385 }()
386 }
387}
388
389func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
390 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 +0000391 if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000392 oo.requestMdsValue(ctx)
393 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000394 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 +0000395 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000396 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000397 }()
398 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000399}
400
dbainbri4d3a0dc2020-12-02 00:33:42 +0000401func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
402 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
403 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000404}
405
dbainbri4d3a0dc2020-12-02 00:33:42 +0000406func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
407 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Start routine to process OMCI-messages for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000408loop:
409 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000410 // case <-ctx.Done():
411 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
412 // break loop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000413 message, ok := <-oo.PMibUploadFsm.CommChan
Himani Chawla4d908332020-08-31 12:30:20 +0530414 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000415 logger.Info(ctx, "MibSync Msg", log.Fields{"Message couldn't be read from channel for device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530416 break loop
417 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000418 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000419
Himani Chawla4d908332020-08-31 12:30:20 +0530420 switch message.Type {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000421 case cmn.TestMsg:
422 msg, _ := message.Data.(cmn.TestMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000423 oo.handleTestMsg(ctx, msg)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000424 case cmn.OMCI:
425 msg, _ := message.Data.(cmn.OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000426 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530427 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000428 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 +0000429 }
430 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000431 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000432 // TODO: only this action?
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000433 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000434}
435
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000436func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg cmn.TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000437
dbainbri4d3a0dc2020-12-02 00:33:42 +0000438 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 +0000439
440 switch msg.TestMessageVal {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000441 case cmn.LoadMibTemplateFailed:
442 _ = oo.PMibUploadFsm.PFsm.Event(UlEvUploadMib)
443 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.PMibUploadFsm.PFsm.Current())})
444 case cmn.LoadMibTemplateOk:
445 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
446 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.PMibUploadFsm.PFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000447 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000448 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 +0000449 }
450}
451
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000452func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
453 if oo.PMibUploadFsm.PFsm.Is(UlStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530454 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
455 if msgLayer != nil {
456 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
457 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000458 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530459 if msgObj.Result == me.Success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000460 oo.MutexPersOnuConfig.Lock()
461 oo.SOnuPersistentData.PersMibDataSyncAdpt = 0
462 oo.MutexPersOnuConfig.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530463 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000464 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530465 return
466 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000467 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530468 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000469 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530470 }
471 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000472 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530473 }
474 } else {
mpagenko01499812021-03-25 10:37:12 +0000475 //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset
476 // with Sequence number 0x8000 as last request before - so it may still respond to that
477 // 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 +0000478 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000479 if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
480 logger.Debugw(ctx, "MibSync FSM - repeat MdsGetRequest (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
481 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000482 _, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
483 me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300484 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000485 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300486 logger.Errorw(ctx, "ONUData get failed, aborting MibSync", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000487 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300488 return
489 }
mpagenko01499812021-03-25 10:37:12 +0000490 //TODO: needs extra handling of timeouts
491 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000492 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000493 return
494 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000495 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000496 logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
497 //perhaps some still lingering message from some prior activity, let's wait for the real response
498 return
Himani Chawla4d908332020-08-31 12:30:20 +0530499 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000500 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000501 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530502}
503
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000504func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530505 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
506 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000507 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530508 return
509 }
510 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
511 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000512 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530513 return
514 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000515 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530516 /* to be verified / reworked !!! */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000517 oo.PDevOmciCC.UploadNoOfCmds = msgObj.NumberOfCommands
518 if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds {
519 _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000520 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
521 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000522 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000523 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000524 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530525 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000526 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 +0530527 //TODO right action?
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000528 _ = oo.PMibUploadFsm.PFsm.Event(UlEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530529 }
530}
531
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000532func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530533 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
Andrea Campanella6515c582020-10-05 11:25:00 +0200534
Holger Hildebrandte2439342020-12-03 16:06:54 +0000535 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000536 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000537 return
538 }
539 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
540 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000541 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000542 return
543 }
544 meName := msgObj.ReportedME.GetName()
545 if meName == "UnknownItuG988ManagedEntity" || meName == "UnknownVendorSpecificManagedEntity" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000546 logger.Debugw(ctx, "MibUploadNextResponse Data for unknown ME received - temporary workaround is to ignore it!",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000547 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj, "meName": meName})
548 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000549 logger.Debugw(ctx, "MibUploadNextResponse Data for:",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000550 log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
Holger Hildebrandt8998b872020-10-05 13:48:39 +0000551 meClassID := msgObj.ReportedME.GetClassID()
552 meEntityID := msgObj.ReportedME.GetEntityID()
553 meAttributes := msgObj.ReportedME.GetAttributeValueMap()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000554 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes)
Himani Chawla4d908332020-08-31 12:30:20 +0530555 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000556 if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds {
557 _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000558 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
559 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000560 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000561 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000562 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530563 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000564 oo.pOnuDB.LogMeDb(ctx)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000565 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530566 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000567 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 +0530568 }
569
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000570 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530571 }
572}
573
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000574func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg cmn.OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000575 var err error = nil
mpagenko01499812021-03-25 10:37:12 +0000576
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000577 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000578 if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType ||
579 oo.lastTxParamStruct.pLastTxMeInstance == nil {
580 //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest
581 // with Sequence number 0x8000 as last request before - so it may still respond to that
582 // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number
583 if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
584 logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000585 _ = oo.PDevOmciCC.SendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000586 //TODO: needs extra handling of timeouts
587 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000588 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000589 return nil
590 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000591 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000592 logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
593 //perhaps some still lingering message from some prior activity, let's wait for the real response
594 return nil
595 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000596 oo.mutexLastTxParamStruct.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530597 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000598 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000599 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 +0000600 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000601 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 +0000602 }
603 msgObj, msgOk := msgLayer.(*omci.GetResponse)
604 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000605 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 +0000606 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000607 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 +0000608 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000609 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000610 if msgObj.Result == me.Success {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000611 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000612 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
613 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000614 meAttributes := msgObj.Attributes
mpagenko01499812021-03-25 10:37:12 +0000615 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000616 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 +0000617 switch meInstance {
618 case "OnuG":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000619 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000620 oo.MutexPersOnuConfig.Lock()
621 oo.SOnuPersistentData.PersVendorID = cmn.TrimStringFromMeOctet(meAttributes["VendorId"])
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000622 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000623 if cmn.OnugSerialNumberLen == len(snBytes) {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000624 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
625 snNumberPart := hex.EncodeToString(snBytes[4:])
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000626 oo.SOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000627 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-G - VendorId/SerialNumber", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000628 "onuDeviceEntry.vendorID": oo.SOnuPersistentData.PersVendorID, "onuDeviceEntry.serialNumber": oo.SOnuPersistentData.PersSerialNumber})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000629 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000630 logger.Infow(ctx, "MibSync FSM - SerialNumber has wrong length - fill serialNumber with zeros", log.Fields{"device-id": oo.deviceID, "length": len(snBytes)})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000631 oo.SOnuPersistentData.PersSerialNumber = cEmptySerialNumberString
Himani Chawla4d908332020-08-31 12:30:20 +0530632 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000633 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000634 // trigger retrieval of EquipmentId
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000635 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000636 return nil
637 case "Onu2G":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000638 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000639 oo.MutexPersOnuConfig.Lock()
640 oo.SOnuPersistentData.PersEquipmentID = cmn.TrimStringFromMeOctet(meAttributes["EquipmentId"])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000641 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000642 "onuDeviceEntry.equipmentID": oo.SOnuPersistentData.PersEquipmentID})
643 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000644 // trigger retrieval of 1st SW-image info
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000645 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000646 return nil
647 case "SoftwareImage":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000648 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000649 if entityID > cmn.SecondSwImageMeID {
mpagenko15ff4a52021-03-02 10:09:20 +0000650 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
651 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
652 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
653 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000654 }
mpagenko15ff4a52021-03-02 10:09:20 +0000655 // need to use function for go lint complexity
656 oo.handleSwImageIndications(ctx, entityID, meAttributes)
657 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000658 case "IpHostConfigData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000659 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000660 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000661 oo.MutexPersOnuConfig.Lock()
662 if cmn.OmciMacAddressLen == len(macBytes) {
663 oo.SOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000664 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000665 "macAddress": oo.SOnuPersistentData.PersMacAddress})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000666 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000667 logger.Infow(ctx, "MibSync FSM - MacAddress wrong length - fill macAddress with zeros", log.Fields{"device-id": oo.deviceID, "length": len(macBytes)})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000668 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000669 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000670 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000671 // trigger retrieval of mib template
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000672 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000673 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000674 case "OnuData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000675 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000676 oo.checkMdsValue(ctx, meAttributes["MibDataSync"].(uint8))
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000677 return nil
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000678 default:
679 oo.mutexLastTxParamStruct.RUnlock()
680 logger.Warnw(ctx, "Unsupported ME name received!",
681 log.Fields{"ME name": meInstance, "device-id": oo.deviceID})
682
Himani Chawla4d908332020-08-31 12:30:20 +0530683 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800684 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000685 oo.mutexLastTxParamStruct.RUnlock()
686 logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ",
687 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000688 }
Himani Chawla4d908332020-08-31 12:30:20 +0530689 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000690 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000691 return nil
692 }
Himani Chawla4d908332020-08-31 12:30:20 +0530693 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000694 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000695 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000696 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530697}
698
mpagenko15ff4a52021-03-02 10:09:20 +0000699func (oo *OnuDeviceEntry) handleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) {
700 imageIsCommitted := meAttributes["IsCommitted"].(uint8)
701 imageIsActive := meAttributes["IsActive"].(uint8)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000702 imageVersion := cmn.TrimStringFromMeOctet(meAttributes["Version"])
703 oo.MutexPersOnuConfig.RLock()
mpagenko15ff4a52021-03-02 10:09:20 +0000704 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
705 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000706 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.SOnuPersistentData.PersSerialNumber})
707 oo.MutexPersOnuConfig.RUnlock()
708 if cmn.FirstSwImageMeID == entityID {
mpagenko15ff4a52021-03-02 10:09:20 +0000709 //always accept the state of the first image (2nd image info should not yet be available)
Holger Hildebrandt05011352021-06-15 09:40:24 +0000710 oo.mutexOnuSwImageIndications.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000711 if imageIsActive == cmn.SwIsActive {
712 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID
713 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true
714 oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion
715 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000716 //as the SW version indication may stem from some ONU Down/up event
717 //the complementary image state is to be invalidated
718 // (state of the second image is always expected afterwards or just invalid)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000719 oo.onuSwImageIndications.InActiveEntityEntry.Valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000720 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000721 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
722 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true
723 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
724 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000725 //as the SW version indication may stem form some ONU Down/up event
726 //the complementary image state is to be invalidated
727 // (state of the second image is always expected afterwards or just invalid)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000728 oo.onuSwImageIndications.ActiveEntityEntry.Valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000729 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000730 oo.mutexOnuSwImageIndications.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000731 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetSecondSwVersion)
mpagenko15ff4a52021-03-02 10:09:20 +0000732 return
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000733 } else if cmn.SecondSwImageMeID == entityID {
mpagenko15ff4a52021-03-02 10:09:20 +0000734 //2nd image info might conflict with first image info, in which case we priorize first image info!
Holger Hildebrandt05011352021-06-15 09:40:24 +0000735 oo.mutexOnuSwImageIndications.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000736 if imageIsActive == cmn.SwIsActive { //2nd image reported to be active
737 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
mpagenko15ff4a52021-03-02 10:09:20 +0000738 //conflict exists - state of first image is left active
739 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
740 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000741 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
742 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true ////to indicate that at least something has been reported
743 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
744 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000745 } else { //first image inactive, this one active
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000746 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID
747 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true
748 oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion
749 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000750 }
751 } else { //2nd image reported to be inactive
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000752 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
mpagenko15ff4a52021-03-02 10:09:20 +0000753 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
754 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
755 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000756 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = cmn.FirstSwImageMeID
757 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true //to indicate that at least something has been reported
mpagenko15ff4a52021-03-02 10:09:20 +0000758 //copy active commit/version from the previously stored inactive position
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000759 oo.onuSwImageIndications.ActiveEntityEntry.Version = oo.onuSwImageIndications.InActiveEntityEntry.Version
760 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000761 }
762 //in any case we indicate (and possibly overwrite) the second image indications as inactive
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000763 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
764 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true
765 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
766 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000767 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000768 oo.mutexOnuSwImageIndications.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000769 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMacAddress)
mpagenko15ff4a52021-03-02 10:09:20 +0000770 return
771 }
772}
773
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000774func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000775 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200776 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000777 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
778 switch msg.OmciMsg.MessageType {
779 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000780 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000781
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000782 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000783 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530784
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000785 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000786 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000787
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000788 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000789 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000790 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530791
Andrea Campanella6515c582020-10-05 11:25:00 +0200792 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000793 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200794
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000795 }
796}
797
dbainbri4d3a0dc2020-12-02 00:33:42 +0000798func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000799 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000800 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 +0000801 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
802 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000803 oo.mutexLastTxParamStruct.RLock()
804 if oo.lastTxParamStruct.pLastTxMeInstance != nil {
805 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
806 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
807 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
808 switch meInstance {
809 case "IpHostConfigData":
810 oo.mutexLastTxParamStruct.RUnlock()
811 logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros",
812 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000813 oo.MutexPersOnuConfig.Lock()
814 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
815 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000816 // trigger retrieval of mib template
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000817 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000818 return nil
819 default:
820 oo.mutexLastTxParamStruct.RUnlock()
821 logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
822 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
823 }
824 } else {
825 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000826 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000827 } else {
828 oo.mutexLastTxParamStruct.RUnlock()
829 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000830 }
831 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000832 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 +0000833 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
834 }
835 return err
836}
837
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000838// IsNewOnu - TODO: add comment
839func (oo *OnuDeviceEntry) IsNewOnu() bool {
840 oo.MutexPersOnuConfig.RLock()
841 defer oo.MutexPersOnuConfig.RUnlock()
842 return oo.SOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000843}
844
Himani Chawla6d2ae152020-09-02 13:11:20 +0530845func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000846 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530847 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000848 return true
849 }
850 }
851 return false
852}
853
dbainbri4d3a0dc2020-12-02 00:33:42 +0000854func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
855 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000856 return errors.New("not_implemented")
857}
858
Himani Chawla6d2ae152020-09-02 13:11:20 +0530859// 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 +0530860// 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 +0000861// 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 +0000862func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
863 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000864 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530865
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000866 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
867 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); exist {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000868 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000869 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000870 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000871 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000872 return nil
873 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000874 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000875 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
876 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000877 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000878 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
879 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000880 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, true)
881 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000882
883 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +0530884 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000885 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +0530886 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
887
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000888 firstLevelMap := oo.pOnuDB.MeDb
divyadesaibbed37c2020-08-28 13:35:20 +0530889 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000890 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +0530891 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530892
893 secondLevelMap := make(map[string]interface{})
894 for secondLevelKey, secondLevelValue := range firstLevelValue {
895 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +0530896 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530897 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +0530898 thirdLevelMap["InstanceId"] = entityID
899 secondLevelMap[entityID] = thirdLevelMap
900 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +0530901 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
902 delete(forthLevelMap, "SerialNumber")
903 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
904
905 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530906 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +0530907 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
908 delete(forthLevelMap, "MacAddress")
909 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
910 }
911 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530912 secondLevelMap["ClassId"] = classID
913 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +0530914 }
915 mibTemplate, err := json.Marshal(&templateMap)
916 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000917 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000918 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
919 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
920 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
divyadesaibbed37c2020-08-28 13:35:20 +0530921 return err
922 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000923 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +0530924 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000925 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 +0000926 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
927 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
928 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
divyadesaibbed37c2020-08-28 13:35:20 +0530929 return err
930 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000931 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530932 return nil
933}
934
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000935func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
936 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
937 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000938 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
939 me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000940 //accept also nil as (error) return value for writing to LastTx
941 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300942 if err != nil {
943 logger.Errorw(ctx, "ONUData get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000944 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300945 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000946 go func(a_pAFsm *cmn.AdapterFsm) {
947 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300948 }(pMibUlFsm)
949 }
950 return
951 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000952 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000953 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
954 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
955 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000956 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000957}
958
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000959func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000960 oo.MutexPersOnuConfig.RLock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000961 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000962 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.SOnuPersistentData.PersMibDataSyncAdpt})
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000963
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000964 mdsValuesAreEqual := oo.SOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
965 oo.MutexPersOnuConfig.RUnlock()
966 if oo.PMibUploadFsm.PFsm.Is(UlStAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000967 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000968 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000969 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000970 } else {
971 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 +0000972 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000973 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000974 } else if oo.PMibUploadFsm.PFsm.Is(UlStReAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000975 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000976 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000977 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000978 } else {
979 logger.Errorw(ctx, "MibSync FSM - mib audit - MDS check failed for the second time!", log.Fields{"device-id": oo.deviceID})
980 //TODO: send new event notification "MDS counter mismatch" to the core
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000981 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000982 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000983 } else if oo.PMibUploadFsm.PFsm.Is(UlStExaminingMds) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000984 if mdsValuesAreEqual && mibDataSyncOnu != 0 {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000985 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000986 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000987 } else {
988 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000989 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000990 }
991 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000992 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 +0000993 }
994}
mpagenko15ff4a52021-03-02 10:09:20 +0000995
996//GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
997func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000998 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000999 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
1000 value := oo.onuSwImageIndications.ActiveEntityEntry.EntityID
Holger Hildebrandt05011352021-06-15 09:40:24 +00001001 oo.mutexOnuSwImageIndications.RUnlock()
1002 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +00001003 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001004 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001005 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
1006}
1007
1008//GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
1009func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001010 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001011 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
1012 value := oo.onuSwImageIndications.InActiveEntityEntry.EntityID
Holger Hildebrandt05011352021-06-15 09:40:24 +00001013 oo.mutexOnuSwImageIndications.RUnlock()
1014 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +00001015 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001016 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001017 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
1018}
1019
1020//IsImageToBeCommitted returns true if the active image is still uncommitted
1021func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001022 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001023 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
1024 if oo.onuSwImageIndications.ActiveEntityEntry.EntityID == aImageID {
1025 if oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted == cmn.SwIsUncommitted {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001026 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001027 return true
1028 }
1029 }
1030 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001031 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001032 return false //all other case are treated as 'nothing to commit
1033}
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001034func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool {
1035
1036 oo.mibTemplatePath = oo.buildMibTemplatePath()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +00001037 logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath),
1038 "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001039
1040 restoredFromMibTemplate := false
1041 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
1042 if err == nil {
1043 if Value != nil {
1044 logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value)
1045
1046 // swap out tokens with specific data
1047 mibTmpString, _ := kvstore.ToString(Value.Value)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001048 oo.MutexPersOnuConfig.RLock()
1049 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.SOnuPersistentData.PersSerialNumber, -1)
1050 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.SOnuPersistentData.PersMacAddress, -1)
1051 oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001052 mibTmpBytes := []byte(mibTmpString)
1053 logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes)
1054
1055 var firstLevelMap map[string]interface{}
1056 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
1057 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
1058 } else {
1059 for firstLevelKey, firstLevelValue := range firstLevelMap {
1060 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
1061 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
1062 meClassID := me.ClassID(uint16ValidNumber)
1063 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
1064 if isSupportedClassID(meClassID) {
1065 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
1066 secondLevelMap := firstLevelValue.(map[string]interface{})
1067 for secondLevelKey, secondLevelValue := range secondLevelMap {
1068 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
1069 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
1070 meEntityID := uint16(uint16ValidNumber)
1071 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
1072 thirdLevelMap := secondLevelValue.(map[string]interface{})
1073 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
1074 if thirdLevelKey == "Attributes" {
1075 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
1076 attributesMap := thirdLevelValue.(map[string]interface{})
1077 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
1078 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
1079 restoredFromMibTemplate = true
1080 }
1081 }
1082 }
1083 }
1084 }
1085 }
1086 }
1087 }
1088 } else {
1089 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1090 }
1091 } else {
1092 logger.Errorf(ctx, "Get from kvstore operation failed for path",
1093 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1094 }
1095 return restoredFromMibTemplate
1096}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001097
1098//CancelProcessing terminates potentially running reconciling processes and stops the FSM
1099func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) {
1100
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001101 if oo.IsReconcilingFlows() {
1102 oo.chReconcilingFlowsFinished <- false
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001103 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001104 if oo.baseDeviceHandler.IsReconciling() {
1105 oo.baseDeviceHandler.StopReconciling(ctx, false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001106 }
1107 //the MibSync FSM might be active all the ONU-active time,
1108 // hence it must be stopped unconditionally
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001109 pMibUlFsm := oo.PMibUploadFsm.PFsm
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001110 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001111 _ = pMibUlFsm.Event(UlEvStop)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001112 }
1113}