blob: 0c71848795cf7fc081a9e46f07ad3d0f78f395fc [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
17//Package adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
19
20import (
Holger Hildebrandt2fb70892020-10-28 11:53:18 +000021 "bytes"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000022 "context"
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000023 "encoding/hex"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000024 "encoding/json"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000025 "errors"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000026 "fmt"
27 "strconv"
mpagenko3af1f032020-06-10 08:53:41 +000028 "strings"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000029
30 "github.com/looplab/fsm"
31
32 //"sync"
divyadesaibbed37c2020-08-28 13:35:20 +053033 "time"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000034
dbainbri4d3a0dc2020-12-02 00:33:42 +000035 //"github.com/opencord/voltha-lib-go/v4/pkg/kafka"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000036 "github.com/opencord/omci-lib-go"
37 me "github.com/opencord/omci-lib-go/generated"
dbainbri4d3a0dc2020-12-02 00:33:42 +000038 "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore"
39 "github.com/opencord/voltha-lib-go/v4/pkg/log"
40 //ic "github.com/opencord/voltha-protos/v4/go/inter_container"
41 //"github.com/opencord/voltha-protos/v4/go/openflow_13"
42 //"github.com/opencord/voltha-protos/v4/go/voltha"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000043)
44
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000045var supportedClassIds = []me.ClassID{
46 me.CardholderClassID, // 5
47 me.CircuitPackClassID, // 6
48 me.SoftwareImageClassID, // 7
49 me.PhysicalPathTerminationPointEthernetUniClassID, // 11
50 me.OltGClassID, // 131
51 me.OnuPowerSheddingClassID, // 133
52 me.IpHostConfigDataClassID, // 134
53 me.OnuGClassID, // 256
54 me.Onu2GClassID, // 257
55 me.TContClassID, // 262
56 me.AniGClassID, // 263
57 me.UniGClassID, // 264
58 me.PriorityQueueClassID, // 277
59 me.TrafficSchedulerClassID, // 278
60 me.VirtualEthernetInterfacePointClassID, // 329
61 me.EnhancedSecurityControlClassID, // 332
62 me.OnuDynamicPowerManagementControlClassID, // 336
63 // 347 // definitions for ME "IPv6 host config data" are currently missing in omci-lib-go!
64}
65
66var fsmMsg TestMessageType
67
dbainbri4d3a0dc2020-12-02 00:33:42 +000068func (oo *OnuDeviceEntry) enterStartingState(ctx context.Context, e *fsm.Event) {
69 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": oo.deviceID})
70 oo.pOnuDB = newOnuDeviceDB(log.WithSpanFromContext(context.TODO(), ctx), oo)
71 go oo.processMibSyncMessages(ctx)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000072}
73
dbainbri4d3a0dc2020-12-02 00:33:42 +000074func (oo *OnuDeviceEntry) enterResettingMibState(ctx context.Context, e *fsm.Event) {
75 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 +000076
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +000077 if !oo.isNewOnu() && !oo.baseDeviceHandler.isReconciling() {
Holger Hildebrandt10d98192021-01-27 15:29:31 +000078 oo.baseDeviceHandler.prepareReconcilingWithActiveAdapter(ctx)
79 oo.devState = DeviceStatusInit
80 }
dbainbri4d3a0dc2020-12-02 00:33:42 +000081 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send mibReset in State": e.FSM.Current(), "device-id": oo.deviceID})
82 _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000083 //TODO: needs to handle timeouts
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000084}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000085
dbainbri4d3a0dc2020-12-02 00:33:42 +000086func (oo *OnuDeviceEntry) enterGettingVendorAndSerialState(ctx context.Context, e *fsm.Event) {
87 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 +000088 requestedAttributes := me.AttributeValueMap{"VendorId": "", "SerialNumber": 0}
Girish Gowdrae09a6202021-01-12 18:10:59 -080089 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.OnuGClassID, onugMeID, requestedAttributes, ConstDefaultOmciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000090 //accept also nil as (error) return value for writing to LastTx
91 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000092 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000093}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000094
dbainbri4d3a0dc2020-12-02 00:33:42 +000095func (oo *OnuDeviceEntry) enterGettingEquipmentIDState(ctx context.Context, e *fsm.Event) {
96 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 +000097 requestedAttributes := me.AttributeValueMap{"EquipmentId": ""}
Girish Gowdrae09a6202021-01-12 18:10:59 -080098 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.Onu2GClassID, onu2gMeID, requestedAttributes, ConstDefaultOmciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000099 //accept also nil as (error) return value for writing to LastTx
100 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000101 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000102}
103
dbainbri4d3a0dc2020-12-02 00:33:42 +0000104func (oo *OnuDeviceEntry) enterGettingFirstSwVersionState(ctx context.Context, e *fsm.Event) {
105 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 +0000106 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Girish Gowdrae09a6202021-01-12 18:10:59 -0800107 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, firstSwImageMeID, requestedAttributes, ConstDefaultOmciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000108 //accept also nil as (error) return value for writing to LastTx
109 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000110 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000111}
112
dbainbri4d3a0dc2020-12-02 00:33:42 +0000113func (oo *OnuDeviceEntry) enterGettingSecondSwVersionState(ctx context.Context, e *fsm.Event) {
114 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 +0000115 requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""}
Girish Gowdrae09a6202021-01-12 18:10:59 -0800116 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, secondSwImageMeID, requestedAttributes, ConstDefaultOmciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000117 //accept also nil as (error) return value for writing to LastTx
118 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000119 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000120}
121
dbainbri4d3a0dc2020-12-02 00:33:42 +0000122func (oo *OnuDeviceEntry) enterGettingMacAddressState(ctx context.Context, e *fsm.Event) {
123 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 +0000124 requestedAttributes := me.AttributeValueMap{"MacAddress": ""}
Girish Gowdrae09a6202021-01-12 18:10:59 -0800125 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.IpHostConfigDataClassID, ipHostConfigDataMeID, requestedAttributes, ConstDefaultOmciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000126 //accept also nil as (error) return value for writing to LastTx
127 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000128 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000129}
130
dbainbri4d3a0dc2020-12-02 00:33:42 +0000131func (oo *OnuDeviceEntry) enterGettingMibTemplate(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000132
mpagenko15ff4a52021-03-02 10:09:20 +0000133 if oo.onuSwImageIndications.activeEntityEntry.valid {
134 oo.activeSwVersion = oo.onuSwImageIndications.activeEntityEntry.version
135 } else {
136 logger.Errorw(ctx, "get-mib-template: no active SW version found, working with empty SW version, which might be untrustworthy",
137 log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000138 }
139
140 meStoredFromTemplate := false
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000141 oo.mibTemplatePath = fmt.Sprintf(cSuffixMibTemplateKvStore, oo.vendorID, oo.equipmentID, oo.activeSwVersion)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000142 logger.Debugw(ctx, "MibSync FSM - MibTemplate - etcd search string", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath)})
143 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000144 if err == nil {
145 if Value != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000146 logger.Debugf(ctx, "MibSync FSM - MibTemplate read: Key: %s, Value: %s %s", Value.Key, Value.Value)
mpagenko3af1f032020-06-10 08:53:41 +0000147
148 // swap out tokens with specific data
149 mibTmpString, _ := kvstore.ToString(Value.Value)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000150 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.serialNumber, -1)
151 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.macAddress, -1)
mpagenko3af1f032020-06-10 08:53:41 +0000152 mibTmpBytes := []byte(mibTmpString)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000153 logger.Debugf(ctx, "MibSync FSM - MibTemplate tokens swapped out: %s", mibTmpBytes)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000154
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000155 var firstLevelMap map[string]interface{}
156 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000157 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000158 } else {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000159 for firstLevelKey, firstLevelValue := range firstLevelMap {
160 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
161 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530162 meClassID := me.ClassID(uint16ValidNumber)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000163 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530164 if isSupportedClassID(meClassID) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000165 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000166 secondLevelMap := firstLevelValue.(map[string]interface{})
167 for secondLevelKey, secondLevelValue := range secondLevelMap {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000168 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000169 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530170 meEntityID := uint16(uint16ValidNumber)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000171 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000172 thirdLevelMap := secondLevelValue.(map[string]interface{})
173 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
Andrea Campanellad10d1db2020-09-08 17:00:29 +0200174 if thirdLevelKey == "Attributes" {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000175 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000176 attributesMap := thirdLevelValue.(map[string]interface{})
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000177 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000178 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000179 meStoredFromTemplate = true
180 }
181 }
182 }
183 }
184 }
185 }
186 }
187 }
188 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000189 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000190 }
191 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000192 logger.Errorf(ctx, "Get from kvstore operation failed for path",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000193 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000194 }
195 if meStoredFromTemplate {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000196 logger.Debug(ctx, "MibSync FSM - valid MEs stored from template")
197 oo.pOnuDB.logMeDb(ctx)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000198 fsmMsg = LoadMibTemplateOk
199 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000200 logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000201 fsmMsg = LoadMibTemplateFailed
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000202
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000203 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
204 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
205 if mibTemplateIsGenerated {
206 logger.Debugw(ctx,
207 "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map",
208 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
209 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
210 }
211 }
212 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
213 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000214 mibSyncMsg := Message{
215 Type: TestMsg,
216 Data: TestMessage{
217 TestMessageVal: fsmMsg,
218 },
219 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000220 oo.pMibUploadFsm.commChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000221}
222
dbainbri4d3a0dc2020-12-02 00:33:42 +0000223func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
224 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send MibUpload in State": e.FSM.Current(), "device-id": oo.deviceID})
225 _ = oo.PDevOmciCC.sendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000226}
227
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000228func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000229 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID})
230 oo.transferSystemEvent(ctx, MibDatabaseSync)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000231 go func() {
232 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
233 }()
234}
235
236func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
237 oo.sOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix())
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000238 if oo.mibAuditInterval > 0 {
239 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 +0000240 go func() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000241 time.Sleep(oo.mibAuditInterval)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000242 if err := oo.pMibUploadFsm.pFsm.Event(ulEvAuditMib); err != nil {
243 logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err})
244 }
245 }()
246 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000247}
248
dbainbri4d3a0dc2020-12-02 00:33:42 +0000249func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
250 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start GetMds processing in State": e.FSM.Current(), "device-id": oo.deviceID})
Holger Hildebrandtfce856b2021-02-12 17:20:41 +0000251 // TODO: As long as story VOL-3834 "Avoid ONU service distruption on adapter restart" is not finished,
252 // we need a full configuration cycle of the ONU to reconcile all local FSM data.
253 // Therefore we simulate a failed MDS check here to trigger this config
254 //oo.requestMdsValue(ctx)
255 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
256 go func() {
257 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
258 }()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000259}
260
dbainbri4d3a0dc2020-12-02 00:33:42 +0000261func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
262 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
263 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000264 // TODOs:
265 // VOL-3805 - Provide exclusive OMCI channel for one FSM
266 // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go
267 // VOL-3792 - Support periodical audit via mib resync
268 // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000269}
270
dbainbri4d3a0dc2020-12-02 00:33:42 +0000271func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000272 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibAudit processing in State": e.FSM.Current(), "device-id": oo.deviceID})
mpagenkof1fc3862021-02-16 10:09:52 +0000273 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000274 oo.requestMdsValue(ctx)
275 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000276 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 +0000277 go func() {
278 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
279 }()
280 }
281}
282
283func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
284 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start retest MdsValue processing in State": e.FSM.Current(), "device-id": oo.deviceID})
mpagenkof1fc3862021-02-16 10:09:52 +0000285 if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000286 oo.requestMdsValue(ctx)
287 } else {
mpagenkof1fc3862021-02-16 10:09:52 +0000288 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 +0000289 go func() {
290 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
291 }()
292 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000293}
294
dbainbri4d3a0dc2020-12-02 00:33:42 +0000295func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
296 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
297 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000298}
299
dbainbri4d3a0dc2020-12-02 00:33:42 +0000300func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
301 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 +0000302loop:
303 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000304 // case <-ctx.Done():
305 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
306 // break loop
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000307 message, ok := <-oo.pMibUploadFsm.commChan
Himani Chawla4d908332020-08-31 12:30:20 +0530308 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000309 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 +0530310 break loop
311 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000312 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000313
Himani Chawla4d908332020-08-31 12:30:20 +0530314 switch message.Type {
315 case TestMsg:
316 msg, _ := message.Data.(TestMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000317 oo.handleTestMsg(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530318 case OMCI:
319 msg, _ := message.Data.(OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000320 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530321 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000322 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 +0000323 }
324 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000325 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000326 // TODO: only this action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000327 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000328}
329
dbainbri4d3a0dc2020-12-02 00:33:42 +0000330func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000331
dbainbri4d3a0dc2020-12-02 00:33:42 +0000332 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 +0000333
334 switch msg.TestMessageVal {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000335 case LoadMibTemplateFailed:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000336 _ = oo.pMibUploadFsm.pFsm.Event(ulEvUploadMib)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000337 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000338 case LoadMibTemplateOk:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000339 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000340 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000341 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000342 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 +0000343 }
344}
345
dbainbri4d3a0dc2020-12-02 00:33:42 +0000346func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg OmciMessage) {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000347 if oo.pMibUploadFsm.pFsm.Is(ulStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530348 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
349 if msgLayer != nil {
350 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
351 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000352 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530353 if msgObj.Result == me.Success {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000354 oo.sOnuPersistentData.PersMibDataSyncAdpt = 0
Himani Chawla4d908332020-08-31 12:30:20 +0530355 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000356 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530357 return
358 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000359 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530360 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000361 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530362 }
363 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000364 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530365 }
366 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000367 logger.Errorw(ctx, "Wrong Omci MibResetResponse received", log.Fields{"in state ": oo.pMibUploadFsm.pFsm.Current,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000368 "device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530369 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000370 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000371 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530372
373}
374
dbainbri4d3a0dc2020-12-02 00:33:42 +0000375func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530376 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
377 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000378 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530379 return
380 }
381 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
382 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000383 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530384 return
385 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000386 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530387 /* to be verified / reworked !!! */
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000388 oo.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
389 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000390 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true)
Himani Chawla4d908332020-08-31 12:30:20 +0530391 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000392 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 +0530393 //TODO right action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000394 _ = oo.pMibUploadFsm.pFsm.Event(ulEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530395 }
396}
397
dbainbri4d3a0dc2020-12-02 00:33:42 +0000398func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530399 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
Andrea Campanella6515c582020-10-05 11:25:00 +0200400
Holger Hildebrandte2439342020-12-03 16:06:54 +0000401 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000402 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000403 return
404 }
405 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
406 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000407 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000408 return
409 }
410 meName := msgObj.ReportedME.GetName()
411 if meName == "UnknownItuG988ManagedEntity" || meName == "UnknownVendorSpecificManagedEntity" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000412 logger.Debugw(ctx, "MibUploadNextResponse Data for unknown ME received - temporary workaround is to ignore it!",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000413 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj, "meName": meName})
414 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000415 logger.Debugw(ctx, "MibUploadNextResponse Data for:",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000416 log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
Holger Hildebrandt8998b872020-10-05 13:48:39 +0000417 meClassID := msgObj.ReportedME.GetClassID()
418 meEntityID := msgObj.ReportedME.GetEntityID()
419 meAttributes := msgObj.ReportedME.GetAttributeValueMap()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000420 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes)
Himani Chawla4d908332020-08-31 12:30:20 +0530421 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000422 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000423 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true)
Himani Chawla4d908332020-08-31 12:30:20 +0530424 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000425 oo.pOnuDB.logMeDb(ctx)
426 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530427 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000428 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 +0530429 }
430
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000431 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530432 }
433}
434
dbainbri4d3a0dc2020-12-02 00:33:42 +0000435func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000436 var err error = nil
Himani Chawla4d908332020-08-31 12:30:20 +0530437 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000438 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000439 logger.Errorw(ctx, "omci Msg layer could not be detected for GetResponse - handling of MibSyncChan stopped", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000440 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
441 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 +0000442 }
443 msgObj, msgOk := msgLayer.(*omci.GetResponse)
444 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000445 logger.Errorw(ctx, "omci Msg layer could not be assigned for GetResponse - handling of MibSyncChan stopped", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000446 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
447 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 +0000448 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000449 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000450 if msgObj.Result == me.Success {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000451 entityID := oo.PDevOmciCC.pLastTxMeInstance.GetEntityID()
452 if msgObj.EntityClass == oo.PDevOmciCC.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000453 meAttributes := msgObj.Attributes
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000454 meInstance := oo.PDevOmciCC.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000455 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 +0000456 switch meInstance {
457 case "OnuG":
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000458 oo.vendorID = trimStringFromInterface(meAttributes["VendorId"])
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000459 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
460 if onugSerialNumberLen == len(snBytes) {
461 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
462 snNumberPart := hex.EncodeToString(snBytes[4:])
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000463 oo.serialNumber = snVendorPart + snNumberPart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000464 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-G - VendorId/SerialNumber", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000465 "onuDeviceEntry.vendorID": oo.vendorID, "onuDeviceEntry.serialNumber": oo.serialNumber})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000466 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000467 logger.Infow(ctx, "MibSync FSM - SerialNumber has wrong length - fill serialNumber with zeros", log.Fields{"device-id": oo.deviceID, "length": len(snBytes)})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000468 oo.serialNumber = cEmptySerialNumberString
Himani Chawla4d908332020-08-31 12:30:20 +0530469 }
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000470 // trigger retrieval of EquipmentId
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000471 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000472 return nil
473 case "Onu2G":
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000474 oo.equipmentID = trimStringFromInterface(meAttributes["EquipmentId"])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000475 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000476 "onuDeviceEntry.equipmentID": oo.equipmentID})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000477 // trigger retrieval of 1st SW-image info
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000478 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000479 return nil
480 case "SoftwareImage":
mpagenko15ff4a52021-03-02 10:09:20 +0000481 if entityID > secondSwImageMeID {
482 logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId",
483 log.Fields{"device-id": oo.deviceID, "entity-ID": entityID})
484 return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x",
485 oo.deviceID, entityID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000486 }
mpagenko15ff4a52021-03-02 10:09:20 +0000487 // need to use function for go lint complexity
488 oo.handleSwImageIndications(ctx, entityID, meAttributes)
489 return nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000490 case "IpHostConfigData":
491 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
492 if omciMacAddressLen == len(macBytes) {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000493 oo.macAddress = hex.EncodeToString(macBytes[:])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000494 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000495 "onuDeviceEntry.macAddress": oo.macAddress})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000496 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000497 logger.Infow(ctx, "MibSync FSM - MacAddress wrong length - fill macAddress with zeros", log.Fields{"device-id": oo.deviceID, "length": len(macBytes)})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000498 oo.macAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000499 }
500 // trigger retrieval of mib template
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000501 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000502 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000503 case "OnuData":
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000504 oo.checkMdsValue(ctx, meAttributes["MibDataSync"].(uint8))
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000505 return nil
Himani Chawla4d908332020-08-31 12:30:20 +0530506 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800507 } else {
508 logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000509 }
Himani Chawla4d908332020-08-31 12:30:20 +0530510 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000511 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000512 return nil
513 }
Himani Chawla4d908332020-08-31 12:30:20 +0530514 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000515 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000516 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000517 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530518}
519
mpagenko15ff4a52021-03-02 10:09:20 +0000520func (oo *OnuDeviceEntry) handleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) {
521 imageIsCommitted := meAttributes["IsCommitted"].(uint8)
522 imageIsActive := meAttributes["IsActive"].(uint8)
523 imageVersion := trimStringFromInterface(meAttributes["Version"])
524 logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage",
525 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
526 "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.serialNumber})
527 if firstSwImageMeID == entityID {
528 //always accept the state of the first image (2nd image info should not yet be available)
529 if imageIsActive == swIsActive {
530 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
531 oo.onuSwImageIndications.activeEntityEntry.valid = true
532 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
533 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
534 } else {
535 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
536 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
537 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
538 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
539 }
540 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion)
541 return
542 } else if secondSwImageMeID == entityID {
543 //2nd image info might conflict with first image info, in which case we priorize first image info!
544 if imageIsActive == swIsActive { //2nd image reported to be active
545 if oo.onuSwImageIndications.activeEntityEntry.valid {
546 //conflict exists - state of first image is left active
547 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive",
548 log.Fields{"device-id": oo.deviceID})
549 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
550 oo.onuSwImageIndications.inactiveEntityEntry.valid = true ////to indicate that at least something has been reported
551 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
552 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
553 } else { //first image inactive, this one active
554 oo.onuSwImageIndications.activeEntityEntry.entityID = entityID
555 oo.onuSwImageIndications.activeEntityEntry.valid = true
556 oo.onuSwImageIndications.activeEntityEntry.version = imageVersion
557 oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted
558 }
559 } else { //2nd image reported to be inactive
560 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
561 //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active
562 logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active",
563 log.Fields{"device-id": oo.deviceID})
564 oo.onuSwImageIndications.activeEntityEntry.entityID = firstSwImageMeID
565 oo.onuSwImageIndications.activeEntityEntry.valid = true //to indicate that at least something has been reported
566 //copy active commit/version from the previously stored inactive position
567 oo.onuSwImageIndications.activeEntityEntry.version = oo.onuSwImageIndications.inactiveEntityEntry.version
568 oo.onuSwImageIndications.activeEntityEntry.isCommitted = oo.onuSwImageIndications.inactiveEntityEntry.isCommitted
569 }
570 //in any case we indicate (and possibly overwrite) the second image indications as inactive
571 oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID
572 oo.onuSwImageIndications.inactiveEntityEntry.valid = true
573 oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion
574 oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted
575 }
576 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress)
577 return
578 }
579}
580
dbainbri4d3a0dc2020-12-02 00:33:42 +0000581func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg OmciMessage) {
582 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200583 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000584 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
585 switch msg.OmciMsg.MessageType {
586 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000587 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000588
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000589 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000590 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530591
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000592 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000593 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000594
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000595 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000596 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000597 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530598
Andrea Campanella6515c582020-10-05 11:25:00 +0200599 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000600 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200601
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000602 }
603}
604
dbainbri4d3a0dc2020-12-02 00:33:42 +0000605func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000606 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000607 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 +0000608 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
609 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
610 entityID := oo.PDevOmciCC.pLastTxMeInstance.GetEntityID()
611 if msgObj.EntityClass == oo.PDevOmciCC.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
612 meInstance := oo.PDevOmciCC.pLastTxMeInstance.GetName()
613 switch meInstance {
614 case "IpHostConfigData":
dbainbri4d3a0dc2020-12-02 00:33:42 +0000615 logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros",
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000616 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
617 oo.macAddress = cEmptyMacAddrString
618 // trigger retrieval of mib template
619 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
620 return nil
621 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000622 logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance)
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000623 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
624 }
625 }
626 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000627 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 +0000628 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
629 }
630 return err
631}
632
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000633func (oo *OnuDeviceEntry) isNewOnu() bool {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000634 return oo.sOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000635}
636
Himani Chawla6d2ae152020-09-02 13:11:20 +0530637func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000638 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530639 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000640 return true
641 }
642 }
643 return false
644}
645
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000646func trimStringFromInterface(input interface{}) string {
647 ifBytes, _ := me.InterfaceToOctets(input)
648 return fmt.Sprintf("%s", bytes.Trim(ifBytes, "\x00"))
649}
650
dbainbri4d3a0dc2020-12-02 00:33:42 +0000651func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
652 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000653 return errors.New("not_implemented")
654}
655
Himani Chawla6d2ae152020-09-02 13:11:20 +0530656// 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 +0530657// 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 +0000658// 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 +0000659func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
660 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000661 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530662
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000663 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
664 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
665 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000666 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000667 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
668 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
669 return nil
670 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000671 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000672 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
673 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000674 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000675 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
676 }
677 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = true
678 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
679
680 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +0530681 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000682 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +0530683 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
684
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000685 firstLevelMap := oo.pOnuDB.meDb
divyadesaibbed37c2020-08-28 13:35:20 +0530686 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000687 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +0530688 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530689
690 secondLevelMap := make(map[string]interface{})
691 for secondLevelKey, secondLevelValue := range firstLevelValue {
692 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +0530693 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530694 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +0530695 thirdLevelMap["InstanceId"] = entityID
696 secondLevelMap[entityID] = thirdLevelMap
697 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +0530698 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
699 delete(forthLevelMap, "SerialNumber")
700 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
701
702 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530703 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +0530704 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
705 delete(forthLevelMap, "MacAddress")
706 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
707 }
708 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530709 secondLevelMap["ClassId"] = classID
710 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +0530711 }
712 mibTemplate, err := json.Marshal(&templateMap)
713 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000714 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000715 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
716 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
717 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530718 return err
719 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000720 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +0530721 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000722 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to store template in etcd", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000723 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
724 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
725 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530726 return err
727 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000728 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530729 return nil
730}
731
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000732func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
733 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
734 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
735 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
Girish Gowdrae09a6202021-01-12 18:10:59 -0800736 me.OnuDataClassID, onuDataMeID, requestedAttributes, ConstDefaultOmciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000737 //accept also nil as (error) return value for writing to LastTx
738 // - this avoids misinterpretation of new received OMCI messages
739 oo.PDevOmciCC.pLastTxMeInstance = meInstance
740}
741
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000742func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
743 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
744 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.sOnuPersistentData.PersMibDataSyncAdpt})
745
746 mdsCheckOk := oo.sOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
747 if oo.pMibUploadFsm.pFsm.Is(ulStAuditing) {
748 if mdsCheckOk {
749 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
750 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
751 } else {
752 logger.Warnw(ctx, "MibSync FSM - mib audit - MDS check failed for the first time!", log.Fields{"device-id": oo.deviceID})
753 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
754 }
755 } else if oo.pMibUploadFsm.pFsm.Is(ulStReAuditing) {
756 if mdsCheckOk {
757 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
758 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
759 } else {
760 logger.Errorw(ctx, "MibSync FSM - mib audit - MDS check failed for the second time!", log.Fields{"device-id": oo.deviceID})
761 //TODO: send new event notification "MDS counter mismatch" to the core
762 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
763 }
764 } else if oo.pMibUploadFsm.pFsm.Is(ulStExaminingMds) {
765 if mdsCheckOk {
766 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
767 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
768 } else {
769 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
770 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
771 }
772 } else {
773 logger.Warnw(ctx, "wrong state for MDS evaluation!", log.Fields{"state": oo.pMibUploadFsm.pFsm.Current(), "device-id": oo.deviceID})
774 }
775}
mpagenko15ff4a52021-03-02 10:09:20 +0000776
777//GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity
778func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) {
779 if oo.onuSwImageIndications.activeEntityEntry.valid {
780 return oo.onuSwImageIndications.activeEntityEntry.entityID, nil
781 }
782 return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID)
783}
784
785//GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity
786func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) {
787 if oo.onuSwImageIndications.inactiveEntityEntry.valid {
788 return oo.onuSwImageIndications.inactiveEntityEntry.entityID, nil
789 }
790 return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID)
791}
792
793//IsImageToBeCommitted returns true if the active image is still uncommitted
794func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool {
795 if oo.onuSwImageIndications.activeEntityEntry.valid {
796 if oo.onuSwImageIndications.activeEntityEntry.entityID == aImageID {
797 if oo.onuSwImageIndications.activeEntityEntry.isCommitted == swIsUncommitted {
798 return true
799 }
800 }
801 }
802 return false //all other case are treated as 'nothing to commit
803}