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 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 35 | //"github.com/opencord/voltha-lib-go/v4/pkg/kafka" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 36 | "github.com/opencord/omci-lib-go" |
| 37 | me "github.com/opencord/omci-lib-go/generated" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 38 | "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore" |
| 39 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
| 40 | //ic "github.com/opencord/voltha-protos/v4/go/inter_container" |
| 41 | //"github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 42 | //"github.com/opencord/voltha-protos/v4/go/voltha" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 43 | ) |
| 44 | |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 45 | type sLastTxMeParameter struct { |
| 46 | lastTxMessageType omci.MessageType |
| 47 | pLastTxMeInstance *me.ManagedEntity |
| 48 | repeatCount uint8 |
| 49 | } |
| 50 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 51 | var supportedClassIds = []me.ClassID{ |
| 52 | me.CardholderClassID, // 5 |
| 53 | me.CircuitPackClassID, // 6 |
| 54 | me.SoftwareImageClassID, // 7 |
| 55 | me.PhysicalPathTerminationPointEthernetUniClassID, // 11 |
| 56 | me.OltGClassID, // 131 |
| 57 | me.OnuPowerSheddingClassID, // 133 |
| 58 | me.IpHostConfigDataClassID, // 134 |
| 59 | me.OnuGClassID, // 256 |
| 60 | me.Onu2GClassID, // 257 |
| 61 | me.TContClassID, // 262 |
| 62 | me.AniGClassID, // 263 |
| 63 | me.UniGClassID, // 264 |
| 64 | me.PriorityQueueClassID, // 277 |
| 65 | me.TrafficSchedulerClassID, // 278 |
| 66 | me.VirtualEthernetInterfacePointClassID, // 329 |
| 67 | me.EnhancedSecurityControlClassID, // 332 |
| 68 | me.OnuDynamicPowerManagementControlClassID, // 336 |
| 69 | // 347 // definitions for ME "IPv6 host config data" are currently missing in omci-lib-go! |
| 70 | } |
| 71 | |
| 72 | var fsmMsg TestMessageType |
| 73 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 74 | func (oo *OnuDeviceEntry) enterStartingState(ctx context.Context, e *fsm.Event) { |
| 75 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 76 | oo.pOnuDB = newOnuDeviceDB(log.WithSpanFromContext(context.TODO(), ctx), oo) |
| 77 | go oo.processMibSyncMessages(ctx) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 78 | } |
| 79 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 80 | func (oo *OnuDeviceEntry) enterResettingMibState(ctx context.Context, e *fsm.Event) { |
| 81 | logger.Debugw(ctx, "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] | 82 | |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 83 | if (!oo.isNewOnu() && !oo.baseDeviceHandler.isReconciling()) || //use case: re-auditing failed |
| 84 | oo.baseDeviceHandler.isSkipOnuConfigReconciling() { //use case: reconciling without omci-config failed |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 85 | oo.baseDeviceHandler.prepareReconcilingWithActiveAdapter(ctx) |
| 86 | oo.devState = DeviceStatusInit |
| 87 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 88 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"send mibReset in State": e.FSM.Current(), "device-id": oo.deviceID}) |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 89 | _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 90 | //TODO: needs to handle timeouts |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 91 | //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure |
| 92 | // that the lastTxMessageType is correctly set to avoid misinterpreting other responses |
| 93 | oo.lastTxParamStruct.lastTxMessageType = omci.MibResetRequestType |
| 94 | oo.lastTxParamStruct.repeatCount = 0 |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 95 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 96 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 97 | func (oo *OnuDeviceEntry) enterGettingVendorAndSerialState(ctx context.Context, e *fsm.Event) { |
| 98 | logger.Debugw(ctx, "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] | 99 | requestedAttributes := me.AttributeValueMap{"VendorId": "", "SerialNumber": 0} |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 100 | meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.OnuGClassID, onugMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 101 | //accept also nil as (error) return value for writing to LastTx |
| 102 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 103 | oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType |
| 104 | oo.lastTxParamStruct.pLastTxMeInstance = meInstance |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 105 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 106 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 107 | func (oo *OnuDeviceEntry) enterGettingEquipmentIDState(ctx context.Context, e *fsm.Event) { |
| 108 | logger.Debugw(ctx, "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] | 109 | requestedAttributes := me.AttributeValueMap{"EquipmentId": ""} |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 110 | meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.Onu2GClassID, onu2gMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 111 | //accept also nil as (error) return value for writing to LastTx |
| 112 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 113 | oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType |
| 114 | oo.lastTxParamStruct.pLastTxMeInstance = meInstance |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 115 | } |
| 116 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 117 | func (oo *OnuDeviceEntry) enterGettingFirstSwVersionState(ctx context.Context, e *fsm.Event) { |
| 118 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting IsActive and Version of first SW-image in State": e.FSM.Current(), "device-id": oo.deviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 119 | requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""} |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 120 | meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, firstSwImageMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 121 | //accept also nil as (error) return value for writing to LastTx |
| 122 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 123 | oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType |
| 124 | oo.lastTxParamStruct.pLastTxMeInstance = meInstance |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 125 | } |
| 126 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 127 | func (oo *OnuDeviceEntry) enterGettingSecondSwVersionState(ctx context.Context, e *fsm.Event) { |
| 128 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting IsActive and Version of second SW-image in State": e.FSM.Current(), "device-id": oo.deviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 129 | requestedAttributes := me.AttributeValueMap{"IsCommitted": 0, "IsActive": 0, "Version": ""} |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 130 | meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, secondSwImageMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 131 | //accept also nil as (error) return value for writing to LastTx |
| 132 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 133 | oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType |
| 134 | oo.lastTxParamStruct.pLastTxMeInstance = meInstance |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 135 | } |
| 136 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 137 | func (oo *OnuDeviceEntry) enterGettingMacAddressState(ctx context.Context, e *fsm.Event) { |
| 138 | logger.Debugw(ctx, "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] | 139 | requestedAttributes := me.AttributeValueMap{"MacAddress": ""} |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 140 | meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.IpHostConfigDataClassID, ipHostConfigDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 141 | //accept also nil as (error) return value for writing to LastTx |
| 142 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 143 | oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType |
| 144 | oo.lastTxParamStruct.pLastTxMeInstance = meInstance |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 147 | func (oo *OnuDeviceEntry) enterGettingMibTemplateState(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 148 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 149 | if oo.onuSwImageIndications.activeEntityEntry.valid { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 150 | oo.sOnuPersistentData.PersActiveSwVersion = oo.onuSwImageIndications.activeEntityEntry.version |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 151 | } else { |
| 152 | logger.Errorw(ctx, "get-mib-template: no active SW version found, working with empty SW version, which might be untrustworthy", |
| 153 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 154 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 155 | if oo.getMibFromTemplate(ctx) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 156 | logger.Debug(ctx, "MibSync FSM - valid MEs stored from template") |
| 157 | oo.pOnuDB.logMeDb(ctx) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 158 | fsmMsg = LoadMibTemplateOk |
| 159 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 160 | logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!") |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 161 | fsmMsg = LoadMibTemplateFailed |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 162 | |
Holger Hildebrandt | 441a017 | 2020-12-10 13:57:08 +0000 | [diff] [blame] | 163 | oo.pOpenOnuAc.lockMibTemplateGenerated.Lock() |
| 164 | if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist { |
| 165 | if mibTemplateIsGenerated { |
| 166 | logger.Debugw(ctx, |
| 167 | "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map", |
| 168 | log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
| 169 | oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false |
| 170 | } |
| 171 | } |
| 172 | oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock() |
| 173 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 174 | mibSyncMsg := Message{ |
| 175 | Type: TestMsg, |
| 176 | Data: TestMessage{ |
| 177 | TestMessageVal: fsmMsg, |
| 178 | }, |
| 179 | } |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 180 | oo.pMibUploadFsm.commChan <- mibSyncMsg |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 181 | } |
| 182 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 183 | func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) { |
| 184 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"send MibUpload in State": e.FSM.Current(), "device-id": oo.deviceID}) |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 185 | _ = oo.PDevOmciCC.sendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true) |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 186 | //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure |
| 187 | // that the lastTxMessageType is correctly set to avoid misinterpreting other responses |
| 188 | oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadRequestType |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 191 | func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 192 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 193 | oo.transferSystemEvent(ctx, MibDatabaseSync) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 194 | go func() { |
| 195 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess) |
| 196 | }() |
| 197 | } |
| 198 | |
| 199 | func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) { |
| 200 | oo.sOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix()) |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 201 | if oo.mibAuditInterval > 0 { |
| 202 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"trigger next Audit in State": e.FSM.Current(), "oo.mibAuditInterval": oo.mibAuditInterval, "device-id": oo.deviceID}) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 203 | go func() { |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 204 | time.Sleep(oo.mibAuditInterval) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 205 | if err := oo.pMibUploadFsm.pFsm.Event(ulEvAuditMib); err != nil { |
| 206 | logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err}) |
| 207 | } |
| 208 | }() |
| 209 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 210 | } |
| 211 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 212 | func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) { |
| 213 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start GetMds processing in State": e.FSM.Current(), "device-id": oo.deviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 214 | oo.requestMdsValue(ctx) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 215 | } |
| 216 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 217 | func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) { |
| 218 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 219 | logger.Debug(ctx, "function not implemented yet") |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 220 | // TODOs: |
| 221 | // VOL-3805 - Provide exclusive OMCI channel for one FSM |
| 222 | // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go |
| 223 | // VOL-3792 - Support periodical audit via mib resync |
| 224 | // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 227 | func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) { |
| 228 | logger.Debugw(ctx, "MibSync FSM", |
| 229 | log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 230 | |
| 231 | if oo.getMibFromTemplate(ctx) { |
| 232 | oo.baseDeviceHandler.startReconciling(ctx, true) |
| 233 | oo.baseDeviceHandler.addAllUniPorts(ctx) |
| 234 | oo.baseDeviceHandler.setDeviceReason(drInitialMibDownloaded) |
| 235 | oo.baseDeviceHandler.ReadyForSpecificOmciConfig = true |
| 236 | // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm |
| 237 | |
| 238 | oo.baseDeviceHandler.reconcileDeviceTechProf(ctx) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 239 | |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 240 | // start go routine with select() on reconciling flow channel before |
| 241 | // starting flow reconciling process to prevent loss of any signal |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 242 | go func() { |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 243 | // In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until |
| 244 | // we get a signal that the processing of the last step to rebuild the adapter internal |
| 245 | // flow data is finished. |
| 246 | select { |
| 247 | case success := <-oo.baseDeviceHandler.chReconcilingFlowsFinished: |
| 248 | if success { |
| 249 | logger.Debugw(ctx, "reconciling flows has been finished in time", |
| 250 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 251 | oo.baseDeviceHandler.stopReconciling(ctx) |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 252 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess) |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 253 | |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 254 | } else { |
| 255 | logger.Debugw(ctx, "wait for reconciling flows aborted", |
| 256 | log.Fields{"device-id": oo.deviceID}) |
| 257 | oo.baseDeviceHandler.setReconcilingFlows(false) |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 258 | } |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 259 | case <-time.After(500 * time.Millisecond): |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 260 | logger.Errorw(ctx, "timeout waiting for reconciling flows to be finished!", |
| 261 | log.Fields{"device-id": oo.deviceID}) |
| 262 | oo.baseDeviceHandler.setReconcilingFlows(false) |
| 263 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch) |
| 264 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 265 | }() |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 266 | oo.baseDeviceHandler.reconcileDeviceFlowConfig(ctx) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 267 | |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 268 | if oo.sOnuPersistentData.PersUniDisableDone { |
| 269 | oo.baseDeviceHandler.disableUniPortStateUpdate(ctx) |
| 270 | oo.baseDeviceHandler.setDeviceReason(drOmciAdminLock) |
| 271 | } else { |
| 272 | oo.baseDeviceHandler.enableUniPortStateUpdate(ctx) |
| 273 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 274 | } else { |
| 275 | logger.Debugw(ctx, "MibSync FSM", |
| 276 | log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID}) |
| 277 | go func() { |
| 278 | //switch to reconciling with OMCI config |
| 279 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch) |
| 280 | }() |
| 281 | } |
| 282 | } |
| 283 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 284 | func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 285 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibAudit processing in State": e.FSM.Current(), "device-id": oo.deviceID}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 286 | if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 287 | oo.requestMdsValue(ctx) |
| 288 | } else { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 289 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Configuration is ongoing or missing - skip auditing!": e.FSM.Current(), "device-id": oo.deviceID}) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 290 | go func() { |
| 291 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess) |
| 292 | }() |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) { |
| 297 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start retest MdsValue processing in State": e.FSM.Current(), "device-id": oo.deviceID}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 298 | if oo.baseDeviceHandler.checkAuditStartCondition(ctx, cUploadFsm) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 299 | oo.requestMdsValue(ctx) |
| 300 | } else { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 301 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Configuration is ongoing or missing - skip re-auditing!": e.FSM.Current(), "device-id": oo.deviceID}) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 302 | go func() { |
| 303 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess) |
| 304 | }() |
| 305 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 306 | } |
| 307 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 308 | func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) { |
| 309 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 310 | logger.Debug(ctx, "function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 311 | } |
| 312 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 313 | func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) { |
| 314 | logger.Debugw(ctx, "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] | 315 | loop: |
| 316 | for { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 317 | // case <-ctx.Done(): |
| 318 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID}) |
| 319 | // break loop |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 320 | message, ok := <-oo.pMibUploadFsm.commChan |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 321 | if !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 322 | logger.Info(ctx, "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] | 323 | break loop |
| 324 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 325 | logger.Debugw(ctx, "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] | 326 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 327 | switch message.Type { |
| 328 | case TestMsg: |
| 329 | msg, _ := message.Data.(TestMessage) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 330 | oo.handleTestMsg(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 331 | case OMCI: |
| 332 | msg, _ := message.Data.(OmciMessage) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 333 | oo.handleOmciMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 334 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 335 | logger.Warn(ctx, "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] | 336 | } |
| 337 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 338 | logger.Info(ctx, "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] | 339 | // TODO: only this action? |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 340 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 341 | } |
| 342 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 343 | func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg TestMessage) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 344 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 345 | logger.Debugw(ctx, "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] | 346 | |
| 347 | switch msg.TestMessageVal { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 348 | case LoadMibTemplateFailed: |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 349 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvUploadMib) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 350 | logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 351 | case LoadMibTemplateOk: |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 352 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 353 | logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.pMibUploadFsm.pFsm.Current())}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 354 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 355 | logger.Warn(ctx, "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] | 356 | } |
| 357 | } |
| 358 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 359 | func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg OmciMessage) { |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 360 | if oo.pMibUploadFsm.pFsm.Is(ulStResettingMib) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 361 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse) |
| 362 | if msgLayer != nil { |
| 363 | msgObj, msgOk := msgLayer.(*omci.MibResetResponse) |
| 364 | if msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 365 | logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 366 | if msgObj.Result == me.Success { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 367 | oo.sOnuPersistentData.PersMibDataSyncAdpt = 0 |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 368 | // trigger retrieval of VendorId and SerialNumber |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 369 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetVendorAndSerial) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 370 | return |
| 371 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 372 | logger.Errorw(ctx, "Omci MibResetResponse Error", log.Fields{"device-id": oo.deviceID, "Error": msgObj.Result}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 373 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 374 | logger.Errorw(ctx, "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] | 375 | } |
| 376 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 377 | logger.Errorw(ctx, "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] | 378 | } |
| 379 | } else { |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 380 | //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset |
| 381 | // with Sequence number 0x8000 as last request before - so it may still respond to that |
| 382 | // then we may force the ONU to react on the MdsGetRequest with a new message that uses an increased Sequence number |
| 383 | if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 { |
| 384 | logger.Debugw(ctx, "MibSync FSM - repeat MdsGetRequest (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID}) |
| 385 | requestedAttributes := me.AttributeValueMap{"MibDataSync": ""} |
| 386 | _ = oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), |
| 387 | me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan) |
| 388 | //TODO: needs extra handling of timeouts |
| 389 | oo.lastTxParamStruct.repeatCount = 1 |
| 390 | return |
| 391 | } |
| 392 | logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID}) |
| 393 | //perhaps some still lingering message from some prior activity, let's wait for the real response |
| 394 | return |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 395 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 396 | logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID}) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 397 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 398 | } |
| 399 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 400 | func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg OmciMessage) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 401 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse) |
| 402 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 403 | logger.Errorw(ctx, "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] | 404 | return |
| 405 | } |
| 406 | msgObj, msgOk := msgLayer.(*omci.MibUploadResponse) |
| 407 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 408 | logger.Errorw(ctx, "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] | 409 | return |
| 410 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 411 | logger.Debugw(ctx, "MibUploadResponse Data for:", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 412 | /* to be verified / reworked !!! */ |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 413 | oo.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands |
| 414 | if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds { |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 415 | _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true) |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 416 | //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure |
| 417 | // that the lastTxMessageType is correctly set to avoid misinterpreting other responses |
| 418 | oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 419 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 420 | logger.Errorw(ctx, "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] | 421 | //TODO right action? |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 422 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvTimeout) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 426 | func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg OmciMessage) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 427 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 428 | |
Holger Hildebrandt | e243934 | 2020-12-03 16:06:54 +0000 | [diff] [blame] | 429 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 430 | logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | e243934 | 2020-12-03 16:06:54 +0000 | [diff] [blame] | 431 | return |
| 432 | } |
| 433 | msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse) |
| 434 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 435 | logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | e243934 | 2020-12-03 16:06:54 +0000 | [diff] [blame] | 436 | return |
| 437 | } |
| 438 | meName := msgObj.ReportedME.GetName() |
| 439 | if meName == "UnknownItuG988ManagedEntity" || meName == "UnknownVendorSpecificManagedEntity" { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 440 | logger.Debugw(ctx, "MibUploadNextResponse Data for unknown ME received - temporary workaround is to ignore it!", |
Holger Hildebrandt | e243934 | 2020-12-03 16:06:54 +0000 | [diff] [blame] | 441 | log.Fields{"device-id": oo.deviceID, "data-fields": msgObj, "meName": meName}) |
| 442 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 443 | logger.Debugw(ctx, "MibUploadNextResponse Data for:", |
Holger Hildebrandt | e243934 | 2020-12-03 16:06:54 +0000 | [diff] [blame] | 444 | log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj}) |
Holger Hildebrandt | 8998b87 | 2020-10-05 13:48:39 +0000 | [diff] [blame] | 445 | meClassID := msgObj.ReportedME.GetClassID() |
| 446 | meEntityID := msgObj.ReportedME.GetEntityID() |
| 447 | meAttributes := msgObj.ReportedME.GetAttributeValueMap() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 448 | oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, meAttributes) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 449 | } |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 450 | if oo.PDevOmciCC.uploadSequNo < oo.PDevOmciCC.uploadNoOfCmds { |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 451 | _ = oo.PDevOmciCC.sendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true) |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 452 | //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure |
| 453 | // that the lastTxMessageType is correctly set to avoid misinterpreting other responses |
| 454 | oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 455 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 456 | oo.pOnuDB.logMeDb(ctx) |
| 457 | err := oo.createAndPersistMibTemplate(ctx) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 458 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 459 | logger.Errorw(ctx, "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] | 460 | } |
| 461 | |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 462 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 466 | func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg OmciMessage) error { |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 467 | var err error = nil |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 468 | |
| 469 | if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType || |
| 470 | oo.lastTxParamStruct.pLastTxMeInstance == nil { |
| 471 | //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest |
| 472 | // with Sequence number 0x8000 as last request before - so it may still respond to that |
| 473 | // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number |
| 474 | if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 { |
| 475 | logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID}) |
| 476 | _ = oo.PDevOmciCC.sendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.pOpenOnuAc.omciTimeout, true) |
| 477 | //TODO: needs extra handling of timeouts |
| 478 | oo.lastTxParamStruct.repeatCount = 1 |
| 479 | return nil |
| 480 | } |
| 481 | logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID}) |
| 482 | //perhaps some still lingering message from some prior activity, let's wait for the real response |
| 483 | return nil |
| 484 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 485 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 486 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 487 | logger.Errorw(ctx, "omci Msg layer could not be detected for GetResponse - handling of MibSyncChan stopped", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 488 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop) |
| 489 | 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] | 490 | } |
| 491 | msgObj, msgOk := msgLayer.(*omci.GetResponse) |
| 492 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 493 | logger.Errorw(ctx, "omci Msg layer could not be assigned for GetResponse - handling of MibSyncChan stopped", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 494 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop) |
| 495 | 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] | 496 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 497 | logger.Debugw(ctx, "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] | 498 | if msgObj.Result == me.Success { |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 499 | entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID() |
| 500 | if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID { |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 501 | meAttributes := msgObj.Attributes |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 502 | meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 503 | logger.Debugf(ctx, "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] | 504 | switch meInstance { |
| 505 | case "OnuG": |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 506 | oo.sOnuPersistentData.PersVendorID = trimStringFromInterface(meAttributes["VendorId"]) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 507 | snBytes, _ := me.InterfaceToOctets(meAttributes["SerialNumber"]) |
| 508 | if onugSerialNumberLen == len(snBytes) { |
| 509 | snVendorPart := fmt.Sprintf("%s", snBytes[:4]) |
| 510 | snNumberPart := hex.EncodeToString(snBytes[4:]) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 511 | oo.sOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 512 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-G - VendorId/SerialNumber", log.Fields{"device-id": oo.deviceID, |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 513 | "onuDeviceEntry.vendorID": oo.sOnuPersistentData.PersVendorID, "onuDeviceEntry.serialNumber": oo.sOnuPersistentData.PersSerialNumber}) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 514 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 515 | logger.Infow(ctx, "MibSync FSM - SerialNumber has wrong length - fill serialNumber with zeros", log.Fields{"device-id": oo.deviceID, "length": len(snBytes)}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 516 | oo.sOnuPersistentData.PersSerialNumber = cEmptySerialNumberString |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 517 | } |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 518 | // trigger retrieval of EquipmentId |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 519 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetEquipmentID) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 520 | return nil |
| 521 | case "Onu2G": |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 522 | oo.sOnuPersistentData.PersEquipmentID = trimStringFromInterface(meAttributes["EquipmentId"]) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 523 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID, |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 524 | "onuDeviceEntry.equipmentID": oo.sOnuPersistentData.PersEquipmentID}) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 525 | // trigger retrieval of 1st SW-image info |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 526 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetFirstSwVersion) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 527 | return nil |
| 528 | case "SoftwareImage": |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 529 | if entityID > secondSwImageMeID { |
| 530 | logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId", |
| 531 | log.Fields{"device-id": oo.deviceID, "entity-ID": entityID}) |
| 532 | return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x", |
| 533 | oo.deviceID, entityID) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 534 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 535 | // need to use function for go lint complexity |
| 536 | oo.handleSwImageIndications(ctx, entityID, meAttributes) |
| 537 | return nil |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 538 | case "IpHostConfigData": |
| 539 | macBytes, _ := me.InterfaceToOctets(meAttributes["MacAddress"]) |
| 540 | if omciMacAddressLen == len(macBytes) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 541 | oo.sOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:]) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 542 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID, |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 543 | "macAddress": oo.sOnuPersistentData.PersMacAddress}) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 544 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 545 | logger.Infow(ctx, "MibSync FSM - MacAddress wrong length - fill macAddress with zeros", log.Fields{"device-id": oo.deviceID, "length": len(macBytes)}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 546 | oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 547 | } |
| 548 | // trigger retrieval of mib template |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 549 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 550 | return nil |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 551 | case "OnuData": |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 552 | oo.checkMdsValue(ctx, meAttributes["MibDataSync"].(uint8)) |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 553 | return nil |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 554 | } |
Matteo Scandolo | 20ca10c | 2021-01-21 14:35:45 -0800 | [diff] [blame] | 555 | } else { |
| 556 | logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 557 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 558 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 559 | if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil { |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 560 | return nil |
| 561 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 562 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 563 | logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID}) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 564 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvStop) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 565 | return err |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 566 | } |
| 567 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 568 | func (oo *OnuDeviceEntry) handleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) { |
| 569 | imageIsCommitted := meAttributes["IsCommitted"].(uint8) |
| 570 | imageIsActive := meAttributes["IsActive"].(uint8) |
| 571 | imageVersion := trimStringFromInterface(meAttributes["Version"]) |
| 572 | logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage", |
| 573 | log.Fields{"device-id": oo.deviceID, "entityID": entityID, |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 574 | "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.sOnuPersistentData.PersSerialNumber}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 575 | if firstSwImageMeID == entityID { |
| 576 | //always accept the state of the first image (2nd image info should not yet be available) |
| 577 | if imageIsActive == swIsActive { |
| 578 | oo.onuSwImageIndications.activeEntityEntry.entityID = entityID |
| 579 | oo.onuSwImageIndications.activeEntityEntry.valid = true |
| 580 | oo.onuSwImageIndications.activeEntityEntry.version = imageVersion |
| 581 | oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 582 | //as the SW version indication may stem from some ONU Down/up event |
| 583 | //the complementary image state is to be invalidated |
| 584 | // (state of the second image is always expected afterwards or just invalid) |
| 585 | oo.onuSwImageIndications.inactiveEntityEntry.valid = false |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 586 | } else { |
| 587 | oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID |
| 588 | oo.onuSwImageIndications.inactiveEntityEntry.valid = true |
| 589 | oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion |
| 590 | oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 591 | //as the SW version indication may stem form some ONU Down/up event |
| 592 | //the complementary image state is to be invalidated |
| 593 | // (state of the second image is always expected afterwards or just invalid) |
| 594 | oo.onuSwImageIndications.activeEntityEntry.valid = false |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 595 | } |
| 596 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetSecondSwVersion) |
| 597 | return |
| 598 | } else if secondSwImageMeID == entityID { |
| 599 | //2nd image info might conflict with first image info, in which case we priorize first image info! |
| 600 | if imageIsActive == swIsActive { //2nd image reported to be active |
| 601 | if oo.onuSwImageIndications.activeEntityEntry.valid { |
| 602 | //conflict exists - state of first image is left active |
| 603 | logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive", |
| 604 | log.Fields{"device-id": oo.deviceID}) |
| 605 | oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID |
| 606 | oo.onuSwImageIndications.inactiveEntityEntry.valid = true ////to indicate that at least something has been reported |
| 607 | oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion |
| 608 | oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted |
| 609 | } else { //first image inactive, this one active |
| 610 | oo.onuSwImageIndications.activeEntityEntry.entityID = entityID |
| 611 | oo.onuSwImageIndications.activeEntityEntry.valid = true |
| 612 | oo.onuSwImageIndications.activeEntityEntry.version = imageVersion |
| 613 | oo.onuSwImageIndications.activeEntityEntry.isCommitted = imageIsCommitted |
| 614 | } |
| 615 | } else { //2nd image reported to be inactive |
| 616 | if oo.onuSwImageIndications.inactiveEntityEntry.valid { |
| 617 | //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active |
| 618 | logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active", |
| 619 | log.Fields{"device-id": oo.deviceID}) |
| 620 | oo.onuSwImageIndications.activeEntityEntry.entityID = firstSwImageMeID |
| 621 | oo.onuSwImageIndications.activeEntityEntry.valid = true //to indicate that at least something has been reported |
| 622 | //copy active commit/version from the previously stored inactive position |
| 623 | oo.onuSwImageIndications.activeEntityEntry.version = oo.onuSwImageIndications.inactiveEntityEntry.version |
| 624 | oo.onuSwImageIndications.activeEntityEntry.isCommitted = oo.onuSwImageIndications.inactiveEntityEntry.isCommitted |
| 625 | } |
| 626 | //in any case we indicate (and possibly overwrite) the second image indications as inactive |
| 627 | oo.onuSwImageIndications.inactiveEntityEntry.entityID = entityID |
| 628 | oo.onuSwImageIndications.inactiveEntityEntry.valid = true |
| 629 | oo.onuSwImageIndications.inactiveEntityEntry.version = imageVersion |
| 630 | oo.onuSwImageIndications.inactiveEntityEntry.isCommitted = imageIsCommitted |
| 631 | } |
| 632 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMacAddress) |
| 633 | return |
| 634 | } |
| 635 | } |
| 636 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 637 | func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg OmciMessage) { |
| 638 | logger.Debugw(ctx, "MibSync Msg", log.Fields{"OmciMessage received for device-id": oo.deviceID, |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 639 | "msgType": msg.OmciMsg.MessageType, "msg": msg}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 640 | //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ... |
| 641 | switch msg.OmciMsg.MessageType { |
| 642 | case omci.MibResetResponseType: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 643 | oo.handleOmciMibResetResponseMessage(ctx, msg) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 644 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 645 | case omci.MibUploadResponseType: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 646 | oo.handleOmciMibUploadResponseMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 647 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 648 | case omci.MibUploadNextResponseType: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 649 | oo.handleOmciMibUploadNextResponseMessage(ctx, msg) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 650 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 651 | case omci.GetResponseType: |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 652 | //TODO: error handling |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 653 | _ = oo.handleOmciGetResponseMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 654 | |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 655 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 656 | logger.Warnw(ctx, "Unknown Message Type", log.Fields{"msgType": msg.OmciMsg.MessageType}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 657 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 661 | func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error { |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 662 | var err error = nil |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 663 | logger.Debugf(ctx, "MibSync FSM - erroneous result in GetResponse Data: %s", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.Result) |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 664 | // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME |
| 665 | if msgObj.Result == me.UnknownInstance || msgObj.Result == me.UnknownEntity || msgObj.Result == me.ProcessingError || msgObj.Result == me.NotSupported { |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 666 | entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID() |
| 667 | if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID { |
| 668 | meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName() |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 669 | switch meInstance { |
| 670 | case "IpHostConfigData": |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 671 | logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros", |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 672 | log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 673 | oo.sOnuPersistentData.PersMacAddress = cEmptyMacAddrString |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 674 | // trigger retrieval of mib template |
| 675 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvGetMibTemplate) |
| 676 | return nil |
| 677 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 678 | logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance) |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 679 | err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID) |
| 680 | } |
| 681 | } |
| 682 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 683 | logger.Errorf(ctx, "MibSync FSM - erroneous result in GetResponse Data: %s", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.Result) |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 684 | err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID) |
| 685 | } |
| 686 | return err |
| 687 | } |
| 688 | |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 689 | func (oo *OnuDeviceEntry) isNewOnu() bool { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 690 | return oo.sOnuPersistentData.PersMibLastDbSync == 0 |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 691 | } |
| 692 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 693 | func isSupportedClassID(meClassID me.ClassID) bool { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 694 | for _, v := range supportedClassIds { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 695 | if v == meClassID { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 696 | return true |
| 697 | } |
| 698 | } |
| 699 | return false |
| 700 | } |
| 701 | |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 702 | func trimStringFromInterface(input interface{}) string { |
| 703 | ifBytes, _ := me.InterfaceToOctets(input) |
| 704 | return fmt.Sprintf("%s", bytes.Trim(ifBytes, "\x00")) |
| 705 | } |
| 706 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 707 | func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error { |
| 708 | logger.Debug(ctx, "MibVolatileDict- running from default Entry code") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 709 | return errors.New("not_implemented") |
| 710 | } |
| 711 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 712 | // 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] | 713 | // 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] | 714 | // and then storing the template into etcd "service/voltha/omci_mibs/go_templates/verdor_id/equipment_id/software_version" path. |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 715 | func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error { |
| 716 | logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath, |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 717 | "device-id": oo.deviceID}) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 718 | |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 719 | oo.pOpenOnuAc.lockMibTemplateGenerated.Lock() |
| 720 | if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath]; exist { |
| 721 | if mibTemplateIsGenerated { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 722 | logger.Debugw(ctx, "MibSync - MibTemplate - another thread has already started to generate it - skip", |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 723 | log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
| 724 | oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock() |
| 725 | return nil |
| 726 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 727 | logger.Debugw(ctx, "MibSync - MibTemplate - previous generation attempt seems to be failed - try again", |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 728 | log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
| 729 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 730 | logger.Debugw(ctx, "MibSync - MibTemplate - first ONU-instance of this kind - start generation", |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 731 | log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
| 732 | } |
| 733 | oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = true |
| 734 | oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock() |
| 735 | |
| 736 | currentTime := time.Now() |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 737 | templateMap := make(map[string]interface{}) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 738 | templateMap["TemplateName"] = oo.mibTemplatePath |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 739 | templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000") |
| 740 | |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 741 | firstLevelMap := oo.pOnuDB.meDb |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 742 | for firstLevelKey, firstLevelValue := range firstLevelMap { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 743 | logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 744 | classID := strconv.Itoa(int(firstLevelKey)) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 745 | |
| 746 | secondLevelMap := make(map[string]interface{}) |
| 747 | for secondLevelKey, secondLevelValue := range firstLevelValue { |
| 748 | thirdLevelMap := make(map[string]interface{}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 749 | entityID := strconv.Itoa(int(secondLevelKey)) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 750 | thirdLevelMap["Attributes"] = secondLevelValue |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 751 | thirdLevelMap["InstanceId"] = entityID |
| 752 | secondLevelMap[entityID] = thirdLevelMap |
| 753 | if classID == "6" || classID == "256" { |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 754 | forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap)) |
| 755 | delete(forthLevelMap, "SerialNumber") |
| 756 | forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%" |
| 757 | |
| 758 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 759 | if classID == "134" { |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 760 | forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap)) |
| 761 | delete(forthLevelMap, "MacAddress") |
| 762 | forthLevelMap["MacAddress"] = "%MAC_ADDRESS%" |
| 763 | } |
| 764 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 765 | secondLevelMap["ClassId"] = classID |
| 766 | templateMap[classID] = secondLevelMap |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 767 | } |
| 768 | mibTemplate, err := json.Marshal(&templateMap) |
| 769 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 770 | logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID}) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 771 | oo.pOpenOnuAc.lockMibTemplateGenerated.Lock() |
| 772 | oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false |
| 773 | oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock() |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 774 | return err |
| 775 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 776 | err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate)) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 777 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 778 | logger.Errorw(ctx, "MibSync - MibTemplate - Failed to store template in etcd", log.Fields{"error": err, "device-id": oo.deviceID}) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 779 | oo.pOpenOnuAc.lockMibTemplateGenerated.Lock() |
| 780 | oo.pOpenOnuAc.mibTemplatesGenerated[oo.mibTemplatePath] = false |
| 781 | oo.pOpenOnuAc.lockMibTemplateGenerated.Unlock() |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 782 | return err |
| 783 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 784 | logger.Debugw(ctx, "MibSync - MibTemplate - Stored the template to etcd", log.Fields{"device-id": oo.deviceID}) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 785 | return nil |
| 786 | } |
| 787 | |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 788 | func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) { |
| 789 | logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID}) |
| 790 | requestedAttributes := me.AttributeValueMap{"MibDataSync": ""} |
| 791 | meInstance := oo.PDevOmciCC.sendGetMe(log.WithSpanFromContext(context.TODO(), ctx), |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 792 | me.OnuDataClassID, onuDataMeID, requestedAttributes, oo.pOpenOnuAc.omciTimeout, true, oo.pMibUploadFsm.commChan) |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 793 | //accept also nil as (error) return value for writing to LastTx |
| 794 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 795 | oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType |
| 796 | oo.lastTxParamStruct.pLastTxMeInstance = meInstance |
| 797 | oo.lastTxParamStruct.repeatCount = 0 |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 798 | } |
| 799 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 800 | func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) { |
| 801 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID, |
| 802 | "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.sOnuPersistentData.PersMibDataSyncAdpt}) |
| 803 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 804 | mdsValuesAreEqual := oo.sOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 805 | if oo.pMibUploadFsm.pFsm.Is(ulStAuditing) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 806 | if mdsValuesAreEqual { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 807 | logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID}) |
| 808 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess) |
| 809 | } else { |
| 810 | logger.Warnw(ctx, "MibSync FSM - mib audit - MDS check failed for the first time!", log.Fields{"device-id": oo.deviceID}) |
| 811 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch) |
| 812 | } |
| 813 | } else if oo.pMibUploadFsm.pFsm.Is(ulStReAuditing) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 814 | if mdsValuesAreEqual { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 815 | logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID}) |
| 816 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess) |
| 817 | } else { |
| 818 | logger.Errorw(ctx, "MibSync FSM - mib audit - MDS check failed for the second time!", log.Fields{"device-id": oo.deviceID}) |
| 819 | //TODO: send new event notification "MDS counter mismatch" to the core |
| 820 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch) |
| 821 | } |
| 822 | } else if oo.pMibUploadFsm.pFsm.Is(ulStExaminingMds) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 823 | if mdsValuesAreEqual && mibDataSyncOnu != 0 { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 824 | logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID}) |
| 825 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvSuccess) |
| 826 | } else { |
| 827 | logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID}) |
| 828 | _ = oo.pMibUploadFsm.pFsm.Event(ulEvMismatch) |
| 829 | } |
| 830 | } else { |
| 831 | logger.Warnw(ctx, "wrong state for MDS evaluation!", log.Fields{"state": oo.pMibUploadFsm.pFsm.Current(), "device-id": oo.deviceID}) |
| 832 | } |
| 833 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 834 | |
| 835 | //GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity |
| 836 | func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) { |
| 837 | if oo.onuSwImageIndications.activeEntityEntry.valid { |
| 838 | return oo.onuSwImageIndications.activeEntityEntry.entityID, nil |
| 839 | } |
| 840 | return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID) |
| 841 | } |
| 842 | |
| 843 | //GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity |
| 844 | func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) { |
| 845 | if oo.onuSwImageIndications.inactiveEntityEntry.valid { |
| 846 | return oo.onuSwImageIndications.inactiveEntityEntry.entityID, nil |
| 847 | } |
| 848 | return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID) |
| 849 | } |
| 850 | |
| 851 | //IsImageToBeCommitted returns true if the active image is still uncommitted |
| 852 | func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool { |
| 853 | if oo.onuSwImageIndications.activeEntityEntry.valid { |
| 854 | if oo.onuSwImageIndications.activeEntityEntry.entityID == aImageID { |
| 855 | if oo.onuSwImageIndications.activeEntityEntry.isCommitted == swIsUncommitted { |
| 856 | return true |
| 857 | } |
| 858 | } |
| 859 | } |
| 860 | return false //all other case are treated as 'nothing to commit |
| 861 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 862 | func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool { |
| 863 | |
| 864 | oo.mibTemplatePath = oo.buildMibTemplatePath() |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 865 | logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath), |
| 866 | "device-id": oo.deviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 867 | |
| 868 | restoredFromMibTemplate := false |
| 869 | Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath) |
| 870 | if err == nil { |
| 871 | if Value != nil { |
| 872 | logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value) |
| 873 | |
| 874 | // swap out tokens with specific data |
| 875 | mibTmpString, _ := kvstore.ToString(Value.Value) |
| 876 | mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.sOnuPersistentData.PersSerialNumber, -1) |
| 877 | mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.sOnuPersistentData.PersMacAddress, -1) |
| 878 | mibTmpBytes := []byte(mibTmpString) |
| 879 | logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes) |
| 880 | |
| 881 | var firstLevelMap map[string]interface{} |
| 882 | if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil { |
| 883 | logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID}) |
| 884 | } else { |
| 885 | for firstLevelKey, firstLevelValue := range firstLevelMap { |
| 886 | //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey}) |
| 887 | if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil { |
| 888 | meClassID := me.ClassID(uint16ValidNumber) |
| 889 | //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber}) |
| 890 | if isSupportedClassID(meClassID) { |
| 891 | //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID}) |
| 892 | secondLevelMap := firstLevelValue.(map[string]interface{}) |
| 893 | for secondLevelKey, secondLevelValue := range secondLevelMap { |
| 894 | //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey}) |
| 895 | if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil { |
| 896 | meEntityID := uint16(uint16ValidNumber) |
| 897 | //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID}) |
| 898 | thirdLevelMap := secondLevelValue.(map[string]interface{}) |
| 899 | for thirdLevelKey, thirdLevelValue := range thirdLevelMap { |
| 900 | if thirdLevelKey == "Attributes" { |
| 901 | //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey}) |
| 902 | attributesMap := thirdLevelValue.(map[string]interface{}) |
| 903 | //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap}) |
| 904 | oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap) |
| 905 | restoredFromMibTemplate = true |
| 906 | } |
| 907 | } |
| 908 | } |
| 909 | } |
| 910 | } |
| 911 | } |
| 912 | } |
| 913 | } |
| 914 | } else { |
| 915 | logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
| 916 | } |
| 917 | } else { |
| 918 | logger.Errorf(ctx, "Get from kvstore operation failed for path", |
| 919 | log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
| 920 | } |
| 921 | return restoredFromMibTemplate |
| 922 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 923 | |
| 924 | //CancelProcessing terminates potentially running reconciling processes and stops the FSM |
| 925 | func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) { |
| 926 | |
| 927 | if oo.baseDeviceHandler.isReconcilingFlows() { |
| 928 | oo.baseDeviceHandler.chReconcilingFlowsFinished <- false |
| 929 | } |
| 930 | if oo.baseDeviceHandler.isReconciling() { |
| 931 | oo.baseDeviceHandler.chReconcilingFinished <- false |
| 932 | } |
| 933 | //the MibSync FSM might be active all the ONU-active time, |
| 934 | // hence it must be stopped unconditionally |
| 935 | pMibUlFsm := oo.pMibUploadFsm.pFsm |
| 936 | if pMibUlFsm != nil { |
| 937 | _ = pMibUlFsm.Event(ulEvStop) |
| 938 | } |
| 939 | } |