blob: d3b3543884f9098ace76c6d63a07ae7f428ff850 [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
mpagenko836a1fd2021-11-01 16:12:42 +000033 "github.com/opencord/omci-lib-go/v2"
34 me "github.com/opencord/omci-lib-go/v2/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()
mpagenko836a1fd2021-11-01 16:12:42 +0000554
555 //with relaxed decoding set in the OMCI-LIB we have the chance to detect if there are some unknown attributes appended which we cannot decode
556 if unknownAttrLayer := (*msg.OmciPacket).Layer(omci.LayerTypeUnknownAttributes); unknownAttrLayer != nil {
557 logger.Warnw(ctx, "MibUploadNextResponse contains unknown attributes", log.Fields{"device-id": oo.deviceID})
558 if unknownAttributes, ok := unknownAttrLayer.(*omci.UnknownAttributes); ok {
559 // provide a loop over several ME's here already in preparation of OMCI extended message format
560 for _, unknown := range unknownAttributes.Attributes {
561 unknownAttrClassID := unknown.EntityClass // ClassID
562 unknownAttrInst := unknown.EntityInstance // uint16
563 unknownAttrMask := unknown.AttributeMask // ui
564 unknownAttrBlob := unknown.AttributeData // []byte
565 logger.Warnw(ctx, "unknown attributes detected for", log.Fields{"device-id": oo.deviceID,
566 "Me-ClassId": unknownAttrClassID, "Me-InstId": unknownAttrInst, "unknown mask": unknownAttrMask,
567 "unknown attributes": unknownAttrBlob})
568 //TODO!!! We have to find a way to put this extra information into the (MIB)DB, see below pOnuDB.PutMe
569 // this probably requires an (add-on) extension in the DB, that should not harm any other (get) processing -> later as a second step
570 } // for all included ME's with unknown attributes
571 } else {
572 logger.Errorw(ctx, "unknownAttrLayer could not be decoded", log.Fields{"device-id": oo.deviceID})
573 }
574 }
575
dbainbri4d3a0dc2020-12-02 00:33:42 +0000576 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes)
Himani Chawla4d908332020-08-31 12:30:20 +0530577 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000578 if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds {
579 _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000580 //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure
581 // that the lastTxMessageType is correctly set to avoid misinterpreting other responses
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000582 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000583 oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000584 oo.mutexLastTxParamStruct.Unlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530585 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000586 oo.pOnuDB.LogMeDb(ctx)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000587 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530588 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000589 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 +0530590 }
591
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000592 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530593 }
594}
595
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000596func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg cmn.OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000597 var err error = nil
mpagenko01499812021-03-25 10:37:12 +0000598
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000599 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000600 if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType ||
601 oo.lastTxParamStruct.pLastTxMeInstance == nil {
602 //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest
603 // with Sequence number 0x8000 as last request before - so it may still respond to that
604 // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number
605 if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 {
606 logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000607 _ = oo.PDevOmciCC.SendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true)
mpagenko01499812021-03-25 10:37:12 +0000608 //TODO: needs extra handling of timeouts
609 oo.lastTxParamStruct.repeatCount = 1
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000610 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000611 return nil
612 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000613 oo.mutexLastTxParamStruct.RUnlock()
mpagenko01499812021-03-25 10:37:12 +0000614 logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID})
615 //perhaps some still lingering message from some prior activity, let's wait for the real response
616 return nil
617 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000618 oo.mutexLastTxParamStruct.RUnlock()
Himani Chawla4d908332020-08-31 12:30:20 +0530619 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000620 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000621 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 +0000622 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000623 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 +0000624 }
625 msgObj, msgOk := msgLayer.(*omci.GetResponse)
626 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000627 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 +0000628 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000629 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 +0000630 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000631 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000632 if msgObj.Result == me.Success {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000633 oo.mutexLastTxParamStruct.RLock()
mpagenko01499812021-03-25 10:37:12 +0000634 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
635 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000636 meAttributes := msgObj.Attributes
mpagenko01499812021-03-25 10:37:12 +0000637 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000638 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 +0000639 switch meInstance {
640 case "OnuG":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000641 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000642 oo.MutexPersOnuConfig.Lock()
643 oo.SOnuPersistentData.PersVendorID = cmn.TrimStringFromMeOctet(meAttributes["VendorId"])
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000644 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000645 if cmn.OnugSerialNumberLen == len(snBytes) {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000646 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
647 snNumberPart := hex.EncodeToString(snBytes[4:])
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000648 oo.SOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000649 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 +0000650 "onuDeviceEntry.vendorID": oo.SOnuPersistentData.PersVendorID, "onuDeviceEntry.serialNumber": oo.SOnuPersistentData.PersSerialNumber})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000651 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000652 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 +0000653 oo.SOnuPersistentData.PersSerialNumber = cEmptySerialNumberString
Himani Chawla4d908332020-08-31 12:30:20 +0530654 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000655 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000656 // trigger retrieval of EquipmentId
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000657 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000658 return nil
659 case "Onu2G":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000660 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000661 oo.MutexPersOnuConfig.Lock()
662 oo.SOnuPersistentData.PersEquipmentID = cmn.TrimStringFromMeOctet(meAttributes["EquipmentId"])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000663 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000664 "onuDeviceEntry.equipmentID": oo.SOnuPersistentData.PersEquipmentID})
665 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000666 // trigger retrieval of 1st SW-image info
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000667 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000668 return nil
669 case "SoftwareImage":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000670 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000671 if entityID > cmn.SecondSwImageMeID {
mpagenko15ff4a52021-03-02 10:09:20 +0000672 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
673 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
674 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
675 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000676 }
mpagenko15ff4a52021-03-02 10:09:20 +0000677 // need to use function for go lint complexity
678 oo.handleSwImageIndications(ctx, entityID, meAttributes)
679 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000680 case "IpHostConfigData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000681 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000682 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000683 oo.MutexPersOnuConfig.Lock()
684 if cmn.OmciMacAddressLen == len(macBytes) {
685 oo.SOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000686 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000687 "macAddress": oo.SOnuPersistentData.PersMacAddress})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000688 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000689 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 +0000690 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000691 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000692 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000693 // trigger retrieval of mib template
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000694 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000695 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000696 case "OnuData":
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000697 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000698 oo.checkMdsValue(ctx, meAttributes["MibDataSync"].(uint8))
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000699 return nil
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000700 default:
701 oo.mutexLastTxParamStruct.RUnlock()
702 logger.Warnw(ctx, "Unsupported ME name received!",
703 log.Fields{"ME name": meInstance, "device-id": oo.deviceID})
704
Himani Chawla4d908332020-08-31 12:30:20 +0530705 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800706 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000707 oo.mutexLastTxParamStruct.RUnlock()
708 logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ",
709 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000710 }
Himani Chawla4d908332020-08-31 12:30:20 +0530711 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000712 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000713 return nil
714 }
Himani Chawla4d908332020-08-31 12:30:20 +0530715 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000716 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000717 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000718 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530719}
720
mpagenko15ff4a52021-03-02 10:09:20 +0000721func (oo *OnuDeviceEntry) handleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) {
722 imageIsCommitted := meAttributes["IsCommitted"].(uint8)
723 imageIsActive := meAttributes["IsActive"].(uint8)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000724 imageVersion := cmn.TrimStringFromMeOctet(meAttributes["Version"])
725 oo.MutexPersOnuConfig.RLock()
mpagenko15ff4a52021-03-02 10:09:20 +0000726 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
727 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000728 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.SOnuPersistentData.PersSerialNumber})
729 oo.MutexPersOnuConfig.RUnlock()
730 if cmn.FirstSwImageMeID == entityID {
mpagenko15ff4a52021-03-02 10:09:20 +0000731 //always accept the state of the first image (2nd image info should not yet be available)
Holger Hildebrandt05011352021-06-15 09:40:24 +0000732 oo.mutexOnuSwImageIndications.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000733 if imageIsActive == cmn.SwIsActive {
734 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID
735 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true
736 oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion
737 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000738 //as the SW version indication may stem from some ONU Down/up event
739 //the complementary image state is to be invalidated
740 // (state of the second image is always expected afterwards or just invalid)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000741 oo.onuSwImageIndications.InActiveEntityEntry.Valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000742 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000743 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
744 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true
745 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
746 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko59498c12021-03-18 14:15:15 +0000747 //as the SW version indication may stem form some ONU Down/up event
748 //the complementary image state is to be invalidated
749 // (state of the second image is always expected afterwards or just invalid)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000750 oo.onuSwImageIndications.ActiveEntityEntry.Valid = false
mpagenko15ff4a52021-03-02 10:09:20 +0000751 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000752 oo.mutexOnuSwImageIndications.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000753 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetSecondSwVersion)
mpagenko15ff4a52021-03-02 10:09:20 +0000754 return
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000755 } else if cmn.SecondSwImageMeID == entityID {
mpagenko15ff4a52021-03-02 10:09:20 +0000756 //2nd image info might conflict with first image info, in which case we priorize first image info!
Holger Hildebrandt05011352021-06-15 09:40:24 +0000757 oo.mutexOnuSwImageIndications.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000758 if imageIsActive == cmn.SwIsActive { //2nd image reported to be active
759 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
mpagenko15ff4a52021-03-02 10:09:20 +0000760 //conflict exists - state of first image is left active
761 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
762 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000763 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
764 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true ////to indicate that at least something has been reported
765 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
766 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000767 } else { //first image inactive, this one active
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000768 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID
769 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true
770 oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion
771 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000772 }
773 } else { //2nd image reported to be inactive
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000774 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
mpagenko15ff4a52021-03-02 10:09:20 +0000775 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
776 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
777 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000778 oo.onuSwImageIndications.ActiveEntityEntry.EntityID = cmn.FirstSwImageMeID
779 oo.onuSwImageIndications.ActiveEntityEntry.Valid = true //to indicate that at least something has been reported
mpagenko15ff4a52021-03-02 10:09:20 +0000780 //copy active commit/version from the previously stored inactive position
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000781 oo.onuSwImageIndications.ActiveEntityEntry.Version = oo.onuSwImageIndications.InActiveEntityEntry.Version
782 oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000783 }
784 //in any case we indicate (and possibly overwrite) the second image indications as inactive
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000785 oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID
786 oo.onuSwImageIndications.InActiveEntityEntry.Valid = true
787 oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion
788 oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted
mpagenko15ff4a52021-03-02 10:09:20 +0000789 }
Holger Hildebrandt05011352021-06-15 09:40:24 +0000790 oo.mutexOnuSwImageIndications.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000791 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMacAddress)
mpagenko15ff4a52021-03-02 10:09:20 +0000792 return
793 }
794}
795
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000796func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000797 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200798 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000799 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
800 switch msg.OmciMsg.MessageType {
801 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000802 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000803
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000804 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000805 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530806
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000807 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000808 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000809
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000810 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000811 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000812 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530813
Andrea Campanella6515c582020-10-05 11:25:00 +0200814 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000815 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200816
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000817 }
818}
819
dbainbri4d3a0dc2020-12-02 00:33:42 +0000820func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000821 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000822 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 +0000823 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
824 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000825 oo.mutexLastTxParamStruct.RLock()
826 if oo.lastTxParamStruct.pLastTxMeInstance != nil {
827 entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID()
828 if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
829 meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName()
830 switch meInstance {
831 case "IpHostConfigData":
832 oo.mutexLastTxParamStruct.RUnlock()
833 logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros",
834 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000835 oo.MutexPersOnuConfig.Lock()
836 oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString
837 oo.MutexPersOnuConfig.Unlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000838 // trigger retrieval of mib template
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000839 _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000840 return nil
841 default:
842 oo.mutexLastTxParamStruct.RUnlock()
843 logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
844 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
845 }
846 } else {
847 oo.mutexLastTxParamStruct.RUnlock()
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000848 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000849 } else {
850 oo.mutexLastTxParamStruct.RUnlock()
851 logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000852 }
853 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000854 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 +0000855 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
856 }
857 return err
858}
859
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000860// IsNewOnu - TODO: add comment
861func (oo *OnuDeviceEntry) IsNewOnu() bool {
862 oo.MutexPersOnuConfig.RLock()
863 defer oo.MutexPersOnuConfig.RUnlock()
864 return oo.SOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000865}
866
Himani Chawla6d2ae152020-09-02 13:11:20 +0530867func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000868 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530869 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000870 return true
871 }
872 }
873 return false
874}
875
dbainbri4d3a0dc2020-12-02 00:33:42 +0000876func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
877 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000878 return errors.New("not_implemented")
879}
880
Himani Chawla6d2ae152020-09-02 13:11:20 +0530881// 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 +0530882// 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 +0000883// 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 +0000884func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
885 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000886 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530887
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000888 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
889 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); exist {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000890 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000891 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000892 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000893 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000894 return nil
895 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000896 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000897 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
898 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000899 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000900 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
901 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000902 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, true)
903 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000904
905 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +0530906 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000907 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +0530908 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
909
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000910 firstLevelMap := oo.pOnuDB.MeDb
divyadesaibbed37c2020-08-28 13:35:20 +0530911 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000912 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +0530913 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530914
915 secondLevelMap := make(map[string]interface{})
916 for secondLevelKey, secondLevelValue := range firstLevelValue {
917 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +0530918 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530919 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +0530920 thirdLevelMap["InstanceId"] = entityID
921 secondLevelMap[entityID] = thirdLevelMap
922 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +0530923 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
924 delete(forthLevelMap, "SerialNumber")
925 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
926
927 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530928 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +0530929 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
930 delete(forthLevelMap, "MacAddress")
931 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
932 }
933 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530934 secondLevelMap["ClassId"] = classID
935 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +0530936 }
937 mibTemplate, err := json.Marshal(&templateMap)
938 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000939 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000940 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
941 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
942 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
divyadesaibbed37c2020-08-28 13:35:20 +0530943 return err
944 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000945 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +0530946 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000947 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 +0000948 oo.pOpenOnuAc.LockMutexMibTemplateGenerated()
949 oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false)
950 oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated()
divyadesaibbed37c2020-08-28 13:35:20 +0530951 return err
952 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000953 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530954 return nil
955}
956
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000957func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
958 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
959 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000960 meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
961 me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000962 //accept also nil as (error) return value for writing to LastTx
963 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +0300964 if err != nil {
965 logger.Errorw(ctx, "ONUData get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000966 pMibUlFsm := oo.PMibUploadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300967 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000968 go func(a_pAFsm *cmn.AdapterFsm) {
969 _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300970 }(pMibUlFsm)
971 }
972 return
973 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000974 oo.mutexLastTxParamStruct.Lock()
mpagenko01499812021-03-25 10:37:12 +0000975 oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType
976 oo.lastTxParamStruct.pLastTxMeInstance = meInstance
977 oo.lastTxParamStruct.repeatCount = 0
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000978 oo.mutexLastTxParamStruct.Unlock()
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000979}
980
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000981func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000982 oo.MutexPersOnuConfig.RLock()
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000983 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000984 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.SOnuPersistentData.PersMibDataSyncAdpt})
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000985
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000986 mdsValuesAreEqual := oo.SOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
987 oo.MutexPersOnuConfig.RUnlock()
988 if oo.PMibUploadFsm.PFsm.Is(UlStAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000989 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000990 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000991 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000992 } else {
993 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 +0000994 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000995 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000996 } else if oo.PMibUploadFsm.PFsm.Is(UlStReAuditing) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000997 if mdsValuesAreEqual {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000998 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000999 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001000 } else {
1001 logger.Errorw(ctx, "MibSync FSM - mib audit - MDS check failed for the second time!", log.Fields{"device-id": oo.deviceID})
1002 //TODO: send new event notification "MDS counter mismatch" to the core
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001003 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001004 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001005 } else if oo.PMibUploadFsm.PFsm.Is(UlStExaminingMds) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001006 if mdsValuesAreEqual && mibDataSyncOnu != 0 {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001007 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001008 _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001009 } else {
1010 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001011 _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001012 }
1013 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001014 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 +00001015 }
1016}
mpagenko15ff4a52021-03-02 10:09:20 +00001017
1018//GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
1019func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001020 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001021 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
1022 value := oo.onuSwImageIndications.ActiveEntityEntry.EntityID
Holger Hildebrandt05011352021-06-15 09:40:24 +00001023 oo.mutexOnuSwImageIndications.RUnlock()
1024 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +00001025 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001026 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001027 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
1028}
1029
1030//GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
1031func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001032 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001033 if oo.onuSwImageIndications.InActiveEntityEntry.Valid {
1034 value := oo.onuSwImageIndications.InActiveEntityEntry.EntityID
Holger Hildebrandt05011352021-06-15 09:40:24 +00001035 oo.mutexOnuSwImageIndications.RUnlock()
1036 return value, nil
mpagenko15ff4a52021-03-02 10:09:20 +00001037 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001038 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001039 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
1040}
1041
1042//IsImageToBeCommitted returns true if the active image is still uncommitted
1043func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001044 oo.mutexOnuSwImageIndications.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001045 if oo.onuSwImageIndications.ActiveEntityEntry.Valid {
1046 if oo.onuSwImageIndications.ActiveEntityEntry.EntityID == aImageID {
1047 if oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted == cmn.SwIsUncommitted {
Holger Hildebrandt05011352021-06-15 09:40:24 +00001048 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001049 return true
1050 }
1051 }
1052 }
Holger Hildebrandt05011352021-06-15 09:40:24 +00001053 oo.mutexOnuSwImageIndications.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001054 return false //all other case are treated as 'nothing to commit
1055}
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001056func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool {
1057
1058 oo.mibTemplatePath = oo.buildMibTemplatePath()
Holger Hildebrandtbdc5f002021-04-19 14:46:21 +00001059 logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath),
1060 "device-id": oo.deviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001061
1062 restoredFromMibTemplate := false
1063 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
1064 if err == nil {
1065 if Value != nil {
1066 logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value)
1067
1068 // swap out tokens with specific data
1069 mibTmpString, _ := kvstore.ToString(Value.Value)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001070 oo.MutexPersOnuConfig.RLock()
1071 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.SOnuPersistentData.PersSerialNumber, -1)
1072 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.SOnuPersistentData.PersMacAddress, -1)
1073 oo.MutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001074 mibTmpBytes := []byte(mibTmpString)
1075 logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes)
1076
1077 var firstLevelMap map[string]interface{}
1078 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
1079 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
1080 } else {
1081 for firstLevelKey, firstLevelValue := range firstLevelMap {
1082 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
1083 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
1084 meClassID := me.ClassID(uint16ValidNumber)
1085 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
1086 if isSupportedClassID(meClassID) {
1087 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
1088 secondLevelMap := firstLevelValue.(map[string]interface{})
1089 for secondLevelKey, secondLevelValue := range secondLevelMap {
1090 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
1091 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
1092 meEntityID := uint16(uint16ValidNumber)
1093 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
1094 thirdLevelMap := secondLevelValue.(map[string]interface{})
1095 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
1096 if thirdLevelKey == "Attributes" {
1097 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
1098 attributesMap := thirdLevelValue.(map[string]interface{})
1099 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
1100 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
1101 restoredFromMibTemplate = true
1102 }
1103 }
1104 }
1105 }
1106 }
1107 }
1108 }
1109 }
1110 } else {
1111 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1112 }
1113 } else {
1114 logger.Errorf(ctx, "Get from kvstore operation failed for path",
1115 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
1116 }
1117 return restoredFromMibTemplate
1118}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001119
1120//CancelProcessing terminates potentially running reconciling processes and stops the FSM
1121func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) {
1122
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001123 if oo.IsReconcilingFlows() {
1124 oo.chReconcilingFlowsFinished <- false
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001125 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001126 if oo.baseDeviceHandler.IsReconciling() {
1127 oo.baseDeviceHandler.StopReconciling(ctx, false)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001128 }
1129 //the MibSync FSM might be active all the ONU-active time,
1130 // hence it must be stopped unconditionally
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001131 pMibUlFsm := oo.PMibUploadFsm.PFsm
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001132 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001133 _ = pMibUlFsm.Event(UlEvStop)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001134 }
1135}