| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1 | /* |
| Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 2 | * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 17 | // Package core provides the utility for onu devices, flows and statistics |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 18 | package core |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 22 | "errors" |
| 23 | "fmt" |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 24 | "strconv" |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 25 | "sync" |
| 26 | "time" |
| 27 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 28 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config" |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 29 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 30 | "github.com/gogo/protobuf/proto" |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 31 | "github.com/looplab/fsm" |
| mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 32 | me "github.com/opencord/omci-lib-go/v2/generated" |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 33 | "github.com/opencord/voltha-lib-go/v7/pkg/db" |
| 34 | "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif" |
| 35 | flow "github.com/opencord/voltha-lib-go/v7/pkg/flows" |
| 36 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| 37 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 38 | platform "github.com/opencord/voltha-lib-go/v7/pkg/platform" |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 39 | almgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/almgr" |
| 40 | avcfg "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/avcfg" |
| 41 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
| 42 | mib "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/mib" |
| 43 | otst "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/omcitst" |
| 44 | pmmgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/pmmgr" |
| 45 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/swupg" |
| 46 | uniprt "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/uniprt" |
| kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 47 | "github.com/opencord/voltha-protos/v5/go/common" |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 48 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 49 | "github.com/opencord/voltha-protos/v5/go/extension" |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 50 | ia "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 51 | of "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 52 | oop "github.com/opencord/voltha-protos/v5/go/openolt" |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 53 | "github.com/opencord/voltha-protos/v5/go/tech_profile" |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 54 | "github.com/opencord/voltha-protos/v5/go/voltha" |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 55 | "google.golang.org/grpc/codes" |
| 56 | "google.golang.org/grpc/status" |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 57 | ) |
| 58 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 59 | const ( |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 60 | //constants for reconcile flow check channel |
| 61 | cWaitReconcileFlowAbortOnSuccess = 0xFFFD |
| 62 | cWaitReconcileFlowAbortOnError = 0xFFFE |
| 63 | cWaitReconcileFlowNoActivity = 0xFFFF |
| 64 | ) |
| 65 | |
| 66 | const ( |
| 67 | // constants for timeouts |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 68 | cTimeOutRemoveUpgrade = 1 //for usage in seconds |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 69 | ) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 70 | |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 71 | const ( |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 72 | // dummy constant - irregular value for ConnState - used to avoiding setting this state in the updateDeviceState() |
| 73 | // should better be defined in voltha protobuf or best solution would be to define an interface to just set the OperState |
| 74 | // as long as such is not available by the libraries - use this workaround |
| 75 | connectStatusINVALID = 255 // as long as not used as key in voltha.ConnectStatus_Types_name |
| 76 | ) |
| 77 | |
| 78 | const ( |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 79 | // events of Device FSM |
| 80 | devEvDeviceInit = "devEvDeviceInit" |
| 81 | devEvGrpcConnected = "devEvGrpcConnected" |
| 82 | devEvGrpcDisconnected = "devEvGrpcDisconnected" |
| 83 | devEvDeviceUpInd = "devEvDeviceUpInd" |
| 84 | devEvDeviceDownInd = "devEvDeviceDownInd" |
| 85 | ) |
| 86 | const ( |
| 87 | // states of Device FSM |
| 88 | devStNull = "devStNull" |
| 89 | devStDown = "devStDown" |
| 90 | devStInit = "devStInit" |
| 91 | devStConnected = "devStConnected" |
| 92 | devStUp = "devStUp" |
| 93 | ) |
| 94 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 95 | // Event category and subcategory definitions - same as defiend for OLT in eventmgr.go - should be done more centrally |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 96 | const ( |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 97 | pon = voltha.EventSubCategory_PON |
| 98 | //olt = voltha.EventSubCategory_OLT |
| 99 | //ont = voltha.EventSubCategory_ONT |
| 100 | //onu = voltha.EventSubCategory_ONU |
| 101 | //nni = voltha.EventSubCategory_NNI |
| 102 | //service = voltha.EventCategory_SERVICE |
| 103 | //security = voltha.EventCategory_SECURITY |
| 104 | equipment = voltha.EventCategory_EQUIPMENT |
| 105 | //processing = voltha.EventCategory_PROCESSING |
| 106 | //environment = voltha.EventCategory_ENVIRONMENT |
| 107 | //communication = voltha.EventCategory_COMMUNICATION |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 108 | ) |
| 109 | |
| 110 | const ( |
| 111 | cEventObjectType = "ONU" |
| 112 | ) |
| 113 | const ( |
| 114 | cOnuActivatedEvent = "ONU_ACTIVATED" |
| 115 | ) |
| 116 | |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 117 | type omciIdleCheckStruct struct { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 118 | omciIdleCheckFunc func(*deviceHandler, context.Context, cmn.UsedOmciConfigFsms, string) bool |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 119 | omciIdleState string |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 122 | var fsmOmciIdleStateFuncMap = map[cmn.UsedOmciConfigFsms]omciIdleCheckStruct{ |
| 123 | cmn.CUploadFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibUlFsmIdleState}, |
| 124 | cmn.CDownloadFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibDlFsmIdleState}, |
| 125 | cmn.CUniLockFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState}, |
| 126 | cmn.CUniUnLockFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState}, |
| 127 | cmn.CAniConfigFsm: {(*deviceHandler).isAniConfigFsmInOmciIdleState, avcfg.CAniFsmIdleState}, |
| 128 | cmn.CUniVlanConfigFsm: {(*deviceHandler).isUniVlanConfigFsmInOmciIdleState, avcfg.CVlanFsmIdleState}, |
| 129 | cmn.CL2PmFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, pmmgr.CL2PmFsmIdleState}, |
| 130 | cmn.COnuUpgradeFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, swupg.COnuUpgradeFsmIdleState}, |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 133 | const ( |
| 134 | cNoReconciling = iota |
| 135 | cOnuConfigReconciling |
| 136 | cSkipOnuConfigReconciling |
| 137 | ) |
| 138 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 139 | // FlowCb is the flow control block containing flow add/delete information along with a response channel |
| 140 | type FlowCb struct { |
| 141 | ctx context.Context // Flow handler context |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 142 | flowItem *of.OfpFlowStats |
| 143 | uniPort *cmn.OnuUniPort |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 144 | flowMetaData *of.FlowMetadata |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 145 | respChan *chan error // channel to report the Flow handling error |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 146 | addFlow bool // if true flow to be added, else removed |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 149 | // deviceHandler will interact with the ONU ? device. |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 150 | type deviceHandler struct { |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 151 | EventProxy eventif.EventProxy |
| 152 | |
| 153 | device *voltha.Device |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 154 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 155 | coreClient *vgrpc.Client |
| Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 156 | |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 157 | pmConfigs *voltha.PmConfigs |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 158 | config *config.AdapterFlags |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 159 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 160 | pOpenOnuAc *OpenONUAC |
| 161 | pDeviceStateFsm *fsm.FSM |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 162 | //pPonPort *voltha.Port |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 163 | deviceEntrySet chan bool //channel for DeviceEntry set event |
| 164 | pOnuOmciDevice *mib.OnuDeviceEntry |
| 165 | pOnuTP *avcfg.OnuUniTechProf |
| 166 | pOnuMetricsMgr *pmmgr.OnuMetricsManager |
| 167 | pAlarmMgr *almgr.OnuAlarmManager |
| 168 | pSelfTestHdlr *otst.SelfTestControlBlock |
| 169 | exitChannel chan int |
| 170 | pOnuIndication *oop.OnuIndication |
| 171 | pLockStateFsm *uniprt.LockStateFsm |
| 172 | pUnlockStateFsm *uniprt.LockStateFsm |
| 173 | |
| 174 | stopCollector chan bool |
| 175 | stopAlarmManager chan bool |
| 176 | stopHeartbeatCheck chan bool |
| 177 | uniEntityMap cmn.OnuUniPortMap |
| 178 | UniVlanConfigFsmMap map[uint8]*avcfg.UniVlanConfigFsm |
| 179 | pOnuUpradeFsm *swupg.OnuUpgradeFsm |
| 180 | chUniVlanConfigReconcilingDone chan uint16 //channel to indicate that VlanConfig reconciling for a specific UNI has been finished |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 181 | chUniVlanConfigOnRebootDone chan uint16 |
| 182 | chReconcilingFinished chan bool //channel to indicate that reconciling has been finished |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 183 | pLastUpgradeImageState *voltha.ImageState |
| 184 | upgradeFsmChan chan struct{} |
| 185 | |
| 186 | deviceDeleteCommChan chan bool |
| 187 | DeviceID string |
| 188 | DeviceType string |
| 189 | adminState string |
| 190 | logicalDeviceID string |
| 191 | ProxyAddressID string |
| 192 | ProxyAddressType string |
| 193 | parentID string |
| 194 | |
| 195 | flowCbChan []chan FlowCb |
| 196 | stopFlowMonitoringRoutine []chan bool // length of slice equal to number of uni ports |
| 197 | isFlowMonitoringRoutineActive []bool // length of slice equal to number of uni ports |
| 198 | reconcileExpiryComplete time.Duration |
| 199 | reconcileExpiryVlanConfig time.Duration |
| 200 | lockDevice sync.RWMutex |
| 201 | mutexDeviceReason sync.RWMutex |
| 202 | mutexCollectorFlag sync.RWMutex |
| 203 | mutextAlarmManagerFlag sync.RWMutex |
| 204 | lockVlanConfig sync.RWMutex |
| 205 | lockVlanAdd sync.RWMutex |
| 206 | lockUpgradeFsm sync.RWMutex |
| 207 | mutexReconcilingFlag sync.RWMutex |
| 208 | mutexReconcilingFirstPassFlag sync.RWMutex |
| 209 | mutexReconcilingReasonUpdate sync.RWMutex |
| 210 | mutexReadyForOmciConfig sync.RWMutex |
| 211 | mutexDeletionInProgressFlag sync.RWMutex |
| 212 | mutexFlowMonitoringRoutineFlag sync.RWMutex |
| 213 | mutexForDisableDeviceRequested sync.RWMutex |
| 214 | mutexOltAvailable sync.RWMutex |
| 215 | mutexKvStoreContext sync.Mutex |
| 216 | ponPortNumber uint32 |
| 217 | |
| 218 | deviceReason uint8 |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 219 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 220 | //flowMgr *OpenOltFlowMgr |
| 221 | //eventMgr *OpenOltEventMgr |
| 222 | //resourceMgr *rsrcMgr.OpenOltResourceMgr |
| 223 | |
| 224 | //discOnus sync.Map |
| 225 | //onus sync.Map |
| 226 | //portStats *OpenOltStatisticsMgr |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 227 | collectorIsRunning bool |
| 228 | alarmManagerIsRunning bool |
| 229 | upgradeCanceled bool |
| 230 | reconciling uint8 |
| 231 | reconcilingFirstPass bool |
| 232 | reconcilingReasonUpdate bool |
| 233 | readyForOmciConfig bool |
| 234 | deletionInProgress bool |
| 235 | disableDeviceRequested bool // this flag identify ONU received disable request or not |
| 236 | oltAvailable bool |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 239 | // newDeviceHandler creates a new device handler |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 240 | func newDeviceHandler(ctx context.Context, cc *vgrpc.Client, ep eventif.EventProxy, device *voltha.Device, adapter *OpenONUAC) *deviceHandler { |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 241 | var dh deviceHandler |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 242 | dh.coreClient = cc |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 243 | dh.EventProxy = ep |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 244 | dh.config = adapter.config |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 245 | cloned := (proto.Clone(device)).(*voltha.Device) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 246 | dh.DeviceID = cloned.Id |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 247 | dh.DeviceType = cloned.Type |
| 248 | dh.adminState = "up" |
| 249 | dh.device = cloned |
| 250 | dh.pOpenOnuAc = adapter |
| 251 | dh.exitChannel = make(chan int, 1) |
| 252 | dh.lockDevice = sync.RWMutex{} |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 253 | dh.deviceEntrySet = make(chan bool, 1) |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 254 | dh.collectorIsRunning = false |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 255 | dh.stopCollector = make(chan bool, 2) |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 256 | dh.alarmManagerIsRunning = false |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 257 | dh.stopAlarmManager = make(chan bool, 2) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 258 | dh.stopHeartbeatCheck = make(chan bool, 2) |
| 259 | //dh.metrics = pmmetrics.NewPmMetrics(cloned.Id, pmmetrics.Frequency(150), pmmetrics.FrequencyOverride(false), pmmetrics.Grouped(false), pmmetrics.Metrics(pmNames)) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 260 | //TODO initialize the support classes. |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 261 | dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 262 | dh.lockVlanConfig = sync.RWMutex{} |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 263 | dh.lockVlanAdd = sync.RWMutex{} |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 264 | dh.lockUpgradeFsm = sync.RWMutex{} |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 265 | dh.mutexForDisableDeviceRequested = sync.RWMutex{} |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 266 | dh.UniVlanConfigFsmMap = make(map[uint8]*avcfg.UniVlanConfigFsm) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 267 | dh.reconciling = cNoReconciling |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 268 | dh.reconcilingReasonUpdate = false |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 269 | dh.reconcilingFirstPass = true |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 270 | dh.disableDeviceRequested = false |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 271 | dh.oltAvailable = false |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 272 | dh.chReconcilingFinished = make(chan bool) |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 273 | dh.reconcileExpiryComplete = adapter.maxTimeoutReconciling //assumption is to have it as duration in s! |
| 274 | rECSeconds := int(dh.reconcileExpiryComplete / time.Second) |
| 275 | if rECSeconds < 2 { |
| 276 | dh.reconcileExpiryComplete = time.Duration(2) * time.Second //ensure a minimum expiry time of 2s for complete reconciling |
| 277 | rECSeconds = 2 |
| 278 | } |
| 279 | rEVCSeconds := rECSeconds / 2 |
| 280 | dh.reconcileExpiryVlanConfig = time.Duration(rEVCSeconds) * time.Second //set this duration to some according lower value |
| Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 281 | dh.readyForOmciConfig = false |
| Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 282 | dh.deletionInProgress = false |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 283 | dh.pLastUpgradeImageState = &voltha.ImageState{ |
| 284 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 285 | Reason: voltha.ImageState_UNKNOWN_ERROR, |
| 286 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 287 | } |
| 288 | dh.upgradeFsmChan = make(chan struct{}) |
| praneeth nalmas | f405e96 | 2023-08-07 15:02:03 +0530 | [diff] [blame] | 289 | dh.deviceDeleteCommChan = make(chan bool, 2) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 290 | |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 291 | if dh.device.PmConfigs != nil { // can happen after onu adapter restart |
| 292 | dh.pmConfigs = cloned.PmConfigs |
| 293 | } /* else { |
| 294 | // will be populated when onu_metrics_mananger is initialized. |
| 295 | }*/ |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 296 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 297 | // Device related state machine |
| 298 | dh.pDeviceStateFsm = fsm.NewFSM( |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 299 | devStNull, |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 300 | fsm.Events{ |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 301 | {Name: devEvDeviceInit, Src: []string{devStNull, devStDown}, Dst: devStInit}, |
| 302 | {Name: devEvGrpcConnected, Src: []string{devStInit}, Dst: devStConnected}, |
| 303 | {Name: devEvGrpcDisconnected, Src: []string{devStConnected, devStDown}, Dst: devStInit}, |
| 304 | {Name: devEvDeviceUpInd, Src: []string{devStConnected, devStDown}, Dst: devStUp}, |
| 305 | {Name: devEvDeviceDownInd, Src: []string{devStUp}, Dst: devStDown}, |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 306 | }, |
| 307 | fsm.Callbacks{ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 308 | "before_event": func(e *fsm.Event) { dh.logStateChange(ctx, e) }, |
| 309 | ("before_" + devEvDeviceInit): func(e *fsm.Event) { dh.doStateInit(ctx, e) }, |
| 310 | ("after_" + devEvDeviceInit): func(e *fsm.Event) { dh.postInit(ctx, e) }, |
| 311 | ("before_" + devEvGrpcConnected): func(e *fsm.Event) { dh.doStateConnected(ctx, e) }, |
| 312 | ("before_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.doStateInit(ctx, e) }, |
| 313 | ("after_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.postInit(ctx, e) }, |
| 314 | ("before_" + devEvDeviceUpInd): func(e *fsm.Event) { dh.doStateUp(ctx, e) }, |
| 315 | ("before_" + devEvDeviceDownInd): func(e *fsm.Event) { dh.doStateDown(ctx, e) }, |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 316 | }, |
| 317 | ) |
| mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 318 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 319 | return &dh |
| 320 | } |
| 321 | |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 322 | // start save the device to the data model |
| 323 | func (dh *deviceHandler) start(ctx context.Context) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 324 | logger.Debugw(ctx, "starting-device-handler", log.Fields{"device": dh.device, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 325 | // Add the initial device to the local model |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 326 | logger.Debugw(ctx, "device-handler-started", log.Fields{"device": dh.device}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 329 | /* |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 330 | // stop stops the device dh. Not much to do for now |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 331 | func (dh *deviceHandler) stop(ctx context.Context) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 332 | logger.Debug("stopping-device-handler") |
| 333 | dh.exitChannel <- 1 |
| 334 | } |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 335 | */ |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 336 | |
| 337 | // ########################################################################################## |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 338 | // deviceHandler methods that implement the adapters interface requests ##### begin ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 339 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 340 | // adoptOrReconcileDevice adopts the ONU device |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 341 | func (dh *deviceHandler) adoptOrReconcileDevice(ctx context.Context, device *voltha.Device) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 342 | logger.Debugw(ctx, "adopt_or_reconcile_device", log.Fields{"device-id": device.Id, "Address": device.GetHostAndPort()}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 343 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 344 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"device-id": device.Id, "state": string(dh.pDeviceStateFsm.Current())}) |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 345 | |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 346 | if dh.pDeviceStateFsm.Is(devStNull) { |
| 347 | if err := dh.pDeviceStateFsm.Event(devEvDeviceInit); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 348 | logger.Errorw(ctx, "Device FSM: Can't go to state DeviceInit", log.Fields{"device-id": device.Id, "err": err}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 349 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 350 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"device-id": device.Id, "state": string(dh.pDeviceStateFsm.Current())}) |
| Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 351 | // device.PmConfigs is not nil in cases when adapter restarts. We should not re-set the core again. |
| 352 | if device.PmConfigs == nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 353 | // Now, set the initial PM configuration for that device |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 354 | if err := dh.updatePMConfigInCore(ctx, dh.pmConfigs); err != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 355 | logger.Errorw(ctx, "error updating pm config to core", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 356 | } |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 357 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 358 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 359 | logger.Debugw(ctx, "AdoptOrReconcileDevice: Agent/device init already done", log.Fields{"device-id": device.Id}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 364 | func (dh *deviceHandler) handleOMCIIndication(ctx context.Context, msg *ia.OmciMessage) error { |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 365 | /* msg print moved symmetrically to omci_cc, if wanted here as additional debug, than perhaps only based on additional debug setting! |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 366 | //assuming omci message content is hex coded! |
| 367 | // with restricted output of 16(?) bytes would be ...omciMsg.Message[:16] |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 368 | logger.Debugw(ctx, "inter-adapter-recv-omci", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 369 | "device-id": dh.DeviceID, "RxOmciMessage": hex.EncodeToString(omciMsg.Message)}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 370 | */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 371 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 372 | if pDevEntry != nil { |
| Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 373 | if pDevEntry.PDevOmciCC != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 374 | return pDevEntry.PDevOmciCC.ReceiveMessage(log.WithSpanFromContext(context.TODO(), ctx), msg.Message) |
| Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 375 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 376 | logger.Debugw(ctx, "omciCC not ready to receive omci messages - incoming omci message ignored", log.Fields{"device-id": dh.DeviceID, |
| 377 | "rxMsg": msg.Message}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 378 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 379 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 380 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 381 | } |
| 382 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 383 | func (dh *deviceHandler) handleTechProfileDownloadRequest(ctx context.Context, techProfMsg *ia.TechProfileDownloadMessage) error { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 384 | logger.Infow(ctx, "tech-profile-download-request", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 385 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 386 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 387 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 388 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 389 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 390 | } |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 391 | dh.lockDevice.RLock() |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 392 | if dh.pOnuTP == nil { |
| 393 | //should normally not happen ... |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 394 | logger.Errorw(ctx, "onuTechProf instance not set up for DLMsg request - ignoring request", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 395 | log.Fields{"device-id": dh.DeviceID}) |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 396 | dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 397 | return fmt.Errorf("techProfile DLMsg request while onuTechProf instance not setup: %s", dh.DeviceID) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 398 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 399 | if !dh.IsReadyForOmciConfig() { |
| 400 | logger.Errorw(ctx, "TechProf-set rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 401 | "device-state": dh.GetDeviceReasonString()}) |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 402 | dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 403 | return fmt.Errorf("improper device state %s on device %s", dh.GetDeviceReasonString(), dh.DeviceID) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 404 | } |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 405 | //previous state test here was just this one, now extended for more states to reject the SetRequest: |
| 406 | // at least 'mib-downloaded' should be reached for processing of this specific ONU configuration |
| 407 | // if (dh.deviceReason == "stopping-openomci") || (dh.deviceReason == "omci-admin-lock") |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 408 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 409 | // we have to lock access to TechProfile processing based on different messageType calls or |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 410 | // even to fast subsequent calls of the same messageType as well as OnuKVStore processing due |
| 411 | // to possible concurrent access by flow processing |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 412 | dh.pOnuTP.LockTpProcMutex() |
| 413 | defer dh.pOnuTP.UnlockTpProcMutex() |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 414 | defer dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 415 | |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 416 | if techProfMsg.UniId >= platform.MaxUnisPerOnu { |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 417 | return fmt.Errorf("received UniId value exceeds range: %d, device-id: %s", |
| 418 | techProfMsg.UniId, dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 419 | } |
| 420 | uniID := uint8(techProfMsg.UniId) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 421 | tpID, err := cmn.GetTpIDFromTpPath(techProfMsg.TpInstancePath) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 422 | if err != nil { |
| Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 423 | logger.Errorw(ctx, "error-parsing-tpid-from-tppath", |
| 424 | log.Fields{"device-id": dh.DeviceID, "err": err, "tp-path": techProfMsg.TpInstancePath}) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 425 | return err |
| 426 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 427 | logger.Debugw(ctx, "unmarshal-techprof-msg-body", log.Fields{"device-id": dh.DeviceID, |
| 428 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 429 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 430 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, uint8(tpID), techProfMsg.TpInstancePath); bTpModify { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 431 | |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 432 | switch tpInst := techProfMsg.TechTpInstance.(type) { |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 433 | case *ia.TechProfileDownloadMessage_TpInstance: |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 434 | logger.Debugw(ctx, "onu-uni-tp-path-modified", log.Fields{"device-id": dh.DeviceID, |
| 435 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 436 | |
| 437 | err = dh.CheckAvailableOnuCapabilities(ctx, pDevEntry, *tpInst.TpInstance) |
| 438 | if err != nil { |
| 439 | logger.Errorw(ctx, "error-checking-available-onu-capabilities-stopping-device", |
| 440 | log.Fields{"device-id": dh.DeviceID, "err": err, "tp-path": techProfMsg.TpInstancePath}) |
| 441 | // stopping all further processing |
| 442 | _ = dh.UpdateInterface(ctx) |
| 443 | return err |
| 444 | } |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 445 | // if there has been some change for some uni TechProfilePath |
| 446 | //in order to allow concurrent calls to other dh instances we do not wait for execution here |
| 447 | //but doing so we can not indicate problems to the caller (who does what with that then?) |
| 448 | //by now we just assume straightforward successful execution |
| 449 | //TODO!!! Generally: In this scheme it would be good to have some means to indicate |
| 450 | // possible problems to the caller later autonomously |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 451 | |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 452 | // deadline context to ensure completion of background routines waited for |
| 453 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 454 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 455 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 456 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 457 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 458 | |
| 459 | var wg sync.WaitGroup |
| 460 | wg.Add(1) // for the 1 go routine to finish |
| 461 | // attention: deadline completion check and wg.Done is to be done in both routines |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 462 | go dh.pOnuTP.ConfigureUniTp(log.WithSpanFromContext(dctx, ctx), uniID, techProfMsg.TpInstancePath, *tpInst.TpInstance, &wg) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 463 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfDwld") //wait for background process to finish |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 464 | if tpErr := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); tpErr != nil { |
| 465 | logger.Errorw(ctx, "error-processing-tp", log.Fields{"device-id": dh.DeviceID, "err": tpErr, "tp-path": techProfMsg.TpInstancePath}) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 466 | return tpErr |
| 467 | } |
| 468 | deadline = time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 469 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 470 | defer cancel2() |
| 471 | err1 := pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx)) |
| 472 | if err1 != nil { |
| 473 | logger.Errorf(ctx, "UpdateOnuKvStore-failed", log.Fields{"device-id": dh.DeviceID, "error": err1}) |
| 474 | return err |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 475 | } |
| 476 | return nil |
| 477 | default: |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 478 | logger.Errorw(ctx, "unsupported-tp-instance-type", log.Fields{"device-id": dh.DeviceID, "tp-path": techProfMsg.TpInstancePath}) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 479 | return fmt.Errorf("unsupported-tp-instance-type--tp-id-%v", techProfMsg.TpInstancePath) |
| Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 480 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 481 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 482 | // no change, nothing really to do - return success |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 483 | logger.Debugw(ctx, "onu-uni-tp-path-not-modified", log.Fields{"device-id": dh.DeviceID, |
| 484 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 485 | return nil |
| 486 | } |
| 487 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 488 | func (dh *deviceHandler) handleDeleteGemPortRequest(ctx context.Context, delGemPortMsg *ia.DeleteGemPortMessage) error { |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 489 | logger.Infow(ctx, "delete-gem-port-request start", log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 490 | |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 491 | dh.lockDevice.RLock() |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 492 | if dh.pOnuTP == nil { |
| 493 | //should normally not happen ... |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 494 | logger.Warnw(ctx, "onuTechProf instance not set up for DelGem request - ignoring request", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 495 | log.Fields{"device-id": dh.DeviceID}) |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 496 | dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 497 | return fmt.Errorf("techProfile DelGem request while onuTechProf instance not setup: %s", dh.DeviceID) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 498 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 499 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 500 | dh.pOnuTP.LockTpProcMutex() |
| 501 | defer dh.pOnuTP.UnlockTpProcMutex() |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 502 | defer dh.lockDevice.RUnlock() |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 503 | |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 504 | if delGemPortMsg.UniId >= platform.MaxUnisPerOnu { |
| 505 | logger.Errorw(ctx, "delete-gem-port UniId exceeds range", log.Fields{ |
| 506 | "device-id": dh.DeviceID, "uni-id": delGemPortMsg.UniId}) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 507 | return fmt.Errorf("received UniId value exceeds range: %d, device-id: %s", |
| 508 | delGemPortMsg.UniId, dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 509 | } |
| 510 | uniID := uint8(delGemPortMsg.UniId) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 511 | tpID, err := cmn.GetTpIDFromTpPath(delGemPortMsg.TpInstancePath) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 512 | if err != nil { |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 513 | logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{ |
| 514 | "device-id": dh.DeviceID, "err": err, "tp-path": delGemPortMsg.TpInstancePath}) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 515 | return err |
| 516 | } |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 517 | logger.Infow(ctx, "delete-gem-port-request", log.Fields{ |
| 518 | "device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "gem": delGemPortMsg.GemPortId}) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 519 | //a removal of some GemPort would never remove the complete TechProfile entry (done on T-Cont) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 520 | |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 521 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delGemPortMsg.TpInstancePath, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 522 | avcfg.CResourceGemPort, delGemPortMsg.GemPortId) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 523 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 524 | } |
| 525 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 526 | func (dh *deviceHandler) handleDeleteTcontRequest(ctx context.Context, delTcontMsg *ia.DeleteTcontMessage) error { |
| Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 527 | logger.Infow(ctx, "delete-tcont-request start", log.Fields{"device-id": dh.DeviceID, "uni-id": delTcontMsg.UniId, "tcont": delTcontMsg.AllocId}) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 528 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 529 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 530 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 531 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 532 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 533 | } |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 534 | dh.lockDevice.RLock() |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 535 | if dh.pOnuTP == nil { |
| 536 | //should normally not happen ... |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 537 | logger.Warnw(ctx, "onuTechProf instance not set up for DelTcont request - ignoring request", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 538 | log.Fields{"device-id": dh.DeviceID}) |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 539 | dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 540 | return fmt.Errorf("techProfile DelTcont request while onuTechProf instance not setup: %s", dh.DeviceID) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 541 | } |
| 542 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 543 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 544 | dh.pOnuTP.LockTpProcMutex() |
| 545 | defer dh.pOnuTP.UnlockTpProcMutex() |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 546 | defer dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 547 | |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 548 | if delTcontMsg.UniId >= platform.MaxUnisPerOnu { |
| 549 | logger.Errorw(ctx, "delete-tcont UniId exceeds range", log.Fields{ |
| 550 | "device-id": dh.DeviceID, "uni-id": delTcontMsg.UniId}) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 551 | return fmt.Errorf("received UniId value exceeds range: %d, device-id: %s", |
| 552 | delTcontMsg.UniId, dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 553 | } |
| 554 | uniID := uint8(delTcontMsg.UniId) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 555 | tpPath := delTcontMsg.TpInstancePath |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 556 | tpID, err := cmn.GetTpIDFromTpPath(tpPath) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 557 | if err != nil { |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 558 | logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{ |
| 559 | "device-id": dh.DeviceID, "err": err, "tp-path": tpPath}) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 560 | return err |
| 561 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 562 | pDevEntry.FreeTcont(ctx, uint16(delTcontMsg.AllocId)) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 563 | |
| Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 564 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 565 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 566 | defer cancel() |
| Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 567 | logger.Debugw(ctx, "remove-tcont-in-kv", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "tcont": delTcontMsg.AllocId}) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 568 | err1 := pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx)) |
| 569 | if err1 != nil { |
| 570 | logger.Errorw(ctx, "UpdateOnuKvStore-failed", log.Fields{"device-id": dh.DeviceID, "err": err1}) |
| 571 | return err1 |
| Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 574 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delTcontMsg.TpInstancePath, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 575 | avcfg.CResourceTcont, delTcontMsg.AllocId) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 576 | |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 577 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 578 | |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 579 | func (dh *deviceHandler) deleteTechProfileResource(ctx context.Context, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 580 | uniID uint8, tpID uint8, pathString string, resource avcfg.ResourceEntry, entryID uint32) error { |
| 581 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 582 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 583 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 584 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 585 | } |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 586 | var resourceName string |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 587 | if avcfg.CResourceGemPort == resource { |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 588 | resourceName = "Gem" |
| 589 | } else { |
| 590 | resourceName = "Tcont" |
| 591 | } |
| 592 | |
| 593 | // deadline context to ensure completion of background routines waited for |
| 594 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 595 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 596 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 597 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 598 | |
| 599 | var wg sync.WaitGroup |
| 600 | wg.Add(1) // for the 1 go routine to finish |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 601 | go dh.pOnuTP.DeleteTpResource(log.WithSpanFromContext(dctx, ctx), uniID, tpID, pathString, |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 602 | resource, entryID, &wg) |
| 603 | dh.waitForCompletion(ctx, cancel, &wg, resourceName+"Delete") //wait for background process to finish |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 604 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); err != nil { |
| 605 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 606 | return err |
| 607 | } |
| 608 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 609 | if dh.pOnuTP.IsTechProfileConfigCleared(ctx, uniID, tpID) { |
| 610 | logger.Debugw(ctx, "techProfile-config-cleared", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID}) |
| 611 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, tpID, ""); bTpModify { |
| 612 | pDevEntry.ResetKvProcessingErrorIndication() |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 613 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 614 | defer cancel2() |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 615 | // Removal of the gem id mapping represents the removal of the tech profile |
| Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 616 | logger.Debugw(ctx, "remove-techProfile-indication-in-kv", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID}) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 617 | err := pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx)) |
| 618 | if err != nil { |
| 619 | logger.Errorw(ctx, "UpdateOnuKvStore-failed", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 620 | return err |
| 621 | } |
| 622 | } |
| 623 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 624 | logger.Debugw(ctx, "delete-tech-profile-resource-completed", log.Fields{"device-id": dh.DeviceID, |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 625 | "uni-id": uniID, "tpID": tpID, "resource-type": resourceName, "resource-id": entryID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 626 | return nil |
| 627 | } |
| 628 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 629 | // FlowUpdateIncremental removes and/or adds the flow changes on a given device |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 630 | func (dh *deviceHandler) FlowUpdateIncremental(ctx context.Context, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 631 | apOfFlowChanges *of.FlowChanges, |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 632 | apOfGroupChanges *of.FlowGroupChanges, apFlowMetaData *of.FlowMetadata) error { |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 633 | logger.Debugw(ctx, "FlowUpdateIncremental started", log.Fields{"device-id": dh.DeviceID, "flow": apOfFlowChanges, "metadata": apFlowMetaData}) |
| 634 | var errorsList []error |
| 635 | var retError error |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 636 | if dh.GetPersRebootFlag(ctx) { |
| 637 | logger.Warnw(ctx, "FlowUpdateIncremental ignored as deivce is being configured post reboot", log.Fields{"device-id": dh.DeviceID}) |
| 638 | return fmt.Errorf("errors-installing-one-or-more-flows-groups-reboot-in-progress") |
| 639 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 640 | //Remove flows (always remove flows first - remove old and add new with same cookie may be part of the same request) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 641 | if apOfFlowChanges.ToRemove != nil { |
| 642 | for _, flowItem := range apOfFlowChanges.ToRemove.Items { |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 643 | if flowItem.GetCookie() == 0 { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 644 | logger.Warnw(ctx, "flow-remove no cookie: ignore and continuing on checking further flows", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 645 | "device-id": dh.DeviceID}) |
| 646 | retError = fmt.Errorf("flow-remove no cookie, device-id %s", dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 647 | errorsList = append(errorsList, retError) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 648 | continue |
| 649 | } |
| 650 | flowInPort := flow.GetInPort(flowItem) |
| 651 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 652 | logger.Warnw(ctx, "flow-remove inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 653 | retError = fmt.Errorf("flow-remove inPort invalid, device-id %s", dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 654 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 655 | continue |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 656 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 657 | } else if flowInPort == dh.ponPortNumber { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 658 | //this is some downstream flow, not regarded as error, just ignored |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 659 | logger.Debugw(ctx, "flow-remove for downstream: ignore and continuing on checking further flows", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 660 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 661 | continue |
| 662 | } else { |
| 663 | // this is the relevant upstream flow |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 664 | var loUniPort *cmn.OnuUniPort |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 665 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 666 | loUniPort = uniPort |
| 667 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 668 | logger.Warnw(ctx, "flow-remove inPort not found in UniPorts: ignore and continuing on checking further flows", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 669 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 670 | retError = fmt.Errorf("flow-remove inPort not found in UniPorts, inPort %d, device-id %s", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 671 | flowInPort, dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 672 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 673 | continue |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 674 | } |
| 675 | flowOutPort := flow.GetOutPort(flowItem) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 676 | logger.Debugw(ctx, "flow-remove port indications", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 677 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 678 | "uniPortName": loUniPort.Name}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 679 | |
| 680 | if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) { |
| 681 | // Step1 : Fill flowControlBlock |
| 682 | // Step2 : Push the flowControlBlock to ONU channel |
| 683 | // Step3 : Wait on response channel for response |
| 684 | // Step4 : Return error value |
| 685 | startTime := time.Now() |
| 686 | respChan := make(chan error) |
| 687 | flowCb := FlowCb{ |
| 688 | ctx: ctx, |
| 689 | addFlow: false, |
| 690 | flowItem: flowItem, |
| 691 | flowMetaData: nil, |
| 692 | uniPort: loUniPort, |
| 693 | respChan: &respChan, |
| 694 | } |
| 695 | dh.flowCbChan[loUniPort.UniID] <- flowCb |
| 696 | logger.Infow(ctx, "process-flow-remove-start", log.Fields{"device-id": dh.DeviceID}) |
| 697 | // Wait on the channel for flow handlers return value |
| 698 | retError = <-respChan |
| 699 | logger.Infow(ctx, "process-flow-remove-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| 700 | if retError != nil { |
| 701 | logger.Warnw(ctx, "flow-delete processing error: continuing on checking further flows", |
| 702 | log.Fields{"device-id": dh.DeviceID, "error": retError}) |
| 703 | errorsList = append(errorsList, retError) |
| 704 | continue |
| 705 | } |
| 706 | } else { |
| 707 | retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID) |
| 708 | errorsList = append(errorsList, retError) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | } |
| 712 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 713 | if apOfFlowChanges.ToAdd != nil { |
| 714 | for _, flowItem := range apOfFlowChanges.ToAdd.Items { |
| 715 | if flowItem.GetCookie() == 0 { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 716 | logger.Debugw(ctx, "incremental flow-add no cookie: ignore and continuing on checking further flows", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 717 | "device-id": dh.DeviceID}) |
| 718 | retError = fmt.Errorf("flow-add no cookie, device-id %s", dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 719 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 720 | continue |
| 721 | } |
| 722 | flowInPort := flow.GetInPort(flowItem) |
| 723 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 724 | logger.Warnw(ctx, "flow-add inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 725 | retError = fmt.Errorf("flow-add inPort invalid, device-id %s", dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 726 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 727 | continue |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 728 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 729 | } else if flowInPort == dh.ponPortNumber { |
| 730 | //this is some downstream flow |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 731 | logger.Debugw(ctx, "flow-add for downstream: ignore and continuing on checking further flows", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 732 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 733 | continue |
| 734 | } else { |
| 735 | // this is the relevant upstream flow |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 736 | var loUniPort *cmn.OnuUniPort |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 737 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 738 | loUniPort = uniPort |
| 739 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 740 | logger.Warnw(ctx, "flow-add inPort not found in UniPorts: ignore and continuing on checking further flows", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 741 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 742 | retError = fmt.Errorf("flow-add inPort not found in UniPorts, inPort %d, device-id %s", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 743 | flowInPort, dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 744 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 745 | continue |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 746 | } |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 747 | // let's still assume that we receive the flow-add only in some 'active' device state (as so far observed) |
| 748 | // if not, we just throw some error here to have an indication about that, if we really need to support that |
| 749 | // then we would need to create some means to activate the internal stored flows |
| 750 | // after the device gets active automatically (and still with its dependency to the TechProfile) |
| 751 | // for state checking compare also code here: processInterAdapterTechProfileDownloadReqMessage |
| 752 | // also abort for the other still possible flows here |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 753 | if !dh.IsReadyForOmciConfig() { |
| 754 | logger.Errorw(ctx, "flow-add rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 755 | "last device-reason": dh.GetDeviceReasonString()}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 756 | retError = fmt.Errorf("improper device state on device %s", dh.DeviceID) |
| 757 | errorsList = append(errorsList, retError) |
| 758 | continue |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 761 | flowOutPort := flow.GetOutPort(flowItem) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 762 | logger.Debugw(ctx, "flow-add port indications", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 763 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 764 | "uniPortName": loUniPort.Name}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 765 | if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) { |
| 766 | // Step1 : Fill flowControlBlock |
| 767 | // Step2 : Push the flowControlBlock to ONU channel |
| 768 | // Step3 : Wait on response channel for response |
| 769 | // Step4 : Return error value |
| 770 | startTime := time.Now() |
| 771 | respChan := make(chan error) |
| 772 | flowCb := FlowCb{ |
| 773 | ctx: ctx, |
| 774 | addFlow: true, |
| 775 | flowItem: flowItem, |
| 776 | flowMetaData: apFlowMetaData, |
| 777 | uniPort: loUniPort, |
| 778 | respChan: &respChan, |
| 779 | } |
| 780 | dh.flowCbChan[loUniPort.UniID] <- flowCb |
| 781 | logger.Infow(ctx, "process-flow-add-start", log.Fields{"device-id": dh.DeviceID}) |
| 782 | // Wait on the channel for flow handlers return value |
| 783 | retError = <-respChan |
| 784 | logger.Infow(ctx, "process-flow-add-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| 785 | if retError != nil { |
| 786 | logger.Warnw(ctx, "flow-add processing error: continuing on checking further flows", |
| 787 | log.Fields{"device-id": dh.DeviceID, "error": retError}) |
| 788 | errorsList = append(errorsList, retError) |
| 789 | continue |
| 790 | } |
| 791 | } else { |
| 792 | retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID) |
| 793 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | } |
| 797 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 798 | if len(errorsList) > 0 { |
| 799 | logger.Errorw(ctx, "error-processing-flow", log.Fields{"device-id": dh.DeviceID, "errList": errorsList}) |
| 800 | return fmt.Errorf("errors-installing-one-or-more-flows-groups, errors:%v", errorsList) |
| 801 | } |
| 802 | return nil |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 805 | // disableDevice locks the ONU and its UNI/VEIP ports (admin lock via OMCI) |
| 806 | // following are the expected device states after this activity: |
| 807 | // Device Admin-State : down (on rwCore), Port-State: UNKNOWN, Conn-State: REACHABLE, Reason: omci-admin-lock |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 808 | // (Conn-State: REACHABLE might conflict with some previous ONU Down indication - maybe to be resolved later) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 809 | func (dh *deviceHandler) disableDevice(ctx context.Context, device *voltha.Device) { |
| 810 | logger.Debugw(ctx, "disable-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 811 | dh.mutexForDisableDeviceRequested.Lock() |
| 812 | dh.disableDeviceRequested = true |
| 813 | dh.mutexForDisableDeviceRequested.Unlock() |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 814 | //admin-lock reason can also be used uniquely for setting the DeviceState accordingly |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 815 | //note that disableDevice sequences in some 'ONU active' state may yield also |
| 816 | // "tech...delete-success" or "omci-flow-deleted" according to further received requests in the end |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 817 | // - inblock state checking to prevent possibly unneeded processing (on command repitition) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 818 | if dh.getDeviceReason() != cmn.DrOmciAdminLock { |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 819 | //disable-device shall be just a UNi/ONU-G related admin state setting |
| 820 | //all other configurations/FSM's shall not be impacted and shall execute as required by the system |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 821 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 822 | if dh.IsReadyForOmciConfig() { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 823 | // disable UNI ports/ONU |
| 824 | // *** should generate UniDisableStateDone event - used to disable the port(s) on success |
| 825 | if dh.pLockStateFsm == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 826 | dh.createUniLockFsm(ctx, true, cmn.UniDisableStateDone) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 827 | } else { //LockStateFSM already init |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 828 | dh.pLockStateFsm.SetSuccessEvent(cmn.UniDisableStateDone) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 829 | dh.runUniLockFsm(ctx, true) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 830 | } |
| 831 | } else { |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 832 | logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 833 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID}) |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 834 | // disable device should have no impact on ConnStatus |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 835 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 836 | DeviceId: dh.DeviceID, |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 837 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 838 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 839 | }); err != nil { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 840 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 841 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 842 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 843 | // DeviceReason to update acc.to modified py code as per beginning of Sept 2020 |
| Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 844 | |
| 845 | //TODO with VOL-3045/VOL-3046: catch and return error, valid for all occurrences in the codebase |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 846 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciAdminLock, true) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 847 | } |
| ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 851 | // reEnableDevice unlocks the ONU and its UNI/VEIP ports (admin unlock via OMCI) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 852 | func (dh *deviceHandler) reEnableDevice(ctx context.Context, device *voltha.Device) { |
| 853 | logger.Debugw(ctx, "reenable-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 854 | |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 855 | //setting readyForOmciConfig here is just a workaround for BBSIM testing in the sequence |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 856 | // OnuSoftReboot-disable-enable, because BBSIM does not generate a new OnuIndication-Up event after SoftReboot |
| 857 | // which is the assumption for real ONU's, where the ready-state is then set according to the following MibUpload/Download |
| 858 | // for real ONU's that should have nearly no influence |
| 859 | // Note that for real ONU's there is anyway a problematic situation with following sequence: |
| 860 | // OnuIndication-Dw (or not active at all) (- disable) - enable: here already the LockFsm may run into timeout (no OmciResponse) |
| 861 | // but that anyway is hopefully resolved by some OnuIndication-Up event (maybe to be tested) |
| 862 | // one could also argue, that a device-enable should also enable attempts for specific omci configuration |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 863 | dh.SetReadyForOmciConfig(true) //needed to allow subsequent flow/techProf config (on BBSIM) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 864 | |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 865 | // enable ONU/UNI ports |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 866 | // *** should generate cmn.UniEnableStateDone event - used to disable the port(s) on success |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 867 | dh.mutexForDisableDeviceRequested.Lock() |
| 868 | dh.disableDeviceRequested = false |
| 869 | dh.mutexForDisableDeviceRequested.Unlock() |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 870 | if dh.pUnlockStateFsm == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 871 | dh.createUniLockFsm(ctx, false, cmn.UniEnableStateDone) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 872 | } else { //UnlockStateFSM already init |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 873 | dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniEnableStateDone) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 874 | dh.runUniLockFsm(ctx, false) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 875 | } |
| ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 876 | } |
| 877 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 878 | func (dh *deviceHandler) reconcileDeviceOnuInd(ctx context.Context) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 879 | logger.Info(ctx, "reconciling - simulate onu indication", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 880 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 881 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 882 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 883 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 884 | return |
| 885 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 886 | if err := pDevEntry.RestoreDataFromOnuKvStore(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 887 | if err == fmt.Errorf("no-ONU-data-found") { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 888 | logger.Debugw(ctx, "no persistent data found - abort reconciling", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 889 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 890 | logger.Errorw(ctx, "reconciling - restoring OnuTp-data failed - abort", log.Fields{"err": err, "device-id": dh.DeviceID}) |
| mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 891 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 892 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 893 | return |
| Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 894 | } |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 895 | var onuIndication oop.OnuIndication |
| akashreddyk | b03dde0 | 2025-12-02 10:53:18 +0530 | [diff] [blame] | 896 | var rebootInProgress bool |
| 897 | var persUniUnlockDone bool |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 898 | pDevEntry.MutexPersOnuConfig.RLock() |
| 899 | onuIndication.IntfId = pDevEntry.SOnuPersistentData.PersIntfID |
| 900 | onuIndication.OnuId = pDevEntry.SOnuPersistentData.PersOnuID |
| 901 | onuIndication.OperState = pDevEntry.SOnuPersistentData.PersOperState |
| 902 | onuIndication.AdminState = pDevEntry.SOnuPersistentData.PersAdminState |
| akashreddyk | b03dde0 | 2025-12-02 10:53:18 +0530 | [diff] [blame] | 903 | rebootInProgress = pDevEntry.SOnuPersistentData.PersRebootInProgress |
| 904 | persUniUnlockDone = pDevEntry.SOnuPersistentData.PersUniUnlockDone |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 905 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| akashreddyk | b03dde0 | 2025-12-02 10:53:18 +0530 | [diff] [blame] | 906 | if rebootInProgress { |
| 907 | if persUniUnlockDone { |
| 908 | logger.Warnw(ctx, "ONU indication shows reboot in progress - cannot proceed with reconciliation", log.Fields{"device-id": dh.DeviceID}) |
| 909 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| 910 | return |
| 911 | } |
| 912 | } |
| 913 | if onuIndication.OperState == "up" { |
| 914 | if err := dh.createInterface(ctx, &onuIndication); err != nil { |
| 915 | logger.Errorw(ctx, "failed to handle device up indication", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| 916 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| 917 | return |
| 918 | } |
| 919 | } else { |
| 920 | logger.Warnw(ctx, "ONU indication does not have 'up' state, cannot proceed with reconciliation", log.Fields{"device-id": dh.DeviceID, "operState": onuIndication.OperState}) |
| 921 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| 922 | return |
| 923 | } |
| 924 | logger.Debugw(ctx, "reconciling - simulate onu indication done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 927 | func (dh *deviceHandler) ReconcileDeviceTechProf(ctx context.Context) bool { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 928 | logger.Info(ctx, "reconciling - trigger tech profile config", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 929 | |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 930 | continueWithFlowConfig := false |
| 931 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 932 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 933 | if pDevEntry == nil { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 934 | logger.Errorw(ctx, "reconciling - no valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 935 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| 936 | return continueWithFlowConfig |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 937 | } |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 938 | dh.lockDevice.RLock() |
| 939 | if dh.pOnuTP == nil { |
| 940 | //should normally not happen ... |
| 941 | logger.Warnw(ctx, "onuTechProf instance not set up for reconcile tech prof - ignoring request", |
| 942 | log.Fields{"device-id": dh.DeviceID}) |
| 943 | dh.lockDevice.RUnlock() |
| 944 | return continueWithFlowConfig |
| 945 | } |
| 946 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 947 | dh.pOnuTP.LockTpProcMutex() |
| 948 | defer dh.pOnuTP.UnlockTpProcMutex() |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 949 | defer dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 950 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 951 | pDevEntry.MutexPersOnuConfig.RLock() |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 952 | persMutexLock := true |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 953 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 954 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 955 | logger.Info(ctx, "reconciling - no uni-configs have been stored before adapter restart - terminate reconcilement", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 956 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 957 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| 958 | return continueWithFlowConfig |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 959 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 960 | flowsFound := false |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 961 | techProfsFound := false |
| 962 | techProfInstLoadFailed := false |
| 963 | outerLoop: |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 964 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 965 | uniID := uniData.PersUniID |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 966 | //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 967 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 968 | logger.Debugw(ctx, "reconciling - no TPs stored for uniID", |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 969 | log.Fields{"uni-id": uniID, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 970 | continue |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 971 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 972 | //release MutexPersOnuConfig before TechProfile (ANIConfig) processing as otherwise the reception of |
| 973 | // OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 974 | // frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 975 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 976 | persMutexLock = false |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 977 | techProfsFound = true // set to true if we found TP once for any UNI port |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 978 | var iaTechTpInst ia.TechProfileDownloadMessage |
| 979 | var ok bool |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 980 | for tpID := range uniData.PersTpPathMap { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 981 | pDevEntry.MutexReconciledTpInstances.RLock() |
| 982 | if iaTechTpInst, ok = pDevEntry.ReconciledTpInstances[uniID][tpID]; !ok { |
| 983 | logger.Errorw(ctx, "reconciling - no reconciled tp instance available", |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 984 | log.Fields{"tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 985 | "device-id": dh.DeviceID}) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 986 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 987 | pDevEntry.MutexReconciledTpInstances.RUnlock() |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 988 | break outerLoop |
| 989 | } |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 990 | pDevEntry.MutexReconciledTpInstances.RUnlock() |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 991 | continueWithFlowConfig = true // valid TP found - try flow configuration later |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 992 | var tpInst tech_profile.TechProfileInstance |
| 993 | switch techTpInst := iaTechTpInst.TechTpInstance.(type) { |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 994 | case *ia.TechProfileDownloadMessage_TpInstance: // supports only GPON, XGPON, XGS-PON |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 995 | tpInst = *techTpInst.TpInstance |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 996 | logger.Debugw(ctx, "reconciling - received-tp-instance-successfully-after-reconcile", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 997 | "tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 998 | default: // do not support epon or other tech |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 999 | logger.Errorw(ctx, "reconciling - unsupported-tech-profile", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1000 | "tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 1001 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 1002 | break outerLoop |
| 1003 | } |
| 1004 | |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 1005 | // deadline context to ensure completion of background routines waited for |
| 1006 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 1007 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1008 | dctx, cancel := context.WithDeadline(ctx, deadline) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1009 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1010 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniData.PersUniID, tpID) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 1011 | var wg sync.WaitGroup |
| 1012 | wg.Add(1) // for the 1 go routine to finish |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1013 | go dh.pOnuTP.ConfigureUniTp(log.WithSpanFromContext(dctx, ctx), uniData.PersUniID, uniData.PersTpPathMap[tpID], tpInst, &wg) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1014 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfReconcile") //wait for background process to finish |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1015 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniData.PersUniID, tpID); err != nil { |
| 1016 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 1017 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 1018 | break outerLoop |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 1019 | } |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1020 | } // for all TpPath entries for this UNI |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1021 | if len(uniData.PersFlowParams) != 0 { |
| 1022 | flowsFound = true |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1023 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1024 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1025 | persMutexLock = true |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1026 | } // for all UNI entries from SOnuPersistentData |
| 1027 | if persMutexLock { // if loop was left with MutexPersOnuConfig still set |
| 1028 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1029 | } |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1030 | |
| 1031 | //had to move techProf/flow result evaluation into separate function due to SCA complexity limit |
| 1032 | dh.updateReconcileStates(ctx, techProfsFound, techProfInstLoadFailed, flowsFound) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1033 | |
| 1034 | return continueWithFlowConfig |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | func (dh *deviceHandler) updateReconcileStates(ctx context.Context, |
| 1038 | abTechProfsFound bool, abTechProfInstLoadFailed bool, abFlowsFound bool) { |
| 1039 | if !abTechProfsFound { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1040 | logger.Warn(ctx, "reconciling - no TPs have been stored before adapter restart - terminate reconcilement", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1041 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1042 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1043 | return |
| 1044 | } |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1045 | if abTechProfInstLoadFailed { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1046 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadFailed, dh.IsReconcilingReasonUpdate()) |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1047 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 1048 | return |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1049 | } else if dh.IsSkipOnuConfigReconciling() { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1050 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, dh.IsReconcilingReasonUpdate()) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1051 | } |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1052 | if !abFlowsFound { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1053 | logger.Warn(ctx, "reconciling - no flows have been stored before adapter restart - terminate reconcilement", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1054 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1055 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1056 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1059 | func (dh *deviceHandler) ReconcileDeviceFlowConfig(ctx context.Context) { |
| 1060 | logger.Debugw(ctx, "reconciling - trigger flow config", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1061 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1062 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1063 | if pDevEntry == nil { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1064 | logger.Errorw(ctx, "reconciling - no valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1065 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1066 | return |
| 1067 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1068 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1069 | pDevEntry.MutexPersOnuConfig.RLock() |
| 1070 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 1071 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1072 | logger.Warn(ctx, "reconciling - no uni-configs have been stored before adapter restart - terminate reconcilement", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1073 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1074 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1075 | return |
| 1076 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1077 | flowsFound := false |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1078 | var uniVlanConfigEntries []uint8 |
| 1079 | var loWaitGroupWTO cmn.WaitGroupWithTimeOut |
| 1080 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1081 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1082 | //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support |
| 1083 | if len(uniData.PersFlowParams) == 0 { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1084 | logger.Debugw(ctx, "reconciling - no flows stored for uniID", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1085 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1086 | continue |
| 1087 | } |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1088 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1089 | logger.Warnw(ctx, "reconciling flows - but no TPs stored for uniID, abort", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1090 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 1091 | // It doesn't make sense to configure any flows if no TPs are available |
| 1092 | continue |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1093 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1094 | //release MutexPersOnuConfig before VlanConfig processing as otherwise the reception of |
| 1095 | // OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1096 | // frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1097 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1098 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1099 | var uniPort *cmn.OnuUniPort |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1100 | var exist bool |
| Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 1101 | uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), uint32(uniData.PersUniID)) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1102 | if uniPort, exist = dh.uniEntityMap[uniNo]; !exist { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1103 | logger.Errorw(ctx, "reconciling - OnuUniPort data not found - terminate reconcilement", |
| 1104 | log.Fields{"uniNo": uniNo, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1105 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1106 | return |
| 1107 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1108 | //needed to split up function due to sca complexity |
| 1109 | dh.updateReconcileFlowConfig(ctx, uniPort, uniData.PersFlowParams, uniVlanConfigEntries, &loWaitGroupWTO, &flowsFound) |
| 1110 | |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1111 | logger.Debugw(ctx, "reconciling - flows processed", log.Fields{ |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1112 | "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1113 | "NumUniFlows": dh.UniVlanConfigFsmMap[uniData.PersUniID].NumUniFlows, |
| 1114 | "ConfiguredUniFlow": dh.UniVlanConfigFsmMap[uniData.PersUniID].ConfiguredUniFlow}) |
| Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 1115 | // this can't be used as global finished reconciling flag because |
| 1116 | // assumes is getting called before the state machines for the last flow is completed, |
| 1117 | // while this is not guaranteed. |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1118 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| 1119 | } // for all UNI entries from SOnuPersistentData |
| 1120 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1121 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1122 | if !flowsFound { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1123 | logger.Warn(ctx, "reconciling - no flows have been stored before adapter restart - terminate reconcilement", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1124 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1125 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1126 | return |
| 1127 | } |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1128 | logger.Debugw(ctx, "reconciling flows - waiting on ready indication of requested UNIs", log.Fields{ |
| 1129 | "device-id": dh.DeviceID, "expiry": dh.reconcileExpiryVlanConfig}) |
| 1130 | if executed := loWaitGroupWTO.WaitTimeout(dh.reconcileExpiryVlanConfig); executed { |
| 1131 | logger.Debugw(ctx, "reconciling flows for all UNI's has been finished in time", |
| 1132 | log.Fields{"device-id": dh.DeviceID}) |
| 1133 | dh.stopReconciling(ctx, true, cWaitReconcileFlowAbortOnSuccess) |
| 1134 | if pDevEntry != nil { |
| 1135 | pDevEntry.SendChReconcilingFlowsFinished(ctx, true) |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1136 | } |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1137 | } else { |
| 1138 | logger.Errorw(ctx, "reconciling - timeout waiting for reconciling flows for all UNI's to be finished!", |
| 1139 | log.Fields{"device-id": dh.DeviceID}) |
| 1140 | dh.stopReconciling(ctx, false, cWaitReconcileFlowAbortOnError) |
| 1141 | if pDevEntry != nil { |
| 1142 | pDevEntry.SendChReconcilingFlowsFinished(ctx, false) |
| 1143 | } |
| 1144 | return |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1145 | } |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1146 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsPushed, dh.IsReconcilingReasonUpdate()) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1149 | func (dh *deviceHandler) updateReconcileFlowConfig(ctx context.Context, apUniPort *cmn.OnuUniPort, |
| 1150 | aPersFlowParam []cmn.UniVlanFlowParams, aUniVlanConfigEntries []uint8, |
| 1151 | apWaitGroup *cmn.WaitGroupWithTimeOut, apFlowsFound *bool) { |
| 1152 | flowsProcessed := 0 |
| 1153 | lastFlowToReconcile := false |
| 1154 | loUniID := apUniPort.UniID |
| 1155 | for _, flowData := range aPersFlowParam { |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1156 | if !(*apFlowsFound) { |
| 1157 | *apFlowsFound = true |
| 1158 | syncChannel := make(chan struct{}) |
| 1159 | // start go routine with select() on reconciling vlan config channel before |
| 1160 | // starting vlan config reconciling process to prevent loss of any signal |
| 1161 | // this routine just collects all the received 'flow-reconciled' signals - possibly from different UNI's |
| 1162 | go dh.waitOnUniVlanConfigReconcilingReady(ctx, syncChannel, apWaitGroup) |
| 1163 | //block until the wait routine is really blocked on channel input |
| 1164 | // in order to prevent to early ready signal from VlanConfig processing |
| 1165 | <-syncChannel |
| 1166 | } |
| 1167 | if flowsProcessed == len(aPersFlowParam)-1 { |
| 1168 | var uniAdded bool |
| 1169 | lastFlowToReconcile = true |
| 1170 | if aUniVlanConfigEntries, uniAdded = dh.appendIfMissing(aUniVlanConfigEntries, loUniID); uniAdded { |
| 1171 | apWaitGroup.Add(1) //increment the waiting group |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1172 | } |
| 1173 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1174 | logger.Debugw(ctx, "reconciling - add flow with cookie slice", log.Fields{ |
| 1175 | "device-id": dh.DeviceID, "uni-id": loUniID, |
| 1176 | "flowsProcessed": flowsProcessed, "cookies": flowData.CookieSlice}) |
| 1177 | dh.lockVlanConfig.Lock() |
| 1178 | //the CookieSlice can be passed 'by value' here, - which internally passes its reference |
| 1179 | if _, exist := dh.UniVlanConfigFsmMap[loUniID]; exist { |
| 1180 | if err := dh.UniVlanConfigFsmMap[loUniID].SetUniFlowParams(ctx, flowData.VlanRuleParams.TpID, |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 1181 | flowData.CookieSlice, uint16(flowData.VlanRuleParams.MatchVid), uint8(flowData.VlanRuleParams.MatchPcp), uint16(flowData.VlanRuleParams.SetVid), uint8(flowData.VlanRuleParams.SetPcp), flowData.VlanRuleParams.InnerCvlan, lastFlowToReconcile, false, flowData.Meter, nil); err != nil { |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1182 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1183 | } |
| 1184 | } else { |
| 1185 | if err := dh.createVlanFilterFsm(ctx, apUniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice, |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 1186 | uint16(flowData.VlanRuleParams.MatchVid), uint8(flowData.VlanRuleParams.MatchPcp), uint16(flowData.VlanRuleParams.SetVid), |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 1187 | uint8(flowData.VlanRuleParams.SetPcp), flowData.VlanRuleParams.InnerCvlan, cmn.OmciVlanFilterAddDone, lastFlowToReconcile, false, flowData.Meter, nil); err != nil { |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1188 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1189 | } |
| 1190 | } |
| 1191 | dh.lockVlanConfig.Unlock() |
| 1192 | flowsProcessed++ |
| 1193 | } //for all flows of this UNI |
| 1194 | } |
| 1195 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1196 | // waitOnUniVlanConfigReconcilingReady collects all VlanConfigReady signals from VlanConfig FSM processing in reconciling |
| 1197 | // |
| 1198 | // and decrements the according handler wait group waiting for these indications |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1199 | func (dh *deviceHandler) waitOnUniVlanConfigReconcilingReady(ctx context.Context, aSyncChannel chan<- struct{}, |
| 1200 | waitGroup *cmn.WaitGroupWithTimeOut) { |
| 1201 | var reconciledUniVlanConfigEntries []uint8 |
| 1202 | var appended bool |
| 1203 | expiry := dh.GetReconcileExpiryVlanConfigAbort() |
| 1204 | logger.Debugw(ctx, "start waiting on reconcile vlanConfig ready indications", log.Fields{ |
| 1205 | "device-id": dh.DeviceID, "expiry": expiry}) |
| 1206 | // indicate blocking on channel now to the caller |
| 1207 | aSyncChannel <- struct{}{} |
| 1208 | for { |
| 1209 | select { |
| 1210 | case uniIndication := <-dh.chUniVlanConfigReconcilingDone: |
| 1211 | switch uniIndication { |
| 1212 | // no activity requested (should normally not be received) - just continue waiting |
| 1213 | case cWaitReconcileFlowNoActivity: |
| 1214 | // waiting on channel inputs from VlanConfig for all UNI's to be aborted on error condition |
| 1215 | case cWaitReconcileFlowAbortOnError: |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1216 | logger.Warn(ctx, "waitReconcileFlow aborted on error", |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1217 | log.Fields{"device-id": dh.DeviceID, "rxEntries": reconciledUniVlanConfigEntries}) |
| 1218 | return |
| 1219 | // waiting on channel inputs from VlanConfig for all UNI's to be aborted on success condition |
| 1220 | case cWaitReconcileFlowAbortOnSuccess: |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1221 | logger.Warn(ctx, "waitReconcileFlow aborted on success", |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1222 | log.Fields{"device-id": dh.DeviceID, "rxEntries": reconciledUniVlanConfigEntries}) |
| 1223 | return |
| 1224 | // this should be a valid UNI vlan config done indication |
| 1225 | default: |
| 1226 | if uniIndication < platform.MaxUnisPerOnu { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1227 | logger.Info(ctx, "reconciling flows has been finished in time for this UNI", |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1228 | log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| 1229 | if reconciledUniVlanConfigEntries, appended = |
| 1230 | dh.appendIfMissing(reconciledUniVlanConfigEntries, uint8(uniIndication)); appended { |
| 1231 | waitGroup.Done() |
| 1232 | } |
| 1233 | } else { |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 1234 | logger.Errorw(ctx, "received unexpected UNI flowConfig done indication - is ignored", log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1235 | } |
| 1236 | } //switch uniIndication |
| 1237 | |
| 1238 | case <-time.After(expiry): //a bit longer than reconcileExpiryVlanConfig |
| 1239 | logger.Errorw(ctx, "timeout waiting for reconciling all UNI flows to be finished!", |
| 1240 | log.Fields{"device-id": dh.DeviceID}) |
| 1241 | return |
| 1242 | } |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | func (dh *deviceHandler) GetReconcileExpiryVlanConfigAbort() time.Duration { |
| 1247 | return dh.reconcileExpiryVlanConfig + (500 * time.Millisecond) |
| 1248 | } |
| 1249 | |
| 1250 | func (dh *deviceHandler) appendIfMissing(slice []uint8, val uint8) ([]uint8, bool) { |
| 1251 | for _, ele := range slice { |
| 1252 | if ele == val { |
| 1253 | return slice, false |
| 1254 | } |
| 1255 | } |
| 1256 | return append(slice, val), true |
| 1257 | } |
| 1258 | |
| 1259 | // sendChReconcileFinished - sends true or false on reconcileFinish channel |
| 1260 | func (dh *deviceHandler) sendChReconcileFinished(success bool) { |
| 1261 | if dh != nil { //if the object still exists (might have been already deleted in background) |
| 1262 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1263 | select { |
| 1264 | case dh.chReconcilingFinished <- success: |
| 1265 | default: |
| 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | // SendChUniVlanConfigFinished - sends the Uni number on channel if the flow reconcilement for this UNI is finished |
| 1271 | func (dh *deviceHandler) SendChUniVlanConfigFinished(value uint16) { |
| 1272 | if dh != nil { //if the object still exists (might have been already deleted in background) |
| 1273 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1274 | select { |
| 1275 | case dh.chUniVlanConfigReconcilingDone <- value: |
| 1276 | default: |
| 1277 | } |
| 1278 | } |
| 1279 | } |
| 1280 | |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 1281 | func (dh *deviceHandler) DeviceFlowConfigOnReboot(ctx context.Context) { |
| 1282 | logger.Debugw(ctx, "rebooting - trigger flow config", log.Fields{"device-id": dh.DeviceID}) |
| 1283 | |
| 1284 | defer dh.UpdateAndStoreRebootState(ctx, false) |
| 1285 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 1286 | if pDevEntry == nil { |
| 1287 | logger.Errorw(ctx, "rebooting - no valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 1288 | return |
| 1289 | } |
| 1290 | |
| 1291 | pDevEntry.MutexPersOnuConfig.RLock() |
| 1292 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 1293 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1294 | logger.Warn(ctx, "rebooting - no uni-configs have been stored - aborting", |
| 1295 | log.Fields{"device-id": dh.DeviceID}) |
| 1296 | return |
| 1297 | } |
| 1298 | flowsFound := false |
| 1299 | var uniVlanConfigEntries []uint8 |
| 1300 | var loWaitGroupWTO cmn.WaitGroupWithTimeOut |
| 1301 | |
| 1302 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
| 1303 | //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support |
| 1304 | if len(uniData.PersFlowParams) == 0 { |
| 1305 | logger.Debugw(ctx, "rebooting - no flows stored for uniID", |
| 1306 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| 1307 | continue |
| 1308 | } |
| 1309 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
| 1310 | logger.Warnw(ctx, "rebooting - but no TPs stored for uniID, abort", |
| 1311 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| 1312 | // It doesn't make sense to configure any flows if no TPs are available |
| 1313 | continue |
| 1314 | } |
| 1315 | //release MutexPersOnuConfig before VlanConfig processing as otherwise the reception of |
| 1316 | // OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI |
| 1317 | // frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap |
| 1318 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1319 | |
| 1320 | var uniPort *cmn.OnuUniPort |
| 1321 | var exist bool |
| 1322 | uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), uint32(uniData.PersUniID)) |
| 1323 | if uniPort, exist = dh.uniEntityMap[uniNo]; !exist { |
| 1324 | logger.Errorw(ctx, "rebooting - OnuUniPort data not found - terminate flow config", |
| 1325 | log.Fields{"uniNo": uniNo, "device-id": dh.DeviceID}) |
| 1326 | return |
| 1327 | } |
| 1328 | |
| 1329 | dh.updateOnRebootFlowConfig(ctx, uniPort, uniData.PersFlowParams, uniVlanConfigEntries, &loWaitGroupWTO, &flowsFound) |
| 1330 | |
| 1331 | logger.Debugw(ctx, "rebooting - flows processed", log.Fields{ |
| 1332 | "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, |
| 1333 | "NumUniFlows": dh.UniVlanConfigFsmMap[uniData.PersUniID].NumUniFlows, |
| 1334 | "ConfiguredUniFlow": dh.UniVlanConfigFsmMap[uniData.PersUniID].ConfiguredUniFlow}) |
| 1335 | // this can't be used as global finished reconciling flag because |
| 1336 | // assumes is getting called before the state machines for the last flow is completed, |
| 1337 | // while this is not guaranteed. |
| 1338 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| 1339 | } // for all UNI entries from SOnuPersistentData |
| 1340 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1341 | |
| 1342 | if !flowsFound { |
| 1343 | logger.Warn(ctx, "rebooting - no flows have been stored before device reboot - terminate flow config", |
| 1344 | log.Fields{"device-id": dh.DeviceID}) |
| 1345 | return |
| 1346 | } |
| 1347 | logger.Debugw(ctx, "rebooting - waiting on ready indication of requested UNIs", log.Fields{ |
| 1348 | "device-id": dh.DeviceID, "expiry": dh.reconcileExpiryVlanConfig}) |
| 1349 | if executed := loWaitGroupWTO.WaitTimeout(dh.reconcileExpiryVlanConfig); executed { |
| 1350 | logger.Debugw(ctx, "rebooting - flow config for all UNI's has been finished in time", |
| 1351 | log.Fields{"device-id": dh.DeviceID}) |
| 1352 | } else { |
| 1353 | logger.Errorw(ctx, "rebooting - timeout waiting for flow config for all UNI's to be finished!", |
| 1354 | log.Fields{"device-id": dh.DeviceID}) |
| 1355 | return |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | func (dh *deviceHandler) UpdateAndStoreRebootState(ctx context.Context, flag bool) { |
| 1360 | dh.UpdateRebootPersData(ctx, flag) |
| 1361 | if err := dh.StorePersistentData(ctx); err != nil { |
| 1362 | logger.Errorw(ctx, "rebooting - failed to store persistent data in kv store", log.Fields{"device-id": dh.DeviceID}) |
| 1363 | } |
| 1364 | } |
| 1365 | |
| 1366 | func (dh *deviceHandler) updateOnRebootFlowConfig(ctx context.Context, apUniPort *cmn.OnuUniPort, |
| 1367 | aPersFlowParam []cmn.UniVlanFlowParams, aUniVlanConfigEntries []uint8, |
| 1368 | apWaitGroup *cmn.WaitGroupWithTimeOut, apFlowsFound *bool) { |
| 1369 | flowsProcessed := 0 |
| 1370 | lastFlowToConfigOnReboot := false |
| 1371 | loUniID := apUniPort.UniID |
| 1372 | for _, flowData := range aPersFlowParam { |
| 1373 | if !(*apFlowsFound) { |
| 1374 | *apFlowsFound = true |
| 1375 | syncChannel := make(chan struct{}) |
| 1376 | // start go routine with select() on reconciling vlan config channel before |
| 1377 | // starting vlan config reconciling process to prevent loss of any signal |
| 1378 | // this routine just collects all the received 'flow-reconciled' signals - possibly from different UNI's |
| 1379 | go dh.waitOnUniVlanConfigOnRebootReady(ctx, syncChannel, apWaitGroup) |
| 1380 | //block until the wait routine is really blocked on channel input |
| 1381 | // in order to prevent to early ready signal from VlanConfig processing |
| 1382 | <-syncChannel |
| 1383 | } |
| 1384 | if flowsProcessed == len(aPersFlowParam)-1 { |
| 1385 | var uniAdded bool |
| 1386 | lastFlowToConfigOnReboot = true |
| 1387 | if aUniVlanConfigEntries, uniAdded = dh.appendIfMissing(aUniVlanConfigEntries, loUniID); uniAdded { |
| 1388 | apWaitGroup.Add(1) //increment the waiting group |
| 1389 | } |
| 1390 | } |
| 1391 | logger.Debugw(ctx, "rebooting - add flow with cookie slice", log.Fields{ |
| 1392 | "device-id": dh.DeviceID, "uni-id": loUniID, |
| 1393 | "flowsProcessed": flowsProcessed, "cookies": flowData.CookieSlice}) |
| 1394 | dh.lockVlanConfig.Lock() |
| 1395 | //the CookieSlice can be passed 'by value' here, - which internally passes its reference |
| 1396 | if _, exist := dh.UniVlanConfigFsmMap[loUniID]; exist { |
| 1397 | if err := dh.UniVlanConfigFsmMap[loUniID].SetUniFlowParams(ctx, flowData.VlanRuleParams.TpID, |
| 1398 | flowData.CookieSlice, uint16(flowData.VlanRuleParams.MatchVid), uint8(flowData.VlanRuleParams.MatchPcp), uint16(flowData.VlanRuleParams.SetVid), uint8(flowData.VlanRuleParams.SetPcp), flowData.VlanRuleParams.InnerCvlan, false, lastFlowToConfigOnReboot, flowData.Meter, nil); err != nil { |
| 1399 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1400 | } |
| 1401 | } else { |
| 1402 | if err := dh.createVlanFilterFsm(ctx, apUniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice, |
| 1403 | uint16(flowData.VlanRuleParams.MatchVid), uint8(flowData.VlanRuleParams.MatchPcp), uint16(flowData.VlanRuleParams.SetVid), |
| 1404 | uint8(flowData.VlanRuleParams.SetPcp), flowData.VlanRuleParams.InnerCvlan, cmn.OmciVlanFilterAddDone, false, lastFlowToConfigOnReboot, flowData.Meter, nil); err != nil { |
| 1405 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1406 | } |
| 1407 | } |
| 1408 | dh.lockVlanConfig.Unlock() |
| 1409 | flowsProcessed++ |
| 1410 | } //for all flows of this UNI |
| 1411 | } |
| 1412 | |
| 1413 | func (dh *deviceHandler) waitOnUniVlanConfigOnRebootReady(ctx context.Context, aSyncChannel chan<- struct{}, |
| 1414 | waitGroup *cmn.WaitGroupWithTimeOut) { |
| 1415 | var rebootUniVlanConfigEntries []uint8 |
| 1416 | var appended bool |
| 1417 | expiry := dh.GetReconcileExpiryVlanConfigAbort() |
| 1418 | logger.Debugw(ctx, "start waiting on vlanConfig ready indications on reboot", log.Fields{ |
| 1419 | "device-id": dh.DeviceID, "expiry": expiry}) |
| 1420 | // indicate blocking on channel now to the caller |
| 1421 | aSyncChannel <- struct{}{} |
| 1422 | for { |
| 1423 | select { |
| 1424 | case <-dh.deviceDeleteCommChan: |
| 1425 | // Cancel the context and return |
| 1426 | logger.Warnw(ctx, "Device Deletion invoked , stop further processing ", log.Fields{"device-id": dh.DeviceID}) |
| 1427 | return |
| 1428 | |
| 1429 | case uniIndication := <-dh.chUniVlanConfigOnRebootDone: |
| 1430 | switch uniIndication { |
| 1431 | // this should be a valid UNI vlan config done indication |
| 1432 | default: |
| 1433 | if uniIndication < platform.MaxUnisPerOnu { |
| 1434 | logger.Info(ctx, "rebooting - configuring flows has been finished in time for this UNI", |
| 1435 | log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| 1436 | if rebootUniVlanConfigEntries, appended = |
| 1437 | dh.appendIfMissing(rebootUniVlanConfigEntries, uint8(uniIndication)); appended { |
| 1438 | waitGroup.Done() |
| 1439 | } |
| 1440 | } else { |
| 1441 | logger.Errorw(ctx, "received unexpected UNI flowConfig done indication - is ignored", log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| 1442 | } |
| 1443 | } //switch uniIndication |
| 1444 | |
| 1445 | case <-time.After(expiry): |
| 1446 | logger.Errorw(ctx, "timeout waiting for configuring all UNI flows to be finished!", |
| 1447 | log.Fields{"device-id": dh.DeviceID}) |
| 1448 | return |
| 1449 | } |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | func (dh *deviceHandler) SendChUniVlanConfigFinishedOnReboot(value uint16) { |
| 1454 | if dh != nil { //if the object still exists (might have been already deleted in background) |
| 1455 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1456 | select { |
| 1457 | case dh.chUniVlanConfigOnRebootDone <- value: |
| 1458 | default: |
| 1459 | } |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | func (dh *deviceHandler) CheckForDeviceTechProf(ctx context.Context) bool { |
| 1464 | logger.Info(ctx, "Check for tech profile config", log.Fields{"device-id": dh.DeviceID}) |
| 1465 | techProfInstLoadFailed := false |
| 1466 | continueWithFlowConfig := false |
| 1467 | defer dh.UpdateAndStoreRebootState(ctx, continueWithFlowConfig) |
| 1468 | // Stop any on going reconciling thread as the flow configuration post reboot will be performed here |
| 1469 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| 1470 | |
| 1471 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 1472 | if pDevEntry == nil { |
| 1473 | logger.Errorw(ctx, "no valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 1474 | return continueWithFlowConfig |
| 1475 | } |
| 1476 | dh.lockDevice.RLock() |
| 1477 | if dh.pOnuTP == nil { |
| 1478 | //should normally not happen ... |
| 1479 | logger.Warnw(ctx, "onuTechProf instance not set up - ignoring request", |
| 1480 | log.Fields{"device-id": dh.DeviceID}) |
| 1481 | dh.lockDevice.RUnlock() |
| 1482 | return continueWithFlowConfig |
| 1483 | } |
| 1484 | |
| 1485 | dh.pOnuTP.LockTpProcMutex() |
| 1486 | defer dh.pOnuTP.UnlockTpProcMutex() |
| 1487 | defer dh.lockDevice.RUnlock() |
| 1488 | |
| 1489 | pDevEntry.MutexPersOnuConfig.RLock() |
| 1490 | persMutexLock := true |
| 1491 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 1492 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1493 | logger.Info(ctx, "no uni-configs have been stored - aborting", |
| 1494 | log.Fields{"device-id": dh.DeviceID}) |
| 1495 | return continueWithFlowConfig |
| 1496 | } |
| 1497 | |
| 1498 | outerLoop: |
| 1499 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
| 1500 | uniID := uniData.PersUniID |
| 1501 | |
| 1502 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
| 1503 | logger.Debugw(ctx, "no TPs stored for uniID", |
| 1504 | log.Fields{"uni-id": uniID, "device-id": dh.DeviceID}) |
| 1505 | continue |
| 1506 | } |
| 1507 | //release MutexPersOnuConfig before TechProfile (ANIConfig) processing as otherwise the reception of |
| 1508 | // OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI |
| 1509 | // frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap |
| 1510 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1511 | persMutexLock = false |
| 1512 | for tpID, tpPath := range uniData.PersTpPathMap { |
| 1513 | if tpPath != "" { |
| 1514 | logger.Infow(ctx, "Starting retrieval for TechProfileInstance", log.Fields{ |
| 1515 | "uniID": uniID, "tpID": tpID, "tpPath": tpPath, "device-id": dh.DeviceID, |
| 1516 | }) |
| 1517 | // Attempt the initial call before entering the retry loop |
| 1518 | iaTechTpInst, err := dh.GetTechProfileInstanceFromParentAdapter(ctx, uniID, tpPath) |
| 1519 | if err != nil { |
| 1520 | logger.Warnw(ctx, "Starting retrieval for TechProfileInstance", log.Fields{ |
| 1521 | "uniID": uniID, "tpID": tpID, "tpPath": tpPath, "device-id": dh.DeviceID, |
| 1522 | }) |
| 1523 | techProfInstLoadFailed = true |
| 1524 | break outerLoop |
| 1525 | } |
| 1526 | if iaTechTpInst != nil { |
| 1527 | var tpInst tech_profile.TechProfileInstance |
| 1528 | switch techTpInst := iaTechTpInst.TechTpInstance.(type) { |
| 1529 | case *ia.TechProfileDownloadMessage_TpInstance: // supports only GPON, XGPON, XGS-PON |
| 1530 | tpInst = *techTpInst.TpInstance |
| 1531 | logger.Debugw(ctx, "received-tp-instance-successfully-after-reboot", log.Fields{ |
| 1532 | "tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| 1533 | default: // do not support epon or other tech |
| 1534 | logger.Errorw(ctx, "unsupported-tech-profile", log.Fields{ |
| 1535 | "tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| 1536 | techProfInstLoadFailed = true |
| 1537 | break outerLoop |
| 1538 | } |
| 1539 | |
| 1540 | continueWithFlowConfig = true |
| 1541 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 1542 | dctx, cancel := context.WithDeadline(ctx, deadline) |
| 1543 | |
| 1544 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniData.PersUniID, tpID) |
| 1545 | var wg sync.WaitGroup |
| 1546 | wg.Add(1) // for the 1 go routine to finish |
| 1547 | go dh.pOnuTP.ConfigureUniTp(log.WithSpanFromContext(dctx, ctx), uniData.PersUniID, uniData.PersTpPathMap[tpID], tpInst, &wg) |
| 1548 | // Wait for either completion or cancellation |
| 1549 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfDwldDuringReboot") |
| 1550 | if tpErr := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); tpErr != nil { |
| 1551 | logger.Errorw(ctx, "error-processing-tp", log.Fields{"device-id": dh.DeviceID, "err": tpErr, "tp-path": uniData.PersTpPathMap[tpID]}) |
| 1552 | techProfInstLoadFailed = true |
| 1553 | continueWithFlowConfig = false |
| 1554 | break outerLoop |
| 1555 | } |
| 1556 | } else { |
| 1557 | logger.Errorw(ctx, "Tp instance is not valid", log.Fields{"tp-id": tpID, "tpPath": tpPath, "device-id": dh.DeviceID, "err": err}) |
| 1558 | techProfInstLoadFailed = true |
| 1559 | break outerLoop |
| 1560 | } |
| 1561 | } else { |
| 1562 | logger.Errorw(ctx, "Tp instance is nil", log.Fields{"tp-id": tpID, "tpPath": tpPath, |
| 1563 | "uni-id": uniID, "device-id": dh.DeviceID}) |
| 1564 | techProfInstLoadFailed = true |
| 1565 | break outerLoop |
| 1566 | } |
| 1567 | } |
| 1568 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| 1569 | persMutexLock = true |
| 1570 | } |
| 1571 | if persMutexLock { |
| 1572 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1573 | } |
| 1574 | go dh.deviceRebootStateUpdate(ctx, techProfInstLoadFailed) |
| 1575 | return continueWithFlowConfig |
| 1576 | } |
| 1577 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1578 | func (dh *deviceHandler) deleteDevicePersistencyData(ctx context.Context) error { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1579 | logger.Debugw(ctx, "delete device persistency data", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1580 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1581 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1582 | if pDevEntry == nil { |
| mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1583 | //IfDevEntry does not exist here, no problem - no persistent data should have been stored |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1584 | logger.Debugw(ctx, "OnuDevice does not exist - nothing to delete", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1585 | return nil |
| Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1586 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1587 | |
| 1588 | // deadline context to ensure completion of background routines waited for |
| 1589 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 1590 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1591 | dctx, cancel := context.WithDeadline(ctx, deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 1592 | defer cancel() |
| 1593 | err := pDevEntry.DeleteDataFromOnuKvStore(log.WithSpanFromContext(dctx, ctx)) |
| 1594 | if err != nil { |
| 1595 | logger.Errorw(ctx, "delete data from onu kv store failed", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 1596 | return err |
| 1597 | } |
| 1598 | return nil |
| Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1601 | // func (dh *deviceHandler) rebootDevice(ctx context.Context, device *voltha.Device) error { |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1602 | // before this change here return like this was used: |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1603 | // |
| 1604 | // return fmt.Errorf("device-unreachable: %s, %s", dh.DeviceID, device.SerialNumber) |
| 1605 | // |
| 1606 | // was and is called in background - error return does not make sense |
| akashreddyk | e30dfa9 | 2025-11-26 10:51:57 +0530 | [diff] [blame] | 1607 | func (dh *deviceHandler) rebootDevice(ctx context.Context, aCheckDeviceState bool, device *voltha.Device) error { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1608 | logger.Infow(ctx, "reboot-device", log.Fields{"device-id": dh.DeviceID, "SerialNumber": dh.device.SerialNumber}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1609 | if aCheckDeviceState && device.ConnectStatus != voltha.ConnectStatus_REACHABLE { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1610 | logger.Errorw(ctx, "device-unreachable", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
| akashreddyk | e30dfa9 | 2025-11-26 10:51:57 +0530 | [diff] [blame] | 1611 | return fmt.Errorf("device-unreachable: %s, %s", dh.DeviceID, device.SerialNumber) |
| ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1612 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1613 | if err := dh.pOnuOmciDevice.Reboot(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1614 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1615 | logger.Errorw(ctx, "error-rebooting-device", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| akashreddyk | e30dfa9 | 2025-11-26 10:51:57 +0530 | [diff] [blame] | 1616 | return err |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1617 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1618 | |
| 1619 | //transfer the possibly modified logical uni port state |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1620 | dh.DisableUniPortStateUpdate(ctx) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1621 | |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 1622 | logger.Debugw(ctx, "call DeviceStateUpdate upon reboot", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1623 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID}) |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 1624 | // do not set the ConnStatus here as it may conflict with the parallel setting from ONU down indication (updateInterface()) |
| akashreddyk | e30dfa9 | 2025-11-26 10:51:57 +0530 | [diff] [blame] | 1625 | go func() { |
| 1626 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| 1627 | DeviceId: dh.DeviceID, |
| 1628 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
| 1629 | OperStatus: voltha.OperStatus_DISCOVERED, |
| 1630 | }); err != nil { |
| 1631 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1632 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| 1633 | return |
| 1634 | } |
| akashreddyk | b03dde0 | 2025-12-02 10:53:18 +0530 | [diff] [blame] | 1635 | dh.UpdateAndStoreRebootState(ctx, true) |
| akashreddyk | e30dfa9 | 2025-11-26 10:51:57 +0530 | [diff] [blame] | 1636 | if err := dh.ReasonUpdate(ctx, cmn.DrRebooting, true); err != nil { |
| 1637 | logger.Errorw(ctx, "errror-updating-device-reason-to-core", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| 1638 | return |
| 1639 | } |
| 1640 | dh.SetReadyForOmciConfig(false) |
| 1641 | }() |
| 1642 | return nil |
| mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1643 | //no specific activity to synchronize any internal FSM to the 'rebooted' state is explicitly done here |
| 1644 | // the expectation ids for a real device, that it will be synced with the expected following 'down' indication |
| 1645 | // as BBSIM does not support this testing requires explicite disable/enable device calls in which sequence also |
| 1646 | // all other FSM's should be synchronized again |
| ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1647 | } |
| 1648 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1649 | // doOnuSwUpgrade initiates the SW download transfer to the ONU and on success activates the (inactive) image |
| 1650 | // |
| 1651 | // used only for old - R2.7 style - upgrade API |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1652 | func (dh *deviceHandler) doOnuSwUpgrade(ctx context.Context, apImageDsc *voltha.ImageDownload, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1653 | apDownloadManager *swupg.AdapterDownloadManager) error { |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1654 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1655 | "device-id": dh.DeviceID, "image-name": (*apImageDsc).Name}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1656 | |
| 1657 | var err error |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1658 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1659 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1660 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1661 | return fmt.Errorf("start Onu SW upgrade rejected: no valid OnuDevice for device-id: %s", dh.DeviceID) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1664 | if dh.IsReadyForOmciConfig() { |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1665 | var inactiveImageID uint16 |
| 1666 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1667 | dh.lockUpgradeFsm.Lock() |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1668 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| 1669 | // but must be still locked at calling createOnuUpgradeFsm |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1670 | if dh.pOnuUpradeFsm == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1671 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1672 | dh.lockUpgradeFsm.Unlock() |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1673 | if err == nil { |
| 1674 | if err = dh.pOnuUpradeFsm.SetDownloadParams(ctx, inactiveImageID, apImageDsc, apDownloadManager); err != nil { |
| 1675 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1676 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1677 | } |
| 1678 | } else { |
| 1679 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1680 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1681 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1682 | } else { //OnuSw upgrade already running - restart (with possible abort of running) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1683 | dh.lockUpgradeFsm.Unlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1684 | logger.Debugw(ctx, "Onu SW upgrade already running - abort", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1685 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1686 | dh.upgradeCanceled = true |
| 1687 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1688 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1689 | //no effort spent anymore for the old API to automatically cancel and restart the download |
| 1690 | // like done for the new API |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1691 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1692 | } else { |
| 1693 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no inactive image", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1694 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1695 | } |
| 1696 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1697 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no active OMCI connection", log.Fields{"device-id": dh.DeviceID}) |
| 1698 | err = fmt.Errorf("start Onu SW upgrade rejected: no active OMCI connection for device-id: %s", dh.DeviceID) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1699 | } |
| 1700 | return err |
| mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1703 | // onuSwUpgradeAfterDownload initiates the SW download transfer to the ONU with activate and commit options |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1704 | // after the OnuImage has been downloaded to the adapter, called in background |
| 1705 | func (dh *deviceHandler) onuSwUpgradeAfterDownload(ctx context.Context, apImageRequest *voltha.DeviceImageDownloadRequest, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1706 | apDownloadManager *swupg.FileDownloadManager, aImageIdentifier string) { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1707 | |
| 1708 | var err error |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1709 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1710 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1711 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1712 | return |
| 1713 | } |
| 1714 | |
| 1715 | var inactiveImageID uint16 |
| 1716 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1717 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1718 | "device-id": dh.DeviceID, "image-version": apImageRequest.Image.Version, "to onu-image": inactiveImageID}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1719 | |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1720 | dh.lockUpgradeFsm.Lock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1721 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1722 | // but must be still locked at calling createOnuUpgradeFsm |
| 1723 | // (and working with a local pointer copy does not work here if asynchronous request are done to fast |
| 1724 | // [e.g.leaving the local pointer on nil even though a creation is already on the way]) |
| 1725 | if dh.pOnuUpradeFsm != nil { |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1726 | //OnuSw upgrade already running on this device (e.g. with activate/commit not yet set) |
| 1727 | // abort the current processing, running upgrades are always aborted by newer request |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1728 | logger.Debugw(ctx, "Onu SW upgrade already running - abort previous activity", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1729 | //flush the remove upgradeFsmChan channel |
| 1730 | select { |
| 1731 | case <-dh.upgradeFsmChan: |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1732 | logger.Debugw(ctx, "flushed-upgrade-fsm-channel", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1733 | default: |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1734 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1735 | dh.lockUpgradeFsm.Unlock() |
| 1736 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1737 | dh.upgradeCanceled = true |
| 1738 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1739 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1740 | select { |
| 1741 | case <-time.After(cTimeOutRemoveUpgrade * time.Second): |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1742 | logger.Errorw(ctx, "could not remove Upgrade FSM in time, aborting", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1743 | //should not appear, can't proceed with new upgrade, perhaps operator can retry manually later |
| 1744 | return |
| 1745 | case <-dh.upgradeFsmChan: |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1746 | logger.Debugw(ctx, "recent Upgrade FSM removed, proceed with new request", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1747 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1748 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1749 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1750 | |
| 1751 | //here it can be assumed that no running upgrade processing exists (anymore) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1752 | //OmciOnuSwUpgradeDone could be used to create some event notification with information on upgrade completion, |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1753 | // but none yet defined |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1754 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1755 | dh.lockUpgradeFsm.Unlock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1756 | if err == nil { |
| 1757 | if err = dh.pOnuUpradeFsm.SetDownloadParamsAfterDownload(ctx, inactiveImageID, |
| 1758 | apImageRequest, apDownloadManager, aImageIdentifier); err != nil { |
| 1759 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1760 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1761 | return |
| 1762 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1763 | } else { |
| 1764 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1765 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1766 | } |
| 1767 | return |
| 1768 | } |
| 1769 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no inactive image", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1770 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1773 | // onuSwActivateRequest ensures activation of the requested image with commit options |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1774 | func (dh *deviceHandler) onuSwActivateRequest(ctx context.Context, |
| 1775 | aVersion string, aCommitRequest bool) (*voltha.ImageState, error) { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1776 | var err error |
| 1777 | //SW activation for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1778 | // 1.) activation of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1779 | // 2.) activation of the inactive image |
| 1780 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1781 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1782 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1783 | logger.Errorw(ctx, "Onu image activation rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1784 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1785 | } |
| 1786 | dh.lockUpgradeFsm.RLock() |
| 1787 | if dh.pOnuUpradeFsm != nil { |
| 1788 | dh.lockUpgradeFsm.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1789 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1790 | if getErr != nil || onuVolthaDevice == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1791 | logger.Errorw(ctx, "Failed to fetch Onu device for image activation", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1792 | return nil, fmt.Errorf("could not fetch device for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1793 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1794 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1795 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1796 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1797 | } |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1798 | // use the OnuVendor identification from this device for the internal unique name |
| 1799 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1800 | // 1.) check a started upgrade process and relay the activation request to it |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1801 | if err = dh.pOnuUpradeFsm.SetActivationParamsRunning(ctx, imageIdentifier, aCommitRequest); err != nil { |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1802 | //if some ONU upgrade is ongoing we do not accept some explicit ONU image-version related activation |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1803 | logger.Errorw(ctx, "onu upgrade fsm did not accept activation while running", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1804 | "device-id": dh.DeviceID, "error": err}) |
| 1805 | return nil, fmt.Errorf("activation not accepted for this version for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1806 | } |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1807 | logger.Debugw(ctx, "image activation acknowledged by onu upgrade processing", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1808 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1809 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1810 | return pImageStates, nil |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1811 | } //else |
| 1812 | dh.lockUpgradeFsm.RUnlock() |
| 1813 | |
| 1814 | // 2.) check if requested image-version equals the inactive one and start its activation |
| 1815 | // (image version is not [yet] checked - would be possible, but with increased effort ...) |
| 1816 | var inactiveImageID uint16 |
| 1817 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err != nil || inactiveImageID > 1 { |
| 1818 | logger.Errorw(ctx, "get inactive image failed", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1819 | "device-id": dh.DeviceID, "err": err, "image-id": inactiveImageID}) |
| 1820 | return nil, fmt.Errorf("no valid inactive image found for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1821 | } |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1822 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1823 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1824 | dh.lockUpgradeFsm.Unlock() |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1825 | if err == nil { |
| 1826 | if err = dh.pOnuUpradeFsm.SetActivationParamsStart(ctx, aVersion, |
| 1827 | inactiveImageID, aCommitRequest); err != nil { |
| 1828 | logger.Errorw(ctx, "onu upgrade fsm did not accept activation to start", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1829 | "device-id": dh.DeviceID, "error": err}) |
| 1830 | return nil, fmt.Errorf("activation to start from scratch not accepted for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1831 | } |
| 1832 | logger.Debugw(ctx, "inactive image activation acknowledged by onu upgrade", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1833 | "device-id": dh.DeviceID, "image-version": aVersion}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1834 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1835 | return pImageStates, nil |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1836 | } //else |
| 1837 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1838 | "device-id": dh.DeviceID, "error": err}) |
| 1839 | return nil, fmt.Errorf("could not start upgradeFsm for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1842 | // onuSwCommitRequest ensures commitment of the requested image |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1843 | func (dh *deviceHandler) onuSwCommitRequest(ctx context.Context, |
| 1844 | aVersion string) (*voltha.ImageState, error) { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1845 | var err error |
| 1846 | //SW commitment for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1847 | // 1.) commitment of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1848 | // 2.) commitment of the active image |
| 1849 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1850 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1851 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1852 | logger.Errorw(ctx, "Onu image commitment rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1853 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1854 | } |
| 1855 | dh.lockUpgradeFsm.RLock() |
| 1856 | if dh.pOnuUpradeFsm != nil { |
| 1857 | dh.lockUpgradeFsm.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1858 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1859 | if getErr != nil || onuVolthaDevice == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1860 | logger.Errorw(ctx, "Failed to fetch Onu device for image commitment", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1861 | return nil, fmt.Errorf("could not fetch device for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1862 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1863 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1864 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1865 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1866 | } |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1867 | // use the OnuVendor identification from this device for the internal unique name |
| 1868 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1869 | // 1.) check a started upgrade process and relay the commitment request to it |
| 1870 | // the running upgrade may be based either on the imageIdentifier (started from download) |
| 1871 | // or on the imageVersion (started from pure activation) |
| 1872 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsRunning(ctx, imageIdentifier, aVersion); err != nil { |
| 1873 | //if some ONU upgrade is ongoing we do not accept some explicit different ONU image-version related commitment |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1874 | logger.Errorw(ctx, "onu upgrade fsm did not accept commitment while running", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1875 | "device-id": dh.DeviceID, "error": err}) |
| 1876 | return nil, fmt.Errorf("commitment not accepted for this version for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1877 | } |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1878 | logger.Debugw(ctx, "image commitment acknowledged by onu upgrade processing", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1879 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1880 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1881 | return pImageStates, nil |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1882 | } //else |
| 1883 | dh.lockUpgradeFsm.RUnlock() |
| 1884 | |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1885 | // 2.) use the active image to directly commit |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1886 | var activeImageID uint16 |
| 1887 | if activeImageID, err = pDevEntry.GetActiveImageMeID(ctx); err != nil || activeImageID > 1 { |
| 1888 | logger.Errorw(ctx, "get active image failed", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1889 | "device-id": dh.DeviceID, "err": err, "image-id": activeImageID}) |
| 1890 | return nil, fmt.Errorf("no valid active image found for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1891 | } |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1892 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1893 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1894 | dh.lockUpgradeFsm.Unlock() |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1895 | if err == nil { |
| 1896 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsStart(ctx, aVersion, activeImageID); err != nil { |
| 1897 | logger.Errorw(ctx, "onu upgrade fsm did not accept commitment to start", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1898 | "device-id": dh.DeviceID, "error": err}) |
| 1899 | return nil, fmt.Errorf("commitment to start from scratch not accepted for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1900 | } |
| 1901 | logger.Debugw(ctx, "active image commitment acknowledged by onu upgrade", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1902 | "device-id": dh.DeviceID, "image-version": aVersion}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1903 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1904 | return pImageStates, nil |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1905 | } //else |
| 1906 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1907 | "device-id": dh.DeviceID, "error": err}) |
| 1908 | return nil, fmt.Errorf("could not start upgradeFsm for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1911 | func (dh *deviceHandler) requestOnuSwUpgradeState(ctx context.Context, aImageIdentifier string, |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1912 | aVersion string) *voltha.ImageState { |
| 1913 | var pImageState *voltha.ImageState |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1914 | dh.lockUpgradeFsm.RLock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1915 | defer dh.lockUpgradeFsm.RUnlock() |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1916 | if dh.pOnuUpradeFsm != nil { |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1917 | pImageState = dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1918 | } else { //use the last stored ImageState (if the requested Imageversion coincides) |
| 1919 | if aVersion == dh.pLastUpgradeImageState.Version { |
| 1920 | pImageState = dh.pLastUpgradeImageState |
| 1921 | } else { //state request for an image version different from last processed image version |
| 1922 | pImageState = &voltha.ImageState{ |
| 1923 | Version: aVersion, |
| 1924 | //we cannot state something concerning this version |
| 1925 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 1926 | Reason: voltha.ImageState_NO_ERROR, |
| 1927 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 1928 | } |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1929 | } |
| 1930 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1931 | return pImageState |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | func (dh *deviceHandler) cancelOnuSwUpgrade(ctx context.Context, aImageIdentifier string, |
| 1935 | aVersion string, pDeviceImageState *voltha.DeviceImageState) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1936 | pDeviceImageState.DeviceId = dh.DeviceID |
| mpagenko | 7455fd4 | 2021-06-10 16:25:55 +0000 | [diff] [blame] | 1937 | pDeviceImageState.ImageState.Version = aVersion |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1938 | dh.lockUpgradeFsm.RLock() |
| 1939 | if dh.pOnuUpradeFsm != nil { |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1940 | dh.lockUpgradeFsm.RUnlock() |
| 1941 | // so then we cancel the upgrade operation |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1942 | // but before we still request the actual upgrade states for the direct response |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1943 | pImageState := dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1944 | pDeviceImageState.ImageState.DownloadState = pImageState.DownloadState |
| 1945 | pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST |
| 1946 | pDeviceImageState.ImageState.ImageState = pImageState.ImageState |
| 1947 | if pImageState.DownloadState != voltha.ImageState_DOWNLOAD_UNKNOWN { |
| 1948 | //so here the imageIdentifier or version equals to what is used in the upgrade FSM |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1949 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1950 | dh.upgradeCanceled = true |
| 1951 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1952 | } |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1953 | } //nothing to cancel (upgrade FSM for different image stays alive) |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1954 | } else { |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1955 | dh.lockUpgradeFsm.RUnlock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1956 | // if no upgrade is ongoing, nothing is canceled and accordingly the states of the requested image are unknown |
| 1957 | // reset also the dh handler LastUpgradeImageState (not relevant anymore/cleared) |
| 1958 | (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1959 | (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR |
| 1960 | (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1961 | (*dh.pLastUpgradeImageState).Version = "" //reset to 'no (relevant) upgrade done' (like initial state) |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1962 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1963 | pDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1964 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1965 | //an abort request to a not active upgrade processing can be used to reset the device upgrade states completely |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1966 | } |
| 1967 | } |
| 1968 | |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1969 | func (dh *deviceHandler) getOnuImages(ctx context.Context) (*voltha.OnuImages, error) { |
| 1970 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1971 | var onuImageStatus *swupg.OnuImageStatus |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1972 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1973 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1974 | if pDevEntry != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1975 | onuImageStatus = swupg.NewOnuImageStatus(dh, pDevEntry) |
| 1976 | pDevEntry.MutexOnuImageStatus.Lock() |
| 1977 | pDevEntry.POnuImageStatus = onuImageStatus |
| 1978 | pDevEntry.MutexOnuImageStatus.Unlock() |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1979 | |
| 1980 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1981 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1982 | return nil, fmt.Errorf("no-valid-OnuDevice-aborting") |
| 1983 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1984 | images, err := onuImageStatus.GetOnuImageStatus(ctx) |
| 1985 | pDevEntry.MutexOnuImageStatus.Lock() |
| 1986 | pDevEntry.POnuImageStatus = nil |
| 1987 | pDevEntry.MutexOnuImageStatus.Unlock() |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1988 | return images, err |
| 1989 | } |
| 1990 | |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1991 | // deviceHandler methods that implement the adapters interface requests## end ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1992 | // ##################################################################################### |
| 1993 | |
| 1994 | // ################ to be updated acc. needs of ONU Device ######################## |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1995 | // deviceHandler StateMachine related state transition methods ##### begin ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1996 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1997 | func (dh *deviceHandler) logStateChange(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1998 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"event name": string(e.Event), |
| 1999 | "src state": string(e.Src), "dst state": string(e.Dst), "device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | // doStateInit provides the device update to the core |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2003 | func (dh *deviceHandler) doStateInit(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2004 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2005 | logger.Debugw(ctx, "doStateInit-started", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2006 | var err error |
| 2007 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2008 | // populate what we know. rest comes later after mib sync |
| 2009 | dh.device.Root = false |
| 2010 | dh.device.Vendor = "OpenONU" |
| 2011 | dh.device.Model = "go" |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2012 | dh.device.Reason = cmn.DeviceReasonMap[cmn.DrActivatingOnu] |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2013 | _ = dh.ReasonUpdate(ctx, cmn.DrActivatingOnu, false) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2014 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2015 | dh.logicalDeviceID = dh.DeviceID // really needed - what for ??? //TODO!!! |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2016 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2017 | if !dh.IsReconciling() { |
| 2018 | logger.Infow(ctx, "DeviceUpdate", log.Fields{"deviceReason": dh.device.Reason, "device-id": dh.DeviceID}) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2019 | if err = dh.updateDeviceInCore(ctx, dh.device); err != nil { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2020 | logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err}) |
| 2021 | } |
| Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 2022 | //TODO Need to Update Device Reason To CORE as part of device update userstory |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2023 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2024 | logger.Infow(ctx, "reconciling - don't notify core about DeviceUpdate", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2025 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2026 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2027 | |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2028 | dh.parentID = dh.device.ParentId |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2029 | dh.ponPortNumber = dh.device.ParentPortNo |
| 2030 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2031 | // store proxy parameters for later communication - assumption: invariant, else they have to be requested dynamically!! |
| 2032 | dh.ProxyAddressID = dh.device.ProxyAddress.GetDeviceId() |
| 2033 | dh.ProxyAddressType = dh.device.ProxyAddress.GetDeviceType() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2034 | logger.Debugw(ctx, "device-updated", log.Fields{"device-id": dh.DeviceID, "proxyAddressID": dh.ProxyAddressID, |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2035 | "proxyAddressType": dh.ProxyAddressType, "SNR": dh.device.SerialNumber, |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2036 | "ParentId": dh.parentID, "ParentPortNo": dh.ponPortNumber}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2037 | |
| 2038 | /* |
| 2039 | self._pon = PonPort.create(self, self._pon_port_number) |
| 2040 | self._pon.add_peer(self.parent_id, self._pon_port_number) |
| 2041 | self.logger.debug('adding-pon-port-to-agent', |
| 2042 | type=self._pon.get_port().type, |
| 2043 | admin_state=self._pon.get_port().admin_state, |
| 2044 | oper_status=self._pon.get_port().oper_status, |
| 2045 | ) |
| 2046 | */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2047 | if !dh.IsReconciling() { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2048 | logger.Infow(ctx, "adding-pon-port", log.Fields{"device-id": dh.DeviceID, "ponPortNo": dh.ponPortNumber}) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2049 | var ponPortNo uint32 = 1 |
| 2050 | if dh.ponPortNumber != 0 { |
| 2051 | ponPortNo = dh.ponPortNumber |
| 2052 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2053 | |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2054 | pPonPort := &voltha.Port{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2055 | DeviceId: dh.DeviceID, |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2056 | PortNo: ponPortNo, |
| 2057 | Label: fmt.Sprintf("pon-%d", ponPortNo), |
| 2058 | Type: voltha.Port_PON_ONU, |
| 2059 | OperStatus: voltha.OperStatus_ACTIVE, |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2060 | Peers: []*voltha.Port_PeerPort{{DeviceId: dh.parentID, // Peer device is OLT |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2061 | PortNo: ponPortNo}}, // Peer port is parent's port number |
| 2062 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2063 | if err = dh.CreatePortInCore(ctx, pPonPort); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2064 | logger.Fatalf(ctx, "Device FSM: PortCreated-failed-%s:%s", err, dh.DeviceID) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2065 | e.Cancel(err) |
| 2066 | return |
| 2067 | } |
| 2068 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2069 | logger.Infow(ctx, "reconciling - pon-port already added", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2070 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2071 | logger.Debugw(ctx, "doStateInit-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | // postInit setups the DeviceEntry for the conerned device |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2075 | func (dh *deviceHandler) postInit(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2076 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2077 | logger.Debugw(ctx, "postInit-started", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2078 | var err error |
| 2079 | /* |
| 2080 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
| 2081 | dh.pTransitionMap.Handle(ctx, GrpcConnected) |
| 2082 | return nil |
| 2083 | */ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2084 | if err = dh.addOnuDeviceEntry(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2085 | logger.Fatalf(ctx, "Device FSM: addOnuDeviceEntry-failed-%s:%s", err, dh.DeviceID) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2086 | e.Cancel(err) |
| 2087 | return |
| 2088 | } |
| 2089 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2090 | if dh.IsReconciling() { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2091 | go dh.reconcileDeviceOnuInd(ctx) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2092 | // reconcilement will be continued after mib download is done |
| 2093 | } |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 2094 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2095 | /* |
| 2096 | ############################################################################ |
| 2097 | # Setup Alarm handler |
| 2098 | self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id, |
| 2099 | device.serial_number) |
| 2100 | ############################################################################ |
| 2101 | # Setup PM configuration for this device |
| 2102 | # Pass in ONU specific options |
| 2103 | kwargs = { |
| 2104 | OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY, |
| 2105 | 'heartbeat': self.heartbeat, |
| 2106 | OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device |
| 2107 | } |
| 2108 | self.logger.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number) |
| 2109 | self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id, |
| 2110 | self.logical_device_id, device.serial_number, |
| 2111 | grouped=True, freq_override=False, **kwargs) |
| 2112 | pm_config = self._pm_metrics.make_proto() |
| 2113 | self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm) |
| 2114 | self.logger.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number) |
| 2115 | yield self.core_proxy.device_pm_config_update(pm_config, init=True) |
| 2116 | |
| 2117 | # Note, ONU ID and UNI intf set in add_uni_port method |
| 2118 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events, |
| 2119 | ani_ports=[self._pon]) |
| 2120 | |
| 2121 | # Code to Run OMCI Test Action |
| 2122 | kwargs_omci_test_action = { |
| 2123 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 2124 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 2125 | } |
| 2126 | serial_number = device.serial_number |
| 2127 | self._test_request = OmciTestRequest(self.core_proxy, |
| 2128 | self.omci_agent, self.device_id, |
| 2129 | AniG, serial_number, |
| 2130 | self.logical_device_id, |
| 2131 | exclusive=False, |
| 2132 | **kwargs_omci_test_action) |
| 2133 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2134 | self.Enabled = True |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2135 | else: |
| 2136 | self.logger.info('onu-already-activated') |
| 2137 | */ |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 2138 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2139 | logger.Debugw(ctx, "postInit-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | // doStateConnected get the device info and update to voltha core |
| 2143 | // for comparison of the original method (not that easy to uncomment): compare here: |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 2144 | // |
| 2145 | // voltha-openolt-adapter/adaptercore/device_handler.go |
| 2146 | // -> this one obviously initiates all communication interfaces of the device ...? |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2147 | func (dh *deviceHandler) doStateConnected(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2148 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2149 | logger.Debugw(ctx, "doStateConnected-started", log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2150 | err := errors.New("device FSM: function not implemented yet") |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2151 | e.Cancel(err) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2152 | logger.Debugw(ctx, "doStateConnected-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | // doStateUp handle the onu up indication and update to voltha core |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2156 | func (dh *deviceHandler) doStateUp(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2157 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2158 | logger.Debugw(ctx, "doStateUp-started", log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2159 | err := errors.New("device FSM: function not implemented yet") |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2160 | e.Cancel(err) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2161 | logger.Debugw(ctx, "doStateUp-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2162 | |
| 2163 | /* |
| 2164 | // Synchronous call to update device state - this method is run in its own go routine |
| 2165 | if err := dh.coreProxy.DeviceStateUpdate(ctx, dh.device.Id, voltha.ConnectStatus_REACHABLE, |
| 2166 | voltha.OperStatus_ACTIVE); err != nil { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2167 | logger.Errorw("Failed to update device with OLT UP indication", log.Fields{"device-id": dh.device.Id, "error": err}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2168 | return err |
| 2169 | } |
| 2170 | return nil |
| 2171 | */ |
| 2172 | } |
| 2173 | |
| 2174 | // doStateDown handle the onu down indication |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2175 | func (dh *deviceHandler) doStateDown(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2176 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2177 | logger.Debugw(ctx, "doStateDown-started", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2178 | var err error |
| 2179 | |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2180 | device := dh.device |
| 2181 | if device == nil { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2182 | /*TODO: needs to handle error scenarios */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2183 | logger.Errorw(ctx, "Failed to fetch handler device", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2184 | e.Cancel(err) |
| 2185 | return |
| 2186 | } |
| 2187 | |
| 2188 | cloned := proto.Clone(device).(*voltha.Device) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2189 | logger.Debugw(ctx, "do-state-down", log.Fields{"ClonedDeviceID": cloned.Id}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2190 | /* |
| 2191 | // Update the all ports state on that device to disable |
| 2192 | if er := dh.coreProxy.PortsStateUpdate(ctx, cloned.Id, voltha.OperStatus_UNKNOWN); er != nil { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2193 | logger.Errorw("updating-ports-failed", log.Fields{"device-id": device.Id, "error": er}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2194 | return er |
| 2195 | } |
| 2196 | |
| 2197 | //Update the device oper state and connection status |
| 2198 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 2199 | cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE |
| 2200 | dh.device = cloned |
| 2201 | |
| 2202 | if er := dh.coreProxy.DeviceStateUpdate(ctx, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); er != nil { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2203 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": device.Id, "error": er}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2204 | return er |
| 2205 | } |
| 2206 | |
| 2207 | //get the child device for the parent device |
| 2208 | onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id) |
| 2209 | if err != nil { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2210 | logger.Errorw("failed to get child devices information", log.Fields{"device-id": dh.device.Id, "error": err}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2211 | return err |
| 2212 | } |
| 2213 | for _, onuDevice := range onuDevices.Items { |
| 2214 | |
| 2215 | // Update onu state as down in onu adapter |
| 2216 | onuInd := oop.OnuIndication{} |
| 2217 | onuInd.OperState = "down" |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2218 | er := dh.adapterProxy.SendInterAdapterMessage(ctx, &onuInd, ca.InterAdapterMessageType_ONU_IND_REQUEST, |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2219 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 2220 | if er != nil { |
| 2221 | logger.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2222 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "device-id": onuDevice.Id}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2223 | //Do not return here and continue to process other ONUs |
| 2224 | } |
| 2225 | } |
| 2226 | // * Discovered ONUs entries need to be cleared , since after OLT |
| 2227 | // is up, it starts sending discovery indications again* / |
| 2228 | dh.discOnus = sync.Map{} |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2229 | logger.Debugw("do-state-down-end", log.Fields{"device-id": device.Id}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2230 | return nil |
| 2231 | */ |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2232 | err = errors.New("device FSM: function not implemented yet") |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2233 | e.Cancel(err) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2234 | logger.Debugw(ctx, "doStateDown-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2237 | // deviceHandler StateMachine related state transition methods ##### end ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2238 | // ################################################################################# |
| 2239 | |
| 2240 | // ################################################### |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2241 | // deviceHandler utility methods ##### begin ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2242 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 2243 | // GetOnuDeviceEntry gets the ONU device entry and may wait until its value is defined |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2244 | func (dh *deviceHandler) GetOnuDeviceEntry(ctx context.Context, aWait bool) *mib.OnuDeviceEntry { |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2245 | dh.lockDevice.RLock() |
| 2246 | pOnuDeviceEntry := dh.pOnuOmciDevice |
| 2247 | if aWait && pOnuDeviceEntry == nil { |
| 2248 | //keep the read sema short to allow for subsequent write |
| 2249 | dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2250 | logger.Debugw(ctx, "Waiting for DeviceEntry to be set ...", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2251 | // based on concurrent processing the deviceEntry setup may not yet be finished at his point |
| 2252 | // so it might be needed to wait here for that event with some timeout |
| 2253 | select { |
| 2254 | case <-time.After(60 * time.Second): //timer may be discussed ... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2255 | logger.Errorw(ctx, "No valid DeviceEntry set after maxTime", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2256 | return nil |
| 2257 | case <-dh.deviceEntrySet: |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2258 | logger.Debugw(ctx, "devicEntry ready now - continue", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2259 | // if written now, we can return the written value without sema |
| 2260 | return dh.pOnuOmciDevice |
| 2261 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2262 | } |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2263 | dh.lockDevice.RUnlock() |
| 2264 | return pOnuDeviceEntry |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2265 | } |
| 2266 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 2267 | // setDeviceHandlerEntries sets the ONU device entry within the handler |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2268 | func (dh *deviceHandler) setDeviceHandlerEntries(apDeviceEntry *mib.OnuDeviceEntry, apOnuTp *avcfg.OnuUniTechProf, |
| 2269 | apOnuMetricsMgr *pmmgr.OnuMetricsManager, apOnuAlarmMgr *almgr.OnuAlarmManager, apSelfTestHdlr *otst.SelfTestControlBlock) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2270 | dh.lockDevice.Lock() |
| 2271 | defer dh.lockDevice.Unlock() |
| mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 2272 | dh.pOnuOmciDevice = apDeviceEntry |
| 2273 | dh.pOnuTP = apOnuTp |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 2274 | dh.pOnuMetricsMgr = apOnuMetricsMgr |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 2275 | dh.pAlarmMgr = apOnuAlarmMgr |
| Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 2276 | dh.pSelfTestHdlr = apSelfTestHdlr |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 2279 | // addOnuDeviceEntry creates a new ONU device or returns the existing |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2280 | // |
| 2281 | //nolint:unparam |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2282 | func (dh *deviceHandler) addOnuDeviceEntry(ctx context.Context) error { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2283 | logger.Debugw(ctx, "adding-deviceEntry", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2284 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2285 | deviceEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2286 | if deviceEntry == nil { |
| 2287 | /* costum_me_map in python code seems always to be None, |
| 2288 | we omit that here first (declaration unclear) -> todo at Adapter specialization ...*/ |
| 2289 | /* also no 'clock' argument - usage open ...*/ |
| 2290 | /* and no alarm_db yet (oo.alarm_db) */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2291 | deviceEntry = mib.NewOnuDeviceEntry(ctx, dh.coreClient, dh, dh.pOpenOnuAc) |
| 2292 | onuTechProfProc := avcfg.NewOnuUniTechProf(ctx, dh, deviceEntry) |
| 2293 | onuMetricsMgr := pmmgr.NewOnuMetricsManager(ctx, dh, deviceEntry) |
| 2294 | onuAlarmManager := almgr.NewAlarmManager(ctx, dh, deviceEntry) |
| 2295 | selfTestHdlr := otst.NewSelfTestMsgHandlerCb(ctx, dh, deviceEntry) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2296 | //error treatment possible //TODO!!! |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2297 | dh.setDeviceHandlerEntries(deviceEntry, onuTechProfProc, onuMetricsMgr, onuAlarmManager, selfTestHdlr) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2298 | // fire deviceEntry ready event to spread to possibly waiting processing |
| 2299 | dh.deviceEntrySet <- true |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2300 | logger.Debugw(ctx, "onuDeviceEntry-added", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2301 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2302 | logger.Debugw(ctx, "onuDeviceEntry-add: Device already exists", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2303 | } |
| 2304 | // might be updated with some error handling !!! |
| 2305 | return nil |
| 2306 | } |
| 2307 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2308 | func (dh *deviceHandler) createInterface(ctx context.Context, onuind *oop.OnuIndication) error { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2309 | logger.Debugw(ctx, "create_interface-started", log.Fields{"device-id": dh.DeviceID, "OnuId": onuind.GetOnuId(), |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2310 | "OnuIntfId": onuind.GetIntfId(), "OnuSerialNumber": onuind.GetSerialNumber()}) |
| 2311 | |
| 2312 | dh.pOnuIndication = onuind // let's revise if storing the pointer is sufficient... |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2313 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2314 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2315 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2316 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 2317 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2318 | } |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 2319 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2320 | if !dh.IsReconciling() { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2321 | logger.Debugw(ctx, "call DeviceStateUpdate upon create interface", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2322 | "OperStatus": voltha.OperStatus_ACTIVATING, "device-id": dh.DeviceID}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2323 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2324 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2325 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2326 | OperStatus: voltha.OperStatus_ACTIVATING, |
| 2327 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2328 | }); err != nil { |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2329 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2330 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 2331 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| 2332 | } |
| 2333 | // On onu reboot, we have to perform mib-reset and persist the reboot state for reconciling scenario |
| 2334 | if dh.GetDeviceTechProfOnReboot() { |
| 2335 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2336 | pDevEntry.SOnuPersistentData.PersMibLastDbSync = 0 |
| 2337 | pDevEntry.SOnuPersistentData.PersRebootInProgress = true |
| akashreddyk | b03dde0 | 2025-12-02 10:53:18 +0530 | [diff] [blame] | 2338 | pDevEntry.SOnuPersistentData.PersUniUnlockDone = false |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 2339 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2340 | } |
| 2341 | // Moving the previous call to write to KV store here, to store the ONU pers data after the update. |
| 2342 | if err := dh.StorePersistentData(ctx); err != nil { |
| 2343 | logger.Warnw(ctx, "store persistent data error - continue as there will be additional write attempts", |
| 2344 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2345 | } |
| 2346 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2347 | logger.Info(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVATING", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2348 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2349 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2350 | pDevEntry.MutexPersOnuConfig.RLock() |
| 2351 | if !pDevEntry.SOnuPersistentData.PersUniUnlockDone { |
| 2352 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2353 | logger.Debugw(ctx, "reconciling - uni-ports were not unlocked before adapter restart - resume with a normal start-up", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2354 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 2355 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 2356 | |
| 2357 | //VOL-4965: Recover previously Activating ONU during reconciliation. |
| 2358 | if dh.device.OperStatus == common.OperStatus_ACTIVATING { |
| 2359 | logger.Debugw(ctx, "Reconciling an ONU in previously activating state, perform MIB reset and resume normal start up", |
| 2360 | log.Fields{"device-id": dh.DeviceID}) |
| 2361 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2362 | pDevEntry.SOnuPersistentData.PersMibLastDbSync = 0 |
| 2363 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2364 | } |
| Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2365 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2366 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2367 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2368 | } |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2369 | // It does not look to me as if makes sense to work with the real core device here, (not the stored clone)? |
| 2370 | // in this code the GetDevice would just make a check if the DeviceID's Device still exists in core |
| 2371 | // in python code it looks as the started onu_omci_device might have been updated with some new instance state of the core device |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2372 | // but I would not know why, and the go code anyway does not work with the device directly anymore in the mib.OnuDeviceEntry |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2373 | // so let's just try to keep it simple ... |
| 2374 | /* |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2375 | device, err := dh.coreProxy.GetDevice(log.WithSpanFromContext(context.TODO(), ctx), dh.device.Id, dh.device.Id) |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2376 | if err != nil || device == nil { |
| 2377 | //TODO: needs to handle error scenarios |
| 2378 | logger.Errorw("Failed to fetch device device at creating If", log.Fields{"err": err}) |
| 2379 | return errors.New("Voltha Device not found") |
| 2380 | } |
| 2381 | */ |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2382 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2383 | if err := pDevEntry.Start(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2384 | return err |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2385 | } |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2386 | _ = dh.ReasonUpdate(ctx, cmn.DrStartingOpenomci, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 2387 | if !dh.IsReconciling() && !dh.GetSkipOnuConfigEnabled() { |
| 2388 | /* this might be a good time for Omci Verify message? */ |
| 2389 | verifyExec := make(chan bool) |
| 2390 | omciVerify := otst.NewOmciTestRequest(log.WithSpanFromContext(context.TODO(), ctx), |
| 2391 | dh.device.Id, pDevEntry.PDevOmciCC, false, |
| 2392 | true, true) //exclusive and allowFailure (anyway not yet checked) |
| 2393 | omciVerify.PerformOmciTest(log.WithSpanFromContext(context.TODO(), ctx), verifyExec) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2394 | |
| Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 2395 | /* give the handler some time here to wait for the OMCi verification result |
| 2396 | after Timeout start and try MibUpload FSM anyway |
| 2397 | (to prevent stopping on just not supported OMCI verification from ONU) */ |
| 2398 | select { |
| 2399 | case <-time.After(((cmn.CDefaultRetries+1)*otst.CTestRequestOmciTimeout + 1) * time.Second): |
| 2400 | logger.Warnw(ctx, "omci start-verification timed out (continue normal)", log.Fields{"device-id": dh.DeviceID}) |
| 2401 | case testresult := <-verifyExec: |
| 2402 | logger.Infow(ctx, "Omci start verification done", log.Fields{"device-id": dh.DeviceID, "result": testresult}) |
| 2403 | case <-dh.deviceDeleteCommChan: |
| 2404 | logger.Warnw(ctx, "Deleting device, stopping the omci test activity", log.Fields{"device-id": dh.DeviceID}) |
| 2405 | return nil |
| 2406 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | /* In py code it looks earlier (on activate ..) |
| 2410 | # Code to Run OMCI Test Action |
| 2411 | kwargs_omci_test_action = { |
| 2412 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 2413 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 2414 | } |
| 2415 | serial_number = device.serial_number |
| 2416 | self._test_request = OmciTestRequest(self.core_proxy, |
| 2417 | self.omci_agent, self.device_id, |
| 2418 | AniG, serial_number, |
| 2419 | self.logical_device_id, |
| 2420 | exclusive=False, |
| 2421 | **kwargs_omci_test_action) |
| 2422 | ... |
| 2423 | # Start test requests after a brief pause |
| 2424 | if not self._test_request_started: |
| 2425 | self._test_request_started = True |
| 2426 | tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 2427 | reactor.callLater(tststart, self._test_request.start_collector) |
| 2428 | |
| 2429 | */ |
| 2430 | /* which is then: in omci_test_request.py : */ |
| 2431 | /* |
| 2432 | def start_collector(self, callback=None): |
| 2433 | """ |
| 2434 | Start the collection loop for an adapter if the frequency > 0 |
| 2435 | |
| 2436 | :param callback: (callable) Function to call to collect PM data |
| 2437 | """ |
| 2438 | self.logger.info("starting-pm-collection", device_name=self.name, default_freq=self.default_freq) |
| 2439 | if callback is None: |
| 2440 | callback = self.perform_test_omci |
| 2441 | |
| 2442 | if self.lc is None: |
| 2443 | self.lc = LoopingCall(callback) |
| 2444 | |
| 2445 | if self.default_freq > 0: |
| 2446 | self.lc.start(interval=self.default_freq / 10) |
| 2447 | |
| 2448 | def perform_test_omci(self): |
| 2449 | """ |
| 2450 | Perform the initial test request |
| 2451 | """ |
| 2452 | ani_g_entities = self._device.configuration.ani_g_entities |
| 2453 | ani_g_entities_ids = list(ani_g_entities.keys()) if ani_g_entities \ |
| 2454 | is not None else None |
| 2455 | self._entity_id = ani_g_entities_ids[0] |
| 2456 | self.logger.info('perform-test', entity_class=self._entity_class, |
| 2457 | entity_id=self._entity_id) |
| 2458 | try: |
| 2459 | frame = MEFrame(self._entity_class, self._entity_id, []).test() |
| 2460 | result = yield self._device.omci_cc.send(frame) |
| 2461 | if not result.fields['omci_message'].fields['success_code']: |
| 2462 | self.logger.info('Self-Test Submitted Successfully', |
| 2463 | code=result.fields[ |
| 2464 | 'omci_message'].fields['success_code']) |
| 2465 | else: |
| 2466 | raise TestFailure('Test Failure: {}'.format( |
| 2467 | result.fields['omci_message'].fields['success_code'])) |
| 2468 | except TimeoutError as e: |
| 2469 | self.deferred.errback(failure.Failure(e)) |
| 2470 | |
| 2471 | except Exception as e: |
| 2472 | self.logger.exception('perform-test-Error', e=e, |
| 2473 | class_id=self._entity_class, |
| 2474 | entity_id=self._entity_id) |
| 2475 | self.deferred.errback(failure.Failure(e)) |
| 2476 | |
| 2477 | */ |
| 2478 | |
| 2479 | // PM related heartbeat??? !!!TODO.... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2480 | //self._heartbeat.Enabled = True |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2481 | |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 2482 | /* Note: Even though FSM calls look 'synchronous' here, FSM is running in background with the effect that possible errors |
| 2483 | * within the MibUpload are not notified in the OnuIndication response, this might be acceptable here, |
| 2484 | * as further OltAdapter processing may rely on the deviceReason event 'MibUploadDone' as a result of the FSM processing |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2485 | * otherwise some processing synchronization would be required - cmp. e.g TechProfile processing |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 2486 | */ |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 2487 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2488 | //call MibUploadFSM - transition up to state UlStInSync |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 2489 | // Breaking this part of code due to sca complexity |
| 2490 | err := dh.CheckAndStartMibUploadFsm(ctx, pDevEntry) |
| 2491 | return err |
| 2492 | } |
| 2493 | |
| 2494 | func (dh *deviceHandler) CheckAndStartMibUploadFsm(ctx context.Context, pDevEntry *mib.OnuDeviceEntry) error { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2495 | pMibUlFsm := pDevEntry.PMibUploadFsm.PFsm |
| Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 2496 | if pMibUlFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2497 | if pMibUlFsm.Is(mib.UlStDisabled) { |
| 2498 | if err := pMibUlFsm.Event(mib.UlEvStart); err != nil { |
| 2499 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2500 | return fmt.Errorf("can't go to state starting: %s", dh.DeviceID) |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2501 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2502 | logger.Debugw(ctx, "MibSyncFsm", log.Fields{"device-id": dh.DeviceID, "state": string(pMibUlFsm.Current())}) |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2503 | //Determine ONU status and start/re-start MIB Synchronization tasks |
| 2504 | //Determine if this ONU has ever synchronized |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2505 | if pDevEntry.IsNewOnu() { |
| 2506 | if err := pMibUlFsm.Event(mib.UlEvResetMib); err != nil { |
| 2507 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state resetting_mib", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2508 | return fmt.Errorf("can't go to state resetting_mib: %s", dh.DeviceID) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2509 | } |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2510 | } else { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2511 | if err := pMibUlFsm.Event(mib.UlEvVerifyAndStoreTPs); err != nil { |
| 2512 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state verify and store TPs", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2513 | return fmt.Errorf("can't go to state verify and store TPs: %s", dh.DeviceID) |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2514 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2515 | logger.Debugw(ctx, "state of MibSyncFsm", log.Fields{"device-id": dh.DeviceID, "state": string(pMibUlFsm.Current())}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2516 | } |
| Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 2517 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2518 | logger.Errorw(ctx, "wrong state of MibSyncFsm - want: disabled", log.Fields{"have": string(pMibUlFsm.Current()), |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2519 | "device-id": dh.DeviceID}) |
| 2520 | return fmt.Errorf("wrong state of MibSyncFsm: %s", dh.DeviceID) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2521 | } |
| 2522 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2523 | logger.Errorw(ctx, "MibSyncFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID}) |
| 2524 | return fmt.Errorf("can't execute MibSync: %s", dh.DeviceID) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2525 | } |
| 2526 | return nil |
| 2527 | } |
| 2528 | |
| Holger Hildebrandt | 68854a8 | 2022-09-05 07:00:21 +0000 | [diff] [blame] | 2529 | func (dh *deviceHandler) UpdateInterface(ctx context.Context) error { |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2530 | //state checking to prevent unneeded processing (eg. on ONU 'unreachable' and 'down') |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2531 | // (but note that the deviceReason may also have changed to e.g. TechProf*Delete_Success in between) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2532 | if dh.getDeviceReason() != cmn.DrStoppingOpenomci { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2533 | logger.Info(ctx, "updateInterface-started - stopping-device", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 2534 | |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2535 | //stop all running FSM processing - make use of the DH-state as mirrored in the deviceReason |
| 2536 | //here no conflict with aborted FSM's should arise as a complete OMCI initialization is assumed on ONU-Up |
| 2537 | //but that might change with some simple MDS check on ONU-Up treatment -> attention!!! |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2538 | if err := dh.resetFsms(ctx, true); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2539 | logger.Errorw(ctx, "error-updateInterface at FSM stop", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2540 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2541 | // abort: system behavior is just unstable ... |
| 2542 | return err |
| 2543 | } |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2544 | //all stored persistent data are not valid anymore (loosing knowledge about the connected ONU) |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 2545 | if !dh.GetDeviceTechProfOnReboot() { |
| 2546 | _ = dh.deleteDevicePersistencyData(ctx) //ignore possible errors here and continue, hope is that data is synchronized with new ONU-Up |
| 2547 | } |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2548 | |
| 2549 | //deviceEntry stop without omciCC reset here, regarding the OMCI_CC still valid for this ONU |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2550 | //stop the device entry to allow for all system event transfers again |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2551 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2552 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2553 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 2554 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2555 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2556 | _ = pDevEntry.Stop(log.WithSpanFromContext(context.TODO(), ctx), false) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2557 | |
| 2558 | //TODO!!! remove existing traffic profiles |
| 2559 | /* from py code, if TP's exist, remove them - not yet implemented |
| 2560 | self._tp = dict() |
| 2561 | # Let TP download happen again |
| 2562 | for uni_id in self._tp_service_specific_task: |
| 2563 | self._tp_service_specific_task[uni_id].clear() |
| 2564 | for uni_id in self._tech_profile_download_done: |
| 2565 | self._tech_profile_download_done[uni_id].clear() |
| 2566 | */ |
| 2567 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2568 | dh.DisableUniPortStateUpdate(ctx) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2569 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2570 | dh.SetReadyForOmciConfig(false) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2571 | |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2572 | if err := dh.ReasonUpdate(ctx, cmn.DrStoppingOpenomci, true); err != nil { |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2573 | // abort: system behavior is just unstable ... |
| 2574 | return err |
| 2575 | } |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2576 | logger.Debugw(ctx, "call DeviceStateUpdate upon update interface", log.Fields{"ConnectStatus": voltha.ConnectStatus_UNREACHABLE, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2577 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID}) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2578 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2579 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2580 | ConnStatus: voltha.ConnectStatus_UNREACHABLE, |
| 2581 | OperStatus: voltha.OperStatus_DISCOVERED, |
| 2582 | }); err != nil { |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2583 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2584 | logger.Errorw(ctx, "error-updating-device-state unreachable-discovered", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2585 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2586 | // abort: system behavior is just unstable ... |
| 2587 | return err |
| 2588 | } |
| akashreddyk | b03dde0 | 2025-12-02 10:53:18 +0530 | [diff] [blame] | 2589 | if dh.GetDeviceTechProfOnReboot() { |
| 2590 | logger.Debugw(ctx, "Storing OnuPersData during device-down-indication", log.Fields{"device": dh.DeviceID, "onu-pers-data": dh.pOnuOmciDevice.SOnuPersistentData}) |
| 2591 | if err := dh.StorePersistentData(ctx); err != nil { |
| 2592 | logger.Warnw(ctx, "store persistent data error - Failed to store DownIndication", |
| 2593 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2594 | } |
| 2595 | } |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2596 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2597 | logger.Debugw(ctx, "updateInterface - device already stopped", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2598 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2599 | return nil |
| 2600 | } |
| 2601 | |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2602 | func (dh *deviceHandler) resetFsms(ctx context.Context, includingMibSyncFsm bool) error { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2603 | //all possible FSM's are stopped or reset here to ensure their transition to 'disabled' |
| 2604 | //it is not sufficient to stop/reset the latest running FSM as done in previous versions |
| 2605 | // as after down/up procedures all FSM's might be active/ongoing (in theory) |
| 2606 | // and using the stop/reset event should never harm |
| Holger Hildebrandt | 12609a1 | 2022-03-25 13:23:25 +0000 | [diff] [blame] | 2607 | logger.Debugw(ctx, "resetFsms entered", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2608 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2609 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Praneeth Kumar Nalmas | fcdd20b | 2024-01-24 22:26:39 +0530 | [diff] [blame] | 2610 | //VOL-5260: During race conditions when adoptDevice has not yet completed |
| 2611 | // and deleteDevice is issued , returning error will further prevent clean up |
| 2612 | // at rwcore . Returning success for clean up to happen and discovery to happen again. |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2613 | if pDevEntry == nil { |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 2614 | errMsg := fmt.Sprintf("Device entry is not found %s", dh.DeviceID) |
| 2615 | logger.Error(ctx, errMsg) |
| 2616 | return status.Error(codes.NotFound, errMsg) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2617 | } |
| Holger Hildebrandt | c8ece36 | 2021-05-17 12:01:10 +0000 | [diff] [blame] | 2618 | if pDevEntry.PDevOmciCC != nil { |
| mpagenko | 8cd1bf7 | 2021-06-22 10:11:19 +0000 | [diff] [blame] | 2619 | pDevEntry.PDevOmciCC.CancelRequestMonitoring(ctx) |
| Holger Hildebrandt | c8ece36 | 2021-05-17 12:01:10 +0000 | [diff] [blame] | 2620 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2621 | pDevEntry.MutexOnuImageStatus.RLock() |
| 2622 | if pDevEntry.POnuImageStatus != nil { |
| 2623 | pDevEntry.POnuImageStatus.CancelProcessing(ctx) |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 2624 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2625 | pDevEntry.MutexOnuImageStatus.RUnlock() |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 2626 | |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2627 | if includingMibSyncFsm { |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 2628 | pDevEntry.CancelProcessing(ctx) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2629 | } |
| 2630 | //MibDownload may run |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2631 | pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2632 | if pMibDlFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2633 | _ = pMibDlFsm.Event(mib.DlEvReset) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2634 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 2635 | //stop any deviceHandler reconcile processing (if running) |
| 2636 | dh.stopReconciling(ctx, false, cWaitReconcileFlowAbortOnError) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2637 | //port lock/unlock FSM's may be active |
| 2638 | if dh.pUnlockStateFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2639 | _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2640 | } |
| 2641 | if dh.pLockStateFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2642 | _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2643 | } |
| 2644 | //techProfile related PonAniConfigFsm FSM may be active |
| 2645 | if dh.pOnuTP != nil { |
| 2646 | // should always be the case here |
| 2647 | // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2648 | if dh.pOnuTP.PAniConfigFsm != nil { |
| 2649 | for uniTP := range dh.pOnuTP.PAniConfigFsm { |
| 2650 | dh.pOnuTP.PAniConfigFsm[uniTP].CancelProcessing(ctx) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 2651 | } |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2652 | } |
| 2653 | for _, uniPort := range dh.uniEntityMap { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2654 | // reset the possibly existing VlanConfigFsm |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2655 | dh.lockVlanConfig.RLock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2656 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniPort.UniID]; exist { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2657 | //VlanFilterFsm exists and was already started |
| mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2658 | dh.lockVlanConfig.RUnlock() |
| mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2659 | //ensure the FSM processing is stopped in case waiting for some response |
| mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 2660 | pVlanFilterFsm.CancelProcessing(ctx) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2661 | } else { |
| 2662 | dh.lockVlanConfig.RUnlock() |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2663 | } |
| 2664 | } |
| 2665 | } |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2666 | |
| 2667 | dh.mutexCollectorFlag.Lock() |
| 2668 | logger.Debugw(ctx, "check-collector-is-running", log.Fields{"device-id": dh.device.Id, "flag": dh.collectorIsRunning}) |
| 2669 | if dh.collectorIsRunning { |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2670 | // Stop collector routine |
| 2671 | dh.stopCollector <- true |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2672 | dh.collectorIsRunning = false |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2673 | } |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2674 | dh.mutexCollectorFlag.Unlock() |
| 2675 | |
| 2676 | dh.mutextAlarmManagerFlag.Lock() |
| 2677 | logger.Debugw(ctx, "check-alarm-manager-is-running", log.Fields{"device-id": dh.device.Id, "flag": dh.alarmManagerIsRunning}) |
| 2678 | if dh.alarmManagerIsRunning { |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2679 | dh.stopAlarmManager <- true |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2680 | dh.alarmManagerIsRunning = false |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2681 | } |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2682 | dh.mutextAlarmManagerFlag.Unlock() |
| 2683 | |
| 2684 | dh.pSelfTestHdlr.SelfTestHandlerLock.Lock() |
| 2685 | logger.Debugw(ctx, "check-self-test-control-block-is-running", log.Fields{"device-id": dh.device.Id, "flag": dh.pSelfTestHdlr.SelfTestHandlerActive}) |
| 2686 | if dh.pSelfTestHdlr.SelfTestHandlerActive { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2687 | dh.pSelfTestHdlr.StopSelfTestModule <- true |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2688 | dh.pSelfTestHdlr.SelfTestHandlerActive = false |
| Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 2689 | } |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2690 | dh.pSelfTestHdlr.SelfTestHandlerLock.Unlock() |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2691 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2692 | // Note: We want flow deletes to be processed on onu down, so do not stop flow monitoring routines |
| 2693 | |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2694 | //reset a possibly running upgrade FSM |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2695 | // (note the Upgrade FSM may stay alive e.g. in state UpgradeStWaitForCommit to endure the ONU reboot) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2696 | dh.lockUpgradeFsm.RLock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2697 | lopOnuUpradeFsm := dh.pOnuUpradeFsm |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2698 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2699 | dh.lockUpgradeFsm.RUnlock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2700 | if lopOnuUpradeFsm != nil { |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2701 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 2702 | //here we do not expect intermediate cancelation, we still allow for other commands on this FSM |
| 2703 | // (even though it may also run into direct cancellation, a bit hard to verify here) |
| 2704 | // so don't set 'dh.upgradeCanceled = true' here! |
| 2705 | lopOnuUpradeFsm.CancelProcessing(ctx, false, voltha.ImageState_CANCELLED_ON_ONU_STATE) //conditional cancel |
| 2706 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2707 | } |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2708 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2709 | logger.Infow(ctx, "resetFsms done", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2710 | return nil |
| 2711 | } |
| 2712 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2713 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2714 | func (dh *deviceHandler) processMibDatabaseSyncEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2715 | logger.Debugw(ctx, "MibInSync event received, adding uni ports and locking the ONU interfaces", log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2716 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2717 | // store persistent data collected during MIB upload processing |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2718 | if err := dh.StorePersistentData(ctx); err != nil { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2719 | logger.Warnw(ctx, "store persistent data error - continue as there will be additional write attempts", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2720 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2721 | } |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2722 | _ = dh.ReasonUpdate(ctx, cmn.DrDiscoveryMibsyncComplete, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2723 | dh.AddAllUniPorts(ctx) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2724 | |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2725 | /* 200605: lock processing after initial MIBUpload removed now as the ONU should be in the lock state per default here */ |
| 2726 | /* 201117: build_dt-berlin-pod-openonugo_1T8GEM_voltha_DT_openonugo_master_test runs into error TC |
| 2727 | * 'Test Disable ONUs and OLT Then Delete ONUs and OLT for DT' with Sercom ONU, which obviously needs |
| 2728 | * disable/enable toggling here to allow traffic |
| 2729 | * but moreover it might be useful for tracking the interface operState changes if this will be implemented, |
| 2730 | * like the py comment says: |
| 2731 | * # start by locking all the unis till mib sync and initial mib is downloaded |
| 2732 | * # this way we can capture the port down/up events when we are ready |
| 2733 | */ |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2734 | |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2735 | // Init Uni Ports to Admin locked state |
| 2736 | // *** should generate UniLockStateDone event ***** |
| 2737 | if dh.pLockStateFsm == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2738 | dh.createUniLockFsm(ctx, true, cmn.UniLockStateDone) |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2739 | } else { //LockStateFSM already init |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2740 | dh.pLockStateFsm.SetSuccessEvent(cmn.UniLockStateDone) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2741 | dh.runUniLockFsm(ctx, true) |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2742 | } |
| 2743 | } |
| 2744 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2745 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2746 | func (dh *deviceHandler) processUniLockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2747 | logger.Infow(ctx, "UniLockStateDone event: Starting MIB download", log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2748 | /* Mib download procedure - |
| 2749 | ***** should run over 'downloaded' state and generate MibDownloadDone event ***** |
| 2750 | */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2751 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2752 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2753 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2754 | return |
| 2755 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2756 | pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2757 | if pMibDlFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2758 | if pMibDlFsm.Is(mib.DlStDisabled) { |
| 2759 | if err := pMibDlFsm.Event(mib.DlEvStart); err != nil { |
| 2760 | logger.Errorw(ctx, "MibDownloadFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2761 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2762 | } else { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2763 | logger.Debugw(ctx, "MibDownloadFsm", log.Fields{"device-id": dh.DeviceID, "state": string(pMibDlFsm.Current())}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2764 | // maybe use more specific states here for the specific download steps ... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2765 | if err := pMibDlFsm.Event(mib.DlEvCreateGal); err != nil { |
| 2766 | logger.Errorw(ctx, "MibDownloadFsm: Can't start CreateGal", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2767 | } else { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2768 | logger.Debugw(ctx, "state of MibDownloadFsm", log.Fields{"device-id": dh.DeviceID, "state": string(pMibDlFsm.Current())}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2769 | //Begin MIB data download (running autonomously) |
| 2770 | } |
| 2771 | } |
| 2772 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2773 | logger.Errorw(ctx, "wrong state of MibDownloadFsm - want: disabled", log.Fields{"have": string(pMibDlFsm.Current()), |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2774 | "device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2775 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2776 | } |
| 2777 | /***** Mib download started */ |
| 2778 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2779 | logger.Errorw(ctx, "MibDownloadFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2780 | } |
| 2781 | } |
| 2782 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2783 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2784 | func (dh *deviceHandler) processMibDownloadDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2785 | logger.Info(ctx, "MibDownloadDone event received, unlocking the ONU interfaces", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 2786 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 2787 | if pDevEntry == nil { |
| 2788 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 2789 | return |
| 2790 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2791 | if !dh.IsReconciling() { |
| Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 2792 | logger.Debugw(ctx, "call DeviceUpdate and DeviceStateUpdate upon mib-download done", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2793 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 2794 | // update device info in core |
| 2795 | pDevEntry.MutexPersOnuConfig.RLock() |
| 2796 | dh.device.Vendor = pDevEntry.SOnuPersistentData.PersVendorID |
| 2797 | dh.device.VendorId = pDevEntry.SOnuPersistentData.PersVendorID |
| 2798 | dh.device.Model = pDevEntry.SOnuPersistentData.PersVersion |
| 2799 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 2800 | dh.logicalDeviceID = dh.DeviceID |
| 2801 | if err := dh.updateDeviceInCore(ctx, dh.device); err != nil { |
| 2802 | logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err}) |
| 2803 | } |
| 2804 | // update device state in core |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2805 | //we allow a possible OnuSw image commit only in the normal startup, not at reconciling |
| 2806 | // in case of adapter restart connected to an ONU upgrade I would not rely on the image quality |
| 2807 | // maybe some 'forced' commitment can be done in this situation from system management (or upgrade restarted) |
| 2808 | dh.checkOnOnuImageCommit(ctx) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2809 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2810 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2811 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2812 | OperStatus: voltha.OperStatus_ACTIVE, |
| 2813 | }); err != nil { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2814 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2815 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2816 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2817 | logger.Debugw(ctx, "dev state updated to 'Oper.Active'", log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2818 | } |
| 2819 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2820 | logger.Info(ctx, "reconciling - don't notify core about updated device info and DeviceStateUpdate to ACTIVE", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2821 | log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2822 | } |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2823 | _ = dh.ReasonUpdate(ctx, cmn.DrInitialMibDownloaded, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2824 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2825 | if !dh.GetCollectorIsRunning() { |
| Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 2826 | var waitForOmciProcessor sync.WaitGroup |
| 2827 | waitForOmciProcessor.Add(1) |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2828 | // Start PM collector routine |
| Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 2829 | go dh.StartCollector(ctx, &waitForOmciProcessor) |
| 2830 | waitForOmciProcessor.Wait() |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2831 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2832 | if !dh.GetAlarmManagerIsRunning(ctx) { |
| 2833 | go dh.StartAlarmManager(ctx) |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2836 | // Start flow handler routines per UNI |
| 2837 | for _, uniPort := range dh.uniEntityMap { |
| 2838 | // only if this port was enabled for use by the operator at startup |
| 2839 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 2840 | if !dh.GetFlowMonitoringIsRunning(uniPort.UniID) { |
| 2841 | go dh.PerOnuFlowHandlerRoutine(uniPort.UniID) |
| 2842 | } |
| 2843 | } |
| 2844 | } |
| 2845 | |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2846 | // Initialize classical L2 PM Interval Counters |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2847 | if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventInit); err != nil { |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2848 | // There is no way we should be landing here, but if we do then |
| 2849 | // there is nothing much we can do about this other than log error |
| 2850 | logger.Errorw(ctx, "error starting l2 pm fsm", log.Fields{"device-id": dh.device.Id, "err": err}) |
| 2851 | } |
| 2852 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2853 | dh.SetReadyForOmciConfig(true) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2854 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2855 | pDevEntry.MutexPersOnuConfig.RLock() |
| 2856 | if dh.IsReconciling() && pDevEntry.SOnuPersistentData.PersUniDisableDone { |
| 2857 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2858 | logger.Warn(ctx, "reconciling - uni-ports were disabled by admin before adapter restart - keep the ports locked", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2859 | log.Fields{"device-id": dh.DeviceID}) |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 2860 | dh.mutexForDisableDeviceRequested.Lock() |
| 2861 | dh.disableDeviceRequested = true |
| 2862 | dh.mutexForDisableDeviceRequested.Unlock() |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 2863 | dh.ReconcileDeviceTechProf(ctx) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2864 | // reconcilement will be continued after ani config is done |
| 2865 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2866 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2867 | // *** should generate UniUnlockStateDone event ***** |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 2868 | dh.mutexForDisableDeviceRequested.RLock() |
| 2869 | if !dh.disableDeviceRequested { |
| 2870 | if dh.pUnlockStateFsm == nil { |
| 2871 | dh.createUniLockFsm(ctx, false, cmn.UniUnlockStateDone) |
| 2872 | } else { //UnlockStateFSM already init |
| 2873 | dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniUnlockStateDone) |
| 2874 | dh.runUniLockFsm(ctx, false) |
| 2875 | } |
| 2876 | dh.mutexForDisableDeviceRequested.RUnlock() |
| 2877 | } else { |
| 2878 | dh.mutexForDisableDeviceRequested.RUnlock() |
| 2879 | logger.Debugw(ctx, "Uni already lock", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2880 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2881 | } |
| 2882 | } |
| 2883 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2884 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2885 | func (dh *deviceHandler) processUniUnlockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2886 | dh.EnableUniPortStateUpdate(ctx) //cmp python yield self.enable_ports() |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2887 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2888 | if !dh.IsReconciling() { |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 2889 | // Check if TPs are available post device reboot. If TPs are available start processing them and configure flows |
| 2890 | if dh.GetDeviceTechProfOnReboot() { |
| 2891 | if dh.CheckForDeviceTechProf(ctx) { |
| 2892 | go dh.DeviceFlowConfigOnReboot(ctx) |
| 2893 | } |
| 2894 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2895 | logger.Infow(ctx, "UniUnlockStateDone event: Sending OnuUp event", log.Fields{"device-id": dh.DeviceID}) |
| ozgecanetsia | 2f05ed3 | 2021-05-31 17:13:48 +0300 | [diff] [blame] | 2896 | raisedTs := time.Now().Unix() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2897 | go dh.sendOnuOperStateEvent(ctx, voltha.OperStatus_ACTIVE, dh.DeviceID, raisedTs) //cmp python onu_active_event |
| 2898 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2899 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2900 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2901 | return |
| 2902 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2903 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2904 | pDevEntry.SOnuPersistentData.PersUniUnlockDone = true |
| 2905 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2906 | if err := dh.StorePersistentData(ctx); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2907 | logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2908 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2909 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2910 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2911 | logger.Info(ctx, "reconciling - don't notify core that onu went to active but trigger tech profile config", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2912 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 2913 | dh.ReconcileDeviceTechProf(ctx) |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 2914 | |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2915 | // reconcilement will be continued after ani config is done |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 2916 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2917 | } |
| 2918 | } |
| 2919 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2920 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2921 | func (dh *deviceHandler) processUniDisableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2922 | logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2923 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2924 | |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2925 | // disable device should have no impact on ConnStatus |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2926 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2927 | DeviceId: dh.DeviceID, |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2928 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2929 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 2930 | }); err != nil { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2931 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2932 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2933 | } |
| 2934 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2935 | logger.Debugw(ctx, "DeviceReasonUpdate upon disable", log.Fields{"reason": cmn.DeviceReasonMap[cmn.DrOmciAdminLock], "device-id": dh.DeviceID}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2936 | // DeviceReason to update acc.to modified py code as per beginning of Sept 2020 |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2937 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciAdminLock, true) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2938 | |
| 2939 | //transfer the modified logical uni port state |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2940 | dh.DisableUniPortStateUpdate(ctx) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2941 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2942 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2943 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2944 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2945 | return |
| 2946 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2947 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2948 | pDevEntry.SOnuPersistentData.PersUniDisableDone = true |
| 2949 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2950 | if err := dh.StorePersistentData(ctx); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2951 | logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2952 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2953 | } |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2954 | } |
| 2955 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2956 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2957 | func (dh *deviceHandler) processUniEnableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2958 | logger.Debugw(ctx, "DeviceStateUpdate upon re-enable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2959 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID}) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2960 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2961 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2962 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2963 | OperStatus: voltha.OperStatus_ACTIVE, |
| 2964 | }); err != nil { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2965 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2966 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2967 | } |
| 2968 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2969 | logger.Debugw(ctx, "DeviceReasonUpdate upon re-enable", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2970 | "reason": cmn.DeviceReasonMap[cmn.DrOnuReenabled], "device-id": dh.DeviceID}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2971 | // DeviceReason to update acc.to modified py code as per beginning of Sept 2020 |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2972 | _ = dh.ReasonUpdate(ctx, cmn.DrOnuReenabled, true) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2973 | |
| 2974 | //transfer the modified logical uni port state |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2975 | dh.EnableUniPortStateUpdate(ctx) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2976 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2977 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2978 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2979 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2980 | return |
| 2981 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2982 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2983 | pDevEntry.SOnuPersistentData.PersUniDisableDone = false |
| 2984 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2985 | if err := dh.StorePersistentData(ctx); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2986 | logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2987 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2988 | } |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2989 | } |
| 2990 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2991 | //nolint:unparam |
| Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 2992 | func (dh *deviceHandler) processUniEnableStateFailedEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2993 | logger.Debugw(ctx, "DeviceStateUpdate upon re-enable failure. ", log.Fields{ |
| 2994 | "OperStatus": voltha.OperStatus_FAILED, "device-id": dh.DeviceID}) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2995 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 2996 | DeviceId: dh.DeviceID, |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2997 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
| Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 2998 | OperStatus: voltha.OperStatus_FAILED, |
| 2999 | }); err != nil { |
| 3000 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| 3001 | } |
| 3002 | } |
| 3003 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3004 | func (dh *deviceHandler) processOmciAniConfigDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 3005 | if devEvent == cmn.OmciAniConfigDone { |
| 3006 | logger.Debugw(ctx, "OmciAniConfigDone event received", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3007 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 3008 | // - which may cause some inconsistency |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3009 | if dh.getDeviceReason() != cmn.DrTechProfileConfigDownloadSuccess { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 3010 | // which may be the case from some previous activity even on this UNI Port (but also other UNI ports) |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 3011 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3012 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3013 | if dh.IsReconciling() { |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 3014 | // during reconciling with OMCI configuration in TT multi-UNI scenario, OmciAniConfigDone is reached several times |
| 3015 | // therefore it must be ensured that reconciling of flow config is only started on the first pass of this code position |
| 3016 | dh.mutexReconcilingFirstPassFlag.Lock() |
| 3017 | if dh.reconcilingFirstPass { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3018 | logger.Info(ctx, "reconciling - OmciAniConfigDone first pass, start flow processing", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 3019 | dh.reconcilingFirstPass = false |
| 3020 | go dh.ReconcileDeviceFlowConfig(ctx) |
| 3021 | } |
| 3022 | dh.mutexReconcilingFirstPassFlag.Unlock() |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3023 | } |
| 3024 | } else { // should be the OmciAniResourceRemoved block |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3025 | logger.Debugw(ctx, "OmciAniResourceRemoved event received", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3026 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 3027 | // - which may cause some inconsistency |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3028 | if dh.getDeviceReason() != cmn.DrTechProfileConfigDeleteSuccess { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 3029 | // which may be the case from some previous activity even on this ONU port (but also other UNI ports) |
| 3030 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDeleteSuccess, true) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3031 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3032 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3033 | } |
| 3034 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3035 | func (dh *deviceHandler) processOmciVlanFilterDoneEvent(ctx context.Context, aDevEvent cmn.OnuDeviceEvent) { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3036 | logger.Debugw(ctx, "OmciVlanFilterDone event received", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3037 | log.Fields{"device-id": dh.DeviceID, "event": aDevEvent}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3038 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 3039 | // - which may cause some inconsistency |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3040 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3041 | if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterAddDoneNoKvStore { |
| 3042 | if dh.getDeviceReason() != cmn.DrOmciFlowsPushed { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 3043 | // which may be the case from some previous activity on another UNI Port of the ONU |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3044 | // or even some previous flow add activity on the same port |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 3045 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsPushed, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3046 | } |
| 3047 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3048 | if dh.getDeviceReason() != cmn.DrOmciFlowsDeleted { |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3049 | //not relevant for reconcile |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 3050 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsDeleted, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3051 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3052 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3053 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3054 | if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterRemDone { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3055 | //events that request KvStore write |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3056 | if err := dh.StorePersistentData(ctx); err != nil { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3057 | logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3058 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3059 | } |
| 3060 | } else { |
| 3061 | logger.Debugw(ctx, "OmciVlanFilter*Done* - write to KvStore not requested", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3062 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3063 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3064 | } |
| 3065 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3066 | // DeviceProcStatusUpdate evaluates possible processing events and initiates according next activities |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3067 | func (dh *deviceHandler) DeviceProcStatusUpdate(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3068 | switch devEvent { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3069 | case cmn.MibDatabaseSync: |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3070 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3071 | dh.processMibDatabaseSyncEvent(ctx, devEvent) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3072 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3073 | case cmn.UniLockStateDone: |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 3074 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3075 | dh.processUniLockStateDoneEvent(ctx, devEvent) |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 3076 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3077 | case cmn.MibDownloadDone: |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3078 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3079 | dh.processMibDownloadDoneEvent(ctx, devEvent) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3080 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3081 | case cmn.UniUnlockStateDone: |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3082 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3083 | dh.processUniUnlockStateDoneEvent(ctx, devEvent) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3084 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3085 | case cmn.UniEnableStateDone: |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3086 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3087 | dh.processUniEnableStateDoneEvent(ctx, devEvent) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3088 | } |
| Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 3089 | case cmn.UniEnableStateFailed: |
| 3090 | { |
| 3091 | dh.processUniEnableStateFailedEvent(ctx, devEvent) |
| 3092 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3093 | case cmn.UniDisableStateDone: |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3094 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3095 | dh.processUniDisableStateDoneEvent(ctx, devEvent) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3096 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3097 | case cmn.OmciAniConfigDone, cmn.OmciAniResourceRemoved: |
| mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 3098 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3099 | dh.processOmciAniConfigDoneEvent(ctx, devEvent) |
| mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 3100 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3101 | case cmn.OmciVlanFilterAddDone, cmn.OmciVlanFilterAddDoneNoKvStore, cmn.OmciVlanFilterRemDone, cmn.OmciVlanFilterRemDoneNoKvStore: |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3102 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3103 | dh.processOmciVlanFilterDoneEvent(ctx, devEvent) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3104 | } |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3105 | default: |
| 3106 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3107 | logger.Debugw(ctx, "unhandled-device-event", log.Fields{"device-id": dh.DeviceID, "event": devEvent}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3108 | } |
| 3109 | } //switch |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 3110 | } |
| 3111 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3112 | func (dh *deviceHandler) addUniPort(ctx context.Context, aUniInstNo uint16, aUniID uint8, aPortType cmn.UniPortType) { |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3113 | // parameters are IntfId, OnuId, uniId |
| Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 3114 | uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3115 | uint32(aUniID)) |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3116 | if _, present := dh.uniEntityMap[uniNo]; present { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3117 | logger.Warnw(ctx, "OnuUniPort-add: Port already exists", log.Fields{"device-id": dh.DeviceID, "for InstanceId": aUniInstNo}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 3118 | } else { |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3119 | //with arguments aUniID, a_portNo, aPortType |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3120 | pUniPort := cmn.NewOnuUniPort(ctx, aUniID, uniNo, aUniInstNo, aPortType) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 3121 | if pUniPort == nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3122 | logger.Warnw(ctx, "OnuUniPort-add: Could not create Port", log.Fields{"device-id": dh.DeviceID, "for InstanceId": aUniInstNo}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 3123 | } else { |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3124 | //store UniPort with the System-PortNumber key |
| 3125 | dh.uniEntityMap[uniNo] = pUniPort |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3126 | if !dh.IsReconciling() { |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 3127 | // create announce the UniPort to the core as VOLTHA Port object |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3128 | if err := pUniPort.CreateVolthaPort(ctx, dh); err == nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3129 | logger.Infow(ctx, "OnuUniPort-added", log.Fields{"device-id": dh.DeviceID, "for PortNo": uniNo}) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 3130 | } //error logging already within UniPort method |
| 3131 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3132 | logger.Warn(ctx, "reconciling - OnuUniPort already added", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 3133 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 3134 | } |
| 3135 | } |
| 3136 | } |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3137 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3138 | func (dh *deviceHandler) AddAllUniPorts(ctx context.Context) { |
| 3139 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3140 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3141 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3142 | return |
| 3143 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3144 | uniCnt := uint8(0) //UNI Port limit: see MaxUnisPerOnu (by now 16) (OMCI supports max 255 p.b.) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3145 | if pptpInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3146 | ctx, me.PhysicalPathTerminationPointEthernetUniClassID); len(pptpInstKeys) > 0 { |
| 3147 | for _, mgmtEntityID := range pptpInstKeys { |
| 3148 | logger.Debugw(ctx, "Add PPTPEthUni port for MIB-stored instance:", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3149 | "device-id": dh.DeviceID, "PPTPEthUni EntityID": mgmtEntityID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3150 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniPPTP) |
| 3151 | uniCnt++ |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3152 | } |
| 3153 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3154 | logger.Debugw(ctx, "No PPTP instances found", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3155 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3156 | if veipInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3157 | ctx, me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 { |
| 3158 | for _, mgmtEntityID := range veipInstKeys { |
| 3159 | logger.Debugw(ctx, "Add VEIP for MIB-stored instance:", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3160 | "device-id": dh.DeviceID, "VEIP EntityID": mgmtEntityID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3161 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniVEIP) |
| 3162 | uniCnt++ |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3163 | } |
| 3164 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3165 | logger.Debugw(ctx, "No VEIP instances found", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3166 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3167 | if potsInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
| ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 3168 | ctx, me.PhysicalPathTerminationPointPotsUniClassID); len(potsInstKeys) > 0 { |
| 3169 | for _, mgmtEntityID := range potsInstKeys { |
| 3170 | logger.Debugw(ctx, "Add PPTP Pots UNI for MIB-stored instance:", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3171 | "device-id": dh.DeviceID, "PPTP Pots UNI EntityID": mgmtEntityID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3172 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniPPTPPots) |
| 3173 | uniCnt++ |
| ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 3174 | } |
| 3175 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3176 | logger.Debugw(ctx, "No PPTP Pots UNI instances found", log.Fields{"device-id": dh.DeviceID}) |
| ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 3177 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3178 | if uniCnt == 0 { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3179 | logger.Warnw(ctx, "No UniG instances found", log.Fields{"device-id": dh.DeviceID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3180 | return |
| 3181 | } |
| 3182 | |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 3183 | //Note: For the moment is is not required to include the (newly added) POTS ports into the range |
| 3184 | // of flowCall or reconcile channels. But some sort of flow and reconcile processing might get necessary |
| 3185 | // also for the POTS ports, so we include them already for future usage - should anyway do no great harm |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3186 | dh.flowCbChan = make([]chan FlowCb, uniCnt) |
| 3187 | dh.stopFlowMonitoringRoutine = make([]chan bool, uniCnt) |
| 3188 | dh.isFlowMonitoringRoutineActive = make([]bool, uniCnt) |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 3189 | //chUniVlanConfigReconcilingDone needs to have the capacity of all UniPorts as flow reconcile may run parallel for all of them |
| 3190 | dh.chUniVlanConfigReconcilingDone = make(chan uint16, uniCnt) |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 3191 | dh.chUniVlanConfigOnRebootDone = make(chan uint16, uniCnt) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3192 | for i := 0; i < int(uniCnt); i++ { |
| 3193 | dh.flowCbChan[i] = make(chan FlowCb, dh.pOpenOnuAc.config.MaxConcurrentFlowsPerUni) |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 3194 | dh.stopFlowMonitoringRoutine[i] = make(chan bool, 1) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3195 | } |
| 3196 | } |
| 3197 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3198 | // EnableUniPortStateUpdate enables UniPortState and update core port state accordingly |
| 3199 | func (dh *deviceHandler) EnableUniPortStateUpdate(ctx context.Context) { |
| Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 3200 | // py code was updated 2003xx to activate the real ONU UNI ports per OMCI (VEIP or PPTP) |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3201 | // but towards core only the first port active state is signaled |
| Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 3202 | // with following remark: |
| 3203 | // # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow |
| 3204 | // # load on the core |
| 3205 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3206 | // lock_ports(false) as done in py code here is shifted to separate call from device event processing |
| Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 3207 | |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3208 | for uniNo, uniPort := range dh.uniEntityMap { |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3209 | // only if this port is validated for operState transfer |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3210 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 3211 | logger.Infow(ctx, "OnuUniPort-forced-OperState-ACTIVE", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID}) |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 3212 | uniPort.SetOperState(common.OperStatus_ACTIVE) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3213 | if !dh.IsReconciling() { |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 3214 | //maybe also use getter functions on uniPort - perhaps later ... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3215 | go func(port *cmn.OnuUniPort) { |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3216 | if err := dh.updatePortStateInCore(ctx, &ca.PortState{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3217 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3218 | PortType: voltha.Port_ETHERNET_UNI, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3219 | PortNo: port.PortNo, |
| 3220 | OperStatus: port.OperState, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3221 | }); err != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3222 | logger.Errorw(ctx, "port-state-update-failed", log.Fields{"error": err, "port-no": uniPort.PortNo, "device-id": dh.DeviceID}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3223 | } |
| 3224 | }(uniPort) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 3225 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3226 | logger.Debug(ctx, "reconciling - don't notify core about PortStateUpdate", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 3227 | } |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3228 | } |
| 3229 | } |
| 3230 | } |
| 3231 | |
| 3232 | // Disable UniPortState and update core port state accordingly |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3233 | func (dh *deviceHandler) DisableUniPortStateUpdate(ctx context.Context) { |
| 3234 | // compare EnableUniPortStateUpdate() above |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3235 | // -> use current restriction to operate only on first UNI port as inherited from actual Py code |
| 3236 | for uniNo, uniPort := range dh.uniEntityMap { |
| 3237 | // only if this port is validated for operState transfer |
| Matteo Scandolo | 20d180c | 2021-06-10 17:20:21 +0200 | [diff] [blame] | 3238 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3239 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 3240 | logger.Infow(ctx, "OnuUniPort-forced-OperState-UNKNOWN", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID}) |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 3241 | uniPort.SetOperState(common.OperStatus_UNKNOWN) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3242 | if !dh.IsReconciling() { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3243 | //maybe also use getter functions on uniPort - perhaps later ... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3244 | go func(port *cmn.OnuUniPort) { |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3245 | if err := dh.updatePortStateInCore(ctx, &ca.PortState{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3246 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3247 | PortType: voltha.Port_ETHERNET_UNI, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3248 | PortNo: port.PortNo, |
| 3249 | OperStatus: port.OperState, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3250 | }); err != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3251 | logger.Errorw(ctx, "port-state-update-failed", log.Fields{"error": err, "port-no": uniPort.PortNo, "device-id": dh.DeviceID}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3252 | } |
| 3253 | }(uniPort) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3254 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3255 | logger.Debug(ctx, "reconciling - don't notify core about PortStateUpdate", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3256 | } |
| 3257 | |
| Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 3258 | } |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3259 | } |
| 3260 | } |
| 3261 | |
| 3262 | // ONU_Active/Inactive announcement on system KAFKA bus |
| 3263 | // tried to re-use procedure of oltUpDownIndication from openolt_eventmgr.go with used values from Py code |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 3264 | func (dh *deviceHandler) sendOnuOperStateEvent(ctx context.Context, aOperState common.OperStatus_Types, aDeviceID string, raisedTs int64) { |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3265 | var de voltha.DeviceEvent |
| 3266 | eventContext := make(map[string]string) |
| 3267 | //Populating event context |
| 3268 | // assume giving ParentId in GetDevice twice really gives the ParentDevice (there is no GetParentDevice()...) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3269 | parentDevice, err := dh.getDeviceFromCore(ctx, dh.parentID) |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3270 | if err != nil || parentDevice == nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3271 | logger.Errorw(ctx, "Failed to fetch parent device for OnuEvent", |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3272 | log.Fields{"device-id": dh.DeviceID, "parentID": dh.parentID, "err": err}) |
| Holger Hildebrandt | 7ec14c4 | 2021-05-28 14:21:58 +0000 | [diff] [blame] | 3273 | return //TODO with VOL-3045: rw-core is unresponsive: report error and/or perform self-initiated onu-reset? |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3274 | } |
| 3275 | oltSerialNumber := parentDevice.SerialNumber |
| 3276 | |
| 3277 | eventContext["pon-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.IntfId), 10) |
| 3278 | eventContext["onu-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.OnuId), 10) |
| 3279 | eventContext["serial-number"] = dh.device.SerialNumber |
| ssiddiqui | 1221d1a | 2021-02-15 11:12:51 +0530 | [diff] [blame] | 3280 | eventContext["olt-serial-number"] = oltSerialNumber |
| 3281 | eventContext["device-id"] = aDeviceID |
| 3282 | eventContext["registration-id"] = aDeviceID //py: string(device_id)?? |
| ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 3283 | eventContext["num-of-unis"] = strconv.Itoa(len(dh.uniEntityMap)) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3284 | if deviceEntry := dh.GetOnuDeviceEntry(ctx, false); deviceEntry != nil { |
| 3285 | deviceEntry.MutexPersOnuConfig.RLock() |
| Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 3286 | eventContext["vendor-id"] = deviceEntry.SOnuPersistentData.PersVendorID |
| 3287 | eventContext["model"] = deviceEntry.SOnuPersistentData.PersVersion |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3288 | eventContext["equipment-id"] = deviceEntry.SOnuPersistentData.PersEquipmentID |
| 3289 | deviceEntry.MutexPersOnuConfig.RUnlock() |
| 3290 | eventContext["software-version"] = deviceEntry.GetActiveImageVersion(ctx) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3291 | eventContext["inactive-software-version"] = deviceEntry.GetInactiveImageVersion(ctx) |
| ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 3292 | logger.Debugw(ctx, "prepare ONU_ACTIVATED event", |
| 3293 | log.Fields{"device-id": aDeviceID, "EventContext": eventContext}) |
| 3294 | } else { |
| 3295 | logger.Errorw(ctx, "Failed to fetch device-entry. ONU_ACTIVATED event is not sent", |
| 3296 | log.Fields{"device-id": aDeviceID}) |
| 3297 | return |
| 3298 | } |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3299 | |
| 3300 | /* Populating device event body */ |
| 3301 | de.Context = eventContext |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3302 | de.ResourceId = aDeviceID |
| 3303 | if aOperState == voltha.OperStatus_ACTIVE { |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3304 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "RAISE_EVENT") |
| 3305 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 3306 | cEventObjectType, cOnuActivatedEvent, "Raised") |
| 3307 | } else { |
| 3308 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "CLEAR_EVENT") |
| 3309 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 3310 | cEventObjectType, cOnuActivatedEvent, "Cleared") |
| 3311 | } |
| 3312 | /* Send event to KAFKA */ |
| kesavand | 510a31c | 2022-03-16 17:12:12 +0530 | [diff] [blame] | 3313 | if err := dh.EventProxy.SendDeviceEventWithKey(ctx, &de, equipment, pon, raisedTs, aDeviceID); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3314 | logger.Warnw(ctx, "could not send ONU_ACTIVATED event", |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3315 | log.Fields{"device-id": aDeviceID, "error": err}) |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3316 | } |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3317 | logger.Infow(ctx, "ctx, ONU_ACTIVATED event sent to KAFKA", |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3318 | log.Fields{"device-id": aDeviceID, "with-EventName": de.DeviceEventName}) |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3319 | } |
| 3320 | |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3321 | // createUniLockFsm initializes and runs the UniLock FSM to transfer the OMCI related commands for port lock/unlock |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3322 | func (dh *deviceHandler) createUniLockFsm(ctx context.Context, aAdminState bool, devEvent cmn.OnuDeviceEvent) { |
| Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 3323 | chLSFsm := make(chan cmn.Message, 2) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3324 | var sFsmName string |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3325 | if aAdminState { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3326 | logger.Debugw(ctx, "createLockStateFSM", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3327 | sFsmName = "LockStateFSM" |
| 3328 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3329 | logger.Debugw(ctx, "createUnlockStateFSM", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3330 | sFsmName = "UnLockStateFSM" |
| 3331 | } |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3332 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3333 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3334 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3335 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3336 | return |
| 3337 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3338 | pLSFsm := uniprt.NewLockStateFsm(ctx, aAdminState, devEvent, sFsmName, dh, pDevEntry, chLSFsm) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3339 | if pLSFsm != nil { |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3340 | if aAdminState { |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3341 | dh.pLockStateFsm = pLSFsm |
| 3342 | } else { |
| 3343 | dh.pUnlockStateFsm = pLSFsm |
| 3344 | } |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3345 | dh.runUniLockFsm(ctx, aAdminState) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3346 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3347 | logger.Errorw(ctx, "LockStateFSM could not be created - abort!!", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3348 | } |
| 3349 | } |
| 3350 | |
| 3351 | // runUniLockFsm starts the UniLock FSM to transfer the OMCI related commands for port lock/unlock |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3352 | func (dh *deviceHandler) runUniLockFsm(ctx context.Context, aAdminState bool) { |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3353 | /* Uni Port lock/unlock procedure - |
| 3354 | ***** should run via 'adminDone' state and generate the argument requested event ***** |
| 3355 | */ |
| 3356 | var pLSStatemachine *fsm.FSM |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3357 | if aAdminState { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3358 | pLSStatemachine = dh.pLockStateFsm.PAdaptFsm.PFsm |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3359 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 3360 | if (dh.pUnlockStateFsm != nil) && |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3361 | (dh.pUnlockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) { |
| 3362 | _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3363 | } |
| 3364 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3365 | pLSStatemachine = dh.pUnlockStateFsm.PAdaptFsm.PFsm |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3366 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 3367 | if (dh.pLockStateFsm != nil) && |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3368 | (dh.pLockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) { |
| 3369 | _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3370 | } |
| 3371 | } |
| 3372 | if pLSStatemachine != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3373 | if pLSStatemachine.Is(uniprt.UniStDisabled) { |
| 3374 | if err := pLSStatemachine.Event(uniprt.UniEvStart); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3375 | logger.Warnw(ctx, "LockStateFSM: can't start", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3376 | // maybe try a FSM reset and then again ... - TODO!!! |
| 3377 | } else { |
| 3378 | /***** LockStateFSM started */ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3379 | logger.Debugw(ctx, "LockStateFSM started", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3380 | "state": pLSStatemachine.Current(), "device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3381 | } |
| 3382 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3383 | logger.Warnw(ctx, "wrong state of LockStateFSM - want: disabled", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3384 | "have": pLSStatemachine.Current(), "device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3385 | // maybe try a FSM reset and then again ... - TODO!!! |
| 3386 | } |
| 3387 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3388 | logger.Errorw(ctx, "LockStateFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3389 | // maybe try a FSM reset and then again ... - TODO!!! |
| 3390 | } |
| 3391 | } |
| 3392 | |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3393 | // createOnuUpgradeFsm initializes and runs the Onu Software upgrade FSM |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3394 | // precondition: lockUpgradeFsm is already locked from caller of this function |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3395 | // |
| 3396 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3397 | func (dh *deviceHandler) createOnuUpgradeFsm(ctx context.Context, apDevEntry *mib.OnuDeviceEntry, aDevEvent cmn.OnuDeviceEvent) error { |
| Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 3398 | chUpgradeFsm := make(chan cmn.Message, 2) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3399 | var sFsmName = "OnuSwUpgradeFSM" |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3400 | logger.Debugw(ctx, "create OnuSwUpgradeFSM", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3401 | if apDevEntry.PDevOmciCC == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3402 | logger.Errorw(ctx, "no valid OnuDevice or omciCC - abort", log.Fields{"device-id": dh.DeviceID}) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3403 | return fmt.Errorf("no valid omciCC - abort for device-id: %s", dh.device.Id) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3404 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3405 | dh.pOnuUpradeFsm = swupg.NewOnuUpgradeFsm(ctx, dh, apDevEntry, apDevEntry.GetOnuDB(), aDevEvent, |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3406 | sFsmName, chUpgradeFsm) |
| 3407 | if dh.pOnuUpradeFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3408 | pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3409 | if pUpgradeStatemachine != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3410 | if pUpgradeStatemachine.Is(swupg.UpgradeStDisabled) { |
| 3411 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvStart); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3412 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't start", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3413 | // maybe try a FSM reset and then again ... - TODO!!! |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3414 | return fmt.Errorf("OnuSwUpgradeFSM could not be started for device-id: %s", dh.device.Id) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3415 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3416 | /***** Upgrade FSM started */ |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 3417 | //reset the last stored upgrade states (which anyway should be don't care as long as the newly created FSM exists) |
| 3418 | (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 3419 | (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR |
| 3420 | (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3421 | logger.Debugw(ctx, "OnuSwUpgradeFSM started", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3422 | "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3423 | } else { |
| 3424 | logger.Errorw(ctx, "wrong state of OnuSwUpgradeFSM to start - want: disabled", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3425 | "have": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3426 | // maybe try a FSM reset and then again ... - TODO!!! |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3427 | return fmt.Errorf("OnuSwUpgradeFSM could not be started for device-id: %s, wrong internal state", dh.device.Id) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3428 | } |
| 3429 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3430 | logger.Errorw(ctx, "OnuSwUpgradeFSM internal FSM invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3431 | // maybe try a FSM reset and then again ... - TODO!!! |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3432 | return fmt.Errorf("OnuSwUpgradeFSM internal FSM could not be created for device-id: %s", dh.device.Id) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3433 | } |
| 3434 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3435 | logger.Errorw(ctx, "OnuSwUpgradeFSM could not be created - abort", log.Fields{"device-id": dh.DeviceID}) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3436 | return fmt.Errorf("OnuSwUpgradeFSM could not be created - abort for device-id: %s", dh.device.Id) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3437 | } |
| 3438 | return nil |
| 3439 | } |
| 3440 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3441 | // RemoveOnuUpgradeFsm clears the Onu Software upgrade FSM |
| 3442 | func (dh *deviceHandler) RemoveOnuUpgradeFsm(ctx context.Context, apImageState *voltha.ImageState) { |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3443 | logger.Debugw(ctx, "remove OnuSwUpgradeFSM StateMachine", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3444 | "device-id": dh.DeviceID}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3445 | dh.lockUpgradeFsm.Lock() |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3446 | dh.pOnuUpradeFsm = nil //resource clearing is left to garbage collector |
| 3447 | dh.upgradeCanceled = false //cancelation done |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 3448 | dh.pLastUpgradeImageState = apImageState |
| 3449 | dh.lockUpgradeFsm.Unlock() |
| 3450 | //signal upgradeFsm removed using non-blocking channel send |
| 3451 | select { |
| 3452 | case dh.upgradeFsmChan <- struct{}{}: |
| 3453 | default: |
| 3454 | logger.Debugw(ctx, "removed-UpgradeFsm signal not send on upgradeFsmChan (no receiver)", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3455 | "device-id": dh.DeviceID}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 3456 | } |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3457 | } |
| 3458 | |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3459 | // checkOnOnuImageCommit verifies if the ONU is in some upgrade state that allows for image commit and if tries to commit |
| 3460 | func (dh *deviceHandler) checkOnOnuImageCommit(ctx context.Context) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3461 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3462 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3463 | logger.Errorw(ctx, "No valid OnuDevice -aborting checkOnOnuImageCommit", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3464 | return |
| 3465 | } |
| 3466 | |
| 3467 | dh.lockUpgradeFsm.RLock() |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3468 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3469 | if dh.pOnuUpradeFsm != nil { |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3470 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 3471 | dh.lockUpgradeFsm.RUnlock() |
| 3472 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 3473 | return |
| 3474 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3475 | pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3476 | if pUpgradeStatemachine != nil { |
| 3477 | // commit is only processed in case out upgrade FSM indicates the according state (for automatic commit) |
| 3478 | // (some manual forced commit could do without) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3479 | UpgradeState := pUpgradeStatemachine.Current() |
| 3480 | if (UpgradeState == swupg.UpgradeStWaitForCommit) || |
| 3481 | (UpgradeState == swupg.UpgradeStRequestingActivate) { |
| 3482 | // also include UpgradeStRequestingActivate as it may be left in case the ActivateResponse just got lost |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 3483 | // here no need to update the upgrade image state to activated as the state will be immediately be set to committing |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3484 | if pDevEntry.IsImageToBeCommitted(ctx, dh.pOnuUpradeFsm.InactiveImageMeID) { |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3485 | activeImageID, errImg := pDevEntry.GetActiveImageMeID(ctx) |
| 3486 | if errImg != nil { |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3487 | dh.lockUpgradeFsm.RUnlock() |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3488 | logger.Errorw(ctx, "OnuSwUpgradeFSM abort - could not get active image after reboot", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3489 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3490 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 3491 | dh.upgradeCanceled = true |
| 3492 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 3493 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3494 | return |
| 3495 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3496 | dh.lockUpgradeFsm.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3497 | if activeImageID == dh.pOnuUpradeFsm.InactiveImageMeID { |
| 3498 | if (UpgradeState == swupg.UpgradeStRequestingActivate) && !dh.pOnuUpradeFsm.GetCommitFlag(ctx) { |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3499 | // if FSM was waiting on activateResponse, new image is active, but FSM shall not commit, then: |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3500 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvActivationDone); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3501 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call activate-done event", |
| 3502 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3503 | return |
| 3504 | } |
| 3505 | logger.Debugw(ctx, "OnuSwUpgradeFSM activate-done after reboot", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3506 | "state": UpgradeState, "device-id": dh.DeviceID}) |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3507 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3508 | //FSM in waitForCommit or (UpgradeStRequestingActivate [lost ActivateResp] and commit allowed) |
| 3509 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvCommitSw); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3510 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call commit event", |
| 3511 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3512 | return |
| 3513 | } |
| 3514 | logger.Debugw(ctx, "OnuSwUpgradeFSM commit image requested", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3515 | "state": UpgradeState, "device-id": dh.DeviceID}) |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3516 | } |
| 3517 | } else { |
| 3518 | logger.Errorw(ctx, "OnuSwUpgradeFSM waiting to commit/on ActivateResponse, but load did not start with expected image Id", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3519 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 3520 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 3521 | dh.upgradeCanceled = true |
| 3522 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 3523 | } |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3524 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3525 | return |
| 3526 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3527 | dh.lockUpgradeFsm.RUnlock() |
| 3528 | logger.Errorw(ctx, "OnuSwUpgradeFSM waiting to commit, but nothing to commit on ONU - abort upgrade", |
| 3529 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 3530 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 3531 | dh.upgradeCanceled = true |
| 3532 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 3533 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3534 | return |
| 3535 | } |
| 3536 | //upgrade FSM is active but not waiting for commit: maybe because commit flag is not set |
| 3537 | // upgrade FSM is to be informed if the current active image is the one that was used in upgrade for the download |
| 3538 | if activeImageID, err := pDevEntry.GetActiveImageMeID(ctx); err == nil { |
| 3539 | if dh.pOnuUpradeFsm.InactiveImageMeID == activeImageID { |
| 3540 | logger.Debugw(ctx, "OnuSwUpgradeFSM image state set to activated", log.Fields{ |
| 3541 | "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
| 3542 | dh.pOnuUpradeFsm.SetImageStateActive(ctx) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 3543 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3544 | } |
| 3545 | } |
| 3546 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3547 | logger.Debugw(ctx, "no ONU image to be committed", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3548 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3549 | dh.lockUpgradeFsm.RUnlock() |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3550 | } |
| 3551 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3552 | // SetBackend provides a DB backend for the specified path on the existing KV client |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3553 | func (dh *deviceHandler) SetBackend(ctx context.Context, aBasePathKvStore string) *db.Backend { |
| Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 3554 | |
| 3555 | logger.Debugw(ctx, "SetKVStoreBackend", log.Fields{"IpTarget": dh.pOpenOnuAc.KVStoreAddress, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3556 | "BasePathKvStore": aBasePathKvStore, "device-id": dh.DeviceID}) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 3557 | // kvbackend := db.NewBackend(ctx, dh.pOpenOnuAc.KVStoreType, dh.pOpenOnuAc.KVStoreAddress, dh.pOpenOnuAc.KVStoreTimeout, aBasePathKvStore) |
| mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 3558 | kvbackend := &db.Backend{ |
| 3559 | Client: dh.pOpenOnuAc.kvClient, |
| 3560 | StoreType: dh.pOpenOnuAc.KVStoreType, |
| 3561 | /* address config update acc. to [VOL-2736] */ |
| Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 3562 | Address: dh.pOpenOnuAc.KVStoreAddress, |
| mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 3563 | Timeout: dh.pOpenOnuAc.KVStoreTimeout, |
| 3564 | PathPrefix: aBasePathKvStore} |
| Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 3565 | |
| mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 3566 | return kvbackend |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3567 | } |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3568 | |
| 3569 | //nolint:unparam |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3570 | func (dh *deviceHandler) getFlowOfbFields(ctx context.Context, apFlowItem *of.OfpFlowStats, loMatchVlan *uint16, |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3571 | loMatchPcp *uint8, loIPProto *uint32) { |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3572 | |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3573 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 3574 | switch field.Type { |
| 3575 | case of.OxmOfbFieldTypes_OFPXMT_OFB_ETH_TYPE: |
| 3576 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3577 | logger.Debugw(ctx, "flow type EthType", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3578 | "EthType": strconv.FormatInt(int64(field.GetEthType()), 16)}) |
| 3579 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3580 | /* TT related temporary workaround - should not be needed anymore |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3581 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO: |
| 3582 | { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3583 | *loIPProto = field.GetIpProto() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3584 | logger.Debugw("flow type IpProto", log.Fields{"device-id": dh.DeviceID, |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3585 | "IpProto": strconv.FormatInt(int64(*loIPProto), 16)}) |
| 3586 | if *loIPProto == 2 { |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3587 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 3588 | // avoids installing invalid EVTOCD rule |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3589 | logger.Debugw("flow type IpProto 2: TT workaround: ignore flow", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3590 | log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3591 | return |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3592 | } |
| 3593 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3594 | */ |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3595 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID: |
| 3596 | { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3597 | *loMatchVlan = uint16(field.GetVlanVid()) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3598 | loMatchVlanMask := uint16(field.GetVlanVidMask()) |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 3599 | if *loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) || |
| 3600 | loMatchVlanMask != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3601 | *loMatchVlan = *loMatchVlan & 0xFFF // not transparent: copy only ID bits |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3602 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3603 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3604 | "VID": strconv.FormatInt(int64(*loMatchVlan), 16)}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3605 | } |
| 3606 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP: |
| 3607 | { |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3608 | *loMatchPcp = uint8(field.GetVlanPcp()) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3609 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3610 | "PCP": loMatchPcp}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3611 | } |
| 3612 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_DST: |
| 3613 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3614 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3615 | "UDP-DST": strconv.FormatInt(int64(field.GetUdpDst()), 16)}) |
| 3616 | } |
| 3617 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_SRC: |
| 3618 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3619 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3620 | "UDP-SRC": strconv.FormatInt(int64(field.GetUdpSrc()), 16)}) |
| 3621 | } |
| 3622 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_DST: |
| 3623 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3624 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3625 | "IPv4-DST": field.GetIpv4Dst()}) |
| 3626 | } |
| 3627 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_SRC: |
| 3628 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3629 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3630 | "IPv4-SRC": field.GetIpv4Src()}) |
| 3631 | } |
| 3632 | case of.OxmOfbFieldTypes_OFPXMT_OFB_METADATA: |
| 3633 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3634 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3635 | "Metadata": field.GetTableMetadata()}) |
| 3636 | } |
| 3637 | /* |
| 3638 | default: |
| 3639 | { |
| 3640 | //all other entires ignored |
| 3641 | } |
| 3642 | */ |
| 3643 | } |
| 3644 | } //for all OfbFields |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3645 | } |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3646 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3647 | func (dh *deviceHandler) getFlowActions(ctx context.Context, apFlowItem *of.OfpFlowStats, loSetPcp *uint8, loSetVlan *uint16) { |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3648 | for _, action := range flow.GetActions(apFlowItem) { |
| 3649 | switch action.Type { |
| 3650 | /* not used: |
| 3651 | case of.OfpActionType_OFPAT_OUTPUT: |
| 3652 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3653 | logger.Debugw("flow action type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3654 | "Output": action.GetOutput()}) |
| 3655 | } |
| 3656 | */ |
| 3657 | case of.OfpActionType_OFPAT_PUSH_VLAN: |
| 3658 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3659 | logger.Debugw(ctx, "flow action type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3660 | "PushEthType": strconv.FormatInt(int64(action.GetPush().Ethertype), 16)}) |
| 3661 | } |
| 3662 | case of.OfpActionType_OFPAT_SET_FIELD: |
| 3663 | { |
| 3664 | pActionSetField := action.GetSetField() |
| 3665 | if pActionSetField.Field.OxmClass != of.OfpOxmClass_OFPXMC_OPENFLOW_BASIC { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3666 | logger.Warnw(ctx, "flow action SetField invalid OxmClass (ignored)", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3667 | "OxcmClass": pActionSetField.Field.OxmClass}) |
| 3668 | } |
| 3669 | if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3670 | *loSetVlan = uint16(pActionSetField.Field.GetOfbField().GetVlanVid()) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3671 | logger.Debugw(ctx, "flow Set VLAN from SetField action", log.Fields{"device-id": dh.DeviceID, |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3672 | "SetVlan": strconv.FormatInt(int64(*loSetVlan), 16)}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3673 | } else if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3674 | *loSetPcp = uint8(pActionSetField.Field.GetOfbField().GetVlanPcp()) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3675 | logger.Debugw(ctx, "flow Set PCP from SetField action", log.Fields{"device-id": dh.DeviceID, |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3676 | "SetPcp": *loSetPcp}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3677 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3678 | logger.Warnw(ctx, "flow action SetField invalid FieldType", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3679 | "Type": pActionSetField.Field.GetOfbField().Type}) |
| 3680 | } |
| 3681 | } |
| 3682 | /* |
| 3683 | default: |
| 3684 | { |
| 3685 | //all other entires ignored |
| 3686 | } |
| 3687 | */ |
| 3688 | } |
| 3689 | } //for all Actions |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3690 | } |
| 3691 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3692 | // addFlowItemToUniPort parses the actual flow item to add it to the UniPort |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3693 | func (dh *deviceHandler) addFlowItemToUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort, |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3694 | apFlowMetaData *of.FlowMetadata, respChan *chan error) { |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 3695 | var loSetVlan = uint16(of.OfpVlanId_OFPVID_NONE) //noValidEntry |
| 3696 | var loMatchVlan = uint16(of.OfpVlanId_OFPVID_PRESENT) //reserved VLANID entry |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3697 | var loSetPcp uint8 |
| 3698 | var loMatchPcp uint8 = 8 // could the const 'cPrioDoNotFilter' be used from omci_vlan_config.go ? |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3699 | var loIPProto uint32 |
| 3700 | /* the TechProfileId is part of the flow Metadata - compare also comment within |
| 3701 | * OLT-Adapter:openolt_flowmgr.go |
| 3702 | * Metadata 8 bytes: |
| 3703 | * Most Significant 2 Bytes = Inner VLAN |
| 3704 | * Next 2 Bytes = Tech Profile ID(TPID) |
| 3705 | * Least Significant 4 Bytes = Port ID |
| 3706 | * Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all |
| 3707 | * subscriber related flows. |
| 3708 | */ |
| 3709 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3710 | metadata := flow.GetMetadataFromWriteMetadataAction(ctx, apFlowItem) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3711 | if metadata == 0 { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3712 | logger.Debugw(ctx, "flow-add invalid metadata - abort", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3713 | log.Fields{"device-id": dh.DeviceID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3714 | *respChan <- fmt.Errorf("flow-add invalid metadata: %s", dh.DeviceID) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3715 | } |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3716 | loTpID := uint8(flow.GetTechProfileIDFromWriteMetaData(ctx, metadata)) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3717 | loCookie := apFlowItem.GetCookie() |
| 3718 | loCookieSlice := []uint64{loCookie} |
| Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 3719 | loInnerCvlan := flow.GetInnerTagFromWriteMetaData(ctx, metadata) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3720 | logger.Debugw(ctx, "flow-add base indications", log.Fields{"device-id": dh.DeviceID, |
| Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 3721 | "TechProf-Id": loTpID, "cookie": loCookie, "innerCvlan": loInnerCvlan}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3722 | |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3723 | dh.getFlowOfbFields(ctx, apFlowItem, &loMatchVlan, &loMatchPcp, &loIPProto) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3724 | /* TT related temporary workaround - should not be needed anymore |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3725 | if loIPProto == 2 { |
| 3726 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 3727 | // avoids installing invalid EVTOCD rule |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3728 | logger.Debugw("flow-add type IpProto 2: TT workaround: ignore flow", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3729 | log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3730 | return nil |
| 3731 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3732 | */ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3733 | dh.getFlowActions(ctx, apFlowItem, &loSetPcp, &loSetVlan) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3734 | |
| Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 3735 | if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) && (loMatchPcp == 8) && |
| 3736 | loInnerCvlan == uint16(of.OfpVlanId_OFPVID_NONE) { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3737 | logger.Errorw(ctx, "flow-add aborted - SetVlanId undefined, but MatchVid set", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3738 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3739 | "set_vid": strconv.FormatInt(int64(loSetVlan), 16), |
| 3740 | "match_vid": strconv.FormatInt(int64(loMatchVlan), 16)}) |
| 3741 | //TODO!!: Use DeviceId within the error response to rwCore |
| 3742 | // likewise also in other error response cases to calling components as requested in [VOL-3458] |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3743 | *respChan <- fmt.Errorf("flow-add Set/Match VlanId inconsistent: %s", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3744 | } |
| 3745 | if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan == uint16(of.OfpVlanId_OFPVID_PRESENT) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3746 | logger.Debugw(ctx, "flow-add vlan-any/copy", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3747 | loSetVlan = loMatchVlan //both 'transparent' (copy any) |
| Abhilash Laxmeshwar | f15a0d0 | 2022-08-08 11:09:32 +0530 | [diff] [blame] | 3748 | } else if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) && |
| 3749 | loInnerCvlan != uint16(of.OfpVlanId_OFPVID_NONE) { |
| 3750 | loSetVlan = loMatchVlan |
| 3751 | logger.Debugw(ctx, "flow-add, double tagged case, set setvlan to matchvlan ", log.Fields{"device-id": dh.DeviceID, "loSetVlan": loSetVlan, "loMatchVlan": loMatchVlan}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3752 | } else { |
| 3753 | //looks like OMCI value 4097 (copyFromOuter - for Uni double tagged) is not supported here |
| 3754 | if loSetVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
| 3755 | // not set to transparent |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3756 | loSetVlan &= 0x0FFF //mask VID bits as prerequisite for vlanConfigFsm |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3757 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3758 | logger.Debugw(ctx, "flow-add vlan-set", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3759 | } |
| mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3760 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3761 | var meter *of.OfpMeterConfig |
| ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3762 | if apFlowMetaData != nil { |
| 3763 | meter = apFlowMetaData.Meters[0] |
| 3764 | } |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3765 | //mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities |
| 3766 | // must be set including the execution of createVlanFilterFsm() to avoid unintended creation of FSM's |
| 3767 | // when different rules are requested concurrently for the same uni |
| 3768 | // (also vlan persistency data does not support multiple FSM's on the same UNI correctly!) |
| 3769 | dh.lockVlanAdd.Lock() //prevent multiple add activities to start in parallel |
| 3770 | dh.lockVlanConfig.RLock() //read protection on UniVlanConfigFsmMap (removeFlowItemFromUniPort) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3771 | logger.Debugw(ctx, "flow-add got lock", log.Fields{"device-id": dh.DeviceID, "tpID": loTpID, "uniID": apUniPort.UniID}) |
| 3772 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3773 | //SetUniFlowParams() may block on some rule that is suspended-to-add |
| 3774 | // in order to allow for according flow removal lockVlanConfig may only be used with RLock here |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3775 | // Also the error is returned to caller via response channel |
| 3776 | _ = dh.UniVlanConfigFsmMap[apUniPort.UniID].SetUniFlowParams(ctx, loTpID, loCookieSlice, |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 3777 | loMatchVlan, loMatchPcp, loSetVlan, loSetPcp, loInnerCvlan, false, false, meter, respChan) |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3778 | dh.lockVlanConfig.RUnlock() |
| 3779 | dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3780 | return |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3781 | } |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3782 | dh.lockVlanConfig.RUnlock() |
| 3783 | dh.lockVlanConfig.Lock() //createVlanFilterFsm should always be a non-blocking operation and requires r+w lock |
| mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3784 | err := dh.createVlanFilterFsm(ctx, apUniPort, loTpID, loCookieSlice, |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 3785 | loMatchVlan, loMatchPcp, loSetVlan, loSetPcp, loInnerCvlan, cmn.OmciVlanFilterAddDone, false, false, meter, respChan) |
| mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3786 | dh.lockVlanConfig.Unlock() |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3787 | dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3788 | if err != nil { |
| 3789 | *respChan <- err |
| 3790 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3791 | } |
| 3792 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3793 | // removeFlowItemFromUniPort parses the actual flow item to remove it from the UniPort |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3794 | func (dh *deviceHandler) removeFlowItemFromUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort, respChan *chan error) { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3795 | //optimization and assumption: the flow cookie uniquely identifies the flow and with that the internal rule |
| 3796 | //hence only the cookie is used here to find the relevant flow and possibly remove the rule |
| 3797 | //no extra check is done on the rule parameters |
| 3798 | //accordingly the removal is done only once - for the first found flow with that cookie, even though |
| 3799 | // at flow creation is not assured, that the same cookie is not configured for different flows - just assumed |
| 3800 | //additionally it is assumed here, that removal can only be done for one cookie per flow in a sequence (different |
| 3801 | // from addFlow - where at reconcilement multiple cookies per flow ) can be configured in one sequence) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3802 | // - some possible 'delete-all' sequence would have to be implemented separately (where the cookies are don't care anyway) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3803 | loCookie := apFlowItem.GetCookie() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3804 | logger.Debugw(ctx, "flow-remove base indications", log.Fields{"device-id": dh.DeviceID, "cookie": loCookie}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3805 | |
| 3806 | /* TT related temporary workaround - should not be needed anymore |
| 3807 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 3808 | if field.Type == of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO { |
| 3809 | loIPProto := field.GetIpProto() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3810 | logger.Debugw(ctx, "flow type IpProto", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3811 | "IpProto": strconv.FormatInt(int64(loIPProto), 16)}) |
| 3812 | if loIPProto == 2 { |
| 3813 | // some workaround for TT workflow on proto == 2 (IGMP trap) -> the flow was not added, no need to remove |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3814 | logger.Debugw(ctx, "flow-remove type IpProto 2: TT workaround: ignore flow", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3815 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3816 | return nil |
| 3817 | } |
| 3818 | } |
| 3819 | } //for all OfbFields |
| 3820 | */ |
| 3821 | |
| mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3822 | //mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3823 | dh.lockVlanConfig.RLock() |
| 3824 | defer dh.lockVlanConfig.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3825 | logger.Debugw(ctx, "flow-remove got RLock", log.Fields{"device-id": dh.DeviceID, "uniID": apUniPort.UniID}) |
| 3826 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3827 | _ = dh.UniVlanConfigFsmMap[apUniPort.UniID].RemoveUniFlowParams(ctx, loCookie, respChan) |
| 3828 | return |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3829 | } |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3830 | logger.Debugw(ctx, "flow-remove called, but no flow is configured (no VlanConfigFsm, flow already removed) ", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3831 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3832 | //but as we regard the flow as not existing = removed we respond just ok |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3833 | // and treat the reason accordingly (which in the normal removal procedure is initiated by the FSM) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3834 | // Push response on the response channel |
| 3835 | if respChan != nil { |
| 3836 | // Do it in a non blocking fashion, so that in case the flow handler routine has shutdown for any reason, we do not block here |
| 3837 | select { |
| 3838 | case *respChan <- nil: |
| 3839 | logger.Debugw(ctx, "submitted-response-for-flow", log.Fields{"device-id": dh.DeviceID, "err": nil}) |
| 3840 | default: |
| 3841 | } |
| 3842 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3843 | go dh.DeviceProcStatusUpdate(ctx, cmn.OmciVlanFilterRemDone) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3844 | } |
| 3845 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3846 | // createVlanFilterFsm initializes and runs the VlanFilter FSM to transfer OMCI related VLAN config |
| mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3847 | // if this function is called from possibly concurrent processes it must be mutex-protected from the caller! |
| mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3848 | // precondition: dh.lockVlanConfig is locked by the caller! |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3849 | func (dh *deviceHandler) createVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8, aCookieSlice []uint64, |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 3850 | aMatchVlan uint16, aMatchPcp uint8, aSetVlan uint16, aSetPcp uint8, innerCvlan uint16, aDevEvent cmn.OnuDeviceEvent, lastFlowToReconcile bool, lastFlowToConfOnReboot bool, aMeter *of.OfpMeterConfig, respChan *chan error) error { |
| Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 3851 | chVlanFilterFsm := make(chan cmn.Message, 2) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3852 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3853 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3854 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3855 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 3856 | return fmt.Errorf("no valid OnuDevice for device-id %x - aborting", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
| Sridhar Ravindra | 2f86efb | 2024-12-06 11:02:10 +0530 | [diff] [blame] | 3859 | if dh.pDeviceStateFsm.Current() == devStDown { |
| 3860 | logger.Warnw(ctx, "UniVlanConfigFsm : aborting, device state down", log.Fields{"device-id": dh.DeviceID}) |
| 3861 | return fmt.Errorf("device state down for device-id %x - aborting", dh.DeviceID) |
| 3862 | } |
| 3863 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3864 | pVlanFilterFsm := avcfg.NewUniVlanConfigFsm(ctx, dh, pDevEntry, pDevEntry.PDevOmciCC, apUniPort, dh.pOnuTP, |
| 3865 | pDevEntry.GetOnuDB(), aTpID, aDevEvent, "UniVlanConfigFsm", chVlanFilterFsm, |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 3866 | dh.pOpenOnuAc.AcceptIncrementalEvto, aCookieSlice, aMatchVlan, aMatchPcp, aSetVlan, aSetPcp, innerCvlan, lastFlowToReconcile, lastFlowToConfOnReboot, aMeter, respChan) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3867 | if pVlanFilterFsm != nil { |
| mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3868 | //dh.lockVlanConfig is locked (by caller) throughout the state transition to 'starting' |
| 3869 | // to prevent unintended (ignored) events to be sent there (from parallel processing) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3870 | dh.UniVlanConfigFsmMap[apUniPort.UniID] = pVlanFilterFsm |
| 3871 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3872 | if pVlanFilterStatemachine != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3873 | if pVlanFilterStatemachine.Is(avcfg.VlanStDisabled) { |
| 3874 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvStart); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3875 | logger.Warnw(ctx, "UniVlanConfigFsm: can't start", |
| 3876 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3877 | return fmt.Errorf("can't start UniVlanConfigFsm for device-id %x", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3878 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3879 | /***** UniVlanConfigFsm started */ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3880 | logger.Debugw(ctx, "UniVlanConfigFsm started", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3881 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3882 | "UniPort": apUniPort.PortNo}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3883 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3884 | logger.Warnw(ctx, "wrong state of UniVlanConfigFsm - want: disabled", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3885 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID}) |
| 3886 | return fmt.Errorf("uniVlanConfigFsm not in expected disabled state for device-id %x", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3887 | } |
| 3888 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3889 | logger.Errorw(ctx, "UniVlanConfigFsm StateMachine invalid - cannot be executed!!", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3890 | "device-id": dh.DeviceID}) |
| 3891 | return fmt.Errorf("uniVlanConfigFsm invalid for device-id %x", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3892 | } |
| 3893 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3894 | logger.Errorw(ctx, "UniVlanConfigFsm could not be created - abort!!", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3895 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| 3896 | return fmt.Errorf("uniVlanConfigFsm could not be created for device-id %x", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3897 | } |
| 3898 | return nil |
| 3899 | } |
| 3900 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3901 | // VerifyVlanConfigRequest checks on existence of a given uniPort |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3902 | // and starts verification of flow config based on that |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3903 | func (dh *deviceHandler) VerifyVlanConfigRequest(ctx context.Context, aUniID uint8, aTpID uint8) { |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3904 | //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3905 | var pCurrentUniPort *cmn.OnuUniPort |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3906 | for _, uniPort := range dh.uniEntityMap { |
| 3907 | // only if this port is validated for operState transfer |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3908 | if uniPort.UniID == uint8(aUniID) { |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3909 | pCurrentUniPort = uniPort |
| 3910 | break //found - end search loop |
| 3911 | } |
| 3912 | } |
| 3913 | if pCurrentUniPort == nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3914 | logger.Debugw(ctx, "VerifyVlanConfig aborted: requested uniID not found in PortDB", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3915 | log.Fields{"device-id": dh.DeviceID, "uni-id": aUniID}) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3916 | return |
| 3917 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3918 | dh.VerifyUniVlanConfigRequest(ctx, pCurrentUniPort, aTpID) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3919 | } |
| 3920 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3921 | // VerifyUniVlanConfigRequest checks on existence of flow configuration and starts it accordingly |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3922 | func (dh *deviceHandler) VerifyUniVlanConfigRequest(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8) { |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3923 | //TODO!! verify and start pending flow configuration |
| 3924 | //some pending config request my exist in case the UniVlanConfig FSM was already started - with internal data - |
| 3925 | //but execution was set to 'on hold' as first the TechProfile config had to be applied |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3926 | logger.Info(ctx, "Verifying UniVlanConfig Request", log.Fields{"device-id": dh.DeviceID, "UniPort": apUniPort.PortNo, "techprofile-id": aTpID}) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3927 | dh.lockVlanConfig.RLock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3928 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3929 | dh.lockVlanConfig.RUnlock() |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3930 | //VlanFilterFsm exists and was already started (assumed to wait for TechProfile execution here) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3931 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3932 | if pVlanFilterStatemachine != nil { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3933 | //if this was an event of the TP processing that was waited for in the VlanFilterFsm |
| Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 3934 | if pVlanFilterFsm.GetWaitingTpID(ctx) == aTpID { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3935 | if pVlanFilterStatemachine.Is(avcfg.VlanStWaitingTechProf) { |
| 3936 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvContinueConfig); err != nil { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3937 | logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3938 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3939 | } else { |
| 3940 | /***** UniVlanConfigFsm continued */ |
| 3941 | logger.Debugw(ctx, "UniVlanConfigFsm continued", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3942 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3943 | "UniPort": apUniPort.PortNo}) |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3944 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3945 | } else if pVlanFilterStatemachine.Is(avcfg.VlanStIncrFlowWaitTP) { |
| 3946 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvIncrFlowConfig); err != nil { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3947 | logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3948 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3949 | } else { |
| 3950 | /***** UniVlanConfigFsm continued */ |
| 3951 | logger.Debugw(ctx, "UniVlanConfigFsm continued with incremental flow", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3952 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3953 | "UniPort": apUniPort.PortNo}) |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3954 | } |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3955 | } else { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3956 | logger.Debugw(ctx, "no state of UniVlanConfigFsm to be continued", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3957 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3958 | "UniPort": apUniPort.PortNo}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3959 | } |
| 3960 | } else { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3961 | logger.Debugw(ctx, "TechProfile Ready event for TpId that was not waited for in the VlanConfigFsm - continue waiting", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3962 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3963 | "UniPort": apUniPort.PortNo, "techprofile-id (done)": aTpID}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3964 | } |
| 3965 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3966 | logger.Debugw(ctx, "UniVlanConfigFsm StateMachine does not exist, no flow processing", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3967 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3968 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3969 | } else { |
| 3970 | dh.lockVlanConfig.RUnlock() |
| 3971 | } |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3972 | } |
| 3973 | |
| Akash Soni | 3de0e06 | 2024-12-11 16:37:26 +0530 | [diff] [blame] | 3974 | // handleAniConfigFSMFailure handles the failure of the ANI config FSM by resetting the VLAN filter FSM |
| 3975 | func (dh *deviceHandler) HandleAniConfigFSMFailure(ctx context.Context, uniID uint8) { |
| 3976 | dh.lockVlanConfig.Lock() |
| 3977 | defer dh.lockVlanConfig.Unlock() |
| 3978 | |
| 3979 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniID]; exist { |
| 3980 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
| 3981 | if pVlanFilterStatemachine != nil { |
| 3982 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvReset); err != nil { |
| 3983 | logger.Warnw(ctx, "Failed to reset UniVlanConfigFsm", log.Fields{ |
| 3984 | "err": err, "device-id": dh.DeviceID, "UniPort": uniID, "FsmState": pVlanFilterStatemachine.Current(), |
| 3985 | }) |
| 3986 | } else { |
| 3987 | logger.Infow(ctx, "Successfully reset UniVlanConfigFsm", log.Fields{ |
| 3988 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, "UniPort": uniID, |
| 3989 | }) |
| 3990 | } |
| 3991 | } else { |
| 3992 | logger.Debugw(ctx, "UniVlanConfigFsm StateMachine does not exist, no reset performed", log.Fields{ |
| 3993 | "device-id": dh.DeviceID, "UniPort": uniID, |
| 3994 | }) |
| 3995 | } |
| 3996 | } else { |
| 3997 | logger.Debugw(ctx, "No UniVlanConfigFsm found for the UNI ID", log.Fields{ |
| 3998 | "device-id": dh.DeviceID, "UniPort": uniID, |
| 3999 | }) |
| 4000 | } |
| 4001 | } |
| 4002 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 4003 | // RemoveVlanFilterFsm deletes the stored pointer to the VlanConfigFsm |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 4004 | // intention is to provide this method to be called from VlanConfigFsm itself, when resources (and methods!) are cleaned up |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4005 | func (dh *deviceHandler) RemoveVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort) { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 4006 | logger.Debugw(ctx, "remove UniVlanConfigFsm StateMachine", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4007 | "device-id": dh.DeviceID, "uniPort": apUniPort.PortNo}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 4008 | //save to do, even if entry dows not exist |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4009 | dh.lockVlanConfig.Lock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4010 | delete(dh.UniVlanConfigFsmMap, apUniPort.UniID) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4011 | dh.lockVlanConfig.Unlock() |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 4012 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4013 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 4014 | // startWritingOnuDataToKvStore initiates the KVStore write of ONU persistent data |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4015 | func (dh *deviceHandler) startWritingOnuDataToKvStore(ctx context.Context, aPDevEntry *mib.OnuDeviceEntry) error { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4016 | dh.mutexKvStoreContext.Lock() //this write routine may (could) be called with the same context, |
| 4017 | defer dh.mutexKvStoreContext.Unlock() //this write routine may (could) be called with the same context, |
| 4018 | // obviously then parallel processing on the cancel must be avoided |
| 4019 | // deadline context to ensure completion of background routines waited for |
| 4020 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 4021 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 4022 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 4023 | defer cancel() // Ensure cancel is called to release resources |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4024 | |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 4025 | err := aPDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx)) |
| 4026 | if err != nil { |
| 4027 | logger.Errorw(ctx, "UpdateOnuKvStore-failed", log.Fields{"device-id": dh.DeviceID}) |
| 4028 | return err |
| 4029 | } |
| 4030 | return nil |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4031 | } |
| 4032 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 4033 | // StorePersUniFlowConfig updates local storage of OnuUniFlowConfig and writes it into kv-store afterwards to have it |
| 4034 | // available for potential reconcilement |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4035 | func (dh *deviceHandler) StorePersUniFlowConfig(ctx context.Context, aUniID uint8, |
| 4036 | aUniVlanFlowParams *[]cmn.UniVlanFlowParams, aWriteToKvStore bool) error { |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4037 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4038 | if dh.IsReconciling() { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4039 | logger.Info(ctx, "reconciling - don't store persistent UniFlowConfig", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4040 | return nil |
| 4041 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4042 | logger.Debugw(ctx, "Store or clear persistent UniFlowConfig", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4043 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4044 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4045 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4046 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 4047 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4048 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4049 | pDevEntry.UpdateOnuUniFlowConfig(aUniID, aUniVlanFlowParams) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4050 | |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4051 | if aWriteToKvStore { |
| 4052 | return dh.startWritingOnuDataToKvStore(ctx, pDevEntry) |
| 4053 | } |
| 4054 | return nil |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4055 | } |
| 4056 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 4057 | func (dh *deviceHandler) waitForCompletion(ctx context.Context, cancel context.CancelFunc, wg *sync.WaitGroup, aCallerIdent string) { |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4058 | defer cancel() //ensure termination of context (may be pro forma) |
| 4059 | wg.Wait() |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 4060 | logger.Debugw(ctx, "WaitGroup processing completed", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4061 | "device-id": dh.DeviceID, "called from": aCallerIdent}) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4062 | } |
| 4063 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 4064 | // ReasonUpdate set the internally store device reason and if requested in notifyCore updates this state in the core |
| 4065 | // |
| 4066 | // (renamed from previous deviceReasonUpdate to avoid confusing with the core function DeviceReasonUpdate) |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4067 | func (dh *deviceHandler) ReasonUpdate(ctx context.Context, deviceReason uint8, notifyCore bool) error { |
| 4068 | // acquire the deviceReason semaphore throughout this function including the possible update processing in core |
| 4069 | // in order to avoid reversion of the state sequence within core in case of quasi-parallel calls (eg. in multi UNI processing) |
| 4070 | dh.mutexDeviceReason.Lock() |
| 4071 | defer dh.mutexDeviceReason.Unlock() |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 4072 | if notifyCore { |
| Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 4073 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing at calling position |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4074 | if err := dh.updateDeviceReasonInCore(ctx, &ca.DeviceReason{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4075 | DeviceId: dh.DeviceID, |
| 4076 | Reason: cmn.DeviceReasonMap[deviceReason], |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4077 | }); err != nil { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4078 | logger.Errorf(ctx, "updating reason in core failed for: %s", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4079 | log.Fields{"device-id": dh.DeviceID, "error": err}, cmn.DeviceReasonMap[deviceReason]) |
| Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 4080 | return err |
| 4081 | } |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4082 | } else { |
| 4083 | logger.Debugf(ctx, "update reason in core not requested: %s - device-id: %s", cmn.DeviceReasonMap[deviceReason], dh.DeviceID) |
| Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 4084 | } |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4085 | dh.deviceReason = deviceReason |
| 4086 | logger.Infof(ctx, "reason update done for: %s - device-id: %s - with core update: %v", |
| 4087 | cmn.DeviceReasonMap[deviceReason], dh.DeviceID, notifyCore) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 4088 | return nil |
| 4089 | } |
| 4090 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4091 | func (dh *deviceHandler) StorePersistentData(ctx context.Context) error { |
| 4092 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 4093 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4094 | logger.Warnw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 4095 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 4096 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4097 | return dh.startWritingOnuDataToKvStore(ctx, pDevEntry) |
| Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 4098 | } |
| 4099 | |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 4100 | func (dh *deviceHandler) UpdateRebootPersData(ctx context.Context, flag bool) { |
| 4101 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 4102 | if pDevEntry != nil { |
| 4103 | pDevEntry.MutexPersOnuConfig.Lock() |
| 4104 | pDevEntry.SOnuPersistentData.PersRebootInProgress = flag |
| 4105 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 4106 | } else { |
| 4107 | logger.Errorw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | func (dh *deviceHandler) GetPersRebootFlag(ctx context.Context) bool { |
| 4112 | rebootFlag := false |
| 4113 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 4114 | if pDevEntry != nil { |
| 4115 | pDevEntry.MutexPersOnuConfig.RLock() |
| 4116 | rebootFlag = pDevEntry.SOnuPersistentData.PersRebootInProgress |
| 4117 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 4118 | } else { |
| 4119 | logger.Errorw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 4120 | } |
| 4121 | return rebootFlag |
| 4122 | } |
| 4123 | |
| ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 4124 | // getUniPortMEEntityID takes uniPortNo as the input and returns the Entity ID corresponding to this UNI-G ME Instance |
| ozgecanetsia | 72e1c9f | 2021-05-26 17:26:29 +0300 | [diff] [blame] | 4125 | // nolint: unused |
| ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 4126 | func (dh *deviceHandler) getUniPortMEEntityID(uniPortNo uint32) (uint16, error) { |
| 4127 | dh.lockDevice.RLock() |
| 4128 | defer dh.lockDevice.RUnlock() |
| 4129 | if uniPort, ok := dh.uniEntityMap[uniPortNo]; ok { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4130 | return uniPort.EntityID, nil |
| ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 4131 | } |
| 4132 | return 0, errors.New("error-fetching-uni-port") |
| 4133 | } |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4134 | |
| 4135 | // updatePmConfig updates the pm metrics config. |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4136 | func (dh *deviceHandler) updatePmConfig(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 4137 | var errorsList []error |
| 4138 | logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": dh.device.Id, "new-pm-configs": pmConfigs, "old-pm-config": dh.pmConfigs}) |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4139 | |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4140 | errorsList = append(dh.handleGlobalPmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 4141 | errorsList = append(dh.handleGroupPmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 4142 | errorsList = append(dh.handleStandalonePmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 4143 | |
| 4144 | // Note that if more than one pm config field is updated in a given call, it is possible that partial pm config is handled |
| 4145 | // successfully. |
| 4146 | // TODO: Although it is possible to revert to old config in case of partial failure, the code becomes quite complex. Needs more investigation |
| 4147 | // Is it possible the rw-core reverts to old config on partial failure but adapter retains a partial new config? |
| 4148 | if len(errorsList) > 0 { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4149 | logger.Errorw(ctx, "one-or-more-pm-config-failed", log.Fields{"device-id": dh.DeviceID, "pmConfig": dh.pmConfigs}) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4150 | return fmt.Errorf("errors-handling-one-or-more-pm-config, errors:%v", errorsList) |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4151 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4152 | logger.Infow(ctx, "pm-config-updated", log.Fields{"device-id": dh.DeviceID, "pmConfig": dh.pmConfigs}) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4153 | return nil |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4154 | } |
| 4155 | |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4156 | func (dh *deviceHandler) handleGlobalPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 4157 | var err error |
| 4158 | var errorsList []error |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4159 | logger.Infow(ctx, "handling-global-pm-config-params - start", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4160 | |
| 4161 | if pmConfigs.DefaultFreq != dh.pmConfigs.DefaultFreq { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4162 | if err = dh.pOnuMetricsMgr.UpdateDefaultFrequency(ctx, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4163 | errorsList = append(errorsList, err) |
| 4164 | } |
| 4165 | } |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4166 | logger.Infow(ctx, "handling-global-pm-config-params - done", log.Fields{"device-id": dh.device.Id}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 4167 | |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4168 | return errorsList |
| 4169 | } |
| 4170 | |
| 4171 | func (dh *deviceHandler) handleGroupPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 4172 | var err error |
| 4173 | var errorsList []error |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4174 | logger.Debugw(ctx, "handling-group-pm-config-params - start", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4175 | // Check if group metric related config is updated |
| 4176 | for _, v := range pmConfigs.Groups { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4177 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() |
| 4178 | m, ok := dh.pOnuMetricsMgr.GroupMetricMap[v.GroupName] |
| 4179 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4180 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4181 | if ok && m.Frequency != v.GroupFreq { |
| 4182 | if err = dh.pOnuMetricsMgr.UpdateGroupFreq(ctx, v.GroupName, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4183 | errorsList = append(errorsList, err) |
| 4184 | } |
| 4185 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4186 | if ok && m.Enabled != v.Enabled { |
| 4187 | if err = dh.pOnuMetricsMgr.UpdateGroupSupport(ctx, v.GroupName, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4188 | errorsList = append(errorsList, err) |
| 4189 | } |
| 4190 | } |
| 4191 | } |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4192 | logger.Debugw(ctx, "handling-group-pm-config-params - done", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4193 | return errorsList |
| 4194 | } |
| 4195 | |
| 4196 | func (dh *deviceHandler) handleStandalonePmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 4197 | var err error |
| 4198 | var errorsList []error |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4199 | logger.Debugw(ctx, "handling-individual-pm-config-params - start", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4200 | // Check if standalone metric related config is updated |
| 4201 | for _, v := range pmConfigs.Metrics { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4202 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() |
| 4203 | m, ok := dh.pOnuMetricsMgr.StandaloneMetricMap[v.Name] |
| 4204 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4205 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4206 | if ok && m.Frequency != v.SampleFreq { |
| 4207 | if err = dh.pOnuMetricsMgr.UpdateMetricFreq(ctx, v.Name, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4208 | errorsList = append(errorsList, err) |
| 4209 | } |
| 4210 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4211 | if ok && m.Enabled != v.Enabled { |
| 4212 | if err = dh.pOnuMetricsMgr.UpdateMetricSupport(ctx, v.Name, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4213 | errorsList = append(errorsList, err) |
| 4214 | } |
| 4215 | } |
| 4216 | } |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4217 | logger.Debugw(ctx, "handling-individual-pm-config-params - done", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4218 | return errorsList |
| 4219 | } |
| 4220 | |
| 4221 | // nolint: gocyclo |
| Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 4222 | func (dh *deviceHandler) StartCollector(ctx context.Context, waitForOmciProcessor *sync.WaitGroup) { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4223 | logger.Debugw(ctx, "startingCollector", log.Fields{"device-id": dh.device.Id}) |
| bseeniva | 596a522 | 2026-01-23 19:26:11 +0530 | [diff] [blame] | 4224 | dh.RLockMutexDeletionInProgressFlag() |
| 4225 | if dh.GetDeletionInProgress() { |
| 4226 | logger.Warnw(ctx, "Device deletion in progress - avoid starting metrics collector routine", log.Fields{"device-id": dh.device.Id}) |
| 4227 | dh.RUnlockMutexDeletionInProgressFlag() |
| 4228 | return |
| 4229 | } |
| 4230 | // Set collectorIsRunning flag to true while still holding deviceDeletionFlag lock, |
| 4231 | // to avoid potential race condition where resetFsm from DeleteDevice might avoid stopping the collector routine if this flag is not yet set |
| 4232 | dh.setCollectorIsRunning(true) |
| 4233 | dh.RUnlockMutexDeletionInProgressFlag() |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4234 | |
| 4235 | // Start routine to process OMCI GET Responses |
| Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 4236 | go dh.pOnuMetricsMgr.ProcessOmciMessages(ctx, waitForOmciProcessor) |
| Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 4237 | // Create Extended Frame PM ME |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4238 | go dh.pOnuMetricsMgr.CreateEthernetFrameExtendedPMME(ctx) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4239 | // Initialize the next metric collection time. |
| 4240 | // Normally done when the onu_metrics_manager is initialized the first time, but needed again later when ONU is |
| 4241 | // reset like onu rebooted. |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4242 | dh.pOnuMetricsMgr.InitializeMetricCollectionTime(ctx) |
| praneeth nalmas | 808f43a | 2023-05-14 12:54:34 +0530 | [diff] [blame] | 4243 | statsCollectionticker := time.NewTicker((pmmgr.FrequencyGranularity) * time.Second) |
| 4244 | defer statsCollectionticker.Stop() |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4245 | for { |
| praneeth nalmas | 808f43a | 2023-05-14 12:54:34 +0530 | [diff] [blame] | 4246 | |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4247 | select { |
| 4248 | case <-dh.stopCollector: |
| 4249 | logger.Debugw(ctx, "stopping-collector-for-onu", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 4250 | // Stop the L2 PM FSM |
| 4251 | go func() { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4252 | if dh.pOnuMetricsMgr.PAdaptFsm != nil && dh.pOnuMetricsMgr.PAdaptFsm.PFsm != nil { |
| 4253 | if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventStop); err != nil { |
| 4254 | logger.Errorw(ctx, "error calling event", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 4255 | } |
| 4256 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4257 | logger.Errorw(ctx, "metrics manager fsm not initialized", log.Fields{"device-id": dh.DeviceID}) |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 4258 | } |
| 4259 | }() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4260 | if dh.pOnuMetricsMgr.GetOmciProcessingStatus() { |
| 4261 | dh.pOnuMetricsMgr.StopProcessingOmciResponses <- true // Stop the OMCI GET response processing routine |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 4262 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4263 | if dh.pOnuMetricsMgr.GetTickGenerationStatus() { |
| 4264 | dh.pOnuMetricsMgr.StopTicks <- true |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 4265 | } |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 4266 | |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4267 | return |
| praneeth nalmas | 808f43a | 2023-05-14 12:54:34 +0530 | [diff] [blame] | 4268 | case <-statsCollectionticker.C: // Check every FrequencyGranularity to see if it is time for collecting metrics |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4269 | if !dh.pmConfigs.FreqOverride { // If FreqOverride is false, then NextGlobalMetricCollectionTime applies |
| 4270 | // If the current time is eqaul to or greater than the NextGlobalMetricCollectionTime, collect the group and standalone metrics |
| 4271 | if time.Now().Equal(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) || time.Now().After(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) { |
| 4272 | go dh.pOnuMetricsMgr.CollectAllGroupAndStandaloneMetrics(ctx) |
| Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 4273 | // Update the next metric collection time. |
| Mahir Gunyel | e184e9f | 2024-09-18 00:12:19 -0700 | [diff] [blame] | 4274 | prevInternal := dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime |
| 4275 | dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime = prevInternal.Add(time.Duration(dh.pmConfigs.DefaultFreq) * time.Second) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4276 | } |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4277 | } else { |
| 4278 | if dh.pmConfigs.Grouped { // metrics are managed as a group |
| 4279 | // parse through the group and standalone metrics to see it is time to collect their metrics |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4280 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() // Rlock as we are reading GroupMetricMap and StandaloneMetricMap |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4281 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4282 | for n, g := range dh.pOnuMetricsMgr.GroupMetricMap { |
| 4283 | // If the group is enabled AND (current time is equal to OR after NextCollectionInterval, collect the group metric) |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 4284 | // Since the L2 PM counters are collected in a separate FSM, we should avoid those counters in the check. |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4285 | if g.Enabled && !g.IsL2PMCounter && (time.Now().Equal(g.NextCollectionInterval) || time.Now().After(g.NextCollectionInterval)) { |
| 4286 | go dh.pOnuMetricsMgr.CollectGroupMetric(ctx, n) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4287 | } |
| 4288 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4289 | for n, m := range dh.pOnuMetricsMgr.StandaloneMetricMap { |
| 4290 | // If the standalone is enabled AND (current time is equal to OR after NextCollectionInterval, collect the metric) |
| 4291 | if m.Enabled && (time.Now().Equal(m.NextCollectionInterval) || time.Now().After(m.NextCollectionInterval)) { |
| 4292 | go dh.pOnuMetricsMgr.CollectStandaloneMetric(ctx, n) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4293 | } |
| 4294 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4295 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4296 | |
| 4297 | // parse through the group and update the next metric collection time |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4298 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.Lock() // Lock as we are writing the next metric collection time |
| 4299 | for _, g := range dh.pOnuMetricsMgr.GroupMetricMap { |
| 4300 | // If group enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 4301 | // Since the L2 PM counters are collected and managed in a separate FSM, we should avoid those counters in the check. |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4302 | if g.Enabled && !g.IsL2PMCounter && (g.NextCollectionInterval.Before(time.Now()) || g.NextCollectionInterval.Equal(time.Now())) { |
| Mahir Gunyel | e184e9f | 2024-09-18 00:12:19 -0700 | [diff] [blame] | 4303 | prevInternal := g.NextCollectionInterval |
| 4304 | g.NextCollectionInterval = prevInternal.Add(time.Duration(g.Frequency) * time.Second) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4305 | } |
| 4306 | } |
| 4307 | // parse through the standalone metrics and update the next metric collection time |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4308 | for _, m := range dh.pOnuMetricsMgr.StandaloneMetricMap { |
| 4309 | // If standalone metrics enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp |
| 4310 | if m.Enabled && (m.NextCollectionInterval.Before(time.Now()) || m.NextCollectionInterval.Equal(time.Now())) { |
| Mahir Gunyel | e184e9f | 2024-09-18 00:12:19 -0700 | [diff] [blame] | 4311 | prevInternal := m.NextCollectionInterval |
| 4312 | m.NextCollectionInterval = prevInternal.Add(time.Duration(m.Frequency) * time.Second) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4313 | } |
| 4314 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4315 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.Unlock() |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4316 | } /* else { // metrics are not managed as a group |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4317 | // TODO: We currently do not have standalone metrics. When available, add code here to fetch the metrca. |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4318 | } */ |
| 4319 | } |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4320 | } |
| 4321 | } |
| 4322 | } |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 4323 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4324 | //nolint:unparam |
| Akash Soni | 3c176c6 | 2024-12-04 13:30:43 +0530 | [diff] [blame] | 4325 | func (dh *deviceHandler) setOnuOffloadStats(ctx context.Context, config *extension.AppOffloadOnuConfig) *extension.SingleSetValueResponse { |
| 4326 | |
| 4327 | singleValResp := extension.SingleSetValueResponse{ |
| 4328 | Response: &extension.SetValueResponse{ |
| 4329 | Status: extension.SetValueResponse_OK, |
| 4330 | }, |
| 4331 | } |
| 4332 | |
| 4333 | return &singleValResp |
| 4334 | } |
| 4335 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4336 | func (dh *deviceHandler) GetUniPortStatus(ctx context.Context, uniInfo *extension.GetOnuUniInfoRequest) *extension.SingleGetValueResponse { |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 4337 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4338 | portStatus := uniprt.NewUniPortStatus(dh, dh.pOnuOmciDevice.PDevOmciCC) |
| 4339 | return portStatus.GetUniPortStatus(ctx, uniInfo.UniIndex) |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 4340 | } |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4341 | |
| Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 4342 | func (dh *deviceHandler) getOnuOMCICounters(ctx context.Context, onuInfo *extension.GetOmciEthernetFrameExtendedPmRequest) *extension.SingleGetValueResponse { |
| 4343 | if dh.pOnuMetricsMgr == nil { |
| 4344 | return &extension.SingleGetValueResponse{ |
| 4345 | Response: &extension.GetValueResponse{ |
| 4346 | Status: extension.GetValueResponse_ERROR, |
| 4347 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 4348 | }, |
| 4349 | } |
| 4350 | } |
| Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 4351 | resp := dh.pOnuMetricsMgr.CollectEthernetFrameExtendedPMCounters(ctx, onuInfo) |
| Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 4352 | return resp |
| 4353 | } |
| 4354 | |
| Holger Hildebrandt | 66af5ce | 2022-09-07 13:38:02 +0000 | [diff] [blame] | 4355 | func (dh *deviceHandler) getOnuOMCIStats(ctx context.Context) (*extension.SingleGetValueResponse, error) { |
| 4356 | |
| 4357 | var err error |
| 4358 | var pDevOmciCC *cmn.OmciCC |
| 4359 | if dh.pOnuOmciDevice == nil { |
| 4360 | logger.Errorw(ctx, "No valid DeviceEntry", log.Fields{"device-id": dh.DeviceID}) |
| 4361 | err = fmt.Errorf("no-valid-DeviceEntry-%s", dh.DeviceID) |
| 4362 | } else { |
| 4363 | pDevOmciCC = dh.pOnuOmciDevice.GetDevOmciCC() |
| 4364 | if pDevOmciCC == nil { |
| 4365 | logger.Errorw(ctx, "No valid DeviceOmciCCEntry", log.Fields{"device-id": dh.DeviceID}) |
| 4366 | err = fmt.Errorf("no-valid-DeviceOmciCCEntry-%s", dh.DeviceID) |
| 4367 | } |
| 4368 | } |
| 4369 | if err != nil { |
| 4370 | return &extension.SingleGetValueResponse{ |
| 4371 | Response: &extension.GetValueResponse{ |
| 4372 | Status: extension.GetValueResponse_ERROR, |
| 4373 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 4374 | }, |
| 4375 | }, |
| 4376 | err |
| 4377 | } |
| 4378 | return pDevOmciCC.GetOmciCounters(), nil |
| 4379 | } |
| 4380 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4381 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4382 | func (dh *deviceHandler) isFsmInOmciIdleState(ctx context.Context, PFsm *fsm.FSM, wantedState string) bool { |
| 4383 | if PFsm == nil { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4384 | return true //FSM not active - so there is no activity on omci |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4385 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4386 | return PFsm.Current() == wantedState |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4387 | } |
| 4388 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4389 | func (dh *deviceHandler) isFsmInOmciIdleStateDefault(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, wantedState string) bool { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4390 | var pAdapterFsm *cmn.AdapterFsm |
| 4391 | //note/TODO!!: might be that access to all these specific FSM pointers need a semaphore protection as well, cmp lockUpgradeFsm |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4392 | switch omciFsm { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4393 | case cmn.CUploadFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4394 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4395 | if dh.pOnuOmciDevice != nil { |
| 4396 | pAdapterFsm = dh.pOnuOmciDevice.PMibUploadFsm |
| 4397 | } else { |
| 4398 | return true //FSM not active - so there is no activity on omci |
| 4399 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4400 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4401 | case cmn.CDownloadFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4402 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4403 | if dh.pOnuOmciDevice != nil { |
| 4404 | pAdapterFsm = dh.pOnuOmciDevice.PMibDownloadFsm |
| 4405 | } else { |
| 4406 | return true //FSM not active - so there is no activity on omci |
| 4407 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4408 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4409 | case cmn.CUniLockFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4410 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4411 | if dh.pLockStateFsm != nil { |
| 4412 | pAdapterFsm = dh.pLockStateFsm.PAdaptFsm |
| 4413 | } else { |
| 4414 | return true //FSM not active - so there is no activity on omci |
| 4415 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4416 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4417 | case cmn.CUniUnLockFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4418 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4419 | if dh.pUnlockStateFsm != nil { |
| 4420 | pAdapterFsm = dh.pUnlockStateFsm.PAdaptFsm |
| 4421 | } else { |
| 4422 | return true //FSM not active - so there is no activity on omci |
| 4423 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4424 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4425 | case cmn.CL2PmFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4426 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4427 | if dh.pOnuMetricsMgr != nil { |
| 4428 | pAdapterFsm = dh.pOnuMetricsMgr.PAdaptFsm |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4429 | } else { |
| 4430 | return true //FSM not active - so there is no activity on omci |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4431 | } |
| 4432 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4433 | case cmn.COnuUpgradeFsm: |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 4434 | { |
| 4435 | dh.lockUpgradeFsm.RLock() |
| 4436 | defer dh.lockUpgradeFsm.RUnlock() |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4437 | if dh.pOnuUpradeFsm != nil { |
| 4438 | pAdapterFsm = dh.pOnuUpradeFsm.PAdaptFsm |
| 4439 | } else { |
| 4440 | return true //FSM not active - so there is no activity on omci |
| 4441 | } |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 4442 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4443 | default: |
| 4444 | { |
| 4445 | logger.Errorw(ctx, "invalid stateMachine selected for idle check", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4446 | "device-id": dh.DeviceID, "selectedFsm number": omciFsm}) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4447 | return false //logical error in FSM check, do not not indicate 'idle' - we can't be sure |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4448 | } |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4449 | } |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4450 | if pAdapterFsm != nil && pAdapterFsm.PFsm != nil { |
| 4451 | return dh.isFsmInOmciIdleState(ctx, pAdapterFsm.PFsm, wantedState) |
| 4452 | } |
| 4453 | return true //FSM not active - so there is no activity on omci |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4454 | } |
| 4455 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4456 | func (dh *deviceHandler) isAniConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool { |
| 4457 | for _, v := range dh.pOnuTP.PAniConfigFsm { |
| 4458 | if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) { |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4459 | return false |
| 4460 | } |
| 4461 | } |
| 4462 | return true |
| 4463 | } |
| 4464 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4465 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4466 | func (dh *deviceHandler) isUniVlanConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4467 | dh.lockVlanConfig.RLock() |
| 4468 | defer dh.lockVlanConfig.RUnlock() |
| 4469 | for _, v := range dh.UniVlanConfigFsmMap { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4470 | if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4471 | return false |
| 4472 | } |
| 4473 | } |
| 4474 | return true //FSM not active - so there is no activity on omci |
| 4475 | } |
| 4476 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4477 | //nolint:unparam |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4478 | func (dh *deviceHandler) checkUserServiceExists(ctx context.Context) bool { |
| 4479 | dh.lockVlanConfig.RLock() |
| 4480 | defer dh.lockVlanConfig.RUnlock() |
| 4481 | for _, v := range dh.UniVlanConfigFsmMap { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4482 | if v.PAdaptFsm.PFsm != nil { |
| 4483 | if v.PAdaptFsm.PFsm.Is(avcfg.CVlanFsmConfiguredState) { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4484 | return true //there is at least one VLAN FSM with some active configuration |
| 4485 | } |
| 4486 | } |
| 4487 | } |
| 4488 | return false //there is no VLAN FSM with some active configuration |
| 4489 | } |
| 4490 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4491 | func (dh *deviceHandler) CheckAuditStartCondition(ctx context.Context, callingFsm cmn.UsedOmciConfigFsms) bool { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4492 | for fsmName, fsmStruct := range fsmOmciIdleStateFuncMap { |
| 4493 | if fsmName != callingFsm && !fsmStruct.omciIdleCheckFunc(dh, ctx, fsmName, fsmStruct.omciIdleState) { |
| 4494 | return false |
| 4495 | } |
| 4496 | } |
| 4497 | // a further check is done to identify, if at least some data traffic related configuration exists |
| 4498 | // so that a user of this ONU could be 'online' (otherwise it makes no sense to check the MDS [with the intention to keep the user service up]) |
| 4499 | return dh.checkUserServiceExists(ctx) |
| 4500 | } |
| 4501 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4502 | func (dh *deviceHandler) PrepareReconcilingWithActiveAdapter(ctx context.Context) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4503 | logger.Info(ctx, "prepare to reconcile the ONU with adapter using persistency data", log.Fields{"device-id": dh.device.Id}) |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4504 | if err := dh.resetFsms(ctx, false); err != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4505 | logger.Errorw(ctx, "reset of FSMs failed!", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4506 | // TODO: fatal error reset ONU, delete deviceHandler! |
| 4507 | return |
| 4508 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4509 | dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort) |
| 4510 | dh.StartReconciling(ctx, false) |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | func (dh *deviceHandler) setCollectorIsRunning(flagValue bool) { |
| 4514 | dh.mutexCollectorFlag.Lock() |
| 4515 | dh.collectorIsRunning = flagValue |
| 4516 | dh.mutexCollectorFlag.Unlock() |
| 4517 | } |
| 4518 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4519 | func (dh *deviceHandler) GetCollectorIsRunning() bool { |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4520 | dh.mutexCollectorFlag.RLock() |
| 4521 | flagValue := dh.collectorIsRunning |
| 4522 | dh.mutexCollectorFlag.RUnlock() |
| 4523 | return flagValue |
| 4524 | } |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 4525 | |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 4526 | func (dh *deviceHandler) setAlarmManagerIsRunning(flagValue bool) { |
| 4527 | dh.mutextAlarmManagerFlag.Lock() |
| 4528 | dh.alarmManagerIsRunning = flagValue |
| 4529 | dh.mutextAlarmManagerFlag.Unlock() |
| 4530 | } |
| 4531 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4532 | func (dh *deviceHandler) GetAlarmManagerIsRunning(ctx context.Context) bool { |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 4533 | dh.mutextAlarmManagerFlag.RLock() |
| 4534 | flagValue := dh.alarmManagerIsRunning |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4535 | logger.Debugw(ctx, "alarm-manager-is-running", log.Fields{"device-id": dh.device.Id, "flag": dh.alarmManagerIsRunning}) |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 4536 | dh.mutextAlarmManagerFlag.RUnlock() |
| 4537 | return flagValue |
| 4538 | } |
| 4539 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4540 | func (dh *deviceHandler) StartAlarmManager(ctx context.Context) { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4541 | logger.Debugw(ctx, "startingAlarmManager", log.Fields{"device-id": dh.device.Id}) |
| bseeniva | 596a522 | 2026-01-23 19:26:11 +0530 | [diff] [blame] | 4542 | dh.RLockMutexDeletionInProgressFlag() |
| 4543 | if dh.GetDeletionInProgress() { |
| 4544 | logger.Warnw(ctx, "Device deletion in progress - avoid starting alarm manager", log.Fields{"device-id": dh.DeviceID}) |
| 4545 | dh.RUnlockMutexDeletionInProgressFlag() |
| 4546 | return |
| 4547 | } |
| 4548 | // Set alarmManagerIsRunning flag to true while still holding deviceDeletionFlag lock, |
| 4549 | // to avoid potential race condition where resetFsm from DeleteDevice might avoid stopping the alarm manager if this flag is not yet set |
| 4550 | dh.setAlarmManagerIsRunning(true) |
| 4551 | |
| 4552 | dh.RUnlockMutexDeletionInProgressFlag() |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 4553 | |
| 4554 | // Start routine to process OMCI GET Responses |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4555 | go dh.pAlarmMgr.StartOMCIAlarmMessageProcessing(ctx) |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 4556 | if stop := <-dh.stopAlarmManager; stop { |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 4557 | logger.Debugw(ctx, "stopping-alarm-manager-for-onu", log.Fields{"device-id": dh.device.Id}) |
| Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 4558 | go func() { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4559 | if dh.pAlarmMgr.AlarmSyncFsm != nil && dh.pAlarmMgr.AlarmSyncFsm.PFsm != nil { |
| 4560 | _ = dh.pAlarmMgr.AlarmSyncFsm.PFsm.Event(almgr.AsEvStop) |
| Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 4561 | } |
| Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 4562 | }() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4563 | dh.pAlarmMgr.StopProcessingOmciMessages <- true // Stop the OMCI routines if any(This will stop the fsms also) |
| 4564 | dh.pAlarmMgr.StopAlarmAuditTimer <- struct{}{} |
| Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 4565 | logger.Debugw(ctx, "sent-all-stop-signals-to-alarm-manager", log.Fields{"device-id": dh.device.Id}) |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 4566 | } |
| 4567 | } |
| Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 4568 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4569 | func (dh *deviceHandler) setFlowMonitoringIsRunning(uniID uint8, flag bool) { |
| 4570 | dh.mutexFlowMonitoringRoutineFlag.Lock() |
| 4571 | defer dh.mutexFlowMonitoringRoutineFlag.Unlock() |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4572 | logger.Debugw(context.Background(), "set-flow-monitoring-routine", log.Fields{"device-id": dh.device.Id, "flag": flag}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4573 | dh.isFlowMonitoringRoutineActive[uniID] = flag |
| 4574 | } |
| 4575 | |
| 4576 | func (dh *deviceHandler) GetFlowMonitoringIsRunning(uniID uint8) bool { |
| 4577 | dh.mutexFlowMonitoringRoutineFlag.RLock() |
| 4578 | defer dh.mutexFlowMonitoringRoutineFlag.RUnlock() |
| 4579 | logger.Debugw(context.Background(), "get-flow-monitoring-routine", |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4580 | log.Fields{"device-id": dh.device.Id, "isFlowMonitoringRoutineActive": dh.isFlowMonitoringRoutineActive}) |
| Sridhar Ravindra | e9a8bcc | 2024-12-06 10:40:54 +0530 | [diff] [blame] | 4581 | if len(dh.isFlowMonitoringRoutineActive) != 0 { |
| 4582 | return dh.isFlowMonitoringRoutineActive[uniID] |
| 4583 | } |
| 4584 | return false |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4585 | } |
| 4586 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4587 | func (dh *deviceHandler) StartReconciling(ctx context.Context, skipOnuConfig bool) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4588 | logger.Info(ctx, "start reconciling", log.Fields{"skipOnuConfig": skipOnuConfig, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4589 | |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4590 | connectStatus := voltha.ConnectStatus_UNREACHABLE |
| 4591 | operState := voltha.OperStatus_UNKNOWN |
| 4592 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4593 | if !dh.IsReconciling() { |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4594 | go func() { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4595 | logger.Debugw(ctx, "wait for channel signal or timeout", |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4596 | log.Fields{"timeout": dh.reconcileExpiryComplete, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4597 | select { |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4598 | case success := <-dh.chReconcilingFinished: |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4599 | logger.Info(ctx, "reconciling finished signal received", |
| Holger Hildebrandt | f745925 | 2022-01-03 16:10:37 +0000 | [diff] [blame] | 4600 | log.Fields{"device-id": dh.DeviceID, "dh.chReconcilingFinished": dh.chReconcilingFinished}) |
| 4601 | // To guarantee that the case-branch below is completely processed before reconciling processing is continued, |
| 4602 | // dh.mutexReconcilingFlag is locked already here. Thereby it is ensured, that further reconciling processing is stopped |
| 4603 | // at next call of dh.IsReconciling() until dh.reconciling is set after informing core about finished reconciling below. |
| 4604 | // This change addresses a problem described in VOL-4533 where the flag dh.reconciling not yet reset causes the uni ports |
| 4605 | // not to be created in ONOS in function dh.addUniPort(), when reconciling was started in reason "starting-openomci". |
| 4606 | // TODO: Keeping the mutex beyond an RPC towards core seems justifiable, as the effects here are easily overseeable. |
| 4607 | // However, a later refactoring of the functionality remains unaffected. |
| 4608 | dh.mutexReconcilingFlag.Lock() |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4609 | if success { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4610 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4611 | logger.Errorw(ctx, "No valid OnuDevice - aborting Core DeviceStateUpdate", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4612 | log.Fields{"device-id": dh.DeviceID}) |
| akashreddyk | b03dde0 | 2025-12-02 10:53:18 +0530 | [diff] [blame] | 4613 | } else if !onuDevEntry.SOnuPersistentData.PersRebootInProgress { |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4614 | onuDevEntry.MutexPersOnuConfig.RLock() |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 4615 | switch onuDevEntry.SOnuPersistentData.PersOperState { |
| 4616 | case "up": |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4617 | connectStatus = voltha.ConnectStatus_REACHABLE |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4618 | if !onuDevEntry.SOnuPersistentData.PersUniDisableDone { |
| 4619 | if onuDevEntry.SOnuPersistentData.PersUniUnlockDone { |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4620 | operState = voltha.OperStatus_ACTIVE |
| 4621 | } else { |
| 4622 | operState = voltha.OperStatus_ACTIVATING |
| 4623 | } |
| 4624 | } |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 4625 | case "down", "unknown", "": |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4626 | operState = voltha.OperStatus_DISCOVERED |
| 4627 | } |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4628 | onuDevEntry.MutexPersOnuConfig.RUnlock() |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4629 | logger.Debugw(ctx, "Core DeviceStateUpdate", |
| 4630 | log.Fields{"device-id": dh.device.Id, "connectStatus": connectStatus, "operState": operState}) |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4631 | } |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4632 | logger.Info(ctx, "reconciling has been finished in time", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4633 | log.Fields{"device-id": dh.DeviceID}) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4634 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4635 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4636 | ConnStatus: connectStatus, |
| 4637 | OperStatus: operState, |
| 4638 | }); err != nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4639 | logger.Errorw(ctx, "unable to update device state to core", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4640 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4641 | } |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4642 | } else { |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4643 | logger.Errorw(ctx, "wait for reconciling aborted", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4644 | log.Fields{"device-id": dh.DeviceID}) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4645 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4646 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4647 | logger.Errorw(ctx, "No valid OnuDevice", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4648 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4649 | } else { |
| 4650 | onuDevEntry.MutexPersOnuConfig.RLock() |
| 4651 | if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
| 4652 | connectStatus = voltha.ConnectStatus_REACHABLE |
| 4653 | } |
| 4654 | onuDevEntry.MutexPersOnuConfig.RUnlock() |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4655 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4656 | dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileCanceled, connectStatus) |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4657 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4658 | case <-time.After(dh.reconcileExpiryComplete): |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4659 | logger.Errorw(ctx, "timeout waiting for reconciling to be finished!", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4660 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | f745925 | 2022-01-03 16:10:37 +0000 | [diff] [blame] | 4661 | dh.mutexReconcilingFlag.Lock() |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4662 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4663 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4664 | logger.Errorw(ctx, "No valid OnuDevice", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4665 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4666 | } else { |
| 4667 | onuDevEntry.MutexPersOnuConfig.RLock() |
| 4668 | if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
| 4669 | connectStatus = voltha.ConnectStatus_REACHABLE |
| 4670 | } |
| 4671 | onuDevEntry.MutexPersOnuConfig.RUnlock() |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4672 | } |
| 4673 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4674 | dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileMaxTimeout, connectStatus) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4675 | |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4676 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4677 | dh.reconciling = cNoReconciling |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4678 | dh.mutexReconcilingFlag.Unlock() |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4679 | dh.SetReconcilingReasonUpdate(false) |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 4680 | dh.SetReconcilingFirstPass(true) |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4681 | |
| 4682 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
| 4683 | logger.Errorw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 4684 | } else { |
| 4685 | onuDevEntry.MutexReconciledTpInstances.Lock() |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 4686 | onuDevEntry.ReconciledTpInstances = make(map[uint8]map[uint8]ia.TechProfileDownloadMessage) |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4687 | onuDevEntry.MutexReconciledTpInstances.Unlock() |
| 4688 | } |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4689 | }() |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4690 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4691 | dh.mutexReconcilingFlag.Lock() |
| Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 4692 | if skipOnuConfig || dh.GetSkipOnuConfigEnabled() { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4693 | dh.reconciling = cSkipOnuConfigReconciling |
| 4694 | } else { |
| 4695 | dh.reconciling = cOnuConfigReconciling |
| 4696 | } |
| 4697 | dh.mutexReconcilingFlag.Unlock() |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4698 | } |
| 4699 | |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4700 | func (dh *deviceHandler) stopReconciling(ctx context.Context, success bool, reconcileFlowResult uint16) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4701 | logger.Warn(ctx, "stop reconciling", log.Fields{"device-id": dh.DeviceID, "success": success}) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4702 | if dh.IsReconciling() { |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4703 | dh.sendChReconcileFinished(success) |
| 4704 | if reconcileFlowResult != cWaitReconcileFlowNoActivity { |
| 4705 | dh.SendChUniVlanConfigFinished(reconcileFlowResult) |
| 4706 | } |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4707 | } else { |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4708 | logger.Debugw(ctx, "nothing to stop - reconciling is not running", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4709 | } |
| 4710 | } |
| 4711 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4712 | func (dh *deviceHandler) IsReconciling() bool { |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4713 | dh.mutexReconcilingFlag.RLock() |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4714 | defer dh.mutexReconcilingFlag.RUnlock() |
| 4715 | return dh.reconciling != cNoReconciling |
| 4716 | } |
| 4717 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4718 | func (dh *deviceHandler) IsSkipOnuConfigReconciling() bool { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4719 | dh.mutexReconcilingFlag.RLock() |
| 4720 | defer dh.mutexReconcilingFlag.RUnlock() |
| 4721 | return dh.reconciling == cSkipOnuConfigReconciling |
| 4722 | } |
| 4723 | |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 4724 | func (dh *deviceHandler) SetReconcilingFirstPass(value bool) { |
| 4725 | dh.mutexReconcilingFirstPassFlag.Lock() |
| 4726 | dh.reconcilingFirstPass = value |
| 4727 | dh.mutexReconcilingFirstPassFlag.Unlock() |
| 4728 | } |
| 4729 | |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4730 | func (dh *deviceHandler) SetReconcilingReasonUpdate(value bool) { |
| 4731 | dh.mutexReconcilingReasonUpdate.Lock() |
| 4732 | dh.reconcilingReasonUpdate = value |
| 4733 | dh.mutexReconcilingReasonUpdate.Unlock() |
| 4734 | } |
| 4735 | |
| 4736 | func (dh *deviceHandler) IsReconcilingReasonUpdate() bool { |
| 4737 | dh.mutexReconcilingReasonUpdate.RLock() |
| 4738 | defer dh.mutexReconcilingReasonUpdate.RUnlock() |
| 4739 | return dh.reconcilingReasonUpdate |
| 4740 | } |
| 4741 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4742 | func (dh *deviceHandler) getDeviceReason() uint8 { |
| 4743 | dh.mutexDeviceReason.RLock() |
| 4744 | value := dh.deviceReason |
| 4745 | dh.mutexDeviceReason.RUnlock() |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4746 | return value |
| 4747 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4748 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4749 | func (dh *deviceHandler) GetDeviceReasonString() string { |
| 4750 | return cmn.DeviceReasonMap[dh.getDeviceReason()] |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4751 | } |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4752 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4753 | func (dh *deviceHandler) SetReadyForOmciConfig(flagValue bool) { |
| Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 4754 | dh.mutexReadyForOmciConfig.Lock() |
| 4755 | dh.readyForOmciConfig = flagValue |
| 4756 | dh.mutexReadyForOmciConfig.Unlock() |
| 4757 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4758 | func (dh *deviceHandler) IsReadyForOmciConfig() bool { |
| Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 4759 | dh.mutexReadyForOmciConfig.RLock() |
| 4760 | flagValue := dh.readyForOmciConfig |
| 4761 | dh.mutexReadyForOmciConfig.RUnlock() |
| 4762 | return flagValue |
| 4763 | } |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4764 | |
| 4765 | func (dh *deviceHandler) deviceReconcileFailedUpdate(ctx context.Context, deviceReason uint8, connectStatus voltha.ConnectStatus_Types) { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4766 | if err := dh.ReasonUpdate(ctx, deviceReason, true); err != nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4767 | logger.Errorw(ctx, "unable to update device reason to core", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4768 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4769 | } |
| 4770 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4771 | logger.Debugw(ctx, "Core DeviceStateUpdate", |
| 4772 | log.Fields{"device-id": dh.device.Id, "connectStatus": connectStatus, "operState": voltha.OperStatus_RECONCILING_FAILED}) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4773 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4774 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4775 | ConnStatus: connectStatus, |
| 4776 | OperStatus: voltha.OperStatus_RECONCILING_FAILED, |
| 4777 | }); err != nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4778 | logger.Errorw(ctx, "unable to update device state to core", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4779 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4780 | } |
| 4781 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4782 | |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 4783 | func (dh *deviceHandler) deviceRebootStateUpdate(ctx context.Context, techProfInstLoadFailed bool) { |
| 4784 | if techProfInstLoadFailed { |
| 4785 | if err := dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadFailed, true); err != nil { |
| 4786 | logger.Errorw(ctx, "unable to update device reason to core", |
| 4787 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
| 4788 | } |
| 4789 | context := make(map[string]string) |
| 4790 | context["device-id"] = dh.DeviceID |
| 4791 | context["onu-serial-number"] = dh.device.SerialNumber |
| 4792 | context["parent-id"] = dh.parentID |
| 4793 | |
| 4794 | // Send event on flow configuration failure so that corrective action can be triggered from NB |
| 4795 | deviceEvent := &voltha.DeviceEvent{ |
| 4796 | ResourceId: dh.DeviceID, |
| 4797 | DeviceEventName: cmn.OnuFlowConfigFailed, |
| 4798 | Description: cmn.OnuFlowConfigFailedDesc, |
| 4799 | Context: context, |
| 4800 | } |
| 4801 | logger.Debugw(ctx, "send device event", log.Fields{"deviceEvent": deviceEvent, "device-id": dh.DeviceID}) |
| 4802 | _ = dh.EventProxy.SendDeviceEvent(ctx, deviceEvent, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, time.Now().Unix()) |
| 4803 | } |
| 4804 | } |
| 4805 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4806 | /* |
| 4807 | Helper functions to communicate with Core |
| 4808 | */ |
| 4809 | |
| 4810 | func (dh *deviceHandler) getDeviceFromCore(ctx context.Context, deviceID string) (*voltha.Device, error) { |
| 4811 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4812 | if err != nil || cClient == nil { |
| 4813 | return nil, err |
| 4814 | } |
| 4815 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4816 | defer cancel() |
| 4817 | logger.Debugw(subCtx, "get-device-from-core", log.Fields{"device-id": deviceID}) |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 4818 | return cClient.GetDevice(subCtx, &common.ID{Id: deviceID}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4819 | } |
| 4820 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4821 | func (dh *deviceHandler) updateDeviceStateInCore(ctx context.Context, deviceStateFilter *ca.DeviceStateFilter) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4822 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4823 | if err != nil || cClient == nil { |
| 4824 | return err |
| 4825 | } |
| 4826 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4827 | defer cancel() |
| 4828 | _, err = cClient.DeviceStateUpdate(subCtx, deviceStateFilter) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4829 | logger.Debugw(subCtx, "device-updated-in-core", |
| 4830 | log.Fields{"device-id": dh.device.Id, "device-state": deviceStateFilter, "error": err}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4831 | return err |
| 4832 | } |
| 4833 | |
| 4834 | func (dh *deviceHandler) updatePMConfigInCore(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 4835 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4836 | if err != nil || cClient == nil { |
| 4837 | return err |
| 4838 | } |
| 4839 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4840 | defer cancel() |
| 4841 | _, err = cClient.DevicePMConfigUpdate(subCtx, pmConfigs) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4842 | logger.Debugw(subCtx, "pmconfig-updated-in-core", |
| 4843 | log.Fields{"device-id": dh.device.Id, "pm-configs": pmConfigs, "error": err}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4844 | return err |
| 4845 | } |
| 4846 | |
| 4847 | func (dh *deviceHandler) updateDeviceInCore(ctx context.Context, device *voltha.Device) error { |
| 4848 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4849 | if err != nil || cClient == nil { |
| 4850 | return err |
| 4851 | } |
| 4852 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4853 | defer cancel() |
| 4854 | _, err = cClient.DeviceUpdate(subCtx, device) |
| 4855 | logger.Debugw(subCtx, "device-updated-in-core", log.Fields{"device-id": device.Id, "error": err}) |
| 4856 | return err |
| 4857 | } |
| 4858 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4859 | func (dh *deviceHandler) CreatePortInCore(ctx context.Context, port *voltha.Port) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4860 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4861 | if err != nil || cClient == nil { |
| 4862 | return err |
| 4863 | } |
| 4864 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4865 | defer cancel() |
| 4866 | _, err = cClient.PortCreated(subCtx, port) |
| 4867 | logger.Debugw(subCtx, "port-created-in-core", log.Fields{"port": port, "error": err}) |
| 4868 | return err |
| 4869 | } |
| 4870 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4871 | func (dh *deviceHandler) updatePortStateInCore(ctx context.Context, portState *ca.PortState) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4872 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4873 | if err != nil || cClient == nil { |
| 4874 | return err |
| 4875 | } |
| 4876 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4877 | defer cancel() |
| 4878 | _, err = cClient.PortStateUpdate(subCtx, portState) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4879 | logger.Debugw(subCtx, "port-state-updated-in-core", log.Fields{"device-id": dh.device.Id, "port-state": portState, "error": err}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4880 | return err |
| 4881 | } |
| 4882 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4883 | func (dh *deviceHandler) updateDeviceReasonInCore(ctx context.Context, reason *ca.DeviceReason) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4884 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4885 | if err != nil || cClient == nil { |
| 4886 | return err |
| 4887 | } |
| 4888 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4889 | defer cancel() |
| 4890 | _, err = cClient.DeviceReasonUpdate(subCtx, reason) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4891 | logger.Debugw(subCtx, "device-reason-updated-in-core", log.Fields{"device-id": dh.device.Id, "reason": reason, "error": err}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4892 | return err |
| 4893 | } |
| 4894 | |
| 4895 | /* |
| 4896 | Helper functions to communicate with parent adapter |
| 4897 | */ |
| 4898 | |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4899 | func (dh *deviceHandler) GetTechProfileInstanceFromParentAdapter(ctx context.Context, aUniID uint8, |
| 4900 | aTpPath string) (*ia.TechProfileDownloadMessage, error) { |
| 4901 | |
| 4902 | var request = ia.TechProfileInstanceRequestMessage{ |
| 4903 | DeviceId: dh.DeviceID, |
| 4904 | TpInstancePath: aTpPath, |
| 4905 | ParentDeviceId: dh.parentID, |
| 4906 | ParentPonPort: dh.device.ParentPortNo, |
| 4907 | OnuId: dh.device.ProxyAddress.OnuId, |
| 4908 | UniId: uint32(aUniID), |
| 4909 | } |
| 4910 | |
| 4911 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(dh.device.ProxyAddress.AdapterEndpoint) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4912 | if err != nil || pgClient == nil { |
| 4913 | return nil, err |
| 4914 | } |
| 4915 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 4916 | defer cancel() |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4917 | logger.Debugw(subCtx, "get-tech-profile-instance", |
| 4918 | log.Fields{"device-id": dh.device.Id, "request": request, "parent-endpoint": dh.device.ProxyAddress.AdapterEndpoint}) |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4919 | return pgClient.GetTechProfileInstance(subCtx, &request) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4920 | } |
| 4921 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4922 | // This routine is unique per ONU ID and blocks on flowControlBlock channel for incoming flows |
| 4923 | // Each incoming flow is processed in a synchronous manner, i.e., the flow is processed to completion before picking another |
| 4924 | func (dh *deviceHandler) PerOnuFlowHandlerRoutine(uniID uint8) { |
| 4925 | logger.Infow(context.Background(), "starting-flow-handler-routine", log.Fields{"device-id": dh.DeviceID}) |
| 4926 | dh.setFlowMonitoringIsRunning(uniID, true) |
| 4927 | for { |
| 4928 | select { |
| 4929 | // block on the channel to receive an incoming flow |
| 4930 | // process the flow completely before proceeding to handle the next flow |
| 4931 | case flowCb := <-dh.flowCbChan[uniID]: |
| 4932 | startTime := time.Now() |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4933 | logger.Info(flowCb.ctx, "serial-flow-processor--start", log.Fields{"device-id": dh.DeviceID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4934 | respChan := make(chan error) |
| 4935 | if flowCb.addFlow { |
| 4936 | go dh.addFlowItemToUniPort(flowCb.ctx, flowCb.flowItem, flowCb.uniPort, flowCb.flowMetaData, &respChan) |
| 4937 | } else { |
| 4938 | go dh.removeFlowItemFromUniPort(flowCb.ctx, flowCb.flowItem, flowCb.uniPort, &respChan) |
| 4939 | } |
| 4940 | // Block on response and tunnel it back to the caller |
| balaji.nagarajan | 62ac62b | 2025-09-08 10:49:58 +0530 | [diff] [blame] | 4941 | select { |
| 4942 | |
| 4943 | case msg := <-respChan: |
| 4944 | *flowCb.respChan <- msg |
| 4945 | // response sent successfully |
| 4946 | logger.Info(flowCb.ctx, "serial-flow-processor--end", |
| 4947 | log.Fields{"device-id": dh.DeviceID, "absoluteTimeForFlowProcessingInSecs": time.Since(startTime).Seconds()}) |
| 4948 | case <-flowCb.ctx.Done(): |
| 4949 | logger.Info(flowCb.ctx, "flow handler context cancelled or timed out", log.Fields{"device-id": dh.DeviceID}) |
| 4950 | // Optionally, you can handle cleanup or logging here |
| 4951 | if dh.UniVlanConfigFsmMap[flowCb.uniPort.UniID] != nil && dh.UniVlanConfigFsmMap[flowCb.uniPort.UniID].PAdaptFsm != nil { |
| 4952 | pVlanFilterStatemachine := dh.UniVlanConfigFsmMap[flowCb.uniPort.UniID].PAdaptFsm.PFsm |
| 4953 | if pVlanFilterStatemachine != nil { |
| 4954 | |
| 4955 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvReset); err != nil { |
| 4956 | logger.Warnw(flowCb.ctx, "UniVlanConfigFsm: can't reset", |
| 4957 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 4958 | |
| 4959 | } |
| 4960 | |
| 4961 | } |
| 4962 | } |
| 4963 | |
| 4964 | ctx2 := context.Background() |
| 4965 | metadata := flow.GetMetadataFromWriteMetadataAction(ctx2, flowCb.flowItem) |
| 4966 | if metadata == 0 { |
| 4967 | logger.Warnw(flowCb.ctx, "AniConfigFsm: can't reset,failed to fetch metadata flow: %v", |
| 4968 | log.Fields{"device-id": dh.DeviceID, "flows": flowCb.flowItem}) |
| 4969 | continue |
| 4970 | } |
| 4971 | TpID := flow.GetTechProfileIDFromWriteMetaData(ctx2, metadata) |
| 4972 | |
| 4973 | if TpID == uint16(0) { |
| 4974 | logger.Warnw(flowCb.ctx, "AniConfigFsm: can't reset,failed to fetch techprofileid flow: %v", |
| 4975 | log.Fields{"device-id": dh.DeviceID, "flows": flowCb.flowItem}) |
| 4976 | continue |
| 4977 | } |
| 4978 | if dh.pOnuTP != nil { |
| 4979 | // should always be the case here |
| 4980 | // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting |
| 4981 | if dh.pOnuTP.PAniConfigFsm != nil { |
| 4982 | uniTP := avcfg.UniTP{ |
| 4983 | UniID: flowCb.uniPort.UniID, |
| 4984 | TpID: uint8(TpID), |
| 4985 | } |
| 4986 | if dh.pOnuTP.PAniConfigFsm[uniTP] != nil { |
| 4987 | dh.pOnuTP.PAniConfigFsm[uniTP].CancelProcessing(context.Background()) |
| 4988 | } |
| 4989 | } |
| 4990 | } |
| 4991 | |
| 4992 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4993 | case <-dh.stopFlowMonitoringRoutine[uniID]: |
| 4994 | logger.Infow(context.Background(), "stopping-flow-handler-routine", log.Fields{"device-id": dh.DeviceID}) |
| 4995 | dh.setFlowMonitoringIsRunning(uniID, false) |
| 4996 | return |
| 4997 | } |
| 4998 | } |
| 4999 | } |
| 5000 | |
| kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 5001 | func (dh *deviceHandler) SendOnuSwSectionsOfWindow(ctx context.Context, parentEndpoint string, request *ia.OmciMessages) error { |
| 5002 | request.ParentDeviceId = dh.GetProxyAddressID() |
| 5003 | request.ChildDeviceId = dh.DeviceID |
| 5004 | request.ProxyAddress = dh.GetProxyAddress() |
| 5005 | request.ConnectStatus = common.ConnectStatus_REACHABLE |
| 5006 | |
| 5007 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint) |
| 5008 | if err != nil || pgClient == nil { |
| 5009 | return err |
| 5010 | } |
| 5011 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 5012 | defer cancel() |
| 5013 | logger.Debugw(subCtx, "send-omci-request", log.Fields{"request": request, "parent-endpoint": parentEndpoint}) |
| 5014 | _, err = pgClient.ProxyOmciRequests(subCtx, request) |
| 5015 | if err != nil { |
| Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 5016 | logger.Errorw(ctx, "omci-failure", log.Fields{"device-id": dh.device.Id, "request": request, "error": err, |
| 5017 | "request-parent": request.ParentDeviceId, "request-child": request.ChildDeviceId, "request-proxy": request.ProxyAddress}) |
| kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 5018 | } |
| 5019 | return err |
| 5020 | } |
| 5021 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 5022 | func (dh *deviceHandler) SendOMCIRequest(ctx context.Context, parentEndpoint string, request *ia.OmciMessage) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 5023 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint) |
| 5024 | if err != nil || pgClient == nil { |
| 5025 | return err |
| 5026 | } |
| 5027 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 5028 | defer cancel() |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 5029 | dh.setOltAvailable(true) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 5030 | logger.Debugw(subCtx, "send-omci-request", log.Fields{"device-id": dh.device.Id, "request": request, "parent-endpoint": parentEndpoint}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 5031 | _, err = pgClient.ProxyOmciRequest(subCtx, request) |
| 5032 | if err != nil { |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 5033 | if status.Code(err) == codes.Unavailable { |
| 5034 | dh.setOltAvailable(false) |
| 5035 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 5036 | logger.Errorw(ctx, "omci-failure", |
| 5037 | log.Fields{"device-id": dh.device.Id, "request": request, "error": err, "request-parent": request.ParentDeviceId, |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 5038 | "request-child": request.ChildDeviceId, "request-proxy": request.ProxyAddress, "oltAvailable": dh.IsOltAvailable}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 5039 | } |
| 5040 | return err |
| 5041 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5042 | |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 5043 | func (dh *deviceHandler) CheckAvailableOnuCapabilities(ctx context.Context, pDevEntry *mib.OnuDeviceEntry, tpInst tech_profile.TechProfileInstance) error { |
| 5044 | // Check if there are additional TCONT instances necessary/available |
| 5045 | pDevEntry.MutexPersOnuConfig.Lock() |
| 5046 | if _, ok := pDevEntry.SOnuPersistentData.PersTcontMap[uint16(tpInst.UsScheduler.AllocId)]; !ok { |
| 5047 | numberOfTcontMapEntries := len(pDevEntry.SOnuPersistentData.PersTcontMap) |
| 5048 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 5049 | numberOfTcontDbInsts := pDevEntry.GetOnuDB().GetNumberOfInst(me.TContClassID) |
| 5050 | logger.Debugw(ctx, "checking available TCONT instances", |
| 5051 | log.Fields{"device-id": dh.DeviceID, "numberOfTcontMapEntries": numberOfTcontMapEntries, "numberOfTcontDbInsts": numberOfTcontDbInsts}) |
| 5052 | if numberOfTcontMapEntries >= numberOfTcontDbInsts { |
| 5053 | logger.Errorw(ctx, "configuration exceeds ONU capabilities - running out of TCONT instances: send ONU device event!", |
| 5054 | log.Fields{"device-id": dh.device.Id}) |
| 5055 | pDevEntry.SendOnuDeviceEvent(ctx, cmn.OnuConfigFailureMissingTcont, cmn.OnuConfigFailureMissingTcontDesc) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 5056 | return fmt.Errorf("configuration exceeds ONU capabilities - running out of TCONT instances: device-id: %s", dh.DeviceID) |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 5057 | } |
| 5058 | } else { |
| 5059 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 5060 | } |
| 5061 | // Check if there are enough PrioQueue instances available |
| 5062 | if dh.pOnuTP != nil { |
| 5063 | var numberOfUsPrioQueueDbInsts int |
| 5064 | |
| 5065 | queueInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys(ctx, me.PriorityQueueClassID) |
| 5066 | for _, mgmtEntityID := range queueInstKeys { |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 5067 | if mgmtEntityID >= 0x8000 { |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 5068 | numberOfUsPrioQueueDbInsts++ |
| 5069 | } |
| 5070 | } |
| 5071 | // Check if there is an upstream PriorityQueue instance available for each Gem port |
| 5072 | numberOfConfiguredGemPorts := dh.pOnuTP.GetNumberOfConfiguredUsGemPorts(ctx) |
| 5073 | logger.Debugw(ctx, "checking available upstream PriorityQueue instances", |
| 5074 | log.Fields{"device-id": dh.DeviceID, |
| 5075 | "numberOfConfiguredGemPorts": numberOfConfiguredGemPorts, |
| 5076 | "tpInst.NumGemPorts": tpInst.NumGemPorts, |
| 5077 | "numberOfUsPrioQueueDbInsts": numberOfUsPrioQueueDbInsts}) |
| 5078 | |
| 5079 | if numberOfConfiguredGemPorts+int(tpInst.NumGemPorts) > numberOfUsPrioQueueDbInsts { |
| 5080 | logger.Errorw(ctx, "configuration exceeds ONU capabilities - running out of upstream PrioQueue instances: send ONU device event!", |
| 5081 | log.Fields{"device-id": dh.device.Id}) |
| 5082 | pDevEntry.SendOnuDeviceEvent(ctx, cmn.OnuConfigFailureMissingUsPriorityQueue, cmn.OnuConfigFailureMissingUsPriorityQueueDesc) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 5083 | return fmt.Errorf("configuration exceeds ONU capabilities - running out of upstream PrioQueue instances: device-id: %s", dh.DeviceID) |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 5084 | } |
| 5085 | // Downstream PrioQueue instances are evaluated in accordance with ONU MIB upload data in function UniPonAniConfigFsm::prepareAndEnterConfigState(). |
| 5086 | // In case of missing downstream PrioQueues the attribute "Priority queue pointer for downstream" of ME "GEM port network CTP" will be set to "0", |
| 5087 | // which then alternatively activates the queuing mechanisms of the ONU (refer to Rec. ITU-T G.988 chapter 9.2.3). |
| 5088 | } else { |
| 5089 | logger.Warnw(ctx, "onuTechProf instance not set up - check for PriorityQueue instances skipped!", |
| 5090 | log.Fields{"device-id": dh.DeviceID}) |
| 5091 | } |
| 5092 | return nil |
| 5093 | } |
| 5094 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5095 | // GetDeviceID - TODO: add comment |
| 5096 | func (dh *deviceHandler) GetDeviceID() string { |
| 5097 | return dh.DeviceID |
| 5098 | } |
| 5099 | |
| 5100 | // GetProxyAddressID - TODO: add comment |
| 5101 | func (dh *deviceHandler) GetProxyAddressID() string { |
| 5102 | return dh.device.ProxyAddress.GetDeviceId() |
| 5103 | } |
| 5104 | |
| 5105 | // GetProxyAddressType - TODO: add comment |
| 5106 | func (dh *deviceHandler) GetProxyAddressType() string { |
| 5107 | return dh.device.ProxyAddress.GetDeviceType() |
| 5108 | } |
| 5109 | |
| 5110 | // GetProxyAddress - TODO: add comment |
| 5111 | func (dh *deviceHandler) GetProxyAddress() *voltha.Device_ProxyAddress { |
| 5112 | return dh.device.ProxyAddress |
| 5113 | } |
| 5114 | |
| 5115 | // GetEventProxy - TODO: add comment |
| 5116 | func (dh *deviceHandler) GetEventProxy() eventif.EventProxy { |
| 5117 | return dh.EventProxy |
| 5118 | } |
| 5119 | |
| 5120 | // GetOmciTimeout - TODO: add comment |
| 5121 | func (dh *deviceHandler) GetOmciTimeout() int { |
| 5122 | return dh.pOpenOnuAc.omciTimeout |
| 5123 | } |
| 5124 | |
| 5125 | // GetAlarmAuditInterval - TODO: add comment |
| 5126 | func (dh *deviceHandler) GetAlarmAuditInterval() time.Duration { |
| 5127 | return dh.pOpenOnuAc.alarmAuditInterval |
| 5128 | } |
| 5129 | |
| 5130 | // GetDlToOnuTimeout4M - TODO: add comment |
| 5131 | func (dh *deviceHandler) GetDlToOnuTimeout4M() time.Duration { |
| 5132 | return dh.pOpenOnuAc.dlToOnuTimeout4M |
| 5133 | } |
| 5134 | |
| 5135 | // GetUniEntityMap - TODO: add comment |
| 5136 | func (dh *deviceHandler) GetUniEntityMap() *cmn.OnuUniPortMap { |
| 5137 | return &dh.uniEntityMap |
| 5138 | } |
| 5139 | |
| 5140 | // GetPonPortNumber - TODO: add comment |
| 5141 | func (dh *deviceHandler) GetPonPortNumber() *uint32 { |
| 5142 | return &dh.ponPortNumber |
| 5143 | } |
| 5144 | |
| 5145 | // GetUniVlanConfigFsm - TODO: add comment |
| 5146 | func (dh *deviceHandler) GetUniVlanConfigFsm(uniID uint8) cmn.IuniVlanConfigFsm { |
| Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 5147 | dh.lockVlanConfig.RLock() |
| 5148 | value := dh.UniVlanConfigFsmMap[uniID] |
| 5149 | dh.lockVlanConfig.RUnlock() |
| 5150 | return value |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5151 | } |
| 5152 | |
| 5153 | // GetOnuAlarmManager - TODO: add comment |
| 5154 | func (dh *deviceHandler) GetOnuAlarmManager() cmn.IonuAlarmManager { |
| 5155 | return dh.pAlarmMgr |
| 5156 | } |
| 5157 | |
| 5158 | // GetOnuMetricsManager - TODO: add comment |
| 5159 | func (dh *deviceHandler) GetOnuMetricsManager() cmn.IonuMetricsManager { |
| 5160 | return dh.pOnuMetricsMgr |
| 5161 | } |
| 5162 | |
| 5163 | // GetOnuTP - TODO: add comment |
| 5164 | func (dh *deviceHandler) GetOnuTP() cmn.IonuUniTechProf { |
| 5165 | return dh.pOnuTP |
| 5166 | } |
| 5167 | |
| 5168 | // GetBackendPathPrefix - TODO: add comment |
| 5169 | func (dh *deviceHandler) GetBackendPathPrefix() string { |
| 5170 | return dh.pOpenOnuAc.cm.Backend.PathPrefix |
| 5171 | } |
| 5172 | |
| 5173 | // GetOnuIndication - TODO: add comment |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 5174 | func (dh *deviceHandler) GetOnuIndication() *oop.OnuIndication { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5175 | return dh.pOnuIndication |
| 5176 | } |
| 5177 | |
| 5178 | // RLockMutexDeletionInProgressFlag - TODO: add comment |
| 5179 | func (dh *deviceHandler) RLockMutexDeletionInProgressFlag() { |
| 5180 | dh.mutexDeletionInProgressFlag.RLock() |
| 5181 | } |
| 5182 | |
| 5183 | // RUnlockMutexDeletionInProgressFlag - TODO: add comment |
| 5184 | func (dh *deviceHandler) RUnlockMutexDeletionInProgressFlag() { |
| 5185 | dh.mutexDeletionInProgressFlag.RUnlock() |
| 5186 | } |
| 5187 | |
| 5188 | // GetDeletionInProgress - TODO: add comment |
| 5189 | func (dh *deviceHandler) GetDeletionInProgress() bool { |
| 5190 | return dh.deletionInProgress |
| 5191 | } |
| 5192 | |
| 5193 | // GetPmConfigs - TODO: add comment |
| 5194 | func (dh *deviceHandler) GetPmConfigs() *voltha.PmConfigs { |
| 5195 | return dh.pmConfigs |
| 5196 | } |
| 5197 | |
| 5198 | // GetDeviceType - TODO: add comment |
| 5199 | func (dh *deviceHandler) GetDeviceType() string { |
| 5200 | return dh.DeviceType |
| 5201 | } |
| 5202 | |
| 5203 | // GetLogicalDeviceID - TODO: add comment |
| 5204 | func (dh *deviceHandler) GetLogicalDeviceID() string { |
| 5205 | return dh.logicalDeviceID |
| 5206 | } |
| 5207 | |
| 5208 | // GetDevice - TODO: add comment |
| 5209 | func (dh *deviceHandler) GetDevice() *voltha.Device { |
| 5210 | return dh.device |
| 5211 | } |
| 5212 | |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 5213 | func (dh *deviceHandler) setOltAvailable(value bool) { |
| 5214 | dh.mutexOltAvailable.Lock() |
| 5215 | dh.oltAvailable = value |
| 5216 | dh.mutexOltAvailable.Unlock() |
| 5217 | } |
| 5218 | |
| 5219 | // IsOltAvailable - TODO: add comment |
| 5220 | func (dh *deviceHandler) IsOltAvailable() bool { |
| 5221 | dh.mutexOltAvailable.RLock() |
| 5222 | defer dh.mutexOltAvailable.RUnlock() |
| 5223 | return dh.oltAvailable |
| 5224 | } |
| 5225 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5226 | // GetMetricsEnabled - TODO: add comment |
| 5227 | func (dh *deviceHandler) GetMetricsEnabled() bool { |
| 5228 | return dh.pOpenOnuAc.MetricsEnabled |
| 5229 | } |
| 5230 | |
| Holger Hildebrandt | c572e62 | 2022-06-22 09:19:17 +0000 | [diff] [blame] | 5231 | // GetExtendedOmciSupportEnabled - TODO: add comment |
| 5232 | func (dh *deviceHandler) GetExtendedOmciSupportEnabled() bool { |
| 5233 | return dh.pOpenOnuAc.ExtendedOmciSupportEnabled |
| 5234 | } |
| 5235 | |
| Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 5236 | // GetExtendedOmciSupportEnabled - TODO: add comment |
| 5237 | func (dh *deviceHandler) GetSkipOnuConfigEnabled() bool { |
| 5238 | return dh.pOpenOnuAc.skipOnuConfig |
| 5239 | } |
| 5240 | |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 5241 | func (dh *deviceHandler) GetDeviceTechProfOnReboot() bool { |
| 5242 | return dh.pOpenOnuAc.CheckDeviceTechProfOnReboot |
| 5243 | } |
| 5244 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5245 | // InitPmConfigs - TODO: add comment |
| 5246 | func (dh *deviceHandler) InitPmConfigs() { |
| 5247 | dh.pmConfigs = &voltha.PmConfigs{} |
| 5248 | } |
| 5249 | |
| 5250 | // GetUniPortMask - TODO: add comment |
| 5251 | func (dh *deviceHandler) GetUniPortMask() int { |
| 5252 | return dh.pOpenOnuAc.config.UniPortMask |
| 5253 | } |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 5254 | |
| 5255 | func (dh *deviceHandler) anyTpPathExists(aTpPathMap map[uint8]string) bool { |
| 5256 | tpPathFound := false |
| 5257 | for _, tpPath := range aTpPathMap { |
| 5258 | if tpPath != "" { |
| 5259 | tpPathFound = true |
| 5260 | } |
| 5261 | } |
| 5262 | return tpPathFound |
| 5263 | } |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5264 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 5265 | func (dh *deviceHandler) getOnuActiveAlarms(ctx context.Context) *extension.SingleGetValueResponse { |
| 5266 | resp := dh.GetOnuAlarmManager().GetOnuActiveAlarms(ctx) |
| 5267 | logger.Debugw(ctx, "Received response from AlarmManager for Active Alarms for DeviceEntry", log.Fields{"device-id": dh.DeviceID}) |
| 5268 | return resp |
| 5269 | } |
| 5270 | |
| Akash Reddy Kankanala | c28f0e2 | 2025-06-16 11:00:55 +0530 | [diff] [blame] | 5271 | // getONUGEMStatsInfo - Get the GEM PM history data of the request ONT device |
| 5272 | func (dh *deviceHandler) getONUGEMStatsInfo(ctx context.Context) *extension.SingleGetValueResponse { |
| 5273 | resp := dh.pOnuMetricsMgr.GetONUGEMCounters(ctx) |
| pnalmas | 6d6b7d7 | 2025-10-23 16:34:22 +0530 | [diff] [blame] | 5274 | logger.Debugw(ctx, "Received response from ONU Metrics Manager for GEM Stats", log.Fields{"device-id": dh.DeviceID}) |
| 5275 | return resp |
| 5276 | } |
| 5277 | |
| 5278 | // getOnuFECStats - Get the GEM PM history data of the request ONT device |
| 5279 | func (dh *deviceHandler) getOnuFECStats(ctx context.Context) *extension.SingleGetValueResponse { |
| 5280 | resp := dh.pOnuMetricsMgr.GetONUFECCounters(ctx) |
| 5281 | logger.Debugw(ctx, "Received response from ONU Metrics Manager for FEC Stats", log.Fields{"device-id": dh.DeviceID}) |
| Akash Reddy Kankanala | c28f0e2 | 2025-06-16 11:00:55 +0530 | [diff] [blame] | 5282 | return resp |
| 5283 | } |
| 5284 | |
| Praneeth Kumar Nalmas | aacc612 | 2024-04-09 22:55:49 +0530 | [diff] [blame] | 5285 | func (dh *deviceHandler) GetDeviceDeleteCommChan(ctx context.Context) chan bool { |
| 5286 | return dh.deviceDeleteCommChan |
| 5287 | } |
| 5288 | |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5289 | // PrepareForGarbageCollection - remove references to prepare for garbage collection |
| 5290 | func (dh *deviceHandler) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) { |
| 5291 | logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID}) |
| 5292 | |
| 5293 | // Note: This function must be called as a goroutine to prevent blocking of further processing! |
| 5294 | // first let the objects rest for some time to give all asynchronously started |
| 5295 | // cleanup routines a chance to come to an end |
| Holger Hildebrandt | 12609a1 | 2022-03-25 13:23:25 +0000 | [diff] [blame] | 5296 | time.Sleep(2 * time.Second) |
| 5297 | |
| Holger Hildebrandt | 12609a1 | 2022-03-25 13:23:25 +0000 | [diff] [blame] | 5298 | time.Sleep(3 * time.Second) |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5299 | |
| 5300 | if dh.pOnuTP != nil { |
| 5301 | dh.pOnuTP.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5302 | } |
| 5303 | if dh.pOnuMetricsMgr != nil { |
| Holger Hildebrandt | 34f13b2 | 2023-01-18 15:14:59 +0000 | [diff] [blame] | 5304 | logger.Debugw(ctx, "preparation of garbage collection is done under control of pm fsm - wait for completion", |
| 5305 | log.Fields{"device-id": aDeviceID}) |
| Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 5306 | select { |
| 5307 | case <-dh.pOnuMetricsMgr.GarbageCollectionComplete: |
| 5308 | logger.Debugw(ctx, "pm fsm shut down and garbage collection complete", log.Fields{"deviceID": aDeviceID}) |
| 5309 | case <-time.After(pmmgr.MaxTimeForPmFsmShutDown * time.Second): |
| 5310 | logger.Errorw(ctx, "fsm did not shut down in time", log.Fields{"deviceID": aDeviceID}) |
| Holger Hildebrandt | 34f13b2 | 2023-01-18 15:14:59 +0000 | [diff] [blame] | 5311 | default: |
| Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 5312 | } |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5313 | } |
| 5314 | if dh.pAlarmMgr != nil { |
| 5315 | dh.pAlarmMgr.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5316 | } |
| 5317 | if dh.pSelfTestHdlr != nil { |
| 5318 | dh.pSelfTestHdlr.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5319 | } |
| 5320 | if dh.pLockStateFsm != nil { |
| 5321 | dh.pLockStateFsm.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5322 | } |
| 5323 | if dh.pUnlockStateFsm != nil { |
| 5324 | dh.pUnlockStateFsm.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5325 | } |
| 5326 | if dh.pOnuUpradeFsm != nil { |
| 5327 | dh.pOnuUpradeFsm.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5328 | } |
| 5329 | if dh.pOnuOmciDevice != nil { |
| 5330 | dh.pOnuOmciDevice.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5331 | } |
| 5332 | for k, v := range dh.UniVlanConfigFsmMap { |
| 5333 | v.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5334 | delete(dh.UniVlanConfigFsmMap, k) |
| 5335 | } |
| nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 5336 | dh.pOnuIndication = nil |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5337 | dh.pOnuOmciDevice = nil |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 5338 | dh.lockDevice.Lock() |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5339 | dh.pOnuTP = nil |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 5340 | dh.lockDevice.Unlock() |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5341 | dh.pOnuMetricsMgr = nil |
| 5342 | dh.pAlarmMgr = nil |
| 5343 | dh.pSelfTestHdlr = nil |
| 5344 | dh.pLockStateFsm = nil |
| 5345 | dh.pUnlockStateFsm = nil |
| 5346 | dh.pOnuUpradeFsm = nil |
| 5347 | } |