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