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