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" |
| 32 | //"time" |
| 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}) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 69 | onuDeviceEntry.pOnuDB = NewOnuDeviceDB(context.TODO(), onuDeviceEntry) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 70 | go onuDeviceEntry.ProcessMibSyncMessages() |
| 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}) |
| 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} |
| 85 | meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.OnuGClassID, OnugMeId, requestedAttributes, ConstDefaultOmciTimeout, true) |
| 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 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 91 | func (onuDeviceEntry *OnuDeviceEntry) enterGettingEquipmentIdState(e *fsm.Event) { |
| 92 | logger.Debugw("MibSync FSM", log.Fields{"Start getting EquipmentId in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 93 | requestedAttributes := me.AttributeValueMap{"EquipmentId": ""} |
| 94 | meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.Onu2GClassID, Onu2gMeId, requestedAttributes, ConstDefaultOmciTimeout, true) |
| 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": ""} |
| 103 | meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.SoftwareImageClassID, FirstSwImageMeId, requestedAttributes, ConstDefaultOmciTimeout, true) |
| 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": ""} |
| 112 | meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.SoftwareImageClassID, SecondSwImageMeId, requestedAttributes, ConstDefaultOmciTimeout, true) |
| 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": ""} |
| 121 | meInstance := onuDeviceEntry.PDevOmciCC.sendGetMe(context.TODO(), me.IpHostConfigDataClassID, IpHostConfigDataMeId, requestedAttributes, ConstDefaultOmciTimeout, true) |
| 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 | |
| 129 | for i := FirstSwImageMeId; i <= SecondSwImageMeId; i++ { |
| 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 { |
| 152 | logger.Error("MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": onuDeviceEntry.deviceID}) |
| 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 { |
| 157 | meClassId := me.ClassID(uint16ValidNumber) |
| 158 | logger.Debugw("MibSync FSM - fistLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber}) |
| 159 | if IsSupportedClassId(meClassId) { |
| 160 | logger.Debugw("MibSync FSM - fistLevelKey is a supported classId", log.Fields{"meClassId": meClassId}) |
| 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 { |
| 165 | meEntityId := uint16(uint16ValidNumber) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 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 { |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame^] | 169 | if thirdLevelKey == "Attributes" { |
| 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}) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [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 { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 187 | logger.Errorf("Get from kvstore operation failed for path %s", path) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 188 | } |
| 189 | if meStoredFromTemplate { |
| 190 | logger.Debug("MibSync FSM - valid MEs stored from template") |
| 191 | onuDeviceEntry.pOnuDB.LogMeDb() |
| 192 | fsmMsg = LoadMibTemplateOk |
| 193 | } else { |
| 194 | logger.Debug("MibSync FSM - no valid MEs stored from template - perform MIB-upload!") |
| 195 | fsmMsg = LoadMibTemplateFailed |
| 196 | } |
| 197 | |
| 198 | mibSyncMsg := Message{ |
| 199 | Type: TestMsg, |
| 200 | Data: TestMessage{ |
| 201 | TestMessageVal: fsmMsg, |
| 202 | }, |
| 203 | } |
| 204 | onuDeviceEntry.pMibUploadFsm.commChan <- mibSyncMsg |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | func (onuDeviceEntry *OnuDeviceEntry) enterUploadingState(e *fsm.Event) { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 208 | logger.Debugw("MibSync FSM", log.Fields{"send MibUpload in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 209 | onuDeviceEntry.PDevOmciCC.sendMibUpload(context.TODO(), ConstDefaultOmciTimeout, true) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | func (onuDeviceEntry *OnuDeviceEntry) enterInSyncState(e *fsm.Event) { |
| 213 | logger.Debugw("MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 214 | onuDeviceEntry.transferSystemEvent(MibDatabaseSync) |
| 215 | } |
| 216 | |
| 217 | func (onuDeviceEntry *OnuDeviceEntry) enterExaminingMdsState(e *fsm.Event) { |
| 218 | logger.Debugw("MibSync FSM", log.Fields{"Start GetMds processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 219 | logger.Debug("function not implemented yet") |
| 220 | } |
| 221 | |
| 222 | func (onuDeviceEntry *OnuDeviceEntry) enterResynchronizingState(e *fsm.Event) { |
| 223 | logger.Debugw("MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 224 | logger.Debug("function not implemented yet") |
| 225 | } |
| 226 | |
| 227 | func (onuDeviceEntry *OnuDeviceEntry) enterAuditingState(e *fsm.Event) { |
| 228 | logger.Debugw("MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 229 | logger.Debug("function not implemented yet") |
| 230 | } |
| 231 | |
| 232 | func (onuDeviceEntry *OnuDeviceEntry) enterOutOfSyncState(e *fsm.Event) { |
| 233 | logger.Debugw("MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 234 | logger.Debug("function not implemented yet") |
| 235 | } |
| 236 | |
| 237 | func (onuDeviceEntry *OnuDeviceEntry) ProcessMibSyncMessages( /*ctx context.Context*/ ) { |
| 238 | logger.Debugw("MibSync Msg", log.Fields{"Start routine to process OMCI-messages for device-id": onuDeviceEntry.deviceID}) |
| 239 | loop: |
| 240 | for { |
| 241 | select { |
| 242 | // case <-ctx.Done(): |
| 243 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID}) |
| 244 | // break loop |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 245 | case message, ok := <-onuDeviceEntry.pMibUploadFsm.commChan: |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 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}) |
| 251 | |
| 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}) |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | logger.Info("MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": onuDeviceEntry.deviceID}) |
| 265 | // TODO: only this action? |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 266 | onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvStop) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | func (onuDeviceEntry *OnuDeviceEntry) handleTestMsg(msg TestMessage) { |
| 270 | |
| 271 | logger.Debugw("MibSync Msg", log.Fields{"TestMessage received for device-id": onuDeviceEntry.deviceID, "msg.TestMessageVal": msg.TestMessageVal}) |
| 272 | |
| 273 | switch msg.TestMessageVal { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 274 | case LoadMibTemplateFailed: |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 275 | onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvUploadMib) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 276 | logger.Debugw("MibSync Msg", log.Fields{"state": string(onuDeviceEntry.pMibUploadFsm.pFsm.Current())}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 277 | case LoadMibTemplateOk: |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 278 | onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvSuccess) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 279 | logger.Debugw("MibSync Msg", log.Fields{"state": string(onuDeviceEntry.pMibUploadFsm.pFsm.Current())}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 280 | default: |
| 281 | logger.Warn("MibSync Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID, "msg.TestMessageVal": msg.TestMessageVal}) |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | func (onuDeviceEntry *OnuDeviceEntry) handleOmciMessage(msg OmciMessage) { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 286 | if onuDeviceEntry.mibDebugLevel == "VERBOSE" { |
| 287 | logger.Debugw("MibSync Msg", log.Fields{"OmciMessage received for device-id": onuDeviceEntry.deviceID, |
| 288 | "msgType": msg.OmciMsg.MessageType}) |
| 289 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 290 | //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ... |
| 291 | switch msg.OmciMsg.MessageType { |
| 292 | case omci.MibResetResponseType: |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 293 | if onuDeviceEntry.pMibUploadFsm.pFsm.Is(ulStResettingMib) { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 294 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse) |
| 295 | if msgLayer != nil { |
| 296 | msgObj, msgOk := msgLayer.(*omci.MibResetResponse) |
| 297 | if msgOk { |
| 298 | logger.Debugw("MibResetResponse Data", log.Fields{"data-fields": msgObj}) |
| 299 | if msgObj.Result == me.Success { |
| 300 | // trigger retrieval of VendorId and SerialNumber |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 301 | onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 302 | return |
| 303 | } else { |
| 304 | logger.Errorw("Omci MibResetResponse Error", log.Fields{"Error": msgObj.Result}) |
| 305 | } |
| 306 | } else { |
| 307 | logger.Error("Omci Msg layer could not be assigned") |
| 308 | } |
| 309 | } else { |
| 310 | logger.Error("Omci Msg layer could not be detected") |
| 311 | } |
| 312 | } else { |
| 313 | logger.Errorw("Omci MibResetResponse received", log.Fields{"in state ": onuDeviceEntry.pMibUploadFsm.pFsm.Current}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 314 | } |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 315 | logger.Info("MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": onuDeviceEntry.deviceID}) |
| 316 | onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvStop) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 317 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 318 | case omci.MibUploadResponseType: |
| 319 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse) |
| 320 | if msgLayer == nil { |
| 321 | logger.Error("Omci Msg layer could not be detected") |
| 322 | return |
| 323 | } |
| 324 | msgObj, msgOk := msgLayer.(*omci.MibUploadResponse) |
| 325 | if !msgOk { |
| 326 | logger.Error("Omci Msg layer could not be assigned") |
| 327 | return |
| 328 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 329 | logger.Debugw("MibUploadResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 330 | /* to be verified / reworked !!! */ |
| 331 | onuDeviceEntry.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands |
| 332 | if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds { |
| 333 | onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true) |
| 334 | } else { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 335 | logger.Error("Invalid number of commands received for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "uploadNoOfCmds": onuDeviceEntry.PDevOmciCC.uploadNoOfCmds}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 336 | //TODO right action? |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 337 | onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvTimeout) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 338 | } |
| 339 | case omci.MibUploadNextResponseType: |
| 340 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse) |
| 341 | if msgLayer == nil { |
| 342 | logger.Error("Omci Msg layer could not be detected") |
| 343 | return |
| 344 | } |
| 345 | msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse) |
| 346 | if !msgOk { |
| 347 | logger.Error("Omci Msg layer could not be assigned") |
| 348 | return |
| 349 | } |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 350 | if onuDeviceEntry.mibDebugLevel == "VERBOSE" { |
| 351 | logger.Debugw("MibUploadNextResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
| 352 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 353 | meClassId := msgObj.ReportedME.GetClassID() |
| 354 | meEntityId := msgObj.ReportedME.GetEntityID() |
| 355 | meAttributes := msgObj.ReportedME.GetAttributeValueMap() |
| 356 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 357 | onuDeviceEntry.pOnuDB.PutMe(meClassId, meEntityId, meAttributes) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 358 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 359 | if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds { |
| 360 | onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true) |
| 361 | } else { |
| 362 | //TODO |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 363 | onuDeviceEntry.pOnuDB.LogMeDb() |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 364 | onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvSuccess) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 365 | } |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 366 | case omci.GetResponseType: |
| 367 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse) |
| 368 | if msgLayer != nil { |
| 369 | msgObj, msgOk := msgLayer.(*omci.GetResponse) |
| 370 | if msgOk { |
| 371 | logger.Debugw("MibSync FSM - GetResponse Data", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
| 372 | if msgObj.Result == me.Success { |
| 373 | entityId := onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetEntityID() |
| 374 | if msgObj.EntityClass == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityId { |
| 375 | meAttributes := msgObj.Attributes |
| 376 | switch onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetName() { |
| 377 | case "OnuG": |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 378 | if onuDeviceEntry.mibDebugLevel == "VERBOSE" { |
| 379 | logger.Debugw("MibSync FSM - GetResponse Data for Onu-G", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
| 380 | } |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 381 | onuDeviceEntry.vendorID = fmt.Sprintf("%s", meAttributes["VendorId"]) |
| 382 | snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"]) |
| 383 | if OnugSerialNumberLen == len(snBytes) { |
| 384 | snVendorPart := fmt.Sprintf("%s", snBytes[:4]) |
| 385 | snNumberPart := hex.EncodeToString(snBytes[4:]) |
| 386 | onuDeviceEntry.serialNumber = snVendorPart + snNumberPart |
| 387 | logger.Debugw("MibSync FSM - GetResponse Data for Onu-G - VendorId/SerialNumber", log.Fields{"deviceId": onuDeviceEntry.deviceID, |
| 388 | "onuDeviceEntry.vendorID": onuDeviceEntry.vendorID, "onuDeviceEntry.serialNumber": onuDeviceEntry.serialNumber}) |
| 389 | } else { |
| 390 | logger.Errorw("MibSync FSM - SerialNumber has wrong length", log.Fields{"deviceId": onuDeviceEntry.deviceID, "length": len(snBytes)}) |
| 391 | } |
| 392 | // trigger retrieval of EquipmentId |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 393 | onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentId) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 394 | return |
| 395 | case "Onu2G": |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 396 | if onuDeviceEntry.mibDebugLevel == "VERBOSE" { |
| 397 | logger.Debugw("MibSync FSM - GetResponse Data for Onu2-G", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
| 398 | } |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 399 | onuDeviceEntry.equipmentID = fmt.Sprintf("%s", meAttributes["EquipmentId"]) |
| 400 | logger.Debugw("MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"deviceId": onuDeviceEntry.deviceID, |
| 401 | "onuDeviceEntry.equipmentID": onuDeviceEntry.equipmentID}) |
| 402 | // trigger retrieval of 1st SW-image info |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 403 | onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 404 | return |
| 405 | case "SoftwareImage": |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 406 | if onuDeviceEntry.mibDebugLevel == "VERBOSE" { |
| 407 | logger.Debugw("MibSync FSM - GetResponse Data for SoftwareImage", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
| 408 | } |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 409 | if entityId <= SecondSwImageMeId { |
| 410 | onuDeviceEntry.swImages[entityId].version = fmt.Sprintf("%s", meAttributes["Version"]) |
| 411 | onuDeviceEntry.swImages[entityId].isActive = meAttributes["IsActive"].(uint8) |
| 412 | logger.Debugw("MibSync FSM - GetResponse Data for SoftwareImage - Version/IsActive", |
| 413 | log.Fields{"deviceId": onuDeviceEntry.deviceID, "entityId": entityId, |
| 414 | "version": onuDeviceEntry.swImages[entityId].version, "isActive": onuDeviceEntry.swImages[entityId].isActive}) |
| 415 | } else { |
| 416 | //TODO: error handling |
| 417 | } |
| 418 | if FirstSwImageMeId == entityId { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 419 | onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 420 | return |
| 421 | } else if SecondSwImageMeId == entityId { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 422 | onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 423 | return |
| 424 | } |
| 425 | case "IpHostConfigData": |
| 426 | /// |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 427 | if onuDeviceEntry.mibDebugLevel == "VERBOSE" { |
| 428 | logger.Debugw("MibSync FSM - GetResponse Data for IpHostConfigData", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
| 429 | } |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 430 | macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"]) |
| 431 | if OmciMacAddressLen == len(macBytes) { |
| 432 | onuDeviceEntry.macAddress = hex.EncodeToString(macBytes[:]) |
| 433 | logger.Debugw("MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"deviceId": onuDeviceEntry.deviceID, |
| 434 | "onuDeviceEntry.macAddress": onuDeviceEntry.macAddress}) |
| 435 | } else { |
| 436 | logger.Errorw("MibSync FSM - MacAddress wrong length", log.Fields{"deviceId": onuDeviceEntry.deviceID, "length": len(macBytes)}) |
| 437 | } |
| 438 | // trigger retrieval of mib template |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 439 | onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate) |
| 440 | return |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | } else { |
| 444 | logger.Errorw("Omci GetResponse Error", log.Fields{"Error": msgObj.Result}) |
| 445 | } |
| 446 | } else { |
| 447 | logger.Error("Omci Msg layer could not be assigned for GetResponse") |
| 448 | } |
| 449 | } else { |
| 450 | logger.Error("Omci Msg layer could not be detected for GetResponse") |
| 451 | } |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 452 | logger.Info("MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": onuDeviceEntry.deviceID}) |
| 453 | onuDeviceEntry.pMibUploadFsm.pFsm.Event(ulEvStop) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 457 | func IsSupportedClassId(meClassId me.ClassID) bool { |
| 458 | for _, v := range supportedClassIds { |
| 459 | if v == meClassId { |
| 460 | return true |
| 461 | } |
| 462 | } |
| 463 | return false |
| 464 | } |
| 465 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 466 | func (onuDeviceEntry *OnuDeviceEntry) MibDbVolatileDict() error { |
| 467 | logger.Debug("MibVolatileDict- running from default Entry code") |
| 468 | return errors.New("not_implemented") |
| 469 | } |
| 470 | |
| 471 | // func (onuDeviceEntry *OnuDeviceEntry) MibTemplateTask() error { |
| 472 | // return errors.New("not_implemented") |
| 473 | // } |
| 474 | // func (onuDeviceEntry *OnuDeviceEntry) MibUploadTask() error { |
| 475 | // return errors.New("not_implemented") |
| 476 | // } |
| 477 | // func (onuDeviceEntry *OnuDeviceEntry) GetMdsTask() error { |
| 478 | // return errors.New("not_implemented") |
| 479 | // } |
| 480 | // func (onuDeviceEntry *OnuDeviceEntry) MibResyncTask() error { |
| 481 | // return errors.New("not_implemented") |
| 482 | // } |
| 483 | // func (onuDeviceEntry *OnuDeviceEntry) MibReconcileTask() error { |
| 484 | // return errors.New("not_implemented") |
| 485 | // } |