Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1 | /* |
Joey Armstrong | e8c091f | 2023-01-17 16:56:26 -0500 | [diff] [blame] | 2 | * Copyright 2020-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 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 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 17 | //Package mib provides the utilities for managing the onu mib |
| 18 | package mib |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 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" |
Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 28 | "sync" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 29 | |
| 30 | "github.com/looplab/fsm" |
| 31 | |
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 | |
mpagenko | 7033f4e | 2021-11-19 18:04:22 +0000 | [diff] [blame] | 34 | "github.com/google/gopacket" |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 35 | "github.com/opencord/omci-lib-go/v2" |
| 36 | me "github.com/opencord/omci-lib-go/v2/generated" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 37 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 38 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 39 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
| 40 | devdb "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb" |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 41 | otst "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/omcitst" |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 42 | "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 43 | ) |
| 44 | |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 45 | type sLastTxMeParameter struct { |
| 46 | lastTxMessageType omci.MessageType |
| 47 | pLastTxMeInstance *me.ManagedEntity |
| 48 | repeatCount uint8 |
| 49 | } |
| 50 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 51 | var supportedClassIds = []me.ClassID{ |
| 52 | me.CardholderClassID, // 5 |
| 53 | me.CircuitPackClassID, // 6 |
| 54 | me.SoftwareImageClassID, // 7 |
| 55 | me.PhysicalPathTerminationPointEthernetUniClassID, // 11 |
ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 56 | me.PhysicalPathTerminationPointPotsUniClassID, // 53 |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 57 | me.OltGClassID, // 131 |
| 58 | me.OnuPowerSheddingClassID, // 133 |
| 59 | me.IpHostConfigDataClassID, // 134 |
| 60 | me.OnuGClassID, // 256 |
| 61 | me.Onu2GClassID, // 257 |
| 62 | me.TContClassID, // 262 |
| 63 | me.AniGClassID, // 263 |
| 64 | me.UniGClassID, // 264 |
| 65 | me.PriorityQueueClassID, // 277 |
| 66 | me.TrafficSchedulerClassID, // 278 |
| 67 | me.VirtualEthernetInterfacePointClassID, // 329 |
| 68 | me.EnhancedSecurityControlClassID, // 332 |
| 69 | me.OnuDynamicPowerManagementControlClassID, // 336 |
| 70 | // 347 // definitions for ME "IPv6 host config data" are currently missing in omci-lib-go! |
| 71 | } |
| 72 | |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 73 | var omccVersionSupportsExtendedOmciFormat = map[uint8]bool{ |
| 74 | 0x80: false, |
| 75 | 0x81: false, |
| 76 | 0x82: false, |
| 77 | 0x83: false, |
| 78 | 0x84: false, |
| 79 | 0x85: false, |
| 80 | 0x86: false, |
| 81 | 0xA0: false, |
| 82 | 0xA1: false, |
| 83 | 0xA2: false, |
| 84 | 0xA3: false, |
| 85 | 0x96: true, |
| 86 | 0xB0: true, |
| 87 | 0xB1: true, |
| 88 | 0xB2: true, |
| 89 | 0xB3: true, |
| 90 | 0xB4: true, |
| 91 | } |
| 92 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 93 | var fsmMsg cmn.TestMessageType |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 94 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 95 | func (oo *OnuDeviceEntry) enterStartingState(ctx context.Context, e *fsm.Event) { |
| 96 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 97 | oo.pOnuDB = devdb.NewOnuDeviceDB(log.WithSpanFromContext(context.TODO(), ctx), oo.deviceID) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 98 | go oo.processMibSyncMessages(ctx) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 99 | } |
| 100 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 101 | func (oo *OnuDeviceEntry) enterResettingMibState(ctx context.Context, e *fsm.Event) { |
| 102 | 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] | 103 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 104 | if (!oo.IsNewOnu() && !oo.baseDeviceHandler.IsReconciling()) || //use case: re-auditing failed |
| 105 | oo.baseDeviceHandler.IsSkipOnuConfigReconciling() { //use case: reconciling without omci-config failed |
| 106 | oo.baseDeviceHandler.PrepareReconcilingWithActiveAdapter(ctx) |
| 107 | oo.devState = cmn.DeviceStatusInit |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 108 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 109 | 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] | 110 | oo.mutexLastTxParamStruct.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 111 | _ = oo.PDevOmciCC.SendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 112 | //TODO: needs to handle timeouts |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 113 | //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure |
| 114 | // that the lastTxMessageType is correctly set to avoid misinterpreting other responses |
| 115 | oo.lastTxParamStruct.lastTxMessageType = omci.MibResetRequestType |
| 116 | oo.lastTxParamStruct.repeatCount = 0 |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 117 | oo.mutexLastTxParamStruct.Unlock() |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 118 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 119 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 120 | func (oo *OnuDeviceEntry) enterGettingVendorAndSerialState(ctx context.Context, e *fsm.Event) { |
| 121 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting VendorId and SerialNumber in State": e.FSM.Current(), "device-id": oo.deviceID}) |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 122 | requestedAttributes := me.AttributeValueMap{me.OnuG_VendorId: "", me.OnuG_SerialNumber: 0} |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 123 | oo.mutexLastTxParamStruct.Lock() |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 124 | meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.OnuGClassID, cmn.OnugMeID, requestedAttributes, |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 125 | oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, false) |
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, "ONU-G get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 131 | pMibUlFsm := oo.PMibUploadFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 132 | if pMibUlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 133 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 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 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 143 | |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 144 | func (oo *OnuDeviceEntry) enterGettingVersionState(ctx context.Context, e *fsm.Event) { |
| 145 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting Version in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 146 | requestedAttributes := me.AttributeValueMap{me.OnuG_Version: ""} |
| 147 | oo.mutexLastTxParamStruct.Lock() |
| 148 | meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.OnuGClassID, cmn.OnugMeID, |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 149 | requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, false) |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 150 | //accept also nil as (error) return value for writing to LastTx |
| 151 | // - this avoids misinterpretation of new received OMCI messages |
| 152 | if err != nil { |
| 153 | oo.mutexLastTxParamStruct.Unlock() |
| 154 | logger.Errorw(ctx, "ONU-G get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID}) |
| 155 | pMibUlFsm := oo.PMibUploadFsm |
| 156 | if pMibUlFsm != nil { |
| 157 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 158 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
| 159 | }(pMibUlFsm) |
| 160 | } |
| 161 | return |
| 162 | } |
| 163 | oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType |
| 164 | oo.lastTxParamStruct.pLastTxMeInstance = meInstance |
| 165 | oo.mutexLastTxParamStruct.Unlock() |
| 166 | } |
| 167 | |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 168 | func (oo *OnuDeviceEntry) enterGettingEquipIDAndOmccVersState(ctx context.Context, e *fsm.Event) { |
| 169 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting EquipmentId and OMCC version in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 170 | requestedAttributes := me.AttributeValueMap{me.Onu2G_EquipmentId: "", me.Onu2G_OpticalNetworkUnitManagementAndControlChannelOmccVersion: 0} |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 171 | oo.mutexLastTxParamStruct.Lock() |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 172 | meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.Onu2GClassID, cmn.Onu2gMeID, requestedAttributes, |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 173 | oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, false) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 174 | //accept also nil as (error) return value for writing to LastTx |
| 175 | // - this avoids misinterpretation of new received OMCI messages |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 176 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 177 | oo.mutexLastTxParamStruct.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 178 | logger.Errorw(ctx, "ONU2-G get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 179 | pMibUlFsm := oo.PMibUploadFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 180 | if pMibUlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 181 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 182 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 183 | }(pMibUlFsm) |
| 184 | } |
| 185 | return |
| 186 | } |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 187 | oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType |
| 188 | oo.lastTxParamStruct.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 189 | oo.mutexLastTxParamStruct.Unlock() |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 192 | func (oo *OnuDeviceEntry) enterTestingExtOmciSupportState(ctx context.Context, e *fsm.Event) { |
| 193 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start testing extended OMCI msg in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 194 | omciVerify := otst.NewOmciTestRequest(log.WithSpanFromContext(context.TODO(), ctx), |
| 195 | oo.deviceID, oo.PDevOmciCC, true, true, true) |
| 196 | verifyExec := make(chan bool) |
| 197 | omciVerify.PerformOmciTest(log.WithSpanFromContext(context.TODO(), ctx), verifyExec) |
| 198 | |
| 199 | // If verification of test message in extended OMCI format fails, reset ONU capability to OMCI baseline format |
| 200 | select { |
| 201 | case <-time.After(((cmn.CDefaultRetries+1)*otst.CTestRequestOmciTimeout + 1) * time.Second): |
| 202 | logger.Warnw(ctx, "testing extended OMCI msg format timed out - reset to baseline format", log.Fields{"device-id": oo.deviceID}) |
| 203 | oo.MutexPersOnuConfig.Lock() |
| 204 | oo.SOnuPersistentData.PersIsExtOmciSupported = false |
| 205 | oo.MutexPersOnuConfig.Unlock() |
| 206 | case success := <-verifyExec: |
| 207 | if success { |
| 208 | logger.Debugw(ctx, "testing extended OMCI msg format succeeded", log.Fields{"device-id": oo.deviceID}) |
| 209 | } else { |
| 210 | logger.Warnw(ctx, "testing extended OMCI msg format failed - reset to baseline format", log.Fields{"device-id": oo.deviceID, "result": success}) |
| 211 | oo.MutexPersOnuConfig.Lock() |
| 212 | oo.SOnuPersistentData.PersIsExtOmciSupported = false |
| 213 | oo.MutexPersOnuConfig.Unlock() |
| 214 | } |
| 215 | } |
| 216 | pMibUlFsm := oo.PMibUploadFsm |
| 217 | if pMibUlFsm != nil { |
| 218 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 219 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetFirstSwVersion) |
| 220 | }(pMibUlFsm) |
| 221 | } |
| 222 | } |
| 223 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 224 | func (oo *OnuDeviceEntry) enterGettingFirstSwVersionState(ctx context.Context, e *fsm.Event) { |
| 225 | 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}) |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 226 | requestedAttributes := me.AttributeValueMap{me.SoftwareImage_IsCommitted: 0, me.SoftwareImage_IsActive: 0, me.SoftwareImage_Version: ""} |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 227 | oo.mutexLastTxParamStruct.Lock() |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 228 | meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, cmn.FirstSwImageMeID, requestedAttributes, |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 229 | oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, oo.GetPersIsExtOmciSupported()) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 230 | //accept also nil as (error) return value for writing to LastTx |
| 231 | // - this avoids misinterpretation of new received OMCI messages |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 232 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 233 | oo.mutexLastTxParamStruct.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 234 | logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 235 | pMibUlFsm := oo.PMibUploadFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 236 | if pMibUlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 237 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 238 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 239 | }(pMibUlFsm) |
| 240 | } |
| 241 | return |
| 242 | } |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 243 | oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType |
| 244 | oo.lastTxParamStruct.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 245 | oo.mutexLastTxParamStruct.Unlock() |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 246 | } |
| 247 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 248 | func (oo *OnuDeviceEntry) enterGettingSecondSwVersionState(ctx context.Context, e *fsm.Event) { |
| 249 | 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}) |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 250 | requestedAttributes := me.AttributeValueMap{me.SoftwareImage_IsCommitted: 0, me.SoftwareImage_IsActive: 0, me.SoftwareImage_Version: ""} |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 251 | oo.mutexLastTxParamStruct.Lock() |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 252 | meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.SoftwareImageClassID, cmn.SecondSwImageMeID, requestedAttributes, |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 253 | oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, oo.GetPersIsExtOmciSupported()) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 254 | //accept also nil as (error) return value for writing to LastTx |
| 255 | // - this avoids misinterpretation of new received OMCI messages |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 256 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 257 | oo.mutexLastTxParamStruct.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 258 | logger.Errorw(ctx, "SoftwareImage get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 259 | pMibUlFsm := oo.PMibUploadFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 260 | if pMibUlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 261 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 262 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 263 | }(pMibUlFsm) |
| 264 | } |
| 265 | return |
| 266 | } |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 267 | oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType |
| 268 | oo.lastTxParamStruct.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 269 | oo.mutexLastTxParamStruct.Unlock() |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 270 | } |
| 271 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 272 | func (oo *OnuDeviceEntry) enterGettingMacAddressState(ctx context.Context, e *fsm.Event) { |
| 273 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start getting MacAddress in State": e.FSM.Current(), "device-id": oo.deviceID}) |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 274 | requestedAttributes := me.AttributeValueMap{me.IpHostConfigData_MacAddress: ""} |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 275 | oo.mutexLastTxParamStruct.Lock() |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 276 | meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), me.IpHostConfigDataClassID, cmn.IPHostConfigDataMeID, requestedAttributes, |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 277 | oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, oo.GetPersIsExtOmciSupported()) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 278 | //accept also nil as (error) return value for writing to LastTx |
| 279 | // - this avoids misinterpretation of new received OMCI messages |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 280 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 281 | oo.mutexLastTxParamStruct.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 282 | logger.Errorw(ctx, "IpHostConfigData get failed, aborting MibSync FSM", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 283 | pMibUlFsm := oo.PMibUploadFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 284 | if pMibUlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 285 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 286 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 287 | }(pMibUlFsm) |
| 288 | } |
| 289 | return |
| 290 | } |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 291 | oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType |
| 292 | oo.lastTxParamStruct.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 293 | oo.mutexLastTxParamStruct.Unlock() |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 296 | func (oo *OnuDeviceEntry) enterGettingMibTemplateState(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 297 | |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 298 | oo.mutexOnuSwImageIndications.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 299 | if oo.onuSwImageIndications.ActiveEntityEntry.Valid { |
| 300 | oo.MutexPersOnuConfig.Lock() |
| 301 | oo.SOnuPersistentData.PersActiveSwVersion = oo.onuSwImageIndications.ActiveEntityEntry.Version |
| 302 | oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 303 | oo.mutexOnuSwImageIndications.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 304 | } else { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 305 | oo.mutexOnuSwImageIndications.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 306 | logger.Errorw(ctx, "get-mib-template: no active SW version found, working with empty SW version, which might be untrustworthy", |
| 307 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 308 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 309 | if oo.getMibFromTemplate(ctx) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 310 | logger.Debug(ctx, "MibSync FSM - valid MEs stored from template") |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 311 | oo.pOnuDB.LogMeDb(ctx) |
| 312 | fsmMsg = cmn.LoadMibTemplateOk |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 313 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 314 | logger.Debug(ctx, "MibSync FSM - no valid MEs stored from template - perform MIB-upload!") |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 315 | fsmMsg = cmn.LoadMibTemplateFailed |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 316 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 317 | oo.pOpenOnuAc.LockMutexMibTemplateGenerated() |
| 318 | if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); exist { |
Holger Hildebrandt | 441a017 | 2020-12-10 13:57:08 +0000 | [diff] [blame] | 319 | if mibTemplateIsGenerated { |
| 320 | logger.Debugw(ctx, |
| 321 | "MibSync FSM - template was successfully generated before, but doesn't exist or isn't usable anymore - reset flag in map", |
| 322 | log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 323 | oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false) |
Holger Hildebrandt | 441a017 | 2020-12-10 13:57:08 +0000 | [diff] [blame] | 324 | } |
| 325 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 326 | oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated() |
Holger Hildebrandt | 441a017 | 2020-12-10 13:57:08 +0000 | [diff] [blame] | 327 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 328 | mibSyncMsg := cmn.Message{ |
| 329 | Type: cmn.TestMsg, |
| 330 | Data: cmn.TestMessage{ |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 331 | TestMessageVal: fsmMsg, |
| 332 | }, |
| 333 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 334 | oo.PMibUploadFsm.CommChan <- mibSyncMsg |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 335 | } |
| 336 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 337 | func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) { |
| 338 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"send MibUpload in State": e.FSM.Current(), "device-id": oo.deviceID}) |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 339 | _ = oo.PDevOmciCC.SendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), |
| 340 | oo.baseDeviceHandler.GetOmciTimeout(), true, oo.GetPersIsExtOmciSupported()) |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 341 | //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure |
| 342 | // that the lastTxMessageType is correctly set to avoid misinterpreting other responses |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 343 | oo.mutexLastTxParamStruct.Lock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 344 | oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadRequestType |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 345 | oo.mutexLastTxParamStruct.Unlock() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 348 | func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 349 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 350 | oo.transferSystemEvent(ctx, cmn.MibDatabaseSync) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 351 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 352 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 353 | }() |
| 354 | } |
| 355 | |
| 356 | func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 357 | oo.MutexPersOnuConfig.Lock() |
| 358 | oo.SOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix()) |
| 359 | oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 360 | if oo.mibAuditInterval > 0 { |
| 361 | 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] | 362 | go func() { |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 363 | time.Sleep(oo.mibAuditInterval) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 364 | if err := oo.PMibUploadFsm.PFsm.Event(UlEvAuditMib); err != nil { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 365 | logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err}) |
| 366 | } |
| 367 | }() |
| 368 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 371 | func (oo *OnuDeviceEntry) enterVerifyingAndStoringTPsState(ctx context.Context, e *fsm.Event) { |
| 372 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start verifying and storing TPs in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 373 | |
Holger Hildebrandt | 80f5776 | 2022-02-16 10:03:24 +0000 | [diff] [blame] | 374 | if oo.getAllStoredTpInstFromParentAdapter(ctx) { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 375 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"reconciling - verifying TPs successful": e.FSM.Current(), "device-id": oo.deviceID}) |
| 376 | go func() { |
| 377 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
| 378 | }() |
| 379 | } else { |
| 380 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"reconciling - verifying TPs not successful": e.FSM.Current(), "device-id": oo.deviceID}) |
| 381 | oo.baseDeviceHandler.SetReconcilingReasonUpdate(true) |
| 382 | go func() { |
| 383 | if err := oo.baseDeviceHandler.StorePersistentData(ctx); err != nil { |
| 384 | logger.Warnw(ctx, "reconciling - store persistent data error - continue for now as there will be additional write attempts", |
| 385 | log.Fields{"device-id": oo.deviceID, "err": err}) |
| 386 | } |
| 387 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch) |
| 388 | }() |
| 389 | } |
| 390 | } |
| 391 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 392 | func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) { |
| 393 | 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] | 394 | oo.requestMdsValue(ctx) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 395 | } |
| 396 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 397 | func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) { |
| 398 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 399 | logger.Debug(ctx, "function not implemented yet") |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 400 | // TODOs: |
| 401 | // VOL-3805 - Provide exclusive OMCI channel for one FSM |
| 402 | // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go |
| 403 | // VOL-3792 - Support periodical audit via mib resync |
| 404 | // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 407 | func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) { |
| 408 | logger.Debugw(ctx, "MibSync FSM", |
| 409 | log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 410 | |
| 411 | if oo.getMibFromTemplate(ctx) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 412 | oo.baseDeviceHandler.StartReconciling(ctx, true) |
| 413 | oo.baseDeviceHandler.AddAllUniPorts(ctx) |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 414 | _ = oo.baseDeviceHandler.ReasonUpdate(ctx, cmn.DrInitialMibDownloaded, oo.baseDeviceHandler.IsReconcilingReasonUpdate()) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 415 | oo.baseDeviceHandler.SetReadyForOmciConfig(true) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 416 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 417 | if !oo.baseDeviceHandler.GetCollectorIsRunning() { |
Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 418 | var waitForOmciProcess sync.WaitGroup |
| 419 | waitForOmciProcess.Add(1) |
Holger Hildebrandt | ced74e7 | 2021-06-10 14:55:53 +0000 | [diff] [blame] | 420 | // Start PM collector routine |
Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 421 | go oo.baseDeviceHandler.StartCollector(ctx, &waitForOmciProcess) |
| 422 | waitForOmciProcess.Wait() |
Holger Hildebrandt | ced74e7 | 2021-06-10 14:55:53 +0000 | [diff] [blame] | 423 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 424 | if !oo.baseDeviceHandler.GetAlarmManagerIsRunning(ctx) { |
| 425 | go oo.baseDeviceHandler.StartAlarmManager(ctx) |
Holger Hildebrandt | ced74e7 | 2021-06-10 14:55:53 +0000 | [diff] [blame] | 426 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 427 | |
| 428 | for _, uniPort := range *oo.baseDeviceHandler.GetUniEntityMap() { |
| 429 | // only if this port was enabled for use by the operator at startup |
| 430 | if (1<<uniPort.UniID)&oo.baseDeviceHandler.GetUniPortMask() == (1 << uniPort.UniID) { |
| 431 | if !oo.baseDeviceHandler.GetFlowMonitoringIsRunning(uniPort.UniID) { |
| 432 | go oo.baseDeviceHandler.PerOnuFlowHandlerRoutine(uniPort.UniID) |
| 433 | } |
| 434 | } |
| 435 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 436 | oo.MutexPersOnuConfig.RLock() |
| 437 | if oo.SOnuPersistentData.PersUniDisableDone { |
| 438 | oo.MutexPersOnuConfig.RUnlock() |
| 439 | oo.baseDeviceHandler.DisableUniPortStateUpdate(ctx) |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 440 | _ = oo.baseDeviceHandler.ReasonUpdate(ctx, cmn.DrOmciAdminLock, oo.baseDeviceHandler.IsReconcilingReasonUpdate()) |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 441 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 442 | oo.MutexPersOnuConfig.RUnlock() |
| 443 | oo.baseDeviceHandler.EnableUniPortStateUpdate(ctx) |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 444 | } |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 445 | |
| 446 | // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm |
| 447 | |
| 448 | if oo.baseDeviceHandler.ReconcileDeviceTechProf(ctx) { |
| 449 | // start go routine with select() on reconciling flow channel before |
| 450 | // starting flow reconciling process to prevent loss of any signal |
Holger Hildebrandt | f2fcdd4 | 2021-12-15 11:42:19 +0000 | [diff] [blame] | 451 | syncChannel := make(chan struct{}) |
| 452 | go func(aSyncChannel chan struct{}) { |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 453 | // In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until |
| 454 | // we get a signal that the processing of the last step to rebuild the adapter internal |
| 455 | // flow data is finished. |
| 456 | expiry := oo.baseDeviceHandler.GetReconcileExpiryVlanConfigAbort() |
| 457 | oo.setReconcilingFlows(true) |
Holger Hildebrandt | f2fcdd4 | 2021-12-15 11:42:19 +0000 | [diff] [blame] | 458 | aSyncChannel <- struct{}{} |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 459 | select { |
| 460 | case success := <-oo.chReconcilingFlowsFinished: |
| 461 | if success { |
| 462 | logger.Debugw(ctx, "reconciling flows has been finished in time", |
| 463 | log.Fields{"device-id": oo.deviceID}) |
| 464 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
| 465 | |
| 466 | } else { |
| 467 | logger.Debugw(ctx, "wait for reconciling flows aborted", |
| 468 | log.Fields{"device-id": oo.deviceID}) |
| 469 | } |
| 470 | case <-time.After(expiry): |
| 471 | logger.Errorw(ctx, "timeout waiting for reconciling flows to be finished!", |
| 472 | log.Fields{"device-id": oo.deviceID, "expiry": expiry}) |
| 473 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch) |
| 474 | } |
| 475 | oo.setReconcilingFlows(false) |
Holger Hildebrandt | f2fcdd4 | 2021-12-15 11:42:19 +0000 | [diff] [blame] | 476 | }(syncChannel) |
| 477 | // block further processing until the above Go routine has really started |
| 478 | // and is ready to receive values from chReconcilingFlowsFinished |
| 479 | <-syncChannel |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 480 | oo.baseDeviceHandler.ReconcileDeviceFlowConfig(ctx) |
| 481 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 482 | } else { |
| 483 | logger.Debugw(ctx, "MibSync FSM", |
| 484 | log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID}) |
| 485 | go func() { |
| 486 | //switch to reconciling with OMCI config |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 487 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 488 | }() |
| 489 | } |
| 490 | } |
| 491 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 492 | func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 493 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibAudit processing in State": e.FSM.Current(), "device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 494 | if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 495 | oo.requestMdsValue(ctx) |
| 496 | } else { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 497 | 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] | 498 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 499 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 500 | }() |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) { |
| 505 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start retest MdsValue processing in State": e.FSM.Current(), "device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 506 | if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 507 | oo.requestMdsValue(ctx) |
| 508 | } else { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 509 | 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] | 510 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 511 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 512 | }() |
| 513 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 514 | } |
| 515 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 516 | func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) { |
| 517 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 518 | logger.Debug(ctx, "function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 519 | } |
| 520 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 521 | func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) { |
| 522 | logger.Debugw(ctx, "MibSync Msg", log.Fields{"Start routine to process OMCI-messages for device-id": oo.deviceID}) |
Girish Gowdra | 37c9d91 | 2022-02-08 16:24:57 -0800 | [diff] [blame] | 523 | oo.mutexMibSyncMsgProcessorRunning.Lock() |
| 524 | oo.mibSyncMsgProcessorRunning = true |
| 525 | oo.mutexMibSyncMsgProcessorRunning.Unlock() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 526 | loop: |
| 527 | for { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 528 | // case <-ctx.Done(): |
| 529 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID}) |
| 530 | // break loop |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 531 | message, ok := <-oo.PMibUploadFsm.CommChan |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 532 | if !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 533 | logger.Info(ctx, "MibSync Msg", log.Fields{"Message couldn't be read from channel for device-id": oo.deviceID}) |
Girish Gowdra | 37c9d91 | 2022-02-08 16:24:57 -0800 | [diff] [blame] | 534 | oo.mutexMibSyncMsgProcessorRunning.Lock() |
| 535 | oo.mibSyncMsgProcessorRunning = false |
| 536 | oo.mutexMibSyncMsgProcessorRunning.Unlock() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 537 | break loop |
| 538 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 539 | 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] | 540 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 541 | switch message.Type { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 542 | case cmn.TestMsg: |
| 543 | msg, _ := message.Data.(cmn.TestMessage) |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 544 | if msg.TestMessageVal == cmn.AbortMessageProcessing { |
| 545 | logger.Debugw(ctx, "MibSync Msg abort ProcessMsg", log.Fields{"for device-id": oo.deviceID}) |
Girish Gowdra | 37c9d91 | 2022-02-08 16:24:57 -0800 | [diff] [blame] | 546 | oo.mutexMibSyncMsgProcessorRunning.Lock() |
| 547 | oo.mibSyncMsgProcessorRunning = false |
| 548 | oo.mutexMibSyncMsgProcessorRunning.Unlock() |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 549 | break loop |
| 550 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 551 | oo.handleTestMsg(ctx, msg) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 552 | case cmn.OMCI: |
| 553 | msg, _ := message.Data.(cmn.OmciMessage) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 554 | oo.handleOmciMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 555 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 556 | 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] | 557 | } |
| 558 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 559 | 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] | 560 | // TODO: only this action? |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 561 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 564 | func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg cmn.TestMessage) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 565 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 566 | 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] | 567 | |
| 568 | switch msg.TestMessageVal { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 569 | case cmn.LoadMibTemplateFailed: |
| 570 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvUploadMib) |
| 571 | logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.PMibUploadFsm.PFsm.Current())}) |
| 572 | case cmn.LoadMibTemplateOk: |
| 573 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
| 574 | 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] | 575 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 576 | 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] | 577 | } |
| 578 | } |
| 579 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 580 | func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg cmn.OmciMessage) { |
| 581 | if oo.PMibUploadFsm.PFsm.Is(UlStResettingMib) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 582 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse) |
| 583 | if msgLayer != nil { |
| 584 | msgObj, msgOk := msgLayer.(*omci.MibResetResponse) |
| 585 | if msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 586 | logger.Debugw(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 587 | if msgObj.Result == me.Success { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 588 | oo.MutexPersOnuConfig.Lock() |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 589 | oo.SOnuPersistentData.PersMibDataSyncAdpt = cmn.MdsDefaultMib |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 590 | oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | 7e13846 | 2023-03-29 12:12:14 +0000 | [diff] [blame] | 591 | oo.PDevOmciCC.ResetConfFailMEs() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 592 | // trigger retrieval of VendorId and SerialNumber |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 593 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetVendorAndSerial) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 594 | return |
| 595 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 596 | 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] | 597 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 598 | 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] | 599 | } |
| 600 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 601 | 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] | 602 | } |
| 603 | } else { |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 604 | //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset |
| 605 | // with Sequence number 0x8000 as last request before - so it may still respond to that |
| 606 | // 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] | 607 | oo.mutexLastTxParamStruct.Lock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 608 | if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 { |
| 609 | logger.Debugw(ctx, "MibSync FSM - repeat MdsGetRequest (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 610 | requestedAttributes := me.AttributeValueMap{me.OnuData_MibDataSync: ""} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 611 | _, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 612 | me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, false) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 613 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 614 | oo.mutexLastTxParamStruct.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 615 | logger.Errorw(ctx, "ONUData get failed, aborting MibSync", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 616 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 617 | return |
| 618 | } |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 619 | //TODO: needs extra handling of timeouts |
| 620 | oo.lastTxParamStruct.repeatCount = 1 |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 621 | oo.mutexLastTxParamStruct.Unlock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 622 | return |
| 623 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 624 | oo.mutexLastTxParamStruct.Unlock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 625 | logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID}) |
| 626 | //perhaps some still lingering message from some prior activity, let's wait for the real response |
| 627 | return |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 628 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 629 | logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 630 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 631 | } |
| 632 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 633 | func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg cmn.OmciMessage) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 634 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse) |
| 635 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 636 | 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] | 637 | return |
| 638 | } |
| 639 | msgObj, msgOk := msgLayer.(*omci.MibUploadResponse) |
| 640 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 641 | 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] | 642 | return |
| 643 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 644 | 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] | 645 | /* to be verified / reworked !!! */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 646 | oo.PDevOmciCC.UploadNoOfCmds = msgObj.NumberOfCommands |
| 647 | if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds { |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 648 | _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), |
| 649 | oo.baseDeviceHandler.GetOmciTimeout(), true, oo.GetPersIsExtOmciSupported()) |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 650 | //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure |
| 651 | // that the lastTxMessageType is correctly set to avoid misinterpreting other responses |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 652 | oo.mutexLastTxParamStruct.Lock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 653 | oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 654 | oo.mutexLastTxParamStruct.Unlock() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 655 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 656 | 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] | 657 | //TODO right action? |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 658 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvTimeout) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 662 | func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg cmn.OmciMessage) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 663 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse) |
mpagenko | 7033f4e | 2021-11-19 18:04:22 +0000 | [diff] [blame] | 664 | if msgLayer != nil { |
| 665 | msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse) |
| 666 | if !msgOk { |
| 667 | logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID}) |
| 668 | return |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 669 | } |
mpagenko | 7033f4e | 2021-11-19 18:04:22 +0000 | [diff] [blame] | 670 | meName := msgObj.ReportedME.GetName() |
| 671 | meClassID := msgObj.ReportedME.GetClassID() |
| 672 | meEntityID := msgObj.ReportedME.GetEntityID() |
| 673 | |
| 674 | logger.Debugw(ctx, "MibUploadNextResponse Data for:", log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj}) |
| 675 | |
| 676 | if meName == devdb.CUnknownItuG988ManagedEntity || meName == devdb.CUnknownVendorSpecificManagedEntity { |
Holger Hildebrandt | 3908002 | 2022-03-16 10:03:17 +0000 | [diff] [blame] | 677 | logger.Debugw(ctx, "MibUploadNextResponse contains unknown ME", log.Fields{"device-id": oo.deviceID, |
| 678 | "Me-Name": devdb.UnknownMeOrAttribName(meName), "Me-ClassId": meClassID, "Me-InstId": meEntityID, |
| 679 | "unknown mask": msgObj.ReportedME.GetAttributeMask(), "unknown attributes": msgObj.BaseLayer.Payload}) |
| 680 | oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.UnknownMeOrAttribName(meName), meClassID, meEntityID, |
| 681 | msgObj.ReportedME.GetAttributeMask(), msgObj.BaseLayer.Payload[devdb.CStartUnknownMeAttribsInBaseLayerPayload:]) |
mpagenko | 7033f4e | 2021-11-19 18:04:22 +0000 | [diff] [blame] | 682 | } else { |
| 683 | //with relaxed decoding set in the OMCI-LIB we have the chance to detect if there are some unknown attributes appended which we cannot decode |
| 684 | if unknownAttrLayer := (*msg.OmciPacket).Layer(omci.LayerTypeUnknownAttributes); unknownAttrLayer != nil { |
| 685 | logger.Warnw(ctx, "MibUploadNextResponse contains unknown attributes", log.Fields{"device-id": oo.deviceID}) |
| 686 | if unknownAttributes, ok := unknownAttrLayer.(*omci.UnknownAttributes); ok { |
| 687 | // provide a loop over several ME's here already in preparation of OMCI extended message format |
| 688 | for _, unknown := range unknownAttributes.Attributes { |
| 689 | unknownAttrClassID := unknown.EntityClass // ClassID |
| 690 | unknownAttrInst := unknown.EntityInstance // uint16 |
| 691 | unknownAttrMask := unknown.AttributeMask // ui |
| 692 | unknownAttrBlob := unknown.AttributeData // []byte |
| 693 | logger.Warnw(ctx, "unknown attributes detected for", log.Fields{"device-id": oo.deviceID, |
| 694 | "Me-ClassId": unknownAttrClassID, "Me-InstId": unknownAttrInst, "unknown mask": unknownAttrMask, |
| 695 | "unknown attributes": unknownAttrBlob}) |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 696 | oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.CUnknownAttributesManagedEntity, unknown.EntityClass, unknown.EntityInstance, |
| 697 | unknown.AttributeMask, unknown.AttributeData) |
mpagenko | 7033f4e | 2021-11-19 18:04:22 +0000 | [diff] [blame] | 698 | } // for all included ME's with unknown attributes |
| 699 | } else { |
| 700 | logger.Errorw(ctx, "unknownAttrLayer could not be decoded", log.Fields{"device-id": oo.deviceID}) |
| 701 | } |
| 702 | } |
| 703 | oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, msgObj.ReportedME.GetAttributeValueMap()) |
| 704 | } |
Holger Hildebrandt | 0edf5b0 | 2022-05-04 14:19:43 +0000 | [diff] [blame] | 705 | if msg.OmciMsg.DeviceIdentifier == omci.ExtendedIdent { |
| 706 | for _, additionalME := range msgObj.AdditionalMEs { |
| 707 | meName := additionalME.GetName() |
| 708 | meClassID := additionalME.GetClassID() |
| 709 | meEntityID := additionalME.GetEntityID() |
| 710 | attributes := additionalME.GetAttributeValueMap() |
| 711 | |
| 712 | if meName == devdb.CUnknownItuG988ManagedEntity || meName == devdb.CUnknownVendorSpecificManagedEntity { |
| 713 | attribMask := additionalME.GetAttributeMask() |
| 714 | logger.Debugw(ctx, "MibUploadNextResponse AdditionalData contains unknown ME", log.Fields{"device-id": oo.deviceID, |
| 715 | "Me-Name": devdb.UnknownMeOrAttribName(meName), "Me-ClassId": meClassID, "Me-InstId": meEntityID, |
| 716 | "unknown mask": attribMask}) |
| 717 | |
| 718 | attribValues := make([]byte, 0) |
| 719 | for key, value := range attributes { |
| 720 | if key != cmn.CGenericManagedEntityIDName { |
| 721 | data, err := me.InterfaceToOctets(value) |
| 722 | if err != nil { |
| 723 | logger.Infow(ctx, "MibUploadNextResponse unknown ME AdditionalData attrib - could not decode", log.Fields{"device-id": oo.deviceID, "key": key}) |
| 724 | } else { |
| 725 | attribValues = append(attribValues[:], data[:]...) |
| 726 | logger.Debugw(ctx, "MibUploadNextResponse unknown ME AdditionalData attrib", log.Fields{"device-id": oo.deviceID, "attribValues": attribValues, "data": data, "key": key}) |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.UnknownMeOrAttribName(meName), meClassID, meEntityID, attribMask, attribValues) |
| 731 | } else { |
| 732 | logger.Debugw(ctx, "MibUploadNextResponse AdditionalData for:", log.Fields{"device-id": oo.deviceID, "meName": meName, "meEntityID": meEntityID, "attributes": attributes}) |
| 733 | oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributes) |
| 734 | } |
| 735 | } |
| 736 | } |
mpagenko | 7033f4e | 2021-11-19 18:04:22 +0000 | [diff] [blame] | 737 | } else { |
| 738 | logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID}) |
| 739 | //as long as omci-lib does not support decoding of table attribute as 'unknown/unspecified' attribute |
| 740 | // we have to verify, if this failure is from table attribute and try to go forward with ignoring the complete message |
| 741 | errLayer := (*msg.OmciPacket).Layer(gopacket.LayerTypeDecodeFailure) |
| 742 | if failure, decodeOk := errLayer.(*gopacket.DecodeFailure); decodeOk { |
| 743 | errMsg := failure.String() |
| 744 | if !strings.Contains(strings.ToLower(errMsg), "table decode") { |
| 745 | //something still unexected happened, needs deeper investigation - stop complete MIB upload process (timeout) |
| 746 | return |
| 747 | } |
| 748 | logger.Warnw(ctx, "Decode issue on received MibUploadNextResponse frame - found table attribute(s) (message ignored)", |
| 749 | log.Fields{"device-id": oo.deviceID, "issue": errMsg}) |
| 750 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 751 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 752 | if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds { |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 753 | _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), |
| 754 | oo.baseDeviceHandler.GetOmciTimeout(), true, oo.GetPersIsExtOmciSupported()) |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 755 | //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure |
| 756 | // that the lastTxMessageType is correctly set to avoid misinterpreting other responses |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 757 | oo.mutexLastTxParamStruct.Lock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 758 | oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 759 | oo.mutexLastTxParamStruct.Unlock() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 760 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 761 | oo.pOnuDB.LogMeDb(ctx) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 762 | err := oo.createAndPersistMibTemplate(ctx) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 763 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 764 | 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] | 765 | } |
| 766 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 767 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | |
Girish Gowdra | 21bbf05 | 2022-02-17 16:08:22 -0800 | [diff] [blame] | 771 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 772 | func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg cmn.OmciMessage) error { |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 773 | var err error = nil |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 774 | |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 775 | oo.mutexLastTxParamStruct.RLock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 776 | if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType || |
| 777 | oo.lastTxParamStruct.pLastTxMeInstance == nil { |
| 778 | //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest |
| 779 | // with Sequence number 0x8000 as last request before - so it may still respond to that |
| 780 | // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number |
| 781 | if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 { |
| 782 | logger.Debugw(ctx, "MibSync FSM - repeat mibReset (updated SequenceNumber)", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 783 | _ = oo.PDevOmciCC.SendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true) |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 784 | //TODO: needs extra handling of timeouts |
| 785 | oo.lastTxParamStruct.repeatCount = 1 |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 786 | oo.mutexLastTxParamStruct.RUnlock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 787 | return nil |
| 788 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 789 | oo.mutexLastTxParamStruct.RUnlock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 790 | logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID}) |
| 791 | //perhaps some still lingering message from some prior activity, let's wait for the real response |
| 792 | return nil |
| 793 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 794 | oo.mutexLastTxParamStruct.RUnlock() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 795 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 796 | if msgLayer == nil { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 797 | logger.Errorw(ctx, "omci Msg layer could not be detected for GetResponse - handling of MibSyncChan stopped", |
| 798 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 799 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 800 | 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] | 801 | } |
| 802 | msgObj, msgOk := msgLayer.(*omci.GetResponse) |
| 803 | if !msgOk { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 804 | logger.Errorw(ctx, "omci Msg layer could not be assigned for GetResponse - handling of MibSyncChan stopped", |
| 805 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 806 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 807 | 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] | 808 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 809 | 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] | 810 | if msgObj.Result == me.Success { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 811 | oo.mutexLastTxParamStruct.RLock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 812 | entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID() |
| 813 | if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID { |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 814 | meAttributes := msgObj.Attributes |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 815 | meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName() |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 816 | logger.Debugf(ctx, "MibSync FSM - GetResponse Data for %s", |
| 817 | log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 818 | switch meInstance { |
| 819 | case "OnuG": |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 820 | oo.mutexLastTxParamStruct.RUnlock() |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 821 | return oo.handleOmciGetResponseOnuG(ctx, meAttributes) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 822 | case "Onu2G": |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 823 | oo.mutexLastTxParamStruct.RUnlock() |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 824 | var equipmentID string |
| 825 | if onu2GEquipmentID, ok := meAttributes[me.Onu2G_EquipmentId]; ok { |
| 826 | equipmentID = cmn.TrimStringFromMeOctet(onu2GEquipmentID) |
| 827 | if equipmentID == "" { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 828 | logger.Infow(ctx, |
| 829 | "MibSync FSM - optional attribute EquipmentID is empty in Onu2G instance - fill with appropriate value", |
| 830 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 831 | equipmentID = cEmptyEquipIDString |
| 832 | } |
| 833 | } else { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 834 | logger.Infow(ctx, |
| 835 | "MibSync FSM - optional attribute EquipmentID not present in Onu2G instance - fill with appropriate value", |
| 836 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 837 | equipmentID = cNotPresentEquipIDString |
| 838 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 839 | oo.MutexPersOnuConfig.Lock() |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 840 | oo.SOnuPersistentData.PersEquipmentID = equipmentID |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 841 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - EquipmentId", log.Fields{"device-id": oo.deviceID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 842 | "onuDeviceEntry.equipmentID": oo.SOnuPersistentData.PersEquipmentID}) |
| 843 | oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 844 | |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 845 | var omccVersion uint8 |
| 846 | if onu2GOmccVersion, ok := meAttributes[me.Onu2G_OpticalNetworkUnitManagementAndControlChannelOmccVersion]; ok { |
| 847 | oo.MutexPersOnuConfig.Lock() |
| 848 | omccVersion = onu2GOmccVersion.(uint8) |
| 849 | if _, ok := omccVersionSupportsExtendedOmciFormat[omccVersion]; ok { |
| 850 | oo.SOnuPersistentData.PersIsExtOmciSupported = omccVersionSupportsExtendedOmciFormat[omccVersion] |
Holger Hildebrandt | c572e62 | 2022-06-22 09:19:17 +0000 | [diff] [blame] | 851 | if oo.SOnuPersistentData.PersIsExtOmciSupported && !oo.baseDeviceHandler.GetExtendedOmciSupportEnabled() { |
| 852 | logger.Infow(ctx, "MibSync FSM - ONU supports extended OMCI, but support is disabled in the adapter: reset flag", |
| 853 | log.Fields{"device-id": oo.deviceID}) |
| 854 | oo.SOnuPersistentData.PersIsExtOmciSupported = false |
| 855 | } |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 856 | } else { |
| 857 | logger.Infow(ctx, "MibSync FSM - unknown OMCC version in Onu2G instance - disable extended OMCI support", |
| 858 | log.Fields{"device-id": oo.deviceID}) |
| 859 | oo.SOnuPersistentData.PersIsExtOmciSupported = false |
| 860 | } |
| 861 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - OMCC version", log.Fields{"device-id": oo.deviceID, |
| 862 | "omccVersion": omccVersion, "isExtOmciSupported": oo.SOnuPersistentData.PersIsExtOmciSupported}) |
| 863 | oo.MutexPersOnuConfig.Unlock() |
| 864 | } else { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 865 | logger.Errorw(ctx, |
| 866 | "MibSync FSM - mandatory attribute OMCC version not present in Onu2G instance - handling of MibSyncChan stopped!", |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 867 | log.Fields{"device-id": oo.deviceID}) |
| 868 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 869 | return fmt.Errorf( |
| 870 | "mibSync FSM - mandatory attribute OMCC version not present in Onu2G instance - handling of MibSyncChan stopped: %s", |
| 871 | oo.deviceID) |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 872 | } |
| 873 | oo.MutexPersOnuConfig.RLock() |
| 874 | if oo.SOnuPersistentData.PersIsExtOmciSupported { |
| 875 | oo.MutexPersOnuConfig.RUnlock() |
| 876 | // trigger test of OMCI extended msg format |
| 877 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvTestExtOmciSupport) |
| 878 | return nil |
| 879 | } |
| 880 | oo.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 881 | // trigger retrieval of 1st SW-image info |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 882 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetFirstSwVersion) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 883 | return nil |
| 884 | case "SoftwareImage": |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 885 | oo.mutexLastTxParamStruct.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 886 | if entityID > cmn.SecondSwImageMeID { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 887 | logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId", |
| 888 | log.Fields{"device-id": oo.deviceID, "entity-ID": entityID}) |
| 889 | return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x", |
| 890 | oo.deviceID, entityID) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 891 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 892 | // need to use function for go lint complexity |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 893 | if !oo.HandleSwImageIndications(ctx, entityID, meAttributes) { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 894 | logger.Errorw(ctx, |
| 895 | "MibSync FSM - Not all mandatory attributes present in in SoftwareImage instance - handling of MibSyncChan stopped!", |
| 896 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 897 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 898 | return fmt.Errorf( |
| 899 | "mibSync FSM - Not all mandatory attributes present in in SoftwareImage instance - handling of MibSyncChan stopped: %s", |
| 900 | oo.deviceID) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 901 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 902 | return nil |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 903 | case "IpHostConfigData": |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 904 | oo.mutexLastTxParamStruct.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 905 | oo.MutexPersOnuConfig.Lock() |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 906 | if ipHostConfigMacAddress, ok := meAttributes[me.IpHostConfigData_MacAddress]; ok { |
Girish Gowdra | 21bbf05 | 2022-02-17 16:08:22 -0800 | [diff] [blame] | 907 | macBytes, _ := me.InterfaceToOctets(ipHostConfigMacAddress) |
| 908 | if cmn.OmciMacAddressLen == len(macBytes) { |
| 909 | oo.SOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:]) |
| 910 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID, |
| 911 | "macAddress": oo.SOnuPersistentData.PersMacAddress}) |
| 912 | } else { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 913 | logger.Infow(ctx, "MibSync FSM - MacAddress wrong length - fill macAddress with zeros", |
| 914 | log.Fields{"device-id": oo.deviceID, "length": len(macBytes)}) |
Girish Gowdra | 21bbf05 | 2022-02-17 16:08:22 -0800 | [diff] [blame] | 915 | oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString |
| 916 | } |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 917 | } else { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 918 | // since ONU creates instances of this ME automatically only when IP host services are available, |
| 919 | // processing continues here despite the error |
| 920 | logger.Infow(ctx, "MibSync FSM - MacAddress attribute not present in IpHostConfigData instance - fill macAddress with zeros", |
| 921 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 922 | oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 923 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 924 | oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 925 | // trigger retrieval of mib template |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 926 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 927 | return nil |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 928 | case "OnuData": |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 929 | oo.mutexLastTxParamStruct.RUnlock() |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 930 | if onuDataMibDataSync, ok := meAttributes[me.OnuData_MibDataSync]; ok { |
| 931 | oo.checkMdsValue(ctx, onuDataMibDataSync.(uint8)) |
| 932 | } else { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 933 | logger.Errorw(ctx, "MibSync FSM - MibDataSync attribute not present in OnuData instance - handling of MibSyncChan stopped!", |
| 934 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 935 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 936 | return fmt.Errorf("mibSync FSM - VendorId attribute not present in OnuG instance - handling of MibSyncChan stopped: %s", |
| 937 | oo.deviceID) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 938 | } |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 939 | return nil |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 940 | default: |
| 941 | oo.mutexLastTxParamStruct.RUnlock() |
| 942 | logger.Warnw(ctx, "Unsupported ME name received!", |
| 943 | log.Fields{"ME name": meInstance, "device-id": oo.deviceID}) |
| 944 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 945 | } |
Matteo Scandolo | 20ca10c | 2021-01-21 14:35:45 -0800 | [diff] [blame] | 946 | } else { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 947 | oo.mutexLastTxParamStruct.RUnlock() |
| 948 | logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ", |
| 949 | log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 950 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 951 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 952 | if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil { |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 953 | return nil |
| 954 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 955 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 956 | logger.Info(ctx, "MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 957 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 958 | return err |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 959 | } |
| 960 | |
Holger Hildebrandt | 94688c7 | 2021-12-17 12:13:02 +0000 | [diff] [blame] | 961 | //HandleSwImageIndications updates onuSwImageIndications with the ONU data just received |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 962 | func (oo *OnuDeviceEntry) HandleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) bool { |
| 963 | |
| 964 | var imageVersion string |
| 965 | var imageIsCommitted, imageIsActive uint8 |
| 966 | |
| 967 | allMandAttribsPresent := false |
| 968 | if softwareImageIsCommitted, ok := meAttributes[me.SoftwareImage_IsCommitted]; ok { |
| 969 | if softwareImageIsActiveimage, ok := meAttributes[me.SoftwareImage_IsActive]; ok { |
| 970 | if softwareImageVersion, ok := meAttributes[me.SoftwareImage_Version]; ok { |
| 971 | imageVersion = cmn.TrimStringFromMeOctet(softwareImageVersion) |
| 972 | imageIsActive = softwareImageIsActiveimage.(uint8) |
| 973 | imageIsCommitted = softwareImageIsCommitted.(uint8) |
| 974 | allMandAttribsPresent = true |
| 975 | } |
| 976 | } |
| 977 | } |
| 978 | if !allMandAttribsPresent { |
| 979 | logger.Errorw(ctx, "MibSync FSM - Not all mandatory attributes present in SoftwareImage instance - skip processing!", log.Fields{"device-id": oo.deviceID}) |
| 980 | return allMandAttribsPresent |
| 981 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 982 | oo.MutexPersOnuConfig.RLock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 983 | logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage", |
| 984 | log.Fields{"device-id": oo.deviceID, "entityID": entityID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 985 | "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.SOnuPersistentData.PersSerialNumber}) |
| 986 | oo.MutexPersOnuConfig.RUnlock() |
| 987 | if cmn.FirstSwImageMeID == entityID { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 988 | //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] | 989 | oo.mutexOnuSwImageIndications.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 990 | if imageIsActive == cmn.SwIsActive { |
| 991 | oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID |
| 992 | oo.onuSwImageIndications.ActiveEntityEntry.Valid = true |
| 993 | oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion |
| 994 | oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 995 | //as the SW version indication may stem from some ONU Down/up event |
| 996 | //the complementary image state is to be invalidated |
| 997 | // (state of the second image is always expected afterwards or just invalid) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 998 | oo.onuSwImageIndications.InActiveEntityEntry.Valid = false |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 999 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1000 | oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID |
| 1001 | oo.onuSwImageIndications.InActiveEntityEntry.Valid = true |
| 1002 | oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion |
| 1003 | oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 1004 | //as the SW version indication may stem form some ONU Down/up event |
| 1005 | //the complementary image state is to be invalidated |
| 1006 | // (state of the second image is always expected afterwards or just invalid) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1007 | oo.onuSwImageIndications.ActiveEntityEntry.Valid = false |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1008 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1009 | oo.mutexOnuSwImageIndications.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1010 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetSecondSwVersion) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 1011 | return allMandAttribsPresent |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1012 | } else if cmn.SecondSwImageMeID == entityID { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1013 | //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] | 1014 | oo.mutexOnuSwImageIndications.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1015 | if imageIsActive == cmn.SwIsActive { //2nd image reported to be active |
| 1016 | if oo.onuSwImageIndications.ActiveEntityEntry.Valid { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1017 | //conflict exists - state of first image is left active |
| 1018 | logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive", |
| 1019 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1020 | oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID |
| 1021 | oo.onuSwImageIndications.InActiveEntityEntry.Valid = true ////to indicate that at least something has been reported |
| 1022 | oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion |
| 1023 | oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1024 | } else { //first image inactive, this one active |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1025 | oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID |
| 1026 | oo.onuSwImageIndications.ActiveEntityEntry.Valid = true |
| 1027 | oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion |
| 1028 | oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1029 | } |
| 1030 | } else { //2nd image reported to be inactive |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1031 | if oo.onuSwImageIndications.InActiveEntityEntry.Valid { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1032 | //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active |
| 1033 | logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active", |
| 1034 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1035 | oo.onuSwImageIndications.ActiveEntityEntry.EntityID = cmn.FirstSwImageMeID |
| 1036 | oo.onuSwImageIndications.ActiveEntityEntry.Valid = true //to indicate that at least something has been reported |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1037 | //copy active commit/version from the previously stored inactive position |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1038 | oo.onuSwImageIndications.ActiveEntityEntry.Version = oo.onuSwImageIndications.InActiveEntityEntry.Version |
| 1039 | oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1040 | } |
| 1041 | //in any case we indicate (and possibly overwrite) the second image indications as inactive |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1042 | oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID |
| 1043 | oo.onuSwImageIndications.InActiveEntityEntry.Valid = true |
| 1044 | oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion |
| 1045 | oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1046 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1047 | oo.mutexOnuSwImageIndications.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1048 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMacAddress) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1049 | } |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 1050 | return allMandAttribsPresent |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1053 | func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg cmn.OmciMessage) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1054 | 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] | 1055 | "msgType": msg.OmciMsg.MessageType, "msg": msg}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1056 | //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ... |
| 1057 | switch msg.OmciMsg.MessageType { |
| 1058 | case omci.MibResetResponseType: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1059 | oo.handleOmciMibResetResponseMessage(ctx, msg) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 1060 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1061 | case omci.MibUploadResponseType: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1062 | oo.handleOmciMibUploadResponseMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1063 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1064 | case omci.MibUploadNextResponseType: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1065 | oo.handleOmciMibUploadNextResponseMessage(ctx, msg) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1066 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 1067 | case omci.GetResponseType: |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 1068 | //TODO: error handling |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1069 | _ = oo.handleOmciGetResponseMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1070 | |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 1071 | default: |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 1072 | logger.Warnw(ctx, "Unknown Message Type", log.Fields{"device-id": oo.deviceID, "msgType": msg.OmciMsg.MessageType}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 1073 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1074 | } |
| 1075 | } |
| 1076 | |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 1077 | func (oo *OnuDeviceEntry) handleOmciGetResponseOnuG(ctx context.Context, meAttributes me.AttributeValueMap) error { |
| 1078 | currentState := oo.PMibUploadFsm.PFsm.Current() |
| 1079 | if currentState == UlStGettingVendorAndSerial { |
| 1080 | if onuGVendorID, ok := meAttributes[me.OnuG_VendorId]; ok { |
| 1081 | vendorID := cmn.TrimStringFromMeOctet(onuGVendorID) |
| 1082 | if vendorID == "" { |
| 1083 | logger.Infow(ctx, |
| 1084 | "MibSync FSM - mandatory attribute VendorId is empty in OnuG instance - fill with appropriate value", |
| 1085 | log.Fields{"device-id": oo.deviceID}) |
| 1086 | vendorID = cEmptyVendorIDString |
| 1087 | } |
| 1088 | oo.MutexPersOnuConfig.Lock() |
| 1089 | oo.SOnuPersistentData.PersVendorID = vendorID |
| 1090 | oo.MutexPersOnuConfig.Unlock() |
| 1091 | } else { |
| 1092 | logger.Errorw(ctx, |
| 1093 | "MibSync FSM - mandatory attribute VendorId not present in OnuG instance - handling of MibSyncChan stopped!", |
| 1094 | log.Fields{"device-id": oo.deviceID}) |
| 1095 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
| 1096 | return fmt.Errorf( |
| 1097 | "mibSync FSM - mandatory attribute VendorId not present in OnuG instance - handling of MibSyncChan stopped: %s", |
| 1098 | oo.deviceID) |
| 1099 | } |
| 1100 | if onuGSerialNumber, ok := meAttributes[me.OnuG_SerialNumber]; ok { |
| 1101 | oo.MutexPersOnuConfig.Lock() |
| 1102 | snBytes, _ := me.InterfaceToOctets(onuGSerialNumber) |
| 1103 | if cmn.OnugSerialNumberLen == len(snBytes) { |
| 1104 | snVendorPart := fmt.Sprintf("%s", snBytes[:4]) |
| 1105 | snNumberPart := hex.EncodeToString(snBytes[4:]) |
| 1106 | oo.SOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart |
| 1107 | } else { |
| 1108 | logger.Infow(ctx, "MibSync FSM - SerialNumber has wrong length - fill serialNumber with zeros", |
| 1109 | log.Fields{"device-id": oo.deviceID, "length": len(snBytes)}) |
| 1110 | oo.SOnuPersistentData.PersSerialNumber = cEmptySerialNumberString |
| 1111 | } |
| 1112 | oo.MutexPersOnuConfig.Unlock() |
| 1113 | } else { |
| 1114 | logger.Errorw(ctx, |
| 1115 | "MibSync FSM - mandatory attribute SerialNumber not present in OnuG instance - handling of MibSyncChan stopped!", |
| 1116 | log.Fields{"device-id": oo.deviceID}) |
| 1117 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
| 1118 | return fmt.Errorf( |
| 1119 | "mibSync FSM - mandatory attribute SerialNumber not present in OnuG instance - handling of MibSyncChan stopped: %s", |
| 1120 | oo.deviceID) |
| 1121 | } |
| 1122 | oo.MutexPersOnuConfig.Lock() |
| 1123 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-G - VendorId/SerialNumber", log.Fields{"device-id": oo.deviceID, |
| 1124 | "onuDeviceEntry.vendorID": oo.SOnuPersistentData.PersVendorID, |
| 1125 | "onuDeviceEntry.serialNumber": oo.SOnuPersistentData.PersSerialNumber}) |
| 1126 | oo.MutexPersOnuConfig.Unlock() |
| 1127 | // trigger retrieval of Version |
| 1128 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetVersion) |
| 1129 | return nil |
| 1130 | } else if currentState == UlStGettingVersion { |
| 1131 | if onuGVersion, ok := meAttributes[me.OnuG_Version]; ok { |
| 1132 | version := cmn.TrimStringFromMeOctet(onuGVersion) |
| 1133 | if version == "" { |
| 1134 | logger.Infow(ctx, "MibSync FSM - mandatory attribute Version is empty in OnuG instance - fill with appropriate value", |
| 1135 | log.Fields{"device-id": oo.deviceID}) |
| 1136 | version = cEmptyVersionString |
| 1137 | } |
| 1138 | oo.MutexPersOnuConfig.Lock() |
| 1139 | oo.SOnuPersistentData.PersVersion = version |
| 1140 | oo.MutexPersOnuConfig.Unlock() |
| 1141 | } else { |
| 1142 | logger.Errorw(ctx, |
| 1143 | "MibSync FSM - mandatory attribute Version not present in OnuG instance - handling of MibSyncChan stopped!", |
| 1144 | log.Fields{"device-id": oo.deviceID}) |
| 1145 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
| 1146 | return fmt.Errorf( |
| 1147 | "mibSync FSM - mandatory attribute Version not present in OnuG instance - handling of MibSyncChan stopped: %s", |
| 1148 | oo.deviceID) |
| 1149 | } |
| 1150 | oo.MutexPersOnuConfig.Lock() |
| 1151 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-G - Version", log.Fields{"device-id": oo.deviceID, |
| 1152 | "onuDeviceEntry.version": oo.SOnuPersistentData.PersVersion}) |
| 1153 | oo.MutexPersOnuConfig.Unlock() |
| 1154 | // trigger retrieval of EquipmentId and OMCC version |
| 1155 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetEquipIDAndOmcc) |
| 1156 | return nil |
| 1157 | } else { |
| 1158 | logger.Errorw(ctx, "MibSync FSM - wrong state OnuG response processing - handling of MibSyncChan stopped!", |
| 1159 | log.Fields{"currentState": currentState, "device-id": oo.deviceID}) |
| 1160 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
| 1161 | return fmt.Errorf("mibSync FSM - wrong state OnuG response processing - handling of MibSyncChan stopped: %s", |
| 1162 | oo.deviceID) |
| 1163 | } |
| 1164 | } |
| 1165 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1166 | func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error { |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 1167 | var err error = nil |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1168 | 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] | 1169 | // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME |
| 1170 | 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] | 1171 | oo.mutexLastTxParamStruct.RLock() |
| 1172 | if oo.lastTxParamStruct.pLastTxMeInstance != nil { |
| 1173 | entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID() |
| 1174 | if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID { |
| 1175 | meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName() |
| 1176 | switch meInstance { |
| 1177 | case "IpHostConfigData": |
| 1178 | oo.mutexLastTxParamStruct.RUnlock() |
| 1179 | logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros", |
| 1180 | log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1181 | oo.MutexPersOnuConfig.Lock() |
| 1182 | oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString |
| 1183 | oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1184 | // trigger retrieval of mib template |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1185 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1186 | return nil |
| 1187 | default: |
| 1188 | oo.mutexLastTxParamStruct.RUnlock() |
| 1189 | logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance) |
| 1190 | err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID) |
| 1191 | } |
| 1192 | } else { |
| 1193 | oo.mutexLastTxParamStruct.RUnlock() |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 1194 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1195 | } else { |
| 1196 | oo.mutexLastTxParamStruct.RUnlock() |
| 1197 | 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] | 1198 | } |
| 1199 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1200 | 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] | 1201 | err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID) |
| 1202 | } |
| 1203 | return err |
| 1204 | } |
| 1205 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1206 | // IsNewOnu - TODO: add comment |
| 1207 | func (oo *OnuDeviceEntry) IsNewOnu() bool { |
| 1208 | oo.MutexPersOnuConfig.RLock() |
| 1209 | defer oo.MutexPersOnuConfig.RUnlock() |
| 1210 | return oo.SOnuPersistentData.PersMibLastDbSync == 0 |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1213 | func isSupportedClassID(meClassID me.ClassID) bool { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1214 | for _, v := range supportedClassIds { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1215 | if v == meClassID { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1216 | return true |
| 1217 | } |
| 1218 | } |
| 1219 | return false |
| 1220 | } |
| 1221 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1222 | func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error { |
| 1223 | logger.Debug(ctx, "MibVolatileDict- running from default Entry code") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1224 | return errors.New("not_implemented") |
| 1225 | } |
| 1226 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1227 | // 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] | 1228 | // 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] | 1229 | // 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] | 1230 | func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error { |
| 1231 | logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath, |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 1232 | "device-id": oo.deviceID}) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1233 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1234 | oo.pOpenOnuAc.LockMutexMibTemplateGenerated() |
| 1235 | if mibTemplateIsGenerated, exist := oo.pOpenOnuAc.GetMibTemplatesGenerated(oo.mibTemplatePath); exist { |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 1236 | if mibTemplateIsGenerated { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1237 | 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] | 1238 | log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1239 | oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated() |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 1240 | return nil |
| 1241 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1242 | 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] | 1243 | log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
| 1244 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1245 | 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] | 1246 | log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
| 1247 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1248 | oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, true) |
| 1249 | oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated() |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 1250 | |
| 1251 | currentTime := time.Now() |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1252 | templateMap := make(map[string]interface{}) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 1253 | templateMap["TemplateName"] = oo.mibTemplatePath |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1254 | templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000") |
| 1255 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1256 | firstLevelMap := oo.pOnuDB.MeDb |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1257 | for firstLevelKey, firstLevelValue := range firstLevelMap { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1258 | logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1259 | classID := strconv.Itoa(int(firstLevelKey)) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1260 | |
| 1261 | secondLevelMap := make(map[string]interface{}) |
| 1262 | for secondLevelKey, secondLevelValue := range firstLevelValue { |
Holger Hildebrandt | 8998ed5 | 2022-03-23 09:52:37 +0000 | [diff] [blame] | 1263 | // ManagedEntityId is already key of secondLevelMap - remove this redundant attribute from secondLevelValue |
| 1264 | delete(secondLevelValue, cmn.CGenericManagedEntityIDName) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1265 | thirdLevelMap := make(map[string]interface{}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1266 | entityID := strconv.Itoa(int(secondLevelKey)) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1267 | thirdLevelMap["Attributes"] = secondLevelValue |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1268 | secondLevelMap[entityID] = thirdLevelMap |
| 1269 | if classID == "6" || classID == "256" { |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1270 | forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap)) |
| 1271 | delete(forthLevelMap, "SerialNumber") |
| 1272 | forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%" |
| 1273 | |
| 1274 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1275 | if classID == "134" { |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1276 | forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap)) |
| 1277 | delete(forthLevelMap, "MacAddress") |
| 1278 | forthLevelMap["MacAddress"] = "%MAC_ADDRESS%" |
| 1279 | } |
| 1280 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1281 | templateMap[classID] = secondLevelMap |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1282 | } |
Holger Hildebrandt | 3908002 | 2022-03-16 10:03:17 +0000 | [diff] [blame] | 1283 | unknownMeAndAttribMap := oo.pOnuDB.UnknownMeAndAttribDb |
| 1284 | for unknownMeAndAttribMapKey := range unknownMeAndAttribMap { |
| 1285 | templateMap[string(unknownMeAndAttribMapKey)] = unknownMeAndAttribMap[unknownMeAndAttribMapKey] |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 1286 | } |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1287 | mibTemplate, err := json.Marshal(&templateMap) |
| 1288 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1289 | logger.Errorw(ctx, "MibSync - MibTemplate - Failed to marshal mibTemplate", log.Fields{"error": err, "device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1290 | oo.pOpenOnuAc.LockMutexMibTemplateGenerated() |
| 1291 | oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false) |
| 1292 | oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated() |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1293 | return err |
| 1294 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1295 | err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate)) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1296 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1297 | logger.Errorw(ctx, "MibSync - MibTemplate - Failed to store template in etcd", log.Fields{"error": err, "device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1298 | oo.pOpenOnuAc.LockMutexMibTemplateGenerated() |
| 1299 | oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false) |
| 1300 | oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated() |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1301 | return err |
| 1302 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1303 | 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] | 1304 | return nil |
| 1305 | } |
| 1306 | |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 1307 | func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) { |
| 1308 | logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 1309 | requestedAttributes := me.AttributeValueMap{me.OnuData_MibDataSync: ""} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1310 | meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 1311 | me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, |
| 1312 | oo.PMibUploadFsm.CommChan, oo.GetPersIsExtOmciSupported()) |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 1313 | //accept also nil as (error) return value for writing to LastTx |
| 1314 | // - this avoids misinterpretation of new received OMCI messages |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1315 | if err != nil { |
| 1316 | logger.Errorw(ctx, "ONUData get failed, aborting MibSync FSM!", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1317 | pMibUlFsm := oo.PMibUploadFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1318 | if pMibUlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1319 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1320 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1321 | }(pMibUlFsm) |
| 1322 | } |
| 1323 | return |
| 1324 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1325 | oo.mutexLastTxParamStruct.Lock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 1326 | oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType |
| 1327 | oo.lastTxParamStruct.pLastTxMeInstance = meInstance |
| 1328 | oo.lastTxParamStruct.repeatCount = 0 |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1329 | oo.mutexLastTxParamStruct.Unlock() |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1332 | func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1333 | oo.MutexPersOnuConfig.RLock() |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1334 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-Data - MibDataSync", log.Fields{"device-id": oo.deviceID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1335 | "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.SOnuPersistentData.PersMibDataSyncAdpt}) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1336 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1337 | mdsValuesAreEqual := oo.SOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu |
| 1338 | oo.MutexPersOnuConfig.RUnlock() |
| 1339 | if oo.PMibUploadFsm.PFsm.Is(UlStAuditing) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1340 | if mdsValuesAreEqual { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1341 | logger.Debugw(ctx, "MibSync FSM - mib audit - MDS check ok", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1342 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1343 | } else { |
| 1344 | logger.Warnw(ctx, "MibSync FSM - mib audit - MDS check failed for the first time!", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1345 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1346 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1347 | } else if oo.PMibUploadFsm.PFsm.Is(UlStReAuditing) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1348 | if mdsValuesAreEqual { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1349 | logger.Debugw(ctx, "MibSync FSM - mib reaudit - MDS check ok", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1350 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1351 | } else { |
Holger Hildebrandt | 80f5776 | 2022-02-16 10:03:24 +0000 | [diff] [blame] | 1352 | logger.Errorw(ctx, "MibSync FSM - mib reaudit - MDS check failed for the second time - send ONU device event and reconcile!", |
Holger Hildebrandt | c56febd | 2022-02-09 13:23:30 +0000 | [diff] [blame] | 1353 | log.Fields{"device-id": oo.deviceID}) |
| 1354 | oo.SendOnuDeviceEvent(ctx, cmn.OnuMibAuditFailureMds, cmn.OnuMibAuditFailureMdsDesc) |
Holger Hildebrandt | 80f5776 | 2022-02-16 10:03:24 +0000 | [diff] [blame] | 1355 | // To reconcile ONU with active adapter later on, we have to retrieve TP instances from parent adapter. |
| 1356 | // In the present use case inconsistencies between TP pathes stored in kv store and TP instances retrieved |
| 1357 | // should not occur. Nevertheless, the respective code is inserted to catch the unlikely case. |
| 1358 | if !oo.getAllStoredTpInstFromParentAdapter(ctx) { |
| 1359 | logger.Debugw(ctx, "MibSync FSM - mib reaudit - inconsistencies between TP pathes stored in kv and parent adapter instances", |
| 1360 | log.Fields{"device-id": oo.deviceID}) |
| 1361 | oo.baseDeviceHandler.SetReconcilingReasonUpdate(true) |
| 1362 | go func() { |
| 1363 | if err := oo.baseDeviceHandler.StorePersistentData(ctx); err != nil { |
| 1364 | logger.Warnw(ctx, |
| 1365 | "MibSync FSM - mib reaudit - store persistent data error - continue for now as there will be additional write attempts", |
| 1366 | log.Fields{"device-id": oo.deviceID, "err": err}) |
| 1367 | } |
| 1368 | }() |
| 1369 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1370 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1371 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1372 | } else if oo.PMibUploadFsm.PFsm.Is(UlStExaminingMds) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1373 | if mdsValuesAreEqual && mibDataSyncOnu != 0 { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1374 | logger.Debugw(ctx, "MibSync FSM - MDS examination ok", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1375 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1376 | } else { |
| 1377 | logger.Debugw(ctx, "MibSync FSM - MDS examination failed - new provisioning", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1378 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1379 | } |
| 1380 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1381 | logger.Warnw(ctx, "wrong state for MDS evaluation!", log.Fields{"state": oo.PMibUploadFsm.PFsm.Current(), "device-id": oo.deviceID}) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1382 | } |
| 1383 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1384 | |
| 1385 | //GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity |
| 1386 | func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1387 | oo.mutexOnuSwImageIndications.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1388 | if oo.onuSwImageIndications.ActiveEntityEntry.Valid { |
| 1389 | value := oo.onuSwImageIndications.ActiveEntityEntry.EntityID |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1390 | oo.mutexOnuSwImageIndications.RUnlock() |
| 1391 | return value, nil |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1392 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1393 | oo.mutexOnuSwImageIndications.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1394 | return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID) |
| 1395 | } |
| 1396 | |
| 1397 | //GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity |
| 1398 | func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1399 | oo.mutexOnuSwImageIndications.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1400 | if oo.onuSwImageIndications.InActiveEntityEntry.Valid { |
| 1401 | value := oo.onuSwImageIndications.InActiveEntityEntry.EntityID |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1402 | oo.mutexOnuSwImageIndications.RUnlock() |
| 1403 | return value, nil |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1404 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1405 | oo.mutexOnuSwImageIndications.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1406 | return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID) |
| 1407 | } |
| 1408 | |
| 1409 | //IsImageToBeCommitted returns true if the active image is still uncommitted |
| 1410 | func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1411 | oo.mutexOnuSwImageIndications.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1412 | if oo.onuSwImageIndications.ActiveEntityEntry.Valid { |
| 1413 | if oo.onuSwImageIndications.ActiveEntityEntry.EntityID == aImageID { |
| 1414 | if oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted == cmn.SwIsUncommitted { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1415 | oo.mutexOnuSwImageIndications.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1416 | return true |
| 1417 | } |
| 1418 | } |
| 1419 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1420 | oo.mutexOnuSwImageIndications.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1421 | return false //all other case are treated as 'nothing to commit |
| 1422 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1423 | func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool { |
| 1424 | |
| 1425 | oo.mibTemplatePath = oo.buildMibTemplatePath() |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 1426 | logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath), |
| 1427 | "device-id": oo.deviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1428 | |
| 1429 | restoredFromMibTemplate := false |
| 1430 | Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath) |
| 1431 | if err == nil { |
| 1432 | if Value != nil { |
| 1433 | logger.Debugf(ctx, "MibSync FSM - Mib template read: Key: %s, Value: %s %s", Value.Key, Value.Value) |
| 1434 | |
| 1435 | // swap out tokens with specific data |
| 1436 | mibTmpString, _ := kvstore.ToString(Value.Value) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1437 | oo.MutexPersOnuConfig.RLock() |
| 1438 | mibTmpString2 := strings.Replace(mibTmpString, "%SERIAL_NUMBER%", oo.SOnuPersistentData.PersSerialNumber, -1) |
| 1439 | mibTmpString = strings.Replace(mibTmpString2, "%MAC_ADDRESS%", oo.SOnuPersistentData.PersMacAddress, -1) |
| 1440 | oo.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1441 | mibTmpBytes := []byte(mibTmpString) |
| 1442 | logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes) |
| 1443 | |
| 1444 | var firstLevelMap map[string]interface{} |
| 1445 | if err = json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil { |
| 1446 | logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID}) |
| 1447 | } else { |
| 1448 | for firstLevelKey, firstLevelValue := range firstLevelMap { |
| 1449 | //logger.Debugw(ctx, "MibSync FSM - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey}) |
| 1450 | if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil { |
| 1451 | meClassID := me.ClassID(uint16ValidNumber) |
| 1452 | //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a number in uint16-range", log.Fields{"uint16ValidNumber": uint16ValidNumber}) |
| 1453 | if isSupportedClassID(meClassID) { |
| 1454 | //logger.Debugw(ctx, "MibSync FSM - firstLevelKey is a supported classID", log.Fields{"meClassID": meClassID}) |
| 1455 | secondLevelMap := firstLevelValue.(map[string]interface{}) |
| 1456 | for secondLevelKey, secondLevelValue := range secondLevelMap { |
| 1457 | //logger.Debugw(ctx, "MibSync FSM - secondLevelKey", log.Fields{"secondLevelKey": secondLevelKey}) |
| 1458 | if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil { |
| 1459 | meEntityID := uint16(uint16ValidNumber) |
| 1460 | //logger.Debugw(ctx, "MibSync FSM - secondLevelKey is a number and a valid EntityId", log.Fields{"meEntityID": meEntityID}) |
| 1461 | thirdLevelMap := secondLevelValue.(map[string]interface{}) |
| 1462 | for thirdLevelKey, thirdLevelValue := range thirdLevelMap { |
| 1463 | if thirdLevelKey == "Attributes" { |
| 1464 | //logger.Debugw(ctx, "MibSync FSM - thirdLevelKey refers to attributes", log.Fields{"thirdLevelKey": thirdLevelKey}) |
| 1465 | attributesMap := thirdLevelValue.(map[string]interface{}) |
| 1466 | //logger.Debugw(ctx, "MibSync FSM - attributesMap", log.Fields{"attributesMap": attributesMap}) |
| 1467 | oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributesMap) |
| 1468 | restoredFromMibTemplate = true |
| 1469 | } |
| 1470 | } |
| 1471 | } |
| 1472 | } |
| 1473 | } |
| 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | } else { |
| 1478 | logger.Debugw(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
| 1479 | } |
| 1480 | } else { |
| 1481 | logger.Errorf(ctx, "Get from kvstore operation failed for path", |
| 1482 | log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
| 1483 | } |
| 1484 | return restoredFromMibTemplate |
| 1485 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 1486 | |
Holger Hildebrandt | 80f5776 | 2022-02-16 10:03:24 +0000 | [diff] [blame] | 1487 | func (oo *OnuDeviceEntry) getAllStoredTpInstFromParentAdapter(ctx context.Context) bool { |
| 1488 | |
| 1489 | allTpInstPresent := true |
| 1490 | oo.MutexPersOnuConfig.Lock() |
| 1491 | oo.MutexReconciledTpInstances.Lock() |
| 1492 | for indexUni, uniData := range oo.SOnuPersistentData.PersUniConfig { |
| 1493 | uniID := uniData.PersUniID |
| 1494 | oo.ReconciledTpInstances[uniID] = make(map[uint8]inter_adapter.TechProfileDownloadMessage) |
| 1495 | for tpID, tpPath := range uniData.PersTpPathMap { |
| 1496 | if tpPath != "" { |
| 1497 | // Request the TP instance from the openolt adapter |
| 1498 | iaTechTpInst, err := oo.baseDeviceHandler.GetTechProfileInstanceFromParentAdapter(ctx, uniID, tpPath) |
| 1499 | if err == nil && iaTechTpInst != nil { |
| 1500 | logger.Debugw(ctx, "reconciling - store Tp instance", log.Fields{"uniID": uniID, "tpID": tpID, |
| 1501 | "*iaTechTpInst": iaTechTpInst, "device-id": oo.deviceID}) |
| 1502 | oo.ReconciledTpInstances[uniID][tpID] = *iaTechTpInst |
| 1503 | } else { |
| 1504 | // During the absence of the ONU adapter there seem to have been TP specific configurations! |
| 1505 | // The no longer available TP and the associated flows must be deleted from the ONU KV store |
| 1506 | // and after a MIB reset a new reconciling attempt with OMCI configuration must be started. |
| 1507 | allTpInstPresent = false |
| 1508 | logger.Infow(ctx, "reconciling - can't get tp instance - delete tp and associated flows", |
| 1509 | log.Fields{"tp-id": tpID, "tpPath": tpPath, "uni-id": uniID, "device-id": oo.deviceID, "err": err}) |
| 1510 | delete(oo.SOnuPersistentData.PersUniConfig[indexUni].PersTpPathMap, tpID) |
| 1511 | flowSlice := oo.SOnuPersistentData.PersUniConfig[indexUni].PersFlowParams |
| 1512 | for indexFlow, flowData := range flowSlice { |
| 1513 | if flowData.VlanRuleParams.TpID == tpID { |
| 1514 | if len(flowSlice) == 1 { |
| 1515 | flowSlice = []cmn.UniVlanFlowParams{} |
| 1516 | } else { |
| 1517 | flowSlice = append(flowSlice[:indexFlow], flowSlice[indexFlow+1:]...) |
| 1518 | } |
| 1519 | oo.SOnuPersistentData.PersUniConfig[indexUni].PersFlowParams = flowSlice |
| 1520 | } |
| 1521 | } |
| 1522 | } |
| 1523 | } |
| 1524 | } |
| 1525 | } |
| 1526 | oo.MutexReconciledTpInstances.Unlock() |
| 1527 | oo.MutexPersOnuConfig.Unlock() |
| 1528 | return allTpInstPresent |
| 1529 | } |
| 1530 | |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 1531 | //CancelProcessing terminates potentially running reconciling processes and stops the FSM |
| 1532 | func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) { |
Holger Hildebrandt | 12609a1 | 2022-03-25 13:23:25 +0000 | [diff] [blame] | 1533 | logger.Debugw(ctx, "CancelProcessing entered", log.Fields{"device-id": oo.deviceID}) |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1534 | if oo.isReconcilingFlows() { |
Holger Hildebrandt | f2fcdd4 | 2021-12-15 11:42:19 +0000 | [diff] [blame] | 1535 | oo.SendChReconcilingFlowsFinished(ctx, false) |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 1536 | } |
| 1537 | //the MibSync FSM might be active all the ONU-active time, |
| 1538 | // hence it must be stopped unconditionally |
Girish Gowdra | 37c9d91 | 2022-02-08 16:24:57 -0800 | [diff] [blame] | 1539 | oo.mutexMibSyncMsgProcessorRunning.RLock() |
| 1540 | defer oo.mutexMibSyncMsgProcessorRunning.RUnlock() |
| 1541 | if oo.mibSyncMsgProcessorRunning { |
| 1542 | pMibUlFsm := oo.PMibUploadFsm |
| 1543 | if pMibUlFsm != nil { |
| 1544 | // abort running message processing |
| 1545 | fsmAbortMsg := cmn.Message{ |
| 1546 | Type: cmn.TestMsg, |
| 1547 | Data: cmn.TestMessage{ |
| 1548 | TestMessageVal: cmn.AbortMessageProcessing, |
| 1549 | }, |
| 1550 | } |
| 1551 | pMibUlFsm.CommChan <- fsmAbortMsg |
| 1552 | _ = pMibUlFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 1553 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 1554 | } |
| 1555 | } |