| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1 | /* |
| Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 2 | * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 17 | // Package core provides the utility for onu devices, flows and statistics |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 18 | package core |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 22 | "errors" |
| 23 | "fmt" |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 24 | "strconv" |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 25 | "sync" |
| 26 | "time" |
| 27 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 28 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config" |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 29 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 30 | "github.com/gogo/protobuf/proto" |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 31 | "github.com/looplab/fsm" |
| mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 32 | me "github.com/opencord/omci-lib-go/v2/generated" |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 33 | "github.com/opencord/voltha-lib-go/v7/pkg/db" |
| 34 | "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif" |
| 35 | flow "github.com/opencord/voltha-lib-go/v7/pkg/flows" |
| 36 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| 37 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 38 | platform "github.com/opencord/voltha-lib-go/v7/pkg/platform" |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 39 | almgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/almgr" |
| 40 | avcfg "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/avcfg" |
| 41 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
| 42 | mib "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/mib" |
| 43 | otst "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/omcitst" |
| 44 | pmmgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/pmmgr" |
| 45 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/swupg" |
| 46 | uniprt "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/uniprt" |
| kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 47 | "github.com/opencord/voltha-protos/v5/go/common" |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 48 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 49 | "github.com/opencord/voltha-protos/v5/go/extension" |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 50 | ia "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 51 | of "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 52 | oop "github.com/opencord/voltha-protos/v5/go/openolt" |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 53 | "github.com/opencord/voltha-protos/v5/go/tech_profile" |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 54 | "github.com/opencord/voltha-protos/v5/go/voltha" |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 55 | "google.golang.org/grpc/codes" |
| 56 | "google.golang.org/grpc/status" |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 57 | ) |
| 58 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 59 | const ( |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 60 | //constants for reconcile flow check channel |
| 61 | cWaitReconcileFlowAbortOnSuccess = 0xFFFD |
| 62 | cWaitReconcileFlowAbortOnError = 0xFFFE |
| 63 | cWaitReconcileFlowNoActivity = 0xFFFF |
| 64 | ) |
| 65 | |
| 66 | const ( |
| 67 | // constants for timeouts |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 68 | cTimeOutRemoveUpgrade = 1 //for usage in seconds |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 69 | ) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 70 | |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 71 | const ( |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 72 | // dummy constant - irregular value for ConnState - used to avoiding setting this state in the updateDeviceState() |
| 73 | // should better be defined in voltha protobuf or best solution would be to define an interface to just set the OperState |
| 74 | // as long as such is not available by the libraries - use this workaround |
| 75 | connectStatusINVALID = 255 // as long as not used as key in voltha.ConnectStatus_Types_name |
| 76 | ) |
| 77 | |
| 78 | const ( |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 79 | // events of Device FSM |
| 80 | devEvDeviceInit = "devEvDeviceInit" |
| 81 | devEvGrpcConnected = "devEvGrpcConnected" |
| 82 | devEvGrpcDisconnected = "devEvGrpcDisconnected" |
| 83 | devEvDeviceUpInd = "devEvDeviceUpInd" |
| 84 | devEvDeviceDownInd = "devEvDeviceDownInd" |
| 85 | ) |
| 86 | const ( |
| 87 | // states of Device FSM |
| 88 | devStNull = "devStNull" |
| 89 | devStDown = "devStDown" |
| 90 | devStInit = "devStInit" |
| 91 | devStConnected = "devStConnected" |
| 92 | devStUp = "devStUp" |
| 93 | ) |
| 94 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 95 | // Event category and subcategory definitions - same as defiend for OLT in eventmgr.go - should be done more centrally |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 96 | const ( |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 97 | pon = voltha.EventSubCategory_PON |
| 98 | //olt = voltha.EventSubCategory_OLT |
| 99 | //ont = voltha.EventSubCategory_ONT |
| 100 | //onu = voltha.EventSubCategory_ONU |
| 101 | //nni = voltha.EventSubCategory_NNI |
| 102 | //service = voltha.EventCategory_SERVICE |
| 103 | //security = voltha.EventCategory_SECURITY |
| 104 | equipment = voltha.EventCategory_EQUIPMENT |
| 105 | //processing = voltha.EventCategory_PROCESSING |
| 106 | //environment = voltha.EventCategory_ENVIRONMENT |
| 107 | //communication = voltha.EventCategory_COMMUNICATION |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 108 | ) |
| 109 | |
| 110 | const ( |
| 111 | cEventObjectType = "ONU" |
| 112 | ) |
| 113 | const ( |
| 114 | cOnuActivatedEvent = "ONU_ACTIVATED" |
| 115 | ) |
| 116 | |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 117 | type omciIdleCheckStruct struct { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 118 | omciIdleCheckFunc func(*deviceHandler, context.Context, cmn.UsedOmciConfigFsms, string) bool |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 119 | omciIdleState string |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 122 | var fsmOmciIdleStateFuncMap = map[cmn.UsedOmciConfigFsms]omciIdleCheckStruct{ |
| 123 | cmn.CUploadFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibUlFsmIdleState}, |
| 124 | cmn.CDownloadFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibDlFsmIdleState}, |
| 125 | cmn.CUniLockFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState}, |
| 126 | cmn.CUniUnLockFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState}, |
| 127 | cmn.CAniConfigFsm: {(*deviceHandler).isAniConfigFsmInOmciIdleState, avcfg.CAniFsmIdleState}, |
| 128 | cmn.CUniVlanConfigFsm: {(*deviceHandler).isUniVlanConfigFsmInOmciIdleState, avcfg.CVlanFsmIdleState}, |
| 129 | cmn.CL2PmFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, pmmgr.CL2PmFsmIdleState}, |
| 130 | cmn.COnuUpgradeFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, swupg.COnuUpgradeFsmIdleState}, |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 133 | const ( |
| 134 | cNoReconciling = iota |
| 135 | cOnuConfigReconciling |
| 136 | cSkipOnuConfigReconciling |
| 137 | ) |
| 138 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 139 | // FlowCb is the flow control block containing flow add/delete information along with a response channel |
| 140 | type FlowCb struct { |
| 141 | ctx context.Context // Flow handler context |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 142 | flowItem *of.OfpFlowStats |
| 143 | uniPort *cmn.OnuUniPort |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 144 | flowMetaData *of.FlowMetadata |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 145 | respChan *chan error // channel to report the Flow handling error |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 146 | addFlow bool // if true flow to be added, else removed |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 149 | // deviceHandler will interact with the ONU ? device. |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 150 | type deviceHandler struct { |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 151 | EventProxy eventif.EventProxy |
| 152 | |
| 153 | device *voltha.Device |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 154 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 155 | coreClient *vgrpc.Client |
| Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 156 | |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 157 | pmConfigs *voltha.PmConfigs |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 158 | config *config.AdapterFlags |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 159 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 160 | pOpenOnuAc *OpenONUAC |
| 161 | pDeviceStateFsm *fsm.FSM |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 162 | //pPonPort *voltha.Port |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 163 | deviceEntrySet chan bool //channel for DeviceEntry set event |
| 164 | pOnuOmciDevice *mib.OnuDeviceEntry |
| 165 | pOnuTP *avcfg.OnuUniTechProf |
| 166 | pOnuMetricsMgr *pmmgr.OnuMetricsManager |
| 167 | pAlarmMgr *almgr.OnuAlarmManager |
| 168 | pSelfTestHdlr *otst.SelfTestControlBlock |
| 169 | exitChannel chan int |
| 170 | pOnuIndication *oop.OnuIndication |
| 171 | pLockStateFsm *uniprt.LockStateFsm |
| 172 | pUnlockStateFsm *uniprt.LockStateFsm |
| 173 | |
| 174 | stopCollector chan bool |
| 175 | stopAlarmManager chan bool |
| 176 | stopHeartbeatCheck chan bool |
| 177 | uniEntityMap cmn.OnuUniPortMap |
| 178 | UniVlanConfigFsmMap map[uint8]*avcfg.UniVlanConfigFsm |
| 179 | pOnuUpradeFsm *swupg.OnuUpgradeFsm |
| 180 | chUniVlanConfigReconcilingDone chan uint16 //channel to indicate that VlanConfig reconciling for a specific UNI has been finished |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 181 | chUniVlanConfigOnRebootDone chan uint16 |
| 182 | chReconcilingFinished chan bool //channel to indicate that reconciling has been finished |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 183 | pLastUpgradeImageState *voltha.ImageState |
| 184 | upgradeFsmChan chan struct{} |
| 185 | |
| 186 | deviceDeleteCommChan chan bool |
| 187 | DeviceID string |
| 188 | DeviceType string |
| 189 | adminState string |
| 190 | logicalDeviceID string |
| 191 | ProxyAddressID string |
| 192 | ProxyAddressType string |
| 193 | parentID string |
| 194 | |
| 195 | flowCbChan []chan FlowCb |
| 196 | stopFlowMonitoringRoutine []chan bool // length of slice equal to number of uni ports |
| 197 | isFlowMonitoringRoutineActive []bool // length of slice equal to number of uni ports |
| 198 | reconcileExpiryComplete time.Duration |
| 199 | reconcileExpiryVlanConfig time.Duration |
| 200 | lockDevice sync.RWMutex |
| 201 | mutexDeviceReason sync.RWMutex |
| 202 | mutexCollectorFlag sync.RWMutex |
| 203 | mutextAlarmManagerFlag sync.RWMutex |
| 204 | lockVlanConfig sync.RWMutex |
| 205 | lockVlanAdd sync.RWMutex |
| 206 | lockUpgradeFsm sync.RWMutex |
| 207 | mutexReconcilingFlag sync.RWMutex |
| 208 | mutexReconcilingFirstPassFlag sync.RWMutex |
| 209 | mutexReconcilingReasonUpdate sync.RWMutex |
| 210 | mutexReadyForOmciConfig sync.RWMutex |
| 211 | mutexDeletionInProgressFlag sync.RWMutex |
| 212 | mutexFlowMonitoringRoutineFlag sync.RWMutex |
| 213 | mutexForDisableDeviceRequested sync.RWMutex |
| 214 | mutexOltAvailable sync.RWMutex |
| 215 | mutexKvStoreContext sync.Mutex |
| 216 | ponPortNumber uint32 |
| 217 | |
| 218 | deviceReason uint8 |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 219 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 220 | //flowMgr *OpenOltFlowMgr |
| 221 | //eventMgr *OpenOltEventMgr |
| 222 | //resourceMgr *rsrcMgr.OpenOltResourceMgr |
| 223 | |
| 224 | //discOnus sync.Map |
| 225 | //onus sync.Map |
| 226 | //portStats *OpenOltStatisticsMgr |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 227 | collectorIsRunning bool |
| 228 | alarmManagerIsRunning bool |
| 229 | upgradeCanceled bool |
| 230 | reconciling uint8 |
| 231 | reconcilingFirstPass bool |
| 232 | reconcilingReasonUpdate bool |
| 233 | readyForOmciConfig bool |
| 234 | deletionInProgress bool |
| 235 | disableDeviceRequested bool // this flag identify ONU received disable request or not |
| 236 | oltAvailable bool |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 239 | // newDeviceHandler creates a new device handler |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 240 | func newDeviceHandler(ctx context.Context, cc *vgrpc.Client, ep eventif.EventProxy, device *voltha.Device, adapter *OpenONUAC) *deviceHandler { |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 241 | var dh deviceHandler |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 242 | dh.coreClient = cc |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 243 | dh.EventProxy = ep |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 244 | dh.config = adapter.config |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 245 | cloned := (proto.Clone(device)).(*voltha.Device) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 246 | dh.DeviceID = cloned.Id |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 247 | dh.DeviceType = cloned.Type |
| 248 | dh.adminState = "up" |
| 249 | dh.device = cloned |
| 250 | dh.pOpenOnuAc = adapter |
| 251 | dh.exitChannel = make(chan int, 1) |
| 252 | dh.lockDevice = sync.RWMutex{} |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 253 | dh.deviceEntrySet = make(chan bool, 1) |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 254 | dh.collectorIsRunning = false |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 255 | dh.stopCollector = make(chan bool, 2) |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 256 | dh.alarmManagerIsRunning = false |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 257 | dh.stopAlarmManager = make(chan bool, 2) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 258 | dh.stopHeartbeatCheck = make(chan bool, 2) |
| 259 | //dh.metrics = pmmetrics.NewPmMetrics(cloned.Id, pmmetrics.Frequency(150), pmmetrics.FrequencyOverride(false), pmmetrics.Grouped(false), pmmetrics.Metrics(pmNames)) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 260 | //TODO initialize the support classes. |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 261 | dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 262 | dh.lockVlanConfig = sync.RWMutex{} |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 263 | dh.lockVlanAdd = sync.RWMutex{} |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 264 | dh.lockUpgradeFsm = sync.RWMutex{} |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 265 | dh.mutexForDisableDeviceRequested = sync.RWMutex{} |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 266 | dh.UniVlanConfigFsmMap = make(map[uint8]*avcfg.UniVlanConfigFsm) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 267 | dh.reconciling = cNoReconciling |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 268 | dh.reconcilingReasonUpdate = false |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 269 | dh.reconcilingFirstPass = true |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 270 | dh.disableDeviceRequested = false |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 271 | dh.oltAvailable = false |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 272 | dh.chReconcilingFinished = make(chan bool) |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 273 | dh.reconcileExpiryComplete = adapter.maxTimeoutReconciling //assumption is to have it as duration in s! |
| 274 | rECSeconds := int(dh.reconcileExpiryComplete / time.Second) |
| 275 | if rECSeconds < 2 { |
| 276 | dh.reconcileExpiryComplete = time.Duration(2) * time.Second //ensure a minimum expiry time of 2s for complete reconciling |
| 277 | rECSeconds = 2 |
| 278 | } |
| 279 | rEVCSeconds := rECSeconds / 2 |
| 280 | dh.reconcileExpiryVlanConfig = time.Duration(rEVCSeconds) * time.Second //set this duration to some according lower value |
| Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 281 | dh.readyForOmciConfig = false |
| Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 282 | dh.deletionInProgress = false |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 283 | dh.pLastUpgradeImageState = &voltha.ImageState{ |
| 284 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 285 | Reason: voltha.ImageState_UNKNOWN_ERROR, |
| 286 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 287 | } |
| 288 | dh.upgradeFsmChan = make(chan struct{}) |
| praneeth nalmas | f405e96 | 2023-08-07 15:02:03 +0530 | [diff] [blame] | 289 | dh.deviceDeleteCommChan = make(chan bool, 2) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 290 | |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 291 | if dh.device.PmConfigs != nil { // can happen after onu adapter restart |
| 292 | dh.pmConfigs = cloned.PmConfigs |
| 293 | } /* else { |
| 294 | // will be populated when onu_metrics_mananger is initialized. |
| 295 | }*/ |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 296 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 297 | // Device related state machine |
| 298 | dh.pDeviceStateFsm = fsm.NewFSM( |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 299 | devStNull, |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 300 | fsm.Events{ |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 301 | {Name: devEvDeviceInit, Src: []string{devStNull, devStDown}, Dst: devStInit}, |
| 302 | {Name: devEvGrpcConnected, Src: []string{devStInit}, Dst: devStConnected}, |
| 303 | {Name: devEvGrpcDisconnected, Src: []string{devStConnected, devStDown}, Dst: devStInit}, |
| 304 | {Name: devEvDeviceUpInd, Src: []string{devStConnected, devStDown}, Dst: devStUp}, |
| 305 | {Name: devEvDeviceDownInd, Src: []string{devStUp}, Dst: devStDown}, |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 306 | }, |
| 307 | fsm.Callbacks{ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 308 | "before_event": func(e *fsm.Event) { dh.logStateChange(ctx, e) }, |
| 309 | ("before_" + devEvDeviceInit): func(e *fsm.Event) { dh.doStateInit(ctx, e) }, |
| 310 | ("after_" + devEvDeviceInit): func(e *fsm.Event) { dh.postInit(ctx, e) }, |
| 311 | ("before_" + devEvGrpcConnected): func(e *fsm.Event) { dh.doStateConnected(ctx, e) }, |
| 312 | ("before_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.doStateInit(ctx, e) }, |
| 313 | ("after_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.postInit(ctx, e) }, |
| 314 | ("before_" + devEvDeviceUpInd): func(e *fsm.Event) { dh.doStateUp(ctx, e) }, |
| 315 | ("before_" + devEvDeviceDownInd): func(e *fsm.Event) { dh.doStateDown(ctx, e) }, |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 316 | }, |
| 317 | ) |
| mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 318 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 319 | return &dh |
| 320 | } |
| 321 | |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 322 | // start save the device to the data model |
| 323 | func (dh *deviceHandler) start(ctx context.Context) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 324 | logger.Debugw(ctx, "starting-device-handler", log.Fields{"device": dh.device, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 325 | // Add the initial device to the local model |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 326 | logger.Debugw(ctx, "device-handler-started", log.Fields{"device": dh.device}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 329 | /* |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 330 | // stop stops the device dh. Not much to do for now |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 331 | func (dh *deviceHandler) stop(ctx context.Context) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 332 | logger.Debug("stopping-device-handler") |
| 333 | dh.exitChannel <- 1 |
| 334 | } |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 335 | */ |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 336 | |
| 337 | // ########################################################################################## |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 338 | // deviceHandler methods that implement the adapters interface requests ##### begin ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 339 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 340 | // adoptOrReconcileDevice adopts the ONU device |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 341 | func (dh *deviceHandler) adoptOrReconcileDevice(ctx context.Context, device *voltha.Device) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 342 | logger.Debugw(ctx, "adopt_or_reconcile_device", log.Fields{"device-id": device.Id, "Address": device.GetHostAndPort()}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 343 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 344 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"device-id": device.Id, "state": string(dh.pDeviceStateFsm.Current())}) |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 345 | |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 346 | if dh.pDeviceStateFsm.Is(devStNull) { |
| 347 | if err := dh.pDeviceStateFsm.Event(devEvDeviceInit); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 348 | logger.Errorw(ctx, "Device FSM: Can't go to state DeviceInit", log.Fields{"device-id": device.Id, "err": err}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 349 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 350 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"device-id": device.Id, "state": string(dh.pDeviceStateFsm.Current())}) |
| Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 351 | // device.PmConfigs is not nil in cases when adapter restarts. We should not re-set the core again. |
| 352 | if device.PmConfigs == nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 353 | // Now, set the initial PM configuration for that device |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 354 | if err := dh.updatePMConfigInCore(ctx, dh.pmConfigs); err != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 355 | logger.Errorw(ctx, "error updating pm config to core", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 356 | } |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 357 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 358 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 359 | logger.Debugw(ctx, "AdoptOrReconcileDevice: Agent/device init already done", log.Fields{"device-id": device.Id}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 364 | func (dh *deviceHandler) handleOMCIIndication(ctx context.Context, msg *ia.OmciMessage) error { |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 365 | /* msg print moved symmetrically to omci_cc, if wanted here as additional debug, than perhaps only based on additional debug setting! |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 366 | //assuming omci message content is hex coded! |
| 367 | // with restricted output of 16(?) bytes would be ...omciMsg.Message[:16] |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 368 | logger.Debugw(ctx, "inter-adapter-recv-omci", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 369 | "device-id": dh.DeviceID, "RxOmciMessage": hex.EncodeToString(omciMsg.Message)}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 370 | */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 371 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 372 | if pDevEntry != nil { |
| Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 373 | if pDevEntry.PDevOmciCC != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 374 | return pDevEntry.PDevOmciCC.ReceiveMessage(log.WithSpanFromContext(context.TODO(), ctx), msg.Message) |
| Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 375 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 376 | logger.Debugw(ctx, "omciCC not ready to receive omci messages - incoming omci message ignored", log.Fields{"device-id": dh.DeviceID, |
| 377 | "rxMsg": msg.Message}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 378 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 379 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 380 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 381 | } |
| 382 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 383 | func (dh *deviceHandler) handleTechProfileDownloadRequest(ctx context.Context, techProfMsg *ia.TechProfileDownloadMessage) error { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 384 | logger.Infow(ctx, "tech-profile-download-request", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 385 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 386 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 387 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 388 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 389 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 390 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 391 | if dh.pOnuTP == nil { |
| 392 | //should normally not happen ... |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 393 | 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] | 394 | log.Fields{"device-id": dh.DeviceID}) |
| 395 | 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] | 396 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 397 | if !dh.IsReadyForOmciConfig() { |
| 398 | logger.Errorw(ctx, "TechProf-set rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 399 | "device-state": dh.GetDeviceReasonString()}) |
| 400 | 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] | 401 | } |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 402 | //previous state test here was just this one, now extended for more states to reject the SetRequest: |
| 403 | // at least 'mib-downloaded' should be reached for processing of this specific ONU configuration |
| 404 | // if (dh.deviceReason == "stopping-openomci") || (dh.deviceReason == "omci-admin-lock") |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 405 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 406 | // 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] | 407 | // even to fast subsequent calls of the same messageType as well as OnuKVStore processing due |
| 408 | // to possible concurrent access by flow processing |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 409 | dh.pOnuTP.LockTpProcMutex() |
| 410 | defer dh.pOnuTP.UnlockTpProcMutex() |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 411 | |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 412 | if techProfMsg.UniId >= platform.MaxUnisPerOnu { |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 413 | return fmt.Errorf("received UniId value exceeds range: %d, device-id: %s", |
| 414 | techProfMsg.UniId, dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 415 | } |
| 416 | uniID := uint8(techProfMsg.UniId) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 417 | tpID, err := cmn.GetTpIDFromTpPath(techProfMsg.TpInstancePath) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 418 | if err != nil { |
| Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 419 | logger.Errorw(ctx, "error-parsing-tpid-from-tppath", |
| 420 | log.Fields{"device-id": dh.DeviceID, "err": err, "tp-path": techProfMsg.TpInstancePath}) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 421 | return err |
| 422 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 423 | logger.Debugw(ctx, "unmarshal-techprof-msg-body", log.Fields{"device-id": dh.DeviceID, |
| 424 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 425 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 426 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, uint8(tpID), techProfMsg.TpInstancePath); bTpModify { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 427 | |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 428 | switch tpInst := techProfMsg.TechTpInstance.(type) { |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 429 | case *ia.TechProfileDownloadMessage_TpInstance: |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 430 | logger.Debugw(ctx, "onu-uni-tp-path-modified", log.Fields{"device-id": dh.DeviceID, |
| 431 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 432 | |
| 433 | err = dh.CheckAvailableOnuCapabilities(ctx, pDevEntry, *tpInst.TpInstance) |
| 434 | if err != nil { |
| 435 | logger.Errorw(ctx, "error-checking-available-onu-capabilities-stopping-device", |
| 436 | log.Fields{"device-id": dh.DeviceID, "err": err, "tp-path": techProfMsg.TpInstancePath}) |
| 437 | // stopping all further processing |
| 438 | _ = dh.UpdateInterface(ctx) |
| 439 | return err |
| 440 | } |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 441 | // if there has been some change for some uni TechProfilePath |
| 442 | //in order to allow concurrent calls to other dh instances we do not wait for execution here |
| 443 | //but doing so we can not indicate problems to the caller (who does what with that then?) |
| 444 | //by now we just assume straightforward successful execution |
| 445 | //TODO!!! Generally: In this scheme it would be good to have some means to indicate |
| 446 | // possible problems to the caller later autonomously |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 447 | |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 448 | // deadline context to ensure completion of background routines waited for |
| 449 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 450 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 451 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 452 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 453 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 454 | |
| 455 | var wg sync.WaitGroup |
| 456 | wg.Add(1) // for the 1 go routine to finish |
| 457 | // 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] | 458 | 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] | 459 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfDwld") //wait for background process to finish |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 460 | if tpErr := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); tpErr != nil { |
| 461 | 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] | 462 | return tpErr |
| 463 | } |
| 464 | deadline = time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 465 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 466 | defer cancel2() |
| 467 | err1 := pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx)) |
| 468 | if err1 != nil { |
| 469 | logger.Errorf(ctx, "UpdateOnuKvStore-failed", log.Fields{"device-id": dh.DeviceID, "error": err1}) |
| 470 | return err |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 471 | } |
| 472 | return nil |
| 473 | default: |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 474 | 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] | 475 | return fmt.Errorf("unsupported-tp-instance-type--tp-id-%v", techProfMsg.TpInstancePath) |
| Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 476 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 477 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 478 | // no change, nothing really to do - return success |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 479 | logger.Debugw(ctx, "onu-uni-tp-path-not-modified", log.Fields{"device-id": dh.DeviceID, |
| 480 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 481 | return nil |
| 482 | } |
| 483 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 484 | func (dh *deviceHandler) handleDeleteGemPortRequest(ctx context.Context, delGemPortMsg *ia.DeleteGemPortMessage) error { |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 485 | 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] | 486 | |
| 487 | if dh.pOnuTP == nil { |
| 488 | //should normally not happen ... |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 489 | 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] | 490 | log.Fields{"device-id": dh.DeviceID}) |
| 491 | 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] | 492 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 493 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 494 | dh.pOnuTP.LockTpProcMutex() |
| 495 | defer dh.pOnuTP.UnlockTpProcMutex() |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 496 | |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 497 | if delGemPortMsg.UniId >= platform.MaxUnisPerOnu { |
| 498 | logger.Errorw(ctx, "delete-gem-port UniId exceeds range", log.Fields{ |
| 499 | "device-id": dh.DeviceID, "uni-id": delGemPortMsg.UniId}) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 500 | return fmt.Errorf("received UniId value exceeds range: %d, device-id: %s", |
| 501 | delGemPortMsg.UniId, dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 502 | } |
| 503 | uniID := uint8(delGemPortMsg.UniId) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 504 | tpID, err := cmn.GetTpIDFromTpPath(delGemPortMsg.TpInstancePath) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 505 | if err != nil { |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 506 | logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{ |
| 507 | "device-id": dh.DeviceID, "err": err, "tp-path": delGemPortMsg.TpInstancePath}) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 508 | return err |
| 509 | } |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 510 | logger.Infow(ctx, "delete-gem-port-request", log.Fields{ |
| 511 | "device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "gem": delGemPortMsg.GemPortId}) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 512 | //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] | 513 | |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 514 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delGemPortMsg.TpInstancePath, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 515 | avcfg.CResourceGemPort, delGemPortMsg.GemPortId) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 516 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 517 | } |
| 518 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 519 | func (dh *deviceHandler) handleDeleteTcontRequest(ctx context.Context, delTcontMsg *ia.DeleteTcontMessage) error { |
| Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 520 | 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] | 521 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 522 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 523 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 524 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 525 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 526 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 527 | if dh.pOnuTP == nil { |
| 528 | //should normally not happen ... |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 529 | 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] | 530 | log.Fields{"device-id": dh.DeviceID}) |
| 531 | 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] | 532 | } |
| 533 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 534 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 535 | dh.pOnuTP.LockTpProcMutex() |
| 536 | defer dh.pOnuTP.UnlockTpProcMutex() |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 537 | |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 538 | if delTcontMsg.UniId >= platform.MaxUnisPerOnu { |
| 539 | logger.Errorw(ctx, "delete-tcont UniId exceeds range", log.Fields{ |
| 540 | "device-id": dh.DeviceID, "uni-id": delTcontMsg.UniId}) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 541 | return fmt.Errorf("received UniId value exceeds range: %d, device-id: %s", |
| 542 | delTcontMsg.UniId, dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 543 | } |
| 544 | uniID := uint8(delTcontMsg.UniId) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 545 | tpPath := delTcontMsg.TpInstancePath |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 546 | tpID, err := cmn.GetTpIDFromTpPath(tpPath) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 547 | if err != nil { |
| mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 548 | logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{ |
| 549 | "device-id": dh.DeviceID, "err": err, "tp-path": tpPath}) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 550 | return err |
| 551 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 552 | pDevEntry.FreeTcont(ctx, uint16(delTcontMsg.AllocId)) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 553 | |
| Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 554 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 555 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 556 | defer cancel() |
| Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 557 | 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] | 558 | err1 := pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx)) |
| 559 | if err1 != nil { |
| 560 | logger.Errorw(ctx, "UpdateOnuKvStore-failed", log.Fields{"device-id": dh.DeviceID, "err": err1}) |
| 561 | return err1 |
| Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 564 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delTcontMsg.TpInstancePath, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 565 | avcfg.CResourceTcont, delTcontMsg.AllocId) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 566 | |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 567 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 568 | |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 569 | func (dh *deviceHandler) deleteTechProfileResource(ctx context.Context, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 570 | uniID uint8, tpID uint8, pathString string, resource avcfg.ResourceEntry, entryID uint32) error { |
| 571 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 572 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 573 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 574 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 575 | } |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 576 | var resourceName string |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 577 | if avcfg.CResourceGemPort == resource { |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 578 | resourceName = "Gem" |
| 579 | } else { |
| 580 | resourceName = "Tcont" |
| 581 | } |
| 582 | |
| 583 | // deadline context to ensure completion of background routines waited for |
| 584 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 585 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 586 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 587 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 588 | |
| 589 | var wg sync.WaitGroup |
| 590 | wg.Add(1) // for the 1 go routine to finish |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 591 | go dh.pOnuTP.DeleteTpResource(log.WithSpanFromContext(dctx, ctx), uniID, tpID, pathString, |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 592 | resource, entryID, &wg) |
| 593 | 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] | 594 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); err != nil { |
| 595 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 596 | return err |
| 597 | } |
| 598 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 599 | if dh.pOnuTP.IsTechProfileConfigCleared(ctx, uniID, tpID) { |
| 600 | logger.Debugw(ctx, "techProfile-config-cleared", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID}) |
| 601 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, tpID, ""); bTpModify { |
| 602 | pDevEntry.ResetKvProcessingErrorIndication() |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 603 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 604 | defer cancel2() |
| Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 605 | // 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] | 606 | 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] | 607 | err := pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx)) |
| 608 | if err != nil { |
| 609 | 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] | 610 | return err |
| 611 | } |
| 612 | } |
| 613 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 614 | 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] | 615 | "uni-id": uniID, "tpID": tpID, "resource-type": resourceName, "resource-id": entryID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 616 | return nil |
| 617 | } |
| 618 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 619 | // FlowUpdateIncremental removes and/or adds the flow changes on a given device |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 620 | func (dh *deviceHandler) FlowUpdateIncremental(ctx context.Context, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 621 | apOfFlowChanges *of.FlowChanges, |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 622 | apOfGroupChanges *of.FlowGroupChanges, apFlowMetaData *of.FlowMetadata) error { |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 623 | logger.Debugw(ctx, "FlowUpdateIncremental started", log.Fields{"device-id": dh.DeviceID, "flow": apOfFlowChanges, "metadata": apFlowMetaData}) |
| 624 | var errorsList []error |
| 625 | var retError error |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 626 | if dh.GetPersRebootFlag(ctx) { |
| 627 | logger.Warnw(ctx, "FlowUpdateIncremental ignored as deivce is being configured post reboot", log.Fields{"device-id": dh.DeviceID}) |
| 628 | return fmt.Errorf("errors-installing-one-or-more-flows-groups-reboot-in-progress") |
| 629 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 630 | //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] | 631 | if apOfFlowChanges.ToRemove != nil { |
| 632 | for _, flowItem := range apOfFlowChanges.ToRemove.Items { |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 633 | if flowItem.GetCookie() == 0 { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 634 | 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] | 635 | "device-id": dh.DeviceID}) |
| 636 | retError = fmt.Errorf("flow-remove no cookie, device-id %s", dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 637 | errorsList = append(errorsList, retError) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 638 | continue |
| 639 | } |
| 640 | flowInPort := flow.GetInPort(flowItem) |
| 641 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 642 | logger.Warnw(ctx, "flow-remove inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 643 | retError = fmt.Errorf("flow-remove inPort invalid, device-id %s", dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 644 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 645 | continue |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 646 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 647 | } else if flowInPort == dh.ponPortNumber { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 648 | //this is some downstream flow, not regarded as error, just ignored |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 649 | 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] | 650 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 651 | continue |
| 652 | } else { |
| 653 | // this is the relevant upstream flow |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 654 | var loUniPort *cmn.OnuUniPort |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 655 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 656 | loUniPort = uniPort |
| 657 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 658 | 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] | 659 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 660 | 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] | 661 | flowInPort, dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 662 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 663 | continue |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 664 | } |
| 665 | flowOutPort := flow.GetOutPort(flowItem) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 666 | logger.Debugw(ctx, "flow-remove port indications", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 667 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 668 | "uniPortName": loUniPort.Name}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 669 | |
| 670 | if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) { |
| 671 | // Step1 : Fill flowControlBlock |
| 672 | // Step2 : Push the flowControlBlock to ONU channel |
| 673 | // Step3 : Wait on response channel for response |
| 674 | // Step4 : Return error value |
| 675 | startTime := time.Now() |
| 676 | respChan := make(chan error) |
| 677 | flowCb := FlowCb{ |
| 678 | ctx: ctx, |
| 679 | addFlow: false, |
| 680 | flowItem: flowItem, |
| 681 | flowMetaData: nil, |
| 682 | uniPort: loUniPort, |
| 683 | respChan: &respChan, |
| 684 | } |
| 685 | dh.flowCbChan[loUniPort.UniID] <- flowCb |
| 686 | logger.Infow(ctx, "process-flow-remove-start", log.Fields{"device-id": dh.DeviceID}) |
| 687 | // Wait on the channel for flow handlers return value |
| 688 | retError = <-respChan |
| 689 | logger.Infow(ctx, "process-flow-remove-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| 690 | if retError != nil { |
| 691 | logger.Warnw(ctx, "flow-delete processing error: continuing on checking further flows", |
| 692 | log.Fields{"device-id": dh.DeviceID, "error": retError}) |
| 693 | errorsList = append(errorsList, retError) |
| 694 | continue |
| 695 | } |
| 696 | } else { |
| 697 | retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID) |
| 698 | errorsList = append(errorsList, retError) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | } |
| 702 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 703 | if apOfFlowChanges.ToAdd != nil { |
| 704 | for _, flowItem := range apOfFlowChanges.ToAdd.Items { |
| 705 | if flowItem.GetCookie() == 0 { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 706 | 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] | 707 | "device-id": dh.DeviceID}) |
| 708 | retError = fmt.Errorf("flow-add no cookie, device-id %s", dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 709 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 710 | continue |
| 711 | } |
| 712 | flowInPort := flow.GetInPort(flowItem) |
| 713 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 714 | logger.Warnw(ctx, "flow-add inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 715 | retError = fmt.Errorf("flow-add inPort invalid, device-id %s", dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 716 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 717 | continue |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 718 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 719 | } else if flowInPort == dh.ponPortNumber { |
| 720 | //this is some downstream flow |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 721 | 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] | 722 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 723 | continue |
| 724 | } else { |
| 725 | // this is the relevant upstream flow |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 726 | var loUniPort *cmn.OnuUniPort |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 727 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 728 | loUniPort = uniPort |
| 729 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 730 | 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] | 731 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 732 | 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] | 733 | flowInPort, dh.DeviceID) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 734 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 735 | continue |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 736 | } |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 737 | // let's still assume that we receive the flow-add only in some 'active' device state (as so far observed) |
| 738 | // if not, we just throw some error here to have an indication about that, if we really need to support that |
| 739 | // then we would need to create some means to activate the internal stored flows |
| 740 | // after the device gets active automatically (and still with its dependency to the TechProfile) |
| 741 | // for state checking compare also code here: processInterAdapterTechProfileDownloadReqMessage |
| 742 | // also abort for the other still possible flows here |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 743 | if !dh.IsReadyForOmciConfig() { |
| 744 | logger.Errorw(ctx, "flow-add rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 745 | "last device-reason": dh.GetDeviceReasonString()}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 746 | retError = fmt.Errorf("improper device state on device %s", dh.DeviceID) |
| 747 | errorsList = append(errorsList, retError) |
| 748 | continue |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 749 | } |
| 750 | |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 751 | flowOutPort := flow.GetOutPort(flowItem) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 752 | logger.Debugw(ctx, "flow-add port indications", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 753 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 754 | "uniPortName": loUniPort.Name}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 755 | if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) { |
| 756 | // Step1 : Fill flowControlBlock |
| 757 | // Step2 : Push the flowControlBlock to ONU channel |
| 758 | // Step3 : Wait on response channel for response |
| 759 | // Step4 : Return error value |
| 760 | startTime := time.Now() |
| 761 | respChan := make(chan error) |
| 762 | flowCb := FlowCb{ |
| 763 | ctx: ctx, |
| 764 | addFlow: true, |
| 765 | flowItem: flowItem, |
| 766 | flowMetaData: apFlowMetaData, |
| 767 | uniPort: loUniPort, |
| 768 | respChan: &respChan, |
| 769 | } |
| 770 | dh.flowCbChan[loUniPort.UniID] <- flowCb |
| 771 | logger.Infow(ctx, "process-flow-add-start", log.Fields{"device-id": dh.DeviceID}) |
| 772 | // Wait on the channel for flow handlers return value |
| 773 | retError = <-respChan |
| 774 | logger.Infow(ctx, "process-flow-add-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| 775 | if retError != nil { |
| 776 | logger.Warnw(ctx, "flow-add processing error: continuing on checking further flows", |
| 777 | log.Fields{"device-id": dh.DeviceID, "error": retError}) |
| 778 | errorsList = append(errorsList, retError) |
| 779 | continue |
| 780 | } |
| 781 | } else { |
| 782 | retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID) |
| 783 | errorsList = append(errorsList, retError) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | } |
| 787 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 788 | if len(errorsList) > 0 { |
| 789 | logger.Errorw(ctx, "error-processing-flow", log.Fields{"device-id": dh.DeviceID, "errList": errorsList}) |
| 790 | return fmt.Errorf("errors-installing-one-or-more-flows-groups, errors:%v", errorsList) |
| 791 | } |
| 792 | return nil |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 795 | // disableDevice locks the ONU and its UNI/VEIP ports (admin lock via OMCI) |
| 796 | // following are the expected device states after this activity: |
| 797 | // 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] | 798 | // (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] | 799 | func (dh *deviceHandler) disableDevice(ctx context.Context, device *voltha.Device) { |
| 800 | 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] | 801 | dh.mutexForDisableDeviceRequested.Lock() |
| 802 | dh.disableDeviceRequested = true |
| 803 | dh.mutexForDisableDeviceRequested.Unlock() |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 804 | //admin-lock reason can also be used uniquely for setting the DeviceState accordingly |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 805 | //note that disableDevice sequences in some 'ONU active' state may yield also |
| 806 | // "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] | 807 | // - inblock state checking to prevent possibly unneeded processing (on command repitition) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 808 | if dh.getDeviceReason() != cmn.DrOmciAdminLock { |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 809 | //disable-device shall be just a UNi/ONU-G related admin state setting |
| 810 | //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] | 811 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 812 | if dh.IsReadyForOmciConfig() { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 813 | // disable UNI ports/ONU |
| 814 | // *** should generate UniDisableStateDone event - used to disable the port(s) on success |
| 815 | if dh.pLockStateFsm == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 816 | dh.createUniLockFsm(ctx, true, cmn.UniDisableStateDone) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 817 | } else { //LockStateFSM already init |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 818 | dh.pLockStateFsm.SetSuccessEvent(cmn.UniDisableStateDone) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 819 | dh.runUniLockFsm(ctx, true) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 820 | } |
| 821 | } else { |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 822 | logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 823 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID}) |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 824 | // disable device should have no impact on ConnStatus |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 825 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 826 | DeviceId: dh.DeviceID, |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 827 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 828 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 829 | }); err != nil { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 830 | //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] | 831 | 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] | 832 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 833 | // 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] | 834 | |
| 835 | //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] | 836 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciAdminLock, true) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 837 | } |
| ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 841 | // reEnableDevice unlocks the ONU and its UNI/VEIP ports (admin unlock via OMCI) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 842 | func (dh *deviceHandler) reEnableDevice(ctx context.Context, device *voltha.Device) { |
| 843 | 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] | 844 | |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 845 | //setting readyForOmciConfig here is just a workaround for BBSIM testing in the sequence |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 846 | // OnuSoftReboot-disable-enable, because BBSIM does not generate a new OnuIndication-Up event after SoftReboot |
| 847 | // which is the assumption for real ONU's, where the ready-state is then set according to the following MibUpload/Download |
| 848 | // for real ONU's that should have nearly no influence |
| 849 | // Note that for real ONU's there is anyway a problematic situation with following sequence: |
| 850 | // OnuIndication-Dw (or not active at all) (- disable) - enable: here already the LockFsm may run into timeout (no OmciResponse) |
| 851 | // but that anyway is hopefully resolved by some OnuIndication-Up event (maybe to be tested) |
| 852 | // 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] | 853 | dh.SetReadyForOmciConfig(true) //needed to allow subsequent flow/techProf config (on BBSIM) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 854 | |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 855 | // enable ONU/UNI ports |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 856 | // *** should generate cmn.UniEnableStateDone event - used to disable the port(s) on success |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 857 | dh.mutexForDisableDeviceRequested.Lock() |
| 858 | dh.disableDeviceRequested = false |
| 859 | dh.mutexForDisableDeviceRequested.Unlock() |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 860 | if dh.pUnlockStateFsm == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 861 | dh.createUniLockFsm(ctx, false, cmn.UniEnableStateDone) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 862 | } else { //UnlockStateFSM already init |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 863 | dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniEnableStateDone) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 864 | dh.runUniLockFsm(ctx, false) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 865 | } |
| ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 866 | } |
| 867 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 868 | func (dh *deviceHandler) reconcileDeviceOnuInd(ctx context.Context) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 869 | 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] | 870 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 871 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 872 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 873 | 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] | 874 | return |
| 875 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 876 | if err := pDevEntry.RestoreDataFromOnuKvStore(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 877 | if err == fmt.Errorf("no-ONU-data-found") { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 878 | 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] | 879 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 880 | 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] | 881 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 882 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 883 | return |
| Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 884 | } |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 885 | var onuIndication oop.OnuIndication |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 886 | pDevEntry.MutexPersOnuConfig.RLock() |
| 887 | onuIndication.IntfId = pDevEntry.SOnuPersistentData.PersIntfID |
| 888 | onuIndication.OnuId = pDevEntry.SOnuPersistentData.PersOnuID |
| 889 | onuIndication.OperState = pDevEntry.SOnuPersistentData.PersOperState |
| 890 | onuIndication.AdminState = pDevEntry.SOnuPersistentData.PersAdminState |
| 891 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 892 | _ = dh.createInterface(ctx, &onuIndication) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 893 | } |
| 894 | |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 895 | func (dh *deviceHandler) ReconcileDeviceTechProf(ctx context.Context) bool { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 896 | 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] | 897 | |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 898 | continueWithFlowConfig := false |
| 899 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 900 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 901 | if pDevEntry == nil { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 902 | 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] | 903 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| 904 | return continueWithFlowConfig |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 905 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 906 | dh.pOnuTP.LockTpProcMutex() |
| 907 | defer dh.pOnuTP.UnlockTpProcMutex() |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 908 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 909 | pDevEntry.MutexPersOnuConfig.RLock() |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 910 | persMutexLock := true |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 911 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 912 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 913 | 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] | 914 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 915 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| 916 | return continueWithFlowConfig |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 917 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 918 | flowsFound := false |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 919 | techProfsFound := false |
| 920 | techProfInstLoadFailed := false |
| 921 | outerLoop: |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 922 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 923 | uniID := uniData.PersUniID |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 924 | //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] | 925 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 926 | logger.Debugw(ctx, "reconciling - no TPs stored for uniID", |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 927 | log.Fields{"uni-id": uniID, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 928 | continue |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 929 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 930 | //release MutexPersOnuConfig before TechProfile (ANIConfig) processing as otherwise the reception of |
| 931 | // 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] | 932 | // 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] | 933 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 934 | persMutexLock = false |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 935 | 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] | 936 | var iaTechTpInst ia.TechProfileDownloadMessage |
| 937 | var ok bool |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 938 | for tpID := range uniData.PersTpPathMap { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 939 | pDevEntry.MutexReconciledTpInstances.RLock() |
| 940 | if iaTechTpInst, ok = pDevEntry.ReconciledTpInstances[uniID][tpID]; !ok { |
| 941 | logger.Errorw(ctx, "reconciling - no reconciled tp instance available", |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 942 | 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] | 943 | "device-id": dh.DeviceID}) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 944 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 945 | pDevEntry.MutexReconciledTpInstances.RUnlock() |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 946 | break outerLoop |
| 947 | } |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 948 | pDevEntry.MutexReconciledTpInstances.RUnlock() |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 949 | continueWithFlowConfig = true // valid TP found - try flow configuration later |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 950 | var tpInst tech_profile.TechProfileInstance |
| 951 | switch techTpInst := iaTechTpInst.TechTpInstance.(type) { |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 952 | case *ia.TechProfileDownloadMessage_TpInstance: // supports only GPON, XGPON, XGS-PON |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 953 | tpInst = *techTpInst.TpInstance |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 954 | logger.Debugw(ctx, "reconciling - received-tp-instance-successfully-after-reconcile", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 955 | "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] | 956 | default: // do not support epon or other tech |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 957 | logger.Errorw(ctx, "reconciling - unsupported-tech-profile", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 958 | "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] | 959 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 960 | break outerLoop |
| 961 | } |
| 962 | |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 963 | // deadline context to ensure completion of background routines waited for |
| 964 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 965 | 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] | 966 | dctx, cancel := context.WithDeadline(ctx, deadline) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 967 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 968 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniData.PersUniID, tpID) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 969 | var wg sync.WaitGroup |
| 970 | wg.Add(1) // for the 1 go routine to finish |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 971 | 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] | 972 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfReconcile") //wait for background process to finish |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 973 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniData.PersUniID, tpID); err != nil { |
| 974 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 975 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 976 | break outerLoop |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 977 | } |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 978 | } // for all TpPath entries for this UNI |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 979 | if len(uniData.PersFlowParams) != 0 { |
| 980 | flowsFound = true |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 981 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 982 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 983 | persMutexLock = true |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 984 | } // for all UNI entries from SOnuPersistentData |
| 985 | if persMutexLock { // if loop was left with MutexPersOnuConfig still set |
| 986 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 987 | } |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 988 | |
| 989 | //had to move techProf/flow result evaluation into separate function due to SCA complexity limit |
| 990 | dh.updateReconcileStates(ctx, techProfsFound, techProfInstLoadFailed, flowsFound) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 991 | |
| 992 | return continueWithFlowConfig |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | func (dh *deviceHandler) updateReconcileStates(ctx context.Context, |
| 996 | abTechProfsFound bool, abTechProfInstLoadFailed bool, abFlowsFound bool) { |
| 997 | if !abTechProfsFound { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 998 | 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] | 999 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1000 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1001 | return |
| 1002 | } |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1003 | if abTechProfInstLoadFailed { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1004 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadFailed, dh.IsReconcilingReasonUpdate()) |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1005 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 1006 | return |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1007 | } else if dh.IsSkipOnuConfigReconciling() { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1008 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, dh.IsReconcilingReasonUpdate()) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1009 | } |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1010 | if !abFlowsFound { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1011 | 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] | 1012 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1013 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1014 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1017 | func (dh *deviceHandler) ReconcileDeviceFlowConfig(ctx context.Context) { |
| 1018 | 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] | 1019 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1020 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1021 | if pDevEntry == nil { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1022 | 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] | 1023 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1024 | return |
| 1025 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1026 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1027 | pDevEntry.MutexPersOnuConfig.RLock() |
| 1028 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 1029 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1030 | 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] | 1031 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1032 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1033 | return |
| 1034 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1035 | flowsFound := false |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1036 | var uniVlanConfigEntries []uint8 |
| 1037 | var loWaitGroupWTO cmn.WaitGroupWithTimeOut |
| 1038 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1039 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1040 | //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support |
| 1041 | if len(uniData.PersFlowParams) == 0 { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1042 | logger.Debugw(ctx, "reconciling - no flows stored for uniID", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1043 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1044 | continue |
| 1045 | } |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1046 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1047 | logger.Warnw(ctx, "reconciling flows - but no TPs stored for uniID, abort", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1048 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 1049 | // It doesn't make sense to configure any flows if no TPs are available |
| 1050 | continue |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1051 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1052 | //release MutexPersOnuConfig before VlanConfig processing as otherwise the reception of |
| 1053 | // 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] | 1054 | // 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] | 1055 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1056 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1057 | var uniPort *cmn.OnuUniPort |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1058 | var exist bool |
| Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 1059 | 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] | 1060 | if uniPort, exist = dh.uniEntityMap[uniNo]; !exist { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1061 | logger.Errorw(ctx, "reconciling - OnuUniPort data not found - terminate reconcilement", |
| 1062 | log.Fields{"uniNo": uniNo, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1063 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1064 | return |
| 1065 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1066 | //needed to split up function due to sca complexity |
| 1067 | dh.updateReconcileFlowConfig(ctx, uniPort, uniData.PersFlowParams, uniVlanConfigEntries, &loWaitGroupWTO, &flowsFound) |
| 1068 | |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1069 | logger.Debugw(ctx, "reconciling - flows processed", log.Fields{ |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1070 | "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1071 | "NumUniFlows": dh.UniVlanConfigFsmMap[uniData.PersUniID].NumUniFlows, |
| 1072 | "ConfiguredUniFlow": dh.UniVlanConfigFsmMap[uniData.PersUniID].ConfiguredUniFlow}) |
| Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 1073 | // this can't be used as global finished reconciling flag because |
| 1074 | // assumes is getting called before the state machines for the last flow is completed, |
| 1075 | // while this is not guaranteed. |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1076 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| 1077 | } // for all UNI entries from SOnuPersistentData |
| 1078 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1079 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1080 | if !flowsFound { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1081 | 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] | 1082 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1083 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1084 | return |
| 1085 | } |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1086 | logger.Debugw(ctx, "reconciling flows - waiting on ready indication of requested UNIs", log.Fields{ |
| 1087 | "device-id": dh.DeviceID, "expiry": dh.reconcileExpiryVlanConfig}) |
| 1088 | if executed := loWaitGroupWTO.WaitTimeout(dh.reconcileExpiryVlanConfig); executed { |
| 1089 | logger.Debugw(ctx, "reconciling flows for all UNI's has been finished in time", |
| 1090 | log.Fields{"device-id": dh.DeviceID}) |
| 1091 | dh.stopReconciling(ctx, true, cWaitReconcileFlowAbortOnSuccess) |
| 1092 | if pDevEntry != nil { |
| 1093 | pDevEntry.SendChReconcilingFlowsFinished(ctx, true) |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1094 | } |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1095 | } else { |
| 1096 | logger.Errorw(ctx, "reconciling - timeout waiting for reconciling flows for all UNI's to be finished!", |
| 1097 | log.Fields{"device-id": dh.DeviceID}) |
| 1098 | dh.stopReconciling(ctx, false, cWaitReconcileFlowAbortOnError) |
| 1099 | if pDevEntry != nil { |
| 1100 | pDevEntry.SendChReconcilingFlowsFinished(ctx, false) |
| 1101 | } |
| 1102 | return |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1103 | } |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1104 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsPushed, dh.IsReconcilingReasonUpdate()) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1107 | func (dh *deviceHandler) updateReconcileFlowConfig(ctx context.Context, apUniPort *cmn.OnuUniPort, |
| 1108 | aPersFlowParam []cmn.UniVlanFlowParams, aUniVlanConfigEntries []uint8, |
| 1109 | apWaitGroup *cmn.WaitGroupWithTimeOut, apFlowsFound *bool) { |
| 1110 | flowsProcessed := 0 |
| 1111 | lastFlowToReconcile := false |
| 1112 | loUniID := apUniPort.UniID |
| 1113 | for _, flowData := range aPersFlowParam { |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1114 | if !(*apFlowsFound) { |
| 1115 | *apFlowsFound = true |
| 1116 | syncChannel := make(chan struct{}) |
| 1117 | // start go routine with select() on reconciling vlan config channel before |
| 1118 | // starting vlan config reconciling process to prevent loss of any signal |
| 1119 | // this routine just collects all the received 'flow-reconciled' signals - possibly from different UNI's |
| 1120 | go dh.waitOnUniVlanConfigReconcilingReady(ctx, syncChannel, apWaitGroup) |
| 1121 | //block until the wait routine is really blocked on channel input |
| 1122 | // in order to prevent to early ready signal from VlanConfig processing |
| 1123 | <-syncChannel |
| 1124 | } |
| 1125 | if flowsProcessed == len(aPersFlowParam)-1 { |
| 1126 | var uniAdded bool |
| 1127 | lastFlowToReconcile = true |
| 1128 | if aUniVlanConfigEntries, uniAdded = dh.appendIfMissing(aUniVlanConfigEntries, loUniID); uniAdded { |
| 1129 | apWaitGroup.Add(1) //increment the waiting group |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1130 | } |
| 1131 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1132 | logger.Debugw(ctx, "reconciling - add flow with cookie slice", log.Fields{ |
| 1133 | "device-id": dh.DeviceID, "uni-id": loUniID, |
| 1134 | "flowsProcessed": flowsProcessed, "cookies": flowData.CookieSlice}) |
| 1135 | dh.lockVlanConfig.Lock() |
| 1136 | //the CookieSlice can be passed 'by value' here, - which internally passes its reference |
| 1137 | if _, exist := dh.UniVlanConfigFsmMap[loUniID]; exist { |
| 1138 | if err := dh.UniVlanConfigFsmMap[loUniID].SetUniFlowParams(ctx, flowData.VlanRuleParams.TpID, |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 1139 | 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] | 1140 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1141 | } |
| 1142 | } else { |
| 1143 | if err := dh.createVlanFilterFsm(ctx, apUniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice, |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 1144 | uint16(flowData.VlanRuleParams.MatchVid), uint8(flowData.VlanRuleParams.MatchPcp), uint16(flowData.VlanRuleParams.SetVid), |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 1145 | 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] | 1146 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1147 | } |
| 1148 | } |
| 1149 | dh.lockVlanConfig.Unlock() |
| 1150 | flowsProcessed++ |
| 1151 | } //for all flows of this UNI |
| 1152 | } |
| 1153 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1154 | // waitOnUniVlanConfigReconcilingReady collects all VlanConfigReady signals from VlanConfig FSM processing in reconciling |
| 1155 | // |
| 1156 | // and decrements the according handler wait group waiting for these indications |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1157 | func (dh *deviceHandler) waitOnUniVlanConfigReconcilingReady(ctx context.Context, aSyncChannel chan<- struct{}, |
| 1158 | waitGroup *cmn.WaitGroupWithTimeOut) { |
| 1159 | var reconciledUniVlanConfigEntries []uint8 |
| 1160 | var appended bool |
| 1161 | expiry := dh.GetReconcileExpiryVlanConfigAbort() |
| 1162 | logger.Debugw(ctx, "start waiting on reconcile vlanConfig ready indications", log.Fields{ |
| 1163 | "device-id": dh.DeviceID, "expiry": expiry}) |
| 1164 | // indicate blocking on channel now to the caller |
| 1165 | aSyncChannel <- struct{}{} |
| 1166 | for { |
| 1167 | select { |
| 1168 | case uniIndication := <-dh.chUniVlanConfigReconcilingDone: |
| 1169 | switch uniIndication { |
| 1170 | // no activity requested (should normally not be received) - just continue waiting |
| 1171 | case cWaitReconcileFlowNoActivity: |
| 1172 | // waiting on channel inputs from VlanConfig for all UNI's to be aborted on error condition |
| 1173 | case cWaitReconcileFlowAbortOnError: |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1174 | logger.Warn(ctx, "waitReconcileFlow aborted on error", |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1175 | log.Fields{"device-id": dh.DeviceID, "rxEntries": reconciledUniVlanConfigEntries}) |
| 1176 | return |
| 1177 | // waiting on channel inputs from VlanConfig for all UNI's to be aborted on success condition |
| 1178 | case cWaitReconcileFlowAbortOnSuccess: |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1179 | logger.Warn(ctx, "waitReconcileFlow aborted on success", |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1180 | log.Fields{"device-id": dh.DeviceID, "rxEntries": reconciledUniVlanConfigEntries}) |
| 1181 | return |
| 1182 | // this should be a valid UNI vlan config done indication |
| 1183 | default: |
| 1184 | if uniIndication < platform.MaxUnisPerOnu { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1185 | logger.Info(ctx, "reconciling flows has been finished in time for this UNI", |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1186 | log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| 1187 | if reconciledUniVlanConfigEntries, appended = |
| 1188 | dh.appendIfMissing(reconciledUniVlanConfigEntries, uint8(uniIndication)); appended { |
| 1189 | waitGroup.Done() |
| 1190 | } |
| 1191 | } else { |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 1192 | 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] | 1193 | } |
| 1194 | } //switch uniIndication |
| 1195 | |
| 1196 | case <-time.After(expiry): //a bit longer than reconcileExpiryVlanConfig |
| 1197 | logger.Errorw(ctx, "timeout waiting for reconciling all UNI flows to be finished!", |
| 1198 | log.Fields{"device-id": dh.DeviceID}) |
| 1199 | return |
| 1200 | } |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | func (dh *deviceHandler) GetReconcileExpiryVlanConfigAbort() time.Duration { |
| 1205 | return dh.reconcileExpiryVlanConfig + (500 * time.Millisecond) |
| 1206 | } |
| 1207 | |
| 1208 | func (dh *deviceHandler) appendIfMissing(slice []uint8, val uint8) ([]uint8, bool) { |
| 1209 | for _, ele := range slice { |
| 1210 | if ele == val { |
| 1211 | return slice, false |
| 1212 | } |
| 1213 | } |
| 1214 | return append(slice, val), true |
| 1215 | } |
| 1216 | |
| 1217 | // sendChReconcileFinished - sends true or false on reconcileFinish channel |
| 1218 | func (dh *deviceHandler) sendChReconcileFinished(success bool) { |
| 1219 | if dh != nil { //if the object still exists (might have been already deleted in background) |
| 1220 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1221 | select { |
| 1222 | case dh.chReconcilingFinished <- success: |
| 1223 | default: |
| 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | // SendChUniVlanConfigFinished - sends the Uni number on channel if the flow reconcilement for this UNI is finished |
| 1229 | func (dh *deviceHandler) SendChUniVlanConfigFinished(value uint16) { |
| 1230 | if dh != nil { //if the object still exists (might have been already deleted in background) |
| 1231 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1232 | select { |
| 1233 | case dh.chUniVlanConfigReconcilingDone <- value: |
| 1234 | default: |
| 1235 | } |
| 1236 | } |
| 1237 | } |
| 1238 | |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 1239 | func (dh *deviceHandler) DeviceFlowConfigOnReboot(ctx context.Context) { |
| 1240 | logger.Debugw(ctx, "rebooting - trigger flow config", log.Fields{"device-id": dh.DeviceID}) |
| 1241 | |
| 1242 | defer dh.UpdateAndStoreRebootState(ctx, false) |
| 1243 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 1244 | if pDevEntry == nil { |
| 1245 | logger.Errorw(ctx, "rebooting - no valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 1246 | return |
| 1247 | } |
| 1248 | |
| 1249 | pDevEntry.MutexPersOnuConfig.RLock() |
| 1250 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 1251 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1252 | logger.Warn(ctx, "rebooting - no uni-configs have been stored - aborting", |
| 1253 | log.Fields{"device-id": dh.DeviceID}) |
| 1254 | return |
| 1255 | } |
| 1256 | flowsFound := false |
| 1257 | var uniVlanConfigEntries []uint8 |
| 1258 | var loWaitGroupWTO cmn.WaitGroupWithTimeOut |
| 1259 | |
| 1260 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
| 1261 | //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support |
| 1262 | if len(uniData.PersFlowParams) == 0 { |
| 1263 | logger.Debugw(ctx, "rebooting - no flows stored for uniID", |
| 1264 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| 1265 | continue |
| 1266 | } |
| 1267 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
| 1268 | logger.Warnw(ctx, "rebooting - but no TPs stored for uniID, abort", |
| 1269 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| 1270 | // It doesn't make sense to configure any flows if no TPs are available |
| 1271 | continue |
| 1272 | } |
| 1273 | //release MutexPersOnuConfig before VlanConfig processing as otherwise the reception of |
| 1274 | // OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI |
| 1275 | // frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap |
| 1276 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1277 | |
| 1278 | var uniPort *cmn.OnuUniPort |
| 1279 | var exist bool |
| 1280 | uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), uint32(uniData.PersUniID)) |
| 1281 | if uniPort, exist = dh.uniEntityMap[uniNo]; !exist { |
| 1282 | logger.Errorw(ctx, "rebooting - OnuUniPort data not found - terminate flow config", |
| 1283 | log.Fields{"uniNo": uniNo, "device-id": dh.DeviceID}) |
| 1284 | return |
| 1285 | } |
| 1286 | |
| 1287 | dh.updateOnRebootFlowConfig(ctx, uniPort, uniData.PersFlowParams, uniVlanConfigEntries, &loWaitGroupWTO, &flowsFound) |
| 1288 | |
| 1289 | logger.Debugw(ctx, "rebooting - flows processed", log.Fields{ |
| 1290 | "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, |
| 1291 | "NumUniFlows": dh.UniVlanConfigFsmMap[uniData.PersUniID].NumUniFlows, |
| 1292 | "ConfiguredUniFlow": dh.UniVlanConfigFsmMap[uniData.PersUniID].ConfiguredUniFlow}) |
| 1293 | // this can't be used as global finished reconciling flag because |
| 1294 | // assumes is getting called before the state machines for the last flow is completed, |
| 1295 | // while this is not guaranteed. |
| 1296 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| 1297 | } // for all UNI entries from SOnuPersistentData |
| 1298 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1299 | |
| 1300 | if !flowsFound { |
| 1301 | logger.Warn(ctx, "rebooting - no flows have been stored before device reboot - terminate flow config", |
| 1302 | log.Fields{"device-id": dh.DeviceID}) |
| 1303 | return |
| 1304 | } |
| 1305 | logger.Debugw(ctx, "rebooting - waiting on ready indication of requested UNIs", log.Fields{ |
| 1306 | "device-id": dh.DeviceID, "expiry": dh.reconcileExpiryVlanConfig}) |
| 1307 | if executed := loWaitGroupWTO.WaitTimeout(dh.reconcileExpiryVlanConfig); executed { |
| 1308 | logger.Debugw(ctx, "rebooting - flow config for all UNI's has been finished in time", |
| 1309 | log.Fields{"device-id": dh.DeviceID}) |
| 1310 | } else { |
| 1311 | logger.Errorw(ctx, "rebooting - timeout waiting for flow config for all UNI's to be finished!", |
| 1312 | log.Fields{"device-id": dh.DeviceID}) |
| 1313 | return |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | func (dh *deviceHandler) UpdateAndStoreRebootState(ctx context.Context, flag bool) { |
| 1318 | dh.UpdateRebootPersData(ctx, flag) |
| 1319 | if err := dh.StorePersistentData(ctx); err != nil { |
| 1320 | logger.Errorw(ctx, "rebooting - failed to store persistent data in kv store", log.Fields{"device-id": dh.DeviceID}) |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | func (dh *deviceHandler) updateOnRebootFlowConfig(ctx context.Context, apUniPort *cmn.OnuUniPort, |
| 1325 | aPersFlowParam []cmn.UniVlanFlowParams, aUniVlanConfigEntries []uint8, |
| 1326 | apWaitGroup *cmn.WaitGroupWithTimeOut, apFlowsFound *bool) { |
| 1327 | flowsProcessed := 0 |
| 1328 | lastFlowToConfigOnReboot := false |
| 1329 | loUniID := apUniPort.UniID |
| 1330 | for _, flowData := range aPersFlowParam { |
| 1331 | if !(*apFlowsFound) { |
| 1332 | *apFlowsFound = true |
| 1333 | syncChannel := make(chan struct{}) |
| 1334 | // start go routine with select() on reconciling vlan config channel before |
| 1335 | // starting vlan config reconciling process to prevent loss of any signal |
| 1336 | // this routine just collects all the received 'flow-reconciled' signals - possibly from different UNI's |
| 1337 | go dh.waitOnUniVlanConfigOnRebootReady(ctx, syncChannel, apWaitGroup) |
| 1338 | //block until the wait routine is really blocked on channel input |
| 1339 | // in order to prevent to early ready signal from VlanConfig processing |
| 1340 | <-syncChannel |
| 1341 | } |
| 1342 | if flowsProcessed == len(aPersFlowParam)-1 { |
| 1343 | var uniAdded bool |
| 1344 | lastFlowToConfigOnReboot = true |
| 1345 | if aUniVlanConfigEntries, uniAdded = dh.appendIfMissing(aUniVlanConfigEntries, loUniID); uniAdded { |
| 1346 | apWaitGroup.Add(1) //increment the waiting group |
| 1347 | } |
| 1348 | } |
| 1349 | logger.Debugw(ctx, "rebooting - add flow with cookie slice", log.Fields{ |
| 1350 | "device-id": dh.DeviceID, "uni-id": loUniID, |
| 1351 | "flowsProcessed": flowsProcessed, "cookies": flowData.CookieSlice}) |
| 1352 | dh.lockVlanConfig.Lock() |
| 1353 | //the CookieSlice can be passed 'by value' here, - which internally passes its reference |
| 1354 | if _, exist := dh.UniVlanConfigFsmMap[loUniID]; exist { |
| 1355 | if err := dh.UniVlanConfigFsmMap[loUniID].SetUniFlowParams(ctx, flowData.VlanRuleParams.TpID, |
| 1356 | 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 { |
| 1357 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1358 | } |
| 1359 | } else { |
| 1360 | if err := dh.createVlanFilterFsm(ctx, apUniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice, |
| 1361 | uint16(flowData.VlanRuleParams.MatchVid), uint8(flowData.VlanRuleParams.MatchPcp), uint16(flowData.VlanRuleParams.SetVid), |
| 1362 | uint8(flowData.VlanRuleParams.SetPcp), flowData.VlanRuleParams.InnerCvlan, cmn.OmciVlanFilterAddDone, false, lastFlowToConfigOnReboot, flowData.Meter, nil); err != nil { |
| 1363 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1364 | } |
| 1365 | } |
| 1366 | dh.lockVlanConfig.Unlock() |
| 1367 | flowsProcessed++ |
| 1368 | } //for all flows of this UNI |
| 1369 | } |
| 1370 | |
| 1371 | func (dh *deviceHandler) waitOnUniVlanConfigOnRebootReady(ctx context.Context, aSyncChannel chan<- struct{}, |
| 1372 | waitGroup *cmn.WaitGroupWithTimeOut) { |
| 1373 | var rebootUniVlanConfigEntries []uint8 |
| 1374 | var appended bool |
| 1375 | expiry := dh.GetReconcileExpiryVlanConfigAbort() |
| 1376 | logger.Debugw(ctx, "start waiting on vlanConfig ready indications on reboot", log.Fields{ |
| 1377 | "device-id": dh.DeviceID, "expiry": expiry}) |
| 1378 | // indicate blocking on channel now to the caller |
| 1379 | aSyncChannel <- struct{}{} |
| 1380 | for { |
| 1381 | select { |
| 1382 | case <-dh.deviceDeleteCommChan: |
| 1383 | // Cancel the context and return |
| 1384 | logger.Warnw(ctx, "Device Deletion invoked , stop further processing ", log.Fields{"device-id": dh.DeviceID}) |
| 1385 | return |
| 1386 | |
| 1387 | case uniIndication := <-dh.chUniVlanConfigOnRebootDone: |
| 1388 | switch uniIndication { |
| 1389 | // this should be a valid UNI vlan config done indication |
| 1390 | default: |
| 1391 | if uniIndication < platform.MaxUnisPerOnu { |
| 1392 | logger.Info(ctx, "rebooting - configuring flows has been finished in time for this UNI", |
| 1393 | log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| 1394 | if rebootUniVlanConfigEntries, appended = |
| 1395 | dh.appendIfMissing(rebootUniVlanConfigEntries, uint8(uniIndication)); appended { |
| 1396 | waitGroup.Done() |
| 1397 | } |
| 1398 | } else { |
| 1399 | logger.Errorw(ctx, "received unexpected UNI flowConfig done indication - is ignored", log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| 1400 | } |
| 1401 | } //switch uniIndication |
| 1402 | |
| 1403 | case <-time.After(expiry): |
| 1404 | logger.Errorw(ctx, "timeout waiting for configuring all UNI flows to be finished!", |
| 1405 | log.Fields{"device-id": dh.DeviceID}) |
| 1406 | return |
| 1407 | } |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | func (dh *deviceHandler) SendChUniVlanConfigFinishedOnReboot(value uint16) { |
| 1412 | if dh != nil { //if the object still exists (might have been already deleted in background) |
| 1413 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1414 | select { |
| 1415 | case dh.chUniVlanConfigOnRebootDone <- value: |
| 1416 | default: |
| 1417 | } |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | func (dh *deviceHandler) CheckForDeviceTechProf(ctx context.Context) bool { |
| 1422 | logger.Info(ctx, "Check for tech profile config", log.Fields{"device-id": dh.DeviceID}) |
| 1423 | techProfInstLoadFailed := false |
| 1424 | continueWithFlowConfig := false |
| 1425 | defer dh.UpdateAndStoreRebootState(ctx, continueWithFlowConfig) |
| 1426 | // Stop any on going reconciling thread as the flow configuration post reboot will be performed here |
| 1427 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| 1428 | |
| 1429 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 1430 | if pDevEntry == nil { |
| 1431 | logger.Errorw(ctx, "no valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 1432 | return continueWithFlowConfig |
| 1433 | } |
| 1434 | dh.lockDevice.RLock() |
| 1435 | if dh.pOnuTP == nil { |
| 1436 | //should normally not happen ... |
| 1437 | logger.Warnw(ctx, "onuTechProf instance not set up - ignoring request", |
| 1438 | log.Fields{"device-id": dh.DeviceID}) |
| 1439 | dh.lockDevice.RUnlock() |
| 1440 | return continueWithFlowConfig |
| 1441 | } |
| 1442 | |
| 1443 | dh.pOnuTP.LockTpProcMutex() |
| 1444 | defer dh.pOnuTP.UnlockTpProcMutex() |
| 1445 | defer dh.lockDevice.RUnlock() |
| 1446 | |
| 1447 | pDevEntry.MutexPersOnuConfig.RLock() |
| 1448 | persMutexLock := true |
| 1449 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 1450 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1451 | logger.Info(ctx, "no uni-configs have been stored - aborting", |
| 1452 | log.Fields{"device-id": dh.DeviceID}) |
| 1453 | return continueWithFlowConfig |
| 1454 | } |
| 1455 | |
| 1456 | outerLoop: |
| 1457 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
| 1458 | uniID := uniData.PersUniID |
| 1459 | |
| 1460 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
| 1461 | logger.Debugw(ctx, "no TPs stored for uniID", |
| 1462 | log.Fields{"uni-id": uniID, "device-id": dh.DeviceID}) |
| 1463 | continue |
| 1464 | } |
| 1465 | //release MutexPersOnuConfig before TechProfile (ANIConfig) processing as otherwise the reception of |
| 1466 | // OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI |
| 1467 | // frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap |
| 1468 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1469 | persMutexLock = false |
| 1470 | for tpID, tpPath := range uniData.PersTpPathMap { |
| 1471 | if tpPath != "" { |
| 1472 | logger.Infow(ctx, "Starting retrieval for TechProfileInstance", log.Fields{ |
| 1473 | "uniID": uniID, "tpID": tpID, "tpPath": tpPath, "device-id": dh.DeviceID, |
| 1474 | }) |
| 1475 | // Attempt the initial call before entering the retry loop |
| 1476 | iaTechTpInst, err := dh.GetTechProfileInstanceFromParentAdapter(ctx, uniID, tpPath) |
| 1477 | if err != nil { |
| 1478 | logger.Warnw(ctx, "Starting retrieval for TechProfileInstance", log.Fields{ |
| 1479 | "uniID": uniID, "tpID": tpID, "tpPath": tpPath, "device-id": dh.DeviceID, |
| 1480 | }) |
| 1481 | techProfInstLoadFailed = true |
| 1482 | break outerLoop |
| 1483 | } |
| 1484 | if iaTechTpInst != nil { |
| 1485 | var tpInst tech_profile.TechProfileInstance |
| 1486 | switch techTpInst := iaTechTpInst.TechTpInstance.(type) { |
| 1487 | case *ia.TechProfileDownloadMessage_TpInstance: // supports only GPON, XGPON, XGS-PON |
| 1488 | tpInst = *techTpInst.TpInstance |
| 1489 | logger.Debugw(ctx, "received-tp-instance-successfully-after-reboot", log.Fields{ |
| 1490 | "tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| 1491 | default: // do not support epon or other tech |
| 1492 | logger.Errorw(ctx, "unsupported-tech-profile", log.Fields{ |
| 1493 | "tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
| 1494 | techProfInstLoadFailed = true |
| 1495 | break outerLoop |
| 1496 | } |
| 1497 | |
| 1498 | continueWithFlowConfig = true |
| 1499 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 1500 | dctx, cancel := context.WithDeadline(ctx, deadline) |
| 1501 | |
| 1502 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniData.PersUniID, tpID) |
| 1503 | var wg sync.WaitGroup |
| 1504 | wg.Add(1) // for the 1 go routine to finish |
| 1505 | go dh.pOnuTP.ConfigureUniTp(log.WithSpanFromContext(dctx, ctx), uniData.PersUniID, uniData.PersTpPathMap[tpID], tpInst, &wg) |
| 1506 | // Wait for either completion or cancellation |
| 1507 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfDwldDuringReboot") |
| 1508 | if tpErr := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); tpErr != nil { |
| 1509 | logger.Errorw(ctx, "error-processing-tp", log.Fields{"device-id": dh.DeviceID, "err": tpErr, "tp-path": uniData.PersTpPathMap[tpID]}) |
| 1510 | techProfInstLoadFailed = true |
| 1511 | continueWithFlowConfig = false |
| 1512 | break outerLoop |
| 1513 | } |
| 1514 | } else { |
| 1515 | logger.Errorw(ctx, "Tp instance is not valid", log.Fields{"tp-id": tpID, "tpPath": tpPath, "device-id": dh.DeviceID, "err": err}) |
| 1516 | techProfInstLoadFailed = true |
| 1517 | break outerLoop |
| 1518 | } |
| 1519 | } else { |
| 1520 | logger.Errorw(ctx, "Tp instance is nil", log.Fields{"tp-id": tpID, "tpPath": tpPath, |
| 1521 | "uni-id": uniID, "device-id": dh.DeviceID}) |
| 1522 | techProfInstLoadFailed = true |
| 1523 | break outerLoop |
| 1524 | } |
| 1525 | } |
| 1526 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| 1527 | persMutexLock = true |
| 1528 | } |
| 1529 | if persMutexLock { |
| 1530 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 1531 | } |
| 1532 | go dh.deviceRebootStateUpdate(ctx, techProfInstLoadFailed) |
| 1533 | return continueWithFlowConfig |
| 1534 | } |
| 1535 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1536 | func (dh *deviceHandler) deleteDevicePersistencyData(ctx context.Context) error { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1537 | 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] | 1538 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1539 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1540 | if pDevEntry == nil { |
| mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1541 | //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] | 1542 | 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] | 1543 | return nil |
| Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1544 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1545 | |
| 1546 | // deadline context to ensure completion of background routines waited for |
| 1547 | //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] | 1548 | 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] | 1549 | dctx, cancel := context.WithDeadline(ctx, deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 1550 | defer cancel() |
| 1551 | err := pDevEntry.DeleteDataFromOnuKvStore(log.WithSpanFromContext(dctx, ctx)) |
| 1552 | if err != nil { |
| 1553 | logger.Errorw(ctx, "delete data from onu kv store failed", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 1554 | return err |
| 1555 | } |
| 1556 | return nil |
| Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1559 | // func (dh *deviceHandler) rebootDevice(ctx context.Context, device *voltha.Device) error { |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1560 | // before this change here return like this was used: |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1561 | // |
| 1562 | // return fmt.Errorf("device-unreachable: %s, %s", dh.DeviceID, device.SerialNumber) |
| 1563 | // |
| 1564 | // was and is called in background - error return does not make sense |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1565 | func (dh *deviceHandler) rebootDevice(ctx context.Context, aCheckDeviceState bool, device *voltha.Device) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1566 | 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] | 1567 | if aCheckDeviceState && device.ConnectStatus != voltha.ConnectStatus_REACHABLE { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1568 | logger.Errorw(ctx, "device-unreachable", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1569 | return |
| ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1570 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1571 | if err := dh.pOnuOmciDevice.Reboot(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1572 | //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] | 1573 | logger.Errorw(ctx, "error-rebooting-device", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1574 | return |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1575 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1576 | |
| 1577 | //transfer the possibly modified logical uni port state |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1578 | dh.DisableUniPortStateUpdate(ctx) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1579 | |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 1580 | logger.Debugw(ctx, "call DeviceStateUpdate upon reboot", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1581 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID}) |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 1582 | // do not set the ConnStatus here as it may conflict with the parallel setting from ONU down indication (updateInterface()) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1583 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1584 | DeviceId: dh.DeviceID, |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 1585 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1586 | OperStatus: voltha.OperStatus_DISCOVERED, |
| 1587 | }); err != nil { |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1588 | //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] | 1589 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1590 | return |
| ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1591 | } |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 1592 | if err := dh.ReasonUpdate(ctx, cmn.DrRebooting, true); err != nil { |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1593 | return |
| ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1594 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1595 | dh.SetReadyForOmciConfig(false) |
| mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1596 | //no specific activity to synchronize any internal FSM to the 'rebooted' state is explicitly done here |
| 1597 | // the expectation ids for a real device, that it will be synced with the expected following 'down' indication |
| 1598 | // as BBSIM does not support this testing requires explicite disable/enable device calls in which sequence also |
| 1599 | // all other FSM's should be synchronized again |
| ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1600 | } |
| 1601 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1602 | // doOnuSwUpgrade initiates the SW download transfer to the ONU and on success activates the (inactive) image |
| 1603 | // |
| 1604 | // used only for old - R2.7 style - upgrade API |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1605 | func (dh *deviceHandler) doOnuSwUpgrade(ctx context.Context, apImageDsc *voltha.ImageDownload, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1606 | apDownloadManager *swupg.AdapterDownloadManager) error { |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1607 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1608 | "device-id": dh.DeviceID, "image-name": (*apImageDsc).Name}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1609 | |
| 1610 | var err error |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1611 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1612 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1613 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1614 | 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] | 1615 | } |
| 1616 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1617 | if dh.IsReadyForOmciConfig() { |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1618 | var inactiveImageID uint16 |
| 1619 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1620 | dh.lockUpgradeFsm.Lock() |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1621 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| 1622 | // but must be still locked at calling createOnuUpgradeFsm |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1623 | if dh.pOnuUpradeFsm == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1624 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1625 | dh.lockUpgradeFsm.Unlock() |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1626 | if err == nil { |
| 1627 | if err = dh.pOnuUpradeFsm.SetDownloadParams(ctx, inactiveImageID, apImageDsc, apDownloadManager); err != nil { |
| 1628 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1629 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1630 | } |
| 1631 | } else { |
| 1632 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1633 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1634 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1635 | } else { //OnuSw upgrade already running - restart (with possible abort of running) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1636 | dh.lockUpgradeFsm.Unlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1637 | 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] | 1638 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1639 | dh.upgradeCanceled = true |
| 1640 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1641 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1642 | //no effort spent anymore for the old API to automatically cancel and restart the download |
| 1643 | // like done for the new API |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1644 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1645 | } else { |
| 1646 | 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] | 1647 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1648 | } |
| 1649 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1650 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no active OMCI connection", log.Fields{"device-id": dh.DeviceID}) |
| 1651 | 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] | 1652 | } |
| 1653 | return err |
| mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1656 | // 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] | 1657 | // after the OnuImage has been downloaded to the adapter, called in background |
| 1658 | func (dh *deviceHandler) onuSwUpgradeAfterDownload(ctx context.Context, apImageRequest *voltha.DeviceImageDownloadRequest, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1659 | apDownloadManager *swupg.FileDownloadManager, aImageIdentifier string) { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1660 | |
| 1661 | var err error |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1662 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1663 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1664 | 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] | 1665 | return |
| 1666 | } |
| 1667 | |
| 1668 | var inactiveImageID uint16 |
| 1669 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1670 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1671 | "device-id": dh.DeviceID, "image-version": apImageRequest.Image.Version, "to onu-image": inactiveImageID}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1672 | |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1673 | dh.lockUpgradeFsm.Lock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1674 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1675 | // but must be still locked at calling createOnuUpgradeFsm |
| 1676 | // (and working with a local pointer copy does not work here if asynchronous request are done to fast |
| 1677 | // [e.g.leaving the local pointer on nil even though a creation is already on the way]) |
| 1678 | if dh.pOnuUpradeFsm != nil { |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1679 | //OnuSw upgrade already running on this device (e.g. with activate/commit not yet set) |
| 1680 | // abort the current processing, running upgrades are always aborted by newer request |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1681 | 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] | 1682 | //flush the remove upgradeFsmChan channel |
| 1683 | select { |
| 1684 | case <-dh.upgradeFsmChan: |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1685 | logger.Debugw(ctx, "flushed-upgrade-fsm-channel", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1686 | default: |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1687 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1688 | dh.lockUpgradeFsm.Unlock() |
| 1689 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1690 | dh.upgradeCanceled = true |
| 1691 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1692 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1693 | select { |
| 1694 | case <-time.After(cTimeOutRemoveUpgrade * time.Second): |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1695 | 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] | 1696 | //should not appear, can't proceed with new upgrade, perhaps operator can retry manually later |
| 1697 | return |
| 1698 | case <-dh.upgradeFsmChan: |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1699 | 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] | 1700 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1701 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1702 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1703 | |
| 1704 | //here it can be assumed that no running upgrade processing exists (anymore) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1705 | //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] | 1706 | // but none yet defined |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1707 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1708 | dh.lockUpgradeFsm.Unlock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1709 | if err == nil { |
| 1710 | if err = dh.pOnuUpradeFsm.SetDownloadParamsAfterDownload(ctx, inactiveImageID, |
| 1711 | apImageRequest, apDownloadManager, aImageIdentifier); err != nil { |
| 1712 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1713 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1714 | return |
| 1715 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1716 | } else { |
| 1717 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1718 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1719 | } |
| 1720 | return |
| 1721 | } |
| 1722 | 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] | 1723 | "device-id": dh.DeviceID, "error": err}) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1726 | // onuSwActivateRequest ensures activation of the requested image with commit options |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1727 | func (dh *deviceHandler) onuSwActivateRequest(ctx context.Context, |
| 1728 | aVersion string, aCommitRequest bool) (*voltha.ImageState, error) { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1729 | var err error |
| 1730 | //SW activation for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1731 | // 1.) activation of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1732 | // 2.) activation of the inactive image |
| 1733 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1734 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1735 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1736 | logger.Errorw(ctx, "Onu image activation rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1737 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1738 | } |
| 1739 | dh.lockUpgradeFsm.RLock() |
| 1740 | if dh.pOnuUpradeFsm != nil { |
| 1741 | dh.lockUpgradeFsm.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1742 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1743 | if getErr != nil || onuVolthaDevice == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1744 | logger.Errorw(ctx, "Failed to fetch Onu device for image activation", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1745 | 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] | 1746 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1747 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1748 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1749 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1750 | } |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1751 | // use the OnuVendor identification from this device for the internal unique name |
| 1752 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1753 | // 1.) check a started upgrade process and relay the activation request to it |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1754 | if err = dh.pOnuUpradeFsm.SetActivationParamsRunning(ctx, imageIdentifier, aCommitRequest); err != nil { |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1755 | //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] | 1756 | 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] | 1757 | "device-id": dh.DeviceID, "error": err}) |
| 1758 | 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] | 1759 | } |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1760 | logger.Debugw(ctx, "image activation acknowledged by onu upgrade processing", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1761 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1762 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1763 | return pImageStates, nil |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1764 | } //else |
| 1765 | dh.lockUpgradeFsm.RUnlock() |
| 1766 | |
| 1767 | // 2.) check if requested image-version equals the inactive one and start its activation |
| 1768 | // (image version is not [yet] checked - would be possible, but with increased effort ...) |
| 1769 | var inactiveImageID uint16 |
| 1770 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err != nil || inactiveImageID > 1 { |
| 1771 | logger.Errorw(ctx, "get inactive image failed", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1772 | "device-id": dh.DeviceID, "err": err, "image-id": inactiveImageID}) |
| 1773 | 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] | 1774 | } |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1775 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1776 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1777 | dh.lockUpgradeFsm.Unlock() |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1778 | if err == nil { |
| 1779 | if err = dh.pOnuUpradeFsm.SetActivationParamsStart(ctx, aVersion, |
| 1780 | inactiveImageID, aCommitRequest); err != nil { |
| 1781 | 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] | 1782 | "device-id": dh.DeviceID, "error": err}) |
| 1783 | 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] | 1784 | } |
| 1785 | logger.Debugw(ctx, "inactive image activation acknowledged by onu upgrade", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1786 | "device-id": dh.DeviceID, "image-version": aVersion}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1787 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1788 | return pImageStates, nil |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1789 | } //else |
| 1790 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1791 | "device-id": dh.DeviceID, "error": err}) |
| 1792 | 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] | 1793 | } |
| 1794 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1795 | // onuSwCommitRequest ensures commitment of the requested image |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1796 | func (dh *deviceHandler) onuSwCommitRequest(ctx context.Context, |
| 1797 | aVersion string) (*voltha.ImageState, error) { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1798 | var err error |
| 1799 | //SW commitment for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1800 | // 1.) commitment of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1801 | // 2.) commitment of the active image |
| 1802 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1803 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1804 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1805 | logger.Errorw(ctx, "Onu image commitment rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1806 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1807 | } |
| 1808 | dh.lockUpgradeFsm.RLock() |
| 1809 | if dh.pOnuUpradeFsm != nil { |
| 1810 | dh.lockUpgradeFsm.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1811 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1812 | if getErr != nil || onuVolthaDevice == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1813 | logger.Errorw(ctx, "Failed to fetch Onu device for image commitment", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1814 | 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] | 1815 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1816 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1817 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1818 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1819 | } |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1820 | // use the OnuVendor identification from this device for the internal unique name |
| 1821 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1822 | // 1.) check a started upgrade process and relay the commitment request to it |
| 1823 | // the running upgrade may be based either on the imageIdentifier (started from download) |
| 1824 | // or on the imageVersion (started from pure activation) |
| 1825 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsRunning(ctx, imageIdentifier, aVersion); err != nil { |
| 1826 | //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] | 1827 | 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] | 1828 | "device-id": dh.DeviceID, "error": err}) |
| 1829 | 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] | 1830 | } |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1831 | logger.Debugw(ctx, "image commitment acknowledged by onu upgrade processing", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1832 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1833 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1834 | return pImageStates, nil |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1835 | } //else |
| 1836 | dh.lockUpgradeFsm.RUnlock() |
| 1837 | |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1838 | // 2.) use the active image to directly commit |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1839 | var activeImageID uint16 |
| 1840 | if activeImageID, err = pDevEntry.GetActiveImageMeID(ctx); err != nil || activeImageID > 1 { |
| 1841 | logger.Errorw(ctx, "get active image failed", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1842 | "device-id": dh.DeviceID, "err": err, "image-id": activeImageID}) |
| 1843 | 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] | 1844 | } |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1845 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1846 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1847 | dh.lockUpgradeFsm.Unlock() |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1848 | if err == nil { |
| 1849 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsStart(ctx, aVersion, activeImageID); err != nil { |
| 1850 | 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] | 1851 | "device-id": dh.DeviceID, "error": err}) |
| 1852 | 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] | 1853 | } |
| 1854 | logger.Debugw(ctx, "active image commitment acknowledged by onu upgrade", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1855 | "device-id": dh.DeviceID, "image-version": aVersion}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1856 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1857 | return pImageStates, nil |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1858 | } //else |
| 1859 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1860 | "device-id": dh.DeviceID, "error": err}) |
| 1861 | 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] | 1862 | } |
| 1863 | |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1864 | func (dh *deviceHandler) requestOnuSwUpgradeState(ctx context.Context, aImageIdentifier string, |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1865 | aVersion string) *voltha.ImageState { |
| 1866 | var pImageState *voltha.ImageState |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1867 | dh.lockUpgradeFsm.RLock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1868 | defer dh.lockUpgradeFsm.RUnlock() |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1869 | if dh.pOnuUpradeFsm != nil { |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1870 | pImageState = dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1871 | } else { //use the last stored ImageState (if the requested Imageversion coincides) |
| 1872 | if aVersion == dh.pLastUpgradeImageState.Version { |
| 1873 | pImageState = dh.pLastUpgradeImageState |
| 1874 | } else { //state request for an image version different from last processed image version |
| 1875 | pImageState = &voltha.ImageState{ |
| 1876 | Version: aVersion, |
| 1877 | //we cannot state something concerning this version |
| 1878 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 1879 | Reason: voltha.ImageState_NO_ERROR, |
| 1880 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 1881 | } |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1882 | } |
| 1883 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1884 | return pImageState |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | func (dh *deviceHandler) cancelOnuSwUpgrade(ctx context.Context, aImageIdentifier string, |
| 1888 | aVersion string, pDeviceImageState *voltha.DeviceImageState) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1889 | pDeviceImageState.DeviceId = dh.DeviceID |
| mpagenko | 7455fd4 | 2021-06-10 16:25:55 +0000 | [diff] [blame] | 1890 | pDeviceImageState.ImageState.Version = aVersion |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1891 | dh.lockUpgradeFsm.RLock() |
| 1892 | if dh.pOnuUpradeFsm != nil { |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1893 | dh.lockUpgradeFsm.RUnlock() |
| 1894 | // so then we cancel the upgrade operation |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1895 | // but before we still request the actual upgrade states for the direct response |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1896 | pImageState := dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1897 | pDeviceImageState.ImageState.DownloadState = pImageState.DownloadState |
| 1898 | pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST |
| 1899 | pDeviceImageState.ImageState.ImageState = pImageState.ImageState |
| 1900 | if pImageState.DownloadState != voltha.ImageState_DOWNLOAD_UNKNOWN { |
| 1901 | //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] | 1902 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1903 | dh.upgradeCanceled = true |
| 1904 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1905 | } |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1906 | } //nothing to cancel (upgrade FSM for different image stays alive) |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1907 | } else { |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1908 | dh.lockUpgradeFsm.RUnlock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1909 | // if no upgrade is ongoing, nothing is canceled and accordingly the states of the requested image are unknown |
| 1910 | // reset also the dh handler LastUpgradeImageState (not relevant anymore/cleared) |
| 1911 | (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1912 | (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR |
| 1913 | (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1914 | (*dh.pLastUpgradeImageState).Version = "" //reset to 'no (relevant) upgrade done' (like initial state) |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1915 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1916 | pDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1917 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1918 | //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] | 1919 | } |
| 1920 | } |
| 1921 | |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1922 | func (dh *deviceHandler) getOnuImages(ctx context.Context) (*voltha.OnuImages, error) { |
| 1923 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1924 | var onuImageStatus *swupg.OnuImageStatus |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1925 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1926 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1927 | if pDevEntry != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1928 | onuImageStatus = swupg.NewOnuImageStatus(dh, pDevEntry) |
| 1929 | pDevEntry.MutexOnuImageStatus.Lock() |
| 1930 | pDevEntry.POnuImageStatus = onuImageStatus |
| 1931 | pDevEntry.MutexOnuImageStatus.Unlock() |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1932 | |
| 1933 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1934 | 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] | 1935 | return nil, fmt.Errorf("no-valid-OnuDevice-aborting") |
| 1936 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1937 | images, err := onuImageStatus.GetOnuImageStatus(ctx) |
| 1938 | pDevEntry.MutexOnuImageStatus.Lock() |
| 1939 | pDevEntry.POnuImageStatus = nil |
| 1940 | pDevEntry.MutexOnuImageStatus.Unlock() |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1941 | return images, err |
| 1942 | } |
| 1943 | |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1944 | // deviceHandler methods that implement the adapters interface requests## end ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1945 | // ##################################################################################### |
| 1946 | |
| 1947 | // ################ to be updated acc. needs of ONU Device ######################## |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1948 | // deviceHandler StateMachine related state transition methods ##### begin ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1949 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1950 | func (dh *deviceHandler) logStateChange(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1951 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"event name": string(e.Event), |
| 1952 | "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] | 1953 | } |
| 1954 | |
| 1955 | // doStateInit provides the device update to the core |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1956 | func (dh *deviceHandler) doStateInit(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1957 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1958 | logger.Debugw(ctx, "doStateInit-started", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1959 | var err error |
| 1960 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1961 | // populate what we know. rest comes later after mib sync |
| 1962 | dh.device.Root = false |
| 1963 | dh.device.Vendor = "OpenONU" |
| 1964 | dh.device.Model = "go" |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1965 | dh.device.Reason = cmn.DeviceReasonMap[cmn.DrActivatingOnu] |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 1966 | _ = dh.ReasonUpdate(ctx, cmn.DrActivatingOnu, false) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1967 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1968 | dh.logicalDeviceID = dh.DeviceID // really needed - what for ??? //TODO!!! |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1969 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1970 | if !dh.IsReconciling() { |
| 1971 | 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] | 1972 | if err = dh.updateDeviceInCore(ctx, dh.device); err != nil { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1973 | logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err}) |
| 1974 | } |
| Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 1975 | //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] | 1976 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 1977 | logger.Infow(ctx, "reconciling - don't notify core about DeviceUpdate", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1978 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1979 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1980 | |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1981 | dh.parentID = dh.device.ParentId |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1982 | dh.ponPortNumber = dh.device.ParentPortNo |
| 1983 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1984 | // store proxy parameters for later communication - assumption: invariant, else they have to be requested dynamically!! |
| 1985 | dh.ProxyAddressID = dh.device.ProxyAddress.GetDeviceId() |
| 1986 | dh.ProxyAddressType = dh.device.ProxyAddress.GetDeviceType() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1987 | 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] | 1988 | "proxyAddressType": dh.ProxyAddressType, "SNR": dh.device.SerialNumber, |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1989 | "ParentId": dh.parentID, "ParentPortNo": dh.ponPortNumber}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1990 | |
| 1991 | /* |
| 1992 | self._pon = PonPort.create(self, self._pon_port_number) |
| 1993 | self._pon.add_peer(self.parent_id, self._pon_port_number) |
| 1994 | self.logger.debug('adding-pon-port-to-agent', |
| 1995 | type=self._pon.get_port().type, |
| 1996 | admin_state=self._pon.get_port().admin_state, |
| 1997 | oper_status=self._pon.get_port().oper_status, |
| 1998 | ) |
| 1999 | */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2000 | if !dh.IsReconciling() { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2001 | 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] | 2002 | var ponPortNo uint32 = 1 |
| 2003 | if dh.ponPortNumber != 0 { |
| 2004 | ponPortNo = dh.ponPortNumber |
| 2005 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2006 | |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2007 | pPonPort := &voltha.Port{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2008 | DeviceId: dh.DeviceID, |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2009 | PortNo: ponPortNo, |
| 2010 | Label: fmt.Sprintf("pon-%d", ponPortNo), |
| 2011 | Type: voltha.Port_PON_ONU, |
| 2012 | OperStatus: voltha.OperStatus_ACTIVE, |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2013 | Peers: []*voltha.Port_PeerPort{{DeviceId: dh.parentID, // Peer device is OLT |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2014 | PortNo: ponPortNo}}, // Peer port is parent's port number |
| 2015 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2016 | if err = dh.CreatePortInCore(ctx, pPonPort); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2017 | logger.Fatalf(ctx, "Device FSM: PortCreated-failed-%s:%s", err, dh.DeviceID) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2018 | e.Cancel(err) |
| 2019 | return |
| 2020 | } |
| 2021 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2022 | logger.Infow(ctx, "reconciling - pon-port already added", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2023 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2024 | logger.Debugw(ctx, "doStateInit-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | // postInit setups the DeviceEntry for the conerned device |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2028 | func (dh *deviceHandler) postInit(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2029 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2030 | logger.Debugw(ctx, "postInit-started", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2031 | var err error |
| 2032 | /* |
| 2033 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
| 2034 | dh.pTransitionMap.Handle(ctx, GrpcConnected) |
| 2035 | return nil |
| 2036 | */ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2037 | if err = dh.addOnuDeviceEntry(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2038 | logger.Fatalf(ctx, "Device FSM: addOnuDeviceEntry-failed-%s:%s", err, dh.DeviceID) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2039 | e.Cancel(err) |
| 2040 | return |
| 2041 | } |
| 2042 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2043 | if dh.IsReconciling() { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2044 | go dh.reconcileDeviceOnuInd(ctx) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2045 | // reconcilement will be continued after mib download is done |
| 2046 | } |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 2047 | |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2048 | /* |
| 2049 | ############################################################################ |
| 2050 | # Setup Alarm handler |
| 2051 | self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id, |
| 2052 | device.serial_number) |
| 2053 | ############################################################################ |
| 2054 | # Setup PM configuration for this device |
| 2055 | # Pass in ONU specific options |
| 2056 | kwargs = { |
| 2057 | OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY, |
| 2058 | 'heartbeat': self.heartbeat, |
| 2059 | OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device |
| 2060 | } |
| 2061 | self.logger.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number) |
| 2062 | self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id, |
| 2063 | self.logical_device_id, device.serial_number, |
| 2064 | grouped=True, freq_override=False, **kwargs) |
| 2065 | pm_config = self._pm_metrics.make_proto() |
| 2066 | self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm) |
| 2067 | self.logger.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number) |
| 2068 | yield self.core_proxy.device_pm_config_update(pm_config, init=True) |
| 2069 | |
| 2070 | # Note, ONU ID and UNI intf set in add_uni_port method |
| 2071 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events, |
| 2072 | ani_ports=[self._pon]) |
| 2073 | |
| 2074 | # Code to Run OMCI Test Action |
| 2075 | kwargs_omci_test_action = { |
| 2076 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 2077 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 2078 | } |
| 2079 | serial_number = device.serial_number |
| 2080 | self._test_request = OmciTestRequest(self.core_proxy, |
| 2081 | self.omci_agent, self.device_id, |
| 2082 | AniG, serial_number, |
| 2083 | self.logical_device_id, |
| 2084 | exclusive=False, |
| 2085 | **kwargs_omci_test_action) |
| 2086 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2087 | self.Enabled = True |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2088 | else: |
| 2089 | self.logger.info('onu-already-activated') |
| 2090 | */ |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 2091 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2092 | logger.Debugw(ctx, "postInit-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | // doStateConnected get the device info and update to voltha core |
| 2096 | // 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] | 2097 | // |
| 2098 | // voltha-openolt-adapter/adaptercore/device_handler.go |
| 2099 | // -> this one obviously initiates all communication interfaces of the device ...? |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2100 | func (dh *deviceHandler) doStateConnected(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2101 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2102 | logger.Debugw(ctx, "doStateConnected-started", log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2103 | err := errors.New("device FSM: function not implemented yet") |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2104 | e.Cancel(err) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2105 | logger.Debugw(ctx, "doStateConnected-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | // doStateUp handle the onu up indication and update to voltha core |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2109 | func (dh *deviceHandler) doStateUp(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2110 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2111 | logger.Debugw(ctx, "doStateUp-started", log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2112 | err := errors.New("device FSM: function not implemented yet") |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2113 | e.Cancel(err) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2114 | logger.Debugw(ctx, "doStateUp-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2115 | |
| 2116 | /* |
| 2117 | // Synchronous call to update device state - this method is run in its own go routine |
| 2118 | if err := dh.coreProxy.DeviceStateUpdate(ctx, dh.device.Id, voltha.ConnectStatus_REACHABLE, |
| 2119 | voltha.OperStatus_ACTIVE); err != nil { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2120 | 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] | 2121 | return err |
| 2122 | } |
| 2123 | return nil |
| 2124 | */ |
| 2125 | } |
| 2126 | |
| 2127 | // doStateDown handle the onu down indication |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2128 | func (dh *deviceHandler) doStateDown(ctx context.Context, e *fsm.Event) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2129 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2130 | logger.Debugw(ctx, "doStateDown-started", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2131 | var err error |
| 2132 | |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2133 | device := dh.device |
| 2134 | if device == nil { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2135 | /*TODO: needs to handle error scenarios */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2136 | 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] | 2137 | e.Cancel(err) |
| 2138 | return |
| 2139 | } |
| 2140 | |
| 2141 | cloned := proto.Clone(device).(*voltha.Device) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2142 | logger.Debugw(ctx, "do-state-down", log.Fields{"ClonedDeviceID": cloned.Id}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2143 | /* |
| 2144 | // Update the all ports state on that device to disable |
| 2145 | if er := dh.coreProxy.PortsStateUpdate(ctx, cloned.Id, voltha.OperStatus_UNKNOWN); er != nil { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2146 | 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] | 2147 | return er |
| 2148 | } |
| 2149 | |
| 2150 | //Update the device oper state and connection status |
| 2151 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 2152 | cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE |
| 2153 | dh.device = cloned |
| 2154 | |
| 2155 | 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] | 2156 | 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] | 2157 | return er |
| 2158 | } |
| 2159 | |
| 2160 | //get the child device for the parent device |
| 2161 | onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id) |
| 2162 | if err != nil { |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2163 | 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] | 2164 | return err |
| 2165 | } |
| 2166 | for _, onuDevice := range onuDevices.Items { |
| 2167 | |
| 2168 | // Update onu state as down in onu adapter |
| 2169 | onuInd := oop.OnuIndication{} |
| 2170 | onuInd.OperState = "down" |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2171 | er := dh.adapterProxy.SendInterAdapterMessage(ctx, &onuInd, ca.InterAdapterMessageType_ONU_IND_REQUEST, |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2172 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 2173 | if er != nil { |
| 2174 | logger.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2175 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "device-id": onuDevice.Id}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2176 | //Do not return here and continue to process other ONUs |
| 2177 | } |
| 2178 | } |
| 2179 | // * Discovered ONUs entries need to be cleared , since after OLT |
| 2180 | // is up, it starts sending discovery indications again* / |
| 2181 | dh.discOnus = sync.Map{} |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2182 | logger.Debugw("do-state-down-end", log.Fields{"device-id": device.Id}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2183 | return nil |
| 2184 | */ |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2185 | err = errors.New("device FSM: function not implemented yet") |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2186 | e.Cancel(err) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2187 | logger.Debugw(ctx, "doStateDown-done", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2190 | // deviceHandler StateMachine related state transition methods ##### end ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2191 | // ################################################################################# |
| 2192 | |
| 2193 | // ################################################### |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2194 | // deviceHandler utility methods ##### begin ######### |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2195 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 2196 | // 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] | 2197 | func (dh *deviceHandler) GetOnuDeviceEntry(ctx context.Context, aWait bool) *mib.OnuDeviceEntry { |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2198 | dh.lockDevice.RLock() |
| 2199 | pOnuDeviceEntry := dh.pOnuOmciDevice |
| 2200 | if aWait && pOnuDeviceEntry == nil { |
| 2201 | //keep the read sema short to allow for subsequent write |
| 2202 | dh.lockDevice.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2203 | 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] | 2204 | // based on concurrent processing the deviceEntry setup may not yet be finished at his point |
| 2205 | // so it might be needed to wait here for that event with some timeout |
| 2206 | select { |
| 2207 | case <-time.After(60 * time.Second): //timer may be discussed ... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2208 | 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] | 2209 | return nil |
| 2210 | case <-dh.deviceEntrySet: |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2211 | logger.Debugw(ctx, "devicEntry ready now - continue", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2212 | // if written now, we can return the written value without sema |
| 2213 | return dh.pOnuOmciDevice |
| 2214 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2215 | } |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2216 | dh.lockDevice.RUnlock() |
| 2217 | return pOnuDeviceEntry |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2218 | } |
| 2219 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 2220 | // setDeviceHandlerEntries sets the ONU device entry within the handler |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2221 | func (dh *deviceHandler) setDeviceHandlerEntries(apDeviceEntry *mib.OnuDeviceEntry, apOnuTp *avcfg.OnuUniTechProf, |
| 2222 | apOnuMetricsMgr *pmmgr.OnuMetricsManager, apOnuAlarmMgr *almgr.OnuAlarmManager, apSelfTestHdlr *otst.SelfTestControlBlock) { |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2223 | dh.lockDevice.Lock() |
| 2224 | defer dh.lockDevice.Unlock() |
| mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 2225 | dh.pOnuOmciDevice = apDeviceEntry |
| 2226 | dh.pOnuTP = apOnuTp |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 2227 | dh.pOnuMetricsMgr = apOnuMetricsMgr |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 2228 | dh.pAlarmMgr = apOnuAlarmMgr |
| Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 2229 | dh.pSelfTestHdlr = apSelfTestHdlr |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 2232 | // addOnuDeviceEntry creates a new ONU device or returns the existing |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2233 | // |
| 2234 | //nolint:unparam |
| Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 2235 | func (dh *deviceHandler) addOnuDeviceEntry(ctx context.Context) error { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2236 | logger.Debugw(ctx, "adding-deviceEntry", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2237 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2238 | deviceEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2239 | if deviceEntry == nil { |
| 2240 | /* costum_me_map in python code seems always to be None, |
| 2241 | we omit that here first (declaration unclear) -> todo at Adapter specialization ...*/ |
| 2242 | /* also no 'clock' argument - usage open ...*/ |
| 2243 | /* and no alarm_db yet (oo.alarm_db) */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2244 | deviceEntry = mib.NewOnuDeviceEntry(ctx, dh.coreClient, dh, dh.pOpenOnuAc) |
| 2245 | onuTechProfProc := avcfg.NewOnuUniTechProf(ctx, dh, deviceEntry) |
| 2246 | onuMetricsMgr := pmmgr.NewOnuMetricsManager(ctx, dh, deviceEntry) |
| 2247 | onuAlarmManager := almgr.NewAlarmManager(ctx, dh, deviceEntry) |
| 2248 | selfTestHdlr := otst.NewSelfTestMsgHandlerCb(ctx, dh, deviceEntry) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2249 | //error treatment possible //TODO!!! |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2250 | dh.setDeviceHandlerEntries(deviceEntry, onuTechProfProc, onuMetricsMgr, onuAlarmManager, selfTestHdlr) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2251 | // fire deviceEntry ready event to spread to possibly waiting processing |
| 2252 | dh.deviceEntrySet <- true |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2253 | logger.Debugw(ctx, "onuDeviceEntry-added", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2254 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2255 | 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] | 2256 | } |
| 2257 | // might be updated with some error handling !!! |
| 2258 | return nil |
| 2259 | } |
| 2260 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2261 | func (dh *deviceHandler) createInterface(ctx context.Context, onuind *oop.OnuIndication) error { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2262 | 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] | 2263 | "OnuIntfId": onuind.GetIntfId(), "OnuSerialNumber": onuind.GetSerialNumber()}) |
| 2264 | |
| 2265 | dh.pOnuIndication = onuind // let's revise if storing the pointer is sufficient... |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2266 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2267 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2268 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2269 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 2270 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2271 | } |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 2272 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2273 | if !dh.IsReconciling() { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2274 | 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] | 2275 | "OperStatus": voltha.OperStatus_ACTIVATING, "device-id": dh.DeviceID}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2276 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2277 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2278 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2279 | OperStatus: voltha.OperStatus_ACTIVATING, |
| 2280 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2281 | }); err != nil { |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2282 | //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] | 2283 | 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] | 2284 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| 2285 | } |
| 2286 | // On onu reboot, we have to perform mib-reset and persist the reboot state for reconciling scenario |
| 2287 | if dh.GetDeviceTechProfOnReboot() { |
| 2288 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2289 | pDevEntry.SOnuPersistentData.PersMibLastDbSync = 0 |
| 2290 | pDevEntry.SOnuPersistentData.PersRebootInProgress = true |
| 2291 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2292 | } |
| 2293 | // Moving the previous call to write to KV store here, to store the ONU pers data after the update. |
| 2294 | if err := dh.StorePersistentData(ctx); err != nil { |
| 2295 | logger.Warnw(ctx, "store persistent data error - continue as there will be additional write attempts", |
| 2296 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2297 | } |
| 2298 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2299 | logger.Info(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVATING", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2300 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2301 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2302 | pDevEntry.MutexPersOnuConfig.RLock() |
| 2303 | if !pDevEntry.SOnuPersistentData.PersUniUnlockDone { |
| 2304 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2305 | 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] | 2306 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 2307 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 2308 | |
| 2309 | //VOL-4965: Recover previously Activating ONU during reconciliation. |
| 2310 | if dh.device.OperStatus == common.OperStatus_ACTIVATING { |
| 2311 | logger.Debugw(ctx, "Reconciling an ONU in previously activating state, perform MIB reset and resume normal start up", |
| 2312 | log.Fields{"device-id": dh.DeviceID}) |
| 2313 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2314 | pDevEntry.SOnuPersistentData.PersMibLastDbSync = 0 |
| 2315 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2316 | } |
| Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2317 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2318 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2319 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2320 | } |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2321 | // It does not look to me as if makes sense to work with the real core device here, (not the stored clone)? |
| 2322 | // in this code the GetDevice would just make a check if the DeviceID's Device still exists in core |
| 2323 | // 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] | 2324 | // 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] | 2325 | // so let's just try to keep it simple ... |
| 2326 | /* |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2327 | 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] | 2328 | if err != nil || device == nil { |
| 2329 | //TODO: needs to handle error scenarios |
| 2330 | logger.Errorw("Failed to fetch device device at creating If", log.Fields{"err": err}) |
| 2331 | return errors.New("Voltha Device not found") |
| 2332 | } |
| 2333 | */ |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2334 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2335 | if err := pDevEntry.Start(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2336 | return err |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2337 | } |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2338 | _ = dh.ReasonUpdate(ctx, cmn.DrStartingOpenomci, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 2339 | if !dh.IsReconciling() && !dh.GetSkipOnuConfigEnabled() { |
| 2340 | /* this might be a good time for Omci Verify message? */ |
| 2341 | verifyExec := make(chan bool) |
| 2342 | omciVerify := otst.NewOmciTestRequest(log.WithSpanFromContext(context.TODO(), ctx), |
| 2343 | dh.device.Id, pDevEntry.PDevOmciCC, false, |
| 2344 | true, true) //exclusive and allowFailure (anyway not yet checked) |
| 2345 | omciVerify.PerformOmciTest(log.WithSpanFromContext(context.TODO(), ctx), verifyExec) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2346 | |
| Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 2347 | /* give the handler some time here to wait for the OMCi verification result |
| 2348 | after Timeout start and try MibUpload FSM anyway |
| 2349 | (to prevent stopping on just not supported OMCI verification from ONU) */ |
| 2350 | select { |
| 2351 | case <-time.After(((cmn.CDefaultRetries+1)*otst.CTestRequestOmciTimeout + 1) * time.Second): |
| 2352 | logger.Warnw(ctx, "omci start-verification timed out (continue normal)", log.Fields{"device-id": dh.DeviceID}) |
| 2353 | case testresult := <-verifyExec: |
| 2354 | logger.Infow(ctx, "Omci start verification done", log.Fields{"device-id": dh.DeviceID, "result": testresult}) |
| 2355 | case <-dh.deviceDeleteCommChan: |
| 2356 | logger.Warnw(ctx, "Deleting device, stopping the omci test activity", log.Fields{"device-id": dh.DeviceID}) |
| 2357 | return nil |
| 2358 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | /* In py code it looks earlier (on activate ..) |
| 2362 | # Code to Run OMCI Test Action |
| 2363 | kwargs_omci_test_action = { |
| 2364 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 2365 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 2366 | } |
| 2367 | serial_number = device.serial_number |
| 2368 | self._test_request = OmciTestRequest(self.core_proxy, |
| 2369 | self.omci_agent, self.device_id, |
| 2370 | AniG, serial_number, |
| 2371 | self.logical_device_id, |
| 2372 | exclusive=False, |
| 2373 | **kwargs_omci_test_action) |
| 2374 | ... |
| 2375 | # Start test requests after a brief pause |
| 2376 | if not self._test_request_started: |
| 2377 | self._test_request_started = True |
| 2378 | tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 2379 | reactor.callLater(tststart, self._test_request.start_collector) |
| 2380 | |
| 2381 | */ |
| 2382 | /* which is then: in omci_test_request.py : */ |
| 2383 | /* |
| 2384 | def start_collector(self, callback=None): |
| 2385 | """ |
| 2386 | Start the collection loop for an adapter if the frequency > 0 |
| 2387 | |
| 2388 | :param callback: (callable) Function to call to collect PM data |
| 2389 | """ |
| 2390 | self.logger.info("starting-pm-collection", device_name=self.name, default_freq=self.default_freq) |
| 2391 | if callback is None: |
| 2392 | callback = self.perform_test_omci |
| 2393 | |
| 2394 | if self.lc is None: |
| 2395 | self.lc = LoopingCall(callback) |
| 2396 | |
| 2397 | if self.default_freq > 0: |
| 2398 | self.lc.start(interval=self.default_freq / 10) |
| 2399 | |
| 2400 | def perform_test_omci(self): |
| 2401 | """ |
| 2402 | Perform the initial test request |
| 2403 | """ |
| 2404 | ani_g_entities = self._device.configuration.ani_g_entities |
| 2405 | ani_g_entities_ids = list(ani_g_entities.keys()) if ani_g_entities \ |
| 2406 | is not None else None |
| 2407 | self._entity_id = ani_g_entities_ids[0] |
| 2408 | self.logger.info('perform-test', entity_class=self._entity_class, |
| 2409 | entity_id=self._entity_id) |
| 2410 | try: |
| 2411 | frame = MEFrame(self._entity_class, self._entity_id, []).test() |
| 2412 | result = yield self._device.omci_cc.send(frame) |
| 2413 | if not result.fields['omci_message'].fields['success_code']: |
| 2414 | self.logger.info('Self-Test Submitted Successfully', |
| 2415 | code=result.fields[ |
| 2416 | 'omci_message'].fields['success_code']) |
| 2417 | else: |
| 2418 | raise TestFailure('Test Failure: {}'.format( |
| 2419 | result.fields['omci_message'].fields['success_code'])) |
| 2420 | except TimeoutError as e: |
| 2421 | self.deferred.errback(failure.Failure(e)) |
| 2422 | |
| 2423 | except Exception as e: |
| 2424 | self.logger.exception('perform-test-Error', e=e, |
| 2425 | class_id=self._entity_class, |
| 2426 | entity_id=self._entity_id) |
| 2427 | self.deferred.errback(failure.Failure(e)) |
| 2428 | |
| 2429 | */ |
| 2430 | |
| 2431 | // PM related heartbeat??? !!!TODO.... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2432 | //self._heartbeat.Enabled = True |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2433 | |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 2434 | /* Note: Even though FSM calls look 'synchronous' here, FSM is running in background with the effect that possible errors |
| 2435 | * within the MibUpload are not notified in the OnuIndication response, this might be acceptable here, |
| 2436 | * 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] | 2437 | * otherwise some processing synchronization would be required - cmp. e.g TechProfile processing |
| mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 2438 | */ |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 2439 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2440 | //call MibUploadFSM - transition up to state UlStInSync |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 2441 | // Breaking this part of code due to sca complexity |
| 2442 | err := dh.CheckAndStartMibUploadFsm(ctx, pDevEntry) |
| 2443 | return err |
| 2444 | } |
| 2445 | |
| 2446 | func (dh *deviceHandler) CheckAndStartMibUploadFsm(ctx context.Context, pDevEntry *mib.OnuDeviceEntry) error { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2447 | pMibUlFsm := pDevEntry.PMibUploadFsm.PFsm |
| Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 2448 | if pMibUlFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2449 | if pMibUlFsm.Is(mib.UlStDisabled) { |
| 2450 | if err := pMibUlFsm.Event(mib.UlEvStart); err != nil { |
| 2451 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2452 | return fmt.Errorf("can't go to state starting: %s", dh.DeviceID) |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2453 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2454 | 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] | 2455 | //Determine ONU status and start/re-start MIB Synchronization tasks |
| 2456 | //Determine if this ONU has ever synchronized |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2457 | if pDevEntry.IsNewOnu() { |
| 2458 | if err := pMibUlFsm.Event(mib.UlEvResetMib); err != nil { |
| 2459 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state resetting_mib", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2460 | 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] | 2461 | } |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2462 | } else { |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2463 | if err := pMibUlFsm.Event(mib.UlEvVerifyAndStoreTPs); err != nil { |
| 2464 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state verify and store TPs", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2465 | 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] | 2466 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2467 | 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] | 2468 | } |
| Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 2469 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2470 | 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] | 2471 | "device-id": dh.DeviceID}) |
| 2472 | return fmt.Errorf("wrong state of MibSyncFsm: %s", dh.DeviceID) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2473 | } |
| 2474 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2475 | logger.Errorw(ctx, "MibSyncFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID}) |
| 2476 | return fmt.Errorf("can't execute MibSync: %s", dh.DeviceID) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2477 | } |
| 2478 | return nil |
| 2479 | } |
| 2480 | |
| Holger Hildebrandt | 68854a8 | 2022-09-05 07:00:21 +0000 | [diff] [blame] | 2481 | func (dh *deviceHandler) UpdateInterface(ctx context.Context) error { |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2482 | //state checking to prevent unneeded processing (eg. on ONU 'unreachable' and 'down') |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2483 | // (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] | 2484 | if dh.getDeviceReason() != cmn.DrStoppingOpenomci { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2485 | logger.Info(ctx, "updateInterface-started - stopping-device", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 2486 | |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2487 | //stop all running FSM processing - make use of the DH-state as mirrored in the deviceReason |
| 2488 | //here no conflict with aborted FSM's should arise as a complete OMCI initialization is assumed on ONU-Up |
| 2489 | //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] | 2490 | if err := dh.resetFsms(ctx, true); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2491 | logger.Errorw(ctx, "error-updateInterface at FSM stop", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2492 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2493 | // abort: system behavior is just unstable ... |
| 2494 | return err |
| 2495 | } |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2496 | //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] | 2497 | if !dh.GetDeviceTechProfOnReboot() { |
| 2498 | _ = dh.deleteDevicePersistencyData(ctx) //ignore possible errors here and continue, hope is that data is synchronized with new ONU-Up |
| 2499 | } |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2500 | |
| 2501 | //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] | 2502 | //stop the device entry to allow for all system event transfers again |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2503 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2504 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2505 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 2506 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2507 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2508 | _ = pDevEntry.Stop(log.WithSpanFromContext(context.TODO(), ctx), false) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2509 | |
| 2510 | //TODO!!! remove existing traffic profiles |
| 2511 | /* from py code, if TP's exist, remove them - not yet implemented |
| 2512 | self._tp = dict() |
| 2513 | # Let TP download happen again |
| 2514 | for uni_id in self._tp_service_specific_task: |
| 2515 | self._tp_service_specific_task[uni_id].clear() |
| 2516 | for uni_id in self._tech_profile_download_done: |
| 2517 | self._tech_profile_download_done[uni_id].clear() |
| 2518 | */ |
| 2519 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2520 | dh.DisableUniPortStateUpdate(ctx) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2521 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2522 | dh.SetReadyForOmciConfig(false) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2523 | |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2524 | if err := dh.ReasonUpdate(ctx, cmn.DrStoppingOpenomci, true); err != nil { |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2525 | // abort: system behavior is just unstable ... |
| 2526 | return err |
| 2527 | } |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2528 | 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] | 2529 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID}) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2530 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2531 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2532 | ConnStatus: voltha.ConnectStatus_UNREACHABLE, |
| 2533 | OperStatus: voltha.OperStatus_DISCOVERED, |
| 2534 | }); err != nil { |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2535 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2536 | logger.Errorw(ctx, "error-updating-device-state unreachable-discovered", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2537 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2538 | // abort: system behavior is just unstable ... |
| 2539 | return err |
| 2540 | } |
| 2541 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2542 | logger.Debugw(ctx, "updateInterface - device already stopped", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2543 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2544 | return nil |
| 2545 | } |
| 2546 | |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2547 | func (dh *deviceHandler) resetFsms(ctx context.Context, includingMibSyncFsm bool) error { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2548 | //all possible FSM's are stopped or reset here to ensure their transition to 'disabled' |
| 2549 | //it is not sufficient to stop/reset the latest running FSM as done in previous versions |
| 2550 | // as after down/up procedures all FSM's might be active/ongoing (in theory) |
| 2551 | // and using the stop/reset event should never harm |
| Holger Hildebrandt | 12609a1 | 2022-03-25 13:23:25 +0000 | [diff] [blame] | 2552 | logger.Debugw(ctx, "resetFsms entered", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2553 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2554 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Praneeth Kumar Nalmas | fcdd20b | 2024-01-24 22:26:39 +0530 | [diff] [blame] | 2555 | //VOL-5260: During race conditions when adoptDevice has not yet completed |
| 2556 | // and deleteDevice is issued , returning error will further prevent clean up |
| 2557 | // 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] | 2558 | if pDevEntry == nil { |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 2559 | errMsg := fmt.Sprintf("Device entry is not found %s", dh.DeviceID) |
| 2560 | logger.Error(ctx, errMsg) |
| 2561 | return status.Error(codes.NotFound, errMsg) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2562 | } |
| Holger Hildebrandt | c8ece36 | 2021-05-17 12:01:10 +0000 | [diff] [blame] | 2563 | if pDevEntry.PDevOmciCC != nil { |
| mpagenko | 8cd1bf7 | 2021-06-22 10:11:19 +0000 | [diff] [blame] | 2564 | pDevEntry.PDevOmciCC.CancelRequestMonitoring(ctx) |
| Holger Hildebrandt | c8ece36 | 2021-05-17 12:01:10 +0000 | [diff] [blame] | 2565 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2566 | pDevEntry.MutexOnuImageStatus.RLock() |
| 2567 | if pDevEntry.POnuImageStatus != nil { |
| 2568 | pDevEntry.POnuImageStatus.CancelProcessing(ctx) |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 2569 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2570 | pDevEntry.MutexOnuImageStatus.RUnlock() |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 2571 | |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2572 | if includingMibSyncFsm { |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 2573 | pDevEntry.CancelProcessing(ctx) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2574 | } |
| 2575 | //MibDownload may run |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2576 | pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2577 | if pMibDlFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2578 | _ = pMibDlFsm.Event(mib.DlEvReset) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2579 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 2580 | //stop any deviceHandler reconcile processing (if running) |
| 2581 | dh.stopReconciling(ctx, false, cWaitReconcileFlowAbortOnError) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2582 | //port lock/unlock FSM's may be active |
| 2583 | if dh.pUnlockStateFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2584 | _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2585 | } |
| 2586 | if dh.pLockStateFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2587 | _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2588 | } |
| 2589 | //techProfile related PonAniConfigFsm FSM may be active |
| 2590 | if dh.pOnuTP != nil { |
| 2591 | // should always be the case here |
| 2592 | // 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] | 2593 | if dh.pOnuTP.PAniConfigFsm != nil { |
| 2594 | for uniTP := range dh.pOnuTP.PAniConfigFsm { |
| 2595 | dh.pOnuTP.PAniConfigFsm[uniTP].CancelProcessing(ctx) |
| Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 2596 | } |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2597 | } |
| 2598 | for _, uniPort := range dh.uniEntityMap { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2599 | // reset the possibly existing VlanConfigFsm |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2600 | dh.lockVlanConfig.RLock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2601 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniPort.UniID]; exist { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2602 | //VlanFilterFsm exists and was already started |
| mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2603 | dh.lockVlanConfig.RUnlock() |
| mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2604 | //ensure the FSM processing is stopped in case waiting for some response |
| mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 2605 | pVlanFilterFsm.CancelProcessing(ctx) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2606 | } else { |
| 2607 | dh.lockVlanConfig.RUnlock() |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2608 | } |
| 2609 | } |
| 2610 | } |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2611 | |
| 2612 | dh.mutexCollectorFlag.Lock() |
| 2613 | logger.Debugw(ctx, "check-collector-is-running", log.Fields{"device-id": dh.device.Id, "flag": dh.collectorIsRunning}) |
| 2614 | if dh.collectorIsRunning { |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2615 | // Stop collector routine |
| 2616 | dh.stopCollector <- true |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2617 | dh.collectorIsRunning = false |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2618 | } |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2619 | dh.mutexCollectorFlag.Unlock() |
| 2620 | |
| 2621 | dh.mutextAlarmManagerFlag.Lock() |
| 2622 | logger.Debugw(ctx, "check-alarm-manager-is-running", log.Fields{"device-id": dh.device.Id, "flag": dh.alarmManagerIsRunning}) |
| 2623 | if dh.alarmManagerIsRunning { |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2624 | dh.stopAlarmManager <- true |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2625 | dh.alarmManagerIsRunning = false |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2626 | } |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2627 | dh.mutextAlarmManagerFlag.Unlock() |
| 2628 | |
| 2629 | dh.pSelfTestHdlr.SelfTestHandlerLock.Lock() |
| 2630 | logger.Debugw(ctx, "check-self-test-control-block-is-running", log.Fields{"device-id": dh.device.Id, "flag": dh.pSelfTestHdlr.SelfTestHandlerActive}) |
| 2631 | if dh.pSelfTestHdlr.SelfTestHandlerActive { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2632 | dh.pSelfTestHdlr.StopSelfTestModule <- true |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2633 | dh.pSelfTestHdlr.SelfTestHandlerActive = false |
| Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 2634 | } |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 2635 | dh.pSelfTestHdlr.SelfTestHandlerLock.Unlock() |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2636 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2637 | // Note: We want flow deletes to be processed on onu down, so do not stop flow monitoring routines |
| 2638 | |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2639 | //reset a possibly running upgrade FSM |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2640 | // (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] | 2641 | dh.lockUpgradeFsm.RLock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2642 | lopOnuUpradeFsm := dh.pOnuUpradeFsm |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2643 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2644 | dh.lockUpgradeFsm.RUnlock() |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2645 | if lopOnuUpradeFsm != nil { |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2646 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 2647 | //here we do not expect intermediate cancelation, we still allow for other commands on this FSM |
| 2648 | // (even though it may also run into direct cancellation, a bit hard to verify here) |
| 2649 | // so don't set 'dh.upgradeCanceled = true' here! |
| 2650 | lopOnuUpradeFsm.CancelProcessing(ctx, false, voltha.ImageState_CANCELLED_ON_ONU_STATE) //conditional cancel |
| 2651 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2652 | } |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2653 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2654 | logger.Infow(ctx, "resetFsms done", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2655 | return nil |
| 2656 | } |
| 2657 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2658 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2659 | func (dh *deviceHandler) processMibDatabaseSyncEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2660 | 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] | 2661 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2662 | // store persistent data collected during MIB upload processing |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2663 | if err := dh.StorePersistentData(ctx); err != nil { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2664 | 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] | 2665 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2666 | } |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2667 | _ = dh.ReasonUpdate(ctx, cmn.DrDiscoveryMibsyncComplete, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2668 | dh.AddAllUniPorts(ctx) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2669 | |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2670 | /* 200605: lock processing after initial MIBUpload removed now as the ONU should be in the lock state per default here */ |
| 2671 | /* 201117: build_dt-berlin-pod-openonugo_1T8GEM_voltha_DT_openonugo_master_test runs into error TC |
| 2672 | * 'Test Disable ONUs and OLT Then Delete ONUs and OLT for DT' with Sercom ONU, which obviously needs |
| 2673 | * disable/enable toggling here to allow traffic |
| 2674 | * but moreover it might be useful for tracking the interface operState changes if this will be implemented, |
| 2675 | * like the py comment says: |
| 2676 | * # start by locking all the unis till mib sync and initial mib is downloaded |
| 2677 | * # this way we can capture the port down/up events when we are ready |
| 2678 | */ |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2679 | |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2680 | // Init Uni Ports to Admin locked state |
| 2681 | // *** should generate UniLockStateDone event ***** |
| 2682 | if dh.pLockStateFsm == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2683 | dh.createUniLockFsm(ctx, true, cmn.UniLockStateDone) |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2684 | } else { //LockStateFSM already init |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2685 | dh.pLockStateFsm.SetSuccessEvent(cmn.UniLockStateDone) |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2686 | dh.runUniLockFsm(ctx, true) |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2687 | } |
| 2688 | } |
| 2689 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2690 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2691 | func (dh *deviceHandler) processUniLockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2692 | 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] | 2693 | /* Mib download procedure - |
| 2694 | ***** should run over 'downloaded' state and generate MibDownloadDone event ***** |
| 2695 | */ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2696 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2697 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2698 | 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] | 2699 | return |
| 2700 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2701 | pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2702 | if pMibDlFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2703 | if pMibDlFsm.Is(mib.DlStDisabled) { |
| 2704 | if err := pMibDlFsm.Event(mib.DlEvStart); err != nil { |
| 2705 | 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] | 2706 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2707 | } else { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2708 | 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] | 2709 | // maybe use more specific states here for the specific download steps ... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2710 | if err := pMibDlFsm.Event(mib.DlEvCreateGal); err != nil { |
| 2711 | 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] | 2712 | } else { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2713 | 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] | 2714 | //Begin MIB data download (running autonomously) |
| 2715 | } |
| 2716 | } |
| 2717 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2718 | 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] | 2719 | "device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2720 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2721 | } |
| 2722 | /***** Mib download started */ |
| 2723 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2724 | 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] | 2725 | } |
| 2726 | } |
| 2727 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2728 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2729 | func (dh *deviceHandler) processMibDownloadDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2730 | 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] | 2731 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 2732 | if pDevEntry == nil { |
| 2733 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 2734 | return |
| 2735 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2736 | if !dh.IsReconciling() { |
| Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 2737 | 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] | 2738 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 2739 | // update device info in core |
| 2740 | pDevEntry.MutexPersOnuConfig.RLock() |
| 2741 | dh.device.Vendor = pDevEntry.SOnuPersistentData.PersVendorID |
| 2742 | dh.device.VendorId = pDevEntry.SOnuPersistentData.PersVendorID |
| 2743 | dh.device.Model = pDevEntry.SOnuPersistentData.PersVersion |
| 2744 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 2745 | dh.logicalDeviceID = dh.DeviceID |
| 2746 | if err := dh.updateDeviceInCore(ctx, dh.device); err != nil { |
| 2747 | logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err}) |
| 2748 | } |
| 2749 | // update device state in core |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2750 | //we allow a possible OnuSw image commit only in the normal startup, not at reconciling |
| 2751 | // in case of adapter restart connected to an ONU upgrade I would not rely on the image quality |
| 2752 | // maybe some 'forced' commitment can be done in this situation from system management (or upgrade restarted) |
| 2753 | dh.checkOnOnuImageCommit(ctx) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2754 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2755 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2756 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2757 | OperStatus: voltha.OperStatus_ACTIVE, |
| 2758 | }); err != nil { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2759 | //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] | 2760 | 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] | 2761 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2762 | 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] | 2763 | } |
| 2764 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2765 | 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] | 2766 | log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2767 | } |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2768 | _ = dh.ReasonUpdate(ctx, cmn.DrInitialMibDownloaded, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2769 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2770 | if !dh.GetCollectorIsRunning() { |
| Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 2771 | var waitForOmciProcessor sync.WaitGroup |
| 2772 | waitForOmciProcessor.Add(1) |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2773 | // Start PM collector routine |
| Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 2774 | go dh.StartCollector(ctx, &waitForOmciProcessor) |
| 2775 | waitForOmciProcessor.Wait() |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2776 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2777 | if !dh.GetAlarmManagerIsRunning(ctx) { |
| 2778 | go dh.StartAlarmManager(ctx) |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2779 | } |
| 2780 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2781 | // Start flow handler routines per UNI |
| 2782 | for _, uniPort := range dh.uniEntityMap { |
| 2783 | // only if this port was enabled for use by the operator at startup |
| 2784 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 2785 | if !dh.GetFlowMonitoringIsRunning(uniPort.UniID) { |
| 2786 | go dh.PerOnuFlowHandlerRoutine(uniPort.UniID) |
| 2787 | } |
| 2788 | } |
| 2789 | } |
| 2790 | |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2791 | // Initialize classical L2 PM Interval Counters |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2792 | if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventInit); err != nil { |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2793 | // There is no way we should be landing here, but if we do then |
| 2794 | // there is nothing much we can do about this other than log error |
| 2795 | logger.Errorw(ctx, "error starting l2 pm fsm", log.Fields{"device-id": dh.device.Id, "err": err}) |
| 2796 | } |
| 2797 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2798 | dh.SetReadyForOmciConfig(true) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2799 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2800 | pDevEntry.MutexPersOnuConfig.RLock() |
| 2801 | if dh.IsReconciling() && pDevEntry.SOnuPersistentData.PersUniDisableDone { |
| 2802 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2803 | 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] | 2804 | log.Fields{"device-id": dh.DeviceID}) |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 2805 | dh.mutexForDisableDeviceRequested.Lock() |
| 2806 | dh.disableDeviceRequested = true |
| 2807 | dh.mutexForDisableDeviceRequested.Unlock() |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 2808 | dh.ReconcileDeviceTechProf(ctx) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2809 | // reconcilement will be continued after ani config is done |
| 2810 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2811 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2812 | // *** should generate UniUnlockStateDone event ***** |
| ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 2813 | dh.mutexForDisableDeviceRequested.RLock() |
| 2814 | if !dh.disableDeviceRequested { |
| 2815 | if dh.pUnlockStateFsm == nil { |
| 2816 | dh.createUniLockFsm(ctx, false, cmn.UniUnlockStateDone) |
| 2817 | } else { //UnlockStateFSM already init |
| 2818 | dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniUnlockStateDone) |
| 2819 | dh.runUniLockFsm(ctx, false) |
| 2820 | } |
| 2821 | dh.mutexForDisableDeviceRequested.RUnlock() |
| 2822 | } else { |
| 2823 | dh.mutexForDisableDeviceRequested.RUnlock() |
| 2824 | logger.Debugw(ctx, "Uni already lock", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2825 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2826 | } |
| 2827 | } |
| 2828 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2829 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2830 | func (dh *deviceHandler) processUniUnlockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2831 | dh.EnableUniPortStateUpdate(ctx) //cmp python yield self.enable_ports() |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2832 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2833 | if !dh.IsReconciling() { |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 2834 | // Check if TPs are available post device reboot. If TPs are available start processing them and configure flows |
| 2835 | if dh.GetDeviceTechProfOnReboot() { |
| 2836 | if dh.CheckForDeviceTechProf(ctx) { |
| 2837 | go dh.DeviceFlowConfigOnReboot(ctx) |
| 2838 | } |
| 2839 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2840 | 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] | 2841 | raisedTs := time.Now().Unix() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2842 | go dh.sendOnuOperStateEvent(ctx, voltha.OperStatus_ACTIVE, dh.DeviceID, raisedTs) //cmp python onu_active_event |
| 2843 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2844 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2845 | 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] | 2846 | return |
| 2847 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2848 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2849 | pDevEntry.SOnuPersistentData.PersUniUnlockDone = true |
| 2850 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2851 | if err := dh.StorePersistentData(ctx); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2852 | 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] | 2853 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2854 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2855 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2856 | 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] | 2857 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 2858 | dh.ReconcileDeviceTechProf(ctx) |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 2859 | |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2860 | // reconcilement will be continued after ani config is done |
| praneeth.nalmas | 2d75f00 | 2023-03-31 12:59:59 +0530 | [diff] [blame] | 2861 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2862 | } |
| 2863 | } |
| 2864 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2865 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2866 | func (dh *deviceHandler) processUniDisableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2867 | logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2868 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2869 | |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2870 | // disable device should have no impact on ConnStatus |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2871 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2872 | DeviceId: dh.DeviceID, |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2873 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2874 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 2875 | }); err != nil { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2876 | //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] | 2877 | 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] | 2878 | } |
| 2879 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2880 | 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] | 2881 | // 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] | 2882 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciAdminLock, true) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2883 | |
| 2884 | //transfer the modified logical uni port state |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2885 | dh.DisableUniPortStateUpdate(ctx) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2886 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2887 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2888 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2889 | 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] | 2890 | return |
| 2891 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2892 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2893 | pDevEntry.SOnuPersistentData.PersUniDisableDone = true |
| 2894 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2895 | if err := dh.StorePersistentData(ctx); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2896 | 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] | 2897 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2898 | } |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2901 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2902 | func (dh *deviceHandler) processUniEnableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2903 | 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] | 2904 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID}) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2905 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2906 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2907 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2908 | OperStatus: voltha.OperStatus_ACTIVE, |
| 2909 | }); err != nil { |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2910 | //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] | 2911 | 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] | 2912 | } |
| 2913 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2914 | logger.Debugw(ctx, "DeviceReasonUpdate upon re-enable", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2915 | "reason": cmn.DeviceReasonMap[cmn.DrOnuReenabled], "device-id": dh.DeviceID}) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2916 | // 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] | 2917 | _ = dh.ReasonUpdate(ctx, cmn.DrOnuReenabled, true) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2918 | |
| 2919 | //transfer the modified logical uni port state |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2920 | dh.EnableUniPortStateUpdate(ctx) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2921 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2922 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2923 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2924 | 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] | 2925 | return |
| 2926 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2927 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2928 | pDevEntry.SOnuPersistentData.PersUniDisableDone = false |
| 2929 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2930 | if err := dh.StorePersistentData(ctx); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2931 | 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] | 2932 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2933 | } |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2934 | } |
| 2935 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 2936 | //nolint:unparam |
| Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 2937 | func (dh *deviceHandler) processUniEnableStateFailedEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2938 | logger.Debugw(ctx, "DeviceStateUpdate upon re-enable failure. ", log.Fields{ |
| 2939 | "OperStatus": voltha.OperStatus_FAILED, "device-id": dh.DeviceID}) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2940 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 2941 | DeviceId: dh.DeviceID, |
| mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2942 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
| Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 2943 | OperStatus: voltha.OperStatus_FAILED, |
| 2944 | }); err != nil { |
| 2945 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| 2946 | } |
| 2947 | } |
| 2948 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2949 | func (dh *deviceHandler) processOmciAniConfigDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2950 | if devEvent == cmn.OmciAniConfigDone { |
| 2951 | logger.Debugw(ctx, "OmciAniConfigDone event received", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2952 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 2953 | // - which may cause some inconsistency |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2954 | if dh.getDeviceReason() != cmn.DrTechProfileConfigDownloadSuccess { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2955 | // 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] | 2956 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2957 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2958 | if dh.IsReconciling() { |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 2959 | // during reconciling with OMCI configuration in TT multi-UNI scenario, OmciAniConfigDone is reached several times |
| 2960 | // therefore it must be ensured that reconciling of flow config is only started on the first pass of this code position |
| 2961 | dh.mutexReconcilingFirstPassFlag.Lock() |
| 2962 | if dh.reconcilingFirstPass { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 2963 | 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] | 2964 | dh.reconcilingFirstPass = false |
| 2965 | go dh.ReconcileDeviceFlowConfig(ctx) |
| 2966 | } |
| 2967 | dh.mutexReconcilingFirstPassFlag.Unlock() |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2968 | } |
| 2969 | } else { // should be the OmciAniResourceRemoved block |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2970 | logger.Debugw(ctx, "OmciAniResourceRemoved event received", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2971 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 2972 | // - which may cause some inconsistency |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2973 | if dh.getDeviceReason() != cmn.DrTechProfileConfigDeleteSuccess { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2974 | // which may be the case from some previous activity even on this ONU port (but also other UNI ports) |
| 2975 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDeleteSuccess, true) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2976 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2977 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2978 | } |
| 2979 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2980 | func (dh *deviceHandler) processOmciVlanFilterDoneEvent(ctx context.Context, aDevEvent cmn.OnuDeviceEvent) { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2981 | logger.Debugw(ctx, "OmciVlanFilterDone event received", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2982 | log.Fields{"device-id": dh.DeviceID, "event": aDevEvent}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2983 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 2984 | // - which may cause some inconsistency |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2985 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2986 | if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterAddDoneNoKvStore { |
| 2987 | if dh.getDeviceReason() != cmn.DrOmciFlowsPushed { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2988 | // 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] | 2989 | // or even some previous flow add activity on the same port |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2990 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsPushed, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2991 | } |
| 2992 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2993 | if dh.getDeviceReason() != cmn.DrOmciFlowsDeleted { |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2994 | //not relevant for reconcile |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2995 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsDeleted, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2996 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2997 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2998 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2999 | if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterRemDone { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3000 | //events that request KvStore write |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3001 | if err := dh.StorePersistentData(ctx); err != nil { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3002 | 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] | 3003 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3004 | } |
| 3005 | } else { |
| 3006 | logger.Debugw(ctx, "OmciVlanFilter*Done* - write to KvStore not requested", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3007 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3008 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3009 | } |
| 3010 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3011 | // DeviceProcStatusUpdate evaluates possible processing events and initiates according next activities |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3012 | func (dh *deviceHandler) DeviceProcStatusUpdate(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3013 | switch devEvent { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3014 | case cmn.MibDatabaseSync: |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3015 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3016 | dh.processMibDatabaseSyncEvent(ctx, devEvent) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3017 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3018 | case cmn.UniLockStateDone: |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 3019 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3020 | dh.processUniLockStateDoneEvent(ctx, devEvent) |
| mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 3021 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3022 | case cmn.MibDownloadDone: |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3023 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3024 | dh.processMibDownloadDoneEvent(ctx, devEvent) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3025 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3026 | case cmn.UniUnlockStateDone: |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3027 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3028 | dh.processUniUnlockStateDoneEvent(ctx, devEvent) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3029 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3030 | case cmn.UniEnableStateDone: |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3031 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3032 | dh.processUniEnableStateDoneEvent(ctx, devEvent) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3033 | } |
| Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 3034 | case cmn.UniEnableStateFailed: |
| 3035 | { |
| 3036 | dh.processUniEnableStateFailedEvent(ctx, devEvent) |
| 3037 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3038 | case cmn.UniDisableStateDone: |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3039 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3040 | dh.processUniDisableStateDoneEvent(ctx, devEvent) |
| mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 3041 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3042 | case cmn.OmciAniConfigDone, cmn.OmciAniResourceRemoved: |
| mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 3043 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3044 | dh.processOmciAniConfigDoneEvent(ctx, devEvent) |
| mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 3045 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3046 | case cmn.OmciVlanFilterAddDone, cmn.OmciVlanFilterAddDoneNoKvStore, cmn.OmciVlanFilterRemDone, cmn.OmciVlanFilterRemDoneNoKvStore: |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3047 | { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3048 | dh.processOmciVlanFilterDoneEvent(ctx, devEvent) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3049 | } |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3050 | default: |
| 3051 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3052 | 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] | 3053 | } |
| 3054 | } //switch |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 3055 | } |
| 3056 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3057 | 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] | 3058 | // parameters are IntfId, OnuId, uniId |
| Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 3059 | uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3060 | uint32(aUniID)) |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3061 | if _, present := dh.uniEntityMap[uniNo]; present { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3062 | 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] | 3063 | } else { |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3064 | //with arguments aUniID, a_portNo, aPortType |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3065 | pUniPort := cmn.NewOnuUniPort(ctx, aUniID, uniNo, aUniInstNo, aPortType) |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 3066 | if pUniPort == nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3067 | 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] | 3068 | } else { |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3069 | //store UniPort with the System-PortNumber key |
| 3070 | dh.uniEntityMap[uniNo] = pUniPort |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3071 | if !dh.IsReconciling() { |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 3072 | // create announce the UniPort to the core as VOLTHA Port object |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3073 | if err := pUniPort.CreateVolthaPort(ctx, dh); err == nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3074 | 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] | 3075 | } //error logging already within UniPort method |
| 3076 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3077 | 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] | 3078 | } |
| Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 3079 | } |
| 3080 | } |
| 3081 | } |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3082 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3083 | func (dh *deviceHandler) AddAllUniPorts(ctx context.Context) { |
| 3084 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3085 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3086 | 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] | 3087 | return |
| 3088 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3089 | 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] | 3090 | if pptpInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3091 | ctx, me.PhysicalPathTerminationPointEthernetUniClassID); len(pptpInstKeys) > 0 { |
| 3092 | for _, mgmtEntityID := range pptpInstKeys { |
| 3093 | logger.Debugw(ctx, "Add PPTPEthUni port for MIB-stored instance:", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3094 | "device-id": dh.DeviceID, "PPTPEthUni EntityID": mgmtEntityID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3095 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniPPTP) |
| 3096 | uniCnt++ |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3097 | } |
| 3098 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3099 | 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] | 3100 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3101 | if veipInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3102 | ctx, me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 { |
| 3103 | for _, mgmtEntityID := range veipInstKeys { |
| 3104 | logger.Debugw(ctx, "Add VEIP for MIB-stored instance:", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3105 | "device-id": dh.DeviceID, "VEIP EntityID": mgmtEntityID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3106 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniVEIP) |
| 3107 | uniCnt++ |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3108 | } |
| 3109 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3110 | 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] | 3111 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3112 | if potsInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
| ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 3113 | ctx, me.PhysicalPathTerminationPointPotsUniClassID); len(potsInstKeys) > 0 { |
| 3114 | for _, mgmtEntityID := range potsInstKeys { |
| 3115 | 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] | 3116 | "device-id": dh.DeviceID, "PPTP Pots UNI EntityID": mgmtEntityID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3117 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniPPTPPots) |
| 3118 | uniCnt++ |
| ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 3119 | } |
| 3120 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3121 | 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] | 3122 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3123 | if uniCnt == 0 { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3124 | 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] | 3125 | return |
| 3126 | } |
| 3127 | |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 3128 | //Note: For the moment is is not required to include the (newly added) POTS ports into the range |
| 3129 | // of flowCall or reconcile channels. But some sort of flow and reconcile processing might get necessary |
| 3130 | // 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] | 3131 | dh.flowCbChan = make([]chan FlowCb, uniCnt) |
| 3132 | dh.stopFlowMonitoringRoutine = make([]chan bool, uniCnt) |
| 3133 | dh.isFlowMonitoringRoutineActive = make([]bool, uniCnt) |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 3134 | //chUniVlanConfigReconcilingDone needs to have the capacity of all UniPorts as flow reconcile may run parallel for all of them |
| 3135 | dh.chUniVlanConfigReconcilingDone = make(chan uint16, uniCnt) |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 3136 | dh.chUniVlanConfigOnRebootDone = make(chan uint16, uniCnt) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3137 | for i := 0; i < int(uniCnt); i++ { |
| 3138 | dh.flowCbChan[i] = make(chan FlowCb, dh.pOpenOnuAc.config.MaxConcurrentFlowsPerUni) |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 3139 | dh.stopFlowMonitoringRoutine[i] = make(chan bool, 1) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3140 | } |
| 3141 | } |
| 3142 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3143 | // EnableUniPortStateUpdate enables UniPortState and update core port state accordingly |
| 3144 | func (dh *deviceHandler) EnableUniPortStateUpdate(ctx context.Context) { |
| Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 3145 | // 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] | 3146 | // but towards core only the first port active state is signaled |
| Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 3147 | // with following remark: |
| 3148 | // # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow |
| 3149 | // # load on the core |
| 3150 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3151 | // 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] | 3152 | |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3153 | for uniNo, uniPort := range dh.uniEntityMap { |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3154 | // only if this port is validated for operState transfer |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3155 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 3156 | 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] | 3157 | uniPort.SetOperState(common.OperStatus_ACTIVE) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3158 | if !dh.IsReconciling() { |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 3159 | //maybe also use getter functions on uniPort - perhaps later ... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3160 | go func(port *cmn.OnuUniPort) { |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3161 | if err := dh.updatePortStateInCore(ctx, &ca.PortState{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3162 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3163 | PortType: voltha.Port_ETHERNET_UNI, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3164 | PortNo: port.PortNo, |
| 3165 | OperStatus: port.OperState, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3166 | }); err != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3167 | 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] | 3168 | } |
| 3169 | }(uniPort) |
| Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 3170 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3171 | 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] | 3172 | } |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3173 | } |
| 3174 | } |
| 3175 | } |
| 3176 | |
| 3177 | // Disable UniPortState and update core port state accordingly |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3178 | func (dh *deviceHandler) DisableUniPortStateUpdate(ctx context.Context) { |
| 3179 | // compare EnableUniPortStateUpdate() above |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3180 | // -> use current restriction to operate only on first UNI port as inherited from actual Py code |
| 3181 | for uniNo, uniPort := range dh.uniEntityMap { |
| 3182 | // only if this port is validated for operState transfer |
| Matteo Scandolo | 20d180c | 2021-06-10 17:20:21 +0200 | [diff] [blame] | 3183 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3184 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 3185 | 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] | 3186 | uniPort.SetOperState(common.OperStatus_UNKNOWN) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3187 | if !dh.IsReconciling() { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3188 | //maybe also use getter functions on uniPort - perhaps later ... |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3189 | go func(port *cmn.OnuUniPort) { |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3190 | if err := dh.updatePortStateInCore(ctx, &ca.PortState{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3191 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3192 | PortType: voltha.Port_ETHERNET_UNI, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3193 | PortNo: port.PortNo, |
| 3194 | OperStatus: port.OperState, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3195 | }); err != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3196 | 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] | 3197 | } |
| 3198 | }(uniPort) |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3199 | } else { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3200 | 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] | 3201 | } |
| 3202 | |
| Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 3203 | } |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3204 | } |
| 3205 | } |
| 3206 | |
| 3207 | // ONU_Active/Inactive announcement on system KAFKA bus |
| 3208 | // 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] | 3209 | 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] | 3210 | var de voltha.DeviceEvent |
| 3211 | eventContext := make(map[string]string) |
| 3212 | //Populating event context |
| 3213 | // 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] | 3214 | parentDevice, err := dh.getDeviceFromCore(ctx, dh.parentID) |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3215 | if err != nil || parentDevice == nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3216 | logger.Errorw(ctx, "Failed to fetch parent device for OnuEvent", |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3217 | log.Fields{"device-id": dh.DeviceID, "parentID": dh.parentID, "err": err}) |
| Holger Hildebrandt | 7ec14c4 | 2021-05-28 14:21:58 +0000 | [diff] [blame] | 3218 | 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] | 3219 | } |
| 3220 | oltSerialNumber := parentDevice.SerialNumber |
| 3221 | |
| 3222 | eventContext["pon-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.IntfId), 10) |
| 3223 | eventContext["onu-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.OnuId), 10) |
| 3224 | eventContext["serial-number"] = dh.device.SerialNumber |
| ssiddiqui | 1221d1a | 2021-02-15 11:12:51 +0530 | [diff] [blame] | 3225 | eventContext["olt-serial-number"] = oltSerialNumber |
| 3226 | eventContext["device-id"] = aDeviceID |
| 3227 | eventContext["registration-id"] = aDeviceID //py: string(device_id)?? |
| ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 3228 | eventContext["num-of-unis"] = strconv.Itoa(len(dh.uniEntityMap)) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3229 | if deviceEntry := dh.GetOnuDeviceEntry(ctx, false); deviceEntry != nil { |
| 3230 | deviceEntry.MutexPersOnuConfig.RLock() |
| Holger Hildebrandt | 3d3c2c5 | 2022-06-08 13:25:43 +0000 | [diff] [blame] | 3231 | eventContext["vendor-id"] = deviceEntry.SOnuPersistentData.PersVendorID |
| 3232 | eventContext["model"] = deviceEntry.SOnuPersistentData.PersVersion |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3233 | eventContext["equipment-id"] = deviceEntry.SOnuPersistentData.PersEquipmentID |
| 3234 | deviceEntry.MutexPersOnuConfig.RUnlock() |
| 3235 | eventContext["software-version"] = deviceEntry.GetActiveImageVersion(ctx) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3236 | eventContext["inactive-software-version"] = deviceEntry.GetInactiveImageVersion(ctx) |
| ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 3237 | logger.Debugw(ctx, "prepare ONU_ACTIVATED event", |
| 3238 | log.Fields{"device-id": aDeviceID, "EventContext": eventContext}) |
| 3239 | } else { |
| 3240 | logger.Errorw(ctx, "Failed to fetch device-entry. ONU_ACTIVATED event is not sent", |
| 3241 | log.Fields{"device-id": aDeviceID}) |
| 3242 | return |
| 3243 | } |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3244 | |
| 3245 | /* Populating device event body */ |
| 3246 | de.Context = eventContext |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3247 | de.ResourceId = aDeviceID |
| 3248 | if aOperState == voltha.OperStatus_ACTIVE { |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3249 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "RAISE_EVENT") |
| 3250 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 3251 | cEventObjectType, cOnuActivatedEvent, "Raised") |
| 3252 | } else { |
| 3253 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "CLEAR_EVENT") |
| 3254 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 3255 | cEventObjectType, cOnuActivatedEvent, "Cleared") |
| 3256 | } |
| 3257 | /* Send event to KAFKA */ |
| kesavand | 510a31c | 2022-03-16 17:12:12 +0530 | [diff] [blame] | 3258 | if err := dh.EventProxy.SendDeviceEventWithKey(ctx, &de, equipment, pon, raisedTs, aDeviceID); err != nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3259 | logger.Warnw(ctx, "could not send ONU_ACTIVATED event", |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3260 | log.Fields{"device-id": aDeviceID, "error": err}) |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3261 | } |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3262 | logger.Infow(ctx, "ctx, ONU_ACTIVATED event sent to KAFKA", |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3263 | log.Fields{"device-id": aDeviceID, "with-EventName": de.DeviceEventName}) |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3264 | } |
| 3265 | |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3266 | // 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] | 3267 | 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] | 3268 | chLSFsm := make(chan cmn.Message, 2) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3269 | var sFsmName string |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3270 | if aAdminState { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3271 | logger.Debugw(ctx, "createLockStateFSM", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3272 | sFsmName = "LockStateFSM" |
| 3273 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3274 | logger.Debugw(ctx, "createUnlockStateFSM", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3275 | sFsmName = "UnLockStateFSM" |
| 3276 | } |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3277 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3278 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3279 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3280 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 3281 | return |
| 3282 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3283 | pLSFsm := uniprt.NewLockStateFsm(ctx, aAdminState, devEvent, sFsmName, dh, pDevEntry, chLSFsm) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3284 | if pLSFsm != nil { |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3285 | if aAdminState { |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3286 | dh.pLockStateFsm = pLSFsm |
| 3287 | } else { |
| 3288 | dh.pUnlockStateFsm = pLSFsm |
| 3289 | } |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3290 | dh.runUniLockFsm(ctx, aAdminState) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3291 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3292 | 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] | 3293 | } |
| 3294 | } |
| 3295 | |
| 3296 | // 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] | 3297 | func (dh *deviceHandler) runUniLockFsm(ctx context.Context, aAdminState bool) { |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3298 | /* Uni Port lock/unlock procedure - |
| 3299 | ***** should run via 'adminDone' state and generate the argument requested event ***** |
| 3300 | */ |
| 3301 | var pLSStatemachine *fsm.FSM |
| Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3302 | if aAdminState { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3303 | pLSStatemachine = dh.pLockStateFsm.PAdaptFsm.PFsm |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3304 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 3305 | if (dh.pUnlockStateFsm != nil) && |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3306 | (dh.pUnlockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) { |
| 3307 | _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3308 | } |
| 3309 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3310 | pLSStatemachine = dh.pUnlockStateFsm.PAdaptFsm.PFsm |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3311 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 3312 | if (dh.pLockStateFsm != nil) && |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3313 | (dh.pLockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) { |
| 3314 | _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3315 | } |
| 3316 | } |
| 3317 | if pLSStatemachine != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3318 | if pLSStatemachine.Is(uniprt.UniStDisabled) { |
| 3319 | if err := pLSStatemachine.Event(uniprt.UniEvStart); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3320 | 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] | 3321 | // maybe try a FSM reset and then again ... - TODO!!! |
| 3322 | } else { |
| 3323 | /***** LockStateFSM started */ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3324 | logger.Debugw(ctx, "LockStateFSM started", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3325 | "state": pLSStatemachine.Current(), "device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3326 | } |
| 3327 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3328 | logger.Warnw(ctx, "wrong state of LockStateFSM - want: disabled", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3329 | "have": pLSStatemachine.Current(), "device-id": dh.DeviceID}) |
| Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3330 | // maybe try a FSM reset and then again ... - TODO!!! |
| 3331 | } |
| 3332 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3333 | 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] | 3334 | // maybe try a FSM reset and then again ... - TODO!!! |
| 3335 | } |
| 3336 | } |
| 3337 | |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3338 | // createOnuUpgradeFsm initializes and runs the Onu Software upgrade FSM |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3339 | // precondition: lockUpgradeFsm is already locked from caller of this function |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3340 | // |
| 3341 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3342 | 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] | 3343 | chUpgradeFsm := make(chan cmn.Message, 2) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3344 | var sFsmName = "OnuSwUpgradeFSM" |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3345 | logger.Debugw(ctx, "create OnuSwUpgradeFSM", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3346 | if apDevEntry.PDevOmciCC == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3347 | 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] | 3348 | 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] | 3349 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3350 | dh.pOnuUpradeFsm = swupg.NewOnuUpgradeFsm(ctx, dh, apDevEntry, apDevEntry.GetOnuDB(), aDevEvent, |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3351 | sFsmName, chUpgradeFsm) |
| 3352 | if dh.pOnuUpradeFsm != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3353 | pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3354 | if pUpgradeStatemachine != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3355 | if pUpgradeStatemachine.Is(swupg.UpgradeStDisabled) { |
| 3356 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvStart); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3357 | 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] | 3358 | // maybe try a FSM reset and then again ... - TODO!!! |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3359 | 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] | 3360 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3361 | /***** Upgrade FSM started */ |
| mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 3362 | //reset the last stored upgrade states (which anyway should be don't care as long as the newly created FSM exists) |
| 3363 | (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 3364 | (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR |
| 3365 | (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3366 | logger.Debugw(ctx, "OnuSwUpgradeFSM started", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3367 | "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3368 | } else { |
| 3369 | 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] | 3370 | "have": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3371 | // maybe try a FSM reset and then again ... - TODO!!! |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3372 | 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] | 3373 | } |
| 3374 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3375 | 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] | 3376 | // maybe try a FSM reset and then again ... - TODO!!! |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3377 | 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] | 3378 | } |
| 3379 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3380 | 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] | 3381 | 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] | 3382 | } |
| 3383 | return nil |
| 3384 | } |
| 3385 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3386 | // RemoveOnuUpgradeFsm clears the Onu Software upgrade FSM |
| 3387 | func (dh *deviceHandler) RemoveOnuUpgradeFsm(ctx context.Context, apImageState *voltha.ImageState) { |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3388 | logger.Debugw(ctx, "remove OnuSwUpgradeFSM StateMachine", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3389 | "device-id": dh.DeviceID}) |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3390 | dh.lockUpgradeFsm.Lock() |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3391 | dh.pOnuUpradeFsm = nil //resource clearing is left to garbage collector |
| 3392 | dh.upgradeCanceled = false //cancelation done |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 3393 | dh.pLastUpgradeImageState = apImageState |
| 3394 | dh.lockUpgradeFsm.Unlock() |
| 3395 | //signal upgradeFsm removed using non-blocking channel send |
| 3396 | select { |
| 3397 | case dh.upgradeFsmChan <- struct{}{}: |
| 3398 | default: |
| 3399 | 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] | 3400 | "device-id": dh.DeviceID}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 3401 | } |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3402 | } |
| 3403 | |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3404 | // checkOnOnuImageCommit verifies if the ONU is in some upgrade state that allows for image commit and if tries to commit |
| 3405 | func (dh *deviceHandler) checkOnOnuImageCommit(ctx context.Context) { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3406 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3407 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3408 | 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] | 3409 | return |
| 3410 | } |
| 3411 | |
| 3412 | dh.lockUpgradeFsm.RLock() |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3413 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3414 | if dh.pOnuUpradeFsm != nil { |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3415 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 3416 | dh.lockUpgradeFsm.RUnlock() |
| 3417 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 3418 | return |
| 3419 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3420 | pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3421 | if pUpgradeStatemachine != nil { |
| 3422 | // commit is only processed in case out upgrade FSM indicates the according state (for automatic commit) |
| 3423 | // (some manual forced commit could do without) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3424 | UpgradeState := pUpgradeStatemachine.Current() |
| 3425 | if (UpgradeState == swupg.UpgradeStWaitForCommit) || |
| 3426 | (UpgradeState == swupg.UpgradeStRequestingActivate) { |
| 3427 | // 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] | 3428 | // 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] | 3429 | if pDevEntry.IsImageToBeCommitted(ctx, dh.pOnuUpradeFsm.InactiveImageMeID) { |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3430 | activeImageID, errImg := pDevEntry.GetActiveImageMeID(ctx) |
| 3431 | if errImg != nil { |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3432 | dh.lockUpgradeFsm.RUnlock() |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3433 | logger.Errorw(ctx, "OnuSwUpgradeFSM abort - could not get active image after reboot", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3434 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3435 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 3436 | dh.upgradeCanceled = true |
| 3437 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 3438 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3439 | return |
| 3440 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3441 | dh.lockUpgradeFsm.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3442 | if activeImageID == dh.pOnuUpradeFsm.InactiveImageMeID { |
| 3443 | if (UpgradeState == swupg.UpgradeStRequestingActivate) && !dh.pOnuUpradeFsm.GetCommitFlag(ctx) { |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3444 | // 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] | 3445 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvActivationDone); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3446 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call activate-done event", |
| 3447 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3448 | return |
| 3449 | } |
| 3450 | logger.Debugw(ctx, "OnuSwUpgradeFSM activate-done after reboot", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3451 | "state": UpgradeState, "device-id": dh.DeviceID}) |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3452 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3453 | //FSM in waitForCommit or (UpgradeStRequestingActivate [lost ActivateResp] and commit allowed) |
| 3454 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvCommitSw); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3455 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call commit event", |
| 3456 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3457 | return |
| 3458 | } |
| 3459 | logger.Debugw(ctx, "OnuSwUpgradeFSM commit image requested", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3460 | "state": UpgradeState, "device-id": dh.DeviceID}) |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3461 | } |
| 3462 | } else { |
| 3463 | 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] | 3464 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 3465 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 3466 | dh.upgradeCanceled = true |
| 3467 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 3468 | } |
| mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3469 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3470 | return |
| 3471 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3472 | dh.lockUpgradeFsm.RUnlock() |
| 3473 | logger.Errorw(ctx, "OnuSwUpgradeFSM waiting to commit, but nothing to commit on ONU - abort upgrade", |
| 3474 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 3475 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 3476 | dh.upgradeCanceled = true |
| 3477 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 3478 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3479 | return |
| 3480 | } |
| 3481 | //upgrade FSM is active but not waiting for commit: maybe because commit flag is not set |
| 3482 | // upgrade FSM is to be informed if the current active image is the one that was used in upgrade for the download |
| 3483 | if activeImageID, err := pDevEntry.GetActiveImageMeID(ctx); err == nil { |
| 3484 | if dh.pOnuUpradeFsm.InactiveImageMeID == activeImageID { |
| 3485 | logger.Debugw(ctx, "OnuSwUpgradeFSM image state set to activated", log.Fields{ |
| 3486 | "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
| 3487 | dh.pOnuUpradeFsm.SetImageStateActive(ctx) |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 3488 | } |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3489 | } |
| 3490 | } |
| 3491 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3492 | 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] | 3493 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3494 | dh.lockUpgradeFsm.RUnlock() |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3495 | } |
| 3496 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3497 | // 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] | 3498 | func (dh *deviceHandler) SetBackend(ctx context.Context, aBasePathKvStore string) *db.Backend { |
| Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 3499 | |
| 3500 | logger.Debugw(ctx, "SetKVStoreBackend", log.Fields{"IpTarget": dh.pOpenOnuAc.KVStoreAddress, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3501 | "BasePathKvStore": aBasePathKvStore, "device-id": dh.DeviceID}) |
| Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 3502 | // 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] | 3503 | kvbackend := &db.Backend{ |
| 3504 | Client: dh.pOpenOnuAc.kvClient, |
| 3505 | StoreType: dh.pOpenOnuAc.KVStoreType, |
| 3506 | /* address config update acc. to [VOL-2736] */ |
| Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 3507 | Address: dh.pOpenOnuAc.KVStoreAddress, |
| mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 3508 | Timeout: dh.pOpenOnuAc.KVStoreTimeout, |
| 3509 | PathPrefix: aBasePathKvStore} |
| Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 3510 | |
| mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 3511 | return kvbackend |
| Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3512 | } |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 3513 | |
| 3514 | //nolint:unparam |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3515 | func (dh *deviceHandler) getFlowOfbFields(ctx context.Context, apFlowItem *of.OfpFlowStats, loMatchVlan *uint16, |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3516 | loMatchPcp *uint8, loIPProto *uint32) { |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3517 | |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3518 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 3519 | switch field.Type { |
| 3520 | case of.OxmOfbFieldTypes_OFPXMT_OFB_ETH_TYPE: |
| 3521 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3522 | logger.Debugw(ctx, "flow type EthType", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3523 | "EthType": strconv.FormatInt(int64(field.GetEthType()), 16)}) |
| 3524 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3525 | /* TT related temporary workaround - should not be needed anymore |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3526 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO: |
| 3527 | { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3528 | *loIPProto = field.GetIpProto() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3529 | logger.Debugw("flow type IpProto", log.Fields{"device-id": dh.DeviceID, |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3530 | "IpProto": strconv.FormatInt(int64(*loIPProto), 16)}) |
| 3531 | if *loIPProto == 2 { |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3532 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 3533 | // avoids installing invalid EVTOCD rule |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3534 | logger.Debugw("flow type IpProto 2: TT workaround: ignore flow", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3535 | log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3536 | return |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3537 | } |
| 3538 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3539 | */ |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3540 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID: |
| 3541 | { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3542 | *loMatchVlan = uint16(field.GetVlanVid()) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3543 | loMatchVlanMask := uint16(field.GetVlanVidMask()) |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 3544 | if *loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) || |
| 3545 | loMatchVlanMask != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3546 | *loMatchVlan = *loMatchVlan & 0xFFF // not transparent: copy only ID bits |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3547 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3548 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3549 | "VID": strconv.FormatInt(int64(*loMatchVlan), 16)}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3550 | } |
| 3551 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP: |
| 3552 | { |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3553 | *loMatchPcp = uint8(field.GetVlanPcp()) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3554 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3555 | "PCP": loMatchPcp}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3556 | } |
| 3557 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_DST: |
| 3558 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3559 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3560 | "UDP-DST": strconv.FormatInt(int64(field.GetUdpDst()), 16)}) |
| 3561 | } |
| 3562 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_SRC: |
| 3563 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3564 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3565 | "UDP-SRC": strconv.FormatInt(int64(field.GetUdpSrc()), 16)}) |
| 3566 | } |
| 3567 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_DST: |
| 3568 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3569 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3570 | "IPv4-DST": field.GetIpv4Dst()}) |
| 3571 | } |
| 3572 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_SRC: |
| 3573 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3574 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3575 | "IPv4-SRC": field.GetIpv4Src()}) |
| 3576 | } |
| 3577 | case of.OxmOfbFieldTypes_OFPXMT_OFB_METADATA: |
| 3578 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3579 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3580 | "Metadata": field.GetTableMetadata()}) |
| 3581 | } |
| 3582 | /* |
| 3583 | default: |
| 3584 | { |
| 3585 | //all other entires ignored |
| 3586 | } |
| 3587 | */ |
| 3588 | } |
| 3589 | } //for all OfbFields |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3590 | } |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3591 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3592 | 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] | 3593 | for _, action := range flow.GetActions(apFlowItem) { |
| 3594 | switch action.Type { |
| 3595 | /* not used: |
| 3596 | case of.OfpActionType_OFPAT_OUTPUT: |
| 3597 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3598 | logger.Debugw("flow action type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3599 | "Output": action.GetOutput()}) |
| 3600 | } |
| 3601 | */ |
| 3602 | case of.OfpActionType_OFPAT_PUSH_VLAN: |
| 3603 | { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3604 | logger.Debugw(ctx, "flow action type", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3605 | "PushEthType": strconv.FormatInt(int64(action.GetPush().Ethertype), 16)}) |
| 3606 | } |
| 3607 | case of.OfpActionType_OFPAT_SET_FIELD: |
| 3608 | { |
| 3609 | pActionSetField := action.GetSetField() |
| 3610 | if pActionSetField.Field.OxmClass != of.OfpOxmClass_OFPXMC_OPENFLOW_BASIC { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3611 | 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] | 3612 | "OxcmClass": pActionSetField.Field.OxmClass}) |
| 3613 | } |
| 3614 | if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3615 | *loSetVlan = uint16(pActionSetField.Field.GetOfbField().GetVlanVid()) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3616 | 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] | 3617 | "SetVlan": strconv.FormatInt(int64(*loSetVlan), 16)}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3618 | } else if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP { |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3619 | *loSetPcp = uint8(pActionSetField.Field.GetOfbField().GetVlanPcp()) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3620 | 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] | 3621 | "SetPcp": *loSetPcp}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3622 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3623 | 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] | 3624 | "Type": pActionSetField.Field.GetOfbField().Type}) |
| 3625 | } |
| 3626 | } |
| 3627 | /* |
| 3628 | default: |
| 3629 | { |
| 3630 | //all other entires ignored |
| 3631 | } |
| 3632 | */ |
| 3633 | } |
| 3634 | } //for all Actions |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3635 | } |
| 3636 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3637 | // addFlowItemToUniPort parses the actual flow item to add it to the UniPort |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3638 | func (dh *deviceHandler) addFlowItemToUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort, |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3639 | apFlowMetaData *of.FlowMetadata, respChan *chan error) { |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 3640 | var loSetVlan = uint16(of.OfpVlanId_OFPVID_NONE) //noValidEntry |
| 3641 | var loMatchVlan = uint16(of.OfpVlanId_OFPVID_PRESENT) //reserved VLANID entry |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3642 | var loSetPcp uint8 |
| 3643 | 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] | 3644 | var loIPProto uint32 |
| 3645 | /* the TechProfileId is part of the flow Metadata - compare also comment within |
| 3646 | * OLT-Adapter:openolt_flowmgr.go |
| 3647 | * Metadata 8 bytes: |
| 3648 | * Most Significant 2 Bytes = Inner VLAN |
| 3649 | * Next 2 Bytes = Tech Profile ID(TPID) |
| 3650 | * Least Significant 4 Bytes = Port ID |
| 3651 | * Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all |
| 3652 | * subscriber related flows. |
| 3653 | */ |
| 3654 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3655 | metadata := flow.GetMetadataFromWriteMetadataAction(ctx, apFlowItem) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3656 | if metadata == 0 { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3657 | logger.Debugw(ctx, "flow-add invalid metadata - abort", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3658 | log.Fields{"device-id": dh.DeviceID}) |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3659 | *respChan <- fmt.Errorf("flow-add invalid metadata: %s", dh.DeviceID) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3660 | } |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3661 | loTpID := uint8(flow.GetTechProfileIDFromWriteMetaData(ctx, metadata)) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3662 | loCookie := apFlowItem.GetCookie() |
| 3663 | loCookieSlice := []uint64{loCookie} |
| Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 3664 | loInnerCvlan := flow.GetInnerTagFromWriteMetaData(ctx, metadata) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3665 | 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] | 3666 | "TechProf-Id": loTpID, "cookie": loCookie, "innerCvlan": loInnerCvlan}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3667 | |
| Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 3668 | dh.getFlowOfbFields(ctx, apFlowItem, &loMatchVlan, &loMatchPcp, &loIPProto) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3669 | /* TT related temporary workaround - should not be needed anymore |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3670 | if loIPProto == 2 { |
| 3671 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 3672 | // avoids installing invalid EVTOCD rule |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3673 | logger.Debugw("flow-add type IpProto 2: TT workaround: ignore flow", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3674 | log.Fields{"device-id": dh.DeviceID}) |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3675 | return nil |
| 3676 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3677 | */ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3678 | dh.getFlowActions(ctx, apFlowItem, &loSetPcp, &loSetVlan) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3679 | |
| Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 3680 | if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) && (loMatchPcp == 8) && |
| 3681 | loInnerCvlan == uint16(of.OfpVlanId_OFPVID_NONE) { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3682 | 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] | 3683 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo, |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3684 | "set_vid": strconv.FormatInt(int64(loSetVlan), 16), |
| 3685 | "match_vid": strconv.FormatInt(int64(loMatchVlan), 16)}) |
| 3686 | //TODO!!: Use DeviceId within the error response to rwCore |
| 3687 | // 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] | 3688 | *respChan <- fmt.Errorf("flow-add Set/Match VlanId inconsistent: %s", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3689 | } |
| 3690 | 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] | 3691 | 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] | 3692 | loSetVlan = loMatchVlan //both 'transparent' (copy any) |
| Abhilash Laxmeshwar | f15a0d0 | 2022-08-08 11:09:32 +0530 | [diff] [blame] | 3693 | } else if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) && |
| 3694 | loInnerCvlan != uint16(of.OfpVlanId_OFPVID_NONE) { |
| 3695 | loSetVlan = loMatchVlan |
| 3696 | 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] | 3697 | } else { |
| 3698 | //looks like OMCI value 4097 (copyFromOuter - for Uni double tagged) is not supported here |
| 3699 | if loSetVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
| 3700 | // not set to transparent |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3701 | loSetVlan &= 0x0FFF //mask VID bits as prerequisite for vlanConfigFsm |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3702 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3703 | logger.Debugw(ctx, "flow-add vlan-set", log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3704 | } |
| mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3705 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3706 | var meter *of.OfpMeterConfig |
| ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3707 | if apFlowMetaData != nil { |
| 3708 | meter = apFlowMetaData.Meters[0] |
| 3709 | } |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3710 | //mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities |
| 3711 | // must be set including the execution of createVlanFilterFsm() to avoid unintended creation of FSM's |
| 3712 | // when different rules are requested concurrently for the same uni |
| 3713 | // (also vlan persistency data does not support multiple FSM's on the same UNI correctly!) |
| 3714 | dh.lockVlanAdd.Lock() //prevent multiple add activities to start in parallel |
| 3715 | dh.lockVlanConfig.RLock() //read protection on UniVlanConfigFsmMap (removeFlowItemFromUniPort) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3716 | logger.Debugw(ctx, "flow-add got lock", log.Fields{"device-id": dh.DeviceID, "tpID": loTpID, "uniID": apUniPort.UniID}) |
| 3717 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3718 | //SetUniFlowParams() may block on some rule that is suspended-to-add |
| 3719 | // 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] | 3720 | // Also the error is returned to caller via response channel |
| 3721 | _ = dh.UniVlanConfigFsmMap[apUniPort.UniID].SetUniFlowParams(ctx, loTpID, loCookieSlice, |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 3722 | loMatchVlan, loMatchPcp, loSetVlan, loSetPcp, loInnerCvlan, false, false, meter, respChan) |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3723 | dh.lockVlanConfig.RUnlock() |
| 3724 | dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3725 | return |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3726 | } |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3727 | dh.lockVlanConfig.RUnlock() |
| 3728 | 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] | 3729 | err := dh.createVlanFilterFsm(ctx, apUniPort, loTpID, loCookieSlice, |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 3730 | loMatchVlan, loMatchPcp, loSetVlan, loSetPcp, loInnerCvlan, cmn.OmciVlanFilterAddDone, false, false, meter, respChan) |
| mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3731 | dh.lockVlanConfig.Unlock() |
| mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3732 | dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3733 | if err != nil { |
| 3734 | *respChan <- err |
| 3735 | } |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3736 | } |
| 3737 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3738 | // removeFlowItemFromUniPort parses the actual flow item to remove it from the UniPort |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3739 | 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] | 3740 | //optimization and assumption: the flow cookie uniquely identifies the flow and with that the internal rule |
| 3741 | //hence only the cookie is used here to find the relevant flow and possibly remove the rule |
| 3742 | //no extra check is done on the rule parameters |
| 3743 | //accordingly the removal is done only once - for the first found flow with that cookie, even though |
| 3744 | // at flow creation is not assured, that the same cookie is not configured for different flows - just assumed |
| 3745 | //additionally it is assumed here, that removal can only be done for one cookie per flow in a sequence (different |
| 3746 | // 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] | 3747 | // - 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] | 3748 | loCookie := apFlowItem.GetCookie() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3749 | 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] | 3750 | |
| 3751 | /* TT related temporary workaround - should not be needed anymore |
| 3752 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 3753 | if field.Type == of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO { |
| 3754 | loIPProto := field.GetIpProto() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3755 | logger.Debugw(ctx, "flow type IpProto", log.Fields{"device-id": dh.DeviceID, |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3756 | "IpProto": strconv.FormatInt(int64(loIPProto), 16)}) |
| 3757 | if loIPProto == 2 { |
| 3758 | // 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] | 3759 | logger.Debugw(ctx, "flow-remove type IpProto 2: TT workaround: ignore flow", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3760 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3761 | return nil |
| 3762 | } |
| 3763 | } |
| 3764 | } //for all OfbFields |
| 3765 | */ |
| 3766 | |
| mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3767 | //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] | 3768 | dh.lockVlanConfig.RLock() |
| 3769 | defer dh.lockVlanConfig.RUnlock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3770 | logger.Debugw(ctx, "flow-remove got RLock", log.Fields{"device-id": dh.DeviceID, "uniID": apUniPort.UniID}) |
| 3771 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3772 | _ = dh.UniVlanConfigFsmMap[apUniPort.UniID].RemoveUniFlowParams(ctx, loCookie, respChan) |
| 3773 | return |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3774 | } |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3775 | 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] | 3776 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3777 | //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] | 3778 | // 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] | 3779 | // Push response on the response channel |
| 3780 | if respChan != nil { |
| 3781 | // 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 |
| 3782 | select { |
| 3783 | case *respChan <- nil: |
| 3784 | logger.Debugw(ctx, "submitted-response-for-flow", log.Fields{"device-id": dh.DeviceID, "err": nil}) |
| 3785 | default: |
| 3786 | } |
| 3787 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3788 | go dh.DeviceProcStatusUpdate(ctx, cmn.OmciVlanFilterRemDone) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3789 | } |
| 3790 | |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3791 | // createVlanFilterFsm initializes and runs the VlanFilter FSM to transfer OMCI related VLAN config |
| mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3792 | // 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] | 3793 | // precondition: dh.lockVlanConfig is locked by the caller! |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3794 | 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] | 3795 | 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] | 3796 | chVlanFilterFsm := make(chan cmn.Message, 2) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3797 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3798 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3799 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3800 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 3801 | return fmt.Errorf("no valid OnuDevice for device-id %x - aborting", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3802 | } |
| 3803 | |
| Sridhar Ravindra | 2f86efb | 2024-12-06 11:02:10 +0530 | [diff] [blame] | 3804 | if dh.pDeviceStateFsm.Current() == devStDown { |
| 3805 | logger.Warnw(ctx, "UniVlanConfigFsm : aborting, device state down", log.Fields{"device-id": dh.DeviceID}) |
| 3806 | return fmt.Errorf("device state down for device-id %x - aborting", dh.DeviceID) |
| 3807 | } |
| 3808 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3809 | pVlanFilterFsm := avcfg.NewUniVlanConfigFsm(ctx, dh, pDevEntry, pDevEntry.PDevOmciCC, apUniPort, dh.pOnuTP, |
| 3810 | pDevEntry.GetOnuDB(), aTpID, aDevEvent, "UniVlanConfigFsm", chVlanFilterFsm, |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 3811 | dh.pOpenOnuAc.AcceptIncrementalEvto, aCookieSlice, aMatchVlan, aMatchPcp, aSetVlan, aSetPcp, innerCvlan, lastFlowToReconcile, lastFlowToConfOnReboot, aMeter, respChan) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3812 | if pVlanFilterFsm != nil { |
| mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3813 | //dh.lockVlanConfig is locked (by caller) throughout the state transition to 'starting' |
| 3814 | // to prevent unintended (ignored) events to be sent there (from parallel processing) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3815 | dh.UniVlanConfigFsmMap[apUniPort.UniID] = pVlanFilterFsm |
| 3816 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3817 | if pVlanFilterStatemachine != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3818 | if pVlanFilterStatemachine.Is(avcfg.VlanStDisabled) { |
| 3819 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvStart); err != nil { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3820 | logger.Warnw(ctx, "UniVlanConfigFsm: can't start", |
| 3821 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3822 | return fmt.Errorf("can't start UniVlanConfigFsm for device-id %x", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3823 | } |
| Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3824 | /***** UniVlanConfigFsm started */ |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3825 | logger.Debugw(ctx, "UniVlanConfigFsm started", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3826 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3827 | "UniPort": apUniPort.PortNo}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3828 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3829 | logger.Warnw(ctx, "wrong state of UniVlanConfigFsm - want: disabled", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3830 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID}) |
| 3831 | 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] | 3832 | } |
| 3833 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3834 | logger.Errorw(ctx, "UniVlanConfigFsm StateMachine invalid - cannot be executed!!", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3835 | "device-id": dh.DeviceID}) |
| 3836 | return fmt.Errorf("uniVlanConfigFsm invalid for device-id %x", dh.DeviceID) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3837 | } |
| 3838 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3839 | logger.Errorw(ctx, "UniVlanConfigFsm could not be created - abort!!", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3840 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| 3841 | 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] | 3842 | } |
| 3843 | return nil |
| 3844 | } |
| 3845 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3846 | // VerifyVlanConfigRequest checks on existence of a given uniPort |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3847 | // and starts verification of flow config based on that |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3848 | func (dh *deviceHandler) VerifyVlanConfigRequest(ctx context.Context, aUniID uint8, aTpID uint8) { |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3849 | //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] | 3850 | var pCurrentUniPort *cmn.OnuUniPort |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3851 | for _, uniPort := range dh.uniEntityMap { |
| 3852 | // only if this port is validated for operState transfer |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3853 | if uniPort.UniID == uint8(aUniID) { |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3854 | pCurrentUniPort = uniPort |
| 3855 | break //found - end search loop |
| 3856 | } |
| 3857 | } |
| 3858 | if pCurrentUniPort == nil { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3859 | logger.Debugw(ctx, "VerifyVlanConfig aborted: requested uniID not found in PortDB", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3860 | log.Fields{"device-id": dh.DeviceID, "uni-id": aUniID}) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3861 | return |
| 3862 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3863 | dh.VerifyUniVlanConfigRequest(ctx, pCurrentUniPort, aTpID) |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3864 | } |
| 3865 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3866 | // VerifyUniVlanConfigRequest checks on existence of flow configuration and starts it accordingly |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3867 | func (dh *deviceHandler) VerifyUniVlanConfigRequest(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8) { |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3868 | //TODO!! verify and start pending flow configuration |
| 3869 | //some pending config request my exist in case the UniVlanConfig FSM was already started - with internal data - |
| 3870 | //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] | 3871 | 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] | 3872 | dh.lockVlanConfig.RLock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3873 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3874 | dh.lockVlanConfig.RUnlock() |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3875 | //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] | 3876 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3877 | if pVlanFilterStatemachine != nil { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3878 | //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] | 3879 | if pVlanFilterFsm.GetWaitingTpID(ctx) == aTpID { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3880 | if pVlanFilterStatemachine.Is(avcfg.VlanStWaitingTechProf) { |
| 3881 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvContinueConfig); err != nil { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3882 | logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3883 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3884 | } else { |
| 3885 | /***** UniVlanConfigFsm continued */ |
| 3886 | logger.Debugw(ctx, "UniVlanConfigFsm continued", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3887 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3888 | "UniPort": apUniPort.PortNo}) |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3889 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3890 | } else if pVlanFilterStatemachine.Is(avcfg.VlanStIncrFlowWaitTP) { |
| 3891 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvIncrFlowConfig); err != nil { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3892 | logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err, |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3893 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3894 | } else { |
| 3895 | /***** UniVlanConfigFsm continued */ |
| 3896 | logger.Debugw(ctx, "UniVlanConfigFsm continued with incremental flow", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3897 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3898 | "UniPort": apUniPort.PortNo}) |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3899 | } |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3900 | } else { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3901 | logger.Debugw(ctx, "no state of UniVlanConfigFsm to be continued", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3902 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3903 | "UniPort": apUniPort.PortNo}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3904 | } |
| 3905 | } else { |
| mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3906 | 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] | 3907 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3908 | "UniPort": apUniPort.PortNo, "techprofile-id (done)": aTpID}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3909 | } |
| 3910 | } else { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3911 | 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] | 3912 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3913 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3914 | } else { |
| 3915 | dh.lockVlanConfig.RUnlock() |
| 3916 | } |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3917 | } |
| 3918 | |
| Akash Soni | 3de0e06 | 2024-12-11 16:37:26 +0530 | [diff] [blame] | 3919 | // handleAniConfigFSMFailure handles the failure of the ANI config FSM by resetting the VLAN filter FSM |
| 3920 | func (dh *deviceHandler) HandleAniConfigFSMFailure(ctx context.Context, uniID uint8) { |
| 3921 | dh.lockVlanConfig.Lock() |
| 3922 | defer dh.lockVlanConfig.Unlock() |
| 3923 | |
| 3924 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniID]; exist { |
| 3925 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
| 3926 | if pVlanFilterStatemachine != nil { |
| 3927 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvReset); err != nil { |
| 3928 | logger.Warnw(ctx, "Failed to reset UniVlanConfigFsm", log.Fields{ |
| 3929 | "err": err, "device-id": dh.DeviceID, "UniPort": uniID, "FsmState": pVlanFilterStatemachine.Current(), |
| 3930 | }) |
| 3931 | } else { |
| 3932 | logger.Infow(ctx, "Successfully reset UniVlanConfigFsm", log.Fields{ |
| 3933 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, "UniPort": uniID, |
| 3934 | }) |
| 3935 | } |
| 3936 | } else { |
| 3937 | logger.Debugw(ctx, "UniVlanConfigFsm StateMachine does not exist, no reset performed", log.Fields{ |
| 3938 | "device-id": dh.DeviceID, "UniPort": uniID, |
| 3939 | }) |
| 3940 | } |
| 3941 | } else { |
| 3942 | logger.Debugw(ctx, "No UniVlanConfigFsm found for the UNI ID", log.Fields{ |
| 3943 | "device-id": dh.DeviceID, "UniPort": uniID, |
| 3944 | }) |
| 3945 | } |
| 3946 | } |
| 3947 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3948 | // RemoveVlanFilterFsm deletes the stored pointer to the VlanConfigFsm |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3949 | // 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] | 3950 | func (dh *deviceHandler) RemoveVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort) { |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3951 | logger.Debugw(ctx, "remove UniVlanConfigFsm StateMachine", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3952 | "device-id": dh.DeviceID, "uniPort": apUniPort.PortNo}) |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3953 | //save to do, even if entry dows not exist |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3954 | dh.lockVlanConfig.Lock() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3955 | delete(dh.UniVlanConfigFsmMap, apUniPort.UniID) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3956 | dh.lockVlanConfig.Unlock() |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3957 | } |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3958 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3959 | // startWritingOnuDataToKvStore initiates the KVStore write of ONU persistent data |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3960 | func (dh *deviceHandler) startWritingOnuDataToKvStore(ctx context.Context, aPDevEntry *mib.OnuDeviceEntry) error { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3961 | dh.mutexKvStoreContext.Lock() //this write routine may (could) be called with the same context, |
| 3962 | defer dh.mutexKvStoreContext.Unlock() //this write routine may (could) be called with the same context, |
| 3963 | // obviously then parallel processing on the cancel must be avoided |
| 3964 | // deadline context to ensure completion of background routines waited for |
| 3965 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 3966 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 3967 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 3968 | defer cancel() // Ensure cancel is called to release resources |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3969 | |
| Akash Soni | 840f8d6 | 2024-12-11 19:37:06 +0530 | [diff] [blame] | 3970 | err := aPDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx)) |
| 3971 | if err != nil { |
| 3972 | logger.Errorw(ctx, "UpdateOnuKvStore-failed", log.Fields{"device-id": dh.DeviceID}) |
| 3973 | return err |
| 3974 | } |
| 3975 | return nil |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3976 | } |
| 3977 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 3978 | // StorePersUniFlowConfig updates local storage of OnuUniFlowConfig and writes it into kv-store afterwards to have it |
| 3979 | // available for potential reconcilement |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3980 | func (dh *deviceHandler) StorePersUniFlowConfig(ctx context.Context, aUniID uint8, |
| 3981 | aUniVlanFlowParams *[]cmn.UniVlanFlowParams, aWriteToKvStore bool) error { |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3982 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3983 | if dh.IsReconciling() { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 3984 | logger.Info(ctx, "reconciling - don't store persistent UniFlowConfig", log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3985 | return nil |
| 3986 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3987 | 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] | 3988 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3989 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3990 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3991 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 3992 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3993 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3994 | pDevEntry.UpdateOnuUniFlowConfig(aUniID, aUniVlanFlowParams) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3995 | |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3996 | if aWriteToKvStore { |
| 3997 | return dh.startWritingOnuDataToKvStore(ctx, pDevEntry) |
| 3998 | } |
| 3999 | return nil |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4000 | } |
| 4001 | |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 4002 | 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] | 4003 | defer cancel() //ensure termination of context (may be pro forma) |
| 4004 | wg.Wait() |
| dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 4005 | logger.Debugw(ctx, "WaitGroup processing completed", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4006 | "device-id": dh.DeviceID, "called from": aCallerIdent}) |
| Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 4007 | } |
| 4008 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 4009 | // ReasonUpdate set the internally store device reason and if requested in notifyCore updates this state in the core |
| 4010 | // |
| 4011 | // (renamed from previous deviceReasonUpdate to avoid confusing with the core function DeviceReasonUpdate) |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4012 | func (dh *deviceHandler) ReasonUpdate(ctx context.Context, deviceReason uint8, notifyCore bool) error { |
| 4013 | // acquire the deviceReason semaphore throughout this function including the possible update processing in core |
| 4014 | // in order to avoid reversion of the state sequence within core in case of quasi-parallel calls (eg. in multi UNI processing) |
| 4015 | dh.mutexDeviceReason.Lock() |
| 4016 | defer dh.mutexDeviceReason.Unlock() |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 4017 | if notifyCore { |
| Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 4018 | //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] | 4019 | if err := dh.updateDeviceReasonInCore(ctx, &ca.DeviceReason{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4020 | DeviceId: dh.DeviceID, |
| 4021 | Reason: cmn.DeviceReasonMap[deviceReason], |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4022 | }); err != nil { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4023 | logger.Errorf(ctx, "updating reason in core failed for: %s", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4024 | log.Fields{"device-id": dh.DeviceID, "error": err}, cmn.DeviceReasonMap[deviceReason]) |
| Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 4025 | return err |
| 4026 | } |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4027 | } else { |
| 4028 | 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] | 4029 | } |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4030 | dh.deviceReason = deviceReason |
| 4031 | logger.Infof(ctx, "reason update done for: %s - device-id: %s - with core update: %v", |
| 4032 | cmn.DeviceReasonMap[deviceReason], dh.DeviceID, notifyCore) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 4033 | return nil |
| 4034 | } |
| 4035 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4036 | func (dh *deviceHandler) StorePersistentData(ctx context.Context) error { |
| 4037 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 4038 | if pDevEntry == nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4039 | logger.Warnw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 4040 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
| Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 4041 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4042 | return dh.startWritingOnuDataToKvStore(ctx, pDevEntry) |
| Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 4043 | } |
| 4044 | |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 4045 | func (dh *deviceHandler) UpdateRebootPersData(ctx context.Context, flag bool) { |
| 4046 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 4047 | if pDevEntry != nil { |
| 4048 | pDevEntry.MutexPersOnuConfig.Lock() |
| 4049 | pDevEntry.SOnuPersistentData.PersRebootInProgress = flag |
| 4050 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 4051 | } else { |
| 4052 | logger.Errorw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 4053 | } |
| 4054 | } |
| 4055 | |
| 4056 | func (dh *deviceHandler) GetPersRebootFlag(ctx context.Context) bool { |
| 4057 | rebootFlag := false |
| 4058 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
| 4059 | if pDevEntry != nil { |
| 4060 | pDevEntry.MutexPersOnuConfig.RLock() |
| 4061 | rebootFlag = pDevEntry.SOnuPersistentData.PersRebootInProgress |
| 4062 | pDevEntry.MutexPersOnuConfig.RUnlock() |
| 4063 | } else { |
| 4064 | logger.Errorw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 4065 | } |
| 4066 | return rebootFlag |
| 4067 | } |
| 4068 | |
| ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 4069 | // 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] | 4070 | // nolint: unused |
| ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 4071 | func (dh *deviceHandler) getUniPortMEEntityID(uniPortNo uint32) (uint16, error) { |
| 4072 | dh.lockDevice.RLock() |
| 4073 | defer dh.lockDevice.RUnlock() |
| 4074 | if uniPort, ok := dh.uniEntityMap[uniPortNo]; ok { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4075 | return uniPort.EntityID, nil |
| ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 4076 | } |
| 4077 | return 0, errors.New("error-fetching-uni-port") |
| 4078 | } |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4079 | |
| 4080 | // updatePmConfig updates the pm metrics config. |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4081 | func (dh *deviceHandler) updatePmConfig(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 4082 | var errorsList []error |
| 4083 | 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] | 4084 | |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4085 | errorsList = append(dh.handleGlobalPmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 4086 | errorsList = append(dh.handleGroupPmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 4087 | errorsList = append(dh.handleStandalonePmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 4088 | |
| 4089 | // Note that if more than one pm config field is updated in a given call, it is possible that partial pm config is handled |
| 4090 | // successfully. |
| 4091 | // TODO: Although it is possible to revert to old config in case of partial failure, the code becomes quite complex. Needs more investigation |
| 4092 | // Is it possible the rw-core reverts to old config on partial failure but adapter retains a partial new config? |
| 4093 | if len(errorsList) > 0 { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4094 | 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] | 4095 | 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] | 4096 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4097 | 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] | 4098 | return nil |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4099 | } |
| 4100 | |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4101 | func (dh *deviceHandler) handleGlobalPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 4102 | var err error |
| 4103 | var errorsList []error |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4104 | 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] | 4105 | |
| 4106 | if pmConfigs.DefaultFreq != dh.pmConfigs.DefaultFreq { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4107 | if err = dh.pOnuMetricsMgr.UpdateDefaultFrequency(ctx, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4108 | errorsList = append(errorsList, err) |
| 4109 | } |
| 4110 | } |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4111 | 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] | 4112 | |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4113 | return errorsList |
| 4114 | } |
| 4115 | |
| 4116 | func (dh *deviceHandler) handleGroupPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 4117 | var err error |
| 4118 | var errorsList []error |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4119 | 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] | 4120 | // Check if group metric related config is updated |
| 4121 | for _, v := range pmConfigs.Groups { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4122 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() |
| 4123 | m, ok := dh.pOnuMetricsMgr.GroupMetricMap[v.GroupName] |
| 4124 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4125 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4126 | if ok && m.Frequency != v.GroupFreq { |
| 4127 | if err = dh.pOnuMetricsMgr.UpdateGroupFreq(ctx, v.GroupName, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4128 | errorsList = append(errorsList, err) |
| 4129 | } |
| 4130 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4131 | if ok && m.Enabled != v.Enabled { |
| 4132 | if err = dh.pOnuMetricsMgr.UpdateGroupSupport(ctx, v.GroupName, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4133 | errorsList = append(errorsList, err) |
| 4134 | } |
| 4135 | } |
| 4136 | } |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4137 | 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] | 4138 | return errorsList |
| 4139 | } |
| 4140 | |
| 4141 | func (dh *deviceHandler) handleStandalonePmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 4142 | var err error |
| 4143 | var errorsList []error |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4144 | 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] | 4145 | // Check if standalone metric related config is updated |
| 4146 | for _, v := range pmConfigs.Metrics { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4147 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() |
| 4148 | m, ok := dh.pOnuMetricsMgr.StandaloneMetricMap[v.Name] |
| 4149 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4150 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4151 | if ok && m.Frequency != v.SampleFreq { |
| 4152 | if err = dh.pOnuMetricsMgr.UpdateMetricFreq(ctx, v.Name, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4153 | errorsList = append(errorsList, err) |
| 4154 | } |
| 4155 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4156 | if ok && m.Enabled != v.Enabled { |
| 4157 | if err = dh.pOnuMetricsMgr.UpdateMetricSupport(ctx, v.Name, pmConfigs); err != nil { |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4158 | errorsList = append(errorsList, err) |
| 4159 | } |
| 4160 | } |
| 4161 | } |
| Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 4162 | 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] | 4163 | return errorsList |
| 4164 | } |
| 4165 | |
| 4166 | // nolint: gocyclo |
| Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 4167 | func (dh *deviceHandler) StartCollector(ctx context.Context, waitForOmciProcessor *sync.WaitGroup) { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4168 | logger.Debugw(ctx, "startingCollector", log.Fields{"device-id": dh.device.Id}) |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4169 | |
| 4170 | // Start routine to process OMCI GET Responses |
| Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 4171 | go dh.pOnuMetricsMgr.ProcessOmciMessages(ctx, waitForOmciProcessor) |
| Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 4172 | // Create Extended Frame PM ME |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4173 | go dh.pOnuMetricsMgr.CreateEthernetFrameExtendedPMME(ctx) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4174 | // Initialize the next metric collection time. |
| 4175 | // Normally done when the onu_metrics_manager is initialized the first time, but needed again later when ONU is |
| 4176 | // reset like onu rebooted. |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4177 | dh.pOnuMetricsMgr.InitializeMetricCollectionTime(ctx) |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4178 | dh.setCollectorIsRunning(true) |
| praneeth nalmas | 808f43a | 2023-05-14 12:54:34 +0530 | [diff] [blame] | 4179 | statsCollectionticker := time.NewTicker((pmmgr.FrequencyGranularity) * time.Second) |
| 4180 | defer statsCollectionticker.Stop() |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4181 | for { |
| praneeth nalmas | 808f43a | 2023-05-14 12:54:34 +0530 | [diff] [blame] | 4182 | |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4183 | select { |
| 4184 | case <-dh.stopCollector: |
| 4185 | 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] | 4186 | // Stop the L2 PM FSM |
| 4187 | go func() { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4188 | if dh.pOnuMetricsMgr.PAdaptFsm != nil && dh.pOnuMetricsMgr.PAdaptFsm.PFsm != nil { |
| 4189 | if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventStop); err != nil { |
| 4190 | 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] | 4191 | } |
| 4192 | } else { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4193 | 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] | 4194 | } |
| 4195 | }() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4196 | if dh.pOnuMetricsMgr.GetOmciProcessingStatus() { |
| 4197 | dh.pOnuMetricsMgr.StopProcessingOmciResponses <- true // Stop the OMCI GET response processing routine |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 4198 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4199 | if dh.pOnuMetricsMgr.GetTickGenerationStatus() { |
| 4200 | dh.pOnuMetricsMgr.StopTicks <- true |
| Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 4201 | } |
| Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 4202 | |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4203 | return |
| praneeth nalmas | 808f43a | 2023-05-14 12:54:34 +0530 | [diff] [blame] | 4204 | 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] | 4205 | if !dh.pmConfigs.FreqOverride { // If FreqOverride is false, then NextGlobalMetricCollectionTime applies |
| 4206 | // If the current time is eqaul to or greater than the NextGlobalMetricCollectionTime, collect the group and standalone metrics |
| 4207 | if time.Now().Equal(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) || time.Now().After(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) { |
| 4208 | go dh.pOnuMetricsMgr.CollectAllGroupAndStandaloneMetrics(ctx) |
| Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 4209 | // Update the next metric collection time. |
| Mahir Gunyel | e184e9f | 2024-09-18 00:12:19 -0700 | [diff] [blame] | 4210 | prevInternal := dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime |
| 4211 | dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime = prevInternal.Add(time.Duration(dh.pmConfigs.DefaultFreq) * time.Second) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4212 | } |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4213 | } else { |
| 4214 | if dh.pmConfigs.Grouped { // metrics are managed as a group |
| 4215 | // 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] | 4216 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() // Rlock as we are reading GroupMetricMap and StandaloneMetricMap |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4217 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4218 | for n, g := range dh.pOnuMetricsMgr.GroupMetricMap { |
| 4219 | // 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] | 4220 | // 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] | 4221 | if g.Enabled && !g.IsL2PMCounter && (time.Now().Equal(g.NextCollectionInterval) || time.Now().After(g.NextCollectionInterval)) { |
| 4222 | go dh.pOnuMetricsMgr.CollectGroupMetric(ctx, n) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4223 | } |
| 4224 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4225 | for n, m := range dh.pOnuMetricsMgr.StandaloneMetricMap { |
| 4226 | // If the standalone is enabled AND (current time is equal to OR after NextCollectionInterval, collect the metric) |
| 4227 | if m.Enabled && (time.Now().Equal(m.NextCollectionInterval) || time.Now().After(m.NextCollectionInterval)) { |
| 4228 | go dh.pOnuMetricsMgr.CollectStandaloneMetric(ctx, n) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4229 | } |
| 4230 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4231 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4232 | |
| 4233 | // parse through the group and update the next metric collection time |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4234 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.Lock() // Lock as we are writing the next metric collection time |
| 4235 | for _, g := range dh.pOnuMetricsMgr.GroupMetricMap { |
| 4236 | // 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] | 4237 | // 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] | 4238 | 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] | 4239 | prevInternal := g.NextCollectionInterval |
| 4240 | g.NextCollectionInterval = prevInternal.Add(time.Duration(g.Frequency) * time.Second) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4241 | } |
| 4242 | } |
| 4243 | // parse through the standalone metrics and update the next metric collection time |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4244 | for _, m := range dh.pOnuMetricsMgr.StandaloneMetricMap { |
| 4245 | // If standalone metrics enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp |
| 4246 | 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] | 4247 | prevInternal := m.NextCollectionInterval |
| 4248 | m.NextCollectionInterval = prevInternal.Add(time.Duration(m.Frequency) * time.Second) |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4249 | } |
| 4250 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4251 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.Unlock() |
| Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 4252 | } /* else { // metrics are not managed as a group |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4253 | // 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] | 4254 | } */ |
| 4255 | } |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 4256 | } |
| 4257 | } |
| 4258 | } |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 4259 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4260 | //nolint:unparam |
| Akash Soni | 3c176c6 | 2024-12-04 13:30:43 +0530 | [diff] [blame] | 4261 | func (dh *deviceHandler) setOnuOffloadStats(ctx context.Context, config *extension.AppOffloadOnuConfig) *extension.SingleSetValueResponse { |
| 4262 | |
| 4263 | singleValResp := extension.SingleSetValueResponse{ |
| 4264 | Response: &extension.SetValueResponse{ |
| 4265 | Status: extension.SetValueResponse_OK, |
| 4266 | }, |
| 4267 | } |
| 4268 | |
| 4269 | return &singleValResp |
| 4270 | } |
| 4271 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4272 | func (dh *deviceHandler) GetUniPortStatus(ctx context.Context, uniInfo *extension.GetOnuUniInfoRequest) *extension.SingleGetValueResponse { |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 4273 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4274 | portStatus := uniprt.NewUniPortStatus(dh, dh.pOnuOmciDevice.PDevOmciCC) |
| 4275 | return portStatus.GetUniPortStatus(ctx, uniInfo.UniIndex) |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 4276 | } |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4277 | |
| Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 4278 | func (dh *deviceHandler) getOnuOMCICounters(ctx context.Context, onuInfo *extension.GetOmciEthernetFrameExtendedPmRequest) *extension.SingleGetValueResponse { |
| 4279 | if dh.pOnuMetricsMgr == nil { |
| 4280 | return &extension.SingleGetValueResponse{ |
| 4281 | Response: &extension.GetValueResponse{ |
| 4282 | Status: extension.GetValueResponse_ERROR, |
| 4283 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 4284 | }, |
| 4285 | } |
| 4286 | } |
| Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 4287 | resp := dh.pOnuMetricsMgr.CollectEthernetFrameExtendedPMCounters(ctx, onuInfo) |
| Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 4288 | return resp |
| 4289 | } |
| 4290 | |
| Holger Hildebrandt | 66af5ce | 2022-09-07 13:38:02 +0000 | [diff] [blame] | 4291 | func (dh *deviceHandler) getOnuOMCIStats(ctx context.Context) (*extension.SingleGetValueResponse, error) { |
| 4292 | |
| 4293 | var err error |
| 4294 | var pDevOmciCC *cmn.OmciCC |
| 4295 | if dh.pOnuOmciDevice == nil { |
| 4296 | logger.Errorw(ctx, "No valid DeviceEntry", log.Fields{"device-id": dh.DeviceID}) |
| 4297 | err = fmt.Errorf("no-valid-DeviceEntry-%s", dh.DeviceID) |
| 4298 | } else { |
| 4299 | pDevOmciCC = dh.pOnuOmciDevice.GetDevOmciCC() |
| 4300 | if pDevOmciCC == nil { |
| 4301 | logger.Errorw(ctx, "No valid DeviceOmciCCEntry", log.Fields{"device-id": dh.DeviceID}) |
| 4302 | err = fmt.Errorf("no-valid-DeviceOmciCCEntry-%s", dh.DeviceID) |
| 4303 | } |
| 4304 | } |
| 4305 | if err != nil { |
| 4306 | return &extension.SingleGetValueResponse{ |
| 4307 | Response: &extension.GetValueResponse{ |
| 4308 | Status: extension.GetValueResponse_ERROR, |
| 4309 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 4310 | }, |
| 4311 | }, |
| 4312 | err |
| 4313 | } |
| 4314 | return pDevOmciCC.GetOmciCounters(), nil |
| 4315 | } |
| 4316 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4317 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4318 | func (dh *deviceHandler) isFsmInOmciIdleState(ctx context.Context, PFsm *fsm.FSM, wantedState string) bool { |
| 4319 | if PFsm == nil { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4320 | return true //FSM not active - so there is no activity on omci |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4321 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4322 | return PFsm.Current() == wantedState |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4323 | } |
| 4324 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4325 | func (dh *deviceHandler) isFsmInOmciIdleStateDefault(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, wantedState string) bool { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4326 | var pAdapterFsm *cmn.AdapterFsm |
| 4327 | //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] | 4328 | switch omciFsm { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4329 | case cmn.CUploadFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4330 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4331 | if dh.pOnuOmciDevice != nil { |
| 4332 | pAdapterFsm = dh.pOnuOmciDevice.PMibUploadFsm |
| 4333 | } else { |
| 4334 | return true //FSM not active - so there is no activity on omci |
| 4335 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4336 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4337 | case cmn.CDownloadFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4338 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4339 | if dh.pOnuOmciDevice != nil { |
| 4340 | pAdapterFsm = dh.pOnuOmciDevice.PMibDownloadFsm |
| 4341 | } else { |
| 4342 | return true //FSM not active - so there is no activity on omci |
| 4343 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4344 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4345 | case cmn.CUniLockFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4346 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4347 | if dh.pLockStateFsm != nil { |
| 4348 | pAdapterFsm = dh.pLockStateFsm.PAdaptFsm |
| 4349 | } else { |
| 4350 | return true //FSM not active - so there is no activity on omci |
| 4351 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4352 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4353 | case cmn.CUniUnLockFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4354 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4355 | if dh.pUnlockStateFsm != nil { |
| 4356 | pAdapterFsm = dh.pUnlockStateFsm.PAdaptFsm |
| 4357 | } else { |
| 4358 | return true //FSM not active - so there is no activity on omci |
| 4359 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4360 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4361 | case cmn.CL2PmFsm: |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4362 | { |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4363 | if dh.pOnuMetricsMgr != nil { |
| 4364 | pAdapterFsm = dh.pOnuMetricsMgr.PAdaptFsm |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4365 | } else { |
| 4366 | return true //FSM not active - so there is no activity on omci |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4367 | } |
| 4368 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4369 | case cmn.COnuUpgradeFsm: |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 4370 | { |
| 4371 | dh.lockUpgradeFsm.RLock() |
| 4372 | defer dh.lockUpgradeFsm.RUnlock() |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4373 | if dh.pOnuUpradeFsm != nil { |
| 4374 | pAdapterFsm = dh.pOnuUpradeFsm.PAdaptFsm |
| 4375 | } else { |
| 4376 | return true //FSM not active - so there is no activity on omci |
| 4377 | } |
| mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 4378 | } |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4379 | default: |
| 4380 | { |
| 4381 | logger.Errorw(ctx, "invalid stateMachine selected for idle check", log.Fields{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4382 | "device-id": dh.DeviceID, "selectedFsm number": omciFsm}) |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4383 | 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] | 4384 | } |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4385 | } |
| mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 4386 | if pAdapterFsm != nil && pAdapterFsm.PFsm != nil { |
| 4387 | return dh.isFsmInOmciIdleState(ctx, pAdapterFsm.PFsm, wantedState) |
| 4388 | } |
| 4389 | return true //FSM not active - so there is no activity on omci |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4390 | } |
| 4391 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4392 | func (dh *deviceHandler) isAniConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool { |
| 4393 | for _, v := range dh.pOnuTP.PAniConfigFsm { |
| 4394 | if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) { |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4395 | return false |
| 4396 | } |
| 4397 | } |
| 4398 | return true |
| 4399 | } |
| 4400 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4401 | //nolint:unparam |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4402 | func (dh *deviceHandler) isUniVlanConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4403 | dh.lockVlanConfig.RLock() |
| 4404 | defer dh.lockVlanConfig.RUnlock() |
| 4405 | for _, v := range dh.UniVlanConfigFsmMap { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4406 | if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4407 | return false |
| 4408 | } |
| 4409 | } |
| 4410 | return true //FSM not active - so there is no activity on omci |
| 4411 | } |
| 4412 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4413 | //nolint:unparam |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4414 | func (dh *deviceHandler) checkUserServiceExists(ctx context.Context) bool { |
| 4415 | dh.lockVlanConfig.RLock() |
| 4416 | defer dh.lockVlanConfig.RUnlock() |
| 4417 | for _, v := range dh.UniVlanConfigFsmMap { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4418 | if v.PAdaptFsm.PFsm != nil { |
| 4419 | if v.PAdaptFsm.PFsm.Is(avcfg.CVlanFsmConfiguredState) { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4420 | return true //there is at least one VLAN FSM with some active configuration |
| 4421 | } |
| 4422 | } |
| 4423 | } |
| 4424 | return false //there is no VLAN FSM with some active configuration |
| 4425 | } |
| 4426 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4427 | func (dh *deviceHandler) CheckAuditStartCondition(ctx context.Context, callingFsm cmn.UsedOmciConfigFsms) bool { |
| mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 4428 | for fsmName, fsmStruct := range fsmOmciIdleStateFuncMap { |
| 4429 | if fsmName != callingFsm && !fsmStruct.omciIdleCheckFunc(dh, ctx, fsmName, fsmStruct.omciIdleState) { |
| 4430 | return false |
| 4431 | } |
| 4432 | } |
| 4433 | // a further check is done to identify, if at least some data traffic related configuration exists |
| 4434 | // 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]) |
| 4435 | return dh.checkUserServiceExists(ctx) |
| 4436 | } |
| 4437 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4438 | func (dh *deviceHandler) PrepareReconcilingWithActiveAdapter(ctx context.Context) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4439 | 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] | 4440 | if err := dh.resetFsms(ctx, false); err != nil { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4441 | 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] | 4442 | // TODO: fatal error reset ONU, delete deviceHandler! |
| 4443 | return |
| 4444 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4445 | dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort) |
| 4446 | dh.StartReconciling(ctx, false) |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | func (dh *deviceHandler) setCollectorIsRunning(flagValue bool) { |
| 4450 | dh.mutexCollectorFlag.Lock() |
| 4451 | dh.collectorIsRunning = flagValue |
| 4452 | dh.mutexCollectorFlag.Unlock() |
| 4453 | } |
| 4454 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4455 | func (dh *deviceHandler) GetCollectorIsRunning() bool { |
| Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 4456 | dh.mutexCollectorFlag.RLock() |
| 4457 | flagValue := dh.collectorIsRunning |
| 4458 | dh.mutexCollectorFlag.RUnlock() |
| 4459 | return flagValue |
| 4460 | } |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 4461 | |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 4462 | func (dh *deviceHandler) setAlarmManagerIsRunning(flagValue bool) { |
| 4463 | dh.mutextAlarmManagerFlag.Lock() |
| 4464 | dh.alarmManagerIsRunning = flagValue |
| 4465 | dh.mutextAlarmManagerFlag.Unlock() |
| 4466 | } |
| 4467 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4468 | func (dh *deviceHandler) GetAlarmManagerIsRunning(ctx context.Context) bool { |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 4469 | dh.mutextAlarmManagerFlag.RLock() |
| 4470 | flagValue := dh.alarmManagerIsRunning |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4471 | 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] | 4472 | dh.mutextAlarmManagerFlag.RUnlock() |
| 4473 | return flagValue |
| 4474 | } |
| 4475 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4476 | func (dh *deviceHandler) StartAlarmManager(ctx context.Context) { |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4477 | logger.Debugw(ctx, "startingAlarmManager", log.Fields{"device-id": dh.device.Id}) |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 4478 | |
| 4479 | // Start routine to process OMCI GET Responses |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4480 | go dh.pAlarmMgr.StartOMCIAlarmMessageProcessing(ctx) |
| Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 4481 | dh.setAlarmManagerIsRunning(true) |
| Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 4482 | if stop := <-dh.stopAlarmManager; stop { |
| Sridhar Ravindra | f1331ad | 2024-02-15 16:13:37 +0530 | [diff] [blame] | 4483 | 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] | 4484 | go func() { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4485 | if dh.pAlarmMgr.AlarmSyncFsm != nil && dh.pAlarmMgr.AlarmSyncFsm.PFsm != nil { |
| 4486 | _ = dh.pAlarmMgr.AlarmSyncFsm.PFsm.Event(almgr.AsEvStop) |
| Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 4487 | } |
| Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 4488 | }() |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4489 | dh.pAlarmMgr.StopProcessingOmciMessages <- true // Stop the OMCI routines if any(This will stop the fsms also) |
| 4490 | dh.pAlarmMgr.StopAlarmAuditTimer <- struct{}{} |
| Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 4491 | 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] | 4492 | } |
| 4493 | } |
| Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 4494 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4495 | func (dh *deviceHandler) setFlowMonitoringIsRunning(uniID uint8, flag bool) { |
| 4496 | dh.mutexFlowMonitoringRoutineFlag.Lock() |
| 4497 | defer dh.mutexFlowMonitoringRoutineFlag.Unlock() |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4498 | 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] | 4499 | dh.isFlowMonitoringRoutineActive[uniID] = flag |
| 4500 | } |
| 4501 | |
| 4502 | func (dh *deviceHandler) GetFlowMonitoringIsRunning(uniID uint8) bool { |
| 4503 | dh.mutexFlowMonitoringRoutineFlag.RLock() |
| 4504 | defer dh.mutexFlowMonitoringRoutineFlag.RUnlock() |
| 4505 | logger.Debugw(context.Background(), "get-flow-monitoring-routine", |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4506 | log.Fields{"device-id": dh.device.Id, "isFlowMonitoringRoutineActive": dh.isFlowMonitoringRoutineActive}) |
| Sridhar Ravindra | e9a8bcc | 2024-12-06 10:40:54 +0530 | [diff] [blame] | 4507 | if len(dh.isFlowMonitoringRoutineActive) != 0 { |
| 4508 | return dh.isFlowMonitoringRoutineActive[uniID] |
| 4509 | } |
| 4510 | return false |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4511 | } |
| 4512 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4513 | func (dh *deviceHandler) StartReconciling(ctx context.Context, skipOnuConfig bool) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4514 | 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] | 4515 | |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4516 | connectStatus := voltha.ConnectStatus_UNREACHABLE |
| 4517 | operState := voltha.OperStatus_UNKNOWN |
| 4518 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4519 | if !dh.IsReconciling() { |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4520 | go func() { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4521 | logger.Debugw(ctx, "wait for channel signal or timeout", |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4522 | log.Fields{"timeout": dh.reconcileExpiryComplete, "device-id": dh.DeviceID}) |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4523 | select { |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4524 | case success := <-dh.chReconcilingFinished: |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4525 | logger.Info(ctx, "reconciling finished signal received", |
| Holger Hildebrandt | f745925 | 2022-01-03 16:10:37 +0000 | [diff] [blame] | 4526 | log.Fields{"device-id": dh.DeviceID, "dh.chReconcilingFinished": dh.chReconcilingFinished}) |
| 4527 | // To guarantee that the case-branch below is completely processed before reconciling processing is continued, |
| 4528 | // dh.mutexReconcilingFlag is locked already here. Thereby it is ensured, that further reconciling processing is stopped |
| 4529 | // at next call of dh.IsReconciling() until dh.reconciling is set after informing core about finished reconciling below. |
| 4530 | // This change addresses a problem described in VOL-4533 where the flag dh.reconciling not yet reset causes the uni ports |
| 4531 | // not to be created in ONOS in function dh.addUniPort(), when reconciling was started in reason "starting-openomci". |
| 4532 | // TODO: Keeping the mutex beyond an RPC towards core seems justifiable, as the effects here are easily overseeable. |
| 4533 | // However, a later refactoring of the functionality remains unaffected. |
| 4534 | dh.mutexReconcilingFlag.Lock() |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4535 | if success { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4536 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4537 | logger.Errorw(ctx, "No valid OnuDevice - aborting Core DeviceStateUpdate", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4538 | log.Fields{"device-id": dh.DeviceID}) |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4539 | } else { |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4540 | onuDevEntry.MutexPersOnuConfig.RLock() |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 4541 | switch onuDevEntry.SOnuPersistentData.PersOperState { |
| 4542 | case "up": |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4543 | connectStatus = voltha.ConnectStatus_REACHABLE |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4544 | if !onuDevEntry.SOnuPersistentData.PersUniDisableDone { |
| 4545 | if onuDevEntry.SOnuPersistentData.PersUniUnlockDone { |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4546 | operState = voltha.OperStatus_ACTIVE |
| 4547 | } else { |
| 4548 | operState = voltha.OperStatus_ACTIVATING |
| 4549 | } |
| 4550 | } |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 4551 | case "down", "unknown", "": |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4552 | operState = voltha.OperStatus_DISCOVERED |
| 4553 | } |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4554 | onuDevEntry.MutexPersOnuConfig.RUnlock() |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4555 | logger.Debugw(ctx, "Core DeviceStateUpdate", |
| 4556 | log.Fields{"device-id": dh.device.Id, "connectStatus": connectStatus, "operState": operState}) |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4557 | } |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4558 | logger.Info(ctx, "reconciling has been finished in time", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4559 | log.Fields{"device-id": dh.DeviceID}) |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4560 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4561 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4562 | ConnStatus: connectStatus, |
| 4563 | OperStatus: operState, |
| 4564 | }); err != nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4565 | logger.Errorw(ctx, "unable to update device state to core", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4566 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4567 | } |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4568 | } else { |
| Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4569 | logger.Errorw(ctx, "wait for reconciling aborted", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4570 | log.Fields{"device-id": dh.DeviceID}) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4571 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4572 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4573 | logger.Errorw(ctx, "No valid OnuDevice", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4574 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4575 | } else { |
| 4576 | onuDevEntry.MutexPersOnuConfig.RLock() |
| 4577 | if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
| 4578 | connectStatus = voltha.ConnectStatus_REACHABLE |
| 4579 | } |
| 4580 | onuDevEntry.MutexPersOnuConfig.RUnlock() |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4581 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4582 | dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileCanceled, connectStatus) |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4583 | } |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4584 | case <-time.After(dh.reconcileExpiryComplete): |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4585 | logger.Errorw(ctx, "timeout waiting for reconciling to be finished!", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4586 | log.Fields{"device-id": dh.DeviceID}) |
| Holger Hildebrandt | f745925 | 2022-01-03 16:10:37 +0000 | [diff] [blame] | 4587 | dh.mutexReconcilingFlag.Lock() |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4588 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4589 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4590 | logger.Errorw(ctx, "No valid OnuDevice", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4591 | log.Fields{"device-id": dh.DeviceID}) |
| mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4592 | } else { |
| 4593 | onuDevEntry.MutexPersOnuConfig.RLock() |
| 4594 | if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
| 4595 | connectStatus = voltha.ConnectStatus_REACHABLE |
| 4596 | } |
| 4597 | onuDevEntry.MutexPersOnuConfig.RUnlock() |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4598 | } |
| 4599 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4600 | dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileMaxTimeout, connectStatus) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4601 | |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4602 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4603 | dh.reconciling = cNoReconciling |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4604 | dh.mutexReconcilingFlag.Unlock() |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4605 | dh.SetReconcilingReasonUpdate(false) |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 4606 | dh.SetReconcilingFirstPass(true) |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4607 | |
| 4608 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
| 4609 | logger.Errorw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 4610 | } else { |
| 4611 | onuDevEntry.MutexReconciledTpInstances.Lock() |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 4612 | onuDevEntry.ReconciledTpInstances = make(map[uint8]map[uint8]ia.TechProfileDownloadMessage) |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4613 | onuDevEntry.MutexReconciledTpInstances.Unlock() |
| 4614 | } |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4615 | }() |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4616 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4617 | dh.mutexReconcilingFlag.Lock() |
| Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 4618 | if skipOnuConfig || dh.GetSkipOnuConfigEnabled() { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4619 | dh.reconciling = cSkipOnuConfigReconciling |
| 4620 | } else { |
| 4621 | dh.reconciling = cOnuConfigReconciling |
| 4622 | } |
| 4623 | dh.mutexReconcilingFlag.Unlock() |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4624 | } |
| 4625 | |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4626 | func (dh *deviceHandler) stopReconciling(ctx context.Context, success bool, reconcileFlowResult uint16) { |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4627 | 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] | 4628 | if dh.IsReconciling() { |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4629 | dh.sendChReconcileFinished(success) |
| 4630 | if reconcileFlowResult != cWaitReconcileFlowNoActivity { |
| 4631 | dh.SendChUniVlanConfigFinished(reconcileFlowResult) |
| 4632 | } |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4633 | } else { |
| mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4634 | 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] | 4635 | } |
| 4636 | } |
| 4637 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4638 | func (dh *deviceHandler) IsReconciling() bool { |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4639 | dh.mutexReconcilingFlag.RLock() |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4640 | defer dh.mutexReconcilingFlag.RUnlock() |
| 4641 | return dh.reconciling != cNoReconciling |
| 4642 | } |
| 4643 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4644 | func (dh *deviceHandler) IsSkipOnuConfigReconciling() bool { |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4645 | dh.mutexReconcilingFlag.RLock() |
| 4646 | defer dh.mutexReconcilingFlag.RUnlock() |
| 4647 | return dh.reconciling == cSkipOnuConfigReconciling |
| 4648 | } |
| 4649 | |
| Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 4650 | func (dh *deviceHandler) SetReconcilingFirstPass(value bool) { |
| 4651 | dh.mutexReconcilingFirstPassFlag.Lock() |
| 4652 | dh.reconcilingFirstPass = value |
| 4653 | dh.mutexReconcilingFirstPassFlag.Unlock() |
| 4654 | } |
| 4655 | |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4656 | func (dh *deviceHandler) SetReconcilingReasonUpdate(value bool) { |
| 4657 | dh.mutexReconcilingReasonUpdate.Lock() |
| 4658 | dh.reconcilingReasonUpdate = value |
| 4659 | dh.mutexReconcilingReasonUpdate.Unlock() |
| 4660 | } |
| 4661 | |
| 4662 | func (dh *deviceHandler) IsReconcilingReasonUpdate() bool { |
| 4663 | dh.mutexReconcilingReasonUpdate.RLock() |
| 4664 | defer dh.mutexReconcilingReasonUpdate.RUnlock() |
| 4665 | return dh.reconcilingReasonUpdate |
| 4666 | } |
| 4667 | |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4668 | func (dh *deviceHandler) getDeviceReason() uint8 { |
| 4669 | dh.mutexDeviceReason.RLock() |
| 4670 | value := dh.deviceReason |
| 4671 | dh.mutexDeviceReason.RUnlock() |
| Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4672 | return value |
| 4673 | } |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4674 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4675 | func (dh *deviceHandler) GetDeviceReasonString() string { |
| 4676 | return cmn.DeviceReasonMap[dh.getDeviceReason()] |
| Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4677 | } |
| Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4678 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4679 | func (dh *deviceHandler) SetReadyForOmciConfig(flagValue bool) { |
| Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 4680 | dh.mutexReadyForOmciConfig.Lock() |
| 4681 | dh.readyForOmciConfig = flagValue |
| 4682 | dh.mutexReadyForOmciConfig.Unlock() |
| 4683 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4684 | func (dh *deviceHandler) IsReadyForOmciConfig() bool { |
| Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 4685 | dh.mutexReadyForOmciConfig.RLock() |
| 4686 | flagValue := dh.readyForOmciConfig |
| 4687 | dh.mutexReadyForOmciConfig.RUnlock() |
| 4688 | return flagValue |
| 4689 | } |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4690 | |
| 4691 | func (dh *deviceHandler) deviceReconcileFailedUpdate(ctx context.Context, deviceReason uint8, connectStatus voltha.ConnectStatus_Types) { |
| mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4692 | if err := dh.ReasonUpdate(ctx, deviceReason, true); err != nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4693 | logger.Errorw(ctx, "unable to update device reason to core", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4694 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4695 | } |
| 4696 | |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4697 | logger.Debugw(ctx, "Core DeviceStateUpdate", |
| 4698 | 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] | 4699 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4700 | DeviceId: dh.DeviceID, |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4701 | ConnStatus: connectStatus, |
| 4702 | OperStatus: voltha.OperStatus_RECONCILING_FAILED, |
| 4703 | }); err != nil { |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4704 | logger.Errorw(ctx, "unable to update device state to core", |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4705 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
| Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4706 | } |
| 4707 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4708 | |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 4709 | func (dh *deviceHandler) deviceRebootStateUpdate(ctx context.Context, techProfInstLoadFailed bool) { |
| 4710 | if techProfInstLoadFailed { |
| 4711 | if err := dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadFailed, true); err != nil { |
| 4712 | logger.Errorw(ctx, "unable to update device reason to core", |
| 4713 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
| 4714 | } |
| 4715 | context := make(map[string]string) |
| 4716 | context["device-id"] = dh.DeviceID |
| 4717 | context["onu-serial-number"] = dh.device.SerialNumber |
| 4718 | context["parent-id"] = dh.parentID |
| 4719 | |
| 4720 | // Send event on flow configuration failure so that corrective action can be triggered from NB |
| 4721 | deviceEvent := &voltha.DeviceEvent{ |
| 4722 | ResourceId: dh.DeviceID, |
| 4723 | DeviceEventName: cmn.OnuFlowConfigFailed, |
| 4724 | Description: cmn.OnuFlowConfigFailedDesc, |
| 4725 | Context: context, |
| 4726 | } |
| 4727 | logger.Debugw(ctx, "send device event", log.Fields{"deviceEvent": deviceEvent, "device-id": dh.DeviceID}) |
| 4728 | _ = dh.EventProxy.SendDeviceEvent(ctx, deviceEvent, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, time.Now().Unix()) |
| 4729 | } |
| 4730 | } |
| 4731 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4732 | /* |
| 4733 | Helper functions to communicate with Core |
| 4734 | */ |
| 4735 | |
| 4736 | func (dh *deviceHandler) getDeviceFromCore(ctx context.Context, deviceID string) (*voltha.Device, error) { |
| 4737 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4738 | if err != nil || cClient == nil { |
| 4739 | return nil, err |
| 4740 | } |
| 4741 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4742 | defer cancel() |
| 4743 | logger.Debugw(subCtx, "get-device-from-core", log.Fields{"device-id": deviceID}) |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 4744 | return cClient.GetDevice(subCtx, &common.ID{Id: deviceID}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4745 | } |
| 4746 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4747 | func (dh *deviceHandler) updateDeviceStateInCore(ctx context.Context, deviceStateFilter *ca.DeviceStateFilter) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4748 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4749 | if err != nil || cClient == nil { |
| 4750 | return err |
| 4751 | } |
| 4752 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4753 | defer cancel() |
| 4754 | _, err = cClient.DeviceStateUpdate(subCtx, deviceStateFilter) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4755 | logger.Debugw(subCtx, "device-updated-in-core", |
| 4756 | log.Fields{"device-id": dh.device.Id, "device-state": deviceStateFilter, "error": err}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4757 | return err |
| 4758 | } |
| 4759 | |
| 4760 | func (dh *deviceHandler) updatePMConfigInCore(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 4761 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4762 | if err != nil || cClient == nil { |
| 4763 | return err |
| 4764 | } |
| 4765 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4766 | defer cancel() |
| 4767 | _, err = cClient.DevicePMConfigUpdate(subCtx, pmConfigs) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4768 | logger.Debugw(subCtx, "pmconfig-updated-in-core", |
| 4769 | log.Fields{"device-id": dh.device.Id, "pm-configs": pmConfigs, "error": err}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4770 | return err |
| 4771 | } |
| 4772 | |
| 4773 | func (dh *deviceHandler) updateDeviceInCore(ctx context.Context, device *voltha.Device) error { |
| 4774 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4775 | if err != nil || cClient == nil { |
| 4776 | return err |
| 4777 | } |
| 4778 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4779 | defer cancel() |
| 4780 | _, err = cClient.DeviceUpdate(subCtx, device) |
| 4781 | logger.Debugw(subCtx, "device-updated-in-core", log.Fields{"device-id": device.Id, "error": err}) |
| 4782 | return err |
| 4783 | } |
| 4784 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4785 | func (dh *deviceHandler) CreatePortInCore(ctx context.Context, port *voltha.Port) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4786 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4787 | if err != nil || cClient == nil { |
| 4788 | return err |
| 4789 | } |
| 4790 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4791 | defer cancel() |
| 4792 | _, err = cClient.PortCreated(subCtx, port) |
| 4793 | logger.Debugw(subCtx, "port-created-in-core", log.Fields{"port": port, "error": err}) |
| 4794 | return err |
| 4795 | } |
| 4796 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4797 | func (dh *deviceHandler) updatePortStateInCore(ctx context.Context, portState *ca.PortState) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4798 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4799 | if err != nil || cClient == nil { |
| 4800 | return err |
| 4801 | } |
| 4802 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4803 | defer cancel() |
| 4804 | _, err = cClient.PortStateUpdate(subCtx, portState) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4805 | 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] | 4806 | return err |
| 4807 | } |
| 4808 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4809 | func (dh *deviceHandler) updateDeviceReasonInCore(ctx context.Context, reason *ca.DeviceReason) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4810 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4811 | if err != nil || cClient == nil { |
| 4812 | return err |
| 4813 | } |
| 4814 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4815 | defer cancel() |
| 4816 | _, err = cClient.DeviceReasonUpdate(subCtx, reason) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4817 | 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] | 4818 | return err |
| 4819 | } |
| 4820 | |
| 4821 | /* |
| 4822 | Helper functions to communicate with parent adapter |
| 4823 | */ |
| 4824 | |
| Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4825 | func (dh *deviceHandler) GetTechProfileInstanceFromParentAdapter(ctx context.Context, aUniID uint8, |
| 4826 | aTpPath string) (*ia.TechProfileDownloadMessage, error) { |
| 4827 | |
| 4828 | var request = ia.TechProfileInstanceRequestMessage{ |
| 4829 | DeviceId: dh.DeviceID, |
| 4830 | TpInstancePath: aTpPath, |
| 4831 | ParentDeviceId: dh.parentID, |
| 4832 | ParentPonPort: dh.device.ParentPortNo, |
| 4833 | OnuId: dh.device.ProxyAddress.OnuId, |
| 4834 | UniId: uint32(aUniID), |
| 4835 | } |
| 4836 | |
| 4837 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(dh.device.ProxyAddress.AdapterEndpoint) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4838 | if err != nil || pgClient == nil { |
| 4839 | return nil, err |
| 4840 | } |
| 4841 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 4842 | defer cancel() |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4843 | logger.Debugw(subCtx, "get-tech-profile-instance", |
| 4844 | 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] | 4845 | return pgClient.GetTechProfileInstance(subCtx, &request) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4846 | } |
| 4847 | |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4848 | // This routine is unique per ONU ID and blocks on flowControlBlock channel for incoming flows |
| 4849 | // Each incoming flow is processed in a synchronous manner, i.e., the flow is processed to completion before picking another |
| 4850 | func (dh *deviceHandler) PerOnuFlowHandlerRoutine(uniID uint8) { |
| 4851 | logger.Infow(context.Background(), "starting-flow-handler-routine", log.Fields{"device-id": dh.DeviceID}) |
| 4852 | dh.setFlowMonitoringIsRunning(uniID, true) |
| 4853 | for { |
| 4854 | select { |
| 4855 | // block on the channel to receive an incoming flow |
| 4856 | // process the flow completely before proceeding to handle the next flow |
| 4857 | case flowCb := <-dh.flowCbChan[uniID]: |
| 4858 | startTime := time.Now() |
| nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 4859 | 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] | 4860 | respChan := make(chan error) |
| 4861 | if flowCb.addFlow { |
| 4862 | go dh.addFlowItemToUniPort(flowCb.ctx, flowCb.flowItem, flowCb.uniPort, flowCb.flowMetaData, &respChan) |
| 4863 | } else { |
| 4864 | go dh.removeFlowItemFromUniPort(flowCb.ctx, flowCb.flowItem, flowCb.uniPort, &respChan) |
| 4865 | } |
| 4866 | // Block on response and tunnel it back to the caller |
| balaji.nagarajan | 62ac62b | 2025-09-08 10:49:58 +0530 | [diff] [blame] | 4867 | select { |
| 4868 | |
| 4869 | case msg := <-respChan: |
| 4870 | *flowCb.respChan <- msg |
| 4871 | // response sent successfully |
| 4872 | logger.Info(flowCb.ctx, "serial-flow-processor--end", |
| 4873 | log.Fields{"device-id": dh.DeviceID, "absoluteTimeForFlowProcessingInSecs": time.Since(startTime).Seconds()}) |
| 4874 | case <-flowCb.ctx.Done(): |
| 4875 | logger.Info(flowCb.ctx, "flow handler context cancelled or timed out", log.Fields{"device-id": dh.DeviceID}) |
| 4876 | // Optionally, you can handle cleanup or logging here |
| 4877 | if dh.UniVlanConfigFsmMap[flowCb.uniPort.UniID] != nil && dh.UniVlanConfigFsmMap[flowCb.uniPort.UniID].PAdaptFsm != nil { |
| 4878 | pVlanFilterStatemachine := dh.UniVlanConfigFsmMap[flowCb.uniPort.UniID].PAdaptFsm.PFsm |
| 4879 | if pVlanFilterStatemachine != nil { |
| 4880 | |
| 4881 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvReset); err != nil { |
| 4882 | logger.Warnw(flowCb.ctx, "UniVlanConfigFsm: can't reset", |
| 4883 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 4884 | |
| 4885 | } |
| 4886 | |
| 4887 | } |
| 4888 | } |
| 4889 | |
| 4890 | ctx2 := context.Background() |
| 4891 | metadata := flow.GetMetadataFromWriteMetadataAction(ctx2, flowCb.flowItem) |
| 4892 | if metadata == 0 { |
| 4893 | logger.Warnw(flowCb.ctx, "AniConfigFsm: can't reset,failed to fetch metadata flow: %v", |
| 4894 | log.Fields{"device-id": dh.DeviceID, "flows": flowCb.flowItem}) |
| 4895 | continue |
| 4896 | } |
| 4897 | TpID := flow.GetTechProfileIDFromWriteMetaData(ctx2, metadata) |
| 4898 | |
| 4899 | if TpID == uint16(0) { |
| 4900 | logger.Warnw(flowCb.ctx, "AniConfigFsm: can't reset,failed to fetch techprofileid flow: %v", |
| 4901 | log.Fields{"device-id": dh.DeviceID, "flows": flowCb.flowItem}) |
| 4902 | continue |
| 4903 | } |
| 4904 | if dh.pOnuTP != nil { |
| 4905 | // should always be the case here |
| 4906 | // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting |
| 4907 | if dh.pOnuTP.PAniConfigFsm != nil { |
| 4908 | uniTP := avcfg.UniTP{ |
| 4909 | UniID: flowCb.uniPort.UniID, |
| 4910 | TpID: uint8(TpID), |
| 4911 | } |
| 4912 | if dh.pOnuTP.PAniConfigFsm[uniTP] != nil { |
| 4913 | dh.pOnuTP.PAniConfigFsm[uniTP].CancelProcessing(context.Background()) |
| 4914 | } |
| 4915 | } |
| 4916 | } |
| 4917 | |
| 4918 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4919 | case <-dh.stopFlowMonitoringRoutine[uniID]: |
| 4920 | logger.Infow(context.Background(), "stopping-flow-handler-routine", log.Fields{"device-id": dh.DeviceID}) |
| 4921 | dh.setFlowMonitoringIsRunning(uniID, false) |
| 4922 | return |
| 4923 | } |
| 4924 | } |
| 4925 | } |
| 4926 | |
| kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 4927 | func (dh *deviceHandler) SendOnuSwSectionsOfWindow(ctx context.Context, parentEndpoint string, request *ia.OmciMessages) error { |
| 4928 | request.ParentDeviceId = dh.GetProxyAddressID() |
| 4929 | request.ChildDeviceId = dh.DeviceID |
| 4930 | request.ProxyAddress = dh.GetProxyAddress() |
| 4931 | request.ConnectStatus = common.ConnectStatus_REACHABLE |
| 4932 | |
| 4933 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint) |
| 4934 | if err != nil || pgClient == nil { |
| 4935 | return err |
| 4936 | } |
| 4937 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 4938 | defer cancel() |
| 4939 | logger.Debugw(subCtx, "send-omci-request", log.Fields{"request": request, "parent-endpoint": parentEndpoint}) |
| 4940 | _, err = pgClient.ProxyOmciRequests(subCtx, request) |
| 4941 | if err != nil { |
| Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 4942 | logger.Errorw(ctx, "omci-failure", log.Fields{"device-id": dh.device.Id, "request": request, "error": err, |
| 4943 | "request-parent": request.ParentDeviceId, "request-child": request.ChildDeviceId, "request-proxy": request.ProxyAddress}) |
| kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 4944 | } |
| 4945 | return err |
| 4946 | } |
| 4947 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4948 | func (dh *deviceHandler) SendOMCIRequest(ctx context.Context, parentEndpoint string, request *ia.OmciMessage) error { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4949 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint) |
| 4950 | if err != nil || pgClient == nil { |
| 4951 | return err |
| 4952 | } |
| 4953 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 4954 | defer cancel() |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 4955 | dh.setOltAvailable(true) |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4956 | 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] | 4957 | _, err = pgClient.ProxyOmciRequest(subCtx, request) |
| 4958 | if err != nil { |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 4959 | if status.Code(err) == codes.Unavailable { |
| 4960 | dh.setOltAvailable(false) |
| 4961 | } |
| Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4962 | logger.Errorw(ctx, "omci-failure", |
| 4963 | 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] | 4964 | "request-child": request.ChildDeviceId, "request-proxy": request.ProxyAddress, "oltAvailable": dh.IsOltAvailable}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4965 | } |
| 4966 | return err |
| 4967 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4968 | |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 4969 | func (dh *deviceHandler) CheckAvailableOnuCapabilities(ctx context.Context, pDevEntry *mib.OnuDeviceEntry, tpInst tech_profile.TechProfileInstance) error { |
| 4970 | // Check if there are additional TCONT instances necessary/available |
| 4971 | pDevEntry.MutexPersOnuConfig.Lock() |
| 4972 | if _, ok := pDevEntry.SOnuPersistentData.PersTcontMap[uint16(tpInst.UsScheduler.AllocId)]; !ok { |
| 4973 | numberOfTcontMapEntries := len(pDevEntry.SOnuPersistentData.PersTcontMap) |
| 4974 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 4975 | numberOfTcontDbInsts := pDevEntry.GetOnuDB().GetNumberOfInst(me.TContClassID) |
| 4976 | logger.Debugw(ctx, "checking available TCONT instances", |
| 4977 | log.Fields{"device-id": dh.DeviceID, "numberOfTcontMapEntries": numberOfTcontMapEntries, "numberOfTcontDbInsts": numberOfTcontDbInsts}) |
| 4978 | if numberOfTcontMapEntries >= numberOfTcontDbInsts { |
| 4979 | logger.Errorw(ctx, "configuration exceeds ONU capabilities - running out of TCONT instances: send ONU device event!", |
| 4980 | log.Fields{"device-id": dh.device.Id}) |
| 4981 | pDevEntry.SendOnuDeviceEvent(ctx, cmn.OnuConfigFailureMissingTcont, cmn.OnuConfigFailureMissingTcontDesc) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4982 | 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] | 4983 | } |
| 4984 | } else { |
| 4985 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 4986 | } |
| 4987 | // Check if there are enough PrioQueue instances available |
| 4988 | if dh.pOnuTP != nil { |
| 4989 | var numberOfUsPrioQueueDbInsts int |
| 4990 | |
| 4991 | queueInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys(ctx, me.PriorityQueueClassID) |
| 4992 | for _, mgmtEntityID := range queueInstKeys { |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 4993 | if mgmtEntityID >= 0x8000 { |
| Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 4994 | numberOfUsPrioQueueDbInsts++ |
| 4995 | } |
| 4996 | } |
| 4997 | // Check if there is an upstream PriorityQueue instance available for each Gem port |
| 4998 | numberOfConfiguredGemPorts := dh.pOnuTP.GetNumberOfConfiguredUsGemPorts(ctx) |
| 4999 | logger.Debugw(ctx, "checking available upstream PriorityQueue instances", |
| 5000 | log.Fields{"device-id": dh.DeviceID, |
| 5001 | "numberOfConfiguredGemPorts": numberOfConfiguredGemPorts, |
| 5002 | "tpInst.NumGemPorts": tpInst.NumGemPorts, |
| 5003 | "numberOfUsPrioQueueDbInsts": numberOfUsPrioQueueDbInsts}) |
| 5004 | |
| 5005 | if numberOfConfiguredGemPorts+int(tpInst.NumGemPorts) > numberOfUsPrioQueueDbInsts { |
| 5006 | logger.Errorw(ctx, "configuration exceeds ONU capabilities - running out of upstream PrioQueue instances: send ONU device event!", |
| 5007 | log.Fields{"device-id": dh.device.Id}) |
| 5008 | pDevEntry.SendOnuDeviceEvent(ctx, cmn.OnuConfigFailureMissingUsPriorityQueue, cmn.OnuConfigFailureMissingUsPriorityQueueDesc) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 5009 | 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] | 5010 | } |
| 5011 | // Downstream PrioQueue instances are evaluated in accordance with ONU MIB upload data in function UniPonAniConfigFsm::prepareAndEnterConfigState(). |
| 5012 | // In case of missing downstream PrioQueues the attribute "Priority queue pointer for downstream" of ME "GEM port network CTP" will be set to "0", |
| 5013 | // which then alternatively activates the queuing mechanisms of the ONU (refer to Rec. ITU-T G.988 chapter 9.2.3). |
| 5014 | } else { |
| 5015 | logger.Warnw(ctx, "onuTechProf instance not set up - check for PriorityQueue instances skipped!", |
| 5016 | log.Fields{"device-id": dh.DeviceID}) |
| 5017 | } |
| 5018 | return nil |
| 5019 | } |
| 5020 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5021 | // GetDeviceID - TODO: add comment |
| 5022 | func (dh *deviceHandler) GetDeviceID() string { |
| 5023 | return dh.DeviceID |
| 5024 | } |
| 5025 | |
| 5026 | // GetProxyAddressID - TODO: add comment |
| 5027 | func (dh *deviceHandler) GetProxyAddressID() string { |
| 5028 | return dh.device.ProxyAddress.GetDeviceId() |
| 5029 | } |
| 5030 | |
| 5031 | // GetProxyAddressType - TODO: add comment |
| 5032 | func (dh *deviceHandler) GetProxyAddressType() string { |
| 5033 | return dh.device.ProxyAddress.GetDeviceType() |
| 5034 | } |
| 5035 | |
| 5036 | // GetProxyAddress - TODO: add comment |
| 5037 | func (dh *deviceHandler) GetProxyAddress() *voltha.Device_ProxyAddress { |
| 5038 | return dh.device.ProxyAddress |
| 5039 | } |
| 5040 | |
| 5041 | // GetEventProxy - TODO: add comment |
| 5042 | func (dh *deviceHandler) GetEventProxy() eventif.EventProxy { |
| 5043 | return dh.EventProxy |
| 5044 | } |
| 5045 | |
| 5046 | // GetOmciTimeout - TODO: add comment |
| 5047 | func (dh *deviceHandler) GetOmciTimeout() int { |
| 5048 | return dh.pOpenOnuAc.omciTimeout |
| 5049 | } |
| 5050 | |
| 5051 | // GetAlarmAuditInterval - TODO: add comment |
| 5052 | func (dh *deviceHandler) GetAlarmAuditInterval() time.Duration { |
| 5053 | return dh.pOpenOnuAc.alarmAuditInterval |
| 5054 | } |
| 5055 | |
| 5056 | // GetDlToOnuTimeout4M - TODO: add comment |
| 5057 | func (dh *deviceHandler) GetDlToOnuTimeout4M() time.Duration { |
| 5058 | return dh.pOpenOnuAc.dlToOnuTimeout4M |
| 5059 | } |
| 5060 | |
| 5061 | // GetUniEntityMap - TODO: add comment |
| 5062 | func (dh *deviceHandler) GetUniEntityMap() *cmn.OnuUniPortMap { |
| 5063 | return &dh.uniEntityMap |
| 5064 | } |
| 5065 | |
| 5066 | // GetPonPortNumber - TODO: add comment |
| 5067 | func (dh *deviceHandler) GetPonPortNumber() *uint32 { |
| 5068 | return &dh.ponPortNumber |
| 5069 | } |
| 5070 | |
| 5071 | // GetUniVlanConfigFsm - TODO: add comment |
| 5072 | func (dh *deviceHandler) GetUniVlanConfigFsm(uniID uint8) cmn.IuniVlanConfigFsm { |
| Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 5073 | dh.lockVlanConfig.RLock() |
| 5074 | value := dh.UniVlanConfigFsmMap[uniID] |
| 5075 | dh.lockVlanConfig.RUnlock() |
| 5076 | return value |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5077 | } |
| 5078 | |
| 5079 | // GetOnuAlarmManager - TODO: add comment |
| 5080 | func (dh *deviceHandler) GetOnuAlarmManager() cmn.IonuAlarmManager { |
| 5081 | return dh.pAlarmMgr |
| 5082 | } |
| 5083 | |
| 5084 | // GetOnuMetricsManager - TODO: add comment |
| 5085 | func (dh *deviceHandler) GetOnuMetricsManager() cmn.IonuMetricsManager { |
| 5086 | return dh.pOnuMetricsMgr |
| 5087 | } |
| 5088 | |
| 5089 | // GetOnuTP - TODO: add comment |
| 5090 | func (dh *deviceHandler) GetOnuTP() cmn.IonuUniTechProf { |
| 5091 | return dh.pOnuTP |
| 5092 | } |
| 5093 | |
| 5094 | // GetBackendPathPrefix - TODO: add comment |
| 5095 | func (dh *deviceHandler) GetBackendPathPrefix() string { |
| 5096 | return dh.pOpenOnuAc.cm.Backend.PathPrefix |
| 5097 | } |
| 5098 | |
| 5099 | // GetOnuIndication - TODO: add comment |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 5100 | func (dh *deviceHandler) GetOnuIndication() *oop.OnuIndication { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5101 | return dh.pOnuIndication |
| 5102 | } |
| 5103 | |
| 5104 | // RLockMutexDeletionInProgressFlag - TODO: add comment |
| 5105 | func (dh *deviceHandler) RLockMutexDeletionInProgressFlag() { |
| 5106 | dh.mutexDeletionInProgressFlag.RLock() |
| 5107 | } |
| 5108 | |
| 5109 | // RUnlockMutexDeletionInProgressFlag - TODO: add comment |
| 5110 | func (dh *deviceHandler) RUnlockMutexDeletionInProgressFlag() { |
| 5111 | dh.mutexDeletionInProgressFlag.RUnlock() |
| 5112 | } |
| 5113 | |
| 5114 | // GetDeletionInProgress - TODO: add comment |
| 5115 | func (dh *deviceHandler) GetDeletionInProgress() bool { |
| 5116 | return dh.deletionInProgress |
| 5117 | } |
| 5118 | |
| 5119 | // GetPmConfigs - TODO: add comment |
| 5120 | func (dh *deviceHandler) GetPmConfigs() *voltha.PmConfigs { |
| 5121 | return dh.pmConfigs |
| 5122 | } |
| 5123 | |
| 5124 | // GetDeviceType - TODO: add comment |
| 5125 | func (dh *deviceHandler) GetDeviceType() string { |
| 5126 | return dh.DeviceType |
| 5127 | } |
| 5128 | |
| 5129 | // GetLogicalDeviceID - TODO: add comment |
| 5130 | func (dh *deviceHandler) GetLogicalDeviceID() string { |
| 5131 | return dh.logicalDeviceID |
| 5132 | } |
| 5133 | |
| 5134 | // GetDevice - TODO: add comment |
| 5135 | func (dh *deviceHandler) GetDevice() *voltha.Device { |
| 5136 | return dh.device |
| 5137 | } |
| 5138 | |
| Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame] | 5139 | func (dh *deviceHandler) setOltAvailable(value bool) { |
| 5140 | dh.mutexOltAvailable.Lock() |
| 5141 | dh.oltAvailable = value |
| 5142 | dh.mutexOltAvailable.Unlock() |
| 5143 | } |
| 5144 | |
| 5145 | // IsOltAvailable - TODO: add comment |
| 5146 | func (dh *deviceHandler) IsOltAvailable() bool { |
| 5147 | dh.mutexOltAvailable.RLock() |
| 5148 | defer dh.mutexOltAvailable.RUnlock() |
| 5149 | return dh.oltAvailable |
| 5150 | } |
| 5151 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5152 | // GetMetricsEnabled - TODO: add comment |
| 5153 | func (dh *deviceHandler) GetMetricsEnabled() bool { |
| 5154 | return dh.pOpenOnuAc.MetricsEnabled |
| 5155 | } |
| 5156 | |
| Holger Hildebrandt | c572e62 | 2022-06-22 09:19:17 +0000 | [diff] [blame] | 5157 | // GetExtendedOmciSupportEnabled - TODO: add comment |
| 5158 | func (dh *deviceHandler) GetExtendedOmciSupportEnabled() bool { |
| 5159 | return dh.pOpenOnuAc.ExtendedOmciSupportEnabled |
| 5160 | } |
| 5161 | |
| Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 5162 | // GetExtendedOmciSupportEnabled - TODO: add comment |
| 5163 | func (dh *deviceHandler) GetSkipOnuConfigEnabled() bool { |
| 5164 | return dh.pOpenOnuAc.skipOnuConfig |
| 5165 | } |
| 5166 | |
| Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame] | 5167 | func (dh *deviceHandler) GetDeviceTechProfOnReboot() bool { |
| 5168 | return dh.pOpenOnuAc.CheckDeviceTechProfOnReboot |
| 5169 | } |
| 5170 | |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 5171 | // InitPmConfigs - TODO: add comment |
| 5172 | func (dh *deviceHandler) InitPmConfigs() { |
| 5173 | dh.pmConfigs = &voltha.PmConfigs{} |
| 5174 | } |
| 5175 | |
| 5176 | // GetUniPortMask - TODO: add comment |
| 5177 | func (dh *deviceHandler) GetUniPortMask() int { |
| 5178 | return dh.pOpenOnuAc.config.UniPortMask |
| 5179 | } |
| Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 5180 | |
| 5181 | func (dh *deviceHandler) anyTpPathExists(aTpPathMap map[uint8]string) bool { |
| 5182 | tpPathFound := false |
| 5183 | for _, tpPath := range aTpPathMap { |
| 5184 | if tpPath != "" { |
| 5185 | tpPathFound = true |
| 5186 | } |
| 5187 | } |
| 5188 | return tpPathFound |
| 5189 | } |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5190 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 5191 | func (dh *deviceHandler) getOnuActiveAlarms(ctx context.Context) *extension.SingleGetValueResponse { |
| 5192 | resp := dh.GetOnuAlarmManager().GetOnuActiveAlarms(ctx) |
| 5193 | logger.Debugw(ctx, "Received response from AlarmManager for Active Alarms for DeviceEntry", log.Fields{"device-id": dh.DeviceID}) |
| 5194 | return resp |
| 5195 | } |
| 5196 | |
| Akash Reddy Kankanala | c28f0e2 | 2025-06-16 11:00:55 +0530 | [diff] [blame] | 5197 | // getONUGEMStatsInfo - Get the GEM PM history data of the request ONT device |
| 5198 | func (dh *deviceHandler) getONUGEMStatsInfo(ctx context.Context) *extension.SingleGetValueResponse { |
| 5199 | resp := dh.pOnuMetricsMgr.GetONUGEMCounters(ctx) |
| 5200 | logger.Debugw(ctx, "Received response from AlarmManager for Active Alarms for DeviceEntry", log.Fields{"device-id": dh.DeviceID}) |
| 5201 | return resp |
| 5202 | } |
| 5203 | |
| Praneeth Kumar Nalmas | aacc612 | 2024-04-09 22:55:49 +0530 | [diff] [blame] | 5204 | func (dh *deviceHandler) GetDeviceDeleteCommChan(ctx context.Context) chan bool { |
| 5205 | return dh.deviceDeleteCommChan |
| 5206 | } |
| 5207 | |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5208 | // PrepareForGarbageCollection - remove references to prepare for garbage collection |
| 5209 | func (dh *deviceHandler) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) { |
| 5210 | logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID}) |
| 5211 | |
| 5212 | // Note: This function must be called as a goroutine to prevent blocking of further processing! |
| 5213 | // first let the objects rest for some time to give all asynchronously started |
| 5214 | // cleanup routines a chance to come to an end |
| Holger Hildebrandt | 12609a1 | 2022-03-25 13:23:25 +0000 | [diff] [blame] | 5215 | time.Sleep(2 * time.Second) |
| 5216 | |
| 5217 | if dh.pOnuOmciDevice != nil { |
| 5218 | if dh.pOnuOmciDevice.PDevOmciCC != nil { |
| 5219 | // Since we cannot rule out that one of the handlers had initiated any OMCI configurations during its |
| 5220 | // reset handling (even in future coding), request monitoring is canceled here one last time to |
| 5221 | // be sure that all corresponding go routines are terminated |
| 5222 | dh.pOnuOmciDevice.PDevOmciCC.CancelRequestMonitoring(ctx) |
| 5223 | } |
| 5224 | } |
| 5225 | time.Sleep(3 * time.Second) |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5226 | |
| 5227 | if dh.pOnuTP != nil { |
| 5228 | dh.pOnuTP.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5229 | } |
| 5230 | if dh.pOnuMetricsMgr != nil { |
| Holger Hildebrandt | 34f13b2 | 2023-01-18 15:14:59 +0000 | [diff] [blame] | 5231 | logger.Debugw(ctx, "preparation of garbage collection is done under control of pm fsm - wait for completion", |
| 5232 | log.Fields{"device-id": aDeviceID}) |
| Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 5233 | select { |
| 5234 | case <-dh.pOnuMetricsMgr.GarbageCollectionComplete: |
| 5235 | logger.Debugw(ctx, "pm fsm shut down and garbage collection complete", log.Fields{"deviceID": aDeviceID}) |
| 5236 | case <-time.After(pmmgr.MaxTimeForPmFsmShutDown * time.Second): |
| 5237 | 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] | 5238 | default: |
| Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 5239 | } |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5240 | } |
| 5241 | if dh.pAlarmMgr != nil { |
| 5242 | dh.pAlarmMgr.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5243 | } |
| 5244 | if dh.pSelfTestHdlr != nil { |
| 5245 | dh.pSelfTestHdlr.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5246 | } |
| 5247 | if dh.pLockStateFsm != nil { |
| 5248 | dh.pLockStateFsm.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5249 | } |
| 5250 | if dh.pUnlockStateFsm != nil { |
| 5251 | dh.pUnlockStateFsm.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5252 | } |
| 5253 | if dh.pOnuUpradeFsm != nil { |
| 5254 | dh.pOnuUpradeFsm.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5255 | } |
| 5256 | if dh.pOnuOmciDevice != nil { |
| 5257 | dh.pOnuOmciDevice.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5258 | } |
| 5259 | for k, v := range dh.UniVlanConfigFsmMap { |
| 5260 | v.PrepareForGarbageCollection(ctx, aDeviceID) |
| 5261 | delete(dh.UniVlanConfigFsmMap, k) |
| 5262 | } |
| nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 5263 | dh.pOnuIndication = nil |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 5264 | dh.pOnuOmciDevice = nil |
| 5265 | dh.pOnuTP = nil |
| 5266 | dh.pOnuMetricsMgr = nil |
| 5267 | dh.pAlarmMgr = nil |
| 5268 | dh.pSelfTestHdlr = nil |
| 5269 | dh.pLockStateFsm = nil |
| 5270 | dh.pUnlockStateFsm = nil |
| 5271 | dh.pOnuUpradeFsm = nil |
| 5272 | } |