blob: dd1d25bdfb4b9d936694b3e1a98e4c61dd63633f [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
dbainbri4d3a0dc2020-12-02 00:33:42 +000077 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send mibReset in State": e.FSM.Current(), "device-id": oo.deviceID})
78 _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000079
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000080 //TODO: needs to handle timeouts
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000081}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000082
dbainbri4d3a0dc2020-12-02 00:33:42 +000083func (oo *OnuDeviceEntry) enterGettingVendorAndSerialState(ctx context.Context, e *fsm.Event) {
84 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 +000085 requestedAttributes := me.AttributeValueMap{"VendorId": "", "SerialNumber": 0}
dbainbri4d3a0dc2020-12-02 00:33:42 +000086 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.OnuGClassID, onugMeID, requestedAttributes, ConstDefaultOmciTimeout, true)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000087 //accept also nil as (error) return value for writing to LastTx
88 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000089 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000090}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000091
dbainbri4d3a0dc2020-12-02 00:33:42 +000092func (oo *OnuDeviceEntry) enterGettingEquipmentIDState(ctx context.Context, e *fsm.Event) {
93 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 +000094 requestedAttributes := me.AttributeValueMap{"EquipmentId": ""}
dbainbri4d3a0dc2020-12-02 00:33:42 +000095 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.Onu2GClassID, onu2gMeID, requestedAttributes, ConstDefaultOmciTimeout, true)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000096 //accept also nil as (error) return value for writing to LastTx
97 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000098 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +000099}
100
dbainbri4d3a0dc2020-12-02 00:33:42 +0000101func (oo *OnuDeviceEntry) enterGettingFirstSwVersionState(ctx context.Context, e *fsm.Event) {
102 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 +0000103 requestedAttributes := me.AttributeValueMap{"IsActive": 0, "Version": ""}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000104 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, firstSwImageMeID, requestedAttributes, ConstDefaultOmciTimeout, true)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000105 //accept also nil as (error) return value for writing to LastTx
106 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000107 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000108}
109
dbainbri4d3a0dc2020-12-02 00:33:42 +0000110func (oo *OnuDeviceEntry) enterGettingSecondSwVersionState(ctx context.Context, e *fsm.Event) {
111 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 +0000112 requestedAttributes := me.AttributeValueMap{"IsActive": 0, "Version": ""}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000113 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, secondSwImageMeID, requestedAttributes, ConstDefaultOmciTimeout, true)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000114 //accept also nil as (error) return value for writing to LastTx
115 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000116 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000117}
118
dbainbri4d3a0dc2020-12-02 00:33:42 +0000119func (oo *OnuDeviceEntry) enterGettingMacAddressState(ctx context.Context, e *fsm.Event) {
120 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 +0000121 requestedAttributes := me.AttributeValueMap{"MacAddress": ""}
dbainbri4d3a0dc2020-12-02 00:33:42 +0000122 meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.IpHostConfigDataClassID, ipHostConfigDataMeID, requestedAttributes, ConstDefaultOmciTimeout, true)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000123 //accept also nil as (error) return value for writing to LastTx
124 // - this avoids misinterpretation of new received OMCI messages
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000125 oo.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000126}
127
dbainbri4d3a0dc2020-12-02 00:33:42 +0000128func (oo *OnuDeviceEntry) enterGettingMibTemplate(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000129
Himani Chawla6d2ae152020-09-02 13:11:20 +0530130 for i := firstSwImageMeID; i <= secondSwImageMeID; i++ {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000131 if oo.swImages[i].isActive > 0 {
132 oo.activeSwVersion = oo.swImages[i].version
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000133 }
134 }
135
136 meStoredFromTemplate := false
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000137 oo.mibTemplatePath = fmt.Sprintf(cSuffixMibTemplateKvStore, oo.vendorID, oo.equipmentID, oo.activeSwVersion)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000138 logger.Debugw(ctx, "MibSync FSM - MibTemplate - etcd search string", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath)})
139 Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000140 if err == nil {
141 if Value != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000142 logger.Debugf(ctx, "MibSync FSM - MibTemplate read: Key: %s, Value: %s %s", Value.Key, Value.Value)
mpagenko3af1f032020-06-10 08:53:41 +0000143
144 // swap out tokens with specific data
145 mibTmpString, _ := kvstore.ToString(Value.Value)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000146 mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.serialNumber, -1)
147 mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.macAddress, -1)
mpagenko3af1f032020-06-10 08:53:41 +0000148 mibTmpBytes := []byte(mibTmpString)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000149 logger.Debugf(ctx, "MibSync FSM - MibTemplate tokens swapped out: %s", mibTmpBytes)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000150
151 var fistLevelMap map[string]interface{}
152 if err = json.Unmarshal(mibTmpBytes, &fistLevelMap); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000153 logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000154 } else {
155 for fistLevelKey, firstLevelValue := range fistLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000156 logger.Debugw(ctx, "MibSync FSM - fistLevelKey", log.Fields{"fistLevelKey": fistLevelKey})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000157 if uint16ValidNumber, err := strconv.ParseUint(fistLevelKey, 10, 16); err == nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530158 meClassID := me.ClassID(uint16ValidNumber)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000159 logger.Debugw(ctx, "MibSync FSM - fistLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530160 if isSupportedClassID(meClassID) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000161 logger.Debugw(ctx, "MibSync FSM - fistLevelKey is a supported classID", log.Fields{"meClassID": meClassID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000162 secondLevelMap := firstLevelValue.(map[string]interface{})
163 for secondLevelKey, secondLevelValue := range secondLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000164 logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000165 if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530166 meEntityID := uint16(uint16ValidNumber)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000167 logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000168 thirdLevelMap := secondLevelValue.(map[string]interface{})
169 for thirdLevelKey, thirdLevelValue := range thirdLevelMap {
Andrea Campanellad10d1db2020-09-08 17:00:29 +0200170 if thirdLevelKey == "Attributes" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000171 logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000172 attributesMap := thirdLevelValue.(map[string]interface{})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000173 logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap})
174 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000175 meStoredFromTemplate = true
176 }
177 }
178 }
179 }
180 }
181 }
182 }
183 }
184 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000185 logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000186 }
187 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000188 logger.Errorf(ctx, "Get from kvstore operation failed for path",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000189 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000190 }
191 if meStoredFromTemplate {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000192 logger.Debug(ctx, "MibSync FSM - valid MEs stored from template")
193 oo.pOnuDB.logMeDb(ctx)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000194 fsmMsg = LoadMibTemplateOk
195 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000196 logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000197 fsmMsg = LoadMibTemplateFailed
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000198
Holger Hildebrandt441a0172020-12-10 13:57:08 +0000199 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
200 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
201 if mibTemplateIsGenerated {
202 logger.Debugw(ctx,
203 "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map",
204 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
205 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
206 }
207 }
208 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
209 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000210 mibSyncMsg := Message{
211 Type: TestMsg,
212 Data: TestMessage{
213 TestMessageVal: fsmMsg,
214 },
215 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000216 oo.pMibUploadFsm.commChan <- mibSyncMsg
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000217}
218
dbainbri4d3a0dc2020-12-02 00:33:42 +0000219func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) {
220 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send MibUpload in State": e.FSM.Current(), "device-id": oo.deviceID})
221 _ = oo.PDevOmciCC.sendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000222}
223
dbainbri4d3a0dc2020-12-02 00:33:42 +0000224func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) {
225 logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID})
226 oo.transferSystemEvent(ctx, MibDatabaseSync)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000227}
228
dbainbri4d3a0dc2020-12-02 00:33:42 +0000229func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
230 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start GetMds processing in State": e.FSM.Current(), "device-id": oo.deviceID})
231 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000232}
233
dbainbri4d3a0dc2020-12-02 00:33:42 +0000234func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {
235 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
236 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000237}
238
dbainbri4d3a0dc2020-12-02 00:33:42 +0000239func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) {
240 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID})
241 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000242}
243
dbainbri4d3a0dc2020-12-02 00:33:42 +0000244func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) {
245 logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID})
246 logger.Debug(ctx, "function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000247}
248
dbainbri4d3a0dc2020-12-02 00:33:42 +0000249func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) {
250 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 +0000251loop:
252 for {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000253 // case <-ctx.Done():
254 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
255 // break loop
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000256 message, ok := <-oo.pMibUploadFsm.commChan
Himani Chawla4d908332020-08-31 12:30:20 +0530257 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000258 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 +0530259 break loop
260 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000261 logger.Debugw(ctx, "MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000262
Himani Chawla4d908332020-08-31 12:30:20 +0530263 switch message.Type {
264 case TestMsg:
265 msg, _ := message.Data.(TestMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000266 oo.handleTestMsg(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530267 case OMCI:
268 msg, _ := message.Data.(OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000269 oo.handleOmciMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530270 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000271 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 +0000272 }
273 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000274 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000275 // TODO: only this action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000276 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000277}
278
dbainbri4d3a0dc2020-12-02 00:33:42 +0000279func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg TestMessage) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000280
dbainbri4d3a0dc2020-12-02 00:33:42 +0000281 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 +0000282
283 switch msg.TestMessageVal {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000284 case LoadMibTemplateFailed:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000285 _ = oo.pMibUploadFsm.pFsm.Event(ulEvUploadMib)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000286 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000287 case LoadMibTemplateOk:
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000288 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000289 logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000290 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000291 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 +0000292 }
293}
294
dbainbri4d3a0dc2020-12-02 00:33:42 +0000295func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg OmciMessage) {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000296 if oo.pMibUploadFsm.pFsm.Is(ulStResettingMib) {
Himani Chawla4d908332020-08-31 12:30:20 +0530297 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
298 if msgLayer != nil {
299 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
300 if msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000301 logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530302 if msgObj.Result == me.Success {
303 // trigger retrieval of VendorId and SerialNumber
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000304 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial)
Himani Chawla4d908332020-08-31 12:30:20 +0530305 return
306 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000307 logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result})
Himani Chawla4d908332020-08-31 12:30:20 +0530308 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000309 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530310 }
311 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000312 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530313 }
314 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000315 logger.Errorw(ctx, "Wrong Omci MibResetResponse received", log.Fields{"in state ": oo.pMibUploadFsm.pFsm.Current,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000316 "device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530317 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000318 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000319 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Himani Chawla4d908332020-08-31 12:30:20 +0530320
321}
322
dbainbri4d3a0dc2020-12-02 00:33:42 +0000323func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530324 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
325 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000326 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530327 return
328 }
329 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
330 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000331 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530332 return
333 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000334 logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Himani Chawla4d908332020-08-31 12:30:20 +0530335 /* to be verified / reworked !!! */
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000336 oo.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
337 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000338 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true)
Himani Chawla4d908332020-08-31 12:30:20 +0530339 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000340 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 +0530341 //TODO right action?
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000342 _ = oo.pMibUploadFsm.pFsm.Event(ulEvTimeout)
Himani Chawla4d908332020-08-31 12:30:20 +0530343 }
344}
345
dbainbri4d3a0dc2020-12-02 00:33:42 +0000346func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg OmciMessage) {
Himani Chawla4d908332020-08-31 12:30:20 +0530347 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
Andrea Campanella6515c582020-10-05 11:25:00 +0200348
Holger Hildebrandte2439342020-12-03 16:06:54 +0000349 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000350 logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000351 return
352 }
353 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
354 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000355 logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandte2439342020-12-03 16:06:54 +0000356 return
357 }
358 meName := msgObj.ReportedME.GetName()
359 if meName == "UnknownItuG988ManagedEntity" || meName == "UnknownVendorSpecificManagedEntity" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000360 logger.Debugw(ctx, "MibUploadNextResponse Data for unknown ME received - temporary workaround is to ignore it!",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000361 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj, "meName": meName})
362 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000363 logger.Debugw(ctx, "MibUploadNextResponse Data for:",
Holger Hildebrandte2439342020-12-03 16:06:54 +0000364 log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj})
Holger Hildebrandt8998b872020-10-05 13:48:39 +0000365 meClassID := msgObj.ReportedME.GetClassID()
366 meEntityID := msgObj.ReportedME.GetEntityID()
367 meAttributes := msgObj.ReportedME.GetAttributeValueMap()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000368 oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes)
Himani Chawla4d908332020-08-31 12:30:20 +0530369 }
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000370 if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000371 _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true)
Himani Chawla4d908332020-08-31 12:30:20 +0530372 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000373 oo.pOnuDB.logMeDb(ctx)
374 err := oo.createAndPersistMibTemplate(ctx)
Himani Chawla4d908332020-08-31 12:30:20 +0530375 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000376 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 +0530377 }
378
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000379 _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess)
Himani Chawla4d908332020-08-31 12:30:20 +0530380 }
381}
382
dbainbri4d3a0dc2020-12-02 00:33:42 +0000383func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg OmciMessage) error {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000384 var err error = nil
Himani Chawla4d908332020-08-31 12:30:20 +0530385 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000386 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000387 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 +0000388 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
389 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 +0000390 }
391 msgObj, msgOk := msgLayer.(*omci.GetResponse)
392 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000393 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 +0000394 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
395 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 +0000396 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000397 logger.Debugw(ctx, "MibSync FSM - GetResponse Data", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000398 if msgObj.Result == me.Success {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000399 entityID := oo.PDevOmciCC.pLastTxMeInstance.GetEntityID()
400 if msgObj.EntityClass == oo.PDevOmciCC.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000401 meAttributes := msgObj.Attributes
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000402 meInstance := oo.PDevOmciCC.pLastTxMeInstance.GetName()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000403 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 +0000404 switch meInstance {
405 case "OnuG":
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000406 oo.vendorID = trimStringFromInterface(meAttributes["VendorId"])
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000407 snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"])
408 if onugSerialNumberLen == len(snBytes) {
409 snVendorPart := fmt.Sprintf("%s", snBytes[:4])
410 snNumberPart := hex.EncodeToString(snBytes[4:])
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000411 oo.serialNumber = snVendorPart + snNumberPart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000412 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 +0000413 "onuDeviceEntry.vendorID": oo.vendorID, "onuDeviceEntry.serialNumber": oo.serialNumber})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000414 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000415 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 +0000416 oo.serialNumber = cEmptySerialNumberString
Himani Chawla4d908332020-08-31 12:30:20 +0530417 }
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000418 // trigger retrieval of EquipmentId
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000419 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000420 return nil
421 case "Onu2G":
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000422 oo.equipmentID = trimStringFromInterface(meAttributes["EquipmentId"])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000423 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000424 "onuDeviceEntry.equipmentID": oo.equipmentID})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000425 // trigger retrieval of 1st SW-image info
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000426 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000427 return nil
428 case "SoftwareImage":
429 if entityID <= secondSwImageMeID {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000430 oo.swImages[entityID].version = trimStringFromInterface(meAttributes["Version"])
431 oo.swImages[entityID].isActive = meAttributes["IsActive"].(uint8)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000432 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for SoftwareImage - Version/IsActive",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000433 log.Fields{"device-id": oo.deviceID, "entityID": entityID,
434 "version": oo.swImages[entityID].version, "isActive": oo.swImages[entityID].isActive})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000435 } else {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000436 err = fmt.Errorf("mibSync FSM - Failed to GetResponse Data for SoftwareImage: %s", oo.deviceID)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000437 }
438 if firstSwImageMeID == entityID {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000439 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000440 return nil
441 } else if secondSwImageMeID == entityID {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000442 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000443 return nil
444 }
445 case "IpHostConfigData":
446 macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"])
447 if omciMacAddressLen == len(macBytes) {
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000448 oo.macAddress = hex.EncodeToString(macBytes[:])
dbainbri4d3a0dc2020-12-02 00:33:42 +0000449 logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000450 "onuDeviceEntry.macAddress": oo.macAddress})
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000451 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000452 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 +0000453 oo.macAddress = cEmptyMacAddrString
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000454 }
455 // trigger retrieval of mib template
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000456 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000457 return nil
Himani Chawla4d908332020-08-31 12:30:20 +0530458 }
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000459 }
Himani Chawla4d908332020-08-31 12:30:20 +0530460 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000461 if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000462 return nil
463 }
Himani Chawla4d908332020-08-31 12:30:20 +0530464 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000465 logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000466 _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000467 return err
Himani Chawla4d908332020-08-31 12:30:20 +0530468}
469
dbainbri4d3a0dc2020-12-02 00:33:42 +0000470func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg OmciMessage) {
471 logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200472 "msgType": msg.OmciMsg.MessageType, "msg": msg})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000473 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
474 switch msg.OmciMsg.MessageType {
475 case omci.MibResetResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000476 oo.handleOmciMibResetResponseMessage(ctx, msg)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000477
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000478 case omci.MibUploadResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000479 oo.handleOmciMibUploadResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530480
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000481 case omci.MibUploadNextResponseType:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000482 oo.handleOmciMibUploadNextResponseMessage(ctx, msg)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000483
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000484 case omci.GetResponseType:
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000485 //TODO: error handling
dbainbri4d3a0dc2020-12-02 00:33:42 +0000486 _ = oo.handleOmciGetResponseMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530487
Andrea Campanella6515c582020-10-05 11:25:00 +0200488 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000489 logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType})
Andrea Campanella6515c582020-10-05 11:25:00 +0200490
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000491 }
492}
493
dbainbri4d3a0dc2020-12-02 00:33:42 +0000494func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000495 var err error = nil
dbainbri4d3a0dc2020-12-02 00:33:42 +0000496 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 +0000497 // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME
498 if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported {
499 entityID := oo.PDevOmciCC.pLastTxMeInstance.GetEntityID()
500 if msgObj.EntityClass == oo.PDevOmciCC.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID {
501 meInstance := oo.PDevOmciCC.pLastTxMeInstance.GetName()
502 switch meInstance {
503 case "IpHostConfigData":
dbainbri4d3a0dc2020-12-02 00:33:42 +0000504 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 +0000505 log.Fields{"device-id": oo.deviceID, "data-fields": msgObj})
506 oo.macAddress = cEmptyMacAddrString
507 // trigger retrieval of mib template
508 _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate)
509 return nil
510 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000511 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 +0000512 err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID)
513 }
514 }
515 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000516 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 +0000517 err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID)
518 }
519 return err
520}
521
Himani Chawla6d2ae152020-09-02 13:11:20 +0530522func isSupportedClassID(meClassID me.ClassID) bool {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000523 for _, v := range supportedClassIds {
Himani Chawla4d908332020-08-31 12:30:20 +0530524 if v == meClassID {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000525 return true
526 }
527 }
528 return false
529}
530
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000531func trimStringFromInterface(input interface{}) string {
532 ifBytes, _ := me.InterfaceToOctets(input)
533 return fmt.Sprintf("%s", bytes.Trim(ifBytes, "\x00"))
534}
535
dbainbri4d3a0dc2020-12-02 00:33:42 +0000536func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error {
537 logger.Debug(ctx, "MibVolatileDict- running from default Entry code")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000538 return errors.New("not_implemented")
539}
540
Himani Chawla6d2ae152020-09-02 13:11:20 +0530541// 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 +0530542// 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 +0000543// 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 +0000544func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error {
545 logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath,
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000546 "device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530547
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000548 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
549 if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist {
550 if mibTemplateIsGenerated {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000551 logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000552 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
553 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
554 return nil
555 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000556 logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000557 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
558 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000559 logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation",
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000560 log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID})
561 }
562 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = true
563 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
564
565 currentTime := time.Now()
divyadesaibbed37c2020-08-28 13:35:20 +0530566 templateMap := make(map[string]interface{})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000567 templateMap["TemplateName"] = oo.mibTemplatePath
divyadesaibbed37c2020-08-28 13:35:20 +0530568 templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000")
569
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000570 firstLevelMap := oo.pOnuDB.meDb
divyadesaibbed37c2020-08-28 13:35:20 +0530571 for firstLevelKey, firstLevelValue := range firstLevelMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000572 logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey})
Himani Chawla26e555c2020-08-31 12:30:20 +0530573 classID := strconv.Itoa(int(firstLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530574
575 secondLevelMap := make(map[string]interface{})
576 for secondLevelKey, secondLevelValue := range firstLevelValue {
577 thirdLevelMap := make(map[string]interface{})
Himani Chawla26e555c2020-08-31 12:30:20 +0530578 entityID := strconv.Itoa(int(secondLevelKey))
divyadesaibbed37c2020-08-28 13:35:20 +0530579 thirdLevelMap["Attributes"] = secondLevelValue
Himani Chawla26e555c2020-08-31 12:30:20 +0530580 thirdLevelMap["InstanceId"] = entityID
581 secondLevelMap[entityID] = thirdLevelMap
582 if classID == "6" || classID == "256" {
divyadesaibbed37c2020-08-28 13:35:20 +0530583 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
584 delete(forthLevelMap, "SerialNumber")
585 forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%"
586
587 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530588 if classID == "134" {
divyadesaibbed37c2020-08-28 13:35:20 +0530589 forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap))
590 delete(forthLevelMap, "MacAddress")
591 forthLevelMap["MacAddress"] = "%MAC_ADDRESS%"
592 }
593 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530594 secondLevelMap["ClassId"] = classID
595 templateMap[classID] = secondLevelMap
divyadesaibbed37c2020-08-28 13:35:20 +0530596 }
597 mibTemplate, err := json.Marshal(&templateMap)
598 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000599 logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID})
Holger Hildebrandt61b24d02020-11-16 13:36:40 +0000600 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
601 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
602 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530603 return err
604 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000605 err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate))
divyadesaibbed37c2020-08-28 13:35:20 +0530606 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000607 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 +0000608 oo.pOpenOnuAc.lockMibTemplateGenerated.Lock()
609 oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false
610 oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock()
divyadesaibbed37c2020-08-28 13:35:20 +0530611 return err
612 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000613 logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID})
divyadesaibbed37c2020-08-28 13:35:20 +0530614 return nil
615}
616
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000617// func (onuDeviceEntry *OnuDeviceEntry) MibTemplateTask() error {
618// return errors.New("not_implemented")
619// }
620// func (onuDeviceEntry *OnuDeviceEntry) MibUploadTask() error {
621// return errors.New("not_implemented")
622// }
623// func (onuDeviceEntry *OnuDeviceEntry) GetMdsTask() error {
624// return errors.New("not_implemented")
625// }
626// func (onuDeviceEntry *OnuDeviceEntry) MibResyncTask() error {
627// return errors.New("not_implemented")
628// }
629// func (onuDeviceEntry *OnuDeviceEntry) MibReconcileTask() error {
630// return errors.New("not_implemented")
631// }