Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1 | /* |
| 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 |
| 18 | package adaptercoreonu |
| 19 | |
| 20 | import ( |
| 21 | "context" |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 22 | "encoding/hex" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 23 | "encoding/json" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 24 | "errors" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 25 | "fmt" |
| 26 | "strconv" |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 27 | "strings" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 28 | |
| 29 | "github.com/looplab/fsm" |
| 30 | |
| 31 | //"sync" |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 32 | "time" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 33 | |
| 34 | //"github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 35 | "github.com/opencord/omci-lib-go" |
| 36 | me "github.com/opencord/omci-lib-go/generated" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 37 | "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 38 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 39 | //ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 40 | //"github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 41 | //"github.com/opencord/voltha-protos/v3/go/voltha" |
| 42 | ) |
| 43 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 44 | var supportedClassIds = []me.ClassID{ |
| 45 | me.CardholderClassID, // 5 |
| 46 | me.CircuitPackClassID, // 6 |
| 47 | me.SoftwareImageClassID, // 7 |
| 48 | me.PhysicalPathTerminationPointEthernetUniClassID, // 11 |
| 49 | me.OltGClassID, // 131 |
| 50 | me.OnuPowerSheddingClassID, // 133 |
| 51 | me.IpHostConfigDataClassID, // 134 |
| 52 | me.OnuGClassID, // 256 |
| 53 | me.Onu2GClassID, // 257 |
| 54 | me.TContClassID, // 262 |
| 55 | me.AniGClassID, // 263 |
| 56 | me.UniGClassID, // 264 |
| 57 | me.PriorityQueueClassID, // 277 |
| 58 | me.TrafficSchedulerClassID, // 278 |
| 59 | me.VirtualEthernetInterfacePointClassID, // 329 |
| 60 | me.EnhancedSecurityControlClassID, // 332 |
| 61 | me.OnuDynamicPowerManagementControlClassID, // 336 |
| 62 | // 347 // definitions for ME "IPv6 host config data" are currently missing in omci-lib-go! |
| 63 | } |
| 64 | |
| 65 | var fsmMsg TestMessageType |
| 66 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 67 | func (onuDeviceEntry *OnuDeviceEntry) enterStartingState(e *fsm.Event) { |
| 68 | logger.Debugw("MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 69 | onuDeviceEntry.pOnuDB = newOnuDeviceDB(context.TODO(), onuDeviceEntry) |
| 70 | go onuDeviceEntry.processMibSyncMessages() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 73 | func (onuDeviceEntry *OnuDeviceEntry) enterResettingMibState(e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 74 | logger.Debugw("MibSync FSM", log.Fields{"Start MibTemplate processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 75 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 76 | logger.Debugw("MibSync FSM", log.Fields{"send mibReset in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 77 | _ = onuDeviceEntry.PDevOmciCC.sendMibReset(context.TODO(), ConstDefaultOmciTimeout, true) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 78 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 79 | //TODO: needs to handle timeouts |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 80 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 81 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 82 | func (onuDeviceEntry *OnuDeviceEntry) enterGettingVendorAndSerialState(e *fsm.Event) { |
| 83 | logger.Debugw("MibSync FSM", log.Fields{"Start getting VendorId and SerialNumber in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 84 | requestedAttributes := me.AttributeValueMap{"VendorId": "", "SerialNumber": 0} |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 85 | meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.OnuGClassID, onugMeID, requestedAttributes, ConstDefaultOmciTimeout, true) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 86 | //accept also nil as (error) return value for writing to LastTx |
| 87 | // - this avoids misinterpretation of new received OMCI messages |
| 88 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
| 89 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 90 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 91 | func (onuDeviceEntry *OnuDeviceEntry) enterGettingEquipmentIDState(e *fsm.Event) { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 92 | logger.Debugw("MibSync FSM", log.Fields{"Start getting EquipmentId in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 93 | requestedAttributes := me.AttributeValueMap{"EquipmentId": ""} |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 94 | meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.Onu2GClassID, onu2gMeID, requestedAttributes, ConstDefaultOmciTimeout, true) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 95 | //accept also nil as (error) return value for writing to LastTx |
| 96 | // - this avoids misinterpretation of new received OMCI messages |
| 97 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
| 98 | } |
| 99 | |
| 100 | func (onuDeviceEntry *OnuDeviceEntry) enterGettingFirstSwVersionState(e *fsm.Event) { |
| 101 | logger.Debugw("MibSync FSM", log.Fields{"Start getting IsActive and Version of first SW-image in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 102 | requestedAttributes := me.AttributeValueMap{"IsActive": 0, "Version": ""} |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 103 | meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.SoftwareImageClassID, firstSwImageMeID, requestedAttributes, ConstDefaultOmciTimeout, true) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 104 | //accept also nil as (error) return value for writing to LastTx |
| 105 | // - this avoids misinterpretation of new received OMCI messages |
| 106 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
| 107 | } |
| 108 | |
| 109 | func (onuDeviceEntry *OnuDeviceEntry) enterGettingSecondSwVersionState(e *fsm.Event) { |
| 110 | logger.Debugw("MibSync FSM", log.Fields{"Start getting IsActive and Version of second SW-image in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 111 | requestedAttributes := me.AttributeValueMap{"IsActive": 0, "Version": ""} |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 112 | meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.SoftwareImageClassID, secondSwImageMeID, requestedAttributes, ConstDefaultOmciTimeout, true) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 113 | //accept also nil as (error) return value for writing to LastTx |
| 114 | // - this avoids misinterpretation of new received OMCI messages |
| 115 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
| 116 | } |
| 117 | |
| 118 | func (onuDeviceEntry *OnuDeviceEntry) enterGettingMacAddressState(e *fsm.Event) { |
| 119 | logger.Debugw("MibSync FSM", log.Fields{"Start getting MacAddress in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 120 | requestedAttributes := me.AttributeValueMap{"MacAddress": ""} |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 121 | meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.IpHostConfigDataClassID, ipHostConfigDataMeID, requestedAttributes, ConstDefaultOmciTimeout, true) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 122 | //accept also nil as (error) return value for writing to LastTx |
| 123 | // - this avoids misinterpretation of new received OMCI messages |
| 124 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
| 125 | } |
| 126 | |
| 127 | func (onuDeviceEntry *OnuDeviceEntry) enterGettingMibTemplate(e *fsm.Event) { |
| 128 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 129 | for i := firstSwImageMeID; i <= secondSwImageMeID; i++ { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 130 | if onuDeviceEntry.swImages[i].isActive > 0 { |
| 131 | onuDeviceEntry.activeSwVersion = onuDeviceEntry.swImages[i].version |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | meStoredFromTemplate := false |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 136 | path := fmt.Sprintf(cSuffixMibTemplateKvStore, onuDeviceEntry.vendorID, onuDeviceEntry.equipmentID, onuDeviceEntry.activeSwVersion) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 137 | logger.Debugw("MibSync FSM - MibTemplate - etcd search string", log.Fields{"path": path}) |
| 138 | Value, err := onuDeviceEntry.mibTemplateKVStore.Get(context.TODO(), path) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 139 | if err == nil { |
| 140 | if Value != nil { |
| 141 | logger.Debugf("MibSync FSM - MibTemplate read: Key: %s, Value: %s %s", Value.Key, Value.Value) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 142 | |
| 143 | // swap out tokens with specific data |
| 144 | mibTmpString, _ := kvstore.ToString(Value.Value) |
| 145 | mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", onuDeviceEntry.serialNumber, -1) |
| 146 | mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", onuDeviceEntry.macAddress, -1) |
| 147 | mibTmpBytes := []byte(mibTmpString) |
| 148 | logger.Debugf("MibSync FSM - MibTemplate tokens swapped out: %s", mibTmpBytes) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 149 | |
| 150 | var fistLevelMap map[string]interface{} |
| 151 | if err = json.Unmarshal(mibTmpBytes, &fistLevelMap); err != nil { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 152 | logger.Errorw("MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 153 | } else { |
| 154 | for fistLevelKey, firstLevelValue := range fistLevelMap { |
| 155 | logger.Debugw("MibSync FSM - fistLevelKey", log.Fields{"fistLevelKey": fistLevelKey}) |
| 156 | if uint16ValidNumber, err := strconv.ParseUint(fistLevelKey, 10, 16); err == nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 157 | meClassID := me.ClassID(uint16ValidNumber) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 158 | logger.Debugw("MibSync FSM - fistLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 159 | if isSupportedClassID(meClassID) { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 160 | logger.Debugw("MibSync FSM - fistLevelKey is a supported classID", log.Fields{"meClassID": meClassID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 161 | secondLevelMap := firstLevelValue.(map[string]interface{}) |
| 162 | for secondLevelKey, secondLevelValue := range secondLevelMap { |
| 163 | logger.Debugw("MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey}) |
| 164 | if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 165 | meEntityID := uint16(uint16ValidNumber) |
| 166 | logger.Debugw("MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 167 | thirdLevelMap := secondLevelValue.(map[string]interface{}) |
| 168 | for thirdLevelKey, thirdLevelValue := range thirdLevelMap { |
Andrea Campanella | d10d1db | 2020-09-08 17:00:29 +0200 | [diff] [blame] | 169 | if thirdLevelKey == "Attributes" { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 170 | logger.Debugw("MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 171 | attributesMap := thirdLevelValue.(map[string]interface{}) |
| 172 | logger.Debugw("MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 173 | onuDeviceEntry.pOnuDB.PutMe(meClassID, meEntityID, attributesMap) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 174 | meStoredFromTemplate = true |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | } else { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 184 | logger.Debugw("No MIB template found", log.Fields{"path": path, "device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 185 | } |
| 186 | } else { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 187 | logger.Errorf("Get from kvstore operation failed for path", |
| 188 | log.Fields{"path": path, "device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 189 | } |
| 190 | if meStoredFromTemplate { |
| 191 | logger.Debug("MibSync FSM - valid MEs stored from template") |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 192 | onuDeviceEntry.pOnuDB.logMeDb() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 193 | fsmMsg = LoadMibTemplateOk |
| 194 | } else { |
| 195 | logger.Debug("MibSync FSM - no valid MEs stored from template - perform MIB-upload!") |
| 196 | fsmMsg = LoadMibTemplateFailed |
| 197 | } |
| 198 | |
| 199 | mibSyncMsg := Message{ |
| 200 | Type: TestMsg, |
| 201 | Data: TestMessage{ |
| 202 | TestMessageVal: fsmMsg, |
| 203 | }, |
| 204 | } |
| 205 | onuDeviceEntry.pMibUploadFsm.commChan <- mibSyncMsg |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | func (onuDeviceEntry *OnuDeviceEntry) enterUploadingState(e *fsm.Event) { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 209 | logger.Debugw("MibSync FSM", log.Fields{"send MibUpload in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 210 | _ = onuDeviceEntry.PDevOmciCC.sendMibUpload(context.TODO(), ConstDefaultOmciTimeout, true) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | func (onuDeviceEntry *OnuDeviceEntry) enterInSyncState(e *fsm.Event) { |
| 214 | logger.Debugw("MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 215 | onuDeviceEntry.transferSystemEvent(MibDatabaseSync) |
| 216 | } |
| 217 | |
| 218 | func (onuDeviceEntry *OnuDeviceEntry) enterExaminingMdsState(e *fsm.Event) { |
| 219 | logger.Debugw("MibSync FSM", log.Fields{"Start GetMds processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 220 | logger.Debug("function not implemented yet") |
| 221 | } |
| 222 | |
| 223 | func (onuDeviceEntry *OnuDeviceEntry) enterResynchronizingState(e *fsm.Event) { |
| 224 | logger.Debugw("MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 225 | logger.Debug("function not implemented yet") |
| 226 | } |
| 227 | |
| 228 | func (onuDeviceEntry *OnuDeviceEntry) enterAuditingState(e *fsm.Event) { |
| 229 | logger.Debugw("MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 230 | logger.Debug("function not implemented yet") |
| 231 | } |
| 232 | |
| 233 | func (onuDeviceEntry *OnuDeviceEntry) enterOutOfSyncState(e *fsm.Event) { |
| 234 | logger.Debugw("MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 235 | logger.Debug("function not implemented yet") |
| 236 | } |
| 237 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 238 | func (onuDeviceEntry *OnuDeviceEntry) processMibSyncMessages( /*ctx context.Context*/ ) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 239 | logger.Debugw("MibSync Msg", log.Fields{"Start routine to process OMCI-messages for device-id": onuDeviceEntry.deviceID}) |
| 240 | loop: |
| 241 | for { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 242 | // case <-ctx.Done(): |
| 243 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID}) |
| 244 | // break loop |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 245 | message, ok := <-onuDeviceEntry.pMibUploadFsm.commChan |
| 246 | if !ok { |
| 247 | logger.Info("MibSync Msg", log.Fields{"Message couldn't be read from channel for device-id": onuDeviceEntry.deviceID}) |
| 248 | break loop |
| 249 | } |
| 250 | logger.Debugw("MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 251 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 252 | switch message.Type { |
| 253 | case TestMsg: |
| 254 | msg, _ := message.Data.(TestMessage) |
| 255 | onuDeviceEntry.handleTestMsg(msg) |
| 256 | case OMCI: |
| 257 | msg, _ := message.Data.(OmciMessage) |
| 258 | onuDeviceEntry.handleOmciMessage(msg) |
| 259 | default: |
| 260 | logger.Warn("MibSync Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID, "message.Type": message.Type}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | logger.Info("MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": onuDeviceEntry.deviceID}) |
| 264 | // TODO: only this action? |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 265 | _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvStop) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | func (onuDeviceEntry *OnuDeviceEntry) handleTestMsg(msg TestMessage) { |
| 269 | |
| 270 | logger.Debugw("MibSync Msg", log.Fields{"TestMessage received for device-id": onuDeviceEntry.deviceID, "msg.TestMessageVal": msg.TestMessageVal}) |
| 271 | |
| 272 | switch msg.TestMessageVal { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 273 | case LoadMibTemplateFailed: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 274 | _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvUploadMib) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 275 | logger.Debugw("MibSync Msg", log.Fields{"state": string(onuDeviceEntry.pMibUploadFsm.pFsm.Current())}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 276 | case LoadMibTemplateOk: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 277 | _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvSuccess) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 278 | logger.Debugw("MibSync Msg", log.Fields{"state": string(onuDeviceEntry.pMibUploadFsm.pFsm.Current())}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 279 | default: |
| 280 | logger.Warn("MibSync Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID, "msg.TestMessageVal": msg.TestMessageVal}) |
| 281 | } |
| 282 | } |
| 283 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 284 | func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibResetResponseMessage(msg OmciMessage) { |
| 285 | if onuDeviceEntry.pMibUploadFsm.pFsm.Is(ulStResettingMib) { |
| 286 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse) |
| 287 | if msgLayer != nil { |
| 288 | msgObj, msgOk := msgLayer.(*omci.MibResetResponse) |
| 289 | if msgOk { |
| 290 | logger.Debugw("MibResetResponse Data", log.Fields{"data-fields": msgObj}) |
| 291 | if msgObj.Result == me.Success { |
| 292 | // trigger retrieval of VendorId and SerialNumber |
| 293 | _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial) |
| 294 | return |
| 295 | } |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 296 | logger.Errorw("Omci MibResetResponse Error", log.Fields{"deviceId": onuDeviceEntry.deviceID, "Error": msgObj.Result}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 297 | } else { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 298 | logger.Errorw("Omci Msg layer could not be assigned", log.Fields{"deviceId": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 299 | } |
| 300 | } else { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 301 | logger.Errorw("Omci Msg layer could not be detected", log.Fields{"deviceId": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 302 | } |
| 303 | } else { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 304 | logger.Errorw("Wrong Omci MibResetResponse received", log.Fields{"in state ": onuDeviceEntry.pMibUploadFsm.pFsm.Current, |
| 305 | "deviceId": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 306 | } |
| 307 | logger.Info("MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": onuDeviceEntry.deviceID}) |
| 308 | _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvStop) |
| 309 | |
| 310 | } |
| 311 | |
| 312 | func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibUploadResponseMessage(msg OmciMessage) { |
| 313 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse) |
| 314 | if msgLayer == nil { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 315 | logger.Errorw("Omci Msg layer could not be detected", log.Fields{"deviceId": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 316 | return |
| 317 | } |
| 318 | msgObj, msgOk := msgLayer.(*omci.MibUploadResponse) |
| 319 | if !msgOk { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 320 | logger.Errorw("Omci Msg layer could not be assigned", log.Fields{"deviceId": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 321 | return |
| 322 | } |
| 323 | logger.Debugw("MibUploadResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
| 324 | /* to be verified / reworked !!! */ |
| 325 | onuDeviceEntry.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands |
| 326 | if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds { |
| 327 | _ = onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true) |
| 328 | } else { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 329 | logger.Errorw("Invalid number of commands received for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "uploadNoOfCmds": onuDeviceEntry.PDevOmciCC.uploadNoOfCmds}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 330 | //TODO right action? |
| 331 | _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvTimeout) |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(msg OmciMessage) { |
| 336 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 337 | |
Holger Hildebrandt | 8998b87 | 2020-10-05 13:48:39 +0000 | [diff] [blame] | 338 | //TODO: temporary change due to VOL-3532 |
| 339 | // if msgLayer == nil { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 340 | // logger.Errorw("Omci Msg layer could not be detected", log.Fields{"deviceId": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | 8998b87 | 2020-10-05 13:48:39 +0000 | [diff] [blame] | 341 | // return |
| 342 | // } |
| 343 | if msgLayer != nil { |
| 344 | msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse) |
| 345 | if !msgOk { |
| 346 | logger.Errorw("Omci Msg layer could not be assigned", log.Fields{"deviceId": onuDeviceEntry.deviceID}) |
| 347 | return |
| 348 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 349 | logger.Debugw("MibUploadNextResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
Holger Hildebrandt | 8998b87 | 2020-10-05 13:48:39 +0000 | [diff] [blame] | 350 | meClassID := msgObj.ReportedME.GetClassID() |
| 351 | meEntityID := msgObj.ReportedME.GetEntityID() |
| 352 | meAttributes := msgObj.ReportedME.GetAttributeValueMap() |
| 353 | |
| 354 | onuDeviceEntry.pOnuDB.PutMe(meClassID, meEntityID, meAttributes) |
| 355 | } else { |
| 356 | logger.Warnw("msgLayer could not be decoded - temporary workaround for VOL-3532 in place!", log.Fields{"deviceId": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 357 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 358 | if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds { |
| 359 | _ = onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true) |
| 360 | } else { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 361 | onuDeviceEntry.pOnuDB.logMeDb() |
| 362 | err := onuDeviceEntry.createAndPersistMibTemplate() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 363 | if err != nil { |
| 364 | logger.Errorw("MibSync - MibTemplate - Failed to create and persist the mib template", log.Fields{"error": err, "device-id": onuDeviceEntry.deviceID}) |
| 365 | } |
| 366 | |
| 367 | _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvSuccess) |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | func (onuDeviceEntry *OnuDeviceEntry) handleOmciGetResponseMessage(msg OmciMessage) { |
| 372 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse) |
| 373 | if msgLayer != nil { |
| 374 | msgObj, msgOk := msgLayer.(*omci.GetResponse) |
| 375 | if msgOk { |
| 376 | logger.Debugw("MibSync FSM - GetResponse Data", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
| 377 | if msgObj.Result == me.Success { |
| 378 | entityID := onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetEntityID() |
| 379 | if msgObj.EntityClass == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID { |
| 380 | meAttributes := msgObj.Attributes |
| 381 | meInstance := onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetName() |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 382 | logger.Debugf("MibSync FSM - GetResponse Data for %s", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}, meInstance) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 383 | switch meInstance { |
| 384 | case "OnuG": |
| 385 | onuDeviceEntry.vendorID = fmt.Sprintf("%s", meAttributes["VendorId"]) |
| 386 | snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"]) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 387 | if onugSerialNumberLen == len(snBytes) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 388 | snVendorPart := fmt.Sprintf("%s", snBytes[:4]) |
| 389 | snNumberPart := hex.EncodeToString(snBytes[4:]) |
| 390 | onuDeviceEntry.serialNumber = snVendorPart + snNumberPart |
| 391 | logger.Debugw("MibSync FSM - GetResponse Data for Onu-G - VendorId/SerialNumber", log.Fields{"deviceId": onuDeviceEntry.deviceID, |
| 392 | "onuDeviceEntry.vendorID": onuDeviceEntry.vendorID, "onuDeviceEntry.serialNumber": onuDeviceEntry.serialNumber}) |
| 393 | } else { |
| 394 | logger.Errorw("MibSync FSM - SerialNumber has wrong length", log.Fields{"deviceId": onuDeviceEntry.deviceID, "length": len(snBytes)}) |
| 395 | } |
| 396 | // trigger retrieval of EquipmentId |
| 397 | _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentID) |
| 398 | return |
| 399 | case "Onu2G": |
| 400 | onuDeviceEntry.equipmentID = fmt.Sprintf("%s", meAttributes["EquipmentId"]) |
| 401 | logger.Debugw("MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"deviceId": onuDeviceEntry.deviceID, |
| 402 | "onuDeviceEntry.equipmentID": onuDeviceEntry.equipmentID}) |
| 403 | // trigger retrieval of 1st SW-image info |
| 404 | _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion) |
| 405 | return |
| 406 | case "SoftwareImage": |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 407 | if entityID <= secondSwImageMeID { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 408 | onuDeviceEntry.swImages[entityID].version = fmt.Sprintf("%s", meAttributes["Version"]) |
| 409 | onuDeviceEntry.swImages[entityID].isActive = meAttributes["IsActive"].(uint8) |
| 410 | logger.Debugw("MibSync FSM - GetResponse Data for SoftwareImage - Version/IsActive", |
| 411 | log.Fields{"deviceId": onuDeviceEntry.deviceID, "entityID": entityID, |
| 412 | "version": onuDeviceEntry.swImages[entityID].version, "isActive": onuDeviceEntry.swImages[entityID].isActive}) |
| 413 | } else { |
| 414 | //TODO: error handling |
| 415 | logger.Errorw("MibSync FSM - Failed to GetResponse Data for SoftwareImage", log.Fields{"deviceId": onuDeviceEntry.deviceID}) |
| 416 | |
| 417 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 418 | if firstSwImageMeID == entityID { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 419 | _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion) |
| 420 | return |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 421 | } else if secondSwImageMeID == entityID { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 422 | _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress) |
| 423 | return |
| 424 | } |
| 425 | case "IpHostConfigData": |
| 426 | macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"]) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 427 | if omciMacAddressLen == len(macBytes) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 428 | onuDeviceEntry.macAddress = hex.EncodeToString(macBytes[:]) |
| 429 | logger.Debugw("MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"deviceId": onuDeviceEntry.deviceID, |
| 430 | "onuDeviceEntry.macAddress": onuDeviceEntry.macAddress}) |
| 431 | } else { |
| 432 | logger.Errorw("MibSync FSM - MacAddress wrong length", log.Fields{"deviceId": onuDeviceEntry.deviceID, "length": len(macBytes)}) |
| 433 | } |
| 434 | // trigger retrieval of mib template |
| 435 | _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate) |
| 436 | return |
| 437 | } |
| 438 | } |
| 439 | } else { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 440 | logger.Errorw("Omci GetResponse Error", log.Fields{"deviceId": onuDeviceEntry.deviceID, "Error": msgObj.Result}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 441 | } |
| 442 | } else { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 443 | logger.Errorw("Omci Msg layer could not be assigned for GetResponse", log.Fields{"deviceId": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 444 | } |
| 445 | } else { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 446 | logger.Errorw("Omci Msg layer could not be detected for GetResponse", log.Fields{"deviceId": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 447 | } |
| 448 | logger.Info("MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": onuDeviceEntry.deviceID}) |
| 449 | _ = onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvStop) |
| 450 | } |
| 451 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 452 | func (onuDeviceEntry *OnuDeviceEntry) handleOmciMessage(msg OmciMessage) { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 453 | logger.Debugw("MibSync Msg", log.Fields{"OmciMessage received for device-id": onuDeviceEntry.deviceID, |
| 454 | "msgType": msg.OmciMsg.MessageType, "msg": msg}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 455 | //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ... |
| 456 | switch msg.OmciMsg.MessageType { |
| 457 | case omci.MibResetResponseType: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 458 | onuDeviceEntry.handleOmciMibResetResponseMessage(msg) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 459 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 460 | case omci.MibUploadResponseType: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 461 | onuDeviceEntry.handleOmciMibUploadResponseMessage(msg) |
| 462 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 463 | case omci.MibUploadNextResponseType: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 464 | onuDeviceEntry.handleOmciMibUploadNextResponseMessage(msg) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 465 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 466 | case omci.GetResponseType: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 467 | onuDeviceEntry.handleOmciGetResponseMessage(msg) |
| 468 | |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 469 | default: |
| 470 | log.Warnw("Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType}) |
| 471 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 475 | func isSupportedClassID(meClassID me.ClassID) bool { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 476 | for _, v := range supportedClassIds { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 477 | if v == meClassID { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 478 | return true |
| 479 | } |
| 480 | } |
| 481 | return false |
| 482 | } |
| 483 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 484 | func (onuDeviceEntry *OnuDeviceEntry) mibDbVolatileDict() error { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 485 | logger.Debug("MibVolatileDict- running from default Entry code") |
| 486 | return errors.New("not_implemented") |
| 487 | } |
| 488 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 489 | // createAndPersistMibTemplate method creates a mib template for the device id when operator enables the ONU device for the first time. |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 490 | // We are creating a placeholder for "SerialNumber" for ME Class ID 6 and 256 and "MacAddress" for ME Class ID 134 in the template |
| 491 | // and then storing the template into etcd "service/voltha/omci_mibs/templates/verdor_id/equipment_id/software_version" path. |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 492 | func (onuDeviceEntry *OnuDeviceEntry) createAndPersistMibTemplate() error { |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 493 | path := fmt.Sprintf(cSuffixMibTemplateKvStore, onuDeviceEntry.vendorID, onuDeviceEntry.equipmentID, onuDeviceEntry.activeSwVersion) |
| 494 | logger.Debugw("MibSync - MibTemplate - key name", log.Fields{"path": path}) |
| 495 | currentTime := time.Now() |
| 496 | |
| 497 | templateMap := make(map[string]interface{}) |
| 498 | templateMap["TemplateName"] = path |
| 499 | templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000") |
| 500 | |
| 501 | firstLevelMap := onuDeviceEntry.pOnuDB.meDb |
| 502 | for firstLevelKey, firstLevelValue := range firstLevelMap { |
| 503 | logger.Debugw("MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 504 | classID := strconv.Itoa(int(firstLevelKey)) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 505 | |
| 506 | secondLevelMap := make(map[string]interface{}) |
| 507 | for secondLevelKey, secondLevelValue := range firstLevelValue { |
| 508 | thirdLevelMap := make(map[string]interface{}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 509 | entityID := strconv.Itoa(int(secondLevelKey)) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 510 | thirdLevelMap["Attributes"] = secondLevelValue |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 511 | thirdLevelMap["InstanceId"] = entityID |
| 512 | secondLevelMap[entityID] = thirdLevelMap |
| 513 | if classID == "6" || classID == "256" { |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 514 | forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap)) |
| 515 | delete(forthLevelMap, "SerialNumber") |
| 516 | forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%" |
| 517 | |
| 518 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 519 | if classID == "134" { |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 520 | forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap)) |
| 521 | delete(forthLevelMap, "MacAddress") |
| 522 | forthLevelMap["MacAddress"] = "%MAC_ADDRESS%" |
| 523 | } |
| 524 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 525 | secondLevelMap["ClassId"] = classID |
| 526 | templateMap[classID] = secondLevelMap |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 527 | } |
| 528 | mibTemplate, err := json.Marshal(&templateMap) |
| 529 | if err != nil { |
| 530 | logger.Errorw("MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": onuDeviceEntry.deviceID}) |
| 531 | return err |
| 532 | } |
| 533 | err = onuDeviceEntry.mibTemplateKVStore.Put(context.TODO(), path, string(mibTemplate)) |
| 534 | if err != nil { |
| 535 | logger.Errorw("MibSync - MibTemplate - Failed to store template in etcd", log.Fields{"error": err, "device-id": onuDeviceEntry.deviceID}) |
| 536 | return err |
| 537 | } |
| 538 | logger.Debugw("MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 539 | return nil |
| 540 | } |
| 541 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 542 | // func (onuDeviceEntry *OnuDeviceEntry) MibTemplateTask() error { |
| 543 | // return errors.New("not_implemented") |
| 544 | // } |
| 545 | // func (onuDeviceEntry *OnuDeviceEntry) MibUploadTask() error { |
| 546 | // return errors.New("not_implemented") |
| 547 | // } |
| 548 | // func (onuDeviceEntry *OnuDeviceEntry) GetMdsTask() error { |
| 549 | // return errors.New("not_implemented") |
| 550 | // } |
| 551 | // func (onuDeviceEntry *OnuDeviceEntry) MibResyncTask() error { |
| 552 | // return errors.New("not_implemented") |
| 553 | // } |
| 554 | // func (onuDeviceEntry *OnuDeviceEntry) MibReconcileTask() error { |
| 555 | // return errors.New("not_implemented") |
| 556 | // } |