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