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