blob: 4f1ac22bdc41e91817967ecf2702564041bf48b1 [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 Hildebrandt10d98192021-01-27 15:29:31 +000077 if !oo.isNewOnu() {
78 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})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000106 requestedAttributes := me.AttributeValueMap{"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})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000115 requestedAttributes := me.AttributeValueMap{"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
Himani Chawla6d2ae152020-09-02 13:11:20 +0530133 for i := firstSwImageMeID; i <= secondSwImageMeID; i++ {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000134 if oo.swImages[i].isActive > 0 {
135 oo.activeSwVersion = oo.swImages[i].version
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000136 }
137 }
138
139 meStoredFromTemplate := false
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000140 oo.mibTemplatePath = fmt.Sprintf(cSuffixMibTemplateKvStore, oo.vendorID, oo.equipmentID, oo.activeSwVersion)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000141 logger.Debugw(ctx, "MibSync FSM - MibTemplate - etcd search string", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath)})
142 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000143 if err == nil {
144 if Value != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000145 logger.Debugf(ctx, "MibSync FSM - MibTemplate read: Key: %s, Value: %s %s", Value.Key, Value.Value)
mpagenko3af1f032020-06-10 08:53:41 +0000146
147 // swap out tokens with specific data
148 mibTmpString, _ := kvstore.ToString(Value.Value)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000149 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.serialNumber, -1)
150 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.macAddress, -1)
mpagenko3af1f032020-06-10 08:53:41 +0000151 mibTmpBytes := []byte(mibTmpString)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000152 logger.Debugf(ctx, "MibSync FSM - MibTemplate tokens swapped out: %s", mibTmpBytes)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000153
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000154 var firstLevelMap map[string]interface{}
155 if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000156 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000157 } else {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000158 for firstLevelKey, firstLevelValue := range firstLevelMap {
159 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
160 if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530161 meClassID := me.ClassID(uint16ValidNumber)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000162 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530163 if isSupportedClassID(meClassID) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000164 //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000165 secondLevelMap := firstLevelValue.(map[string]interface{})
166 for secondLevelKey, secondLevelValue := range secondLevelMap {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000167 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000168 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530169 meEntityID := uint16(uint16ValidNumber)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000170 //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000171 thirdLevelMap := secondLevelValue.(map[string]interface{})
172 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
Andrea Campanellad10d1db2020-09-08 17:00:29 +0200173 if thirdLevelKey == "Attributes" {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000174 //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000175 attributesMap := thirdLevelValue.(map[string]interface{})
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000176 //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000177 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000178 meStoredFromTemplate = true
179 }
180 }
181 }
182 }
183 }
184 }
185 }
186 }
187 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000188 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000189 }
190 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000191 logger.Errorf(ctx, "Get from kvstore operation failed for path",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000192 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000193 }
194 if meStoredFromTemplate {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000195 logger.Debug(ctx, "MibSync FSM - valid MEs stored from template")
196 oo.pOnuDB.logMeDb(ctx)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000197 fsmMsg = LoadMibTemplateOk
198 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000199 logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000200 fsmMsg = LoadMibTemplateFailed
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000201
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000202 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
203 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
204 if mibTemplateIsGenerated {
205 logger.Debugw(ctx,
206 "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map",
207 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
208 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
209 }
210 }
211 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
212 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000213 mibSyncMsg := Message{
214 Type: TestMsg,
215 Data: TestMessage{
216 TestMessageVal: fsmMsg,
217 },
218 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000219 oo.pMibUploadFsm.commChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000220}
221
dbainbri4d3a0dc2020-12-02 00:33:42 +0000222func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
223 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send MibUpload in State": e.FSM.Current(), "device-id": oo.deviceID})
224 _ = oo.PDevOmciCC.sendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000225}
226
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000227func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000228 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID})
229 oo.transferSystemEvent(ctx, MibDatabaseSync)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000230 go func() {
231 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
232 }()
233}
234
235func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
236 oo.sOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix())
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000237 if oo.mibAuditInterval > 0 {
238 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 +0000239 go func() {
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000240 time.Sleep(oo.mibAuditInterval)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000241 if err := oo.pMibUploadFsm.pFsm.Event(ulEvAuditMib); err != nil {
242 logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err})
243 }
244 }()
245 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000246}
247
dbainbri4d3a0dc2020-12-02 00:33:42 +0000248func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
249 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 +0000250 // TODO: As long as story VOL-3834 "Avoid ONU service distruption on adapter restart" is not finished,
251 // we need a full configuration cycle of the ONU to reconcile all local FSM data.
252 // Therefore we simulate a failed MDS check here to trigger this config
253 //oo.requestMdsValue(ctx)
254 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
255 go func() {
256 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
257 }()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000258}
259
dbainbri4d3a0dc2020-12-02 00:33:42 +0000260func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
261 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
262 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000263 // TODOs:
264 // VOL-3805 - Provide exclusive OMCI channel for one FSM
265 // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go
266 // VOL-3792 - Support periodical audit via mib resync
267 // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000268}
269
dbainbri4d3a0dc2020-12-02 00:33:42 +0000270func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000271 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibAudit processing in State": e.FSM.Current(), "device-id": oo.deviceID})
272 if oo.baseDeviceHandler.allButCallingFsmInIdleState(ctx, cUploadFsm) {
273 oo.requestMdsValue(ctx)
274 } else {
275 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Configuration is ongoing - skip auditing!": e.FSM.Current(), "device-id": oo.deviceID})
276 go func() {
277 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
278 }()
279 }
280}
281
282func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) {
283 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start retest MdsValue processing in State": e.FSM.Current(), "device-id": oo.deviceID})
284 if oo.baseDeviceHandler.allButCallingFsmInIdleState(ctx, cUploadFsm) {
285 oo.requestMdsValue(ctx)
286 } else {
287 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Configuration is ongoing - skip re-auditing!": e.FSM.Current(), "device-id": oo.deviceID})
288 go func() {
289 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
290 }()
291 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000292}
293
dbainbri4d3a0dc2020-12-02 00:33:42 +0000294func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
295 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
296 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000297}
298
dbainbri4d3a0dc2020-12-02 00:33:42 +0000299func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
300 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 +0000301loop:
302 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000303 // case <-ctx.Done():
304 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
305 // break loop
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000306 message, ok := <-oo.pMibUploadFsm.commChan
Himani Chawla4d908332020-08-31 12:30:20 +0530307 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000308 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 +0530309 break loop
310 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000311 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000312
Himani Chawla4d908332020-08-31 12:30:20 +0530313 switch message.Type {
314 case TestMsg:
315 msg, _ := message.Data.(TestMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000316 oo.handleTestMsg(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530317 case OMCI:
318 msg, _ := message.Data.(OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000319 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530320 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000321 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 +0000322 }
323 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000324 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000325 // TODO: only this action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000326 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000327}
328
dbainbri4d3a0dc2020-12-02 00:33:42 +0000329func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000330
dbainbri4d3a0dc2020-12-02 00:33:42 +0000331 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 +0000332
333 switch msg.TestMessageVal {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000334 case LoadMibTemplateFailed:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000335 _ = oo.pMibUploadFsm.pFsm.Event(ulEvUploadMib)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000336 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000337 case LoadMibTemplateOk:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000338 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000339 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000340 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000341 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 +0000342 }
343}
344
dbainbri4d3a0dc2020-12-02 00:33:42 +0000345func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg OmciMessage) {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000346 if oo.pMibUploadFsm.pFsm.Is(ulStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530347 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
348 if msgLayer != nil {
349 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
350 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000351 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530352 if msgObj.Result == me.Success {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000353 oo.sOnuPersistentData.PersMibDataSyncAdpt = 0
Himani Chawla4d908332020-08-31 12:30:20 +0530354 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000355 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530356 return
357 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000358 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530359 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000360 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530361 }
362 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000363 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530364 }
365 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000366 logger.Errorw(ctx, "Wrong Omci MibResetResponse received", log.Fields{"in state ": oo.pMibUploadFsm.pFsm.Current,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000367 "device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530368 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000369 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000370 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530371
372}
373
dbainbri4d3a0dc2020-12-02 00:33:42 +0000374func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530375 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
376 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000377 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530378 return
379 }
380 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
381 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000382 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530383 return
384 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000385 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530386 /* to be verified / reworked !!! */
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000387 oo.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
388 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000389 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true)
Himani Chawla4d908332020-08-31 12:30:20 +0530390 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000391 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 +0530392 //TODO right action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000393 _ = oo.pMibUploadFsm.pFsm.Event(ulEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530394 }
395}
396
dbainbri4d3a0dc2020-12-02 00:33:42 +0000397func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530398 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
Andrea Campanella6515c582020-10-05 11:25:00 +0200399
Holger Hildebrandte2439342020-12-03 16:06:54 +0000400 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000401 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000402 return
403 }
404 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
405 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000406 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000407 return
408 }
409 meName := msgObj.ReportedME.GetName()
410 if meName == "UnknownItuG988ManagedEntity" || meName == "UnknownVendorSpecificManagedEntity" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000411 logger.Debugw(ctx, "MibUploadNextResponse Data for unknown ME received - temporary workaround is to ignore it!",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000412 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj, "meName": meName})
413 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000414 logger.Debugw(ctx, "MibUploadNextResponse Data for:",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000415 log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
Holger Hildebrandt8998b872020-10-05 13:48:39 +0000416 meClassID := msgObj.ReportedME.GetClassID()
417 meEntityID := msgObj.ReportedME.GetEntityID()
418 meAttributes := msgObj.ReportedME.GetAttributeValueMap()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000419 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes)
Himani Chawla4d908332020-08-31 12:30:20 +0530420 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000421 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000422 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true)
Himani Chawla4d908332020-08-31 12:30:20 +0530423 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000424 oo.pOnuDB.logMeDb(ctx)
425 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530426 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000427 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 +0530428 }
429
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000430 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530431 }
432}
433
dbainbri4d3a0dc2020-12-02 00:33:42 +0000434func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000435 var err error = nil
Himani Chawla4d908332020-08-31 12:30:20 +0530436 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000437 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000438 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 +0000439 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
440 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 +0000441 }
442 msgObj, msgOk := msgLayer.(*omci.GetResponse)
443 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000444 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 +0000445 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
446 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 +0000447 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000448 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000449 if msgObj.Result == me.Success {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000450 entityID := oo.PDevOmciCC.pLastTxMeInstance.GetEntityID()
451 if msgObj.EntityClass == oo.PDevOmciCC.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000452 meAttributes := msgObj.Attributes
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000453 meInstance := oo.PDevOmciCC.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000454 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 +0000455 switch meInstance {
456 case "OnuG":
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000457 oo.vendorID = trimStringFromInterface(meAttributes["VendorId"])
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000458 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
459 if onugSerialNumberLen == len(snBytes) {
460 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
461 snNumberPart := hex.EncodeToString(snBytes[4:])
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000462 oo.serialNumber = snVendorPart + snNumberPart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000463 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 +0000464 "onuDeviceEntry.vendorID": oo.vendorID, "onuDeviceEntry.serialNumber": oo.serialNumber})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000465 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000466 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 +0000467 oo.serialNumber = cEmptySerialNumberString
Himani Chawla4d908332020-08-31 12:30:20 +0530468 }
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000469 // trigger retrieval of EquipmentId
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000470 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000471 return nil
472 case "Onu2G":
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000473 oo.equipmentID = trimStringFromInterface(meAttributes["EquipmentId"])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000474 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000475 "onuDeviceEntry.equipmentID": oo.equipmentID})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000476 // trigger retrieval of 1st SW-image info
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000477 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000478 return nil
479 case "SoftwareImage":
480 if entityID <= secondSwImageMeID {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000481 oo.swImages[entityID].version = trimStringFromInterface(meAttributes["Version"])
482 oo.swImages[entityID].isActive = meAttributes["IsActive"].(uint8)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000483 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for SoftwareImage - Version/IsActive",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000484 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
485 "version": oo.swImages[entityID].version, "isActive": oo.swImages[entityID].isActive})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000486 } else {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000487 err = fmt.Errorf("mibSync FSM - Failed to GetResponse Data for SoftwareImage: %s", oo.deviceID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000488 }
489 if firstSwImageMeID == entityID {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000490 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000491 return nil
492 } else if secondSwImageMeID == entityID {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000493 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000494 return nil
495 }
496 case "IpHostConfigData":
497 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
498 if omciMacAddressLen == len(macBytes) {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000499 oo.macAddress = hex.EncodeToString(macBytes[:])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000500 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000501 "onuDeviceEntry.macAddress": oo.macAddress})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000502 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000503 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 +0000504 oo.macAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000505 }
506 // trigger retrieval of mib template
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000507 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000508 return nil
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000509 case "OnuData":
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000510 oo.checkMdsValue(ctx, meAttributes["MibDataSync"].(uint8))
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000511 return nil
Himani Chawla4d908332020-08-31 12:30:20 +0530512 }
Matteo Scandolo20ca10c2021-01-21 14:35:45 -0800513 } else {
514 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 +0000515 }
Himani Chawla4d908332020-08-31 12:30:20 +0530516 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000517 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000518 return nil
519 }
Himani Chawla4d908332020-08-31 12:30:20 +0530520 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000521 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000522 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000523 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530524}
525
dbainbri4d3a0dc2020-12-02 00:33:42 +0000526func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg OmciMessage) {
527 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200528 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000529 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
530 switch msg.OmciMsg.MessageType {
531 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000532 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000533
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000534 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000535 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530536
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000537 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000538 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000539
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000540 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000541 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000542 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530543
Andrea Campanella6515c582020-10-05 11:25:00 +0200544 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000545 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200546
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000547 }
548}
549
dbainbri4d3a0dc2020-12-02 00:33:42 +0000550func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000551 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000552 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 +0000553 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
554 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
555 entityID := oo.PDevOmciCC.pLastTxMeInstance.GetEntityID()
556 if msgObj.EntityClass == oo.PDevOmciCC.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
557 meInstance := oo.PDevOmciCC.pLastTxMeInstance.GetName()
558 switch meInstance {
559 case "IpHostConfigData":
dbainbri4d3a0dc2020-12-02 00:33:42 +0000560 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 +0000561 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
562 oo.macAddress = cEmptyMacAddrString
563 // trigger retrieval of mib template
564 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
565 return nil
566 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000567 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 +0000568 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
569 }
570 }
571 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000572 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 +0000573 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
574 }
575 return err
576}
577
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000578func (oo *OnuDeviceEntry) isNewOnu() bool {
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000579 return oo.sOnuPersistentData.PersMibLastDbSync == 0
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000580}
581
Himani Chawla6d2ae152020-09-02 13:11:20 +0530582func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000583 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530584 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000585 return true
586 }
587 }
588 return false
589}
590
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000591func trimStringFromInterface(input interface{}) string {
592 ifBytes, _ := me.InterfaceToOctets(input)
593 return fmt.Sprintf("%s", bytes.Trim(ifBytes, "\x00"))
594}
595
dbainbri4d3a0dc2020-12-02 00:33:42 +0000596func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
597 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000598 return errors.New("not_implemented")
599}
600
Himani Chawla6d2ae152020-09-02 13:11:20 +0530601// 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 +0530602// 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 +0000603// 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 +0000604func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
605 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000606 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530607
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000608 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
609 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
610 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000611 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000612 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
613 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
614 return nil
615 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000616 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000617 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
618 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000619 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000620 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
621 }
622 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = true
623 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
624
625 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +0530626 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000627 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +0530628 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
629
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000630 firstLevelMap := oo.pOnuDB.meDb
divyadesaibbed37c2020-08-28 13:35:20 +0530631 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000632 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +0530633 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530634
635 secondLevelMap := make(map[string]interface{})
636 for secondLevelKey, secondLevelValue := range firstLevelValue {
637 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +0530638 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530639 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +0530640 thirdLevelMap["InstanceId"] = entityID
641 secondLevelMap[entityID] = thirdLevelMap
642 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +0530643 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
644 delete(forthLevelMap, "SerialNumber")
645 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
646
647 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530648 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +0530649 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
650 delete(forthLevelMap, "MacAddress")
651 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
652 }
653 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530654 secondLevelMap["ClassId"] = classID
655 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +0530656 }
657 mibTemplate, err := json.Marshal(&templateMap)
658 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000659 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000660 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
661 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
662 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530663 return err
664 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000665 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +0530666 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000667 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 +0000668 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
669 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
670 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530671 return err
672 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000673 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530674 return nil
675}
676
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000677func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) {
678 logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID})
679 requestedAttributes := me.AttributeValueMap{"MibDataSync": ""}
680 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx),
Girish Gowdrae09a6202021-01-12 18:10:59 -0800681 me.OnuDataClassID, onuDataMeID, requestedAttributes, ConstDefaultOmciTimeout, true, oo.pMibUploadFsm.commChan)
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000682 //accept also nil as (error) return value for writing to LastTx
683 // - this avoids misinterpretation of new received OMCI messages
684 oo.PDevOmciCC.pLastTxMeInstance = meInstance
685}
686
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000687func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) {
688 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID,
689 "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.sOnuPersistentData.PersMibDataSyncAdpt})
690
691 mdsCheckOk := oo.sOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu
692 if oo.pMibUploadFsm.pFsm.Is(ulStAuditing) {
693 if mdsCheckOk {
694 logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID})
695 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
696 } else {
697 logger.Warnw(ctx, "MibSync FSM - mib audit - MDS check failed for the first time!", log.Fields{"device-id": oo.deviceID})
698 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
699 }
700 } else if oo.pMibUploadFsm.pFsm.Is(ulStReAuditing) {
701 if mdsCheckOk {
702 logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID})
703 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
704 } else {
705 logger.Errorw(ctx, "MibSync FSM - mib audit - MDS check failed for the second time!", log.Fields{"device-id": oo.deviceID})
706 //TODO: send new event notification "MDS counter mismatch" to the core
707 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
708 }
709 } else if oo.pMibUploadFsm.pFsm.Is(ulStExaminingMds) {
710 if mdsCheckOk {
711 logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID})
712 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
713 } else {
714 logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID})
715 _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch)
716 }
717 } else {
718 logger.Warnw(ctx, "wrong state for MDS evaluation!", log.Fields{"state": oo.pMibUploadFsm.pFsm.Current(), "device-id": oo.deviceID})
719 }
720}