blob: 871b6deb1a84f7e93d9bd3b83dd97554d67e9c47 [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 }
317 // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000318 oo.baseDeviceHandler.ReconcileDeviceTechProf(ctx)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000319
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000320 // start go routine with select() on reconciling flow channel before
321 // starting flow reconciling process to prevent loss of any signal
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000322 go func() {
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000323 // In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until
324 // we get a signal that the processing of the last step to rebuild the adapter internal
325 // flow data is finished.
326 select {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000327 case success := <-oo.chReconcilingFlowsFinished:
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000328 if success {
329 logger.Debugw(ctx, "reconciling flows has been finished in time",
330 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000331 oo.baseDeviceHandler.StopReconciling(ctx, true)
332 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000333
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000334 } else {
335 logger.Debugw(ctx, "wait for reconciling flows aborted",
336 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000337 oo.SetReconcilingFlows(false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000338 }
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000339 case <-time.After(500 * time.Millisecond):
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000340 logger.Errorw(ctx, "timeout waiting for reconciling flows to be finished!",
341 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000342 oo.SetReconcilingFlows(false)
343 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +0000344 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000345 }()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000346 oo.baseDeviceHandler.ReconcileDeviceFlowConfig(ctx)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000347
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000348 oo.MutexPersOnuConfig.RLock()
349 if oo.SOnuPersistentData.PersUniDisableDone {
350 oo.MutexPersOnuConfig.RUnlock()
351 oo.baseDeviceHandler.DisableUniPortStateUpdate(ctx)
352 oo.baseDeviceHandler.SetDeviceReason(cmn.DrOmciAdminLock)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000353 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000354 oo.MutexPersOnuConfig.RUnlock()
355 oo.baseDeviceHandler.EnableUniPortStateUpdate(ctx)
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +0000356 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000357 } else {
358 logger.Debugw(ctx, "MibSync FSM",
359 log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID})
360 go func() {
361 //switch to reconciling with OMCI config
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000362 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000363 }()
364 }
365}
366
dbainbri4d3a0dc2020-12-02 00:33:42 +0000367func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000368 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 +0000369 if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000370 oo.requestMdsValue(ctx)
371 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000372 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 +0000373 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000374 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000375 }()
376 }
377}
378
379func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
380 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 +0000381 if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000382 oo.requestMdsValue(ctx)
383 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000384 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 +0000385 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000386 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000387 }()
388 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000389}
390
dbainbri4d3a0dc2020-12-02 00:33:42 +0000391func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
392 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
393 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000394}
395
dbainbri4d3a0dc2020-12-02 00:33:42 +0000396func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
397 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 +0000398loop:
399 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000400 // case <-ctx.Done():
401 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
402 // break loop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000403 message, ok := <-oo.PMibUploadFsm.CommChan
Himani Chawla4d908332020-08-31 12:30:20 +0530404 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000405 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 +0530406 break loop
407 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000408 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000409
Himani Chawla4d908332020-08-31 12:30:20 +0530410 switch message.Type {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000411 case cmn.TestMsg:
412 msg, _ := message.Data.(cmn.TestMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000413 oo.handleTestMsg(ctx, msg)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000414 case cmn.OMCI:
415 msg, _ := message.Data.(cmn.OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000416 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530417 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000418 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 +0000419 }
420 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000421 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000422 // TODO: only this action?
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000423 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000424}
425
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000426func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg cmn.TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000427
dbainbri4d3a0dc2020-12-02 00:33:42 +0000428 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 +0000429
430 switch msg.TestMessageVal {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000431 case cmn.LoadMibTemplateFailed:
432 _ = oo.PMibUploadFsm.PFsm.Event(UlEvUploadMib)
433 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.PMibUploadFsm.PFsm.Current())})
434 case cmn.LoadMibTemplateOk:
435 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
436 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.PMibUploadFsm.PFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000437 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000438 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 +0000439 }
440}
441
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000442func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
443 if oo.PMibUploadFsm.PFsm.Is(UlStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530444 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
445 if msgLayer != nil {
446 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
447 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000448 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530449 if msgObj.Result == me.Success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000450 oo.MutexPersOnuConfig.Lock()
451 oo.SOnuPersistentData.PersMibDataSyncAdpt = 0
452 oo.MutexPersOnuConfig.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530453 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000454 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530455 return
456 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000457 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530458 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000459 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530460 }
461 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000462 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530463 }
464 } else {
mpagenko01499812021-03-25 10:37:12 +0000465 //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset
466 // with Sequence number 0x8000 as last request before - so it may still respond to that
467 // 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 +0000468 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000469 if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
470 logger.Debugw(ctx, "MibSync FSM - repeat MdsGetRequest (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
471 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000472 _, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
473 me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300474 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000475 oo.mutexLastTxParamStruct.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300476 logger.Errorw(ctx, "ONUData get failed, aborting MibSync", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000477 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300478 return
479 }
mpagenko01499812021-03-25 10:37:12 +0000480 //TODO: needs extra handling of timeouts
481 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000482 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000483 return
484 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000485 oo.mutexLastTxParamStruct.Unlock()
mpagenko01499812021-03-25 10:37:12 +0000486 logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
487 //perhaps some still lingering message from some prior activity, let's wait for the real response
488 return
Himani Chawla4d908332020-08-31 12:30:20 +0530489 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000490 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000491 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530492}
493
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000494func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530495 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
496 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000497 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530498 return
499 }
500 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
501 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000502 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530503 return
504 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000505 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530506 /* to be verified / reworked !!! */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000507 oo.PDevOmciCC.UploadNoOfCmds = msgObj.NumberOfCommands
508 if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds {
509 _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000510 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
511 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000512 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000513 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000514 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530515 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000516 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 +0530517 //TODO right action?
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000518 _ = oo.PMibUploadFsm.PFsm.Event(UlEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530519 }
520}
521
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000522func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530523 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
Andrea Campanella6515c582020-10-05 11:25:00 +0200524
Holger Hildebrandte2439342020-12-03 16:06:54 +0000525 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000526 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000527 return
528 }
529 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
530 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000531 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000532 return
533 }
534 meName := msgObj.ReportedME.GetName()
535 if meName == "UnknownItuG988ManagedEntity" || meName == "UnknownVendorSpecificManagedEntity" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000536 logger.Debugw(ctx, "MibUploadNextResponse Data for unknown ME received - temporary workaround is to ignore it!",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000537 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj, "meName": meName})
538 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000539 logger.Debugw(ctx, "MibUploadNextResponse Data for:",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000540 log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
Holger Hildebrandt8998b872020-10-05 13:48:39 +0000541 meClassID := msgObj.ReportedME.GetClassID()
542 meEntityID := msgObj.ReportedME.GetEntityID()
543 meAttributes := msgObj.ReportedME.GetAttributeValueMap()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000544 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes)
Himani Chawla4d908332020-08-31 12:30:20 +0530545 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000546 if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds {
547 _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000548 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
549 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000550 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000551 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000552 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530553 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000554 oo.pOnuDB.LogMeDb(ctx)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000555 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530556 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000557 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 +0530558 }
559
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000560 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530561 }
562}
563
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000564func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg cmn.OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000565 var err error = nil
mpagenko01499812021-03-25 10:37:12 +0000566
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000567 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000568 if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType ||
569 oo.lastTxParamStruct.pLastTxMeInstance == nil {
570 //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest
571 // with Sequence number 0x8000 as last request before - so it may still respond to that
572 // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number
573 if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
574 logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000575 _ = oo.PDevOmciCC.SendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000576 //TODO: needs extra handling of timeouts
577 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000578 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000579 return nil
580 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000581 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000582 logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
583 //perhaps some still lingering message from some prior activity, let's wait for the real response
584 return nil
585 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000586 oo.mutexLastTxParamStruct.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530587 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000588 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000589 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 +0000590 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000591 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 +0000592 }
593 msgObj, msgOk := msgLayer.(*omci.GetResponse)
594 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000595 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 +0000596 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000597 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 +0000598 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000599 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000600 if msgObj.Result == me.Success {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000601 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000602 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
603 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000604 meAttributes := msgObj.Attributes
mpagenko01499812021-03-25 10:37:12 +0000605 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000606 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 +0000607 switch meInstance {
608 case "OnuG":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000609 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000610 oo.MutexPersOnuConfig.Lock()
611 oo.SOnuPersistentData.PersVendorID = cmn.TrimStringFromMeOctet(meAttributes["VendorId"])
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000612 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000613 if cmn.OnugSerialNumberLen == len(snBytes) {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000614 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
615 snNumberPart := hex.EncodeToString(snBytes[4:])
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000616 oo.SOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000617 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 +0000618 "onuDeviceEntry.vendorID": oo.SOnuPersistentData.PersVendorID, "onuDeviceEntry.serialNumber": oo.SOnuPersistentData.PersSerialNumber})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000619 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000620 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 +0000621 oo.SOnuPersistentData.PersSerialNumber = cEmptySerialNumberString
Himani Chawla4d908332020-08-31 12:30:20 +0530622 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000623 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000624 // trigger retrieval of EquipmentId
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000625 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000626 return nil
627 case "Onu2G":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000628 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000629 oo.MutexPersOnuConfig.Lock()
630 oo.SOnuPersistentData.PersEquipmentID = cmn.TrimStringFromMeOctet(meAttributes["EquipmentId"])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000631 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000632 "onuDeviceEntry.equipmentID": oo.SOnuPersistentData.PersEquipmentID})
633 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000634 // trigger retrieval of 1st SW-image info
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000635 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000636 return nil
637 case "SoftwareImage":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000638 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000639 if entityID > cmn.SecondSwImageMeID {
mpagenko15ff4a52021-03-02 10:09:20 +0000640 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
641 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
642 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
643 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000644 }
mpagenko15ff4a52021-03-02 10:09:20 +0000645 // need to use function for go lint complexity
646 oo.handleSwImageIndications(ctx, entityID, meAttributes)
647 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000648 case "IpHostConfigData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000649 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000650 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000651 oo.MutexPersOnuConfig.Lock()
652 if cmn.OmciMacAddressLen == len(macBytes) {
653 oo.SOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000654 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000655 "macAddress": oo.SOnuPersistentData.PersMacAddress})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000656 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000657 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 +0000658 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000659 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000660 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000661 // trigger retrieval of mib template
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000662 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000663 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000664 case "OnuData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000665 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000666 oo.checkMdsValue(ctx, meAttributes["MibDataSync"].(uint8))
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000667 return nil
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000668 default:
669 oo.mutexLastTxParamStruct.RUnlock()
670 logger.Warnw(ctx, "Unsupported ME name received!",
671 log.Fields{"ME name": meInstance, "device-id": oo.deviceID})
672
Himani Chawla4d908332020-08-31 12:30:20 +0530673 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800674 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000675 oo.mutexLastTxParamStruct.RUnlock()
676 logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ",
677 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000678 }
Himani Chawla4d908332020-08-31 12:30:20 +0530679 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000680 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000681 return nil
682 }
Himani Chawla4d908332020-08-31 12:30:20 +0530683 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000684 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000685 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000686 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530687}
688
mpagenko15ff4a52021-03-02 10:09:20 +0000689func (oo *OnuDeviceEntry) handleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) {
690 imageIsCommitted := meAttributes["IsCommitted"].(uint8)
691 imageIsActive := meAttributes["IsActive"].(uint8)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000692 imageVersion := cmn.TrimStringFromMeOctet(meAttributes["Version"])
693 oo.MutexPersOnuConfig.RLock()
mpagenko15ff4a52021-03-02 10:09:20 +0000694 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
695 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000696 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.SOnuPersistentData.PersSerialNumber})
697 oo.MutexPersOnuConfig.RUnlock()
698 if cmn.FirstSwImageMeID == entityID {
mpagenko15ff4a52021-03-02 10:09:20 +0000699 //always accept the state of the first image (2nd image info should not yet be available)
Holger Hildebrandt05011352021-06-15 09:40:24 +0000700 oo.mutexOnuSwImageIndications.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000701 if imageIsActive == cmn.SwIsActive {
702 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID
703 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true
704 oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion
705 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000706 //as the SW version indication may stem from some ONU Down/up event
707 //the complementary image state is to be invalidated
708 // (state of the second image is always expected afterwards or just invalid)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000709 oo.onuSwImageIndications.InActiveEntityEntry.Valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000710 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000711 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
712 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true
713 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
714 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000715 //as the SW version indication may stem form some ONU Down/up event
716 //the complementary image state is to be invalidated
717 // (state of the second image is always expected afterwards or just invalid)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000718 oo.onuSwImageIndications.ActiveEntityEntry.Valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000719 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000720 oo.mutexOnuSwImageIndications.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000721 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetSecondSwVersion)
mpagenko15ff4a52021-03-02 10:09:20 +0000722 return
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000723 } else if cmn.SecondSwImageMeID == entityID {
mpagenko15ff4a52021-03-02 10:09:20 +0000724 //2nd image info might conflict with first image info, in which case we priorize first image info!
Holger Hildebrandt05011352021-06-15 09:40:24 +0000725 oo.mutexOnuSwImageIndications.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000726 if imageIsActive == cmn.SwIsActive { //2nd image reported to be active
727 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
mpagenko15ff4a52021-03-02 10:09:20 +0000728 //conflict exists - state of first image is left active
729 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
730 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000731 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
732 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true ////to indicate that at least something has been reported
733 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
734 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000735 } else { //first image inactive, this one active
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000736 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID
737 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true
738 oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion
739 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000740 }
741 } else { //2nd image reported to be inactive
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000742 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
mpagenko15ff4a52021-03-02 10:09:20 +0000743 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
744 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
745 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000746 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = cmn.FirstSwImageMeID
747 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true //to indicate that at least something has been reported
mpagenko15ff4a52021-03-02 10:09:20 +0000748 //copy active commit/version from the previously stored inactive position
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000749 oo.onuSwImageIndications.ActiveEntityEntry.Version = oo.onuSwImageIndications.InActiveEntityEntry.Version
750 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000751 }
752 //in any case we indicate (and possibly overwrite) the second image indications as inactive
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000753 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
754 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true
755 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
756 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000757 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000758 oo.mutexOnuSwImageIndications.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000759 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMacAddress)
mpagenko15ff4a52021-03-02 10:09:20 +0000760 return
761 }
762}
763
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000764func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000765 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200766 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000767 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
768 switch msg.OmciMsg.MessageType {
769 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000770 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000771
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000772 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000773 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530774
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000775 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000776 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000777
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000778 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000779 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000780 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530781
Andrea Campanella6515c582020-10-05 11:25:00 +0200782 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000783 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200784
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000785 }
786}
787
dbainbri4d3a0dc2020-12-02 00:33:42 +0000788func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000789 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000790 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 +0000791 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
792 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000793 oo.mutexLastTxParamStruct.RLock()
794 if oo.lastTxParamStruct.pLastTxMeInstance != nil {
795 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
796 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
797 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
798 switch meInstance {
799 case "IpHostConfigData":
800 oo.mutexLastTxParamStruct.RUnlock()
801 logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros",
802 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000803 oo.MutexPersOnuConfig.Lock()
804 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
805 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000806 // trigger retrieval of mib template
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000807 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000808 return nil
809 default:
810 oo.mutexLastTxParamStruct.RUnlock()
811 logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
812 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
813 }
814 } else {
815 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000816 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000817 } else {
818 oo.mutexLastTxParamStruct.RUnlock()
819 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000820 }
821 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000822 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 +0000823 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
824 }
825 return err
826}
827
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000828// IsNewOnu - TODO: add comment
829func (oo *OnuDeviceEntry) IsNewOnu() bool {
830 oo.MutexPersOnuConfig.RLock()
831 defer oo.MutexPersOnuConfig.RUnlock()
832 return oo.SOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000833}
834
Himani Chawla6d2ae152020-09-02 13:11:20 +0530835func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000836 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530837 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000838 return true
839 }
840 }
841 return false
842}
843
dbainbri4d3a0dc2020-12-02 00:33:42 +0000844func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
845 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000846 return errors.New("not_implemented")
847}
848
Himani Chawla6d2ae152020-09-02 13:11:20 +0530849// 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 +0530850// 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 +0000851// 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 +0000852func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
853 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000854 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530855
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000856 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
857 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); exist {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000858 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000859 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000860 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000861 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000862 return nil
863 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000864 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000865 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
866 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000867 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000868 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
869 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000870 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, true)
871 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000872
873 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +0530874 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000875 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +0530876 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
877
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000878 firstLevelMap := oo.pOnuDB.MeDb
divyadesaibbed37c2020-08-28 13:35:20 +0530879 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000880 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +0530881 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530882
883 secondLevelMap := make(map[string]interface{})
884 for secondLevelKey, secondLevelValue := range firstLevelValue {
885 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +0530886 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530887 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +0530888 thirdLevelMap["InstanceId"] = entityID
889 secondLevelMap[entityID] = thirdLevelMap
890 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +0530891 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
892 delete(forthLevelMap, "SerialNumber")
893 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
894
895 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530896 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +0530897 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
898 delete(forthLevelMap, "MacAddress")
899 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
900 }
901 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530902 secondLevelMap["ClassId"] = classID
903 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +0530904 }
905 mibTemplate, err := json.Marshal(&templateMap)
906 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000907 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000908 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
909 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
910 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
divyadesaibbed37c2020-08-28 13:35:20 +0530911 return err
912 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000913 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +0530914 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000915 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 +0000916 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
917 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
918 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
divyadesaibbed37c2020-08-28 13:35:20 +0530919 return err
920 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000921 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530922 return nil
923}
924
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000925func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
926 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
927 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000928 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
929 me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000930 //accept also nil as (error) return value for writing to LastTx
931 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300932 if err != nil {
933 logger.Errorw(ctx, "ONUData get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000934 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300935 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000936 go func(a_pAFsm *cmn.AdapterFsm) {
937 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300938 }(pMibUlFsm)
939 }
940 return
941 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000942 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000943 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
944 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
945 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000946 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000947}
948
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000949func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000950 oo.MutexPersOnuConfig.RLock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000951 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000952 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.SOnuPersistentData.PersMibDataSyncAdpt})
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000953
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000954 mdsValuesAreEqual := oo.SOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
955 oo.MutexPersOnuConfig.RUnlock()
956 if oo.PMibUploadFsm.PFsm.Is(UlStAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000957 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000958 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000959 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000960 } else {
961 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 +0000962 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000963 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000964 } else if oo.PMibUploadFsm.PFsm.Is(UlStReAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000965 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000966 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000967 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000968 } else {
969 logger.Errorw(ctx, "MibSync FSM - mib audit - MDS check failed for the second time!", log.Fields{"device-id": oo.deviceID})
970 //TODO: send new event notification "MDS counter mismatch" to the core
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000971 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000972 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000973 } else if oo.PMibUploadFsm.PFsm.Is(UlStExaminingMds) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000974 if mdsValuesAreEqual && mibDataSyncOnu != 0 {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000975 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000976 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000977 } else {
978 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000979 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000980 }
981 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000982 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 +0000983 }
984}
mpagenko15ff4a52021-03-02 10:09:20 +0000985
986//GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
987func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +0000988 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000989 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
990 value := oo.onuSwImageIndications.ActiveEntityEntry.EntityID
Holger Hildebrandt05011352021-06-15 09:40:24 +0000991 oo.mutexOnuSwImageIndications.RUnlock()
992 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +0000993 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000994 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +0000995 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
996}
997
998//GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
999func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001000 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001001 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
1002 value := oo.onuSwImageIndications.InActiveEntityEntry.EntityID
Holger Hildebrandt05011352021-06-15 09:40:24 +00001003 oo.mutexOnuSwImageIndications.RUnlock()
1004 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +00001005 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001006 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001007 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
1008}
1009
1010//IsImageToBeCommitted returns true if the active image is still uncommitted
1011func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001012 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001013 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
1014 if oo.onuSwImageIndications.ActiveEntityEntry.EntityID == aImageID {
1015 if oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted == cmn.SwIsUncommitted {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001016 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001017 return true
1018 }
1019 }
1020 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001021 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001022 return false //all other case are treated as 'nothing to commit
1023}
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001024func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool {
1025
1026 oo.mibTemplatePath = oo.buildMibTemplatePath()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +00001027 logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath),
1028 "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001029
1030 restoredFromMibTemplate := false
1031 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
1032 if err == nil {
1033 if Value != nil {
1034 logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value)
1035
1036 // swap out tokens with specific data
1037 mibTmpString, _ := kvstore.ToString(Value.Value)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001038 oo.MutexPersOnuConfig.RLock()
1039 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.SOnuPersistentData.PersSerialNumber, -1)
1040 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.SOnuPersistentData.PersMacAddress, -1)
1041 oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001042 mibTmpBytes := []byte(mibTmpString)
1043 logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes)
1044
1045 var firstLevelMap map[string]interface{}
1046 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
1047 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
1048 } else {
1049 for firstLevelKey, firstLevelValue := range firstLevelMap {
1050 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
1051 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
1052 meClassID := me.ClassID(uint16ValidNumber)
1053 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
1054 if isSupportedClassID(meClassID) {
1055 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
1056 secondLevelMap := firstLevelValue.(map[string]interface{})
1057 for secondLevelKey, secondLevelValue := range secondLevelMap {
1058 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
1059 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
1060 meEntityID := uint16(uint16ValidNumber)
1061 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
1062 thirdLevelMap := secondLevelValue.(map[string]interface{})
1063 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
1064 if thirdLevelKey == "Attributes" {
1065 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
1066 attributesMap := thirdLevelValue.(map[string]interface{})
1067 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
1068 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
1069 restoredFromMibTemplate = true
1070 }
1071 }
1072 }
1073 }
1074 }
1075 }
1076 }
1077 }
1078 } else {
1079 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1080 }
1081 } else {
1082 logger.Errorf(ctx, "Get from kvstore operation failed for path",
1083 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1084 }
1085 return restoredFromMibTemplate
1086}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001087
1088//CancelProcessing terminates potentially running reconciling processes and stops the FSM
1089func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) {
1090
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001091 if oo.IsReconcilingFlows() {
1092 oo.chReconcilingFlowsFinished <- false
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001093 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001094 if oo.baseDeviceHandler.IsReconciling() {
1095 oo.baseDeviceHandler.StopReconciling(ctx, false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001096 }
1097 //the MibSync FSM might be active all the ONU-active time,
1098 // hence it must be stopped unconditionally
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001099 pMibUlFsm := oo.PMibUploadFsm.PFsm
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001100 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001101 _ = pMibUlFsm.Event(UlEvStop)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001102 }
1103}