Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1 | /* |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 2 | * Copyright 2020-2024 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 | |
nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 17 | // Package mib provides the utilities for managing the onu mib |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 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 | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 309 | |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 310 | //create the MIB Template path |
| 311 | oo.mibTemplatePath = oo.buildMibTemplatePath() |
| 312 | |
| 313 | if cmnMEDBVal, exist := oo.pOpenOnuAc.FetchEntryFromMibDatabaseMap(ctx, oo.mibTemplatePath); exist { |
| 314 | logger.Infow(ctx, "A Common MIB DB Instance exist for this type of ONT", log.Fields{"device-id": oo.deviceID, "mibTemplatePath": oo.mibTemplatePath}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 315 | oo.pOpenOnuAc.LockMutexMibTemplateGenerated() |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 316 | oo.pOnuDB.CommonMeDb = cmnMEDBVal |
| 317 | |
| 318 | if cmnMEDBVal.MIBUploadStatus == devdb.Completed { |
| 319 | oo.pOnuDB.CommonMeDb.MeDbLock.Lock() |
| 320 | oo.updateOnuSpecificEntries(ctx) |
| 321 | oo.pOnuDB.CommonMeDb.MeDbLock.Unlock() |
| 322 | fsmMsg = cmn.LoadMibTemplateOk |
| 323 | } else { |
| 324 | logger.Errorw(ctx, "A previous MIB Upload for this type of ONT has failed, request for a MIB UPload", log.Fields{"device-id": oo.deviceID}) |
| 325 | oo.pOpenOnuAc.ResetEntryFromMibDatabaseMap(ctx, oo.mibTemplatePath) |
| 326 | fsmMsg = cmn.LoadMibTemplateFailed |
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 | oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated() |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 329 | |
| 330 | } else { |
| 331 | Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath) |
| 332 | if err == nil && Value != nil { |
| 333 | logger.Infow(ctx, "No Common MIB DB instance exist , creating from Template", log.Fields{"device-id": oo.deviceID, "mibTemplatePath": oo.mibTemplatePath}) |
| 334 | oo.processMibTemplate(ctx, Value) |
| 335 | } else { |
| 336 | logger.Infow(ctx, "Neither Common MIB DB Instance nor MIB template exist for this type of ONT", log.Fields{"device-id": oo.deviceID, "mibTemplatePath": oo.mibTemplatePath}) |
| 337 | oo.pOpenOnuAc.LockMutexMibTemplateGenerated() |
| 338 | cmnMEDBValue, _ := oo.pOpenOnuAc.CreateEntryAtMibDatabaseMap(ctx, oo.mibTemplatePath) |
| 339 | oo.pOnuDB.CommonMeDb = cmnMEDBValue |
| 340 | oo.pOnuDB.CommonMeDb.MeDbLock.Lock() |
| 341 | fsmMsg = cmn.LoadMibTemplateFailed |
| 342 | |
| 343 | } |
| 344 | |
Holger Hildebrandt | 441a017 | 2020-12-10 13:57:08 +0000 | [diff] [blame] | 345 | } |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 346 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 347 | mibSyncMsg := cmn.Message{ |
| 348 | Type: cmn.TestMsg, |
| 349 | Data: cmn.TestMessage{ |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 350 | TestMessageVal: fsmMsg, |
| 351 | }, |
| 352 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 353 | oo.PMibUploadFsm.CommChan <- mibSyncMsg |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 354 | } |
| 355 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 356 | func (oo *OnuDeviceEntry) enterUploadingState(ctx context.Context, e *fsm.Event) { |
| 357 | 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] | 358 | _ = oo.PDevOmciCC.SendMibUpload(log.WithSpanFromContext(context.TODO(), ctx), |
| 359 | oo.baseDeviceHandler.GetOmciTimeout(), true, oo.GetPersIsExtOmciSupported()) |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 360 | //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure |
| 361 | // that the lastTxMessageType is correctly set to avoid misinterpreting other responses |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 362 | oo.mutexLastTxParamStruct.Lock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 363 | oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadRequestType |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 364 | oo.mutexLastTxParamStruct.Unlock() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 367 | func (oo *OnuDeviceEntry) enterUploadDoneState(ctx context.Context, e *fsm.Event) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 368 | 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] | 369 | oo.transferSystemEvent(ctx, cmn.MibDatabaseSync) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 370 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 371 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 372 | }() |
| 373 | } |
| 374 | |
| 375 | func (oo *OnuDeviceEntry) enterInSyncState(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 376 | oo.MutexPersOnuConfig.Lock() |
| 377 | oo.SOnuPersistentData.PersMibLastDbSync = uint32(time.Now().Unix()) |
| 378 | oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 379 | if oo.mibAuditInterval > 0 { |
| 380 | 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] | 381 | go func() { |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 382 | time.Sleep(oo.mibAuditInterval) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 383 | if err := oo.PMibUploadFsm.PFsm.Event(UlEvAuditMib); err != nil { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 384 | logger.Debugw(ctx, "MibSyncFsm: Can't go to state auditing", log.Fields{"device-id": oo.deviceID, "err": err}) |
| 385 | } |
| 386 | }() |
| 387 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 390 | func (oo *OnuDeviceEntry) enterVerifyingAndStoringTPsState(ctx context.Context, e *fsm.Event) { |
| 391 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start verifying and storing TPs in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 392 | |
Holger Hildebrandt | 80f5776 | 2022-02-16 10:03:24 +0000 | [diff] [blame] | 393 | if oo.getAllStoredTpInstFromParentAdapter(ctx) { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 394 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"reconciling - verifying TPs successful": e.FSM.Current(), "device-id": oo.deviceID}) |
| 395 | go func() { |
| 396 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
| 397 | }() |
| 398 | } else { |
| 399 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"reconciling - verifying TPs not successful": e.FSM.Current(), "device-id": oo.deviceID}) |
| 400 | oo.baseDeviceHandler.SetReconcilingReasonUpdate(true) |
| 401 | go func() { |
| 402 | if err := oo.baseDeviceHandler.StorePersistentData(ctx); err != nil { |
| 403 | logger.Warnw(ctx, "reconciling - store persistent data error - continue for now as there will be additional write attempts", |
| 404 | log.Fields{"device-id": oo.deviceID, "err": err}) |
| 405 | } |
| 406 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch) |
| 407 | }() |
| 408 | } |
| 409 | } |
| 410 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 411 | func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) { |
| 412 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start GetMds processing in State": e.FSM.Current(), "device-id": oo.deviceID}) |
Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 413 | oo.pOpenOnuAc.RLockMutexDeviceHandlersMap() |
| 414 | dh, _ := oo.pOpenOnuAc.GetDeviceHandler(oo.deviceID) |
| 415 | oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap() |
| 416 | if dh.GetSkipOnuConfigEnabled() { |
| 417 | go func() { |
| 418 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
| 419 | }() |
| 420 | } else { |
| 421 | oo.requestMdsValue(ctx) |
| 422 | } |
| 423 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 424 | } |
| 425 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 426 | func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) { |
| 427 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 428 | logger.Debug(ctx, "function not implemented yet") |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 429 | // TODOs: |
| 430 | // VOL-3805 - Provide exclusive OMCI channel for one FSM |
| 431 | // VOL-3785 - New event notifications and corresponding performance counters for openonu-adapter-go |
| 432 | // VOL-3792 - Support periodical audit via mib resync |
| 433 | // VOL-3793 - ONU-reconcile handling after adapter restart based on mib resync |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 436 | func (oo *OnuDeviceEntry) enterExaminingMdsSuccessState(ctx context.Context, e *fsm.Event) { |
| 437 | logger.Debugw(ctx, "MibSync FSM", |
| 438 | log.Fields{"Start processing on examining MDS success in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 439 | |
| 440 | if oo.getMibFromTemplate(ctx) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 441 | oo.baseDeviceHandler.StartReconciling(ctx, true) |
| 442 | oo.baseDeviceHandler.AddAllUniPorts(ctx) |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 443 | _ = oo.baseDeviceHandler.ReasonUpdate(ctx, cmn.DrInitialMibDownloaded, oo.baseDeviceHandler.IsReconcilingReasonUpdate()) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 444 | oo.baseDeviceHandler.SetReadyForOmciConfig(true) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 445 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 446 | if !oo.baseDeviceHandler.GetCollectorIsRunning() { |
Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 447 | var waitForOmciProcess sync.WaitGroup |
| 448 | waitForOmciProcess.Add(1) |
Holger Hildebrandt | ced74e7 | 2021-06-10 14:55:53 +0000 | [diff] [blame] | 449 | // Start PM collector routine |
Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 450 | go oo.baseDeviceHandler.StartCollector(ctx, &waitForOmciProcess) |
| 451 | waitForOmciProcess.Wait() |
Holger Hildebrandt | ced74e7 | 2021-06-10 14:55:53 +0000 | [diff] [blame] | 452 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 453 | if !oo.baseDeviceHandler.GetAlarmManagerIsRunning(ctx) { |
| 454 | go oo.baseDeviceHandler.StartAlarmManager(ctx) |
Holger Hildebrandt | ced74e7 | 2021-06-10 14:55:53 +0000 | [diff] [blame] | 455 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 456 | |
| 457 | for _, uniPort := range *oo.baseDeviceHandler.GetUniEntityMap() { |
| 458 | // only if this port was enabled for use by the operator at startup |
| 459 | if (1<<uniPort.UniID)&oo.baseDeviceHandler.GetUniPortMask() == (1 << uniPort.UniID) { |
| 460 | if !oo.baseDeviceHandler.GetFlowMonitoringIsRunning(uniPort.UniID) { |
| 461 | go oo.baseDeviceHandler.PerOnuFlowHandlerRoutine(uniPort.UniID) |
| 462 | } |
| 463 | } |
| 464 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 465 | oo.MutexPersOnuConfig.RLock() |
| 466 | if oo.SOnuPersistentData.PersUniDisableDone { |
| 467 | oo.MutexPersOnuConfig.RUnlock() |
| 468 | oo.baseDeviceHandler.DisableUniPortStateUpdate(ctx) |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 469 | _ = oo.baseDeviceHandler.ReasonUpdate(ctx, cmn.DrOmciAdminLock, oo.baseDeviceHandler.IsReconcilingReasonUpdate()) |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 470 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 471 | oo.MutexPersOnuConfig.RUnlock() |
| 472 | oo.baseDeviceHandler.EnableUniPortStateUpdate(ctx) |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 473 | } |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 474 | |
| 475 | // no need to reconcile additional data for MibDownloadFsm, LockStateFsm, or UnlockStateFsm |
| 476 | |
| 477 | if oo.baseDeviceHandler.ReconcileDeviceTechProf(ctx) { |
| 478 | // start go routine with select() on reconciling flow channel before |
| 479 | // starting flow reconciling process to prevent loss of any signal |
Holger Hildebrandt | f2fcdd4 | 2021-12-15 11:42:19 +0000 | [diff] [blame] | 480 | syncChannel := make(chan struct{}) |
| 481 | go func(aSyncChannel chan struct{}) { |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 482 | // In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until |
| 483 | // we get a signal that the processing of the last step to rebuild the adapter internal |
| 484 | // flow data is finished. |
| 485 | expiry := oo.baseDeviceHandler.GetReconcileExpiryVlanConfigAbort() |
| 486 | oo.setReconcilingFlows(true) |
Holger Hildebrandt | f2fcdd4 | 2021-12-15 11:42:19 +0000 | [diff] [blame] | 487 | aSyncChannel <- struct{}{} |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 488 | select { |
| 489 | case success := <-oo.chReconcilingFlowsFinished: |
| 490 | if success { |
| 491 | logger.Debugw(ctx, "reconciling flows has been finished in time", |
| 492 | log.Fields{"device-id": oo.deviceID}) |
| 493 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
| 494 | |
| 495 | } else { |
| 496 | logger.Debugw(ctx, "wait for reconciling flows aborted", |
| 497 | log.Fields{"device-id": oo.deviceID}) |
| 498 | } |
| 499 | case <-time.After(expiry): |
| 500 | logger.Errorw(ctx, "timeout waiting for reconciling flows to be finished!", |
| 501 | log.Fields{"device-id": oo.deviceID, "expiry": expiry}) |
| 502 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch) |
| 503 | } |
| 504 | oo.setReconcilingFlows(false) |
Holger Hildebrandt | f2fcdd4 | 2021-12-15 11:42:19 +0000 | [diff] [blame] | 505 | }(syncChannel) |
| 506 | // block further processing until the above Go routine has really started |
| 507 | // and is ready to receive values from chReconcilingFlowsFinished |
| 508 | <-syncChannel |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 509 | oo.baseDeviceHandler.ReconcileDeviceFlowConfig(ctx) |
| 510 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 511 | } else { |
| 512 | logger.Debugw(ctx, "MibSync FSM", |
| 513 | log.Fields{"Getting MIB from template not successful": e.FSM.Current(), "device-id": oo.deviceID}) |
| 514 | go func() { |
| 515 | //switch to reconciling with OMCI config |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 516 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 517 | }() |
| 518 | } |
| 519 | } |
| 520 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 521 | func (oo *OnuDeviceEntry) enterAuditingState(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 522 | 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] | 523 | if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 524 | oo.requestMdsValue(ctx) |
| 525 | } else { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 526 | 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] | 527 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 528 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 529 | }() |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | func (oo *OnuDeviceEntry) enterReAuditingState(ctx context.Context, e *fsm.Event) { |
| 534 | 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] | 535 | if oo.baseDeviceHandler.CheckAuditStartCondition(ctx, cmn.CUploadFsm) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 536 | oo.requestMdsValue(ctx) |
| 537 | } else { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 538 | 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] | 539 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 540 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 541 | }() |
| 542 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 543 | } |
| 544 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 545 | func (oo *OnuDeviceEntry) enterOutOfSyncState(ctx context.Context, e *fsm.Event) { |
| 546 | logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": oo.deviceID}) |
| 547 | logger.Debug(ctx, "function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 548 | } |
| 549 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 550 | func (oo *OnuDeviceEntry) processMibSyncMessages(ctx context.Context) { |
| 551 | 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] | 552 | oo.mutexMibSyncMsgProcessorRunning.Lock() |
| 553 | oo.mibSyncMsgProcessorRunning = true |
| 554 | oo.mutexMibSyncMsgProcessorRunning.Unlock() |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 555 | loop: |
| 556 | for { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 557 | // case <-ctx.Done(): |
| 558 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID}) |
| 559 | // break loop |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 560 | message, ok := <-oo.PMibUploadFsm.CommChan |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 561 | if !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 562 | 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] | 563 | oo.mutexMibSyncMsgProcessorRunning.Lock() |
| 564 | oo.mibSyncMsgProcessorRunning = false |
| 565 | oo.mutexMibSyncMsgProcessorRunning.Unlock() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 566 | break loop |
| 567 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 568 | 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] | 569 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 570 | switch message.Type { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 571 | case cmn.TestMsg: |
| 572 | msg, _ := message.Data.(cmn.TestMessage) |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 573 | if msg.TestMessageVal == cmn.AbortMessageProcessing { |
| 574 | 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] | 575 | oo.mutexMibSyncMsgProcessorRunning.Lock() |
| 576 | oo.mibSyncMsgProcessorRunning = false |
| 577 | oo.mutexMibSyncMsgProcessorRunning.Unlock() |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 578 | break loop |
| 579 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 580 | oo.handleTestMsg(ctx, msg) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 581 | case cmn.OMCI: |
| 582 | msg, _ := message.Data.(cmn.OmciMessage) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 583 | oo.handleOmciMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 584 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 585 | 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] | 586 | } |
| 587 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 588 | 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] | 589 | // TODO: only this action? |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 590 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 593 | func (oo *OnuDeviceEntry) handleTestMsg(ctx context.Context, msg cmn.TestMessage) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 594 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 595 | 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] | 596 | |
| 597 | switch msg.TestMessageVal { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 598 | case cmn.LoadMibTemplateFailed: |
| 599 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvUploadMib) |
| 600 | logger.Debugw(ctx, "MibSync Msg", log.Fields{"state": string(oo.PMibUploadFsm.PFsm.Current())}) |
| 601 | case cmn.LoadMibTemplateOk: |
| 602 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
| 603 | 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] | 604 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 605 | 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] | 606 | } |
| 607 | } |
| 608 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 609 | func (oo *OnuDeviceEntry) handleOmciMibResetResponseMessage(ctx context.Context, msg cmn.OmciMessage) { |
| 610 | if oo.PMibUploadFsm.PFsm.Is(UlStResettingMib) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 611 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse) |
| 612 | if msgLayer != nil { |
| 613 | msgObj, msgOk := msgLayer.(*omci.MibResetResponse) |
| 614 | if msgOk { |
nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 615 | logger.Infow(ctx, "MibResetResponse Data", log.Fields{"data-fields": msgObj}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 616 | if msgObj.Result == me.Success { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 617 | oo.MutexPersOnuConfig.Lock() |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 618 | oo.SOnuPersistentData.PersMibDataSyncAdpt = cmn.MdsDefaultMib |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 619 | oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | 7e13846 | 2023-03-29 12:12:14 +0000 | [diff] [blame] | 620 | oo.PDevOmciCC.ResetConfFailMEs() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 621 | // trigger retrieval of VendorId and SerialNumber |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 622 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetVendorAndSerial) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 623 | return |
| 624 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 625 | 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] | 626 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 627 | 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] | 628 | } |
| 629 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 630 | 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] | 631 | } |
| 632 | } else { |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 633 | //in case the last request was MdsGetRequest this issue may appear if the ONU was online before and has received the MIB reset |
| 634 | // with Sequence number 0x8000 as last request before - so it may still respond to that |
| 635 | // 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] | 636 | oo.mutexLastTxParamStruct.Lock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 637 | if oo.lastTxParamStruct.lastTxMessageType == omci.GetRequestType && oo.lastTxParamStruct.repeatCount == 0 { |
| 638 | 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] | 639 | requestedAttributes := me.AttributeValueMap{me.OnuData_MibDataSync: ""} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 640 | _, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 641 | me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, oo.PMibUploadFsm.CommChan, false) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 642 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 643 | oo.mutexLastTxParamStruct.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 644 | 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] | 645 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 646 | return |
| 647 | } |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 648 | //TODO: needs extra handling of timeouts |
| 649 | oo.lastTxParamStruct.repeatCount = 1 |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 650 | oo.mutexLastTxParamStruct.Unlock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 651 | return |
| 652 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 653 | oo.mutexLastTxParamStruct.Unlock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 654 | logger.Errorw(ctx, "unexpected MibResetResponse - ignoring", log.Fields{"device-id": oo.deviceID}) |
| 655 | //perhaps some still lingering message from some prior activity, let's wait for the real response |
| 656 | return |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 657 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 658 | 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] | 659 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 660 | } |
| 661 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 662 | func (oo *OnuDeviceEntry) handleOmciMibUploadResponseMessage(ctx context.Context, msg cmn.OmciMessage) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 663 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse) |
| 664 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 665 | 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] | 666 | return |
| 667 | } |
| 668 | msgObj, msgOk := msgLayer.(*omci.MibUploadResponse) |
| 669 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 670 | 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] | 671 | return |
| 672 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 673 | 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] | 674 | /* to be verified / reworked !!! */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 675 | oo.PDevOmciCC.UploadNoOfCmds = msgObj.NumberOfCommands |
| 676 | if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds { |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 677 | _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), |
| 678 | oo.baseDeviceHandler.GetOmciTimeout(), true, oo.GetPersIsExtOmciSupported()) |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 679 | //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure |
| 680 | // that the lastTxMessageType is correctly set to avoid misinterpreting other responses |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 681 | oo.mutexLastTxParamStruct.Lock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 682 | oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 683 | oo.mutexLastTxParamStruct.Unlock() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 684 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 685 | 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] | 686 | //TODO right action? |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 687 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvTimeout) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 691 | func (oo *OnuDeviceEntry) handleOmciMibUploadNextResponseMessage(ctx context.Context, msg cmn.OmciMessage) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 692 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse) |
mpagenko | 7033f4e | 2021-11-19 18:04:22 +0000 | [diff] [blame] | 693 | if msgLayer != nil { |
| 694 | msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse) |
| 695 | if !msgOk { |
| 696 | logger.Errorw(ctx, "Omci Msg layer could not be assigned", log.Fields{"device-id": oo.deviceID}) |
| 697 | return |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 698 | } |
mpagenko | 7033f4e | 2021-11-19 18:04:22 +0000 | [diff] [blame] | 699 | meName := msgObj.ReportedME.GetName() |
| 700 | meClassID := msgObj.ReportedME.GetClassID() |
| 701 | meEntityID := msgObj.ReportedME.GetEntityID() |
| 702 | |
| 703 | logger.Debugw(ctx, "MibUploadNextResponse Data for:", log.Fields{"device-id": oo.deviceID, "meName": meName, "data-fields": msgObj}) |
| 704 | |
| 705 | if meName == devdb.CUnknownItuG988ManagedEntity || meName == devdb.CUnknownVendorSpecificManagedEntity { |
Holger Hildebrandt | 3908002 | 2022-03-16 10:03:17 +0000 | [diff] [blame] | 706 | logger.Debugw(ctx, "MibUploadNextResponse contains unknown ME", log.Fields{"device-id": oo.deviceID, |
| 707 | "Me-Name": devdb.UnknownMeOrAttribName(meName), "Me-ClassId": meClassID, "Me-InstId": meEntityID, |
| 708 | "unknown mask": msgObj.ReportedME.GetAttributeMask(), "unknown attributes": msgObj.BaseLayer.Payload}) |
| 709 | oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.UnknownMeOrAttribName(meName), meClassID, meEntityID, |
| 710 | msgObj.ReportedME.GetAttributeMask(), msgObj.BaseLayer.Payload[devdb.CStartUnknownMeAttribsInBaseLayerPayload:]) |
mpagenko | 7033f4e | 2021-11-19 18:04:22 +0000 | [diff] [blame] | 711 | } else { |
| 712 | //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 |
| 713 | if unknownAttrLayer := (*msg.OmciPacket).Layer(omci.LayerTypeUnknownAttributes); unknownAttrLayer != nil { |
| 714 | logger.Warnw(ctx, "MibUploadNextResponse contains unknown attributes", log.Fields{"device-id": oo.deviceID}) |
| 715 | if unknownAttributes, ok := unknownAttrLayer.(*omci.UnknownAttributes); ok { |
| 716 | // provide a loop over several ME's here already in preparation of OMCI extended message format |
| 717 | for _, unknown := range unknownAttributes.Attributes { |
| 718 | unknownAttrClassID := unknown.EntityClass // ClassID |
| 719 | unknownAttrInst := unknown.EntityInstance // uint16 |
| 720 | unknownAttrMask := unknown.AttributeMask // ui |
| 721 | unknownAttrBlob := unknown.AttributeData // []byte |
| 722 | logger.Warnw(ctx, "unknown attributes detected for", log.Fields{"device-id": oo.deviceID, |
| 723 | "Me-ClassId": unknownAttrClassID, "Me-InstId": unknownAttrInst, "unknown mask": unknownAttrMask, |
| 724 | "unknown attributes": unknownAttrBlob}) |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 725 | oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.CUnknownAttributesManagedEntity, unknown.EntityClass, unknown.EntityInstance, |
| 726 | unknown.AttributeMask, unknown.AttributeData) |
mpagenko | 7033f4e | 2021-11-19 18:04:22 +0000 | [diff] [blame] | 727 | } // for all included ME's with unknown attributes |
| 728 | } else { |
| 729 | logger.Errorw(ctx, "unknownAttrLayer could not be decoded", log.Fields{"device-id": oo.deviceID}) |
| 730 | } |
| 731 | } |
| 732 | oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, msgObj.ReportedME.GetAttributeValueMap()) |
| 733 | } |
Holger Hildebrandt | 0edf5b0 | 2022-05-04 14:19:43 +0000 | [diff] [blame] | 734 | if msg.OmciMsg.DeviceIdentifier == omci.ExtendedIdent { |
| 735 | for _, additionalME := range msgObj.AdditionalMEs { |
| 736 | meName := additionalME.GetName() |
| 737 | meClassID := additionalME.GetClassID() |
| 738 | meEntityID := additionalME.GetEntityID() |
| 739 | attributes := additionalME.GetAttributeValueMap() |
| 740 | |
| 741 | if meName == devdb.CUnknownItuG988ManagedEntity || meName == devdb.CUnknownVendorSpecificManagedEntity { |
| 742 | attribMask := additionalME.GetAttributeMask() |
| 743 | logger.Debugw(ctx, "MibUploadNextResponse AdditionalData contains unknown ME", log.Fields{"device-id": oo.deviceID, |
| 744 | "Me-Name": devdb.UnknownMeOrAttribName(meName), "Me-ClassId": meClassID, "Me-InstId": meEntityID, |
| 745 | "unknown mask": attribMask}) |
| 746 | |
| 747 | attribValues := make([]byte, 0) |
| 748 | for key, value := range attributes { |
| 749 | if key != cmn.CGenericManagedEntityIDName { |
| 750 | data, err := me.InterfaceToOctets(value) |
| 751 | if err != nil { |
| 752 | logger.Infow(ctx, "MibUploadNextResponse unknown ME AdditionalData attrib - could not decode", log.Fields{"device-id": oo.deviceID, "key": key}) |
| 753 | } else { |
| 754 | attribValues = append(attribValues[:], data[:]...) |
| 755 | logger.Debugw(ctx, "MibUploadNextResponse unknown ME AdditionalData attrib", log.Fields{"device-id": oo.deviceID, "attribValues": attribValues, "data": data, "key": key}) |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | oo.pOnuDB.PutUnknownMeOrAttrib(ctx, devdb.UnknownMeOrAttribName(meName), meClassID, meEntityID, attribMask, attribValues) |
| 760 | } else { |
| 761 | logger.Debugw(ctx, "MibUploadNextResponse AdditionalData for:", log.Fields{"device-id": oo.deviceID, "meName": meName, "meEntityID": meEntityID, "attributes": attributes}) |
| 762 | oo.pOnuDB.PutMe(ctx, meClassID, meEntityID, attributes) |
| 763 | } |
| 764 | } |
| 765 | } |
mpagenko | 7033f4e | 2021-11-19 18:04:22 +0000 | [diff] [blame] | 766 | } else { |
| 767 | logger.Errorw(ctx, "Omci Msg layer could not be detected", log.Fields{"device-id": oo.deviceID}) |
| 768 | //as long as omci-lib does not support decoding of table attribute as 'unknown/unspecified' attribute |
| 769 | // we have to verify, if this failure is from table attribute and try to go forward with ignoring the complete message |
| 770 | errLayer := (*msg.OmciPacket).Layer(gopacket.LayerTypeDecodeFailure) |
| 771 | if failure, decodeOk := errLayer.(*gopacket.DecodeFailure); decodeOk { |
| 772 | errMsg := failure.String() |
| 773 | if !strings.Contains(strings.ToLower(errMsg), "table decode") { |
| 774 | //something still unexected happened, needs deeper investigation - stop complete MIB upload process (timeout) |
| 775 | return |
| 776 | } |
| 777 | logger.Warnw(ctx, "Decode issue on received MibUploadNextResponse frame - found table attribute(s) (message ignored)", |
| 778 | log.Fields{"device-id": oo.deviceID, "issue": errMsg}) |
| 779 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 780 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 781 | if oo.PDevOmciCC.UploadSequNo < oo.PDevOmciCC.UploadNoOfCmds { |
Holger Hildebrandt | 5458d89 | 2022-05-31 09:52:06 +0000 | [diff] [blame] | 782 | _ = oo.PDevOmciCC.SendMibUploadNext(log.WithSpanFromContext(context.TODO(), ctx), |
| 783 | oo.baseDeviceHandler.GetOmciTimeout(), true, oo.GetPersIsExtOmciSupported()) |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 784 | //even though lastTxParameters are currently not used for checking the ResetResponse message we have to ensure |
| 785 | // that the lastTxMessageType is correctly set to avoid misinterpreting other responses |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 786 | oo.mutexLastTxParamStruct.Lock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 787 | oo.lastTxParamStruct.lastTxMessageType = omci.MibUploadNextRequestType |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 788 | oo.mutexLastTxParamStruct.Unlock() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 789 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 790 | oo.pOnuDB.LogMeDb(ctx) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 791 | err := oo.createAndPersistMibTemplate(ctx) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 792 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 793 | 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] | 794 | } |
| 795 | |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 796 | oo.updateOnuSpecificEntries(ctx) |
| 797 | logger.Errorw(ctx, "MibSync - Updtaed the ONU Specific MEs ", log.Fields{"device-id": oo.deviceID}) |
| 798 | |
| 799 | cmnMEDB, _ := oo.pOpenOnuAc.FetchEntryFromMibDatabaseMap(ctx, oo.mibTemplatePath) |
| 800 | cmnMEDB.MIBUploadStatus = devdb.Completed |
| 801 | oo.pOnuDB.CommonMeDb.MeDbLock.Unlock() |
| 802 | oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, true) |
| 803 | oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated() |
| 804 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 805 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | |
Girish Gowdra | 21bbf05 | 2022-02-17 16:08:22 -0800 | [diff] [blame] | 809 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 810 | func (oo *OnuDeviceEntry) handleOmciGetResponseMessage(ctx context.Context, msg cmn.OmciMessage) error { |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 811 | var err error = nil |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 812 | |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 813 | oo.mutexLastTxParamStruct.RLock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 814 | if oo.lastTxParamStruct.lastTxMessageType != omci.GetRequestType || |
| 815 | oo.lastTxParamStruct.pLastTxMeInstance == nil { |
| 816 | //in case the last request was MibReset this issue may appear if the ONU was online before and has received the MDS GetRequest |
| 817 | // with Sequence number 0x8000 as last request before - so it may still respond to that |
| 818 | // then we may force the ONU to react on the MIB reset with a new message that uses an increased Sequence number |
| 819 | if oo.lastTxParamStruct.lastTxMessageType == omci.MibResetRequestType && oo.lastTxParamStruct.repeatCount == 0 { |
| 820 | 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] | 821 | _ = oo.PDevOmciCC.SendMibReset(log.WithSpanFromContext(context.TODO(), ctx), oo.baseDeviceHandler.GetOmciTimeout(), true) |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 822 | //TODO: needs extra handling of timeouts |
| 823 | oo.lastTxParamStruct.repeatCount = 1 |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 824 | oo.mutexLastTxParamStruct.RUnlock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 825 | return nil |
| 826 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 827 | oo.mutexLastTxParamStruct.RUnlock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 828 | logger.Warnw(ctx, "unexpected GetResponse - ignoring", log.Fields{"device-id": oo.deviceID}) |
| 829 | //perhaps some still lingering message from some prior activity, let's wait for the real response |
| 830 | return nil |
| 831 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 832 | oo.mutexLastTxParamStruct.RUnlock() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 833 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 834 | if msgLayer == nil { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 835 | logger.Errorw(ctx, "omci Msg layer could not be detected for GetResponse - handling of MibSyncChan stopped", |
| 836 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 837 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 838 | 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] | 839 | } |
| 840 | msgObj, msgOk := msgLayer.(*omci.GetResponse) |
| 841 | if !msgOk { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 842 | logger.Errorw(ctx, "omci Msg layer could not be assigned for GetResponse - handling of MibSyncChan stopped", |
| 843 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 844 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 845 | 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] | 846 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 847 | 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] | 848 | if msgObj.Result == me.Success { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 849 | oo.mutexLastTxParamStruct.RLock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 850 | entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID() |
| 851 | if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID { |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 852 | meAttributes := msgObj.Attributes |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 853 | meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName() |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 854 | logger.Debugf(ctx, "MibSync FSM - GetResponse Data for %s", |
| 855 | log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 856 | switch meInstance { |
| 857 | case "OnuG": |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 858 | oo.mutexLastTxParamStruct.RUnlock() |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 859 | return oo.handleOmciGetResponseOnuG(ctx, meAttributes) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 860 | case "Onu2G": |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 861 | oo.mutexLastTxParamStruct.RUnlock() |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 862 | var equipmentID string |
| 863 | if onu2GEquipmentID, ok := meAttributes[me.Onu2G_EquipmentId]; ok { |
| 864 | equipmentID = cmn.TrimStringFromMeOctet(onu2GEquipmentID) |
| 865 | if equipmentID == "" { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 866 | logger.Infow(ctx, |
| 867 | "MibSync FSM - optional attribute EquipmentID is empty in Onu2G instance - fill with appropriate value", |
| 868 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 869 | equipmentID = cEmptyEquipIDString |
| 870 | } |
| 871 | } else { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 872 | logger.Infow(ctx, |
| 873 | "MibSync FSM - optional attribute EquipmentID not present in Onu2G instance - fill with appropriate value", |
| 874 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 875 | equipmentID = cNotPresentEquipIDString |
| 876 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 877 | oo.MutexPersOnuConfig.Lock() |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 878 | oo.SOnuPersistentData.PersEquipmentID = equipmentID |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 879 | 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] | 880 | "onuDeviceEntry.equipmentID": oo.SOnuPersistentData.PersEquipmentID}) |
| 881 | oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 882 | |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 883 | var omccVersion uint8 |
| 884 | if onu2GOmccVersion, ok := meAttributes[me.Onu2G_OpticalNetworkUnitManagementAndControlChannelOmccVersion]; ok { |
| 885 | oo.MutexPersOnuConfig.Lock() |
| 886 | omccVersion = onu2GOmccVersion.(uint8) |
| 887 | if _, ok := omccVersionSupportsExtendedOmciFormat[omccVersion]; ok { |
| 888 | oo.SOnuPersistentData.PersIsExtOmciSupported = omccVersionSupportsExtendedOmciFormat[omccVersion] |
Holger Hildebrandt | c572e62 | 2022-06-22 09:19:17 +0000 | [diff] [blame] | 889 | if oo.SOnuPersistentData.PersIsExtOmciSupported && !oo.baseDeviceHandler.GetExtendedOmciSupportEnabled() { |
| 890 | logger.Infow(ctx, "MibSync FSM - ONU supports extended OMCI, but support is disabled in the adapter: reset flag", |
| 891 | log.Fields{"device-id": oo.deviceID}) |
| 892 | oo.SOnuPersistentData.PersIsExtOmciSupported = false |
| 893 | } |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 894 | } else { |
| 895 | logger.Infow(ctx, "MibSync FSM - unknown OMCC version in Onu2G instance - disable extended OMCI support", |
| 896 | log.Fields{"device-id": oo.deviceID}) |
| 897 | oo.SOnuPersistentData.PersIsExtOmciSupported = false |
| 898 | } |
| 899 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu2-G - OMCC version", log.Fields{"device-id": oo.deviceID, |
| 900 | "omccVersion": omccVersion, "isExtOmciSupported": oo.SOnuPersistentData.PersIsExtOmciSupported}) |
| 901 | oo.MutexPersOnuConfig.Unlock() |
| 902 | } else { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 903 | logger.Errorw(ctx, |
| 904 | "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] | 905 | log.Fields{"device-id": oo.deviceID}) |
| 906 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 907 | return fmt.Errorf( |
| 908 | "mibSync FSM - mandatory attribute OMCC version not present in Onu2G instance - handling of MibSyncChan stopped: %s", |
| 909 | oo.deviceID) |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame] | 910 | } |
| 911 | oo.MutexPersOnuConfig.RLock() |
| 912 | if oo.SOnuPersistentData.PersIsExtOmciSupported { |
| 913 | oo.MutexPersOnuConfig.RUnlock() |
| 914 | // trigger test of OMCI extended msg format |
| 915 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvTestExtOmciSupport) |
| 916 | return nil |
| 917 | } |
| 918 | oo.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 919 | // trigger retrieval of 1st SW-image info |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 920 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetFirstSwVersion) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 921 | return nil |
| 922 | case "SoftwareImage": |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 923 | oo.mutexLastTxParamStruct.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 924 | if entityID > cmn.SecondSwImageMeID { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 925 | logger.Errorw(ctx, "mibSync FSM - Failed to GetResponse Data for SoftwareImage with expected EntityId", |
| 926 | log.Fields{"device-id": oo.deviceID, "entity-ID": entityID}) |
| 927 | return fmt.Errorf("mibSync FSM - SwResponse Data with unexpected EntityId: %s %x", |
| 928 | oo.deviceID, entityID) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 929 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 930 | // need to use function for go lint complexity |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 931 | if !oo.HandleSwImageIndications(ctx, entityID, meAttributes) { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 932 | logger.Errorw(ctx, |
| 933 | "MibSync FSM - Not all mandatory attributes present in in SoftwareImage 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( |
| 937 | "mibSync FSM - Not all mandatory attributes present in in SoftwareImage instance - handling of MibSyncChan stopped: %s", |
| 938 | oo.deviceID) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 939 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 940 | return nil |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 941 | case "IpHostConfigData": |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 942 | oo.mutexLastTxParamStruct.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 943 | oo.MutexPersOnuConfig.Lock() |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 944 | if ipHostConfigMacAddress, ok := meAttributes[me.IpHostConfigData_MacAddress]; ok { |
Girish Gowdra | 21bbf05 | 2022-02-17 16:08:22 -0800 | [diff] [blame] | 945 | macBytes, _ := me.InterfaceToOctets(ipHostConfigMacAddress) |
| 946 | if cmn.OmciMacAddressLen == len(macBytes) { |
| 947 | oo.SOnuPersistentData.PersMacAddress = hex.EncodeToString(macBytes[:]) |
| 948 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for IpHostConfigData - MacAddress", log.Fields{"device-id": oo.deviceID, |
| 949 | "macAddress": oo.SOnuPersistentData.PersMacAddress}) |
| 950 | } else { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 951 | logger.Infow(ctx, "MibSync FSM - MacAddress wrong length - fill macAddress with zeros", |
| 952 | log.Fields{"device-id": oo.deviceID, "length": len(macBytes)}) |
Girish Gowdra | 21bbf05 | 2022-02-17 16:08:22 -0800 | [diff] [blame] | 953 | oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString |
| 954 | } |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 955 | } else { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 956 | // since ONU creates instances of this ME automatically only when IP host services are available, |
| 957 | // processing continues here despite the error |
| 958 | logger.Infow(ctx, "MibSync FSM - MacAddress attribute not present in IpHostConfigData instance - fill macAddress with zeros", |
| 959 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 960 | oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 961 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 962 | oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 963 | // trigger retrieval of mib template |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 964 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 965 | return nil |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 966 | case "OnuData": |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 967 | oo.mutexLastTxParamStruct.RUnlock() |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 968 | if onuDataMibDataSync, ok := meAttributes[me.OnuData_MibDataSync]; ok { |
| 969 | oo.checkMdsValue(ctx, onuDataMibDataSync.(uint8)) |
| 970 | } else { |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 971 | logger.Errorw(ctx, "MibSync FSM - MibDataSync attribute not present in OnuData instance - handling of MibSyncChan stopped!", |
| 972 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 973 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 974 | return fmt.Errorf("mibSync FSM - VendorId attribute not present in OnuG instance - handling of MibSyncChan stopped: %s", |
| 975 | oo.deviceID) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 976 | } |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 977 | return nil |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 978 | default: |
| 979 | oo.mutexLastTxParamStruct.RUnlock() |
| 980 | logger.Warnw(ctx, "Unsupported ME name received!", |
| 981 | log.Fields{"ME name": meInstance, "device-id": oo.deviceID}) |
| 982 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 983 | } |
Matteo Scandolo | 20ca10c | 2021-01-21 14:35:45 -0800 | [diff] [blame] | 984 | } else { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 985 | oo.mutexLastTxParamStruct.RUnlock() |
| 986 | logger.Warnf(ctx, "MibSync FSM - Received GetResponse Data for %s with wrong classID or entityID ", |
| 987 | log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, msgObj.EntityClass) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 988 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 989 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 990 | if err = oo.handleOmciGetResponseErrors(ctx, msgObj); err == nil { |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 991 | return nil |
| 992 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 993 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 994 | 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] | 995 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 996 | return err |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 997 | } |
| 998 | |
nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 999 | // HandleSwImageIndications updates onuSwImageIndications with the ONU data just received |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 1000 | func (oo *OnuDeviceEntry) HandleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) bool { |
| 1001 | |
| 1002 | var imageVersion string |
| 1003 | var imageIsCommitted, imageIsActive uint8 |
| 1004 | |
| 1005 | allMandAttribsPresent := false |
| 1006 | if softwareImageIsCommitted, ok := meAttributes[me.SoftwareImage_IsCommitted]; ok { |
| 1007 | if softwareImageIsActiveimage, ok := meAttributes[me.SoftwareImage_IsActive]; ok { |
| 1008 | if softwareImageVersion, ok := meAttributes[me.SoftwareImage_Version]; ok { |
| 1009 | imageVersion = cmn.TrimStringFromMeOctet(softwareImageVersion) |
| 1010 | imageIsActive = softwareImageIsActiveimage.(uint8) |
| 1011 | imageIsCommitted = softwareImageIsCommitted.(uint8) |
| 1012 | allMandAttribsPresent = true |
| 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | if !allMandAttribsPresent { |
| 1017 | logger.Errorw(ctx, "MibSync FSM - Not all mandatory attributes present in SoftwareImage instance - skip processing!", log.Fields{"device-id": oo.deviceID}) |
| 1018 | return allMandAttribsPresent |
| 1019 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1020 | oo.MutexPersOnuConfig.RLock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1021 | logger.Infow(ctx, "MibSync FSM - GetResponse Data for SoftwareImage", |
| 1022 | log.Fields{"device-id": oo.deviceID, "entityID": entityID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1023 | "version": imageVersion, "isActive": imageIsActive, "isCommitted": imageIsCommitted, "SNR": oo.SOnuPersistentData.PersSerialNumber}) |
| 1024 | oo.MutexPersOnuConfig.RUnlock() |
| 1025 | if cmn.FirstSwImageMeID == entityID { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1026 | //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] | 1027 | oo.mutexOnuSwImageIndications.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1028 | if imageIsActive == cmn.SwIsActive { |
| 1029 | oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID |
| 1030 | oo.onuSwImageIndications.ActiveEntityEntry.Valid = true |
| 1031 | oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion |
| 1032 | oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 1033 | //as the SW version indication may stem from some ONU Down/up event |
| 1034 | //the complementary image state is to be invalidated |
| 1035 | // (state of the second image is always expected afterwards or just invalid) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1036 | oo.onuSwImageIndications.InActiveEntityEntry.Valid = false |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1037 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1038 | oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID |
| 1039 | oo.onuSwImageIndications.InActiveEntityEntry.Valid = true |
| 1040 | oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion |
| 1041 | oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted |
mpagenko | 59498c1 | 2021-03-18 14:15:15 +0000 | [diff] [blame] | 1042 | //as the SW version indication may stem form some ONU Down/up event |
| 1043 | //the complementary image state is to be invalidated |
| 1044 | // (state of the second image is always expected afterwards or just invalid) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1045 | oo.onuSwImageIndications.ActiveEntityEntry.Valid = false |
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(UlEvGetSecondSwVersion) |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 1049 | return allMandAttribsPresent |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1050 | } else if cmn.SecondSwImageMeID == entityID { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1051 | //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] | 1052 | oo.mutexOnuSwImageIndications.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1053 | if imageIsActive == cmn.SwIsActive { //2nd image reported to be active |
| 1054 | if oo.onuSwImageIndications.ActiveEntityEntry.Valid { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1055 | //conflict exists - state of first image is left active |
| 1056 | logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as active - assuming 2nd to be inactive", |
| 1057 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1058 | oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID |
| 1059 | oo.onuSwImageIndications.InActiveEntityEntry.Valid = true ////to indicate that at least something has been reported |
| 1060 | oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion |
| 1061 | oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1062 | } else { //first image inactive, this one active |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1063 | oo.onuSwImageIndications.ActiveEntityEntry.EntityID = entityID |
| 1064 | oo.onuSwImageIndications.ActiveEntityEntry.Valid = true |
| 1065 | oo.onuSwImageIndications.ActiveEntityEntry.Version = imageVersion |
| 1066 | oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = imageIsCommitted |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1067 | } |
| 1068 | } else { //2nd image reported to be inactive |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1069 | if oo.onuSwImageIndications.InActiveEntityEntry.Valid { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1070 | //conflict exists - both images inactive - regard it as ONU failure and assume first image to be active |
| 1071 | logger.Warnw(ctx, "mibSync FSM - both ONU images are reported as inactive, defining first to be active", |
| 1072 | log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1073 | oo.onuSwImageIndications.ActiveEntityEntry.EntityID = cmn.FirstSwImageMeID |
| 1074 | 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] | 1075 | //copy active commit/version from the previously stored inactive position |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1076 | oo.onuSwImageIndications.ActiveEntityEntry.Version = oo.onuSwImageIndications.InActiveEntityEntry.Version |
| 1077 | oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted = oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1078 | } |
| 1079 | //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] | 1080 | oo.onuSwImageIndications.InActiveEntityEntry.EntityID = entityID |
| 1081 | oo.onuSwImageIndications.InActiveEntityEntry.Valid = true |
| 1082 | oo.onuSwImageIndications.InActiveEntityEntry.Version = imageVersion |
| 1083 | oo.onuSwImageIndications.InActiveEntityEntry.IsCommitted = imageIsCommitted |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1084 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1085 | oo.mutexOnuSwImageIndications.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1086 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMacAddress) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1087 | } |
Holger Hildebrandt | fdb4bba | 2022-03-10 12:12:59 +0000 | [diff] [blame] | 1088 | return allMandAttribsPresent |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1091 | func (oo *OnuDeviceEntry) handleOmciMessage(ctx context.Context, msg cmn.OmciMessage) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1092 | 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] | 1093 | "msgType": msg.OmciMsg.MessageType, "msg": msg}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1094 | //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ... |
| 1095 | switch msg.OmciMsg.MessageType { |
| 1096 | case omci.MibResetResponseType: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1097 | oo.handleOmciMibResetResponseMessage(ctx, msg) |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 1098 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1099 | case omci.MibUploadResponseType: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1100 | oo.handleOmciMibUploadResponseMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1101 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1102 | case omci.MibUploadNextResponseType: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1103 | oo.handleOmciMibUploadNextResponseMessage(ctx, msg) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1104 | |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 1105 | case omci.GetResponseType: |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 1106 | //TODO: error handling |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1107 | _ = oo.handleOmciGetResponseMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1108 | |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 1109 | default: |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 1110 | 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] | 1111 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | |
Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 1115 | func (oo *OnuDeviceEntry) handleOmciGetResponseOnuG(ctx context.Context, meAttributes me.AttributeValueMap) error { |
| 1116 | currentState := oo.PMibUploadFsm.PFsm.Current() |
| 1117 | if currentState == UlStGettingVendorAndSerial { |
| 1118 | if onuGVendorID, ok := meAttributes[me.OnuG_VendorId]; ok { |
| 1119 | vendorID := cmn.TrimStringFromMeOctet(onuGVendorID) |
| 1120 | if vendorID == "" { |
| 1121 | logger.Infow(ctx, |
| 1122 | "MibSync FSM - mandatory attribute VendorId is empty in OnuG instance - fill with appropriate value", |
| 1123 | log.Fields{"device-id": oo.deviceID}) |
| 1124 | vendorID = cEmptyVendorIDString |
| 1125 | } |
| 1126 | oo.MutexPersOnuConfig.Lock() |
| 1127 | oo.SOnuPersistentData.PersVendorID = vendorID |
| 1128 | oo.MutexPersOnuConfig.Unlock() |
| 1129 | } else { |
| 1130 | logger.Errorw(ctx, |
| 1131 | "MibSync FSM - mandatory attribute VendorId not present in OnuG instance - handling of MibSyncChan stopped!", |
| 1132 | log.Fields{"device-id": oo.deviceID}) |
| 1133 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
| 1134 | return fmt.Errorf( |
| 1135 | "mibSync FSM - mandatory attribute VendorId not present in OnuG instance - handling of MibSyncChan stopped: %s", |
| 1136 | oo.deviceID) |
| 1137 | } |
| 1138 | if onuGSerialNumber, ok := meAttributes[me.OnuG_SerialNumber]; ok { |
| 1139 | oo.MutexPersOnuConfig.Lock() |
| 1140 | snBytes, _ := me.InterfaceToOctets(onuGSerialNumber) |
| 1141 | if cmn.OnugSerialNumberLen == len(snBytes) { |
| 1142 | snVendorPart := fmt.Sprintf("%s", snBytes[:4]) |
| 1143 | snNumberPart := hex.EncodeToString(snBytes[4:]) |
| 1144 | oo.SOnuPersistentData.PersSerialNumber = snVendorPart + snNumberPart |
| 1145 | } else { |
| 1146 | logger.Infow(ctx, "MibSync FSM - SerialNumber has wrong length - fill serialNumber with zeros", |
| 1147 | log.Fields{"device-id": oo.deviceID, "length": len(snBytes)}) |
| 1148 | oo.SOnuPersistentData.PersSerialNumber = cEmptySerialNumberString |
| 1149 | } |
| 1150 | oo.MutexPersOnuConfig.Unlock() |
| 1151 | } else { |
| 1152 | logger.Errorw(ctx, |
| 1153 | "MibSync FSM - mandatory attribute SerialNumber not present in OnuG instance - handling of MibSyncChan stopped!", |
| 1154 | log.Fields{"device-id": oo.deviceID}) |
| 1155 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
| 1156 | return fmt.Errorf( |
| 1157 | "mibSync FSM - mandatory attribute SerialNumber not present in OnuG instance - handling of MibSyncChan stopped: %s", |
| 1158 | oo.deviceID) |
| 1159 | } |
| 1160 | oo.MutexPersOnuConfig.Lock() |
| 1161 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-G - VendorId/SerialNumber", log.Fields{"device-id": oo.deviceID, |
| 1162 | "onuDeviceEntry.vendorID": oo.SOnuPersistentData.PersVendorID, |
| 1163 | "onuDeviceEntry.serialNumber": oo.SOnuPersistentData.PersSerialNumber}) |
| 1164 | oo.MutexPersOnuConfig.Unlock() |
| 1165 | // trigger retrieval of Version |
| 1166 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetVersion) |
| 1167 | return nil |
| 1168 | } else if currentState == UlStGettingVersion { |
| 1169 | if onuGVersion, ok := meAttributes[me.OnuG_Version]; ok { |
| 1170 | version := cmn.TrimStringFromMeOctet(onuGVersion) |
| 1171 | if version == "" { |
| 1172 | logger.Infow(ctx, "MibSync FSM - mandatory attribute Version is empty in OnuG instance - fill with appropriate value", |
| 1173 | log.Fields{"device-id": oo.deviceID}) |
| 1174 | version = cEmptyVersionString |
| 1175 | } |
| 1176 | oo.MutexPersOnuConfig.Lock() |
| 1177 | oo.SOnuPersistentData.PersVersion = version |
| 1178 | oo.MutexPersOnuConfig.Unlock() |
| 1179 | } else { |
| 1180 | logger.Errorw(ctx, |
| 1181 | "MibSync FSM - mandatory attribute Version not present in OnuG instance - handling of MibSyncChan stopped!", |
| 1182 | log.Fields{"device-id": oo.deviceID}) |
| 1183 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
| 1184 | return fmt.Errorf( |
| 1185 | "mibSync FSM - mandatory attribute Version not present in OnuG instance - handling of MibSyncChan stopped: %s", |
| 1186 | oo.deviceID) |
| 1187 | } |
| 1188 | oo.MutexPersOnuConfig.Lock() |
| 1189 | logger.Debugw(ctx, "MibSync FSM - GetResponse Data for Onu-G - Version", log.Fields{"device-id": oo.deviceID, |
| 1190 | "onuDeviceEntry.version": oo.SOnuPersistentData.PersVersion}) |
| 1191 | oo.MutexPersOnuConfig.Unlock() |
| 1192 | // trigger retrieval of EquipmentId and OMCC version |
| 1193 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetEquipIDAndOmcc) |
| 1194 | return nil |
| 1195 | } else { |
| 1196 | logger.Errorw(ctx, "MibSync FSM - wrong state OnuG response processing - handling of MibSyncChan stopped!", |
| 1197 | log.Fields{"currentState": currentState, "device-id": oo.deviceID}) |
| 1198 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
| 1199 | return fmt.Errorf("mibSync FSM - wrong state OnuG response processing - handling of MibSyncChan stopped: %s", |
| 1200 | oo.deviceID) |
| 1201 | } |
| 1202 | } |
| 1203 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1204 | func (oo *OnuDeviceEntry) handleOmciGetResponseErrors(ctx context.Context, msgObj *omci.GetResponse) error { |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 1205 | var err error = nil |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1206 | 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] | 1207 | // Up to now the following erroneous results have been seen for different ONU-types to indicate an unsupported ME |
| 1208 | 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] | 1209 | oo.mutexLastTxParamStruct.RLock() |
| 1210 | if oo.lastTxParamStruct.pLastTxMeInstance != nil { |
| 1211 | entityID := oo.lastTxParamStruct.pLastTxMeInstance.GetEntityID() |
| 1212 | if msgObj.EntityClass == oo.lastTxParamStruct.pLastTxMeInstance.GetClassID() && msgObj.EntityInstance == entityID { |
| 1213 | meInstance := oo.lastTxParamStruct.pLastTxMeInstance.GetName() |
| 1214 | switch meInstance { |
| 1215 | case "IpHostConfigData": |
| 1216 | oo.mutexLastTxParamStruct.RUnlock() |
| 1217 | logger.Debugw(ctx, "MibSync FSM - erroneous result for IpHostConfigData received - ONU doesn't support ME - fill macAddress with zeros", |
| 1218 | log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1219 | oo.MutexPersOnuConfig.Lock() |
| 1220 | oo.SOnuPersistentData.PersMacAddress = cEmptyMacAddrString |
| 1221 | oo.MutexPersOnuConfig.Unlock() |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1222 | // trigger retrieval of mib template |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1223 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvGetMibTemplate) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1224 | return nil |
| 1225 | default: |
| 1226 | oo.mutexLastTxParamStruct.RUnlock() |
| 1227 | logger.Warnf(ctx, "MibSync FSM - erroneous result for %s received - no exceptional treatment defined", log.Fields{"device-id": oo.deviceID, "data-fields": msgObj}, meInstance) |
| 1228 | err = fmt.Errorf("erroneous result for %s received - no exceptional treatment defined: %s", meInstance, oo.deviceID) |
| 1229 | } |
| 1230 | } else { |
| 1231 | oo.mutexLastTxParamStruct.RUnlock() |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 1232 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1233 | } else { |
| 1234 | oo.mutexLastTxParamStruct.RUnlock() |
| 1235 | 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] | 1236 | } |
| 1237 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1238 | 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] | 1239 | err = fmt.Errorf("erroneous result in GetResponse Data: %s - %s", msgObj.Result, oo.deviceID) |
| 1240 | } |
| 1241 | return err |
| 1242 | } |
| 1243 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1244 | // IsNewOnu - TODO: add comment |
| 1245 | func (oo *OnuDeviceEntry) IsNewOnu() bool { |
| 1246 | oo.MutexPersOnuConfig.RLock() |
| 1247 | defer oo.MutexPersOnuConfig.RUnlock() |
| 1248 | return oo.SOnuPersistentData.PersMibLastDbSync == 0 |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1251 | func isSupportedClassID(meClassID me.ClassID) bool { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1252 | for _, v := range supportedClassIds { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1253 | if v == meClassID { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1254 | return true |
| 1255 | } |
| 1256 | } |
| 1257 | return false |
| 1258 | } |
| 1259 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1260 | func (oo *OnuDeviceEntry) mibDbVolatileDict(ctx context.Context) error { |
| 1261 | logger.Debug(ctx, "MibVolatileDict- running from default Entry code") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1262 | return errors.New("not_implemented") |
| 1263 | } |
| 1264 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1265 | // 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] | 1266 | // 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] | 1267 | // 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] | 1268 | func (oo *OnuDeviceEntry) createAndPersistMibTemplate(ctx context.Context) error { |
| 1269 | logger.Debugw(ctx, "MibSync - MibTemplate - path name", log.Fields{"path": oo.mibTemplatePath, |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 1270 | "device-id": oo.deviceID}) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1271 | |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 1272 | //Fetch the MEs dependent on serial number and MAC address and add them to onuSpecific ME DB |
| 1273 | //Modify the serial number and MAC address with generic content in the common DB. |
| 1274 | knownAttributeMEDb := oo.pOnuDB.CommonMeDb.MeDb |
| 1275 | for firstLevelKey, firstLevelValue := range knownAttributeMEDb { |
| 1276 | classID := strconv.Itoa(int(firstLevelKey)) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 1277 | |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 1278 | for secondLevelKey, secondLevelValue := range firstLevelValue { |
| 1279 | switch classID { |
| 1280 | case "6", "256": |
| 1281 | if _, exists := secondLevelValue["SerialNumber"]; exists { |
| 1282 | oo.pOnuDB.PutOnuSpeficMe(ctx, firstLevelKey, secondLevelKey, secondLevelValue) |
| 1283 | secondLevelValue["SerialNumber"] = "%SERIAL_NUMBER%" |
| 1284 | } |
| 1285 | case "134": |
| 1286 | if _, exists := secondLevelValue["MacAddress"]; exists { |
| 1287 | oo.pOnuDB.PutOnuSpeficMe(ctx, firstLevelKey, secondLevelKey, secondLevelValue) |
| 1288 | secondLevelValue["MacAddress"] = "%MAC_ADDRESS%" |
| 1289 | } |
| 1290 | } |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | //Create the MIB Template |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 1295 | currentTime := time.Now() |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1296 | templateMap := make(map[string]interface{}) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 1297 | templateMap["TemplateName"] = oo.mibTemplatePath |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1298 | templateMap["TemplateCreated"] = currentTime.Format("2006-01-02 15:04:05.000000") |
| 1299 | |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 1300 | firstLevelMap := oo.pOnuDB.CommonMeDb.MeDb |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1301 | for firstLevelKey, firstLevelValue := range firstLevelMap { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1302 | logger.Debugw(ctx, "MibSync - MibTemplate - firstLevelKey", log.Fields{"firstLevelKey": firstLevelKey}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1303 | classID := strconv.Itoa(int(firstLevelKey)) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1304 | |
| 1305 | secondLevelMap := make(map[string]interface{}) |
| 1306 | for secondLevelKey, secondLevelValue := range firstLevelValue { |
Holger Hildebrandt | 8998ed5 | 2022-03-23 09:52:37 +0000 | [diff] [blame] | 1307 | // ManagedEntityId is already key of secondLevelMap - remove this redundant attribute from secondLevelValue |
| 1308 | delete(secondLevelValue, cmn.CGenericManagedEntityIDName) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1309 | thirdLevelMap := make(map[string]interface{}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1310 | entityID := strconv.Itoa(int(secondLevelKey)) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1311 | thirdLevelMap["Attributes"] = secondLevelValue |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1312 | secondLevelMap[entityID] = thirdLevelMap |
| 1313 | if classID == "6" || classID == "256" { |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1314 | forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap)) |
| 1315 | delete(forthLevelMap, "SerialNumber") |
| 1316 | forthLevelMap["SerialNumber"] = "%SERIAL_NUMBER%" |
| 1317 | |
| 1318 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1319 | if classID == "134" { |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1320 | forthLevelMap := map[string]interface{}(thirdLevelMap["Attributes"].(me.AttributeValueMap)) |
| 1321 | delete(forthLevelMap, "MacAddress") |
| 1322 | forthLevelMap["MacAddress"] = "%MAC_ADDRESS%" |
| 1323 | } |
| 1324 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1325 | templateMap[classID] = secondLevelMap |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1326 | } |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 1327 | unknownMeAndAttribMap := oo.pOnuDB.CommonMeDb.UnknownMeAndAttribDb |
Holger Hildebrandt | 3908002 | 2022-03-16 10:03:17 +0000 | [diff] [blame] | 1328 | for unknownMeAndAttribMapKey := range unknownMeAndAttribMap { |
| 1329 | templateMap[string(unknownMeAndAttribMapKey)] = unknownMeAndAttribMap[unknownMeAndAttribMapKey] |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 1330 | } |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1331 | mibTemplate, err := json.Marshal(&templateMap) |
| 1332 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1333 | 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] | 1334 | oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1335 | return err |
| 1336 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1337 | err = oo.mibTemplateKVStore.Put(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath, string(mibTemplate)) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1338 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1339 | 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] | 1340 | oo.pOpenOnuAc.SetMibTemplatesGenerated(oo.mibTemplatePath, false) |
divyadesai | bbed37c | 2020-08-28 13:35:20 +0530 | [diff] [blame] | 1341 | return err |
| 1342 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1343 | 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] | 1344 | return nil |
| 1345 | } |
| 1346 | |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 1347 | func (oo *OnuDeviceEntry) requestMdsValue(ctx context.Context) { |
| 1348 | logger.Debugw(ctx, "Request MDS value", log.Fields{"device-id": oo.deviceID}) |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 1349 | requestedAttributes := me.AttributeValueMap{me.OnuData_MibDataSync: ""} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1350 | meInstance, err := oo.PDevOmciCC.SendGetMe(log.WithSpanFromContext(context.TODO(), ctx), |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 1351 | me.OnuDataClassID, cmn.OnuDataMeID, requestedAttributes, oo.baseDeviceHandler.GetOmciTimeout(), true, |
| 1352 | oo.PMibUploadFsm.CommChan, oo.GetPersIsExtOmciSupported()) |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 1353 | //accept also nil as (error) return value for writing to LastTx |
| 1354 | // - this avoids misinterpretation of new received OMCI messages |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1355 | if err != nil { |
| 1356 | 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] | 1357 | pMibUlFsm := oo.PMibUploadFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1358 | if pMibUlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1359 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1360 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvStop) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1361 | }(pMibUlFsm) |
| 1362 | } |
| 1363 | return |
| 1364 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1365 | oo.mutexLastTxParamStruct.Lock() |
mpagenko | 0149981 | 2021-03-25 10:37:12 +0000 | [diff] [blame] | 1366 | oo.lastTxParamStruct.lastTxMessageType = omci.GetRequestType |
| 1367 | oo.lastTxParamStruct.pLastTxMeInstance = meInstance |
| 1368 | oo.lastTxParamStruct.repeatCount = 0 |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1369 | oo.mutexLastTxParamStruct.Unlock() |
Holger Hildebrandt | 0bd45f8 | 2021-01-11 13:29:37 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1372 | func (oo *OnuDeviceEntry) checkMdsValue(ctx context.Context, mibDataSyncOnu uint8) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1373 | oo.MutexPersOnuConfig.RLock() |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1374 | 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] | 1375 | "mibDataSyncOnu": mibDataSyncOnu, "PersMibDataSyncAdpt": oo.SOnuPersistentData.PersMibDataSyncAdpt}) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1376 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1377 | mdsValuesAreEqual := oo.SOnuPersistentData.PersMibDataSyncAdpt == mibDataSyncOnu |
| 1378 | oo.MutexPersOnuConfig.RUnlock() |
| 1379 | if oo.PMibUploadFsm.PFsm.Is(UlStAuditing) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1380 | if mdsValuesAreEqual { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1381 | 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] | 1382 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1383 | } else { |
| 1384 | 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] | 1385 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1386 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1387 | } else if oo.PMibUploadFsm.PFsm.Is(UlStReAuditing) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1388 | if mdsValuesAreEqual { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1389 | 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] | 1390 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1391 | } else { |
Holger Hildebrandt | 80f5776 | 2022-02-16 10:03:24 +0000 | [diff] [blame] | 1392 | 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] | 1393 | log.Fields{"device-id": oo.deviceID}) |
| 1394 | oo.SendOnuDeviceEvent(ctx, cmn.OnuMibAuditFailureMds, cmn.OnuMibAuditFailureMdsDesc) |
Holger Hildebrandt | 80f5776 | 2022-02-16 10:03:24 +0000 | [diff] [blame] | 1395 | // To reconcile ONU with active adapter later on, we have to retrieve TP instances from parent adapter. |
| 1396 | // In the present use case inconsistencies between TP pathes stored in kv store and TP instances retrieved |
| 1397 | // should not occur. Nevertheless, the respective code is inserted to catch the unlikely case. |
| 1398 | if !oo.getAllStoredTpInstFromParentAdapter(ctx) { |
| 1399 | logger.Debugw(ctx, "MibSync FSM - mib reaudit - inconsistencies between TP pathes stored in kv and parent adapter instances", |
| 1400 | log.Fields{"device-id": oo.deviceID}) |
| 1401 | oo.baseDeviceHandler.SetReconcilingReasonUpdate(true) |
| 1402 | go func() { |
| 1403 | if err := oo.baseDeviceHandler.StorePersistentData(ctx); err != nil { |
| 1404 | logger.Warnw(ctx, |
| 1405 | "MibSync FSM - mib reaudit - store persistent data error - continue for now as there will be additional write attempts", |
| 1406 | log.Fields{"device-id": oo.deviceID, "err": err}) |
| 1407 | } |
| 1408 | }() |
| 1409 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1410 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1411 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1412 | } else if oo.PMibUploadFsm.PFsm.Is(UlStExaminingMds) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1413 | if mdsValuesAreEqual && mibDataSyncOnu != 0 { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1414 | 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] | 1415 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1416 | } else { |
| 1417 | 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] | 1418 | _ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1419 | } |
| 1420 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1421 | 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] | 1422 | } |
| 1423 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1424 | |
nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1425 | // GetActiveImageMeID returns the Omci MeId of the active ONU image together with error code for validity |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1426 | func (oo *OnuDeviceEntry) GetActiveImageMeID(ctx context.Context) (uint16, error) { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1427 | oo.mutexOnuSwImageIndications.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1428 | if oo.onuSwImageIndications.ActiveEntityEntry.Valid { |
| 1429 | value := oo.onuSwImageIndications.ActiveEntityEntry.EntityID |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1430 | oo.mutexOnuSwImageIndications.RUnlock() |
| 1431 | return value, nil |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1432 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1433 | oo.mutexOnuSwImageIndications.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1434 | return 0xFFFF, fmt.Errorf("no valid active image found: %s", oo.deviceID) |
| 1435 | } |
| 1436 | |
nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1437 | // GetInactiveImageMeID returns the Omci MeId of the inactive ONU image together with error code for validity |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1438 | func (oo *OnuDeviceEntry) GetInactiveImageMeID(ctx context.Context) (uint16, error) { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1439 | oo.mutexOnuSwImageIndications.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1440 | if oo.onuSwImageIndications.InActiveEntityEntry.Valid { |
| 1441 | value := oo.onuSwImageIndications.InActiveEntityEntry.EntityID |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1442 | oo.mutexOnuSwImageIndications.RUnlock() |
| 1443 | return value, nil |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1444 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1445 | oo.mutexOnuSwImageIndications.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1446 | return 0xFFFF, fmt.Errorf("no valid inactive image found: %s", oo.deviceID) |
| 1447 | } |
| 1448 | |
nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1449 | // IsImageToBeCommitted returns true if the active image is still uncommitted |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1450 | func (oo *OnuDeviceEntry) IsImageToBeCommitted(ctx context.Context, aImageID uint16) bool { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1451 | oo.mutexOnuSwImageIndications.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1452 | if oo.onuSwImageIndications.ActiveEntityEntry.Valid { |
| 1453 | if oo.onuSwImageIndications.ActiveEntityEntry.EntityID == aImageID { |
| 1454 | if oo.onuSwImageIndications.ActiveEntityEntry.IsCommitted == cmn.SwIsUncommitted { |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1455 | oo.mutexOnuSwImageIndications.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1456 | return true |
| 1457 | } |
| 1458 | } |
| 1459 | } |
Holger Hildebrandt | 0501135 | 2021-06-15 09:40:24 +0000 | [diff] [blame] | 1460 | oo.mutexOnuSwImageIndications.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1461 | return false //all other case are treated as 'nothing to commit |
| 1462 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1463 | func (oo *OnuDeviceEntry) getMibFromTemplate(ctx context.Context) bool { |
| 1464 | |
| 1465 | oo.mibTemplatePath = oo.buildMibTemplatePath() |
Holger Hildebrandt | bdc5f00 | 2021-04-19 14:46:21 +0000 | [diff] [blame] | 1466 | logger.Debugw(ctx, "MibSync FSM - get Mib from template", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath), |
| 1467 | "device-id": oo.deviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1468 | |
| 1469 | restoredFromMibTemplate := false |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 1470 | oo.pOpenOnuAc.LockMutexMibTemplateGenerated() |
| 1471 | defer oo.pOpenOnuAc.UnlockMutexMibTemplateGenerated() |
| 1472 | if meDbValue, ok := oo.pOpenOnuAc.FetchEntryFromMibDatabaseMap(ctx, oo.mibTemplatePath); ok { |
| 1473 | logger.Infow(ctx, "Found MIB common DB Instance , copy and use", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
| 1474 | oo.pOnuDB.CommonMeDb = meDbValue |
| 1475 | oo.updateOnuSpecificEntries(ctx) |
| 1476 | restoredFromMibTemplate = true |
| 1477 | } else { |
| 1478 | //Create a common ME MIB Instance as it doesn't prior exists. |
| 1479 | Value, err := oo.mibTemplateKVStore.Get(log.WithSpanFromContext(context.TODO(), ctx), oo.mibTemplatePath) |
| 1480 | //Unmarshal the MIB template and create the entry in the ONU Common Device DB |
| 1481 | if err == nil { |
| 1482 | if Value != nil { |
| 1483 | oo.processMibTemplate(ctx, Value) |
| 1484 | restoredFromMibTemplate = true |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1485 | } else { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 1486 | logger.Infow(ctx, "No MIB template found", log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1487 | } |
| 1488 | } else { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 1489 | logger.Errorw(ctx, "Get from kvstore operation failed for path", |
| 1490 | log.Fields{"path": oo.mibTemplatePath, "device-id": oo.deviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1491 | } |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 1492 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1493 | } |
| 1494 | return restoredFromMibTemplate |
| 1495 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 1496 | |
Holger Hildebrandt | 80f5776 | 2022-02-16 10:03:24 +0000 | [diff] [blame] | 1497 | func (oo *OnuDeviceEntry) getAllStoredTpInstFromParentAdapter(ctx context.Context) bool { |
| 1498 | |
| 1499 | allTpInstPresent := true |
| 1500 | oo.MutexPersOnuConfig.Lock() |
| 1501 | oo.MutexReconciledTpInstances.Lock() |
| 1502 | for indexUni, uniData := range oo.SOnuPersistentData.PersUniConfig { |
| 1503 | uniID := uniData.PersUniID |
| 1504 | oo.ReconciledTpInstances[uniID] = make(map[uint8]inter_adapter.TechProfileDownloadMessage) |
| 1505 | for tpID, tpPath := range uniData.PersTpPathMap { |
| 1506 | if tpPath != "" { |
| 1507 | // Request the TP instance from the openolt adapter |
| 1508 | iaTechTpInst, err := oo.baseDeviceHandler.GetTechProfileInstanceFromParentAdapter(ctx, uniID, tpPath) |
| 1509 | if err == nil && iaTechTpInst != nil { |
| 1510 | logger.Debugw(ctx, "reconciling - store Tp instance", log.Fields{"uniID": uniID, "tpID": tpID, |
| 1511 | "*iaTechTpInst": iaTechTpInst, "device-id": oo.deviceID}) |
| 1512 | oo.ReconciledTpInstances[uniID][tpID] = *iaTechTpInst |
| 1513 | } else { |
| 1514 | // During the absence of the ONU adapter there seem to have been TP specific configurations! |
| 1515 | // The no longer available TP and the associated flows must be deleted from the ONU KV store |
| 1516 | // and after a MIB reset a new reconciling attempt with OMCI configuration must be started. |
| 1517 | allTpInstPresent = false |
| 1518 | logger.Infow(ctx, "reconciling - can't get tp instance - delete tp and associated flows", |
| 1519 | log.Fields{"tp-id": tpID, "tpPath": tpPath, "uni-id": uniID, "device-id": oo.deviceID, "err": err}) |
| 1520 | delete(oo.SOnuPersistentData.PersUniConfig[indexUni].PersTpPathMap, tpID) |
| 1521 | flowSlice := oo.SOnuPersistentData.PersUniConfig[indexUni].PersFlowParams |
| 1522 | for indexFlow, flowData := range flowSlice { |
| 1523 | if flowData.VlanRuleParams.TpID == tpID { |
| 1524 | if len(flowSlice) == 1 { |
| 1525 | flowSlice = []cmn.UniVlanFlowParams{} |
| 1526 | } else { |
| 1527 | flowSlice = append(flowSlice[:indexFlow], flowSlice[indexFlow+1:]...) |
| 1528 | } |
| 1529 | oo.SOnuPersistentData.PersUniConfig[indexUni].PersFlowParams = flowSlice |
| 1530 | } |
| 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | } |
| 1535 | } |
| 1536 | oo.MutexReconciledTpInstances.Unlock() |
| 1537 | oo.MutexPersOnuConfig.Unlock() |
| 1538 | return allTpInstPresent |
| 1539 | } |
| 1540 | |
nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1541 | // CancelProcessing terminates potentially running reconciling processes and stops the FSM |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 1542 | func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) { |
Holger Hildebrandt | 12609a1 | 2022-03-25 13:23:25 +0000 | [diff] [blame] | 1543 | logger.Debugw(ctx, "CancelProcessing entered", log.Fields{"device-id": oo.deviceID}) |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1544 | if oo.isReconcilingFlows() { |
Holger Hildebrandt | f2fcdd4 | 2021-12-15 11:42:19 +0000 | [diff] [blame] | 1545 | oo.SendChReconcilingFlowsFinished(ctx, false) |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 1546 | } |
| 1547 | //the MibSync FSM might be active all the ONU-active time, |
| 1548 | // hence it must be stopped unconditionally |
Girish Gowdra | 37c9d91 | 2022-02-08 16:24:57 -0800 | [diff] [blame] | 1549 | oo.mutexMibSyncMsgProcessorRunning.RLock() |
| 1550 | defer oo.mutexMibSyncMsgProcessorRunning.RUnlock() |
| 1551 | if oo.mibSyncMsgProcessorRunning { |
| 1552 | pMibUlFsm := oo.PMibUploadFsm |
| 1553 | if pMibUlFsm != nil { |
| 1554 | // abort running message processing |
| 1555 | fsmAbortMsg := cmn.Message{ |
| 1556 | Type: cmn.TestMsg, |
| 1557 | Data: cmn.TestMessage{ |
| 1558 | TestMessageVal: cmn.AbortMessageProcessing, |
| 1559 | }, |
| 1560 | } |
| 1561 | pMibUlFsm.CommChan <- fsmAbortMsg |
| 1562 | _ = pMibUlFsm.PFsm.Event(UlEvStop) |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 1563 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 1564 | } |
| 1565 | } |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 1566 | |
| 1567 | // Updates Serial Number and MAC Address in the database |
| 1568 | func (oo *OnuDeviceEntry) updateOnuSpecificEntries(ctx context.Context) { |
| 1569 | knownAttributeMEDb := oo.pOnuDB.CommonMeDb.MeDb |
| 1570 | |
| 1571 | for firstLevelKey, firstLevelValue := range knownAttributeMEDb { |
| 1572 | classID := strconv.Itoa(int(firstLevelKey)) |
| 1573 | |
| 1574 | for secondLevelKey, secondLevelValue := range firstLevelValue { |
| 1575 | switch classID { |
| 1576 | case "6", "256": |
| 1577 | oo.updateAttribute(ctx, "SerialNumber", secondLevelValue, firstLevelKey, secondLevelKey, oo.SOnuPersistentData.PersSerialNumber) |
| 1578 | case "134": |
| 1579 | oo.updateAttribute(ctx, "MacAddress", secondLevelValue, firstLevelKey, secondLevelKey, oo.SOnuPersistentData.PersMacAddress) |
| 1580 | } |
| 1581 | } |
| 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | // Updates a specific attribute in the MIB database |
| 1586 | func (oo *OnuDeviceEntry) updateAttribute(ctx context.Context, attributeName string, attributesMap me.AttributeValueMap, classID me.ClassID, entityID uint16, newValue interface{}) { |
| 1587 | if _, exists := attributesMap[attributeName]; exists { |
| 1588 | logger.Infow(ctx, "Updating "+attributeName, log.Fields{"classID": strconv.Itoa(int(classID)), "oldValue": attributesMap[attributeName], "newValue": newValue}) |
| 1589 | attributeCopy := make(me.AttributeValueMap) |
| 1590 | for k, v := range attributesMap { |
| 1591 | attributeCopy[k] = v |
| 1592 | } |
| 1593 | attributeCopy[attributeName] = newValue |
| 1594 | oo.pOnuDB.PutOnuSpeficMe(ctx, classID, entityID, attributeCopy) |
| 1595 | } else { |
| 1596 | logger.Warnw(ctx, attributeName+" key not found", log.Fields{"classID": strconv.Itoa(int(classID))}) |
| 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | // Processes the MIB template by replacing tokens and unmarshaling it |
| 1601 | func (oo *OnuDeviceEntry) processMibTemplate(ctx context.Context, value *kvstore.KVPair) { |
| 1602 | mibTmpString, _ := kvstore.ToString(value.Value) |
| 1603 | mibTmpString2 := strings.ReplaceAll(mibTmpString, "\x00", "") |
| 1604 | mibTmpBytes := []byte(mibTmpString2) |
| 1605 | |
| 1606 | logger.Debugf(ctx, "MibSync FSM - Mib template tokens swapped out: %s", mibTmpBytes) |
| 1607 | |
| 1608 | var firstLevelMap map[string]interface{} |
| 1609 | if err := json.Unmarshal(mibTmpBytes, &firstLevelMap); err != nil { |
| 1610 | logger.Errorw(ctx, "MibSync FSM - Failed to unmarshal template", log.Fields{"error": err, "device-id": oo.deviceID}) |
| 1611 | return |
| 1612 | } |
| 1613 | |
| 1614 | cmnMEDbValue, _ := oo.pOpenOnuAc.CreateEntryAtMibDatabaseMap(ctx, oo.mibTemplatePath) |
| 1615 | oo.populateMibDatabase(ctx, cmnMEDbValue, firstLevelMap) |
| 1616 | cmnMEDbValue.MIBUploadStatus = devdb.Completed |
| 1617 | oo.pOnuDB.CommonMeDb = cmnMEDbValue |
| 1618 | } |
| 1619 | |
| 1620 | // Populates the MIB database with parsed data |
| 1621 | func (oo *OnuDeviceEntry) populateMibDatabase(ctx context.Context, cmnMEDbValue *devdb.OnuCmnMEDB, firstLevelMap map[string]interface{}) { |
| 1622 | cmnMEDbValue.MeDbLock.Lock() |
| 1623 | defer cmnMEDbValue.MeDbLock.Unlock() |
| 1624 | |
| 1625 | logger.Infow(ctx, "Populating MIbDatabase with the template information ", log.Fields{"device-id": oo.deviceID}) |
| 1626 | for firstLevelKey, firstLevelValue := range firstLevelMap { |
| 1627 | if uint16ValidNumber, err := strconv.ParseUint(firstLevelKey, 10, 16); err == nil { |
| 1628 | meClassID := me.ClassID(uint16ValidNumber) |
| 1629 | if isSupportedClassID(meClassID) { |
| 1630 | secondLevelMap := firstLevelValue.(map[string]interface{}) |
| 1631 | for secondLevelKey, secondLevelValue := range secondLevelMap { |
| 1632 | if uint16ValidNumber, err := strconv.ParseUint(secondLevelKey, 10, 16); err == nil { |
| 1633 | meEntityID := uint16(uint16ValidNumber) |
| 1634 | thirdLevelMap := secondLevelValue.(map[string]interface{}) |
| 1635 | if attributes, exists := thirdLevelMap["Attributes"].(map[string]interface{}); exists { |
| 1636 | if _, found := cmnMEDbValue.MeDb[meClassID]; !found { |
| 1637 | cmnMEDbValue.MeDb[meClassID] = make(map[uint16]me.AttributeValueMap) |
| 1638 | } |
| 1639 | if _, found := cmnMEDbValue.MeDb[meClassID][meEntityID]; !found { |
| 1640 | cmnMEDbValue.MeDb[meClassID][meEntityID] = make(me.AttributeValueMap) |
| 1641 | } |
| 1642 | for attrKey, attrValue := range attributes { |
| 1643 | cmnMEDbValue.MeDb[meClassID][meEntityID][attrKey] = attrValue |
| 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | } |
| 1648 | } |
| 1649 | } |
| 1650 | } |
| 1651 | } |
| 1652 | } |