| 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 | */ |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 371 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 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 { |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 374 | logger.Debugw(ctx, "pDevEntry.PDevOmciCC is not nil", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 375 | return pDevEntry.PDevOmciCC.ReceiveMessage(log.WithSpanFromContext(context.TODO(), ctx), msg.Message) |
| Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 376 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 377 | logger.Debugw(ctx, "omciCC not ready to receive omci messages - incoming omci message ignored", log.Fields{"device-id": dh.DeviceID, |
| 378 | "rxMsg": msg.Message}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 379 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 380 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 381 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 382 | } |
| 383 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 384 | func (dh *deviceHandler) handleTechProfileDownloadRequest(ctx context.Context, techProfMsg *ia.TechProfileDownloadMessage) error { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 385 | 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] | 386 | |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 387 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 388 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 389 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 390 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 391 | } |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 392 | dh.lockDevice.RLock() |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 393 | if dh.pOnuTP == nil { |
| 394 | //should normally not happen ... |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 395 | 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] | 396 | log.Fields{"device-id": dh.DeviceID}) |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 397 | dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 398 | 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] | 399 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 400 | if !dh.IsReadyForOmciConfig() { |
| 401 | logger.Errorw(ctx, "TechProf-set rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 402 | "device-state": dh.GetDeviceReasonString()}) |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 403 | dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 404 | 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] | 405 | } |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 406 | //previous state test here was just this one, now extended for more states to reject the SetRequest: |
| 407 | // at least 'mib-downloaded' should be reached for processing of this specific ONU configuration |
| 408 | // if (dh.deviceReason == "stopping-openomci") || (dh.deviceReason == "omci-admin-lock") |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 409 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 410 | // 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] | 411 | // even to fast subsequent calls of the same messageType as well as OnuKVStore processing due |
| 412 | // to possible concurrent access by flow processing |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 413 | dh.pOnuTP.LockTpProcMutex() |
| 414 | defer dh.pOnuTP.UnlockTpProcMutex() |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 415 | defer dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 416 | |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 417 | if techProfMsg.UniId >= platform.MaxUnisPerOnu { |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 418 | return fmt.Errorf("received UniId value exceeds range: %d, device-id: %s", |
| 419 | techProfMsg.UniId, dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 420 | } |
| 421 | uniID := uint8(techProfMsg.UniId) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 422 | tpID, err := cmn.GetTpIDFromTpPath(techProfMsg.TpInstancePath) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 423 | if err != nil { |
| Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 424 | logger.Errorw(ctx, "error-parsing-tpid-from-tppath", |
| 425 | log.Fields{"device-id": dh.DeviceID, "err": err, "tp-path": techProfMsg.TpInstancePath}) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 426 | return err |
| 427 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 428 | logger.Debugw(ctx, "unmarshal-techprof-msg-body", log.Fields{"device-id": dh.DeviceID, |
| 429 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 430 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 431 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, uint8(tpID), techProfMsg.TpInstancePath); bTpModify { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 432 | |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 433 | switch tpInst := techProfMsg.TechTpInstance.(type) { |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 434 | case *ia.TechProfileDownloadMessage_TpInstance: |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 435 | logger.Debugw(ctx, "onu-uni-tp-path-modified", log.Fields{"device-id": dh.DeviceID, |
| 436 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 437 | |
| 438 | err = dh.CheckAvailableOnuCapabilities(ctx, pDevEntry, *tpInst.TpInstance) |
| 439 | if err != nil { |
| 440 | logger.Errorw(ctx, "error-checking-available-onu-capabilities-stopping-device", |
| 441 | log.Fields{"device-id": dh.DeviceID, "err": err, "tp-path": techProfMsg.TpInstancePath}) |
| 442 | // stopping all further processing |
| 443 | _ = dh.UpdateInterface(ctx) |
| 444 | return err |
| 445 | } |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 446 | // if there has been some change for some uni TechProfilePath |
| 447 | //in order to allow concurrent calls to other dh instances we do not wait for execution here |
| 448 | //but doing so we can not indicate problems to the caller (who does what with that then?) |
| 449 | //by now we just assume straightforward successful execution |
| 450 | //TODO!!! Generally: In this scheme it would be good to have some means to indicate |
| 451 | // possible problems to the caller later autonomously |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 452 | |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 453 | // deadline context to ensure completion of background routines waited for |
| 454 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 455 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 456 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 457 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 458 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 459 | |
| 460 | var wg sync.WaitGroup |
| 461 | wg.Add(1) // for the 1 go routine to finish |
| 462 | // 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] | 463 | 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] | 464 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfDwld") //wait for background process to finish |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 465 | if tpErr := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); tpErr != nil { |
| 466 | 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] | 467 | return tpErr |
| 468 | } |
| 469 | deadline = time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 470 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 471 | defer cancel2() |
| 472 | err1 := pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx)) |
| 473 | if err1 != nil { |
| 474 | logger.Errorf(ctx, "UpdateOnuKvStore-failed", log.Fields{"device-id": dh.DeviceID, "error": err1}) |
| 475 | return err |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 476 | } |
| 477 | return nil |
| 478 | default: |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 479 | 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] | 480 | return fmt.Errorf("unsupported-tp-instance-type--tp-id-%v", techProfMsg.TpInstancePath) |
| Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 481 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 482 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 483 | // no change, nothing really to do - return success |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 484 | logger.Debugw(ctx, "onu-uni-tp-path-not-modified", log.Fields{"device-id": dh.DeviceID, |
| 485 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 486 | return nil |
| 487 | } |
| 488 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 489 | func (dh *deviceHandler) handleDeleteGemPortRequest(ctx context.Context, delGemPortMsg *ia.DeleteGemPortMessage) error { |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 490 | 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] | 491 | |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 492 | dh.lockDevice.RLock() |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 493 | if dh.pOnuTP == nil { |
| 494 | //should normally not happen ... |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 495 | 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] | 496 | log.Fields{"device-id": dh.DeviceID}) |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 497 | dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 498 | 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] | 499 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 500 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 501 | dh.pOnuTP.LockTpProcMutex() |
| 502 | defer dh.pOnuTP.UnlockTpProcMutex() |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 503 | defer dh.lockDevice.RUnlock() |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 504 | |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 505 | if delGemPortMsg.UniId >= platform.MaxUnisPerOnu { |
| 506 | logger.Errorw(ctx, "delete-gem-port UniId exceeds range", log.Fields{ |
| 507 | "device-id": dh.DeviceID, "uni-id": delGemPortMsg.UniId}) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 508 | return fmt.Errorf("received UniId value exceeds range: %d, device-id: %s", |
| 509 | delGemPortMsg.UniId, dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 510 | } |
| 511 | uniID := uint8(delGemPortMsg.UniId) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 512 | tpID, err := cmn.GetTpIDFromTpPath(delGemPortMsg.TpInstancePath) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 513 | if err != nil { |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 514 | logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{ |
| 515 | "device-id": dh.DeviceID, "err": err, "tp-path": delGemPortMsg.TpInstancePath}) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 516 | return err |
| 517 | } |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 518 | logger.Infow(ctx, "delete-gem-port-request", log.Fields{ |
| 519 | "device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "gem": delGemPortMsg.GemPortId}) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 520 | //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] | 521 | |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 522 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delGemPortMsg.TpInstancePath, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 523 | avcfg.CResourceGemPort, delGemPortMsg.GemPortId) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 524 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 525 | } |
| 526 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 527 | func (dh *deviceHandler) handleDeleteTcontRequest(ctx context.Context, delTcontMsg *ia.DeleteTcontMessage) error { |
| Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 528 | 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] | 529 | |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 530 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 531 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 532 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 533 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 534 | } |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 535 | dh.lockDevice.RLock() |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 536 | if dh.pOnuTP == nil { |
| 537 | //should normally not happen ... |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 538 | 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] | 539 | log.Fields{"device-id": dh.DeviceID}) |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 540 | dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 541 | 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] | 542 | } |
| 543 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 544 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 545 | dh.pOnuTP.LockTpProcMutex() |
| 546 | defer dh.pOnuTP.UnlockTpProcMutex() |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 547 | defer dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 548 | |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 549 | if delTcontMsg.UniId >= platform.MaxUnisPerOnu { |
| 550 | logger.Errorw(ctx, "delete-tcont UniId exceeds range", log.Fields{ |
| 551 | "device-id": dh.DeviceID, "uni-id": delTcontMsg.UniId}) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 552 | return fmt.Errorf("received UniId value exceeds range: %d, device-id: %s", |
| 553 | delTcontMsg.UniId, dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 554 | } |
| 555 | uniID := uint8(delTcontMsg.UniId) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 556 | tpPath := delTcontMsg.TpInstancePath |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 557 | tpID, err := cmn.GetTpIDFromTpPath(tpPath) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 558 | if err != nil { |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 559 | logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{ |
| 560 | "device-id": dh.DeviceID, "err": err, "tp-path": tpPath}) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 561 | return err |
| 562 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 563 | pDevEntry.FreeTcont(ctx, uint16(delTcontMsg.AllocId)) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 564 | |
| Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 565 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 566 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 567 | defer cancel() |
| Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 568 | 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] | 569 | err1 := pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx)) |
| 570 | if err1 != nil { |
| 571 | logger.Errorw(ctx, "UpdateOnuKvStore-failed", log.Fields{"device-id": dh.DeviceID, "err": err1}) |
| 572 | return err1 |
| Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 575 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delTcontMsg.TpInstancePath, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 576 | avcfg.CResourceTcont, delTcontMsg.AllocId) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 577 | |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 578 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 579 | |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 580 | func (dh *deviceHandler) deleteTechProfileResource(ctx context.Context, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 581 | uniID uint8, tpID uint8, pathString string, resource avcfg.ResourceEntry, entryID uint32) error { |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 582 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 583 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 584 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 585 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 586 | } |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 587 | var resourceName string |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 588 | if avcfg.CResourceGemPort == resource { |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 589 | resourceName = "Gem" |
| 590 | } else { |
| 591 | resourceName = "Tcont" |
| 592 | } |
| 593 | |
| 594 | // deadline context to ensure completion of background routines waited for |
| 595 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 596 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 597 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 598 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 599 | |
| 600 | var wg sync.WaitGroup |
| 601 | wg.Add(1) // for the 1 go routine to finish |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 602 | go dh.pOnuTP.DeleteTpResource(log.WithSpanFromContext(dctx, ctx), uniID, tpID, pathString, |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 603 | resource, entryID, &wg) |
| 604 | 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] | 605 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); err != nil { |
| 606 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 607 | return err |
| 608 | } |
| 609 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 610 | if dh.pOnuTP.IsTechProfileConfigCleared(ctx, uniID, tpID) { |
| 611 | logger.Debugw(ctx, "techProfile-config-cleared", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID}) |
| 612 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, tpID, ""); bTpModify { |
| 613 | pDevEntry.ResetKvProcessingErrorIndication() |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 614 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 615 | defer cancel2() |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 616 | // 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] | 617 | 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] | 618 | err := pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx)) |
| 619 | if err != nil { |
| 620 | 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] | 621 | return err |
| 622 | } |
| 623 | } |
| 624 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 625 | 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] | 626 | "uni-id": uniID, "tpID": tpID, "resource-type": resourceName, "resource-id": entryID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 627 | return nil |
| 628 | } |
| 629 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 630 | // FlowUpdateIncremental removes and/or adds the flow changes on a given device |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 631 | func (dh *deviceHandler) FlowUpdateIncremental(ctx context.Context, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 632 | apOfFlowChanges *of.FlowChanges, |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 633 | apOfGroupChanges *of.FlowGroupChanges, apFlowMetaData *of.FlowMetadata) error { |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 634 | logger.Debugw(ctx, "FlowUpdateIncremental started", log.Fields{"device-id": dh.DeviceID, "flow": apOfFlowChanges, "metadata": apFlowMetaData}) |
| 635 | var errorsList []error |
| 636 | var retError error |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 637 | if dh.GetPersRebootFlag(ctx) { |
| bseeniva | bc19dec | 2026-02-04 11:56:23 +0530 | [diff] [blame] | 638 | logger.Warnw(ctx, "FlowUpdateIncremental ignored as device is being configured post reboot", log.Fields{"device-id": dh.DeviceID}) |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 639 | return fmt.Errorf("errors-installing-one-or-more-flows-groups-reboot-in-progress") |
| 640 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 641 | //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] | 642 | if apOfFlowChanges.ToRemove != nil { |
| 643 | for _, flowItem := range apOfFlowChanges.ToRemove.Items { |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 644 | if flowItem.GetCookie() == 0 { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 645 | 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] | 646 | "device-id": dh.DeviceID}) |
| 647 | retError = fmt.Errorf("flow-remove no cookie, device-id %s", dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 648 | errorsList = append(errorsList, retError) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 649 | continue |
| 650 | } |
| 651 | flowInPort := flow.GetInPort(flowItem) |
| 652 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 653 | logger.Warnw(ctx, "flow-remove inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 654 | retError = fmt.Errorf("flow-remove inPort invalid, device-id %s", dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 655 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 656 | continue |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 657 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 658 | } else if flowInPort == dh.ponPortNumber { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 659 | //this is some downstream flow, not regarded as error, just ignored |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 660 | 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] | 661 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 662 | continue |
| 663 | } else { |
| 664 | // this is the relevant upstream flow |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 665 | var loUniPort *cmn.OnuUniPort |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 666 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 667 | loUniPort = uniPort |
| 668 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 669 | 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] | 670 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 671 | 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] | 672 | flowInPort, dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 673 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 674 | continue |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 675 | } |
| 676 | flowOutPort := flow.GetOutPort(flowItem) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 677 | logger.Debugw(ctx, "flow-remove port indications", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 678 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 679 | "uniPortName": loUniPort.Name}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 680 | |
| 681 | if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) { |
| 682 | // Step1 : Fill flowControlBlock |
| 683 | // Step2 : Push the flowControlBlock to ONU channel |
| 684 | // Step3 : Wait on response channel for response |
| 685 | // Step4 : Return error value |
| 686 | startTime := time.Now() |
| 687 | respChan := make(chan error) |
| 688 | flowCb := FlowCb{ |
| 689 | ctx: ctx, |
| 690 | addFlow: false, |
| 691 | flowItem: flowItem, |
| 692 | flowMetaData: nil, |
| 693 | uniPort: loUniPort, |
| 694 | respChan: &respChan, |
| 695 | } |
| 696 | dh.flowCbChan[loUniPort.UniID] <- flowCb |
| 697 | logger.Infow(ctx, "process-flow-remove-start", log.Fields{"device-id": dh.DeviceID}) |
| 698 | // Wait on the channel for flow handlers return value |
| 699 | retError = <-respChan |
| 700 | logger.Infow(ctx, "process-flow-remove-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| 701 | if retError != nil { |
| 702 | logger.Warnw(ctx, "flow-delete processing error: continuing on checking further flows", |
| 703 | log.Fields{"device-id": dh.DeviceID, "error": retError}) |
| 704 | errorsList = append(errorsList, retError) |
| 705 | continue |
| 706 | } |
| 707 | } else { |
| 708 | retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID) |
| 709 | errorsList = append(errorsList, retError) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | } |
| 713 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 714 | if apOfFlowChanges.ToAdd != nil { |
| 715 | for _, flowItem := range apOfFlowChanges.ToAdd.Items { |
| 716 | if flowItem.GetCookie() == 0 { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 717 | 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] | 718 | "device-id": dh.DeviceID}) |
| 719 | retError = fmt.Errorf("flow-add no cookie, device-id %s", dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 720 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 721 | continue |
| 722 | } |
| 723 | flowInPort := flow.GetInPort(flowItem) |
| 724 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 725 | logger.Warnw(ctx, "flow-add inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 726 | retError = fmt.Errorf("flow-add inPort invalid, device-id %s", dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 727 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 728 | continue |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 729 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 730 | } else if flowInPort == dh.ponPortNumber { |
| 731 | //this is some downstream flow |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 732 | 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] | 733 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 734 | continue |
| 735 | } else { |
| 736 | // this is the relevant upstream flow |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 737 | var loUniPort *cmn.OnuUniPort |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 738 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 739 | loUniPort = uniPort |
| 740 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 741 | 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] | 742 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 743 | 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] | 744 | flowInPort, dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 745 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 746 | continue |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 747 | } |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 748 | // let's still assume that we receive the flow-add only in some 'active' device state (as so far observed) |
| 749 | // if not, we just throw some error here to have an indication about that, if we really need to support that |
| 750 | // then we would need to create some means to activate the internal stored flows |
| 751 | // after the device gets active automatically (and still with its dependency to the TechProfile) |
| 752 | // for state checking compare also code here: processInterAdapterTechProfileDownloadReqMessage |
| 753 | // also abort for the other still possible flows here |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 754 | if !dh.IsReadyForOmciConfig() { |
| 755 | logger.Errorw(ctx, "flow-add rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 756 | "last device-reason": dh.GetDeviceReasonString()}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 757 | retError = fmt.Errorf("improper device state on device %s", dh.DeviceID) |
| 758 | errorsList = append(errorsList, retError) |
| 759 | continue |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 762 | flowOutPort := flow.GetOutPort(flowItem) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 763 | logger.Debugw(ctx, "flow-add port indications", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 764 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 765 | "uniPortName": loUniPort.Name}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 766 | if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) { |
| 767 | // Step1 : Fill flowControlBlock |
| 768 | // Step2 : Push the flowControlBlock to ONU channel |
| 769 | // Step3 : Wait on response channel for response |
| 770 | // Step4 : Return error value |
| 771 | startTime := time.Now() |
| 772 | respChan := make(chan error) |
| 773 | flowCb := FlowCb{ |
| 774 | ctx: ctx, |
| 775 | addFlow: true, |
| 776 | flowItem: flowItem, |
| 777 | flowMetaData: apFlowMetaData, |
| 778 | uniPort: loUniPort, |
| 779 | respChan: &respChan, |
| 780 | } |
| 781 | dh.flowCbChan[loUniPort.UniID] <- flowCb |
| 782 | logger.Infow(ctx, "process-flow-add-start", log.Fields{"device-id": dh.DeviceID}) |
| 783 | // Wait on the channel for flow handlers return value |
| 784 | retError = <-respChan |
| 785 | logger.Infow(ctx, "process-flow-add-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| 786 | if retError != nil { |
| 787 | logger.Warnw(ctx, "flow-add processing error: continuing on checking further flows", |
| 788 | log.Fields{"device-id": dh.DeviceID, "error": retError}) |
| 789 | errorsList = append(errorsList, retError) |
| 790 | continue |
| 791 | } |
| 792 | } else { |
| 793 | retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID) |
| 794 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | } |
| 798 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 799 | if len(errorsList) > 0 { |
| 800 | logger.Errorw(ctx, "error-processing-flow", log.Fields{"device-id": dh.DeviceID, "errList": errorsList}) |
| 801 | return fmt.Errorf("errors-installing-one-or-more-flows-groups, errors:%v", errorsList) |
| 802 | } |
| 803 | return nil |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 806 | // disableDevice locks the ONU and its UNI/VEIP ports (admin lock via OMCI) |
| 807 | // following are the expected device states after this activity: |
| 808 | // 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] | 809 | // (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] | 810 | func (dh *deviceHandler) disableDevice(ctx context.Context, device *voltha.Device) { |
| 811 | 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] | 812 | dh.mutexForDisableDeviceRequested.Lock() |
| 813 | dh.disableDeviceRequested = true |
| 814 | dh.mutexForDisableDeviceRequested.Unlock() |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 815 | //admin-lock reason can also be used uniquely for setting the DeviceState accordingly |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 816 | //note that disableDevice sequences in some 'ONU active' state may yield also |
| 817 | // "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] | 818 | // - inblock state checking to prevent possibly unneeded processing (on command repitition) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 819 | if dh.getDeviceReason() != cmn.DrOmciAdminLock { |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 820 | //disable-device shall be just a UNi/ONU-G related admin state setting |
| 821 | //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] | 822 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 823 | if dh.IsReadyForOmciConfig() { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 824 | // disable UNI ports/ONU |
| 825 | // *** should generate UniDisableStateDone event - used to disable the port(s) on success |
| 826 | if dh.pLockStateFsm == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 827 | dh.createUniLockFsm(ctx, true, cmn.UniDisableStateDone) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 828 | } else { //LockStateFSM already init |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 829 | dh.pLockStateFsm.SetSuccessEvent(cmn.UniDisableStateDone) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 830 | dh.runUniLockFsm(ctx, true) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 831 | } |
| 832 | } else { |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 833 | logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 834 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID}) |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 835 | // disable device should have no impact on ConnStatus |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 836 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 837 | DeviceId: dh.DeviceID, |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 838 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 839 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 840 | }); err != nil { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 841 | //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] | 842 | 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] | 843 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 844 | // 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] | 845 | |
| 846 | //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] | 847 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciAdminLock, true) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 848 | } |
| ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 852 | // reEnableDevice unlocks the ONU and its UNI/VEIP ports (admin unlock via OMCI) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 853 | func (dh *deviceHandler) reEnableDevice(ctx context.Context, device *voltha.Device) { |
| 854 | 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] | 855 | |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 856 | //setting readyForOmciConfig here is just a workaround for BBSIM testing in the sequence |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 857 | // OnuSoftReboot-disable-enable, because BBSIM does not generate a new OnuIndication-Up event after SoftReboot |
| 858 | // which is the assumption for real ONU's, where the ready-state is then set according to the following MibUpload/Download |
| 859 | // for real ONU's that should have nearly no influence |
| 860 | // Note that for real ONU's there is anyway a problematic situation with following sequence: |
| 861 | // OnuIndication-Dw (or not active at all) (- disable) - enable: here already the LockFsm may run into timeout (no OmciResponse) |
| 862 | // but that anyway is hopefully resolved by some OnuIndication-Up event (maybe to be tested) |
| 863 | // 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] | 864 | dh.SetReadyForOmciConfig(true) //needed to allow subsequent flow/techProf config (on BBSIM) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 865 | |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 866 | // enable ONU/UNI ports |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 867 | // *** should generate cmn.UniEnableStateDone event - used to disable the port(s) on success |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 868 | dh.mutexForDisableDeviceRequested.Lock() |
| 869 | dh.disableDeviceRequested = false |
| 870 | dh.mutexForDisableDeviceRequested.Unlock() |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 871 | if dh.pUnlockStateFsm == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 872 | dh.createUniLockFsm(ctx, false, cmn.UniEnableStateDone) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 873 | } else { //UnlockStateFSM already init |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 874 | dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniEnableStateDone) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 875 | dh.runUniLockFsm(ctx, false) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 876 | } |
| ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 877 | } |
| 878 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 879 | func (dh *deviceHandler) reconcileDeviceOnuInd(ctx context.Context) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 880 | 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] | 881 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 882 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 883 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 884 | 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] | 885 | return |
| 886 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 887 | if err := pDevEntry.RestoreDataFromOnuKvStore(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 888 | if err == fmt.Errorf("no-ONU-data-found") { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 889 | 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] | 890 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 891 | 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] | 892 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 893 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 894 | return |
| Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 895 | } |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 896 | var onuIndication oop.OnuIndication |
| akashreddyk | b03dde0 | 2025-12-02 10:53:18 +0530 | [diff] [blame] | 897 | var rebootInProgress bool |
| 898 | var persUniUnlockDone bool |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 899 | pDevEntry.MutexPersOnuConfig.RLock() |
| 900 | onuIndication.IntfId = pDevEntry.SOnuPersistentData.PersIntfID |
| 901 | onuIndication.OnuId = pDevEntry.SOnuPersistentData.PersOnuID |
| 902 | onuIndication.OperState = pDevEntry.SOnuPersistentData.PersOperState |
| 903 | onuIndication.AdminState = pDevEntry.SOnuPersistentData.PersAdminState |
| akashreddyk | b03dde0 | 2025-12-02 10:53:18 +0530 | [diff] [blame] | 904 | rebootInProgress = pDevEntry.SOnuPersistentData.PersRebootInProgress |
| 905 | persUniUnlockDone = pDevEntry.SOnuPersistentData.PersUniUnlockDone |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 906 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| akashreddyk | b03dde0 | 2025-12-02 10:53:18 +0530 | [diff] [blame] | 907 | if rebootInProgress { |
| 908 | if persUniUnlockDone { |
| 909 | logger.Warnw(ctx, "ONU indication shows reboot in progress - cannot proceed with reconciliation", log.Fields{"device-id": dh.DeviceID}) |
| 910 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| 911 | return |
| 912 | } |
| 913 | } |
| 914 | if onuIndication.OperState == "up" { |
| 915 | if err := dh.createInterface(ctx, &onuIndication); err != nil { |
| 916 | logger.Errorw(ctx, "failed to handle device up indication", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| 917 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| 918 | return |
| 919 | } |
| 920 | } else { |
| 921 | logger.Warnw(ctx, "ONU indication does not have 'up' state, cannot proceed with reconciliation", log.Fields{"device-id": dh.DeviceID, "operState": onuIndication.OperState}) |
| 922 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| 923 | return |
| 924 | } |
| 925 | 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] | 926 | } |
| 927 | |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 928 | func (dh *deviceHandler) ReconcileDeviceTechProf(ctx context.Context) bool { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 929 | 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] | 930 | |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 931 | continueWithFlowConfig := false |
| 932 | |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 933 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 934 | if pDevEntry == nil { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 935 | 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] | 936 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| 937 | return continueWithFlowConfig |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 938 | } |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 939 | dh.lockDevice.RLock() |
| 940 | if dh.pOnuTP == nil { |
| 941 | //should normally not happen ... |
| 942 | logger.Warnw(ctx, "onuTechProf instance not set up for reconcile tech prof - ignoring request", |
| 943 | log.Fields{"device-id": dh.DeviceID}) |
| 944 | dh.lockDevice.RUnlock() |
| 945 | return continueWithFlowConfig |
| 946 | } |
| 947 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 948 | dh.pOnuTP.LockTpProcMutex() |
| 949 | defer dh.pOnuTP.UnlockTpProcMutex() |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 950 | defer dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 951 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 952 | pDevEntry.MutexPersOnuConfig.RLock() |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 953 | persMutexLock := true |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 954 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 955 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 956 | 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] | 957 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 958 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| 959 | return continueWithFlowConfig |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 960 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 961 | flowsFound := false |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 962 | techProfsFound := false |
| 963 | techProfInstLoadFailed := false |
| 964 | outerLoop: |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 965 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 966 | uniID := uniData.PersUniID |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 967 | //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] | 968 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 969 | logger.Debugw(ctx, "reconciling - no TPs stored for uniID", |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 970 | log.Fields{"uni-id": uniID, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 971 | continue |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 972 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 973 | //release MutexPersOnuConfig before TechProfile (ANIConfig) processing as otherwise the reception of |
| 974 | // 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] | 975 | // 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] | 976 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 977 | persMutexLock = false |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 978 | 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] | 979 | var iaTechTpInst ia.TechProfileDownloadMessage |
| 980 | var ok bool |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 981 | for tpID := range uniData.PersTpPathMap { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 982 | pDevEntry.MutexReconciledTpInstances.RLock() |
| 983 | if iaTechTpInst, ok = pDevEntry.ReconciledTpInstances[uniID][tpID]; !ok { |
| 984 | logger.Errorw(ctx, "reconciling - no reconciled tp instance available", |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 985 | 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] | 986 | "device-id": dh.DeviceID}) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 987 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 988 | pDevEntry.MutexReconciledTpInstances.RUnlock() |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 989 | break outerLoop |
| 990 | } |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 991 | pDevEntry.MutexReconciledTpInstances.RUnlock() |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 992 | continueWithFlowConfig = true // valid TP found - try flow configuration later |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 993 | var tpInst tech_profile.TechProfileInstance |
| 994 | switch techTpInst := iaTechTpInst.TechTpInstance.(type) { |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 995 | case *ia.TechProfileDownloadMessage_TpInstance: // supports only GPON, XGPON, XGS-PON |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 996 | tpInst = *techTpInst.TpInstance |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 997 | logger.Debugw(ctx, "reconciling - received-tp-instance-successfully-after-reconcile", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 998 | "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] | 999 | default: // do not support epon or other tech |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1000 | logger.Errorw(ctx, "reconciling - unsupported-tech-profile", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1001 | "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] | 1002 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 1003 | break outerLoop |
| 1004 | } |
| 1005 | |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 1006 | // deadline context to ensure completion of background routines waited for |
| 1007 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 1008 | 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] | 1009 | dctx, cancel := context.WithDeadline(ctx, deadline) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1010 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1011 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniData.PersUniID, tpID) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 1012 | var wg sync.WaitGroup |
| 1013 | wg.Add(1) // for the 1 go routine to finish |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1014 | 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] | 1015 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfReconcile") //wait for background process to finish |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1016 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniData.PersUniID, tpID); err != nil { |
| 1017 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 1018 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 1019 | break outerLoop |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 1020 | } |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1021 | } // for all TpPath entries for this UNI |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1022 | if len(uniData.PersFlowParams) != 0 { |
| 1023 | flowsFound = true |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1024 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1025 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1026 | persMutexLock = true |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1027 | } // for all UNI entries from SOnuPersistentData |
| 1028 | if persMutexLock { // if loop was left with MutexPersOnuConfig still set |
| 1029 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1030 | } |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1031 | |
| 1032 | //had to move techProf/flow result evaluation into separate function due to SCA complexity limit |
| 1033 | dh.updateReconcileStates(ctx, techProfsFound, techProfInstLoadFailed, flowsFound) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1034 | |
| 1035 | return continueWithFlowConfig |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | func (dh *deviceHandler) updateReconcileStates(ctx context.Context, |
| 1039 | abTechProfsFound bool, abTechProfInstLoadFailed bool, abFlowsFound bool) { |
| 1040 | if !abTechProfsFound { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1041 | 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] | 1042 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1043 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1044 | return |
| 1045 | } |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1046 | if abTechProfInstLoadFailed { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1047 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadFailed, dh.IsReconcilingReasonUpdate()) |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1048 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 1049 | return |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1050 | } else if dh.IsSkipOnuConfigReconciling() { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1051 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, dh.IsReconcilingReasonUpdate()) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1052 | } |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1053 | if !abFlowsFound { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1054 | 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] | 1055 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1056 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1057 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1060 | func (dh *deviceHandler) ReconcileDeviceFlowConfig(ctx context.Context) { |
| 1061 | 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] | 1062 | |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 1063 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1064 | if pDevEntry == nil { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1065 | 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] | 1066 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1067 | return |
| 1068 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1069 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1070 | pDevEntry.MutexPersOnuConfig.RLock() |
| 1071 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 1072 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1073 | 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] | 1074 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1075 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1076 | return |
| 1077 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1078 | flowsFound := false |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1079 | var uniVlanConfigEntries []uint8 |
| 1080 | var loWaitGroupWTO cmn.WaitGroupWithTimeOut |
| 1081 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1082 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1083 | //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support |
| 1084 | if len(uniData.PersFlowParams) == 0 { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1085 | logger.Debugw(ctx, "reconciling - no flows stored for uniID", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1086 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1087 | continue |
| 1088 | } |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1089 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1090 | logger.Warnw(ctx, "reconciling flows - but no TPs stored for uniID, abort", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1091 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 1092 | // It doesn't make sense to configure any flows if no TPs are available |
| 1093 | continue |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1094 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1095 | //release MutexPersOnuConfig before VlanConfig processing as otherwise the reception of |
| 1096 | // 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] | 1097 | // 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] | 1098 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1099 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1100 | var uniPort *cmn.OnuUniPort |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1101 | var exist bool |
| Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 1102 | 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] | 1103 | if uniPort, exist = dh.uniEntityMap[uniNo]; !exist { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1104 | logger.Errorw(ctx, "reconciling - OnuUniPort data not found - terminate reconcilement", |
| 1105 | log.Fields{"uniNo": uniNo, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1106 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1107 | return |
| 1108 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1109 | //needed to split up function due to sca complexity |
| 1110 | dh.updateReconcileFlowConfig(ctx, uniPort, uniData.PersFlowParams, uniVlanConfigEntries, &loWaitGroupWTO, &flowsFound) |
| 1111 | |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1112 | logger.Debugw(ctx, "reconciling - flows processed", log.Fields{ |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1113 | "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1114 | "NumUniFlows": dh.UniVlanConfigFsmMap[uniData.PersUniID].NumUniFlows, |
| 1115 | "ConfiguredUniFlow": dh.UniVlanConfigFsmMap[uniData.PersUniID].ConfiguredUniFlow}) |
| Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 1116 | // this can't be used as global finished reconciling flag because |
| 1117 | // assumes is getting called before the state machines for the last flow is completed, |
| 1118 | // while this is not guaranteed. |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1119 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| 1120 | } // for all UNI entries from SOnuPersistentData |
| 1121 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1122 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1123 | if !flowsFound { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1124 | 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] | 1125 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1126 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1127 | return |
| 1128 | } |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1129 | logger.Debugw(ctx, "reconciling flows - waiting on ready indication of requested UNIs", log.Fields{ |
| 1130 | "device-id": dh.DeviceID, "expiry": dh.reconcileExpiryVlanConfig}) |
| 1131 | if executed := loWaitGroupWTO.WaitTimeout(dh.reconcileExpiryVlanConfig); executed { |
| 1132 | logger.Debugw(ctx, "reconciling flows for all UNI's has been finished in time", |
| 1133 | log.Fields{"device-id": dh.DeviceID}) |
| 1134 | dh.stopReconciling(ctx, true, cWaitReconcileFlowAbortOnSuccess) |
| 1135 | if pDevEntry != nil { |
| 1136 | pDevEntry.SendChReconcilingFlowsFinished(ctx, true) |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1137 | } |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1138 | } else { |
| 1139 | logger.Errorw(ctx, "reconciling - timeout waiting for reconciling flows for all UNI's to be finished!", |
| 1140 | log.Fields{"device-id": dh.DeviceID}) |
| 1141 | dh.stopReconciling(ctx, false, cWaitReconcileFlowAbortOnError) |
| 1142 | if pDevEntry != nil { |
| 1143 | pDevEntry.SendChReconcilingFlowsFinished(ctx, false) |
| 1144 | } |
| 1145 | return |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1146 | } |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1147 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsPushed, dh.IsReconcilingReasonUpdate()) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1150 | func (dh *deviceHandler) updateReconcileFlowConfig(ctx context.Context, apUniPort *cmn.OnuUniPort, |
| 1151 | aPersFlowParam []cmn.UniVlanFlowParams, aUniVlanConfigEntries []uint8, |
| 1152 | apWaitGroup *cmn.WaitGroupWithTimeOut, apFlowsFound *bool) { |
| 1153 | flowsProcessed := 0 |
| 1154 | lastFlowToReconcile := false |
| 1155 | loUniID := apUniPort.UniID |
| 1156 | for _, flowData := range aPersFlowParam { |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1157 | if !(*apFlowsFound) { |
| 1158 | *apFlowsFound = true |
| 1159 | syncChannel := make(chan struct{}) |
| 1160 | // start go routine with select() on reconciling vlan config channel before |
| 1161 | // starting vlan config reconciling process to prevent loss of any signal |
| 1162 | // this routine just collects all the received 'flow-reconciled' signals - possibly from different UNI's |
| 1163 | go dh.waitOnUniVlanConfigReconcilingReady(ctx, syncChannel, apWaitGroup) |
| 1164 | //block until the wait routine is really blocked on channel input |
| 1165 | // in order to prevent to early ready signal from VlanConfig processing |
| 1166 | <-syncChannel |
| 1167 | } |
| 1168 | if flowsProcessed == len(aPersFlowParam)-1 { |
| 1169 | var uniAdded bool |
| 1170 | lastFlowToReconcile = true |
| 1171 | if aUniVlanConfigEntries, uniAdded = dh.appendIfMissing(aUniVlanConfigEntries, loUniID); uniAdded { |
| 1172 | apWaitGroup.Add(1) //increment the waiting group |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1173 | } |
| 1174 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1175 | logger.Debugw(ctx, "reconciling - add flow with cookie slice", log.Fields{ |
| 1176 | "device-id": dh.DeviceID, "uni-id": loUniID, |
| 1177 | "flowsProcessed": flowsProcessed, "cookies": flowData.CookieSlice}) |
| 1178 | dh.lockVlanConfig.Lock() |
| 1179 | //the CookieSlice can be passed 'by value' here, - which internally passes its reference |
| 1180 | if _, exist := dh.UniVlanConfigFsmMap[loUniID]; exist { |
| 1181 | if err := dh.UniVlanConfigFsmMap[loUniID].SetUniFlowParams(ctx, flowData.VlanRuleParams.TpID, |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 1182 | 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] | 1183 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1184 | } |
| 1185 | } else { |
| 1186 | if err := dh.createVlanFilterFsm(ctx, apUniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice, |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 1187 | uint16(flowData.VlanRuleParams.MatchVid), uint8(flowData.VlanRuleParams.MatchPcp), uint16(flowData.VlanRuleParams.SetVid), |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 1188 | 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] | 1189 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1190 | } |
| 1191 | } |
| 1192 | dh.lockVlanConfig.Unlock() |
| 1193 | flowsProcessed++ |
| 1194 | } //for all flows of this UNI |
| 1195 | } |
| 1196 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1197 | // waitOnUniVlanConfigReconcilingReady collects all VlanConfigReady signals from VlanConfig FSM processing in reconciling |
| 1198 | // |
| 1199 | // and decrements the according handler wait group waiting for these indications |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1200 | func (dh *deviceHandler) waitOnUniVlanConfigReconcilingReady(ctx context.Context, aSyncChannel chan<- struct{}, |
| 1201 | waitGroup *cmn.WaitGroupWithTimeOut) { |
| 1202 | var reconciledUniVlanConfigEntries []uint8 |
| 1203 | var appended bool |
| 1204 | expiry := dh.GetReconcileExpiryVlanConfigAbort() |
| 1205 | logger.Debugw(ctx, "start waiting on reconcile vlanConfig ready indications", log.Fields{ |
| 1206 | "device-id": dh.DeviceID, "expiry": expiry}) |
| 1207 | // indicate blocking on channel now to the caller |
| 1208 | aSyncChannel <- struct{}{} |
| 1209 | for { |
| 1210 | select { |
| 1211 | case uniIndication := <-dh.chUniVlanConfigReconcilingDone: |
| 1212 | switch uniIndication { |
| 1213 | // no activity requested (should normally not be received) - just continue waiting |
| 1214 | case cWaitReconcileFlowNoActivity: |
| 1215 | // waiting on channel inputs from VlanConfig for all UNI's to be aborted on error condition |
| 1216 | case cWaitReconcileFlowAbortOnError: |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1217 | logger.Warn(ctx, "waitReconcileFlow aborted on error", |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1218 | log.Fields{"device-id": dh.DeviceID, "rxEntries": reconciledUniVlanConfigEntries}) |
| 1219 | return |
| 1220 | // waiting on channel inputs from VlanConfig for all UNI's to be aborted on success condition |
| 1221 | case cWaitReconcileFlowAbortOnSuccess: |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1222 | logger.Warn(ctx, "waitReconcileFlow aborted on success", |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1223 | log.Fields{"device-id": dh.DeviceID, "rxEntries": reconciledUniVlanConfigEntries}) |
| 1224 | return |
| 1225 | // this should be a valid UNI vlan config done indication |
| 1226 | default: |
| 1227 | if uniIndication < platform.MaxUnisPerOnu { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1228 | logger.Info(ctx, "reconciling flows has been finished in time for this UNI", |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1229 | log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| 1230 | if reconciledUniVlanConfigEntries, appended = |
| 1231 | dh.appendIfMissing(reconciledUniVlanConfigEntries, uint8(uniIndication)); appended { |
| 1232 | waitGroup.Done() |
| 1233 | } |
| 1234 | } else { |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 1235 | 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] | 1236 | } |
| 1237 | } //switch uniIndication |
| 1238 | |
| 1239 | case <-time.After(expiry): //a bit longer than reconcileExpiryVlanConfig |
| 1240 | logger.Errorw(ctx, "timeout waiting for reconciling all UNI flows to be finished!", |
| 1241 | log.Fields{"device-id": dh.DeviceID}) |
| 1242 | return |
| 1243 | } |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | func (dh *deviceHandler) GetReconcileExpiryVlanConfigAbort() time.Duration { |
| 1248 | return dh.reconcileExpiryVlanConfig + (500 * time.Millisecond) |
| 1249 | } |
| 1250 | |
| 1251 | func (dh *deviceHandler) appendIfMissing(slice []uint8, val uint8) ([]uint8, bool) { |
| 1252 | for _, ele := range slice { |
| 1253 | if ele == val { |
| 1254 | return slice, false |
| 1255 | } |
| 1256 | } |
| 1257 | return append(slice, val), true |
| 1258 | } |
| 1259 | |
| 1260 | // sendChReconcileFinished - sends true or false on reconcileFinish channel |
| 1261 | func (dh *deviceHandler) sendChReconcileFinished(success bool) { |
| 1262 | if dh != nil { //if the object still exists (might have been already deleted in background) |
| 1263 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1264 | select { |
| 1265 | case dh.chReconcilingFinished <- success: |
| 1266 | default: |
| 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | // SendChUniVlanConfigFinished - sends the Uni number on channel if the flow reconcilement for this UNI is finished |
| 1272 | func (dh *deviceHandler) SendChUniVlanConfigFinished(value uint16) { |
| 1273 | if dh != nil { //if the object still exists (might have been already deleted in background) |
| 1274 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1275 | select { |
| 1276 | case dh.chUniVlanConfigReconcilingDone <- value: |
| 1277 | default: |
| 1278 | } |
| 1279 | } |
| 1280 | } |
| 1281 | |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 1282 | func (dh *deviceHandler) DeviceFlowConfigOnReboot(ctx context.Context) { |
| 1283 | logger.Debugw(ctx, "rebooting - trigger flow config", log.Fields{"device-id": dh.DeviceID}) |
| 1284 | |
| 1285 | defer dh.UpdateAndStoreRebootState(ctx, false) |
| 1286 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 1287 | if pDevEntry == nil { |
| 1288 | logger.Errorw(ctx, "rebooting - no valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 1289 | return |
| 1290 | } |
| 1291 | |
| 1292 | pDevEntry.MutexPersOnuConfig.RLock() |
| 1293 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 1294 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1295 | logger.Warn(ctx, "rebooting - no uni-configs have been stored - aborting", |
| 1296 | log.Fields{"device-id": dh.DeviceID}) |
| 1297 | return |
| 1298 | } |
| 1299 | flowsFound := false |
| 1300 | var uniVlanConfigEntries []uint8 |
| 1301 | var loWaitGroupWTO cmn.WaitGroupWithTimeOut |
| 1302 | |
| 1303 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
| 1304 | //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support |
| 1305 | if len(uniData.PersFlowParams) == 0 { |
| 1306 | logger.Debugw(ctx, "rebooting - no flows stored for uniID", |
| 1307 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| 1308 | continue |
| 1309 | } |
| 1310 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
| 1311 | logger.Warnw(ctx, "rebooting - but no TPs stored for uniID, abort", |
| 1312 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| 1313 | // It doesn't make sense to configure any flows if no TPs are available |
| 1314 | continue |
| 1315 | } |
| 1316 | //release MutexPersOnuConfig before VlanConfig processing as otherwise the reception of |
| 1317 | // OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI |
| 1318 | // frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap |
| 1319 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1320 | |
| 1321 | var uniPort *cmn.OnuUniPort |
| 1322 | var exist bool |
| 1323 | uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), uint32(uniData.PersUniID)) |
| 1324 | if uniPort, exist = dh.uniEntityMap[uniNo]; !exist { |
| 1325 | logger.Errorw(ctx, "rebooting - OnuUniPort data not found - terminate flow config", |
| 1326 | log.Fields{"uniNo": uniNo, "device-id": dh.DeviceID}) |
| 1327 | return |
| 1328 | } |
| 1329 | |
| 1330 | dh.updateOnRebootFlowConfig(ctx, uniPort, uniData.PersFlowParams, uniVlanConfigEntries, &loWaitGroupWTO, &flowsFound) |
| 1331 | |
| 1332 | logger.Debugw(ctx, "rebooting - flows processed", log.Fields{ |
| 1333 | "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, |
| 1334 | "NumUniFlows": dh.UniVlanConfigFsmMap[uniData.PersUniID].NumUniFlows, |
| 1335 | "ConfiguredUniFlow": dh.UniVlanConfigFsmMap[uniData.PersUniID].ConfiguredUniFlow}) |
| 1336 | // this can't be used as global finished reconciling flag because |
| 1337 | // assumes is getting called before the state machines for the last flow is completed, |
| 1338 | // while this is not guaranteed. |
| 1339 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| 1340 | } // for all UNI entries from SOnuPersistentData |
| 1341 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1342 | |
| 1343 | if !flowsFound { |
| 1344 | logger.Warn(ctx, "rebooting - no flows have been stored before device reboot - terminate flow config", |
| 1345 | log.Fields{"device-id": dh.DeviceID}) |
| 1346 | return |
| 1347 | } |
| 1348 | logger.Debugw(ctx, "rebooting - waiting on ready indication of requested UNIs", log.Fields{ |
| 1349 | "device-id": dh.DeviceID, "expiry": dh.reconcileExpiryVlanConfig}) |
| 1350 | if executed := loWaitGroupWTO.WaitTimeout(dh.reconcileExpiryVlanConfig); executed { |
| 1351 | logger.Debugw(ctx, "rebooting - flow config for all UNI's has been finished in time", |
| 1352 | log.Fields{"device-id": dh.DeviceID}) |
| 1353 | } else { |
| 1354 | logger.Errorw(ctx, "rebooting - timeout waiting for flow config for all UNI's to be finished!", |
| 1355 | log.Fields{"device-id": dh.DeviceID}) |
| 1356 | return |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | func (dh *deviceHandler) UpdateAndStoreRebootState(ctx context.Context, flag bool) { |
| 1361 | dh.UpdateRebootPersData(ctx, flag) |
| 1362 | if err := dh.StorePersistentData(ctx); err != nil { |
| 1363 | logger.Errorw(ctx, "rebooting - failed to store persistent data in kv store", log.Fields{"device-id": dh.DeviceID}) |
| 1364 | } |
| 1365 | } |
| 1366 | |
| 1367 | func (dh *deviceHandler) updateOnRebootFlowConfig(ctx context.Context, apUniPort *cmn.OnuUniPort, |
| 1368 | aPersFlowParam []cmn.UniVlanFlowParams, aUniVlanConfigEntries []uint8, |
| 1369 | apWaitGroup *cmn.WaitGroupWithTimeOut, apFlowsFound *bool) { |
| 1370 | flowsProcessed := 0 |
| 1371 | lastFlowToConfigOnReboot := false |
| 1372 | loUniID := apUniPort.UniID |
| 1373 | for _, flowData := range aPersFlowParam { |
| 1374 | if !(*apFlowsFound) { |
| 1375 | *apFlowsFound = true |
| 1376 | syncChannel := make(chan struct{}) |
| 1377 | // start go routine with select() on reconciling vlan config channel before |
| 1378 | // starting vlan config reconciling process to prevent loss of any signal |
| 1379 | // this routine just collects all the received 'flow-reconciled' signals - possibly from different UNI's |
| 1380 | go dh.waitOnUniVlanConfigOnRebootReady(ctx, syncChannel, apWaitGroup) |
| 1381 | //block until the wait routine is really blocked on channel input |
| 1382 | // in order to prevent to early ready signal from VlanConfig processing |
| 1383 | <-syncChannel |
| 1384 | } |
| 1385 | if flowsProcessed == len(aPersFlowParam)-1 { |
| 1386 | var uniAdded bool |
| 1387 | lastFlowToConfigOnReboot = true |
| 1388 | if aUniVlanConfigEntries, uniAdded = dh.appendIfMissing(aUniVlanConfigEntries, loUniID); uniAdded { |
| 1389 | apWaitGroup.Add(1) //increment the waiting group |
| 1390 | } |
| 1391 | } |
| 1392 | logger.Debugw(ctx, "rebooting - add flow with cookie slice", log.Fields{ |
| 1393 | "device-id": dh.DeviceID, "uni-id": loUniID, |
| 1394 | "flowsProcessed": flowsProcessed, "cookies": flowData.CookieSlice}) |
| 1395 | dh.lockVlanConfig.Lock() |
| 1396 | //the CookieSlice can be passed 'by value' here, - which internally passes its reference |
| 1397 | if _, exist := dh.UniVlanConfigFsmMap[loUniID]; exist { |
| 1398 | if err := dh.UniVlanConfigFsmMap[loUniID].SetUniFlowParams(ctx, flowData.VlanRuleParams.TpID, |
| 1399 | 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 { |
| 1400 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1401 | } |
| 1402 | } else { |
| 1403 | if err := dh.createVlanFilterFsm(ctx, apUniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice, |
| 1404 | uint16(flowData.VlanRuleParams.MatchVid), uint8(flowData.VlanRuleParams.MatchPcp), uint16(flowData.VlanRuleParams.SetVid), |
| 1405 | uint8(flowData.VlanRuleParams.SetPcp), flowData.VlanRuleParams.InnerCvlan, cmn.OmciVlanFilterAddDone, false, lastFlowToConfigOnReboot, flowData.Meter, nil); err != nil { |
| 1406 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1407 | } |
| 1408 | } |
| 1409 | dh.lockVlanConfig.Unlock() |
| 1410 | flowsProcessed++ |
| 1411 | } //for all flows of this UNI |
| 1412 | } |
| 1413 | |
| 1414 | func (dh *deviceHandler) waitOnUniVlanConfigOnRebootReady(ctx context.Context, aSyncChannel chan<- struct{}, |
| 1415 | waitGroup *cmn.WaitGroupWithTimeOut) { |
| 1416 | var rebootUniVlanConfigEntries []uint8 |
| 1417 | var appended bool |
| 1418 | expiry := dh.GetReconcileExpiryVlanConfigAbort() |
| 1419 | logger.Debugw(ctx, "start waiting on vlanConfig ready indications on reboot", log.Fields{ |
| 1420 | "device-id": dh.DeviceID, "expiry": expiry}) |
| 1421 | // indicate blocking on channel now to the caller |
| 1422 | aSyncChannel <- struct{}{} |
| 1423 | for { |
| 1424 | select { |
| 1425 | case <-dh.deviceDeleteCommChan: |
| 1426 | // Cancel the context and return |
| 1427 | logger.Warnw(ctx, "Device Deletion invoked , stop further processing ", log.Fields{"device-id": dh.DeviceID}) |
| 1428 | return |
| 1429 | |
| 1430 | case uniIndication := <-dh.chUniVlanConfigOnRebootDone: |
| 1431 | switch uniIndication { |
| 1432 | // this should be a valid UNI vlan config done indication |
| 1433 | default: |
| 1434 | if uniIndication < platform.MaxUnisPerOnu { |
| 1435 | logger.Info(ctx, "rebooting - configuring flows has been finished in time for this UNI", |
| 1436 | log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| 1437 | if rebootUniVlanConfigEntries, appended = |
| 1438 | dh.appendIfMissing(rebootUniVlanConfigEntries, uint8(uniIndication)); appended { |
| 1439 | waitGroup.Done() |
| 1440 | } |
| 1441 | } else { |
| 1442 | logger.Errorw(ctx, "received unexpected UNI flowConfig done indication - is ignored", log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| 1443 | } |
| 1444 | } //switch uniIndication |
| 1445 | |
| 1446 | case <-time.After(expiry): |
| 1447 | logger.Errorw(ctx, "timeout waiting for configuring all UNI flows to be finished!", |
| 1448 | log.Fields{"device-id": dh.DeviceID}) |
| 1449 | return |
| 1450 | } |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | func (dh *deviceHandler) SendChUniVlanConfigFinishedOnReboot(value uint16) { |
| 1455 | if dh != nil { //if the object still exists (might have been already deleted in background) |
| 1456 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1457 | select { |
| 1458 | case dh.chUniVlanConfigOnRebootDone <- value: |
| 1459 | default: |
| 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | func (dh *deviceHandler) CheckForDeviceTechProf(ctx context.Context) bool { |
| bseeniva | bc19dec | 2026-02-04 11:56:23 +0530 | [diff] [blame] | 1465 | logger.Infow(ctx, "Check for tech profile config", log.Fields{"device-id": dh.DeviceID}) |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 1466 | techProfInstLoadFailed := false |
| 1467 | continueWithFlowConfig := false |
| 1468 | defer dh.UpdateAndStoreRebootState(ctx, continueWithFlowConfig) |
| 1469 | // Stop any on going reconciling thread as the flow configuration post reboot will be performed here |
| 1470 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| 1471 | |
| 1472 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 1473 | if pDevEntry == nil { |
| 1474 | logger.Errorw(ctx, "no valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 1475 | return continueWithFlowConfig |
| 1476 | } |
| 1477 | dh.lockDevice.RLock() |
| 1478 | if dh.pOnuTP == nil { |
| 1479 | //should normally not happen ... |
| 1480 | logger.Warnw(ctx, "onuTechProf instance not set up - ignoring request", |
| 1481 | log.Fields{"device-id": dh.DeviceID}) |
| 1482 | dh.lockDevice.RUnlock() |
| 1483 | return continueWithFlowConfig |
| 1484 | } |
| 1485 | |
| 1486 | dh.pOnuTP.LockTpProcMutex() |
| 1487 | defer dh.pOnuTP.UnlockTpProcMutex() |
| 1488 | defer dh.lockDevice.RUnlock() |
| 1489 | |
| 1490 | pDevEntry.MutexPersOnuConfig.RLock() |
| 1491 | persMutexLock := true |
| 1492 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 1493 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1494 | logger.Info(ctx, "no uni-configs have been stored - aborting", |
| 1495 | log.Fields{"device-id": dh.DeviceID}) |
| 1496 | return continueWithFlowConfig |
| 1497 | } |
| 1498 | |
| 1499 | outerLoop: |
| 1500 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
| 1501 | uniID := uniData.PersUniID |
| 1502 | |
| 1503 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
| 1504 | logger.Debugw(ctx, "no TPs stored for uniID", |
| 1505 | log.Fields{"uni-id": uniID, "device-id": dh.DeviceID}) |
| 1506 | continue |
| 1507 | } |
| 1508 | //release MutexPersOnuConfig before TechProfile (ANIConfig) processing as otherwise the reception of |
| 1509 | // OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI |
| 1510 | // frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap |
| 1511 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1512 | persMutexLock = false |
| 1513 | for tpID, tpPath := range uniData.PersTpPathMap { |
| 1514 | if tpPath != "" { |
| 1515 | logger.Infow(ctx, "Starting retrieval for TechProfileInstance", log.Fields{ |
| 1516 | "uniID": uniID, "tpID": tpID, "tpPath": tpPath, "device-id": dh.DeviceID, |
| 1517 | }) |
| 1518 | // Attempt the initial call before entering the retry loop |
| 1519 | iaTechTpInst, err := dh.GetTechProfileInstanceFromParentAdapter(ctx, uniID, tpPath) |
| 1520 | if err != nil { |
| 1521 | logger.Warnw(ctx, "Starting retrieval for TechProfileInstance", log.Fields{ |
| 1522 | "uniID": uniID, "tpID": tpID, "tpPath": tpPath, "device-id": dh.DeviceID, |
| 1523 | }) |
| 1524 | techProfInstLoadFailed = true |
| 1525 | break outerLoop |
| 1526 | } |
| 1527 | if iaTechTpInst != nil { |
| 1528 | var tpInst tech_profile.TechProfileInstance |
| 1529 | switch techTpInst := iaTechTpInst.TechTpInstance.(type) { |
| 1530 | case *ia.TechProfileDownloadMessage_TpInstance: // supports only GPON, XGPON, XGS-PON |
| 1531 | tpInst = *techTpInst.TpInstance |
| 1532 | logger.Debugw(ctx, "received-tp-instance-successfully-after-reboot", log.Fields{ |
| 1533 | "tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| 1534 | default: // do not support epon or other tech |
| 1535 | logger.Errorw(ctx, "unsupported-tech-profile", log.Fields{ |
| 1536 | "tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| 1537 | techProfInstLoadFailed = true |
| 1538 | break outerLoop |
| 1539 | } |
| 1540 | |
| 1541 | continueWithFlowConfig = true |
| 1542 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 1543 | dctx, cancel := context.WithDeadline(ctx, deadline) |
| 1544 | |
| 1545 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniData.PersUniID, tpID) |
| 1546 | var wg sync.WaitGroup |
| 1547 | wg.Add(1) // for the 1 go routine to finish |
| 1548 | go dh.pOnuTP.ConfigureUniTp(log.WithSpanFromContext(dctx, ctx), uniData.PersUniID, uniData.PersTpPathMap[tpID], tpInst, &wg) |
| 1549 | // Wait for either completion or cancellation |
| 1550 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfDwldDuringReboot") |
| 1551 | if tpErr := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); tpErr != nil { |
| 1552 | logger.Errorw(ctx, "error-processing-tp", log.Fields{"device-id": dh.DeviceID, "err": tpErr, "tp-path": uniData.PersTpPathMap[tpID]}) |
| 1553 | techProfInstLoadFailed = true |
| 1554 | continueWithFlowConfig = false |
| 1555 | break outerLoop |
| 1556 | } |
| 1557 | } else { |
| 1558 | logger.Errorw(ctx, "Tp instance is not valid", log.Fields{"tp-id": tpID, "tpPath": tpPath, "device-id": dh.DeviceID, "err": err}) |
| 1559 | techProfInstLoadFailed = true |
| 1560 | break outerLoop |
| 1561 | } |
| 1562 | } else { |
| 1563 | logger.Errorw(ctx, "Tp instance is nil", log.Fields{"tp-id": tpID, "tpPath": tpPath, |
| 1564 | "uni-id": uniID, "device-id": dh.DeviceID}) |
| 1565 | techProfInstLoadFailed = true |
| 1566 | break outerLoop |
| 1567 | } |
| 1568 | } |
| 1569 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| 1570 | persMutexLock = true |
| 1571 | } |
| 1572 | if persMutexLock { |
| 1573 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1574 | } |
| 1575 | go dh.deviceRebootStateUpdate(ctx, techProfInstLoadFailed) |
| 1576 | return continueWithFlowConfig |
| 1577 | } |
| 1578 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1579 | func (dh *deviceHandler) deleteDevicePersistencyData(ctx context.Context) error { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1580 | 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] | 1581 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1582 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1583 | if pDevEntry == nil { |
| mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1584 | //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] | 1585 | 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] | 1586 | return nil |
| Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1587 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1588 | |
| 1589 | // deadline context to ensure completion of background routines waited for |
| 1590 | //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] | 1591 | 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] | 1592 | dctx, cancel := context.WithDeadline(ctx, deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 1593 | defer cancel() |
| 1594 | err := pDevEntry.DeleteDataFromOnuKvStore(log.WithSpanFromContext(dctx, ctx)) |
| 1595 | if err != nil { |
| 1596 | logger.Errorw(ctx, "delete data from onu kv store failed", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 1597 | return err |
| 1598 | } |
| 1599 | return nil |
| Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1602 | // func (dh *deviceHandler) rebootDevice(ctx context.Context, device *voltha.Device) error { |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1603 | // before this change here return like this was used: |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1604 | // |
| 1605 | // return fmt.Errorf("device-unreachable: %s, %s", dh.DeviceID, device.SerialNumber) |
| 1606 | // |
| 1607 | // was and is called in background - error return does not make sense |
| akashreddyk | e30dfa9 | 2025-11-26 10:51:57 +0530 | [diff] [blame] | 1608 | 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] | 1609 | 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] | 1610 | if aCheckDeviceState && device.ConnectStatus != voltha.ConnectStatus_REACHABLE { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1611 | 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] | 1612 | return fmt.Errorf("device-unreachable: %s, %s", dh.DeviceID, device.SerialNumber) |
| ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1613 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1614 | if err := dh.pOnuOmciDevice.Reboot(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1615 | //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] | 1616 | 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] | 1617 | return err |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1618 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1619 | |
| 1620 | //transfer the possibly modified logical uni port state |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1621 | dh.DisableUniPortStateUpdate(ctx) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1622 | |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 1623 | logger.Debugw(ctx, "call DeviceStateUpdate upon reboot", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1624 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID}) |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 1625 | // 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] | 1626 | go func() { |
| 1627 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| 1628 | DeviceId: dh.DeviceID, |
| 1629 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
| 1630 | OperStatus: voltha.OperStatus_DISCOVERED, |
| 1631 | }); err != nil { |
| 1632 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 1633 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| 1634 | return |
| 1635 | } |
| bseeniva | bc19dec | 2026-02-04 11:56:23 +0530 | [diff] [blame] | 1636 | if dh.GetDeviceTechProfOnReboot() { |
| 1637 | dh.UpdateAndStoreRebootState(ctx, true) |
| 1638 | } |
| akashreddyk | e30dfa9 | 2025-11-26 10:51:57 +0530 | [diff] [blame] | 1639 | if err := dh.ReasonUpdate(ctx, cmn.DrRebooting, true); err != nil { |
| 1640 | logger.Errorw(ctx, "errror-updating-device-reason-to-core", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| 1641 | return |
| 1642 | } |
| 1643 | dh.SetReadyForOmciConfig(false) |
| 1644 | }() |
| 1645 | return nil |
| mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1646 | //no specific activity to synchronize any internal FSM to the 'rebooted' state is explicitly done here |
| 1647 | // the expectation ids for a real device, that it will be synced with the expected following 'down' indication |
| 1648 | // as BBSIM does not support this testing requires explicite disable/enable device calls in which sequence also |
| 1649 | // all other FSM's should be synchronized again |
| ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1650 | } |
| 1651 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1652 | // doOnuSwUpgrade initiates the SW download transfer to the ONU and on success activates the (inactive) image |
| 1653 | // |
| 1654 | // used only for old - R2.7 style - upgrade API |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1655 | func (dh *deviceHandler) doOnuSwUpgrade(ctx context.Context, apImageDsc *voltha.ImageDownload, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1656 | apDownloadManager *swupg.AdapterDownloadManager) error { |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1657 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1658 | "device-id": dh.DeviceID, "image-name": (*apImageDsc).Name}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1659 | |
| 1660 | var err error |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 1661 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1662 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1663 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1664 | 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] | 1665 | } |
| 1666 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1667 | if dh.IsReadyForOmciConfig() { |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1668 | var inactiveImageID uint16 |
| 1669 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1670 | dh.lockUpgradeFsm.Lock() |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1671 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| 1672 | // but must be still locked at calling createOnuUpgradeFsm |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1673 | if dh.pOnuUpradeFsm == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1674 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1675 | dh.lockUpgradeFsm.Unlock() |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1676 | if err == nil { |
| 1677 | if err = dh.pOnuUpradeFsm.SetDownloadParams(ctx, inactiveImageID, apImageDsc, apDownloadManager); err != nil { |
| 1678 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1679 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1680 | } |
| 1681 | } else { |
| 1682 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1683 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1684 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1685 | } else { //OnuSw upgrade already running - restart (with possible abort of running) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1686 | dh.lockUpgradeFsm.Unlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1687 | 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] | 1688 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1689 | dh.upgradeCanceled = true |
| 1690 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1691 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1692 | //no effort spent anymore for the old API to automatically cancel and restart the download |
| 1693 | // like done for the new API |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1694 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1695 | } else { |
| 1696 | 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] | 1697 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1698 | } |
| 1699 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1700 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no active OMCI connection", log.Fields{"device-id": dh.DeviceID}) |
| 1701 | 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] | 1702 | } |
| 1703 | return err |
| mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1706 | // 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] | 1707 | // after the OnuImage has been downloaded to the adapter, called in background |
| 1708 | func (dh *deviceHandler) onuSwUpgradeAfterDownload(ctx context.Context, apImageRequest *voltha.DeviceImageDownloadRequest, |
| bseeniva | 0b4286b | 2026-01-30 13:05:42 +0530 | [diff] [blame^] | 1709 | apDownloadManager *swupg.FileDownloadManager, aImageIdentifier string, aCancel context.CancelFunc) { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1710 | |
| 1711 | var err error |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 1712 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1713 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1714 | 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] | 1715 | return |
| 1716 | } |
| 1717 | |
| 1718 | var inactiveImageID uint16 |
| 1719 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1720 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1721 | "device-id": dh.DeviceID, "image-version": apImageRequest.Image.Version, "to onu-image": inactiveImageID}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1722 | |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1723 | dh.lockUpgradeFsm.Lock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1724 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1725 | // but must be still locked at calling createOnuUpgradeFsm |
| 1726 | // (and working with a local pointer copy does not work here if asynchronous request are done to fast |
| 1727 | // [e.g.leaving the local pointer on nil even though a creation is already on the way]) |
| 1728 | if dh.pOnuUpradeFsm != nil { |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1729 | //OnuSw upgrade already running on this device (e.g. with activate/commit not yet set) |
| 1730 | // abort the current processing, running upgrades are always aborted by newer request |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1731 | 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] | 1732 | //flush the remove upgradeFsmChan channel |
| 1733 | select { |
| 1734 | case <-dh.upgradeFsmChan: |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1735 | logger.Debugw(ctx, "flushed-upgrade-fsm-channel", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1736 | default: |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1737 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1738 | dh.lockUpgradeFsm.Unlock() |
| 1739 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1740 | dh.upgradeCanceled = true |
| 1741 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1742 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1743 | select { |
| 1744 | case <-time.After(cTimeOutRemoveUpgrade * time.Second): |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1745 | 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] | 1746 | //should not appear, can't proceed with new upgrade, perhaps operator can retry manually later |
| 1747 | return |
| 1748 | case <-dh.upgradeFsmChan: |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1749 | 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] | 1750 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1751 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1752 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1753 | |
| 1754 | //here it can be assumed that no running upgrade processing exists (anymore) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1755 | //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] | 1756 | // but none yet defined |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1757 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1758 | dh.lockUpgradeFsm.Unlock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1759 | if err == nil { |
| 1760 | if err = dh.pOnuUpradeFsm.SetDownloadParamsAfterDownload(ctx, inactiveImageID, |
| 1761 | apImageRequest, apDownloadManager, aImageIdentifier); err != nil { |
| 1762 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1763 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1764 | return |
| 1765 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1766 | } else { |
| 1767 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1768 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1769 | } |
| bseeniva | 0b4286b | 2026-01-30 13:05:42 +0530 | [diff] [blame^] | 1770 | go func() { |
| 1771 | onuDlChn := dh.pOnuUpradeFsm.GetOnuDLChannel() |
| 1772 | select { |
| 1773 | case <-ctx.Done(): |
| 1774 | logger.Errorw(ctx, "context Deadline Exceeded aborting ONU SW upgrade", log.Fields{"device-id": dh.DeviceID, "err": ctx.Err()}) |
| 1775 | dh.lockUpgradeFsm.Lock() |
| 1776 | if dh.pOnuUpradeFsm != nil { |
| 1777 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) |
| 1778 | } |
| 1779 | dh.lockUpgradeFsm.Unlock() |
| 1780 | return |
| 1781 | case <-dh.deviceDeleteCommChan: |
| 1782 | logger.Errorw(ctx, "device deleted aborting ONU SW upgrade", log.Fields{"device-id": dh.DeviceID, "err": ctx.Err()}) |
| 1783 | dh.lockUpgradeFsm.Lock() |
| 1784 | if dh.pOnuUpradeFsm != nil { |
| 1785 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) |
| 1786 | } |
| 1787 | dh.lockUpgradeFsm.Unlock() |
| 1788 | return |
| 1789 | case success := <-onuDlChn: |
| 1790 | logger.Infow(ctx, "onu SW upgrade download completed", log.Fields{"isSuccess": success, "device-id": dh.DeviceID}) |
| 1791 | aCancel() |
| 1792 | return |
| 1793 | |
| 1794 | } |
| 1795 | }() |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1796 | return |
| 1797 | } |
| 1798 | 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] | 1799 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1800 | } |
| 1801 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1802 | // onuSwActivateRequest ensures activation of the requested image with commit options |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1803 | func (dh *deviceHandler) onuSwActivateRequest(ctx context.Context, |
| 1804 | aVersion string, aCommitRequest bool) (*voltha.ImageState, error) { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1805 | var err error |
| 1806 | //SW activation for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1807 | // 1.) activation of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1808 | // 2.) activation of the inactive image |
| 1809 | |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 1810 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1811 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1812 | logger.Errorw(ctx, "Onu image activation rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1813 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1814 | } |
| 1815 | dh.lockUpgradeFsm.RLock() |
| 1816 | if dh.pOnuUpradeFsm != nil { |
| 1817 | dh.lockUpgradeFsm.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1818 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1819 | if getErr != nil || onuVolthaDevice == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1820 | logger.Errorw(ctx, "Failed to fetch Onu device for image activation", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1821 | 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] | 1822 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1823 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1824 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1825 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1826 | } |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1827 | // use the OnuVendor identification from this device for the internal unique name |
| 1828 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1829 | // 1.) check a started upgrade process and relay the activation request to it |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1830 | if err = dh.pOnuUpradeFsm.SetActivationParamsRunning(ctx, imageIdentifier, aCommitRequest); err != nil { |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1831 | //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] | 1832 | 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] | 1833 | "device-id": dh.DeviceID, "error": err}) |
| 1834 | 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] | 1835 | } |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1836 | logger.Debugw(ctx, "image activation acknowledged by onu upgrade processing", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1837 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1838 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1839 | return pImageStates, nil |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1840 | } //else |
| 1841 | dh.lockUpgradeFsm.RUnlock() |
| 1842 | |
| 1843 | // 2.) check if requested image-version equals the inactive one and start its activation |
| 1844 | // (image version is not [yet] checked - would be possible, but with increased effort ...) |
| 1845 | var inactiveImageID uint16 |
| 1846 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err != nil || inactiveImageID > 1 { |
| 1847 | logger.Errorw(ctx, "get inactive image failed", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1848 | "device-id": dh.DeviceID, "err": err, "image-id": inactiveImageID}) |
| 1849 | 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] | 1850 | } |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1851 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1852 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1853 | dh.lockUpgradeFsm.Unlock() |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1854 | if err == nil { |
| 1855 | if err = dh.pOnuUpradeFsm.SetActivationParamsStart(ctx, aVersion, |
| 1856 | inactiveImageID, aCommitRequest); err != nil { |
| 1857 | 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] | 1858 | "device-id": dh.DeviceID, "error": err}) |
| 1859 | 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] | 1860 | } |
| 1861 | logger.Debugw(ctx, "inactive image activation acknowledged by onu upgrade", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1862 | "device-id": dh.DeviceID, "image-version": aVersion}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1863 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1864 | return pImageStates, nil |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1865 | } //else |
| 1866 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1867 | "device-id": dh.DeviceID, "error": err}) |
| 1868 | 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] | 1869 | } |
| 1870 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1871 | // onuSwCommitRequest ensures commitment of the requested image |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1872 | func (dh *deviceHandler) onuSwCommitRequest(ctx context.Context, |
| 1873 | aVersion string) (*voltha.ImageState, error) { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1874 | var err error |
| 1875 | //SW commitment for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1876 | // 1.) commitment of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1877 | // 2.) commitment of the active image |
| 1878 | |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 1879 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1880 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1881 | logger.Errorw(ctx, "Onu image commitment rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1882 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1883 | } |
| 1884 | dh.lockUpgradeFsm.RLock() |
| 1885 | if dh.pOnuUpradeFsm != nil { |
| 1886 | dh.lockUpgradeFsm.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1887 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1888 | if getErr != nil || onuVolthaDevice == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1889 | logger.Errorw(ctx, "Failed to fetch Onu device for image commitment", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1890 | 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] | 1891 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1892 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1893 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1894 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1895 | } |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1896 | // use the OnuVendor identification from this device for the internal unique name |
| 1897 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1898 | // 1.) check a started upgrade process and relay the commitment request to it |
| 1899 | // the running upgrade may be based either on the imageIdentifier (started from download) |
| 1900 | // or on the imageVersion (started from pure activation) |
| 1901 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsRunning(ctx, imageIdentifier, aVersion); err != nil { |
| 1902 | //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] | 1903 | 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] | 1904 | "device-id": dh.DeviceID, "error": err}) |
| 1905 | 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] | 1906 | } |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1907 | logger.Debugw(ctx, "image commitment acknowledged by onu upgrade processing", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1908 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1909 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1910 | return pImageStates, nil |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1911 | } //else |
| 1912 | dh.lockUpgradeFsm.RUnlock() |
| 1913 | |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1914 | // 2.) use the active image to directly commit |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1915 | var activeImageID uint16 |
| 1916 | if activeImageID, err = pDevEntry.GetActiveImageMeID(ctx); err != nil || activeImageID > 1 { |
| 1917 | logger.Errorw(ctx, "get active image failed", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1918 | "device-id": dh.DeviceID, "err": err, "image-id": activeImageID}) |
| 1919 | 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] | 1920 | } |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1921 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1922 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1923 | dh.lockUpgradeFsm.Unlock() |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1924 | if err == nil { |
| 1925 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsStart(ctx, aVersion, activeImageID); err != nil { |
| 1926 | 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] | 1927 | "device-id": dh.DeviceID, "error": err}) |
| 1928 | 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] | 1929 | } |
| 1930 | logger.Debugw(ctx, "active image commitment acknowledged by onu upgrade", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1931 | "device-id": dh.DeviceID, "image-version": aVersion}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1932 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1933 | return pImageStates, nil |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1934 | } //else |
| 1935 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1936 | "device-id": dh.DeviceID, "error": err}) |
| 1937 | 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] | 1938 | } |
| 1939 | |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1940 | func (dh *deviceHandler) requestOnuSwUpgradeState(ctx context.Context, aImageIdentifier string, |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1941 | aVersion string) *voltha.ImageState { |
| 1942 | var pImageState *voltha.ImageState |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1943 | dh.lockUpgradeFsm.RLock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1944 | defer dh.lockUpgradeFsm.RUnlock() |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1945 | if dh.pOnuUpradeFsm != nil { |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1946 | pImageState = dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1947 | } else { //use the last stored ImageState (if the requested Imageversion coincides) |
| 1948 | if aVersion == dh.pLastUpgradeImageState.Version { |
| 1949 | pImageState = dh.pLastUpgradeImageState |
| 1950 | } else { //state request for an image version different from last processed image version |
| 1951 | pImageState = &voltha.ImageState{ |
| 1952 | Version: aVersion, |
| 1953 | //we cannot state something concerning this version |
| 1954 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 1955 | Reason: voltha.ImageState_NO_ERROR, |
| 1956 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 1957 | } |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1958 | } |
| 1959 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1960 | return pImageState |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | func (dh *deviceHandler) cancelOnuSwUpgrade(ctx context.Context, aImageIdentifier string, |
| 1964 | aVersion string, pDeviceImageState *voltha.DeviceImageState) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1965 | pDeviceImageState.DeviceId = dh.DeviceID |
| mpagenko | 7455fd4 | 2021-06-10 16:25:55 +0000 | [diff] [blame] | 1966 | pDeviceImageState.ImageState.Version = aVersion |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1967 | dh.lockUpgradeFsm.RLock() |
| 1968 | if dh.pOnuUpradeFsm != nil { |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1969 | dh.lockUpgradeFsm.RUnlock() |
| 1970 | // so then we cancel the upgrade operation |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1971 | // but before we still request the actual upgrade states for the direct response |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1972 | pImageState := dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1973 | pDeviceImageState.ImageState.DownloadState = pImageState.DownloadState |
| 1974 | pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST |
| 1975 | pDeviceImageState.ImageState.ImageState = pImageState.ImageState |
| 1976 | if pImageState.DownloadState != voltha.ImageState_DOWNLOAD_UNKNOWN { |
| 1977 | //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] | 1978 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1979 | dh.upgradeCanceled = true |
| 1980 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1981 | } |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1982 | } //nothing to cancel (upgrade FSM for different image stays alive) |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1983 | } else { |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1984 | dh.lockUpgradeFsm.RUnlock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1985 | // if no upgrade is ongoing, nothing is canceled and accordingly the states of the requested image are unknown |
| 1986 | // reset also the dh handler LastUpgradeImageState (not relevant anymore/cleared) |
| 1987 | (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1988 | (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR |
| 1989 | (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1990 | (*dh.pLastUpgradeImageState).Version = "" //reset to 'no (relevant) upgrade done' (like initial state) |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1991 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1992 | pDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1993 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1994 | //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] | 1995 | } |
| 1996 | } |
| 1997 | |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1998 | func (dh *deviceHandler) getOnuImages(ctx context.Context) (*voltha.OnuImages, error) { |
| 1999 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2000 | var onuImageStatus *swupg.OnuImageStatus |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 2001 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2002 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 2003 | if pDevEntry != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2004 | onuImageStatus = swupg.NewOnuImageStatus(dh, pDevEntry) |
| 2005 | pDevEntry.MutexOnuImageStatus.Lock() |
| 2006 | pDevEntry.POnuImageStatus = onuImageStatus |
| 2007 | pDevEntry.MutexOnuImageStatus.Unlock() |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 2008 | |
| 2009 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2010 | 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] | 2011 | return nil, fmt.Errorf("no-valid-OnuDevice-aborting") |
| 2012 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2013 | images, err := onuImageStatus.GetOnuImageStatus(ctx) |
| 2014 | pDevEntry.MutexOnuImageStatus.Lock() |
| 2015 | pDevEntry.POnuImageStatus = nil |
| 2016 | pDevEntry.MutexOnuImageStatus.Unlock() |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 2017 | return images, err |
| 2018 | } |
| 2019 | |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2020 | // deviceHandler methods that implement the adapters interface requests## end ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2021 | // ##################################################################################### |
| 2022 | |
| 2023 | // ################ to be updated acc. needs of ONU Device ######################## |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2024 | // deviceHandler StateMachine related state transition methods ##### begin ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2025 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2026 | func (dh *deviceHandler) logStateChange(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2027 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"event name": string(e.Event), |
| 2028 | "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] | 2029 | } |
| 2030 | |
| 2031 | // doStateInit provides the device update to the core |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2032 | func (dh *deviceHandler) doStateInit(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2033 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2034 | logger.Debugw(ctx, "doStateInit-started", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2035 | var err error |
| 2036 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2037 | // populate what we know. rest comes later after mib sync |
| 2038 | dh.device.Root = false |
| 2039 | dh.device.Vendor = "OpenONU" |
| 2040 | dh.device.Model = "go" |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2041 | dh.device.Reason = cmn.DeviceReasonMap[cmn.DrActivatingOnu] |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2042 | _ = dh.ReasonUpdate(ctx, cmn.DrActivatingOnu, false) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2043 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2044 | dh.logicalDeviceID = dh.DeviceID // really needed - what for ??? //TODO!!! |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2045 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2046 | if !dh.IsReconciling() { |
| 2047 | 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] | 2048 | if err = dh.updateDeviceInCore(ctx, dh.device); err != nil { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2049 | logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err}) |
| 2050 | } |
| Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 2051 | //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] | 2052 | } else { |
| bseeniva | 8c4547f | 2026-01-30 16:30:30 +0530 | [diff] [blame] | 2053 | logger.Debugw(ctx, "reconciling - don't notify core about DeviceUpdate", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2054 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2055 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2056 | |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2057 | dh.parentID = dh.device.ParentId |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2058 | dh.ponPortNumber = dh.device.ParentPortNo |
| 2059 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2060 | // store proxy parameters for later communication - assumption: invariant, else they have to be requested dynamically!! |
| 2061 | dh.ProxyAddressID = dh.device.ProxyAddress.GetDeviceId() |
| 2062 | dh.ProxyAddressType = dh.device.ProxyAddress.GetDeviceType() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2063 | 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] | 2064 | "proxyAddressType": dh.ProxyAddressType, "SNR": dh.device.SerialNumber, |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2065 | "ParentId": dh.parentID, "ParentPortNo": dh.ponPortNumber}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2066 | |
| 2067 | /* |
| 2068 | self._pon = PonPort.create(self, self._pon_port_number) |
| 2069 | self._pon.add_peer(self.parent_id, self._pon_port_number) |
| 2070 | self.logger.debug('adding-pon-port-to-agent', |
| 2071 | type=self._pon.get_port().type, |
| 2072 | admin_state=self._pon.get_port().admin_state, |
| 2073 | oper_status=self._pon.get_port().oper_status, |
| 2074 | ) |
| 2075 | */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2076 | if !dh.IsReconciling() { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2077 | 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] | 2078 | var ponPortNo uint32 = 1 |
| 2079 | if dh.ponPortNumber != 0 { |
| 2080 | ponPortNo = dh.ponPortNumber |
| 2081 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2082 | |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2083 | pPonPort := &voltha.Port{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2084 | DeviceId: dh.DeviceID, |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2085 | PortNo: ponPortNo, |
| 2086 | Label: fmt.Sprintf("pon-%d", ponPortNo), |
| 2087 | Type: voltha.Port_PON_ONU, |
| 2088 | OperStatus: voltha.OperStatus_ACTIVE, |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2089 | Peers: []*voltha.Port_PeerPort{{DeviceId: dh.parentID, // Peer device is OLT |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2090 | PortNo: ponPortNo}}, // Peer port is parent's port number |
| 2091 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2092 | if err = dh.CreatePortInCore(ctx, pPonPort); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2093 | logger.Fatalf(ctx, "Device FSM: PortCreated-failed-%s:%s", err, dh.DeviceID) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2094 | e.Cancel(err) |
| 2095 | return |
| 2096 | } |
| 2097 | } else { |
| bseeniva | 8c4547f | 2026-01-30 16:30:30 +0530 | [diff] [blame] | 2098 | logger.Debugw(ctx, "reconciling - pon-port already added", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2099 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2100 | logger.Debugw(ctx, "doStateInit-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | // postInit setups the DeviceEntry for the conerned device |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2104 | func (dh *deviceHandler) postInit(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2105 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2106 | logger.Debugw(ctx, "postInit-started", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2107 | var err error |
| 2108 | /* |
| 2109 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
| 2110 | dh.pTransitionMap.Handle(ctx, GrpcConnected) |
| 2111 | return nil |
| 2112 | */ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2113 | if err = dh.addOnuDeviceEntry(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2114 | logger.Fatalf(ctx, "Device FSM: addOnuDeviceEntry-failed-%s:%s", err, dh.DeviceID) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2115 | e.Cancel(err) |
| 2116 | return |
| 2117 | } |
| 2118 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2119 | if dh.IsReconciling() { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2120 | go dh.reconcileDeviceOnuInd(ctx) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2121 | // reconcilement will be continued after mib download is done |
| 2122 | } |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 2123 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2124 | /* |
| 2125 | ############################################################################ |
| 2126 | # Setup Alarm handler |
| 2127 | self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id, |
| 2128 | device.serial_number) |
| 2129 | ############################################################################ |
| 2130 | # Setup PM configuration for this device |
| 2131 | # Pass in ONU specific options |
| 2132 | kwargs = { |
| 2133 | OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY, |
| 2134 | 'heartbeat': self.heartbeat, |
| 2135 | OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device |
| 2136 | } |
| 2137 | self.logger.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number) |
| 2138 | self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id, |
| 2139 | self.logical_device_id, device.serial_number, |
| 2140 | grouped=True, freq_override=False, **kwargs) |
| 2141 | pm_config = self._pm_metrics.make_proto() |
| 2142 | self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm) |
| 2143 | self.logger.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number) |
| 2144 | yield self.core_proxy.device_pm_config_update(pm_config, init=True) |
| 2145 | |
| 2146 | # Note, ONU ID and UNI intf set in add_uni_port method |
| 2147 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events, |
| 2148 | ani_ports=[self._pon]) |
| 2149 | |
| 2150 | # Code to Run OMCI Test Action |
| 2151 | kwargs_omci_test_action = { |
| 2152 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 2153 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 2154 | } |
| 2155 | serial_number = device.serial_number |
| 2156 | self._test_request = OmciTestRequest(self.core_proxy, |
| 2157 | self.omci_agent, self.device_id, |
| 2158 | AniG, serial_number, |
| 2159 | self.logical_device_id, |
| 2160 | exclusive=False, |
| 2161 | **kwargs_omci_test_action) |
| 2162 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2163 | self.Enabled = True |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2164 | else: |
| 2165 | self.logger.info('onu-already-activated') |
| 2166 | */ |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 2167 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2168 | logger.Debugw(ctx, "postInit-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | // doStateConnected get the device info and update to voltha core |
| 2172 | // 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] | 2173 | // |
| 2174 | // voltha-openolt-adapter/adaptercore/device_handler.go |
| 2175 | // -> this one obviously initiates all communication interfaces of the device ...? |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2176 | func (dh *deviceHandler) doStateConnected(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2177 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2178 | logger.Debugw(ctx, "doStateConnected-started", log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2179 | err := errors.New("device FSM: function not implemented yet") |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2180 | e.Cancel(err) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2181 | logger.Debugw(ctx, "doStateConnected-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | // doStateUp handle the onu up indication and update to voltha core |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2185 | func (dh *deviceHandler) doStateUp(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2186 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2187 | logger.Debugw(ctx, "doStateUp-started", log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2188 | err := errors.New("device FSM: function not implemented yet") |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2189 | e.Cancel(err) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2190 | logger.Debugw(ctx, "doStateUp-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2191 | |
| 2192 | /* |
| 2193 | // Synchronous call to update device state - this method is run in its own go routine |
| 2194 | if err := dh.coreProxy.DeviceStateUpdate(ctx, dh.device.Id, voltha.ConnectStatus_REACHABLE, |
| 2195 | voltha.OperStatus_ACTIVE); err != nil { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2196 | 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] | 2197 | return err |
| 2198 | } |
| 2199 | return nil |
| 2200 | */ |
| 2201 | } |
| 2202 | |
| 2203 | // doStateDown handle the onu down indication |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2204 | func (dh *deviceHandler) doStateDown(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2205 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2206 | logger.Debugw(ctx, "doStateDown-started", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2207 | var err error |
| 2208 | |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2209 | device := dh.device |
| 2210 | if device == nil { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2211 | /*TODO: needs to handle error scenarios */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2212 | 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] | 2213 | e.Cancel(err) |
| 2214 | return |
| 2215 | } |
| 2216 | |
| 2217 | cloned := proto.Clone(device).(*voltha.Device) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2218 | logger.Debugw(ctx, "do-state-down", log.Fields{"ClonedDeviceID": cloned.Id}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2219 | /* |
| 2220 | // Update the all ports state on that device to disable |
| 2221 | if er := dh.coreProxy.PortsStateUpdate(ctx, cloned.Id, voltha.OperStatus_UNKNOWN); er != nil { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2222 | 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] | 2223 | return er |
| 2224 | } |
| 2225 | |
| 2226 | //Update the device oper state and connection status |
| 2227 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 2228 | cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE |
| 2229 | dh.device = cloned |
| 2230 | |
| 2231 | 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] | 2232 | 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] | 2233 | return er |
| 2234 | } |
| 2235 | |
| 2236 | //get the child device for the parent device |
| 2237 | onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id) |
| 2238 | if err != nil { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2239 | 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] | 2240 | return err |
| 2241 | } |
| 2242 | for _, onuDevice := range onuDevices.Items { |
| 2243 | |
| 2244 | // Update onu state as down in onu adapter |
| 2245 | onuInd := oop.OnuIndication{} |
| 2246 | onuInd.OperState = "down" |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2247 | er := dh.adapterProxy.SendInterAdapterMessage(ctx, &onuInd, ca.InterAdapterMessageType_ONU_IND_REQUEST, |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2248 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 2249 | if er != nil { |
| 2250 | logger.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2251 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "device-id": onuDevice.Id}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2252 | //Do not return here and continue to process other ONUs |
| 2253 | } |
| 2254 | } |
| 2255 | // * Discovered ONUs entries need to be cleared , since after OLT |
| 2256 | // is up, it starts sending discovery indications again* / |
| 2257 | dh.discOnus = sync.Map{} |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2258 | logger.Debugw("do-state-down-end", log.Fields{"device-id": device.Id}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2259 | return nil |
| 2260 | */ |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2261 | err = errors.New("device FSM: function not implemented yet") |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2262 | e.Cancel(err) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2263 | logger.Debugw(ctx, "doStateDown-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2264 | } |
| 2265 | |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2266 | // deviceHandler StateMachine related state transition methods ##### end ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2267 | // ################################################################################# |
| 2268 | |
| 2269 | // ################################################### |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2270 | // deviceHandler utility methods ##### begin ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2271 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 2272 | // 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] | 2273 | func (dh *deviceHandler) GetOnuDeviceEntry(ctx context.Context, aWait bool) *mib.OnuDeviceEntry { |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2274 | dh.lockDevice.RLock() |
| 2275 | pOnuDeviceEntry := dh.pOnuOmciDevice |
| 2276 | if aWait && pOnuDeviceEntry == nil { |
| 2277 | //keep the read sema short to allow for subsequent write |
| 2278 | dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2279 | 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] | 2280 | // based on concurrent processing the deviceEntry setup may not yet be finished at his point |
| 2281 | // so it might be needed to wait here for that event with some timeout |
| 2282 | select { |
| 2283 | case <-time.After(60 * time.Second): //timer may be discussed ... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2284 | 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] | 2285 | return nil |
| 2286 | case <-dh.deviceEntrySet: |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2287 | logger.Debugw(ctx, "devicEntry ready now - continue", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2288 | // if written now, we can return the written value without sema |
| 2289 | return dh.pOnuOmciDevice |
| 2290 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2291 | } |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2292 | dh.lockDevice.RUnlock() |
| 2293 | return pOnuDeviceEntry |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2294 | } |
| 2295 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 2296 | // setDeviceHandlerEntries sets the ONU device entry within the handler |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2297 | func (dh *deviceHandler) setDeviceHandlerEntries(apDeviceEntry *mib.OnuDeviceEntry, apOnuTp *avcfg.OnuUniTechProf, |
| 2298 | apOnuMetricsMgr *pmmgr.OnuMetricsManager, apOnuAlarmMgr *almgr.OnuAlarmManager, apSelfTestHdlr *otst.SelfTestControlBlock) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2299 | dh.lockDevice.Lock() |
| 2300 | defer dh.lockDevice.Unlock() |
| mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 2301 | dh.pOnuOmciDevice = apDeviceEntry |
| 2302 | dh.pOnuTP = apOnuTp |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 2303 | dh.pOnuMetricsMgr = apOnuMetricsMgr |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 2304 | dh.pAlarmMgr = apOnuAlarmMgr |
| Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 2305 | dh.pSelfTestHdlr = apSelfTestHdlr |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2306 | } |
| 2307 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 2308 | // addOnuDeviceEntry creates a new ONU device or returns the existing |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2309 | // |
| 2310 | //nolint:unparam |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2311 | func (dh *deviceHandler) addOnuDeviceEntry(ctx context.Context) error { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2312 | logger.Debugw(ctx, "adding-deviceEntry", log.Fields{"device-id": dh.DeviceID}) |
| 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 | deviceEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2315 | if deviceEntry == nil { |
| 2316 | /* costum_me_map in python code seems always to be None, |
| 2317 | we omit that here first (declaration unclear) -> todo at Adapter specialization ...*/ |
| 2318 | /* also no 'clock' argument - usage open ...*/ |
| 2319 | /* and no alarm_db yet (oo.alarm_db) */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2320 | deviceEntry = mib.NewOnuDeviceEntry(ctx, dh.coreClient, dh, dh.pOpenOnuAc) |
| 2321 | onuTechProfProc := avcfg.NewOnuUniTechProf(ctx, dh, deviceEntry) |
| 2322 | onuMetricsMgr := pmmgr.NewOnuMetricsManager(ctx, dh, deviceEntry) |
| 2323 | onuAlarmManager := almgr.NewAlarmManager(ctx, dh, deviceEntry) |
| 2324 | selfTestHdlr := otst.NewSelfTestMsgHandlerCb(ctx, dh, deviceEntry) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2325 | //error treatment possible //TODO!!! |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2326 | dh.setDeviceHandlerEntries(deviceEntry, onuTechProfProc, onuMetricsMgr, onuAlarmManager, selfTestHdlr) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2327 | // fire deviceEntry ready event to spread to possibly waiting processing |
| 2328 | dh.deviceEntrySet <- true |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2329 | logger.Debugw(ctx, "onuDeviceEntry-added", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2330 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2331 | 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] | 2332 | } |
| 2333 | // might be updated with some error handling !!! |
| 2334 | return nil |
| 2335 | } |
| 2336 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2337 | func (dh *deviceHandler) createInterface(ctx context.Context, onuind *oop.OnuIndication) error { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2338 | 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] | 2339 | "OnuIntfId": onuind.GetIntfId(), "OnuSerialNumber": onuind.GetSerialNumber()}) |
| 2340 | |
| 2341 | dh.pOnuIndication = onuind // let's revise if storing the pointer is sufficient... |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2342 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2343 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2344 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2345 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 2346 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2347 | } |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 2348 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2349 | if !dh.IsReconciling() { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2350 | 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] | 2351 | "OperStatus": voltha.OperStatus_ACTIVATING, "device-id": dh.DeviceID}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2352 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2353 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2354 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2355 | OperStatus: voltha.OperStatus_ACTIVATING, |
| 2356 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2357 | }); err != nil { |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2358 | //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] | 2359 | 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] | 2360 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| 2361 | } |
| 2362 | // On onu reboot, we have to perform mib-reset and persist the reboot state for reconciling scenario |
| 2363 | if dh.GetDeviceTechProfOnReboot() { |
| 2364 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2365 | pDevEntry.SOnuPersistentData.PersMibLastDbSync = 0 |
| 2366 | pDevEntry.SOnuPersistentData.PersRebootInProgress = true |
| akashreddyk | b03dde0 | 2025-12-02 10:53:18 +0530 | [diff] [blame] | 2367 | pDevEntry.SOnuPersistentData.PersUniUnlockDone = false |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 2368 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2369 | } |
| 2370 | // Moving the previous call to write to KV store here, to store the ONU pers data after the update. |
| 2371 | if err := dh.StorePersistentData(ctx); err != nil { |
| 2372 | logger.Warnw(ctx, "store persistent data error - continue as there will be additional write attempts", |
| 2373 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2374 | } |
| 2375 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2376 | logger.Info(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVATING", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2377 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2378 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2379 | pDevEntry.MutexPersOnuConfig.RLock() |
| 2380 | if !pDevEntry.SOnuPersistentData.PersUniUnlockDone { |
| 2381 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2382 | 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] | 2383 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 2384 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 2385 | |
| 2386 | //VOL-4965: Recover previously Activating ONU during reconciliation. |
| 2387 | if dh.device.OperStatus == common.OperStatus_ACTIVATING { |
| 2388 | logger.Debugw(ctx, "Reconciling an ONU in previously activating state, perform MIB reset and resume normal start up", |
| 2389 | log.Fields{"device-id": dh.DeviceID}) |
| 2390 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2391 | pDevEntry.SOnuPersistentData.PersMibLastDbSync = 0 |
| 2392 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2393 | } |
| Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2394 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2395 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2396 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2397 | } |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2398 | // It does not look to me as if makes sense to work with the real core device here, (not the stored clone)? |
| 2399 | // in this code the GetDevice would just make a check if the DeviceID's Device still exists in core |
| 2400 | // 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] | 2401 | // 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] | 2402 | // so let's just try to keep it simple ... |
| 2403 | /* |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2404 | 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] | 2405 | if err != nil || device == nil { |
| 2406 | //TODO: needs to handle error scenarios |
| 2407 | logger.Errorw("Failed to fetch device device at creating If", log.Fields{"err": err}) |
| 2408 | return errors.New("Voltha Device not found") |
| 2409 | } |
| 2410 | */ |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2411 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2412 | if err := pDevEntry.Start(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2413 | return err |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2414 | } |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2415 | _ = dh.ReasonUpdate(ctx, cmn.DrStartingOpenomci, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 2416 | if !dh.IsReconciling() && !dh.GetSkipOnuConfigEnabled() { |
| 2417 | /* this might be a good time for Omci Verify message? */ |
| 2418 | verifyExec := make(chan bool) |
| 2419 | omciVerify := otst.NewOmciTestRequest(log.WithSpanFromContext(context.TODO(), ctx), |
| 2420 | dh.device.Id, pDevEntry.PDevOmciCC, false, |
| 2421 | true, true) //exclusive and allowFailure (anyway not yet checked) |
| 2422 | omciVerify.PerformOmciTest(log.WithSpanFromContext(context.TODO(), ctx), verifyExec) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2423 | |
| Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 2424 | /* give the handler some time here to wait for the OMCi verification result |
| 2425 | after Timeout start and try MibUpload FSM anyway |
| 2426 | (to prevent stopping on just not supported OMCI verification from ONU) */ |
| 2427 | select { |
| 2428 | case <-time.After(((cmn.CDefaultRetries+1)*otst.CTestRequestOmciTimeout + 1) * time.Second): |
| 2429 | logger.Warnw(ctx, "omci start-verification timed out (continue normal)", log.Fields{"device-id": dh.DeviceID}) |
| 2430 | case testresult := <-verifyExec: |
| 2431 | logger.Infow(ctx, "Omci start verification done", log.Fields{"device-id": dh.DeviceID, "result": testresult}) |
| 2432 | case <-dh.deviceDeleteCommChan: |
| 2433 | logger.Warnw(ctx, "Deleting device, stopping the omci test activity", log.Fields{"device-id": dh.DeviceID}) |
| 2434 | return nil |
| 2435 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2436 | } |
| 2437 | |
| 2438 | /* In py code it looks earlier (on activate ..) |
| 2439 | # Code to Run OMCI Test Action |
| 2440 | kwargs_omci_test_action = { |
| 2441 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 2442 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 2443 | } |
| 2444 | serial_number = device.serial_number |
| 2445 | self._test_request = OmciTestRequest(self.core_proxy, |
| 2446 | self.omci_agent, self.device_id, |
| 2447 | AniG, serial_number, |
| 2448 | self.logical_device_id, |
| 2449 | exclusive=False, |
| 2450 | **kwargs_omci_test_action) |
| 2451 | ... |
| 2452 | # Start test requests after a brief pause |
| 2453 | if not self._test_request_started: |
| 2454 | self._test_request_started = True |
| 2455 | tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 2456 | reactor.callLater(tststart, self._test_request.start_collector) |
| 2457 | |
| 2458 | */ |
| 2459 | /* which is then: in omci_test_request.py : */ |
| 2460 | /* |
| 2461 | def start_collector(self, callback=None): |
| 2462 | """ |
| 2463 | Start the collection loop for an adapter if the frequency > 0 |
| 2464 | |
| 2465 | :param callback: (callable) Function to call to collect PM data |
| 2466 | """ |
| 2467 | self.logger.info("starting-pm-collection", device_name=self.name, default_freq=self.default_freq) |
| 2468 | if callback is None: |
| 2469 | callback = self.perform_test_omci |
| 2470 | |
| 2471 | if self.lc is None: |
| 2472 | self.lc = LoopingCall(callback) |
| 2473 | |
| 2474 | if self.default_freq > 0: |
| 2475 | self.lc.start(interval=self.default_freq / 10) |
| 2476 | |
| 2477 | def perform_test_omci(self): |
| 2478 | """ |
| 2479 | Perform the initial test request |
| 2480 | """ |
| 2481 | ani_g_entities = self._device.configuration.ani_g_entities |
| 2482 | ani_g_entities_ids = list(ani_g_entities.keys()) if ani_g_entities \ |
| 2483 | is not None else None |
| 2484 | self._entity_id = ani_g_entities_ids[0] |
| 2485 | self.logger.info('perform-test', entity_class=self._entity_class, |
| 2486 | entity_id=self._entity_id) |
| 2487 | try: |
| 2488 | frame = MEFrame(self._entity_class, self._entity_id, []).test() |
| 2489 | result = yield self._device.omci_cc.send(frame) |
| 2490 | if not result.fields['omci_message'].fields['success_code']: |
| 2491 | self.logger.info('Self-Test Submitted Successfully', |
| 2492 | code=result.fields[ |
| 2493 | 'omci_message'].fields['success_code']) |
| 2494 | else: |
| 2495 | raise TestFailure('Test Failure: {}'.format( |
| 2496 | result.fields['omci_message'].fields['success_code'])) |
| 2497 | except TimeoutError as e: |
| 2498 | self.deferred.errback(failure.Failure(e)) |
| 2499 | |
| 2500 | except Exception as e: |
| 2501 | self.logger.exception('perform-test-Error', e=e, |
| 2502 | class_id=self._entity_class, |
| 2503 | entity_id=self._entity_id) |
| 2504 | self.deferred.errback(failure.Failure(e)) |
| 2505 | |
| 2506 | */ |
| 2507 | |
| 2508 | // PM related heartbeat??? !!!TODO.... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2509 | //self._heartbeat.Enabled = True |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2510 | |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 2511 | /* Note: Even though FSM calls look 'synchronous' here, FSM is running in background with the effect that possible errors |
| 2512 | * within the MibUpload are not notified in the OnuIndication response, this might be acceptable here, |
| 2513 | * 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] | 2514 | * otherwise some processing synchronization would be required - cmp. e.g TechProfile processing |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 2515 | */ |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 2516 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2517 | //call MibUploadFSM - transition up to state UlStInSync |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 2518 | // Breaking this part of code due to sca complexity |
| 2519 | err := dh.CheckAndStartMibUploadFsm(ctx, pDevEntry) |
| 2520 | return err |
| 2521 | } |
| 2522 | |
| 2523 | func (dh *deviceHandler) CheckAndStartMibUploadFsm(ctx context.Context, pDevEntry *mib.OnuDeviceEntry) error { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2524 | pMibUlFsm := pDevEntry.PMibUploadFsm.PFsm |
| Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 2525 | if pMibUlFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2526 | if pMibUlFsm.Is(mib.UlStDisabled) { |
| 2527 | if err := pMibUlFsm.Event(mib.UlEvStart); err != nil { |
| 2528 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2529 | return fmt.Errorf("can't go to state starting: %s", dh.DeviceID) |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2530 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2531 | 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] | 2532 | //Determine ONU status and start/re-start MIB Synchronization tasks |
| 2533 | //Determine if this ONU has ever synchronized |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2534 | if pDevEntry.IsNewOnu() { |
| 2535 | if err := pMibUlFsm.Event(mib.UlEvResetMib); err != nil { |
| 2536 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state resetting_mib", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2537 | 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] | 2538 | } |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2539 | } else { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2540 | if err := pMibUlFsm.Event(mib.UlEvVerifyAndStoreTPs); err != nil { |
| 2541 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state verify and store TPs", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2542 | 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] | 2543 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2544 | 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] | 2545 | } |
| Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 2546 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2547 | 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] | 2548 | "device-id": dh.DeviceID}) |
| 2549 | return fmt.Errorf("wrong state of MibSyncFsm: %s", dh.DeviceID) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2550 | } |
| 2551 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2552 | logger.Errorw(ctx, "MibSyncFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID}) |
| 2553 | return fmt.Errorf("can't execute MibSync: %s", dh.DeviceID) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2554 | } |
| 2555 | return nil |
| 2556 | } |
| 2557 | |
| Holger Hildebrandt | 68854a8 | 2022-09-05 07:00:21 +0000 | [diff] [blame] | 2558 | func (dh *deviceHandler) UpdateInterface(ctx context.Context) error { |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2559 | //state checking to prevent unneeded processing (eg. on ONU 'unreachable' and 'down') |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2560 | // (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] | 2561 | if dh.getDeviceReason() != cmn.DrStoppingOpenomci { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2562 | logger.Info(ctx, "updateInterface-started - stopping-device", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 2563 | |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2564 | //stop all running FSM processing - make use of the DH-state as mirrored in the deviceReason |
| 2565 | //here no conflict with aborted FSM's should arise as a complete OMCI initialization is assumed on ONU-Up |
| 2566 | //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] | 2567 | if err := dh.resetFsms(ctx, true); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2568 | logger.Errorw(ctx, "error-updateInterface at FSM stop", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2569 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2570 | // abort: system behavior is just unstable ... |
| 2571 | return err |
| 2572 | } |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2573 | //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] | 2574 | if !dh.GetDeviceTechProfOnReboot() { |
| 2575 | _ = dh.deleteDevicePersistencyData(ctx) //ignore possible errors here and continue, hope is that data is synchronized with new ONU-Up |
| 2576 | } |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2577 | |
| 2578 | //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] | 2579 | //stop the device entry to allow for all system event transfers again |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2580 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2581 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2582 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 2583 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2584 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2585 | _ = pDevEntry.Stop(log.WithSpanFromContext(context.TODO(), ctx), false) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2586 | |
| 2587 | //TODO!!! remove existing traffic profiles |
| 2588 | /* from py code, if TP's exist, remove them - not yet implemented |
| 2589 | self._tp = dict() |
| 2590 | # Let TP download happen again |
| 2591 | for uni_id in self._tp_service_specific_task: |
| 2592 | self._tp_service_specific_task[uni_id].clear() |
| 2593 | for uni_id in self._tech_profile_download_done: |
| 2594 | self._tech_profile_download_done[uni_id].clear() |
| 2595 | */ |
| 2596 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2597 | dh.DisableUniPortStateUpdate(ctx) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2598 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2599 | dh.SetReadyForOmciConfig(false) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2600 | |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2601 | if err := dh.ReasonUpdate(ctx, cmn.DrStoppingOpenomci, true); err != nil { |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2602 | // abort: system behavior is just unstable ... |
| 2603 | return err |
| 2604 | } |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2605 | 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] | 2606 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID}) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2607 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2608 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2609 | ConnStatus: voltha.ConnectStatus_UNREACHABLE, |
| 2610 | OperStatus: voltha.OperStatus_DISCOVERED, |
| 2611 | }); err != nil { |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2612 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2613 | logger.Errorw(ctx, "error-updating-device-state unreachable-discovered", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2614 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2615 | // abort: system behavior is just unstable ... |
| 2616 | return err |
| 2617 | } |
| akashreddyk | b03dde0 | 2025-12-02 10:53:18 +0530 | [diff] [blame] | 2618 | if dh.GetDeviceTechProfOnReboot() { |
| 2619 | logger.Debugw(ctx, "Storing OnuPersData during device-down-indication", log.Fields{"device": dh.DeviceID, "onu-pers-data": dh.pOnuOmciDevice.SOnuPersistentData}) |
| 2620 | if err := dh.StorePersistentData(ctx); err != nil { |
| 2621 | logger.Warnw(ctx, "store persistent data error - Failed to store DownIndication", |
| 2622 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2623 | } |
| 2624 | } |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2625 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2626 | logger.Debugw(ctx, "updateInterface - device already stopped", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2627 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2628 | return nil |
| 2629 | } |
| 2630 | |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2631 | func (dh *deviceHandler) resetFsms(ctx context.Context, includingMibSyncFsm bool) error { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2632 | //all possible FSM's are stopped or reset here to ensure their transition to 'disabled' |
| 2633 | //it is not sufficient to stop/reset the latest running FSM as done in previous versions |
| 2634 | // as after down/up procedures all FSM's might be active/ongoing (in theory) |
| 2635 | // and using the stop/reset event should never harm |
| Holger Hildebrandt | 12609a1 | 2022-03-25 13:23:25 +0000 | [diff] [blame] | 2636 | logger.Debugw(ctx, "resetFsms entered", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2637 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2638 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Praneeth Kumar Nalmas | fcdd20b | 2024-01-24 22:26:39 +0530 | [diff] [blame] | 2639 | //VOL-5260: During race conditions when adoptDevice has not yet completed |
| 2640 | // and deleteDevice is issued , returning error will further prevent clean up |
| 2641 | // 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] | 2642 | if pDevEntry == nil { |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 2643 | errMsg := fmt.Sprintf("Device entry is not found %s", dh.DeviceID) |
| 2644 | logger.Error(ctx, errMsg) |
| 2645 | return status.Error(codes.NotFound, errMsg) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2646 | } |
| Holger Hildebrandt | c8ece36 | 2021-05-17 12:01:10 +0000 | [diff] [blame] | 2647 | if pDevEntry.PDevOmciCC != nil { |
| mpagenko | 8cd1bf7 | 2021-06-22 10:11:19 +0000 | [diff] [blame] | 2648 | pDevEntry.PDevOmciCC.CancelRequestMonitoring(ctx) |
| Holger Hildebrandt | c8ece36 | 2021-05-17 12:01:10 +0000 | [diff] [blame] | 2649 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2650 | pDevEntry.MutexOnuImageStatus.RLock() |
| 2651 | if pDevEntry.POnuImageStatus != nil { |
| 2652 | pDevEntry.POnuImageStatus.CancelProcessing(ctx) |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 2653 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2654 | pDevEntry.MutexOnuImageStatus.RUnlock() |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 2655 | |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2656 | if includingMibSyncFsm { |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 2657 | pDevEntry.CancelProcessing(ctx) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2658 | } |
| 2659 | //MibDownload may run |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2660 | pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2661 | if pMibDlFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2662 | _ = pMibDlFsm.Event(mib.DlEvReset) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2663 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 2664 | //stop any deviceHandler reconcile processing (if running) |
| 2665 | dh.stopReconciling(ctx, false, cWaitReconcileFlowAbortOnError) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2666 | //port lock/unlock FSM's may be active |
| 2667 | if dh.pUnlockStateFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2668 | _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2669 | } |
| 2670 | if dh.pLockStateFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2671 | _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2672 | } |
| 2673 | //techProfile related PonAniConfigFsm FSM may be active |
| 2674 | if dh.pOnuTP != nil { |
| 2675 | // should always be the case here |
| 2676 | // 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] | 2677 | if dh.pOnuTP.PAniConfigFsm != nil { |
| 2678 | for uniTP := range dh.pOnuTP.PAniConfigFsm { |
| 2679 | dh.pOnuTP.PAniConfigFsm[uniTP].CancelProcessing(ctx) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 2680 | } |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2681 | } |
| 2682 | for _, uniPort := range dh.uniEntityMap { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2683 | // reset the possibly existing VlanConfigFsm |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2684 | dh.lockVlanConfig.RLock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2685 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniPort.UniID]; exist { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2686 | //VlanFilterFsm exists and was already started |
| mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2687 | dh.lockVlanConfig.RUnlock() |
| mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2688 | //ensure the FSM processing is stopped in case waiting for some response |
| mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 2689 | pVlanFilterFsm.CancelProcessing(ctx) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2690 | } else { |
| 2691 | dh.lockVlanConfig.RUnlock() |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2692 | } |
| 2693 | } |
| 2694 | } |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2695 | |
| 2696 | dh.mutexCollectorFlag.Lock() |
| 2697 | logger.Debugw(ctx, "check-collector-is-running", log.Fields{"device-id": dh.device.Id, "flag": dh.collectorIsRunning}) |
| 2698 | if dh.collectorIsRunning { |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2699 | // Stop collector routine |
| 2700 | dh.stopCollector <- true |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2701 | dh.collectorIsRunning = false |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2702 | } |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2703 | dh.mutexCollectorFlag.Unlock() |
| 2704 | |
| 2705 | dh.mutextAlarmManagerFlag.Lock() |
| 2706 | logger.Debugw(ctx, "check-alarm-manager-is-running", log.Fields{"device-id": dh.device.Id, "flag": dh.alarmManagerIsRunning}) |
| 2707 | if dh.alarmManagerIsRunning { |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2708 | dh.stopAlarmManager <- true |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2709 | dh.alarmManagerIsRunning = false |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2710 | } |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2711 | dh.mutextAlarmManagerFlag.Unlock() |
| 2712 | |
| 2713 | dh.pSelfTestHdlr.SelfTestHandlerLock.Lock() |
| 2714 | logger.Debugw(ctx, "check-self-test-control-block-is-running", log.Fields{"device-id": dh.device.Id, "flag": dh.pSelfTestHdlr.SelfTestHandlerActive}) |
| 2715 | if dh.pSelfTestHdlr.SelfTestHandlerActive { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2716 | dh.pSelfTestHdlr.StopSelfTestModule <- true |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2717 | dh.pSelfTestHdlr.SelfTestHandlerActive = false |
| Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 2718 | } |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2719 | dh.pSelfTestHdlr.SelfTestHandlerLock.Unlock() |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2720 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2721 | // Note: We want flow deletes to be processed on onu down, so do not stop flow monitoring routines |
| 2722 | |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2723 | //reset a possibly running upgrade FSM |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2724 | // (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] | 2725 | dh.lockUpgradeFsm.RLock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2726 | lopOnuUpradeFsm := dh.pOnuUpradeFsm |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2727 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2728 | dh.lockUpgradeFsm.RUnlock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2729 | if lopOnuUpradeFsm != nil { |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2730 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 2731 | //here we do not expect intermediate cancelation, we still allow for other commands on this FSM |
| 2732 | // (even though it may also run into direct cancellation, a bit hard to verify here) |
| 2733 | // so don't set 'dh.upgradeCanceled = true' here! |
| 2734 | lopOnuUpradeFsm.CancelProcessing(ctx, false, voltha.ImageState_CANCELLED_ON_ONU_STATE) //conditional cancel |
| 2735 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2736 | } |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2737 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2738 | logger.Infow(ctx, "resetFsms done", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2739 | return nil |
| 2740 | } |
| 2741 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2742 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2743 | func (dh *deviceHandler) processMibDatabaseSyncEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2744 | 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] | 2745 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2746 | // store persistent data collected during MIB upload processing |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2747 | if err := dh.StorePersistentData(ctx); err != nil { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2748 | 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] | 2749 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2750 | } |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2751 | _ = dh.ReasonUpdate(ctx, cmn.DrDiscoveryMibsyncComplete, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2752 | dh.AddAllUniPorts(ctx) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2753 | |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2754 | /* 200605: lock processing after initial MIBUpload removed now as the ONU should be in the lock state per default here */ |
| 2755 | /* 201117: build_dt-berlin-pod-openonugo_1T8GEM_voltha_DT_openonugo_master_test runs into error TC |
| 2756 | * 'Test Disable ONUs and OLT Then Delete ONUs and OLT for DT' with Sercom ONU, which obviously needs |
| 2757 | * disable/enable toggling here to allow traffic |
| 2758 | * but moreover it might be useful for tracking the interface operState changes if this will be implemented, |
| 2759 | * like the py comment says: |
| 2760 | * # start by locking all the unis till mib sync and initial mib is downloaded |
| 2761 | * # this way we can capture the port down/up events when we are ready |
| 2762 | */ |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2763 | |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2764 | // Init Uni Ports to Admin locked state |
| 2765 | // *** should generate UniLockStateDone event ***** |
| 2766 | if dh.pLockStateFsm == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2767 | dh.createUniLockFsm(ctx, true, cmn.UniLockStateDone) |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2768 | } else { //LockStateFSM already init |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2769 | dh.pLockStateFsm.SetSuccessEvent(cmn.UniLockStateDone) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2770 | dh.runUniLockFsm(ctx, true) |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2771 | } |
| 2772 | } |
| 2773 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2774 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2775 | func (dh *deviceHandler) processUniLockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2776 | 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] | 2777 | /* Mib download procedure - |
| 2778 | ***** should run over 'downloaded' state and generate MibDownloadDone event ***** |
| 2779 | */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2780 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2781 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2782 | 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] | 2783 | return |
| 2784 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2785 | pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2786 | if pMibDlFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2787 | if pMibDlFsm.Is(mib.DlStDisabled) { |
| 2788 | if err := pMibDlFsm.Event(mib.DlEvStart); err != nil { |
| 2789 | 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] | 2790 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2791 | } else { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2792 | 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] | 2793 | // maybe use more specific states here for the specific download steps ... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2794 | if err := pMibDlFsm.Event(mib.DlEvCreateGal); err != nil { |
| 2795 | 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] | 2796 | } else { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2797 | 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] | 2798 | //Begin MIB data download (running autonomously) |
| 2799 | } |
| 2800 | } |
| 2801 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2802 | 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] | 2803 | "device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2804 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2805 | } |
| 2806 | /***** Mib download started */ |
| 2807 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2808 | 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] | 2809 | } |
| 2810 | } |
| 2811 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2812 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2813 | func (dh *deviceHandler) processMibDownloadDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2814 | 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] | 2815 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 2816 | if pDevEntry == nil { |
| 2817 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 2818 | return |
| 2819 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2820 | if !dh.IsReconciling() { |
| Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 2821 | 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] | 2822 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 2823 | // update device info in core |
| 2824 | pDevEntry.MutexPersOnuConfig.RLock() |
| 2825 | dh.device.Vendor = pDevEntry.SOnuPersistentData.PersVendorID |
| 2826 | dh.device.VendorId = pDevEntry.SOnuPersistentData.PersVendorID |
| 2827 | dh.device.Model = pDevEntry.SOnuPersistentData.PersVersion |
| 2828 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 2829 | dh.logicalDeviceID = dh.DeviceID |
| 2830 | if err := dh.updateDeviceInCore(ctx, dh.device); err != nil { |
| 2831 | logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err}) |
| 2832 | } |
| 2833 | // update device state in core |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2834 | //we allow a possible OnuSw image commit only in the normal startup, not at reconciling |
| 2835 | // in case of adapter restart connected to an ONU upgrade I would not rely on the image quality |
| 2836 | // maybe some 'forced' commitment can be done in this situation from system management (or upgrade restarted) |
| 2837 | dh.checkOnOnuImageCommit(ctx) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2838 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2839 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2840 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2841 | OperStatus: voltha.OperStatus_ACTIVE, |
| 2842 | }); err != nil { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2843 | //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] | 2844 | 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] | 2845 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2846 | 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] | 2847 | } |
| 2848 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2849 | 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] | 2850 | log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2851 | } |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2852 | _ = dh.ReasonUpdate(ctx, cmn.DrInitialMibDownloaded, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2853 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2854 | if !dh.GetCollectorIsRunning() { |
| Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 2855 | var waitForOmciProcessor sync.WaitGroup |
| 2856 | waitForOmciProcessor.Add(1) |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2857 | // Start PM collector routine |
| Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 2858 | go dh.StartCollector(ctx, &waitForOmciProcessor) |
| 2859 | waitForOmciProcessor.Wait() |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2860 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2861 | if !dh.GetAlarmManagerIsRunning(ctx) { |
| 2862 | go dh.StartAlarmManager(ctx) |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2863 | } |
| 2864 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2865 | // Start flow handler routines per UNI |
| 2866 | for _, uniPort := range dh.uniEntityMap { |
| 2867 | // only if this port was enabled for use by the operator at startup |
| 2868 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 2869 | if !dh.GetFlowMonitoringIsRunning(uniPort.UniID) { |
| 2870 | go dh.PerOnuFlowHandlerRoutine(uniPort.UniID) |
| 2871 | } |
| 2872 | } |
| 2873 | } |
| 2874 | |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2875 | // Initialize classical L2 PM Interval Counters |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2876 | if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventInit); err != nil { |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2877 | // There is no way we should be landing here, but if we do then |
| 2878 | // there is nothing much we can do about this other than log error |
| 2879 | logger.Errorw(ctx, "error starting l2 pm fsm", log.Fields{"device-id": dh.device.Id, "err": err}) |
| 2880 | } |
| 2881 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2882 | dh.SetReadyForOmciConfig(true) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2883 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2884 | pDevEntry.MutexPersOnuConfig.RLock() |
| 2885 | if dh.IsReconciling() && pDevEntry.SOnuPersistentData.PersUniDisableDone { |
| 2886 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2887 | 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] | 2888 | log.Fields{"device-id": dh.DeviceID}) |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 2889 | dh.mutexForDisableDeviceRequested.Lock() |
| 2890 | dh.disableDeviceRequested = true |
| 2891 | dh.mutexForDisableDeviceRequested.Unlock() |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 2892 | dh.ReconcileDeviceTechProf(ctx) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2893 | // reconcilement will be continued after ani config is done |
| 2894 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2895 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2896 | // *** should generate UniUnlockStateDone event ***** |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 2897 | dh.mutexForDisableDeviceRequested.RLock() |
| 2898 | if !dh.disableDeviceRequested { |
| 2899 | if dh.pUnlockStateFsm == nil { |
| 2900 | dh.createUniLockFsm(ctx, false, cmn.UniUnlockStateDone) |
| 2901 | } else { //UnlockStateFSM already init |
| 2902 | dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniUnlockStateDone) |
| 2903 | dh.runUniLockFsm(ctx, false) |
| 2904 | } |
| 2905 | dh.mutexForDisableDeviceRequested.RUnlock() |
| 2906 | } else { |
| 2907 | dh.mutexForDisableDeviceRequested.RUnlock() |
| 2908 | logger.Debugw(ctx, "Uni already lock", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2909 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2910 | } |
| 2911 | } |
| 2912 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2913 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2914 | func (dh *deviceHandler) processUniUnlockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2915 | dh.EnableUniPortStateUpdate(ctx) //cmp python yield self.enable_ports() |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2916 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2917 | if !dh.IsReconciling() { |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 2918 | // Check if TPs are available post device reboot. If TPs are available start processing them and configure flows |
| 2919 | if dh.GetDeviceTechProfOnReboot() { |
| 2920 | if dh.CheckForDeviceTechProf(ctx) { |
| 2921 | go dh.DeviceFlowConfigOnReboot(ctx) |
| 2922 | } |
| 2923 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2924 | 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] | 2925 | raisedTs := time.Now().Unix() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2926 | go dh.sendOnuOperStateEvent(ctx, voltha.OperStatus_ACTIVE, dh.DeviceID, raisedTs) //cmp python onu_active_event |
| 2927 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2928 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2929 | 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] | 2930 | return |
| 2931 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2932 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2933 | pDevEntry.SOnuPersistentData.PersUniUnlockDone = true |
| 2934 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2935 | if err := dh.StorePersistentData(ctx); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2936 | 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] | 2937 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2938 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2939 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2940 | 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] | 2941 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 2942 | dh.ReconcileDeviceTechProf(ctx) |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 2943 | |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2944 | // reconcilement will be continued after ani config is done |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 2945 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2946 | } |
| 2947 | } |
| 2948 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2949 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2950 | func (dh *deviceHandler) processUniDisableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2951 | logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2952 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2953 | |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2954 | // disable device should have no impact on ConnStatus |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2955 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2956 | DeviceId: dh.DeviceID, |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2957 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2958 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 2959 | }); err != nil { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2960 | //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] | 2961 | 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] | 2962 | } |
| 2963 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2964 | 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] | 2965 | // 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] | 2966 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciAdminLock, true) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2967 | |
| 2968 | //transfer the modified logical uni port state |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2969 | dh.DisableUniPortStateUpdate(ctx) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2970 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2971 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2972 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2973 | 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] | 2974 | return |
| 2975 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2976 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2977 | pDevEntry.SOnuPersistentData.PersUniDisableDone = true |
| 2978 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2979 | if err := dh.StorePersistentData(ctx); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2980 | 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] | 2981 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2982 | } |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2983 | } |
| 2984 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2985 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2986 | func (dh *deviceHandler) processUniEnableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2987 | 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] | 2988 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID}) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2989 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2990 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2991 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2992 | OperStatus: voltha.OperStatus_ACTIVE, |
| 2993 | }); err != nil { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2994 | //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] | 2995 | 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] | 2996 | } |
| 2997 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2998 | logger.Debugw(ctx, "DeviceReasonUpdate upon re-enable", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2999 | "reason": cmn.DeviceReasonMap[cmn.DrOnuReenabled], "device-id": dh.DeviceID}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3000 | // 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] | 3001 | _ = dh.ReasonUpdate(ctx, cmn.DrOnuReenabled, true) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3002 | |
| 3003 | //transfer the modified logical uni port state |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3004 | dh.EnableUniPortStateUpdate(ctx) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3005 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3006 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3007 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3008 | 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] | 3009 | return |
| 3010 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3011 | pDevEntry.MutexPersOnuConfig.Lock() |
| 3012 | pDevEntry.SOnuPersistentData.PersUniDisableDone = false |
| 3013 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 3014 | if err := dh.StorePersistentData(ctx); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3015 | 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] | 3016 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3017 | } |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3018 | } |
| 3019 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3020 | //nolint:unparam |
| Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 3021 | func (dh *deviceHandler) processUniEnableStateFailedEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 3022 | logger.Debugw(ctx, "DeviceStateUpdate upon re-enable failure. ", log.Fields{ |
| 3023 | "OperStatus": voltha.OperStatus_FAILED, "device-id": dh.DeviceID}) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3024 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 3025 | DeviceId: dh.DeviceID, |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 3026 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
| Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 3027 | OperStatus: voltha.OperStatus_FAILED, |
| 3028 | }); err != nil { |
| 3029 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| 3030 | } |
| 3031 | } |
| 3032 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3033 | func (dh *deviceHandler) processOmciAniConfigDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 3034 | if devEvent == cmn.OmciAniConfigDone { |
| 3035 | logger.Debugw(ctx, "OmciAniConfigDone event received", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3036 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 3037 | // - which may cause some inconsistency |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3038 | if dh.getDeviceReason() != cmn.DrTechProfileConfigDownloadSuccess { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 3039 | // 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] | 3040 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3041 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3042 | if dh.IsReconciling() { |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 3043 | // during reconciling with OMCI configuration in TT multi-UNI scenario, OmciAniConfigDone is reached several times |
| 3044 | // therefore it must be ensured that reconciling of flow config is only started on the first pass of this code position |
| 3045 | dh.mutexReconcilingFirstPassFlag.Lock() |
| 3046 | if dh.reconcilingFirstPass { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3047 | 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] | 3048 | dh.reconcilingFirstPass = false |
| 3049 | go dh.ReconcileDeviceFlowConfig(ctx) |
| 3050 | } |
| 3051 | dh.mutexReconcilingFirstPassFlag.Unlock() |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3052 | } |
| 3053 | } else { // should be the OmciAniResourceRemoved block |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3054 | logger.Debugw(ctx, "OmciAniResourceRemoved event received", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3055 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 3056 | // - which may cause some inconsistency |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3057 | if dh.getDeviceReason() != cmn.DrTechProfileConfigDeleteSuccess { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 3058 | // which may be the case from some previous activity even on this ONU port (but also other UNI ports) |
| 3059 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDeleteSuccess, true) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3060 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3061 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3062 | } |
| 3063 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3064 | func (dh *deviceHandler) processOmciVlanFilterDoneEvent(ctx context.Context, aDevEvent cmn.OnuDeviceEvent) { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3065 | logger.Debugw(ctx, "OmciVlanFilterDone event received", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3066 | log.Fields{"device-id": dh.DeviceID, "event": aDevEvent}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3067 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 3068 | // - which may cause some inconsistency |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3069 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3070 | if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterAddDoneNoKvStore { |
| 3071 | if dh.getDeviceReason() != cmn.DrOmciFlowsPushed { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 3072 | // 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] | 3073 | // or even some previous flow add activity on the same port |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 3074 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsPushed, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3075 | } |
| 3076 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3077 | if dh.getDeviceReason() != cmn.DrOmciFlowsDeleted { |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3078 | //not relevant for reconcile |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 3079 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsDeleted, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3080 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3081 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3082 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3083 | if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterRemDone { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3084 | //events that request KvStore write |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3085 | if err := dh.StorePersistentData(ctx); err != nil { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3086 | 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] | 3087 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3088 | } |
| 3089 | } else { |
| 3090 | logger.Debugw(ctx, "OmciVlanFilter*Done* - write to KvStore not requested", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3091 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3092 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3093 | } |
| 3094 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3095 | // DeviceProcStatusUpdate evaluates possible processing events and initiates according next activities |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3096 | func (dh *deviceHandler) DeviceProcStatusUpdate(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3097 | switch devEvent { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3098 | case cmn.MibDatabaseSync: |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3099 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3100 | dh.processMibDatabaseSyncEvent(ctx, devEvent) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3101 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3102 | case cmn.UniLockStateDone: |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 3103 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3104 | dh.processUniLockStateDoneEvent(ctx, devEvent) |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 3105 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3106 | case cmn.MibDownloadDone: |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3107 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3108 | dh.processMibDownloadDoneEvent(ctx, devEvent) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3109 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3110 | case cmn.UniUnlockStateDone: |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3111 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3112 | dh.processUniUnlockStateDoneEvent(ctx, devEvent) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3113 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3114 | case cmn.UniEnableStateDone: |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3115 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3116 | dh.processUniEnableStateDoneEvent(ctx, devEvent) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3117 | } |
| Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 3118 | case cmn.UniEnableStateFailed: |
| 3119 | { |
| 3120 | dh.processUniEnableStateFailedEvent(ctx, devEvent) |
| 3121 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3122 | case cmn.UniDisableStateDone: |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3123 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3124 | dh.processUniDisableStateDoneEvent(ctx, devEvent) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3125 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3126 | case cmn.OmciAniConfigDone, cmn.OmciAniResourceRemoved: |
| mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 3127 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3128 | dh.processOmciAniConfigDoneEvent(ctx, devEvent) |
| mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 3129 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3130 | case cmn.OmciVlanFilterAddDone, cmn.OmciVlanFilterAddDoneNoKvStore, cmn.OmciVlanFilterRemDone, cmn.OmciVlanFilterRemDoneNoKvStore: |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3131 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3132 | dh.processOmciVlanFilterDoneEvent(ctx, devEvent) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3133 | } |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3134 | default: |
| 3135 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3136 | 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] | 3137 | } |
| 3138 | } //switch |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 3139 | } |
| 3140 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3141 | 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] | 3142 | // parameters are IntfId, OnuId, uniId |
| Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 3143 | uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3144 | uint32(aUniID)) |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3145 | if _, present := dh.uniEntityMap[uniNo]; present { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3146 | 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] | 3147 | } else { |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3148 | //with arguments aUniID, a_portNo, aPortType |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3149 | pUniPort := cmn.NewOnuUniPort(ctx, aUniID, uniNo, aUniInstNo, aPortType) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 3150 | if pUniPort == nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3151 | 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] | 3152 | } else { |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3153 | //store UniPort with the System-PortNumber key |
| 3154 | dh.uniEntityMap[uniNo] = pUniPort |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3155 | if !dh.IsReconciling() { |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 3156 | // create announce the UniPort to the core as VOLTHA Port object |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3157 | if err := pUniPort.CreateVolthaPort(ctx, dh); err == nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3158 | 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] | 3159 | } //error logging already within UniPort method |
| 3160 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3161 | 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] | 3162 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 3163 | } |
| 3164 | } |
| 3165 | } |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3166 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3167 | func (dh *deviceHandler) AddAllUniPorts(ctx context.Context) { |
| 3168 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3169 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3170 | 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] | 3171 | return |
| 3172 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3173 | 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] | 3174 | if pptpInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3175 | ctx, me.PhysicalPathTerminationPointEthernetUniClassID); len(pptpInstKeys) > 0 { |
| 3176 | for _, mgmtEntityID := range pptpInstKeys { |
| 3177 | logger.Debugw(ctx, "Add PPTPEthUni port for MIB-stored instance:", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3178 | "device-id": dh.DeviceID, "PPTPEthUni EntityID": mgmtEntityID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3179 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniPPTP) |
| 3180 | uniCnt++ |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3181 | } |
| 3182 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3183 | 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] | 3184 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3185 | if veipInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3186 | ctx, me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 { |
| 3187 | for _, mgmtEntityID := range veipInstKeys { |
| 3188 | logger.Debugw(ctx, "Add VEIP for MIB-stored instance:", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3189 | "device-id": dh.DeviceID, "VEIP EntityID": mgmtEntityID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3190 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniVEIP) |
| 3191 | uniCnt++ |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3192 | } |
| 3193 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3194 | 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] | 3195 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3196 | if potsInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
| ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 3197 | ctx, me.PhysicalPathTerminationPointPotsUniClassID); len(potsInstKeys) > 0 { |
| 3198 | for _, mgmtEntityID := range potsInstKeys { |
| 3199 | 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] | 3200 | "device-id": dh.DeviceID, "PPTP Pots UNI EntityID": mgmtEntityID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3201 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniPPTPPots) |
| 3202 | uniCnt++ |
| ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 3203 | } |
| 3204 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3205 | 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] | 3206 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3207 | if uniCnt == 0 { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3208 | 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] | 3209 | return |
| 3210 | } |
| 3211 | |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 3212 | //Note: For the moment is is not required to include the (newly added) POTS ports into the range |
| 3213 | // of flowCall or reconcile channels. But some sort of flow and reconcile processing might get necessary |
| 3214 | // 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] | 3215 | dh.flowCbChan = make([]chan FlowCb, uniCnt) |
| 3216 | dh.stopFlowMonitoringRoutine = make([]chan bool, uniCnt) |
| 3217 | dh.isFlowMonitoringRoutineActive = make([]bool, uniCnt) |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 3218 | //chUniVlanConfigReconcilingDone needs to have the capacity of all UniPorts as flow reconcile may run parallel for all of them |
| 3219 | dh.chUniVlanConfigReconcilingDone = make(chan uint16, uniCnt) |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 3220 | dh.chUniVlanConfigOnRebootDone = make(chan uint16, uniCnt) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3221 | for i := 0; i < int(uniCnt); i++ { |
| 3222 | dh.flowCbChan[i] = make(chan FlowCb, dh.pOpenOnuAc.config.MaxConcurrentFlowsPerUni) |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 3223 | dh.stopFlowMonitoringRoutine[i] = make(chan bool, 1) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3224 | } |
| 3225 | } |
| 3226 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3227 | // EnableUniPortStateUpdate enables UniPortState and update core port state accordingly |
| 3228 | func (dh *deviceHandler) EnableUniPortStateUpdate(ctx context.Context) { |
| Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 3229 | // 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] | 3230 | // but towards core only the first port active state is signaled |
| Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 3231 | // with following remark: |
| 3232 | // # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow |
| 3233 | // # load on the core |
| 3234 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3235 | // 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] | 3236 | |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3237 | for uniNo, uniPort := range dh.uniEntityMap { |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3238 | // only if this port is validated for operState transfer |
| 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-ACTIVE", 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_ACTIVE) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3242 | if !dh.IsReconciling() { |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +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 | f41a160 | 2020-08-19 09:52:50 +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 | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 3256 | } |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3257 | } |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | // Disable UniPortState and update core port state accordingly |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3262 | func (dh *deviceHandler) DisableUniPortStateUpdate(ctx context.Context) { |
| 3263 | // compare EnableUniPortStateUpdate() above |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3264 | // -> use current restriction to operate only on first UNI port as inherited from actual Py code |
| 3265 | for uniNo, uniPort := range dh.uniEntityMap { |
| 3266 | // only if this port is validated for operState transfer |
| Matteo Scandolo | 20d180c | 2021-06-10 17:20:21 +0200 | [diff] [blame] | 3267 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3268 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 3269 | 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] | 3270 | uniPort.SetOperState(common.OperStatus_UNKNOWN) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3271 | if !dh.IsReconciling() { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3272 | //maybe also use getter functions on uniPort - perhaps later ... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3273 | go func(port *cmn.OnuUniPort) { |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3274 | if err := dh.updatePortStateInCore(ctx, &ca.PortState{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3275 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3276 | PortType: voltha.Port_ETHERNET_UNI, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3277 | PortNo: port.PortNo, |
| 3278 | OperStatus: port.OperState, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3279 | }); err != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3280 | 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] | 3281 | } |
| 3282 | }(uniPort) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3283 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3284 | 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] | 3285 | } |
| 3286 | |
| Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 3287 | } |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3288 | } |
| 3289 | } |
| 3290 | |
| 3291 | // ONU_Active/Inactive announcement on system KAFKA bus |
| 3292 | // 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] | 3293 | 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] | 3294 | var de voltha.DeviceEvent |
| 3295 | eventContext := make(map[string]string) |
| 3296 | //Populating event context |
| 3297 | // 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] | 3298 | parentDevice, err := dh.getDeviceFromCore(ctx, dh.parentID) |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3299 | if err != nil || parentDevice == nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3300 | logger.Errorw(ctx, "Failed to fetch parent device for OnuEvent", |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3301 | log.Fields{"device-id": dh.DeviceID, "parentID": dh.parentID, "err": err}) |
| Holger Hildebrandt | 7ec14c4 | 2021-05-28 14:21:58 +0000 | [diff] [blame] | 3302 | 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] | 3303 | } |
| 3304 | oltSerialNumber := parentDevice.SerialNumber |
| 3305 | |
| 3306 | eventContext["pon-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.IntfId), 10) |
| 3307 | eventContext["onu-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.OnuId), 10) |
| 3308 | eventContext["serial-number"] = dh.device.SerialNumber |
| ssiddiqui | 1221d1a | 2021-02-15 11:12:51 +0530 | [diff] [blame] | 3309 | eventContext["olt-serial-number"] = oltSerialNumber |
| 3310 | eventContext["device-id"] = aDeviceID |
| 3311 | eventContext["registration-id"] = aDeviceID //py: string(device_id)?? |
| ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 3312 | eventContext["num-of-unis"] = strconv.Itoa(len(dh.uniEntityMap)) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3313 | if deviceEntry := dh.GetOnuDeviceEntry(ctx, false); deviceEntry != nil { |
| 3314 | deviceEntry.MutexPersOnuConfig.RLock() |
| Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 3315 | eventContext["vendor-id"] = deviceEntry.SOnuPersistentData.PersVendorID |
| 3316 | eventContext["model"] = deviceEntry.SOnuPersistentData.PersVersion |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3317 | eventContext["equipment-id"] = deviceEntry.SOnuPersistentData.PersEquipmentID |
| 3318 | deviceEntry.MutexPersOnuConfig.RUnlock() |
| 3319 | eventContext["software-version"] = deviceEntry.GetActiveImageVersion(ctx) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3320 | eventContext["inactive-software-version"] = deviceEntry.GetInactiveImageVersion(ctx) |
| ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 3321 | logger.Debugw(ctx, "prepare ONU_ACTIVATED event", |
| 3322 | log.Fields{"device-id": aDeviceID, "EventContext": eventContext}) |
| 3323 | } else { |
| 3324 | logger.Errorw(ctx, "Failed to fetch device-entry. ONU_ACTIVATED event is not sent", |
| 3325 | log.Fields{"device-id": aDeviceID}) |
| 3326 | return |
| 3327 | } |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3328 | |
| 3329 | /* Populating device event body */ |
| 3330 | de.Context = eventContext |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3331 | de.ResourceId = aDeviceID |
| 3332 | if aOperState == voltha.OperStatus_ACTIVE { |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3333 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "RAISE_EVENT") |
| 3334 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 3335 | cEventObjectType, cOnuActivatedEvent, "Raised") |
| 3336 | } else { |
| 3337 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "CLEAR_EVENT") |
| 3338 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 3339 | cEventObjectType, cOnuActivatedEvent, "Cleared") |
| 3340 | } |
| 3341 | /* Send event to KAFKA */ |
| kesavand | 510a31c | 2022-03-16 17:12:12 +0530 | [diff] [blame] | 3342 | if err := dh.EventProxy.SendDeviceEventWithKey(ctx, &de, equipment, pon, raisedTs, aDeviceID); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3343 | logger.Warnw(ctx, "could not send ONU_ACTIVATED event", |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3344 | log.Fields{"device-id": aDeviceID, "error": err}) |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3345 | } |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3346 | logger.Infow(ctx, "ctx, ONU_ACTIVATED event sent to KAFKA", |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3347 | log.Fields{"device-id": aDeviceID, "with-EventName": de.DeviceEventName}) |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3348 | } |
| 3349 | |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3350 | // 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] | 3351 | 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] | 3352 | chLSFsm := make(chan cmn.Message, 2) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3353 | var sFsmName string |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3354 | if aAdminState { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3355 | logger.Debugw(ctx, "createLockStateFSM", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3356 | sFsmName = "LockStateFSM" |
| 3357 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3358 | logger.Debugw(ctx, "createUnlockStateFSM", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3359 | sFsmName = "UnLockStateFSM" |
| 3360 | } |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3361 | |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 3362 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3363 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3364 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3365 | return |
| 3366 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3367 | pLSFsm := uniprt.NewLockStateFsm(ctx, aAdminState, devEvent, sFsmName, dh, pDevEntry, chLSFsm) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3368 | if pLSFsm != nil { |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3369 | if aAdminState { |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3370 | dh.pLockStateFsm = pLSFsm |
| 3371 | } else { |
| 3372 | dh.pUnlockStateFsm = pLSFsm |
| 3373 | } |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3374 | dh.runUniLockFsm(ctx, aAdminState) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3375 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3376 | 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] | 3377 | } |
| 3378 | } |
| 3379 | |
| 3380 | // 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] | 3381 | func (dh *deviceHandler) runUniLockFsm(ctx context.Context, aAdminState bool) { |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3382 | /* Uni Port lock/unlock procedure - |
| 3383 | ***** should run via 'adminDone' state and generate the argument requested event ***** |
| 3384 | */ |
| 3385 | var pLSStatemachine *fsm.FSM |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3386 | if aAdminState { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3387 | pLSStatemachine = dh.pLockStateFsm.PAdaptFsm.PFsm |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3388 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 3389 | if (dh.pUnlockStateFsm != nil) && |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3390 | (dh.pUnlockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) { |
| 3391 | _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3392 | } |
| 3393 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3394 | pLSStatemachine = dh.pUnlockStateFsm.PAdaptFsm.PFsm |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3395 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 3396 | if (dh.pLockStateFsm != nil) && |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3397 | (dh.pLockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) { |
| 3398 | _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3399 | } |
| 3400 | } |
| 3401 | if pLSStatemachine != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3402 | if pLSStatemachine.Is(uniprt.UniStDisabled) { |
| 3403 | if err := pLSStatemachine.Event(uniprt.UniEvStart); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3404 | 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] | 3405 | // maybe try a FSM reset and then again ... - TODO!!! |
| 3406 | } else { |
| 3407 | /***** LockStateFSM started */ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3408 | logger.Debugw(ctx, "LockStateFSM started", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3409 | "state": pLSStatemachine.Current(), "device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3410 | } |
| 3411 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3412 | logger.Warnw(ctx, "wrong state of LockStateFSM - want: disabled", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3413 | "have": pLSStatemachine.Current(), "device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3414 | // maybe try a FSM reset and then again ... - TODO!!! |
| 3415 | } |
| 3416 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3417 | 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] | 3418 | // maybe try a FSM reset and then again ... - TODO!!! |
| 3419 | } |
| 3420 | } |
| 3421 | |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3422 | // createOnuUpgradeFsm initializes and runs the Onu Software upgrade FSM |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3423 | // precondition: lockUpgradeFsm is already locked from caller of this function |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3424 | // |
| 3425 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3426 | 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] | 3427 | chUpgradeFsm := make(chan cmn.Message, 2) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3428 | var sFsmName = "OnuSwUpgradeFSM" |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3429 | logger.Debugw(ctx, "create OnuSwUpgradeFSM", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3430 | if apDevEntry.PDevOmciCC == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3431 | 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] | 3432 | 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] | 3433 | } |
| bseeniva | 0b4286b | 2026-01-30 13:05:42 +0530 | [diff] [blame^] | 3434 | fsmCtx := log.WithSpanFromContext(context.Background(), ctx) |
| 3435 | dh.pOnuUpradeFsm = swupg.NewOnuUpgradeFsm(fsmCtx, dh, apDevEntry, apDevEntry.GetOnuDB(), aDevEvent, |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3436 | sFsmName, chUpgradeFsm) |
| 3437 | if dh.pOnuUpradeFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3438 | pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3439 | if pUpgradeStatemachine != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3440 | if pUpgradeStatemachine.Is(swupg.UpgradeStDisabled) { |
| 3441 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvStart); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3442 | 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] | 3443 | // maybe try a FSM reset and then again ... - TODO!!! |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3444 | 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] | 3445 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3446 | /***** Upgrade FSM started */ |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 3447 | //reset the last stored upgrade states (which anyway should be don't care as long as the newly created FSM exists) |
| 3448 | (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 3449 | (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR |
| 3450 | (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3451 | logger.Debugw(ctx, "OnuSwUpgradeFSM started", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3452 | "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3453 | } else { |
| 3454 | 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] | 3455 | "have": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3456 | // maybe try a FSM reset and then again ... - TODO!!! |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3457 | 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] | 3458 | } |
| 3459 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3460 | 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] | 3461 | // maybe try a FSM reset and then again ... - TODO!!! |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3462 | 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] | 3463 | } |
| 3464 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3465 | 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] | 3466 | 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] | 3467 | } |
| 3468 | return nil |
| 3469 | } |
| 3470 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3471 | // RemoveOnuUpgradeFsm clears the Onu Software upgrade FSM |
| 3472 | func (dh *deviceHandler) RemoveOnuUpgradeFsm(ctx context.Context, apImageState *voltha.ImageState) { |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3473 | logger.Debugw(ctx, "remove OnuSwUpgradeFSM StateMachine", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3474 | "device-id": dh.DeviceID}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3475 | dh.lockUpgradeFsm.Lock() |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3476 | dh.pOnuUpradeFsm = nil //resource clearing is left to garbage collector |
| 3477 | dh.upgradeCanceled = false //cancelation done |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 3478 | dh.pLastUpgradeImageState = apImageState |
| 3479 | dh.lockUpgradeFsm.Unlock() |
| 3480 | //signal upgradeFsm removed using non-blocking channel send |
| 3481 | select { |
| 3482 | case dh.upgradeFsmChan <- struct{}{}: |
| 3483 | default: |
| 3484 | 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] | 3485 | "device-id": dh.DeviceID}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 3486 | } |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3487 | } |
| 3488 | |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3489 | // checkOnOnuImageCommit verifies if the ONU is in some upgrade state that allows for image commit and if tries to commit |
| 3490 | func (dh *deviceHandler) checkOnOnuImageCommit(ctx context.Context) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3491 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3492 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3493 | 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] | 3494 | return |
| 3495 | } |
| 3496 | |
| 3497 | dh.lockUpgradeFsm.RLock() |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3498 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3499 | if dh.pOnuUpradeFsm != nil { |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3500 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 3501 | dh.lockUpgradeFsm.RUnlock() |
| 3502 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 3503 | return |
| 3504 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3505 | pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3506 | if pUpgradeStatemachine != nil { |
| 3507 | // commit is only processed in case out upgrade FSM indicates the according state (for automatic commit) |
| 3508 | // (some manual forced commit could do without) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3509 | UpgradeState := pUpgradeStatemachine.Current() |
| 3510 | if (UpgradeState == swupg.UpgradeStWaitForCommit) || |
| 3511 | (UpgradeState == swupg.UpgradeStRequestingActivate) { |
| 3512 | // 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] | 3513 | // 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] | 3514 | if pDevEntry.IsImageToBeCommitted(ctx, dh.pOnuUpradeFsm.InactiveImageMeID) { |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3515 | activeImageID, errImg := pDevEntry.GetActiveImageMeID(ctx) |
| 3516 | if errImg != nil { |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3517 | dh.lockUpgradeFsm.RUnlock() |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3518 | logger.Errorw(ctx, "OnuSwUpgradeFSM abort - could not get active image after reboot", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3519 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +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 | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3524 | return |
| 3525 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3526 | dh.lockUpgradeFsm.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3527 | if activeImageID == dh.pOnuUpradeFsm.InactiveImageMeID { |
| 3528 | if (UpgradeState == swupg.UpgradeStRequestingActivate) && !dh.pOnuUpradeFsm.GetCommitFlag(ctx) { |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3529 | // 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] | 3530 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvActivationDone); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3531 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call activate-done event", |
| 3532 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3533 | return |
| 3534 | } |
| 3535 | logger.Debugw(ctx, "OnuSwUpgradeFSM activate-done after reboot", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3536 | "state": UpgradeState, "device-id": dh.DeviceID}) |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3537 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3538 | //FSM in waitForCommit or (UpgradeStRequestingActivate [lost ActivateResp] and commit allowed) |
| 3539 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvCommitSw); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3540 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call commit event", |
| 3541 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3542 | return |
| 3543 | } |
| 3544 | logger.Debugw(ctx, "OnuSwUpgradeFSM commit image requested", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3545 | "state": UpgradeState, "device-id": dh.DeviceID}) |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3546 | } |
| 3547 | } else { |
| 3548 | 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] | 3549 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 3550 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 3551 | dh.upgradeCanceled = true |
| 3552 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 3553 | } |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3554 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3555 | return |
| 3556 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3557 | dh.lockUpgradeFsm.RUnlock() |
| 3558 | logger.Errorw(ctx, "OnuSwUpgradeFSM waiting to commit, but nothing to commit on ONU - abort upgrade", |
| 3559 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 3560 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 3561 | dh.upgradeCanceled = true |
| 3562 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 3563 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3564 | return |
| 3565 | } |
| 3566 | //upgrade FSM is active but not waiting for commit: maybe because commit flag is not set |
| 3567 | // upgrade FSM is to be informed if the current active image is the one that was used in upgrade for the download |
| 3568 | if activeImageID, err := pDevEntry.GetActiveImageMeID(ctx); err == nil { |
| 3569 | if dh.pOnuUpradeFsm.InactiveImageMeID == activeImageID { |
| 3570 | logger.Debugw(ctx, "OnuSwUpgradeFSM image state set to activated", log.Fields{ |
| 3571 | "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
| 3572 | dh.pOnuUpradeFsm.SetImageStateActive(ctx) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 3573 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3574 | } |
| 3575 | } |
| 3576 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3577 | 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] | 3578 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3579 | dh.lockUpgradeFsm.RUnlock() |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3580 | } |
| 3581 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3582 | // 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] | 3583 | func (dh *deviceHandler) SetBackend(ctx context.Context, aBasePathKvStore string) *db.Backend { |
| Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 3584 | |
| 3585 | logger.Debugw(ctx, "SetKVStoreBackend", log.Fields{"IpTarget": dh.pOpenOnuAc.KVStoreAddress, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3586 | "BasePathKvStore": aBasePathKvStore, "device-id": dh.DeviceID}) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 3587 | // 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] | 3588 | kvbackend := &db.Backend{ |
| 3589 | Client: dh.pOpenOnuAc.kvClient, |
| 3590 | StoreType: dh.pOpenOnuAc.KVStoreType, |
| 3591 | /* address config update acc. to [VOL-2736] */ |
| Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 3592 | Address: dh.pOpenOnuAc.KVStoreAddress, |
| mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 3593 | Timeout: dh.pOpenOnuAc.KVStoreTimeout, |
| 3594 | PathPrefix: aBasePathKvStore} |
| Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 3595 | |
| mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 3596 | return kvbackend |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3597 | } |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3598 | |
| 3599 | //nolint:unparam |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3600 | func (dh *deviceHandler) getFlowOfbFields(ctx context.Context, apFlowItem *of.OfpFlowStats, loMatchVlan *uint16, |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3601 | loMatchPcp *uint8, loIPProto *uint32) { |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3602 | |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3603 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 3604 | switch field.Type { |
| 3605 | case of.OxmOfbFieldTypes_OFPXMT_OFB_ETH_TYPE: |
| 3606 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3607 | logger.Debugw(ctx, "flow type EthType", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3608 | "EthType": strconv.FormatInt(int64(field.GetEthType()), 16)}) |
| 3609 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3610 | /* TT related temporary workaround - should not be needed anymore |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3611 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO: |
| 3612 | { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3613 | *loIPProto = field.GetIpProto() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3614 | logger.Debugw("flow type IpProto", log.Fields{"device-id": dh.DeviceID, |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3615 | "IpProto": strconv.FormatInt(int64(*loIPProto), 16)}) |
| 3616 | if *loIPProto == 2 { |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3617 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 3618 | // avoids installing invalid EVTOCD rule |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3619 | logger.Debugw("flow type IpProto 2: TT workaround: ignore flow", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3620 | log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3621 | return |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3622 | } |
| 3623 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3624 | */ |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3625 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID: |
| 3626 | { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3627 | *loMatchVlan = uint16(field.GetVlanVid()) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3628 | loMatchVlanMask := uint16(field.GetVlanVidMask()) |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 3629 | if *loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) || |
| 3630 | loMatchVlanMask != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3631 | *loMatchVlan = *loMatchVlan & 0xFFF // not transparent: copy only ID bits |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3632 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3633 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3634 | "VID": strconv.FormatInt(int64(*loMatchVlan), 16)}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3635 | } |
| 3636 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP: |
| 3637 | { |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3638 | *loMatchPcp = uint8(field.GetVlanPcp()) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3639 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3640 | "PCP": loMatchPcp}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3641 | } |
| 3642 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_DST: |
| 3643 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3644 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3645 | "UDP-DST": strconv.FormatInt(int64(field.GetUdpDst()), 16)}) |
| 3646 | } |
| 3647 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_SRC: |
| 3648 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3649 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3650 | "UDP-SRC": strconv.FormatInt(int64(field.GetUdpSrc()), 16)}) |
| 3651 | } |
| 3652 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_DST: |
| 3653 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3654 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3655 | "IPv4-DST": field.GetIpv4Dst()}) |
| 3656 | } |
| 3657 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_SRC: |
| 3658 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3659 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3660 | "IPv4-SRC": field.GetIpv4Src()}) |
| 3661 | } |
| 3662 | case of.OxmOfbFieldTypes_OFPXMT_OFB_METADATA: |
| 3663 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3664 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3665 | "Metadata": field.GetTableMetadata()}) |
| 3666 | } |
| 3667 | /* |
| 3668 | default: |
| 3669 | { |
| 3670 | //all other entires ignored |
| 3671 | } |
| 3672 | */ |
| 3673 | } |
| 3674 | } //for all OfbFields |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3675 | } |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3676 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3677 | 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] | 3678 | for _, action := range flow.GetActions(apFlowItem) { |
| 3679 | switch action.Type { |
| 3680 | /* not used: |
| 3681 | case of.OfpActionType_OFPAT_OUTPUT: |
| 3682 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3683 | logger.Debugw("flow action type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3684 | "Output": action.GetOutput()}) |
| 3685 | } |
| 3686 | */ |
| 3687 | case of.OfpActionType_OFPAT_PUSH_VLAN: |
| 3688 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3689 | logger.Debugw(ctx, "flow action type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3690 | "PushEthType": strconv.FormatInt(int64(action.GetPush().Ethertype), 16)}) |
| 3691 | } |
| 3692 | case of.OfpActionType_OFPAT_SET_FIELD: |
| 3693 | { |
| 3694 | pActionSetField := action.GetSetField() |
| 3695 | if pActionSetField.Field.OxmClass != of.OfpOxmClass_OFPXMC_OPENFLOW_BASIC { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3696 | 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] | 3697 | "OxcmClass": pActionSetField.Field.OxmClass}) |
| 3698 | } |
| 3699 | if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3700 | *loSetVlan = uint16(pActionSetField.Field.GetOfbField().GetVlanVid()) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3701 | 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] | 3702 | "SetVlan": strconv.FormatInt(int64(*loSetVlan), 16)}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3703 | } else if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3704 | *loSetPcp = uint8(pActionSetField.Field.GetOfbField().GetVlanPcp()) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3705 | 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] | 3706 | "SetPcp": *loSetPcp}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3707 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3708 | 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] | 3709 | "Type": pActionSetField.Field.GetOfbField().Type}) |
| 3710 | } |
| 3711 | } |
| 3712 | /* |
| 3713 | default: |
| 3714 | { |
| 3715 | //all other entires ignored |
| 3716 | } |
| 3717 | */ |
| 3718 | } |
| 3719 | } //for all Actions |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3720 | } |
| 3721 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3722 | // addFlowItemToUniPort parses the actual flow item to add it to the UniPort |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3723 | func (dh *deviceHandler) addFlowItemToUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort, |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3724 | apFlowMetaData *of.FlowMetadata, respChan *chan error) { |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 3725 | var loSetVlan = uint16(of.OfpVlanId_OFPVID_NONE) //noValidEntry |
| 3726 | var loMatchVlan = uint16(of.OfpVlanId_OFPVID_PRESENT) //reserved VLANID entry |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3727 | var loSetPcp uint8 |
| 3728 | 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] | 3729 | var loIPProto uint32 |
| 3730 | /* the TechProfileId is part of the flow Metadata - compare also comment within |
| 3731 | * OLT-Adapter:openolt_flowmgr.go |
| 3732 | * Metadata 8 bytes: |
| 3733 | * Most Significant 2 Bytes = Inner VLAN |
| 3734 | * Next 2 Bytes = Tech Profile ID(TPID) |
| 3735 | * Least Significant 4 Bytes = Port ID |
| 3736 | * Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all |
| 3737 | * subscriber related flows. |
| 3738 | */ |
| 3739 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3740 | metadata := flow.GetMetadataFromWriteMetadataAction(ctx, apFlowItem) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3741 | if metadata == 0 { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3742 | logger.Debugw(ctx, "flow-add invalid metadata - abort", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3743 | log.Fields{"device-id": dh.DeviceID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3744 | *respChan <- fmt.Errorf("flow-add invalid metadata: %s", dh.DeviceID) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3745 | } |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3746 | loTpID := uint8(flow.GetTechProfileIDFromWriteMetaData(ctx, metadata)) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3747 | loCookie := apFlowItem.GetCookie() |
| 3748 | loCookieSlice := []uint64{loCookie} |
| Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 3749 | loInnerCvlan := flow.GetInnerTagFromWriteMetaData(ctx, metadata) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3750 | 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] | 3751 | "TechProf-Id": loTpID, "cookie": loCookie, "innerCvlan": loInnerCvlan}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3752 | |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3753 | dh.getFlowOfbFields(ctx, apFlowItem, &loMatchVlan, &loMatchPcp, &loIPProto) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3754 | /* TT related temporary workaround - should not be needed anymore |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3755 | if loIPProto == 2 { |
| 3756 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 3757 | // avoids installing invalid EVTOCD rule |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3758 | logger.Debugw("flow-add type IpProto 2: TT workaround: ignore flow", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3759 | log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3760 | return nil |
| 3761 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3762 | */ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3763 | dh.getFlowActions(ctx, apFlowItem, &loSetPcp, &loSetVlan) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3764 | |
| Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 3765 | if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) && (loMatchPcp == 8) && |
| 3766 | loInnerCvlan == uint16(of.OfpVlanId_OFPVID_NONE) { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3767 | 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] | 3768 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3769 | "set_vid": strconv.FormatInt(int64(loSetVlan), 16), |
| 3770 | "match_vid": strconv.FormatInt(int64(loMatchVlan), 16)}) |
| 3771 | //TODO!!: Use DeviceId within the error response to rwCore |
| 3772 | // 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] | 3773 | *respChan <- fmt.Errorf("flow-add Set/Match VlanId inconsistent: %s", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3774 | } |
| 3775 | 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] | 3776 | 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] | 3777 | loSetVlan = loMatchVlan //both 'transparent' (copy any) |
| Abhilash Laxmeshwar | f15a0d0 | 2022-08-08 11:09:32 +0530 | [diff] [blame] | 3778 | } else if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) && |
| 3779 | loInnerCvlan != uint16(of.OfpVlanId_OFPVID_NONE) { |
| 3780 | loSetVlan = loMatchVlan |
| 3781 | 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] | 3782 | } else { |
| 3783 | //looks like OMCI value 4097 (copyFromOuter - for Uni double tagged) is not supported here |
| 3784 | if loSetVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
| 3785 | // not set to transparent |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3786 | loSetVlan &= 0x0FFF //mask VID bits as prerequisite for vlanConfigFsm |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3787 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3788 | logger.Debugw(ctx, "flow-add vlan-set", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3789 | } |
| mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3790 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3791 | var meter *of.OfpMeterConfig |
| ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3792 | if apFlowMetaData != nil { |
| 3793 | meter = apFlowMetaData.Meters[0] |
| 3794 | } |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3795 | //mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities |
| 3796 | // must be set including the execution of createVlanFilterFsm() to avoid unintended creation of FSM's |
| 3797 | // when different rules are requested concurrently for the same uni |
| 3798 | // (also vlan persistency data does not support multiple FSM's on the same UNI correctly!) |
| 3799 | dh.lockVlanAdd.Lock() //prevent multiple add activities to start in parallel |
| 3800 | dh.lockVlanConfig.RLock() //read protection on UniVlanConfigFsmMap (removeFlowItemFromUniPort) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3801 | logger.Debugw(ctx, "flow-add got lock", log.Fields{"device-id": dh.DeviceID, "tpID": loTpID, "uniID": apUniPort.UniID}) |
| 3802 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3803 | //SetUniFlowParams() may block on some rule that is suspended-to-add |
| 3804 | // 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] | 3805 | // Also the error is returned to caller via response channel |
| 3806 | _ = dh.UniVlanConfigFsmMap[apUniPort.UniID].SetUniFlowParams(ctx, loTpID, loCookieSlice, |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 3807 | loMatchVlan, loMatchPcp, loSetVlan, loSetPcp, loInnerCvlan, false, false, meter, respChan) |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3808 | dh.lockVlanConfig.RUnlock() |
| 3809 | dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3810 | return |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3811 | } |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3812 | dh.lockVlanConfig.RUnlock() |
| 3813 | 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] | 3814 | err := dh.createVlanFilterFsm(ctx, apUniPort, loTpID, loCookieSlice, |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 3815 | loMatchVlan, loMatchPcp, loSetVlan, loSetPcp, loInnerCvlan, cmn.OmciVlanFilterAddDone, false, false, meter, respChan) |
| mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3816 | dh.lockVlanConfig.Unlock() |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3817 | dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3818 | if err != nil { |
| 3819 | *respChan <- err |
| 3820 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3821 | } |
| 3822 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3823 | // removeFlowItemFromUniPort parses the actual flow item to remove it from the UniPort |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3824 | 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] | 3825 | //optimization and assumption: the flow cookie uniquely identifies the flow and with that the internal rule |
| 3826 | //hence only the cookie is used here to find the relevant flow and possibly remove the rule |
| 3827 | //no extra check is done on the rule parameters |
| 3828 | //accordingly the removal is done only once - for the first found flow with that cookie, even though |
| 3829 | // at flow creation is not assured, that the same cookie is not configured for different flows - just assumed |
| 3830 | //additionally it is assumed here, that removal can only be done for one cookie per flow in a sequence (different |
| 3831 | // 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] | 3832 | // - 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] | 3833 | loCookie := apFlowItem.GetCookie() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3834 | 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] | 3835 | |
| 3836 | /* TT related temporary workaround - should not be needed anymore |
| 3837 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 3838 | if field.Type == of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO { |
| 3839 | loIPProto := field.GetIpProto() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3840 | logger.Debugw(ctx, "flow type IpProto", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3841 | "IpProto": strconv.FormatInt(int64(loIPProto), 16)}) |
| 3842 | if loIPProto == 2 { |
| 3843 | // 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] | 3844 | logger.Debugw(ctx, "flow-remove type IpProto 2: TT workaround: ignore flow", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3845 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3846 | return nil |
| 3847 | } |
| 3848 | } |
| 3849 | } //for all OfbFields |
| 3850 | */ |
| 3851 | |
| mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3852 | //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] | 3853 | dh.lockVlanConfig.RLock() |
| 3854 | defer dh.lockVlanConfig.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3855 | logger.Debugw(ctx, "flow-remove got RLock", log.Fields{"device-id": dh.DeviceID, "uniID": apUniPort.UniID}) |
| 3856 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3857 | _ = dh.UniVlanConfigFsmMap[apUniPort.UniID].RemoveUniFlowParams(ctx, loCookie, respChan) |
| 3858 | return |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3859 | } |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3860 | 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] | 3861 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3862 | //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] | 3863 | // 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] | 3864 | // Push response on the response channel |
| 3865 | if respChan != nil { |
| 3866 | // 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 |
| 3867 | select { |
| 3868 | case *respChan <- nil: |
| 3869 | logger.Debugw(ctx, "submitted-response-for-flow", log.Fields{"device-id": dh.DeviceID, "err": nil}) |
| 3870 | default: |
| 3871 | } |
| 3872 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3873 | go dh.DeviceProcStatusUpdate(ctx, cmn.OmciVlanFilterRemDone) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3874 | } |
| 3875 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3876 | // createVlanFilterFsm initializes and runs the VlanFilter FSM to transfer OMCI related VLAN config |
| mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3877 | // 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] | 3878 | // precondition: dh.lockVlanConfig is locked by the caller! |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3879 | 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] | 3880 | 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] | 3881 | chVlanFilterFsm := make(chan cmn.Message, 2) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3882 | |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 3883 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3884 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3885 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 3886 | return fmt.Errorf("no valid OnuDevice for device-id %x - aborting", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3887 | } |
| 3888 | |
| Sridhar Ravindra | 2f86efb | 2024-12-06 11:02:10 +0530 | [diff] [blame] | 3889 | if dh.pDeviceStateFsm.Current() == devStDown { |
| 3890 | logger.Warnw(ctx, "UniVlanConfigFsm : aborting, device state down", log.Fields{"device-id": dh.DeviceID}) |
| 3891 | return fmt.Errorf("device state down for device-id %x - aborting", dh.DeviceID) |
| 3892 | } |
| 3893 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3894 | pVlanFilterFsm := avcfg.NewUniVlanConfigFsm(ctx, dh, pDevEntry, pDevEntry.PDevOmciCC, apUniPort, dh.pOnuTP, |
| 3895 | pDevEntry.GetOnuDB(), aTpID, aDevEvent, "UniVlanConfigFsm", chVlanFilterFsm, |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 3896 | dh.pOpenOnuAc.AcceptIncrementalEvto, aCookieSlice, aMatchVlan, aMatchPcp, aSetVlan, aSetPcp, innerCvlan, lastFlowToReconcile, lastFlowToConfOnReboot, aMeter, respChan) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3897 | if pVlanFilterFsm != nil { |
| mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3898 | //dh.lockVlanConfig is locked (by caller) throughout the state transition to 'starting' |
| 3899 | // to prevent unintended (ignored) events to be sent there (from parallel processing) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3900 | dh.UniVlanConfigFsmMap[apUniPort.UniID] = pVlanFilterFsm |
| 3901 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3902 | if pVlanFilterStatemachine != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3903 | if pVlanFilterStatemachine.Is(avcfg.VlanStDisabled) { |
| 3904 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvStart); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3905 | logger.Warnw(ctx, "UniVlanConfigFsm: can't start", |
| 3906 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3907 | return fmt.Errorf("can't start UniVlanConfigFsm for device-id %x", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3908 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3909 | /***** UniVlanConfigFsm started */ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3910 | logger.Debugw(ctx, "UniVlanConfigFsm started", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3911 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3912 | "UniPort": apUniPort.PortNo}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3913 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3914 | logger.Warnw(ctx, "wrong state of UniVlanConfigFsm - want: disabled", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3915 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID}) |
| 3916 | 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] | 3917 | } |
| 3918 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3919 | logger.Errorw(ctx, "UniVlanConfigFsm StateMachine invalid - cannot be executed!!", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3920 | "device-id": dh.DeviceID}) |
| 3921 | return fmt.Errorf("uniVlanConfigFsm invalid for device-id %x", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3922 | } |
| 3923 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3924 | logger.Errorw(ctx, "UniVlanConfigFsm could not be created - abort!!", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3925 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| 3926 | 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] | 3927 | } |
| 3928 | return nil |
| 3929 | } |
| 3930 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3931 | // VerifyVlanConfigRequest checks on existence of a given uniPort |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3932 | // and starts verification of flow config based on that |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3933 | func (dh *deviceHandler) VerifyVlanConfigRequest(ctx context.Context, aUniID uint8, aTpID uint8) { |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3934 | //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] | 3935 | var pCurrentUniPort *cmn.OnuUniPort |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3936 | for _, uniPort := range dh.uniEntityMap { |
| 3937 | // only if this port is validated for operState transfer |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3938 | if uniPort.UniID == uint8(aUniID) { |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3939 | pCurrentUniPort = uniPort |
| 3940 | break //found - end search loop |
| 3941 | } |
| 3942 | } |
| 3943 | if pCurrentUniPort == nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3944 | logger.Debugw(ctx, "VerifyVlanConfig aborted: requested uniID not found in PortDB", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3945 | log.Fields{"device-id": dh.DeviceID, "uni-id": aUniID}) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3946 | return |
| 3947 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3948 | dh.VerifyUniVlanConfigRequest(ctx, pCurrentUniPort, aTpID) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3949 | } |
| 3950 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3951 | // VerifyUniVlanConfigRequest checks on existence of flow configuration and starts it accordingly |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3952 | func (dh *deviceHandler) VerifyUniVlanConfigRequest(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8) { |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3953 | //TODO!! verify and start pending flow configuration |
| 3954 | //some pending config request my exist in case the UniVlanConfig FSM was already started - with internal data - |
| 3955 | //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] | 3956 | 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] | 3957 | dh.lockVlanConfig.RLock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3958 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3959 | dh.lockVlanConfig.RUnlock() |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3960 | //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] | 3961 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3962 | if pVlanFilterStatemachine != nil { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3963 | //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] | 3964 | if pVlanFilterFsm.GetWaitingTpID(ctx) == aTpID { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3965 | if pVlanFilterStatemachine.Is(avcfg.VlanStWaitingTechProf) { |
| 3966 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvContinueConfig); err != nil { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3967 | logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3968 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3969 | } else { |
| 3970 | /***** UniVlanConfigFsm continued */ |
| 3971 | logger.Debugw(ctx, "UniVlanConfigFsm continued", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3972 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3973 | "UniPort": apUniPort.PortNo}) |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3974 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3975 | } else if pVlanFilterStatemachine.Is(avcfg.VlanStIncrFlowWaitTP) { |
| 3976 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvIncrFlowConfig); err != nil { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3977 | logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3978 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3979 | } else { |
| 3980 | /***** UniVlanConfigFsm continued */ |
| 3981 | logger.Debugw(ctx, "UniVlanConfigFsm continued with incremental flow", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3982 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3983 | "UniPort": apUniPort.PortNo}) |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3984 | } |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3985 | } else { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3986 | logger.Debugw(ctx, "no state of UniVlanConfigFsm to be continued", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3987 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3988 | "UniPort": apUniPort.PortNo}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3989 | } |
| 3990 | } else { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3991 | 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] | 3992 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3993 | "UniPort": apUniPort.PortNo, "techprofile-id (done)": aTpID}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3994 | } |
| 3995 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3996 | 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] | 3997 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3998 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3999 | } else { |
| 4000 | dh.lockVlanConfig.RUnlock() |
| 4001 | } |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 4002 | } |
| 4003 | |
| Akash Soni | 3de0e06 | 2024-12-11 16:37:26 +0530 | [diff] [blame] | 4004 | // handleAniConfigFSMFailure handles the failure of the ANI config FSM by resetting the VLAN filter FSM |
| 4005 | func (dh *deviceHandler) HandleAniConfigFSMFailure(ctx context.Context, uniID uint8) { |
| 4006 | dh.lockVlanConfig.Lock() |
| 4007 | defer dh.lockVlanConfig.Unlock() |
| 4008 | |
| 4009 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniID]; exist { |
| 4010 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
| 4011 | if pVlanFilterStatemachine != nil { |
| 4012 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvReset); err != nil { |
| 4013 | logger.Warnw(ctx, "Failed to reset UniVlanConfigFsm", log.Fields{ |
| 4014 | "err": err, "device-id": dh.DeviceID, "UniPort": uniID, "FsmState": pVlanFilterStatemachine.Current(), |
| 4015 | }) |
| 4016 | } else { |
| 4017 | logger.Infow(ctx, "Successfully reset UniVlanConfigFsm", log.Fields{ |
| 4018 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, "UniPort": uniID, |
| 4019 | }) |
| 4020 | } |
| 4021 | } else { |
| 4022 | logger.Debugw(ctx, "UniVlanConfigFsm StateMachine does not exist, no reset performed", log.Fields{ |
| 4023 | "device-id": dh.DeviceID, "UniPort": uniID, |
| 4024 | }) |
| 4025 | } |
| 4026 | } else { |
| 4027 | logger.Debugw(ctx, "No UniVlanConfigFsm found for the UNI ID", log.Fields{ |
| 4028 | "device-id": dh.DeviceID, "UniPort": uniID, |
| 4029 | }) |
| 4030 | } |
| 4031 | } |
| 4032 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 4033 | // RemoveVlanFilterFsm deletes the stored pointer to the VlanConfigFsm |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 4034 | // 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] | 4035 | func (dh *deviceHandler) RemoveVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort) { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 4036 | logger.Debugw(ctx, "remove UniVlanConfigFsm StateMachine", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4037 | "device-id": dh.DeviceID, "uniPort": apUniPort.PortNo}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 4038 | //save to do, even if entry dows not exist |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4039 | dh.lockVlanConfig.Lock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4040 | delete(dh.UniVlanConfigFsmMap, apUniPort.UniID) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4041 | dh.lockVlanConfig.Unlock() |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 4042 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4043 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 4044 | // startWritingOnuDataToKvStore initiates the KVStore write of ONU persistent data |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4045 | func (dh *deviceHandler) startWritingOnuDataToKvStore(ctx context.Context, aPDevEntry *mib.OnuDeviceEntry) error { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4046 | dh.mutexKvStoreContext.Lock() //this write routine may (could) be called with the same context, |
| 4047 | defer dh.mutexKvStoreContext.Unlock() //this write routine may (could) be called with the same context, |
| 4048 | // obviously then parallel processing on the cancel must be avoided |
| 4049 | // deadline context to ensure completion of background routines waited for |
| 4050 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 4051 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 4052 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 4053 | defer cancel() // Ensure cancel is called to release resources |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4054 | |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 4055 | err := aPDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx)) |
| 4056 | if err != nil { |
| 4057 | logger.Errorw(ctx, "UpdateOnuKvStore-failed", log.Fields{"device-id": dh.DeviceID}) |
| 4058 | return err |
| 4059 | } |
| 4060 | return nil |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4061 | } |
| 4062 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 4063 | // StorePersUniFlowConfig updates local storage of OnuUniFlowConfig and writes it into kv-store afterwards to have it |
| 4064 | // available for potential reconcilement |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4065 | func (dh *deviceHandler) StorePersUniFlowConfig(ctx context.Context, aUniID uint8, |
| 4066 | aUniVlanFlowParams *[]cmn.UniVlanFlowParams, aWriteToKvStore bool) error { |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4067 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4068 | if dh.IsReconciling() { |
| bseeniva | 8c4547f | 2026-01-30 16:30:30 +0530 | [diff] [blame] | 4069 | logger.Debug(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] | 4070 | return nil |
| 4071 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4072 | 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] | 4073 | |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 4074 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4075 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4076 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 4077 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4078 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4079 | pDevEntry.UpdateOnuUniFlowConfig(aUniID, aUniVlanFlowParams) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4080 | |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4081 | if aWriteToKvStore { |
| 4082 | return dh.startWritingOnuDataToKvStore(ctx, pDevEntry) |
| 4083 | } |
| 4084 | return nil |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4085 | } |
| 4086 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 4087 | 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] | 4088 | defer cancel() //ensure termination of context (may be pro forma) |
| 4089 | wg.Wait() |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 4090 | logger.Debugw(ctx, "WaitGroup processing completed", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4091 | "device-id": dh.DeviceID, "called from": aCallerIdent}) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4092 | } |
| 4093 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 4094 | // ReasonUpdate set the internally store device reason and if requested in notifyCore updates this state in the core |
| 4095 | // |
| 4096 | // (renamed from previous deviceReasonUpdate to avoid confusing with the core function DeviceReasonUpdate) |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4097 | func (dh *deviceHandler) ReasonUpdate(ctx context.Context, deviceReason uint8, notifyCore bool) error { |
| 4098 | // acquire the deviceReason semaphore throughout this function including the possible update processing in core |
| 4099 | // in order to avoid reversion of the state sequence within core in case of quasi-parallel calls (eg. in multi UNI processing) |
| 4100 | dh.mutexDeviceReason.Lock() |
| 4101 | defer dh.mutexDeviceReason.Unlock() |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 4102 | if notifyCore { |
| Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 4103 | //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] | 4104 | if err := dh.updateDeviceReasonInCore(ctx, &ca.DeviceReason{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4105 | DeviceId: dh.DeviceID, |
| 4106 | Reason: cmn.DeviceReasonMap[deviceReason], |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4107 | }); err != nil { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4108 | logger.Errorf(ctx, "updating reason in core failed for: %s", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4109 | log.Fields{"device-id": dh.DeviceID, "error": err}, cmn.DeviceReasonMap[deviceReason]) |
| Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 4110 | return err |
| 4111 | } |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4112 | } else { |
| 4113 | 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] | 4114 | } |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4115 | dh.deviceReason = deviceReason |
| 4116 | logger.Infof(ctx, "reason update done for: %s - device-id: %s - with core update: %v", |
| 4117 | cmn.DeviceReasonMap[deviceReason], dh.DeviceID, notifyCore) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 4118 | return nil |
| 4119 | } |
| 4120 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4121 | func (dh *deviceHandler) StorePersistentData(ctx context.Context) error { |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 4122 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 4123 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4124 | logger.Warnw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 4125 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 4126 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4127 | return dh.startWritingOnuDataToKvStore(ctx, pDevEntry) |
| Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 4128 | } |
| 4129 | |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 4130 | func (dh *deviceHandler) UpdateRebootPersData(ctx context.Context, flag bool) { |
| 4131 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 4132 | if pDevEntry != nil { |
| 4133 | pDevEntry.MutexPersOnuConfig.Lock() |
| 4134 | pDevEntry.SOnuPersistentData.PersRebootInProgress = flag |
| 4135 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 4136 | } else { |
| 4137 | logger.Errorw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | func (dh *deviceHandler) GetPersRebootFlag(ctx context.Context) bool { |
| 4142 | rebootFlag := false |
| 4143 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 4144 | if pDevEntry != nil { |
| 4145 | pDevEntry.MutexPersOnuConfig.RLock() |
| 4146 | rebootFlag = pDevEntry.SOnuPersistentData.PersRebootInProgress |
| 4147 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 4148 | } else { |
| 4149 | logger.Errorw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 4150 | } |
| 4151 | return rebootFlag |
| 4152 | } |
| 4153 | |
| ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 4154 | // 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] | 4155 | // nolint: unused |
| ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 4156 | func (dh *deviceHandler) getUniPortMEEntityID(uniPortNo uint32) (uint16, error) { |
| 4157 | dh.lockDevice.RLock() |
| 4158 | defer dh.lockDevice.RUnlock() |
| 4159 | if uniPort, ok := dh.uniEntityMap[uniPortNo]; ok { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4160 | return uniPort.EntityID, nil |
| ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 4161 | } |
| 4162 | return 0, errors.New("error-fetching-uni-port") |
| 4163 | } |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4164 | |
| 4165 | // updatePmConfig updates the pm metrics config. |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4166 | func (dh *deviceHandler) updatePmConfig(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 4167 | var errorsList []error |
| 4168 | 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] | 4169 | |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4170 | errorsList = append(dh.handleGlobalPmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 4171 | errorsList = append(dh.handleGroupPmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 4172 | errorsList = append(dh.handleStandalonePmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 4173 | |
| 4174 | // Note that if more than one pm config field is updated in a given call, it is possible that partial pm config is handled |
| 4175 | // successfully. |
| 4176 | // TODO: Although it is possible to revert to old config in case of partial failure, the code becomes quite complex. Needs more investigation |
| 4177 | // Is it possible the rw-core reverts to old config on partial failure but adapter retains a partial new config? |
| 4178 | if len(errorsList) > 0 { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4179 | 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] | 4180 | 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] | 4181 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4182 | 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] | 4183 | return nil |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4184 | } |
| 4185 | |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4186 | func (dh *deviceHandler) handleGlobalPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 4187 | var err error |
| 4188 | var errorsList []error |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4189 | 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] | 4190 | |
| 4191 | if pmConfigs.DefaultFreq != dh.pmConfigs.DefaultFreq { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4192 | if err = dh.pOnuMetricsMgr.UpdateDefaultFrequency(ctx, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4193 | errorsList = append(errorsList, err) |
| 4194 | } |
| 4195 | } |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4196 | 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] | 4197 | |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4198 | return errorsList |
| 4199 | } |
| 4200 | |
| 4201 | func (dh *deviceHandler) handleGroupPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 4202 | var err error |
| 4203 | var errorsList []error |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4204 | 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] | 4205 | // Check if group metric related config is updated |
| 4206 | for _, v := range pmConfigs.Groups { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4207 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() |
| 4208 | m, ok := dh.pOnuMetricsMgr.GroupMetricMap[v.GroupName] |
| 4209 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4210 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4211 | if ok && m.Frequency != v.GroupFreq { |
| 4212 | if err = dh.pOnuMetricsMgr.UpdateGroupFreq(ctx, v.GroupName, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4213 | errorsList = append(errorsList, err) |
| 4214 | } |
| 4215 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4216 | if ok && m.Enabled != v.Enabled { |
| 4217 | if err = dh.pOnuMetricsMgr.UpdateGroupSupport(ctx, v.GroupName, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4218 | errorsList = append(errorsList, err) |
| 4219 | } |
| 4220 | } |
| 4221 | } |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4222 | 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] | 4223 | return errorsList |
| 4224 | } |
| 4225 | |
| 4226 | func (dh *deviceHandler) handleStandalonePmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 4227 | var err error |
| 4228 | var errorsList []error |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4229 | 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] | 4230 | // Check if standalone metric related config is updated |
| 4231 | for _, v := range pmConfigs.Metrics { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4232 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() |
| 4233 | m, ok := dh.pOnuMetricsMgr.StandaloneMetricMap[v.Name] |
| 4234 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4235 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4236 | if ok && m.Frequency != v.SampleFreq { |
| 4237 | if err = dh.pOnuMetricsMgr.UpdateMetricFreq(ctx, v.Name, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4238 | errorsList = append(errorsList, err) |
| 4239 | } |
| 4240 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4241 | if ok && m.Enabled != v.Enabled { |
| 4242 | if err = dh.pOnuMetricsMgr.UpdateMetricSupport(ctx, v.Name, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4243 | errorsList = append(errorsList, err) |
| 4244 | } |
| 4245 | } |
| 4246 | } |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4247 | 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] | 4248 | return errorsList |
| 4249 | } |
| 4250 | |
| 4251 | // nolint: gocyclo |
| Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 4252 | func (dh *deviceHandler) StartCollector(ctx context.Context, waitForOmciProcessor *sync.WaitGroup) { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4253 | logger.Debugw(ctx, "startingCollector", log.Fields{"device-id": dh.device.Id}) |
| bseeniva | 596a522 | 2026-01-23 19:26:11 +0530 | [diff] [blame] | 4254 | dh.RLockMutexDeletionInProgressFlag() |
| 4255 | if dh.GetDeletionInProgress() { |
| 4256 | logger.Warnw(ctx, "Device deletion in progress - avoid starting metrics collector routine", log.Fields{"device-id": dh.device.Id}) |
| 4257 | dh.RUnlockMutexDeletionInProgressFlag() |
| 4258 | return |
| 4259 | } |
| 4260 | // Set collectorIsRunning flag to true while still holding deviceDeletionFlag lock, |
| 4261 | // to avoid potential race condition where resetFsm from DeleteDevice might avoid stopping the collector routine if this flag is not yet set |
| 4262 | dh.setCollectorIsRunning(true) |
| 4263 | dh.RUnlockMutexDeletionInProgressFlag() |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4264 | |
| 4265 | // Start routine to process OMCI GET Responses |
| Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 4266 | go dh.pOnuMetricsMgr.ProcessOmciMessages(ctx, waitForOmciProcessor) |
| Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 4267 | // Create Extended Frame PM ME |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4268 | go dh.pOnuMetricsMgr.CreateEthernetFrameExtendedPMME(ctx) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4269 | // Initialize the next metric collection time. |
| 4270 | // Normally done when the onu_metrics_manager is initialized the first time, but needed again later when ONU is |
| 4271 | // reset like onu rebooted. |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4272 | dh.pOnuMetricsMgr.InitializeMetricCollectionTime(ctx) |
| praneeth nalmas | 808f43a | 2023-05-14 12:54:34 +0530 | [diff] [blame] | 4273 | statsCollectionticker := time.NewTicker((pmmgr.FrequencyGranularity) * time.Second) |
| 4274 | defer statsCollectionticker.Stop() |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4275 | for { |
| praneeth nalmas | 808f43a | 2023-05-14 12:54:34 +0530 | [diff] [blame] | 4276 | |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4277 | select { |
| 4278 | case <-dh.stopCollector: |
| 4279 | 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] | 4280 | // Stop the L2 PM FSM |
| 4281 | go func() { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4282 | if dh.pOnuMetricsMgr.PAdaptFsm != nil && dh.pOnuMetricsMgr.PAdaptFsm.PFsm != nil { |
| 4283 | if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventStop); err != nil { |
| 4284 | 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] | 4285 | } |
| 4286 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4287 | 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] | 4288 | } |
| 4289 | }() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4290 | if dh.pOnuMetricsMgr.GetOmciProcessingStatus() { |
| 4291 | dh.pOnuMetricsMgr.StopProcessingOmciResponses <- true // Stop the OMCI GET response processing routine |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 4292 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4293 | if dh.pOnuMetricsMgr.GetTickGenerationStatus() { |
| 4294 | dh.pOnuMetricsMgr.StopTicks <- true |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 4295 | } |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 4296 | |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4297 | return |
| praneeth nalmas | 808f43a | 2023-05-14 12:54:34 +0530 | [diff] [blame] | 4298 | 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] | 4299 | if !dh.pmConfigs.FreqOverride { // If FreqOverride is false, then NextGlobalMetricCollectionTime applies |
| 4300 | // If the current time is eqaul to or greater than the NextGlobalMetricCollectionTime, collect the group and standalone metrics |
| 4301 | if time.Now().Equal(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) || time.Now().After(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) { |
| 4302 | go dh.pOnuMetricsMgr.CollectAllGroupAndStandaloneMetrics(ctx) |
| Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 4303 | // Update the next metric collection time. |
| Mahir Gunyel | e184e9f | 2024-09-18 00:12:19 -0700 | [diff] [blame] | 4304 | prevInternal := dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime |
| 4305 | dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime = prevInternal.Add(time.Duration(dh.pmConfigs.DefaultFreq) * time.Second) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4306 | } |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4307 | } else { |
| 4308 | if dh.pmConfigs.Grouped { // metrics are managed as a group |
| 4309 | // 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] | 4310 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() // Rlock as we are reading GroupMetricMap and StandaloneMetricMap |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4311 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4312 | for n, g := range dh.pOnuMetricsMgr.GroupMetricMap { |
| 4313 | // 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] | 4314 | // 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] | 4315 | if g.Enabled && !g.IsL2PMCounter && (time.Now().Equal(g.NextCollectionInterval) || time.Now().After(g.NextCollectionInterval)) { |
| 4316 | go dh.pOnuMetricsMgr.CollectGroupMetric(ctx, n) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4317 | } |
| 4318 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4319 | for n, m := range dh.pOnuMetricsMgr.StandaloneMetricMap { |
| 4320 | // If the standalone is enabled AND (current time is equal to OR after NextCollectionInterval, collect the metric) |
| 4321 | if m.Enabled && (time.Now().Equal(m.NextCollectionInterval) || time.Now().After(m.NextCollectionInterval)) { |
| 4322 | go dh.pOnuMetricsMgr.CollectStandaloneMetric(ctx, n) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4323 | } |
| 4324 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4325 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4326 | |
| 4327 | // parse through the group and update the next metric collection time |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4328 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.Lock() // Lock as we are writing the next metric collection time |
| 4329 | for _, g := range dh.pOnuMetricsMgr.GroupMetricMap { |
| 4330 | // 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] | 4331 | // 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] | 4332 | 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] | 4333 | prevInternal := g.NextCollectionInterval |
| 4334 | g.NextCollectionInterval = prevInternal.Add(time.Duration(g.Frequency) * time.Second) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4335 | } |
| 4336 | } |
| 4337 | // parse through the standalone metrics and update the next metric collection time |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4338 | for _, m := range dh.pOnuMetricsMgr.StandaloneMetricMap { |
| 4339 | // If standalone metrics enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp |
| 4340 | 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] | 4341 | prevInternal := m.NextCollectionInterval |
| 4342 | m.NextCollectionInterval = prevInternal.Add(time.Duration(m.Frequency) * time.Second) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4343 | } |
| 4344 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4345 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.Unlock() |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4346 | } /* else { // metrics are not managed as a group |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4347 | // 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] | 4348 | } */ |
| 4349 | } |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4350 | } |
| 4351 | } |
| 4352 | } |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 4353 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4354 | //nolint:unparam |
| Akash Soni | 3c176c6 | 2024-12-04 13:30:43 +0530 | [diff] [blame] | 4355 | func (dh *deviceHandler) setOnuOffloadStats(ctx context.Context, config *extension.AppOffloadOnuConfig) *extension.SingleSetValueResponse { |
| 4356 | |
| 4357 | singleValResp := extension.SingleSetValueResponse{ |
| 4358 | Response: &extension.SetValueResponse{ |
| 4359 | Status: extension.SetValueResponse_OK, |
| 4360 | }, |
| 4361 | } |
| 4362 | |
| 4363 | return &singleValResp |
| 4364 | } |
| 4365 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4366 | func (dh *deviceHandler) GetUniPortStatus(ctx context.Context, uniInfo *extension.GetOnuUniInfoRequest) *extension.SingleGetValueResponse { |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 4367 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4368 | portStatus := uniprt.NewUniPortStatus(dh, dh.pOnuOmciDevice.PDevOmciCC) |
| 4369 | return portStatus.GetUniPortStatus(ctx, uniInfo.UniIndex) |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 4370 | } |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4371 | |
| Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 4372 | func (dh *deviceHandler) getOnuOMCICounters(ctx context.Context, onuInfo *extension.GetOmciEthernetFrameExtendedPmRequest) *extension.SingleGetValueResponse { |
| 4373 | if dh.pOnuMetricsMgr == nil { |
| 4374 | return &extension.SingleGetValueResponse{ |
| 4375 | Response: &extension.GetValueResponse{ |
| 4376 | Status: extension.GetValueResponse_ERROR, |
| 4377 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 4378 | }, |
| 4379 | } |
| 4380 | } |
| Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 4381 | resp := dh.pOnuMetricsMgr.CollectEthernetFrameExtendedPMCounters(ctx, onuInfo) |
| Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 4382 | return resp |
| 4383 | } |
| 4384 | |
| Holger Hildebrandt | 66af5ce | 2022-09-07 13:38:02 +0000 | [diff] [blame] | 4385 | func (dh *deviceHandler) getOnuOMCIStats(ctx context.Context) (*extension.SingleGetValueResponse, error) { |
| 4386 | |
| 4387 | var err error |
| 4388 | var pDevOmciCC *cmn.OmciCC |
| 4389 | if dh.pOnuOmciDevice == nil { |
| 4390 | logger.Errorw(ctx, "No valid DeviceEntry", log.Fields{"device-id": dh.DeviceID}) |
| 4391 | err = fmt.Errorf("no-valid-DeviceEntry-%s", dh.DeviceID) |
| 4392 | } else { |
| 4393 | pDevOmciCC = dh.pOnuOmciDevice.GetDevOmciCC() |
| 4394 | if pDevOmciCC == nil { |
| 4395 | logger.Errorw(ctx, "No valid DeviceOmciCCEntry", log.Fields{"device-id": dh.DeviceID}) |
| 4396 | err = fmt.Errorf("no-valid-DeviceOmciCCEntry-%s", dh.DeviceID) |
| 4397 | } |
| 4398 | } |
| 4399 | if err != nil { |
| 4400 | return &extension.SingleGetValueResponse{ |
| 4401 | Response: &extension.GetValueResponse{ |
| 4402 | Status: extension.GetValueResponse_ERROR, |
| 4403 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 4404 | }, |
| 4405 | }, |
| 4406 | err |
| 4407 | } |
| 4408 | return pDevOmciCC.GetOmciCounters(), nil |
| 4409 | } |
| 4410 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4411 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4412 | func (dh *deviceHandler) isFsmInOmciIdleState(ctx context.Context, PFsm *fsm.FSM, wantedState string) bool { |
| 4413 | if PFsm == nil { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4414 | return true //FSM not active - so there is no activity on omci |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4415 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4416 | return PFsm.Current() == wantedState |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4417 | } |
| 4418 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4419 | func (dh *deviceHandler) isFsmInOmciIdleStateDefault(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, wantedState string) bool { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4420 | var pAdapterFsm *cmn.AdapterFsm |
| 4421 | //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] | 4422 | switch omciFsm { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4423 | case cmn.CUploadFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4424 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4425 | if dh.pOnuOmciDevice != nil { |
| 4426 | pAdapterFsm = dh.pOnuOmciDevice.PMibUploadFsm |
| 4427 | } else { |
| 4428 | return true //FSM not active - so there is no activity on omci |
| 4429 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4430 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4431 | case cmn.CDownloadFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4432 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4433 | if dh.pOnuOmciDevice != nil { |
| 4434 | pAdapterFsm = dh.pOnuOmciDevice.PMibDownloadFsm |
| 4435 | } else { |
| 4436 | return true //FSM not active - so there is no activity on omci |
| 4437 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4438 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4439 | case cmn.CUniLockFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4440 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4441 | if dh.pLockStateFsm != nil { |
| 4442 | pAdapterFsm = dh.pLockStateFsm.PAdaptFsm |
| 4443 | } else { |
| 4444 | return true //FSM not active - so there is no activity on omci |
| 4445 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4446 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4447 | case cmn.CUniUnLockFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4448 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4449 | if dh.pUnlockStateFsm != nil { |
| 4450 | pAdapterFsm = dh.pUnlockStateFsm.PAdaptFsm |
| 4451 | } else { |
| 4452 | return true //FSM not active - so there is no activity on omci |
| 4453 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4454 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4455 | case cmn.CL2PmFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4456 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4457 | if dh.pOnuMetricsMgr != nil { |
| 4458 | pAdapterFsm = dh.pOnuMetricsMgr.PAdaptFsm |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4459 | } else { |
| 4460 | return true //FSM not active - so there is no activity on omci |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4461 | } |
| 4462 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4463 | case cmn.COnuUpgradeFsm: |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 4464 | { |
| 4465 | dh.lockUpgradeFsm.RLock() |
| 4466 | defer dh.lockUpgradeFsm.RUnlock() |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4467 | if dh.pOnuUpradeFsm != nil { |
| 4468 | pAdapterFsm = dh.pOnuUpradeFsm.PAdaptFsm |
| 4469 | } else { |
| 4470 | return true //FSM not active - so there is no activity on omci |
| 4471 | } |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 4472 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4473 | default: |
| 4474 | { |
| 4475 | logger.Errorw(ctx, "invalid stateMachine selected for idle check", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4476 | "device-id": dh.DeviceID, "selectedFsm number": omciFsm}) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4477 | 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] | 4478 | } |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4479 | } |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4480 | if pAdapterFsm != nil && pAdapterFsm.PFsm != nil { |
| 4481 | return dh.isFsmInOmciIdleState(ctx, pAdapterFsm.PFsm, wantedState) |
| 4482 | } |
| 4483 | return true //FSM not active - so there is no activity on omci |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4484 | } |
| 4485 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4486 | func (dh *deviceHandler) isAniConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool { |
| 4487 | for _, v := range dh.pOnuTP.PAniConfigFsm { |
| 4488 | if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) { |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4489 | return false |
| 4490 | } |
| 4491 | } |
| 4492 | return true |
| 4493 | } |
| 4494 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4495 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4496 | func (dh *deviceHandler) isUniVlanConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4497 | dh.lockVlanConfig.RLock() |
| 4498 | defer dh.lockVlanConfig.RUnlock() |
| 4499 | for _, v := range dh.UniVlanConfigFsmMap { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4500 | if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4501 | return false |
| 4502 | } |
| 4503 | } |
| 4504 | return true //FSM not active - so there is no activity on omci |
| 4505 | } |
| 4506 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4507 | //nolint:unparam |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4508 | func (dh *deviceHandler) checkUserServiceExists(ctx context.Context) bool { |
| 4509 | dh.lockVlanConfig.RLock() |
| 4510 | defer dh.lockVlanConfig.RUnlock() |
| 4511 | for _, v := range dh.UniVlanConfigFsmMap { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4512 | if v.PAdaptFsm.PFsm != nil { |
| 4513 | if v.PAdaptFsm.PFsm.Is(avcfg.CVlanFsmConfiguredState) { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4514 | return true //there is at least one VLAN FSM with some active configuration |
| 4515 | } |
| 4516 | } |
| 4517 | } |
| 4518 | return false //there is no VLAN FSM with some active configuration |
| 4519 | } |
| 4520 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4521 | func (dh *deviceHandler) CheckAuditStartCondition(ctx context.Context, callingFsm cmn.UsedOmciConfigFsms) bool { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4522 | for fsmName, fsmStruct := range fsmOmciIdleStateFuncMap { |
| 4523 | if fsmName != callingFsm && !fsmStruct.omciIdleCheckFunc(dh, ctx, fsmName, fsmStruct.omciIdleState) { |
| 4524 | return false |
| 4525 | } |
| 4526 | } |
| 4527 | // a further check is done to identify, if at least some data traffic related configuration exists |
| 4528 | // 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]) |
| 4529 | return dh.checkUserServiceExists(ctx) |
| 4530 | } |
| 4531 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4532 | func (dh *deviceHandler) PrepareReconcilingWithActiveAdapter(ctx context.Context) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4533 | 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] | 4534 | if err := dh.resetFsms(ctx, false); err != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4535 | 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] | 4536 | // TODO: fatal error reset ONU, delete deviceHandler! |
| 4537 | return |
| 4538 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4539 | dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort) |
| 4540 | dh.StartReconciling(ctx, false) |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4541 | } |
| 4542 | |
| 4543 | func (dh *deviceHandler) setCollectorIsRunning(flagValue bool) { |
| 4544 | dh.mutexCollectorFlag.Lock() |
| 4545 | dh.collectorIsRunning = flagValue |
| 4546 | dh.mutexCollectorFlag.Unlock() |
| 4547 | } |
| 4548 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4549 | func (dh *deviceHandler) GetCollectorIsRunning() bool { |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4550 | dh.mutexCollectorFlag.RLock() |
| 4551 | flagValue := dh.collectorIsRunning |
| 4552 | dh.mutexCollectorFlag.RUnlock() |
| 4553 | return flagValue |
| 4554 | } |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 4555 | |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 4556 | func (dh *deviceHandler) setAlarmManagerIsRunning(flagValue bool) { |
| 4557 | dh.mutextAlarmManagerFlag.Lock() |
| 4558 | dh.alarmManagerIsRunning = flagValue |
| 4559 | dh.mutextAlarmManagerFlag.Unlock() |
| 4560 | } |
| 4561 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4562 | func (dh *deviceHandler) GetAlarmManagerIsRunning(ctx context.Context) bool { |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 4563 | dh.mutextAlarmManagerFlag.RLock() |
| 4564 | flagValue := dh.alarmManagerIsRunning |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4565 | 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] | 4566 | dh.mutextAlarmManagerFlag.RUnlock() |
| 4567 | return flagValue |
| 4568 | } |
| 4569 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4570 | func (dh *deviceHandler) StartAlarmManager(ctx context.Context) { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4571 | logger.Debugw(ctx, "startingAlarmManager", log.Fields{"device-id": dh.device.Id}) |
| bseeniva | 596a522 | 2026-01-23 19:26:11 +0530 | [diff] [blame] | 4572 | dh.RLockMutexDeletionInProgressFlag() |
| 4573 | if dh.GetDeletionInProgress() { |
| 4574 | logger.Warnw(ctx, "Device deletion in progress - avoid starting alarm manager", log.Fields{"device-id": dh.DeviceID}) |
| 4575 | dh.RUnlockMutexDeletionInProgressFlag() |
| 4576 | return |
| 4577 | } |
| 4578 | // Set alarmManagerIsRunning flag to true while still holding deviceDeletionFlag lock, |
| 4579 | // to avoid potential race condition where resetFsm from DeleteDevice might avoid stopping the alarm manager if this flag is not yet set |
| 4580 | dh.setAlarmManagerIsRunning(true) |
| 4581 | |
| 4582 | dh.RUnlockMutexDeletionInProgressFlag() |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 4583 | |
| 4584 | // Start routine to process OMCI GET Responses |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4585 | go dh.pAlarmMgr.StartOMCIAlarmMessageProcessing(ctx) |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 4586 | if stop := <-dh.stopAlarmManager; stop { |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 4587 | 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] | 4588 | go func() { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4589 | if dh.pAlarmMgr.AlarmSyncFsm != nil && dh.pAlarmMgr.AlarmSyncFsm.PFsm != nil { |
| 4590 | _ = dh.pAlarmMgr.AlarmSyncFsm.PFsm.Event(almgr.AsEvStop) |
| Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 4591 | } |
| Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 4592 | }() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4593 | dh.pAlarmMgr.StopProcessingOmciMessages <- true // Stop the OMCI routines if any(This will stop the fsms also) |
| 4594 | dh.pAlarmMgr.StopAlarmAuditTimer <- struct{}{} |
| Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 4595 | 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] | 4596 | } |
| 4597 | } |
| Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 4598 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4599 | func (dh *deviceHandler) setFlowMonitoringIsRunning(uniID uint8, flag bool) { |
| 4600 | dh.mutexFlowMonitoringRoutineFlag.Lock() |
| 4601 | defer dh.mutexFlowMonitoringRoutineFlag.Unlock() |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4602 | 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] | 4603 | dh.isFlowMonitoringRoutineActive[uniID] = flag |
| 4604 | } |
| 4605 | |
| 4606 | func (dh *deviceHandler) GetFlowMonitoringIsRunning(uniID uint8) bool { |
| 4607 | dh.mutexFlowMonitoringRoutineFlag.RLock() |
| 4608 | defer dh.mutexFlowMonitoringRoutineFlag.RUnlock() |
| 4609 | logger.Debugw(context.Background(), "get-flow-monitoring-routine", |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4610 | log.Fields{"device-id": dh.device.Id, "isFlowMonitoringRoutineActive": dh.isFlowMonitoringRoutineActive}) |
| Sridhar Ravindra | e9a8bcc | 2024-12-06 10:40:54 +0530 | [diff] [blame] | 4611 | if len(dh.isFlowMonitoringRoutineActive) != 0 { |
| 4612 | return dh.isFlowMonitoringRoutineActive[uniID] |
| 4613 | } |
| 4614 | return false |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4615 | } |
| 4616 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4617 | func (dh *deviceHandler) StartReconciling(ctx context.Context, skipOnuConfig bool) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4618 | 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] | 4619 | |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4620 | connectStatus := voltha.ConnectStatus_UNREACHABLE |
| 4621 | operState := voltha.OperStatus_UNKNOWN |
| 4622 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4623 | if !dh.IsReconciling() { |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4624 | go func() { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4625 | logger.Debugw(ctx, "wait for channel signal or timeout", |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4626 | log.Fields{"timeout": dh.reconcileExpiryComplete, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4627 | select { |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4628 | case success := <-dh.chReconcilingFinished: |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4629 | logger.Info(ctx, "reconciling finished signal received", |
| Holger Hildebrandt | f745925 | 2022-01-03 16:10:37 +0000 | [diff] [blame] | 4630 | log.Fields{"device-id": dh.DeviceID, "dh.chReconcilingFinished": dh.chReconcilingFinished}) |
| 4631 | // To guarantee that the case-branch below is completely processed before reconciling processing is continued, |
| 4632 | // dh.mutexReconcilingFlag is locked already here. Thereby it is ensured, that further reconciling processing is stopped |
| 4633 | // at next call of dh.IsReconciling() until dh.reconciling is set after informing core about finished reconciling below. |
| 4634 | // This change addresses a problem described in VOL-4533 where the flag dh.reconciling not yet reset causes the uni ports |
| 4635 | // not to be created in ONOS in function dh.addUniPort(), when reconciling was started in reason "starting-openomci". |
| 4636 | // TODO: Keeping the mutex beyond an RPC towards core seems justifiable, as the effects here are easily overseeable. |
| 4637 | // However, a later refactoring of the functionality remains unaffected. |
| 4638 | dh.mutexReconcilingFlag.Lock() |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4639 | if success { |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 4640 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, false); onuDevEntry == nil { |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4641 | logger.Errorw(ctx, "No valid OnuDevice - aborting Core DeviceStateUpdate", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4642 | log.Fields{"device-id": dh.DeviceID}) |
| akashreddyk | b03dde0 | 2025-12-02 10:53:18 +0530 | [diff] [blame] | 4643 | } else if !onuDevEntry.SOnuPersistentData.PersRebootInProgress { |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4644 | onuDevEntry.MutexPersOnuConfig.RLock() |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 4645 | switch onuDevEntry.SOnuPersistentData.PersOperState { |
| 4646 | case "up": |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4647 | connectStatus = voltha.ConnectStatus_REACHABLE |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4648 | if !onuDevEntry.SOnuPersistentData.PersUniDisableDone { |
| 4649 | if onuDevEntry.SOnuPersistentData.PersUniUnlockDone { |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4650 | operState = voltha.OperStatus_ACTIVE |
| 4651 | } else { |
| 4652 | operState = voltha.OperStatus_ACTIVATING |
| 4653 | } |
| 4654 | } |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 4655 | case "down", "unknown", "": |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4656 | operState = voltha.OperStatus_DISCOVERED |
| 4657 | } |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4658 | onuDevEntry.MutexPersOnuConfig.RUnlock() |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4659 | logger.Debugw(ctx, "Core DeviceStateUpdate", |
| 4660 | log.Fields{"device-id": dh.device.Id, "connectStatus": connectStatus, "operState": operState}) |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4661 | } |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4662 | logger.Info(ctx, "reconciling has been finished in time", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4663 | log.Fields{"device-id": dh.DeviceID}) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4664 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4665 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4666 | ConnStatus: connectStatus, |
| 4667 | OperStatus: operState, |
| 4668 | }); err != nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4669 | logger.Errorw(ctx, "unable to update device state to core", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4670 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4671 | } |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4672 | } else { |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4673 | logger.Errorw(ctx, "wait for reconciling aborted", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4674 | log.Fields{"device-id": dh.DeviceID}) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4675 | |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 4676 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, false); onuDevEntry == nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4677 | logger.Errorw(ctx, "No valid OnuDevice", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4678 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4679 | } else { |
| 4680 | onuDevEntry.MutexPersOnuConfig.RLock() |
| 4681 | if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
| 4682 | connectStatus = voltha.ConnectStatus_REACHABLE |
| 4683 | } |
| 4684 | onuDevEntry.MutexPersOnuConfig.RUnlock() |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4685 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4686 | dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileCanceled, connectStatus) |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4687 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4688 | case <-time.After(dh.reconcileExpiryComplete): |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4689 | logger.Errorw(ctx, "timeout waiting for reconciling to be finished!", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4690 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | f745925 | 2022-01-03 16:10:37 +0000 | [diff] [blame] | 4691 | dh.mutexReconcilingFlag.Lock() |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4692 | |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 4693 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, false); onuDevEntry == nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4694 | logger.Errorw(ctx, "No valid OnuDevice", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4695 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4696 | } else { |
| 4697 | onuDevEntry.MutexPersOnuConfig.RLock() |
| 4698 | if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
| 4699 | connectStatus = voltha.ConnectStatus_REACHABLE |
| 4700 | } |
| 4701 | onuDevEntry.MutexPersOnuConfig.RUnlock() |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4702 | } |
| 4703 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4704 | dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileMaxTimeout, connectStatus) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4705 | |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4706 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4707 | dh.reconciling = cNoReconciling |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4708 | dh.mutexReconcilingFlag.Unlock() |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4709 | dh.SetReconcilingReasonUpdate(false) |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 4710 | dh.SetReconcilingFirstPass(true) |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4711 | |
| bseeniva | cfcd8f7 | 2026-01-30 21:06:49 +0530 | [diff] [blame] | 4712 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, false); onuDevEntry == nil { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4713 | logger.Errorw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 4714 | } else { |
| 4715 | onuDevEntry.MutexReconciledTpInstances.Lock() |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 4716 | onuDevEntry.ReconciledTpInstances = make(map[uint8]map[uint8]ia.TechProfileDownloadMessage) |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4717 | onuDevEntry.MutexReconciledTpInstances.Unlock() |
| 4718 | } |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4719 | }() |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4720 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4721 | dh.mutexReconcilingFlag.Lock() |
| Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 4722 | if skipOnuConfig || dh.GetSkipOnuConfigEnabled() { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4723 | dh.reconciling = cSkipOnuConfigReconciling |
| 4724 | } else { |
| 4725 | dh.reconciling = cOnuConfigReconciling |
| 4726 | } |
| 4727 | dh.mutexReconcilingFlag.Unlock() |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4728 | } |
| 4729 | |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4730 | func (dh *deviceHandler) stopReconciling(ctx context.Context, success bool, reconcileFlowResult uint16) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4731 | 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] | 4732 | if dh.IsReconciling() { |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4733 | dh.sendChReconcileFinished(success) |
| 4734 | if reconcileFlowResult != cWaitReconcileFlowNoActivity { |
| 4735 | dh.SendChUniVlanConfigFinished(reconcileFlowResult) |
| 4736 | } |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4737 | } else { |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4738 | 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] | 4739 | } |
| 4740 | } |
| 4741 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4742 | func (dh *deviceHandler) IsReconciling() bool { |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4743 | dh.mutexReconcilingFlag.RLock() |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4744 | defer dh.mutexReconcilingFlag.RUnlock() |
| 4745 | return dh.reconciling != cNoReconciling |
| 4746 | } |
| 4747 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4748 | func (dh *deviceHandler) IsSkipOnuConfigReconciling() bool { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4749 | dh.mutexReconcilingFlag.RLock() |
| 4750 | defer dh.mutexReconcilingFlag.RUnlock() |
| 4751 | return dh.reconciling == cSkipOnuConfigReconciling |
| 4752 | } |
| 4753 | |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 4754 | func (dh *deviceHandler) SetReconcilingFirstPass(value bool) { |
| 4755 | dh.mutexReconcilingFirstPassFlag.Lock() |
| 4756 | dh.reconcilingFirstPass = value |
| 4757 | dh.mutexReconcilingFirstPassFlag.Unlock() |
| 4758 | } |
| 4759 | |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4760 | func (dh *deviceHandler) SetReconcilingReasonUpdate(value bool) { |
| 4761 | dh.mutexReconcilingReasonUpdate.Lock() |
| 4762 | dh.reconcilingReasonUpdate = value |
| 4763 | dh.mutexReconcilingReasonUpdate.Unlock() |
| 4764 | } |
| 4765 | |
| 4766 | func (dh *deviceHandler) IsReconcilingReasonUpdate() bool { |
| 4767 | dh.mutexReconcilingReasonUpdate.RLock() |
| 4768 | defer dh.mutexReconcilingReasonUpdate.RUnlock() |
| 4769 | return dh.reconcilingReasonUpdate |
| 4770 | } |
| 4771 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4772 | func (dh *deviceHandler) getDeviceReason() uint8 { |
| 4773 | dh.mutexDeviceReason.RLock() |
| 4774 | value := dh.deviceReason |
| 4775 | dh.mutexDeviceReason.RUnlock() |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4776 | return value |
| 4777 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4778 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4779 | func (dh *deviceHandler) GetDeviceReasonString() string { |
| 4780 | return cmn.DeviceReasonMap[dh.getDeviceReason()] |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4781 | } |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4782 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4783 | func (dh *deviceHandler) SetReadyForOmciConfig(flagValue bool) { |
| Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 4784 | dh.mutexReadyForOmciConfig.Lock() |
| 4785 | dh.readyForOmciConfig = flagValue |
| 4786 | dh.mutexReadyForOmciConfig.Unlock() |
| 4787 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4788 | func (dh *deviceHandler) IsReadyForOmciConfig() bool { |
| Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 4789 | dh.mutexReadyForOmciConfig.RLock() |
| 4790 | flagValue := dh.readyForOmciConfig |
| 4791 | dh.mutexReadyForOmciConfig.RUnlock() |
| 4792 | return flagValue |
| 4793 | } |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4794 | |
| 4795 | func (dh *deviceHandler) deviceReconcileFailedUpdate(ctx context.Context, deviceReason uint8, connectStatus voltha.ConnectStatus_Types) { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4796 | if err := dh.ReasonUpdate(ctx, deviceReason, true); err != nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4797 | logger.Errorw(ctx, "unable to update device reason to core", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4798 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4799 | } |
| 4800 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4801 | logger.Debugw(ctx, "Core DeviceStateUpdate", |
| 4802 | 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] | 4803 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4804 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4805 | ConnStatus: connectStatus, |
| 4806 | OperStatus: voltha.OperStatus_RECONCILING_FAILED, |
| 4807 | }); err != nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4808 | logger.Errorw(ctx, "unable to update device state to core", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4809 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4810 | } |
| bseeniva | 4714cee | 2026-01-30 16:21:47 +0530 | [diff] [blame] | 4811 | context := make(map[string]string) |
| 4812 | context["device-id"] = dh.DeviceID |
| 4813 | context["onu-serial-number"] = dh.device.SerialNumber |
| 4814 | context["parent-id"] = dh.parentID |
| 4815 | |
| 4816 | deviceEvent := &voltha.DeviceEvent{ |
| 4817 | ResourceId: dh.DeviceID, |
| 4818 | DeviceEventName: cmn.OnuReconcileFailed, |
| 4819 | Description: cmn.OnuReconcileFailedAbortedDesc, |
| 4820 | Context: context, |
| 4821 | } |
| 4822 | logger.Debugw(ctx, "send device event", log.Fields{"deviceEvent": deviceEvent, "device-id": dh.DeviceID}) |
| 4823 | _ = dh.EventProxy.SendDeviceEvent(ctx, deviceEvent, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, time.Now().Unix()) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4824 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4825 | |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 4826 | func (dh *deviceHandler) deviceRebootStateUpdate(ctx context.Context, techProfInstLoadFailed bool) { |
| 4827 | if techProfInstLoadFailed { |
| 4828 | if err := dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadFailed, true); err != nil { |
| 4829 | logger.Errorw(ctx, "unable to update device reason to core", |
| 4830 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
| 4831 | } |
| 4832 | context := make(map[string]string) |
| 4833 | context["device-id"] = dh.DeviceID |
| 4834 | context["onu-serial-number"] = dh.device.SerialNumber |
| 4835 | context["parent-id"] = dh.parentID |
| 4836 | |
| 4837 | // Send event on flow configuration failure so that corrective action can be triggered from NB |
| 4838 | deviceEvent := &voltha.DeviceEvent{ |
| 4839 | ResourceId: dh.DeviceID, |
| 4840 | DeviceEventName: cmn.OnuFlowConfigFailed, |
| 4841 | Description: cmn.OnuFlowConfigFailedDesc, |
| 4842 | Context: context, |
| 4843 | } |
| 4844 | logger.Debugw(ctx, "send device event", log.Fields{"deviceEvent": deviceEvent, "device-id": dh.DeviceID}) |
| 4845 | _ = dh.EventProxy.SendDeviceEvent(ctx, deviceEvent, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, time.Now().Unix()) |
| 4846 | } |
| 4847 | } |
| 4848 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4849 | /* |
| 4850 | Helper functions to communicate with Core |
| 4851 | */ |
| 4852 | |
| 4853 | func (dh *deviceHandler) getDeviceFromCore(ctx context.Context, deviceID string) (*voltha.Device, error) { |
| 4854 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4855 | if err != nil || cClient == nil { |
| 4856 | return nil, err |
| 4857 | } |
| 4858 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4859 | defer cancel() |
| 4860 | logger.Debugw(subCtx, "get-device-from-core", log.Fields{"device-id": deviceID}) |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 4861 | return cClient.GetDevice(subCtx, &common.ID{Id: deviceID}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4862 | } |
| 4863 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4864 | func (dh *deviceHandler) updateDeviceStateInCore(ctx context.Context, deviceStateFilter *ca.DeviceStateFilter) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4865 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4866 | if err != nil || cClient == nil { |
| 4867 | return err |
| 4868 | } |
| 4869 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4870 | defer cancel() |
| 4871 | _, err = cClient.DeviceStateUpdate(subCtx, deviceStateFilter) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4872 | logger.Debugw(subCtx, "device-updated-in-core", |
| 4873 | log.Fields{"device-id": dh.device.Id, "device-state": deviceStateFilter, "error": err}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4874 | return err |
| 4875 | } |
| 4876 | |
| 4877 | func (dh *deviceHandler) updatePMConfigInCore(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 4878 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4879 | if err != nil || cClient == nil { |
| 4880 | return err |
| 4881 | } |
| 4882 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4883 | defer cancel() |
| 4884 | _, err = cClient.DevicePMConfigUpdate(subCtx, pmConfigs) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4885 | logger.Debugw(subCtx, "pmconfig-updated-in-core", |
| 4886 | log.Fields{"device-id": dh.device.Id, "pm-configs": pmConfigs, "error": err}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4887 | return err |
| 4888 | } |
| 4889 | |
| 4890 | func (dh *deviceHandler) updateDeviceInCore(ctx context.Context, device *voltha.Device) error { |
| 4891 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4892 | if err != nil || cClient == nil { |
| 4893 | return err |
| 4894 | } |
| 4895 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4896 | defer cancel() |
| 4897 | _, err = cClient.DeviceUpdate(subCtx, device) |
| 4898 | logger.Debugw(subCtx, "device-updated-in-core", log.Fields{"device-id": device.Id, "error": err}) |
| 4899 | return err |
| 4900 | } |
| 4901 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4902 | func (dh *deviceHandler) CreatePortInCore(ctx context.Context, port *voltha.Port) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4903 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4904 | if err != nil || cClient == nil { |
| 4905 | return err |
| 4906 | } |
| 4907 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4908 | defer cancel() |
| 4909 | _, err = cClient.PortCreated(subCtx, port) |
| 4910 | logger.Debugw(subCtx, "port-created-in-core", log.Fields{"port": port, "error": err}) |
| 4911 | return err |
| 4912 | } |
| 4913 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4914 | func (dh *deviceHandler) updatePortStateInCore(ctx context.Context, portState *ca.PortState) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4915 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4916 | if err != nil || cClient == nil { |
| 4917 | return err |
| 4918 | } |
| 4919 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4920 | defer cancel() |
| 4921 | _, err = cClient.PortStateUpdate(subCtx, portState) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4922 | 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] | 4923 | return err |
| 4924 | } |
| 4925 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4926 | func (dh *deviceHandler) updateDeviceReasonInCore(ctx context.Context, reason *ca.DeviceReason) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4927 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4928 | if err != nil || cClient == nil { |
| 4929 | return err |
| 4930 | } |
| 4931 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4932 | defer cancel() |
| 4933 | _, err = cClient.DeviceReasonUpdate(subCtx, reason) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4934 | 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] | 4935 | return err |
| 4936 | } |
| 4937 | |
| 4938 | /* |
| 4939 | Helper functions to communicate with parent adapter |
| 4940 | */ |
| 4941 | |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4942 | func (dh *deviceHandler) GetTechProfileInstanceFromParentAdapter(ctx context.Context, aUniID uint8, |
| 4943 | aTpPath string) (*ia.TechProfileDownloadMessage, error) { |
| 4944 | |
| 4945 | var request = ia.TechProfileInstanceRequestMessage{ |
| 4946 | DeviceId: dh.DeviceID, |
| 4947 | TpInstancePath: aTpPath, |
| 4948 | ParentDeviceId: dh.parentID, |
| 4949 | ParentPonPort: dh.device.ParentPortNo, |
| 4950 | OnuId: dh.device.ProxyAddress.OnuId, |
| 4951 | UniId: uint32(aUniID), |
| 4952 | } |
| 4953 | |
| 4954 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(dh.device.ProxyAddress.AdapterEndpoint) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4955 | if err != nil || pgClient == nil { |
| 4956 | return nil, err |
| 4957 | } |
| 4958 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 4959 | defer cancel() |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4960 | logger.Debugw(subCtx, "get-tech-profile-instance", |
| 4961 | 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] | 4962 | return pgClient.GetTechProfileInstance(subCtx, &request) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4963 | } |
| 4964 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4965 | // This routine is unique per ONU ID and blocks on flowControlBlock channel for incoming flows |
| 4966 | // Each incoming flow is processed in a synchronous manner, i.e., the flow is processed to completion before picking another |
| 4967 | func (dh *deviceHandler) PerOnuFlowHandlerRoutine(uniID uint8) { |
| bseeniva | 8c4547f | 2026-01-30 16:30:30 +0530 | [diff] [blame] | 4968 | logger.Debugw(context.Background(), "starting-flow-handler-routine", log.Fields{"device-id": dh.DeviceID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4969 | dh.setFlowMonitoringIsRunning(uniID, true) |
| 4970 | for { |
| 4971 | select { |
| 4972 | // block on the channel to receive an incoming flow |
| 4973 | // process the flow completely before proceeding to handle the next flow |
| 4974 | case flowCb := <-dh.flowCbChan[uniID]: |
| 4975 | startTime := time.Now() |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4976 | 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] | 4977 | respChan := make(chan error) |
| 4978 | if flowCb.addFlow { |
| 4979 | go dh.addFlowItemToUniPort(flowCb.ctx, flowCb.flowItem, flowCb.uniPort, flowCb.flowMetaData, &respChan) |
| 4980 | } else { |
| 4981 | go dh.removeFlowItemFromUniPort(flowCb.ctx, flowCb.flowItem, flowCb.uniPort, &respChan) |
| 4982 | } |
| 4983 | // Block on response and tunnel it back to the caller |
| balaji.nagarajan | 62ac62b | 2025-09-08 10:49:58 +0530 | [diff] [blame] | 4984 | select { |
| 4985 | |
| 4986 | case msg := <-respChan: |
| 4987 | *flowCb.respChan <- msg |
| 4988 | // response sent successfully |
| 4989 | logger.Info(flowCb.ctx, "serial-flow-processor--end", |
| 4990 | log.Fields{"device-id": dh.DeviceID, "absoluteTimeForFlowProcessingInSecs": time.Since(startTime).Seconds()}) |
| 4991 | case <-flowCb.ctx.Done(): |
| 4992 | logger.Info(flowCb.ctx, "flow handler context cancelled or timed out", log.Fields{"device-id": dh.DeviceID}) |
| 4993 | // Optionally, you can handle cleanup or logging here |
| 4994 | if dh.UniVlanConfigFsmMap[flowCb.uniPort.UniID] != nil && dh.UniVlanConfigFsmMap[flowCb.uniPort.UniID].PAdaptFsm != nil { |
| 4995 | pVlanFilterStatemachine := dh.UniVlanConfigFsmMap[flowCb.uniPort.UniID].PAdaptFsm.PFsm |
| 4996 | if pVlanFilterStatemachine != nil { |
| 4997 | |
| 4998 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvReset); err != nil { |
| 4999 | logger.Warnw(flowCb.ctx, "UniVlanConfigFsm: can't reset", |
| 5000 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 5001 | |
| 5002 | } |
| 5003 | |
| 5004 | } |
| 5005 | } |
| 5006 | |
| 5007 | ctx2 := context.Background() |
| 5008 | metadata := flow.GetMetadataFromWriteMetadataAction(ctx2, flowCb.flowItem) |
| 5009 | if metadata == 0 { |
| 5010 | logger.Warnw(flowCb.ctx, "AniConfigFsm: can't reset,failed to fetch metadata flow: %v", |
| 5011 | log.Fields{"device-id": dh.DeviceID, "flows": flowCb.flowItem}) |
| 5012 | continue |
| 5013 | } |
| 5014 | TpID := flow.GetTechProfileIDFromWriteMetaData(ctx2, metadata) |
| 5015 | |
| 5016 | if TpID == uint16(0) { |
| 5017 | logger.Warnw(flowCb.ctx, "AniConfigFsm: can't reset,failed to fetch techprofileid flow: %v", |
| 5018 | log.Fields{"device-id": dh.DeviceID, "flows": flowCb.flowItem}) |
| 5019 | continue |
| 5020 | } |
| 5021 | if dh.pOnuTP != nil { |
| 5022 | // should always be the case here |
| 5023 | // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting |
| 5024 | if dh.pOnuTP.PAniConfigFsm != nil { |
| 5025 | uniTP := avcfg.UniTP{ |
| 5026 | UniID: flowCb.uniPort.UniID, |
| 5027 | TpID: uint8(TpID), |
| 5028 | } |
| 5029 | if dh.pOnuTP.PAniConfigFsm[uniTP] != nil { |
| 5030 | dh.pOnuTP.PAniConfigFsm[uniTP].CancelProcessing(context.Background()) |
| 5031 | } |
| 5032 | } |
| 5033 | } |
| 5034 | |
| 5035 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 5036 | case <-dh.stopFlowMonitoringRoutine[uniID]: |
| 5037 | logger.Infow(context.Background(), "stopping-flow-handler-routine", log.Fields{"device-id": dh.DeviceID}) |
| 5038 | dh.setFlowMonitoringIsRunning(uniID, false) |
| 5039 | return |
| 5040 | } |
| 5041 | } |
| 5042 | } |
| 5043 | |
| kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 5044 | func (dh *deviceHandler) SendOnuSwSectionsOfWindow(ctx context.Context, parentEndpoint string, request *ia.OmciMessages) error { |
| 5045 | request.ParentDeviceId = dh.GetProxyAddressID() |
| 5046 | request.ChildDeviceId = dh.DeviceID |
| 5047 | request.ProxyAddress = dh.GetProxyAddress() |
| 5048 | request.ConnectStatus = common.ConnectStatus_REACHABLE |
| 5049 | |
| 5050 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint) |
| 5051 | if err != nil || pgClient == nil { |
| 5052 | return err |
| 5053 | } |
| 5054 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 5055 | defer cancel() |
| 5056 | logger.Debugw(subCtx, "send-omci-request", log.Fields{"request": request, "parent-endpoint": parentEndpoint}) |
| 5057 | _, err = pgClient.ProxyOmciRequests(subCtx, request) |
| 5058 | if err != nil { |
| Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 5059 | logger.Errorw(ctx, "omci-failure", log.Fields{"device-id": dh.device.Id, "request": request, "error": err, |
| 5060 | "request-parent": request.ParentDeviceId, "request-child": request.ChildDeviceId, "request-proxy": request.ProxyAddress}) |
| kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 5061 | } |
| 5062 | return err |
| 5063 | } |
| 5064 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 5065 | func (dh *deviceHandler) SendOMCIRequest(ctx context.Context, parentEndpoint string, request *ia.OmciMessage) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 5066 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint) |
| 5067 | if err != nil || pgClient == nil { |
| 5068 | return err |
| 5069 | } |
| 5070 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 5071 | defer cancel() |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 5072 | dh.setOltAvailable(true) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 5073 | 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] | 5074 | _, err = pgClient.ProxyOmciRequest(subCtx, request) |
| 5075 | if err != nil { |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 5076 | if status.Code(err) == codes.Unavailable { |
| 5077 | dh.setOltAvailable(false) |
| 5078 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 5079 | logger.Errorw(ctx, "omci-failure", |
| 5080 | 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] | 5081 | "request-child": request.ChildDeviceId, "request-proxy": request.ProxyAddress, "oltAvailable": dh.IsOltAvailable}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 5082 | } |
| 5083 | return err |
| 5084 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5085 | |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 5086 | func (dh *deviceHandler) CheckAvailableOnuCapabilities(ctx context.Context, pDevEntry *mib.OnuDeviceEntry, tpInst tech_profile.TechProfileInstance) error { |
| 5087 | // Check if there are additional TCONT instances necessary/available |
| 5088 | pDevEntry.MutexPersOnuConfig.Lock() |
| 5089 | if _, ok := pDevEntry.SOnuPersistentData.PersTcontMap[uint16(tpInst.UsScheduler.AllocId)]; !ok { |
| 5090 | numberOfTcontMapEntries := len(pDevEntry.SOnuPersistentData.PersTcontMap) |
| 5091 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 5092 | numberOfTcontDbInsts := pDevEntry.GetOnuDB().GetNumberOfInst(me.TContClassID) |
| 5093 | logger.Debugw(ctx, "checking available TCONT instances", |
| 5094 | log.Fields{"device-id": dh.DeviceID, "numberOfTcontMapEntries": numberOfTcontMapEntries, "numberOfTcontDbInsts": numberOfTcontDbInsts}) |
| 5095 | if numberOfTcontMapEntries >= numberOfTcontDbInsts { |
| 5096 | logger.Errorw(ctx, "configuration exceeds ONU capabilities - running out of TCONT instances: send ONU device event!", |
| 5097 | log.Fields{"device-id": dh.device.Id}) |
| 5098 | pDevEntry.SendOnuDeviceEvent(ctx, cmn.OnuConfigFailureMissingTcont, cmn.OnuConfigFailureMissingTcontDesc) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 5099 | 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] | 5100 | } |
| 5101 | } else { |
| 5102 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 5103 | } |
| 5104 | // Check if there are enough PrioQueue instances available |
| 5105 | if dh.pOnuTP != nil { |
| 5106 | var numberOfUsPrioQueueDbInsts int |
| 5107 | |
| 5108 | queueInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys(ctx, me.PriorityQueueClassID) |
| 5109 | for _, mgmtEntityID := range queueInstKeys { |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 5110 | if mgmtEntityID >= 0x8000 { |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 5111 | numberOfUsPrioQueueDbInsts++ |
| 5112 | } |
| 5113 | } |
| 5114 | // Check if there is an upstream PriorityQueue instance available for each Gem port |
| 5115 | numberOfConfiguredGemPorts := dh.pOnuTP.GetNumberOfConfiguredUsGemPorts(ctx) |
| 5116 | logger.Debugw(ctx, "checking available upstream PriorityQueue instances", |
| 5117 | log.Fields{"device-id": dh.DeviceID, |
| 5118 | "numberOfConfiguredGemPorts": numberOfConfiguredGemPorts, |
| 5119 | "tpInst.NumGemPorts": tpInst.NumGemPorts, |
| 5120 | "numberOfUsPrioQueueDbInsts": numberOfUsPrioQueueDbInsts}) |
| 5121 | |
| 5122 | if numberOfConfiguredGemPorts+int(tpInst.NumGemPorts) > numberOfUsPrioQueueDbInsts { |
| 5123 | logger.Errorw(ctx, "configuration exceeds ONU capabilities - running out of upstream PrioQueue instances: send ONU device event!", |
| 5124 | log.Fields{"device-id": dh.device.Id}) |
| 5125 | pDevEntry.SendOnuDeviceEvent(ctx, cmn.OnuConfigFailureMissingUsPriorityQueue, cmn.OnuConfigFailureMissingUsPriorityQueueDesc) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 5126 | 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] | 5127 | } |
| 5128 | // Downstream PrioQueue instances are evaluated in accordance with ONU MIB upload data in function UniPonAniConfigFsm::prepareAndEnterConfigState(). |
| 5129 | // In case of missing downstream PrioQueues the attribute "Priority queue pointer for downstream" of ME "GEM port network CTP" will be set to "0", |
| 5130 | // which then alternatively activates the queuing mechanisms of the ONU (refer to Rec. ITU-T G.988 chapter 9.2.3). |
| 5131 | } else { |
| 5132 | logger.Warnw(ctx, "onuTechProf instance not set up - check for PriorityQueue instances skipped!", |
| 5133 | log.Fields{"device-id": dh.DeviceID}) |
| 5134 | } |
| 5135 | return nil |
| 5136 | } |
| 5137 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5138 | // GetDeviceID - TODO: add comment |
| 5139 | func (dh *deviceHandler) GetDeviceID() string { |
| 5140 | return dh.DeviceID |
| 5141 | } |
| 5142 | |
| 5143 | // GetProxyAddressID - TODO: add comment |
| 5144 | func (dh *deviceHandler) GetProxyAddressID() string { |
| 5145 | return dh.device.ProxyAddress.GetDeviceId() |
| 5146 | } |
| 5147 | |
| 5148 | // GetProxyAddressType - TODO: add comment |
| 5149 | func (dh *deviceHandler) GetProxyAddressType() string { |
| 5150 | return dh.device.ProxyAddress.GetDeviceType() |
| 5151 | } |
| 5152 | |
| 5153 | // GetProxyAddress - TODO: add comment |
| 5154 | func (dh *deviceHandler) GetProxyAddress() *voltha.Device_ProxyAddress { |
| 5155 | return dh.device.ProxyAddress |
| 5156 | } |
| 5157 | |
| 5158 | // GetEventProxy - TODO: add comment |
| 5159 | func (dh *deviceHandler) GetEventProxy() eventif.EventProxy { |
| 5160 | return dh.EventProxy |
| 5161 | } |
| 5162 | |
| 5163 | // GetOmciTimeout - TODO: add comment |
| 5164 | func (dh *deviceHandler) GetOmciTimeout() int { |
| 5165 | return dh.pOpenOnuAc.omciTimeout |
| 5166 | } |
| 5167 | |
| 5168 | // GetAlarmAuditInterval - TODO: add comment |
| 5169 | func (dh *deviceHandler) GetAlarmAuditInterval() time.Duration { |
| 5170 | return dh.pOpenOnuAc.alarmAuditInterval |
| 5171 | } |
| 5172 | |
| 5173 | // GetDlToOnuTimeout4M - TODO: add comment |
| 5174 | func (dh *deviceHandler) GetDlToOnuTimeout4M() time.Duration { |
| 5175 | return dh.pOpenOnuAc.dlToOnuTimeout4M |
| 5176 | } |
| 5177 | |
| 5178 | // GetUniEntityMap - TODO: add comment |
| 5179 | func (dh *deviceHandler) GetUniEntityMap() *cmn.OnuUniPortMap { |
| 5180 | return &dh.uniEntityMap |
| 5181 | } |
| 5182 | |
| 5183 | // GetPonPortNumber - TODO: add comment |
| 5184 | func (dh *deviceHandler) GetPonPortNumber() *uint32 { |
| 5185 | return &dh.ponPortNumber |
| 5186 | } |
| 5187 | |
| 5188 | // GetUniVlanConfigFsm - TODO: add comment |
| 5189 | func (dh *deviceHandler) GetUniVlanConfigFsm(uniID uint8) cmn.IuniVlanConfigFsm { |
| Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 5190 | dh.lockVlanConfig.RLock() |
| 5191 | value := dh.UniVlanConfigFsmMap[uniID] |
| 5192 | dh.lockVlanConfig.RUnlock() |
| 5193 | return value |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5194 | } |
| 5195 | |
| 5196 | // GetOnuAlarmManager - TODO: add comment |
| 5197 | func (dh *deviceHandler) GetOnuAlarmManager() cmn.IonuAlarmManager { |
| 5198 | return dh.pAlarmMgr |
| 5199 | } |
| 5200 | |
| 5201 | // GetOnuMetricsManager - TODO: add comment |
| 5202 | func (dh *deviceHandler) GetOnuMetricsManager() cmn.IonuMetricsManager { |
| 5203 | return dh.pOnuMetricsMgr |
| 5204 | } |
| 5205 | |
| 5206 | // GetOnuTP - TODO: add comment |
| 5207 | func (dh *deviceHandler) GetOnuTP() cmn.IonuUniTechProf { |
| 5208 | return dh.pOnuTP |
| 5209 | } |
| 5210 | |
| 5211 | // GetBackendPathPrefix - TODO: add comment |
| 5212 | func (dh *deviceHandler) GetBackendPathPrefix() string { |
| 5213 | return dh.pOpenOnuAc.cm.Backend.PathPrefix |
| 5214 | } |
| 5215 | |
| 5216 | // GetOnuIndication - TODO: add comment |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 5217 | func (dh *deviceHandler) GetOnuIndication() *oop.OnuIndication { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5218 | return dh.pOnuIndication |
| 5219 | } |
| 5220 | |
| 5221 | // RLockMutexDeletionInProgressFlag - TODO: add comment |
| 5222 | func (dh *deviceHandler) RLockMutexDeletionInProgressFlag() { |
| 5223 | dh.mutexDeletionInProgressFlag.RLock() |
| 5224 | } |
| 5225 | |
| 5226 | // RUnlockMutexDeletionInProgressFlag - TODO: add comment |
| 5227 | func (dh *deviceHandler) RUnlockMutexDeletionInProgressFlag() { |
| 5228 | dh.mutexDeletionInProgressFlag.RUnlock() |
| 5229 | } |
| 5230 | |
| 5231 | // GetDeletionInProgress - TODO: add comment |
| 5232 | func (dh *deviceHandler) GetDeletionInProgress() bool { |
| 5233 | return dh.deletionInProgress |
| 5234 | } |
| 5235 | |
| 5236 | // GetPmConfigs - TODO: add comment |
| 5237 | func (dh *deviceHandler) GetPmConfigs() *voltha.PmConfigs { |
| 5238 | return dh.pmConfigs |
| 5239 | } |
| 5240 | |
| 5241 | // GetDeviceType - TODO: add comment |
| 5242 | func (dh *deviceHandler) GetDeviceType() string { |
| 5243 | return dh.DeviceType |
| 5244 | } |
| 5245 | |
| 5246 | // GetLogicalDeviceID - TODO: add comment |
| 5247 | func (dh *deviceHandler) GetLogicalDeviceID() string { |
| 5248 | return dh.logicalDeviceID |
| 5249 | } |
| 5250 | |
| 5251 | // GetDevice - TODO: add comment |
| 5252 | func (dh *deviceHandler) GetDevice() *voltha.Device { |
| 5253 | return dh.device |
| 5254 | } |
| 5255 | |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 5256 | func (dh *deviceHandler) setOltAvailable(value bool) { |
| 5257 | dh.mutexOltAvailable.Lock() |
| 5258 | dh.oltAvailable = value |
| 5259 | dh.mutexOltAvailable.Unlock() |
| 5260 | } |
| 5261 | |
| 5262 | // IsOltAvailable - TODO: add comment |
| 5263 | func (dh *deviceHandler) IsOltAvailable() bool { |
| 5264 | dh.mutexOltAvailable.RLock() |
| 5265 | defer dh.mutexOltAvailable.RUnlock() |
| 5266 | return dh.oltAvailable |
| 5267 | } |
| 5268 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5269 | // GetMetricsEnabled - TODO: add comment |
| 5270 | func (dh *deviceHandler) GetMetricsEnabled() bool { |
| 5271 | return dh.pOpenOnuAc.MetricsEnabled |
| 5272 | } |
| 5273 | |
| Holger Hildebrandt | c572e62 | 2022-06-22 09:19:17 +0000 | [diff] [blame] | 5274 | // GetExtendedOmciSupportEnabled - TODO: add comment |
| 5275 | func (dh *deviceHandler) GetExtendedOmciSupportEnabled() bool { |
| 5276 | return dh.pOpenOnuAc.ExtendedOmciSupportEnabled |
| 5277 | } |
| 5278 | |
| Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 5279 | // GetExtendedOmciSupportEnabled - TODO: add comment |
| 5280 | func (dh *deviceHandler) GetSkipOnuConfigEnabled() bool { |
| 5281 | return dh.pOpenOnuAc.skipOnuConfig |
| 5282 | } |
| 5283 | |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 5284 | func (dh *deviceHandler) GetDeviceTechProfOnReboot() bool { |
| 5285 | return dh.pOpenOnuAc.CheckDeviceTechProfOnReboot |
| 5286 | } |
| 5287 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5288 | // InitPmConfigs - TODO: add comment |
| 5289 | func (dh *deviceHandler) InitPmConfigs() { |
| 5290 | dh.pmConfigs = &voltha.PmConfigs{} |
| 5291 | } |
| 5292 | |
| 5293 | // GetUniPortMask - TODO: add comment |
| 5294 | func (dh *deviceHandler) GetUniPortMask() int { |
| 5295 | return dh.pOpenOnuAc.config.UniPortMask |
| 5296 | } |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 5297 | |
| 5298 | func (dh *deviceHandler) anyTpPathExists(aTpPathMap map[uint8]string) bool { |
| 5299 | tpPathFound := false |
| 5300 | for _, tpPath := range aTpPathMap { |
| 5301 | if tpPath != "" { |
| 5302 | tpPathFound = true |
| 5303 | } |
| 5304 | } |
| 5305 | return tpPathFound |
| 5306 | } |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5307 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 5308 | func (dh *deviceHandler) getOnuActiveAlarms(ctx context.Context) *extension.SingleGetValueResponse { |
| 5309 | resp := dh.GetOnuAlarmManager().GetOnuActiveAlarms(ctx) |
| 5310 | logger.Debugw(ctx, "Received response from AlarmManager for Active Alarms for DeviceEntry", log.Fields{"device-id": dh.DeviceID}) |
| 5311 | return resp |
| 5312 | } |
| 5313 | |
| Akash Reddy Kankanala | c28f0e2 | 2025-06-16 11:00:55 +0530 | [diff] [blame] | 5314 | // getONUGEMStatsInfo - Get the GEM PM history data of the request ONT device |
| 5315 | func (dh *deviceHandler) getONUGEMStatsInfo(ctx context.Context) *extension.SingleGetValueResponse { |
| 5316 | resp := dh.pOnuMetricsMgr.GetONUGEMCounters(ctx) |
| pnalmas | 6d6b7d7 | 2025-10-23 16:34:22 +0530 | [diff] [blame] | 5317 | logger.Debugw(ctx, "Received response from ONU Metrics Manager for GEM Stats", log.Fields{"device-id": dh.DeviceID}) |
| 5318 | return resp |
| 5319 | } |
| 5320 | |
| 5321 | // getOnuFECStats - Get the GEM PM history data of the request ONT device |
| 5322 | func (dh *deviceHandler) getOnuFECStats(ctx context.Context) *extension.SingleGetValueResponse { |
| 5323 | resp := dh.pOnuMetricsMgr.GetONUFECCounters(ctx) |
| 5324 | 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] | 5325 | return resp |
| 5326 | } |
| 5327 | |
| Praneeth Kumar Nalmas | aacc612 | 2024-04-09 22:55:49 +0530 | [diff] [blame] | 5328 | func (dh *deviceHandler) GetDeviceDeleteCommChan(ctx context.Context) chan bool { |
| 5329 | return dh.deviceDeleteCommChan |
| 5330 | } |
| 5331 | |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5332 | // PrepareForGarbageCollection - remove references to prepare for garbage collection |
| 5333 | func (dh *deviceHandler) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) { |
| 5334 | logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID}) |
| 5335 | |
| 5336 | // Note: This function must be called as a goroutine to prevent blocking of further processing! |
| 5337 | // first let the objects rest for some time to give all asynchronously started |
| 5338 | // cleanup routines a chance to come to an end |
| Holger Hildebrandt | 12609a1 | 2022-03-25 13:23:25 +0000 | [diff] [blame] | 5339 | time.Sleep(2 * time.Second) |
| 5340 | |
| Holger Hildebrandt | 12609a1 | 2022-03-25 13:23:25 +0000 | [diff] [blame] | 5341 | time.Sleep(3 * time.Second) |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5342 | |
| 5343 | if dh.pOnuTP != nil { |
| 5344 | dh.pOnuTP.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5345 | } |
| 5346 | if dh.pOnuMetricsMgr != nil { |
| Holger Hildebrandt | 34f13b2 | 2023-01-18 15:14:59 +0000 | [diff] [blame] | 5347 | logger.Debugw(ctx, "preparation of garbage collection is done under control of pm fsm - wait for completion", |
| 5348 | log.Fields{"device-id": aDeviceID}) |
| Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 5349 | select { |
| 5350 | case <-dh.pOnuMetricsMgr.GarbageCollectionComplete: |
| 5351 | logger.Debugw(ctx, "pm fsm shut down and garbage collection complete", log.Fields{"deviceID": aDeviceID}) |
| 5352 | case <-time.After(pmmgr.MaxTimeForPmFsmShutDown * time.Second): |
| 5353 | 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] | 5354 | default: |
| Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 5355 | } |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5356 | } |
| 5357 | if dh.pAlarmMgr != nil { |
| 5358 | dh.pAlarmMgr.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5359 | } |
| 5360 | if dh.pSelfTestHdlr != nil { |
| 5361 | dh.pSelfTestHdlr.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5362 | } |
| 5363 | if dh.pLockStateFsm != nil { |
| 5364 | dh.pLockStateFsm.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5365 | } |
| 5366 | if dh.pUnlockStateFsm != nil { |
| 5367 | dh.pUnlockStateFsm.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5368 | } |
| 5369 | if dh.pOnuUpradeFsm != nil { |
| 5370 | dh.pOnuUpradeFsm.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5371 | } |
| 5372 | if dh.pOnuOmciDevice != nil { |
| 5373 | dh.pOnuOmciDevice.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5374 | } |
| 5375 | for k, v := range dh.UniVlanConfigFsmMap { |
| 5376 | v.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5377 | delete(dh.UniVlanConfigFsmMap, k) |
| 5378 | } |
| nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 5379 | dh.pOnuIndication = nil |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5380 | dh.pOnuOmciDevice = nil |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 5381 | dh.lockDevice.Lock() |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5382 | dh.pOnuTP = nil |
| bseeniva | 0cbc62a | 2026-01-23 19:08:36 +0530 | [diff] [blame] | 5383 | dh.lockDevice.Unlock() |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5384 | dh.pOnuMetricsMgr = nil |
| 5385 | dh.pAlarmMgr = nil |
| 5386 | dh.pSelfTestHdlr = nil |
| 5387 | dh.pLockStateFsm = nil |
| 5388 | dh.pUnlockStateFsm = nil |
| 5389 | dh.pOnuUpradeFsm = nil |
| 5390 | } |