Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 17 | //Package core provides the utility for onu devices, flows and statistics |
| 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" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 47 | vc "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" |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 50 | "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 51 | ia "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 52 | of "github.com/opencord/voltha-protos/v5/go/openflow_13" |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 53 | "github.com/opencord/voltha-protos/v5/go/openolt" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 54 | oop "github.com/opencord/voltha-protos/v5/go/openolt" |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 55 | "github.com/opencord/voltha-protos/v5/go/tech_profile" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 56 | "github.com/opencord/voltha-protos/v5/go/voltha" |
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 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 95 | //Event category and subcategory definitions - same as defiend for OLT in eventmgr.go - should be done more centrally |
| 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 |
| 142 | addFlow bool // if true flow to be added, else removed |
| 143 | flowItem *of.OfpFlowStats |
| 144 | uniPort *cmn.OnuUniPort |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 145 | flowMetaData *of.FlowMetadata |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 146 | respChan *chan error // channel to report the Flow handling error |
| 147 | } |
| 148 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 149 | //deviceHandler will interact with the ONU ? device. |
| 150 | type deviceHandler struct { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 151 | DeviceID string |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 152 | DeviceType string |
| 153 | adminState string |
| 154 | device *voltha.Device |
| 155 | logicalDeviceID string |
| 156 | ProxyAddressID string |
| 157 | ProxyAddressType string |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 158 | parentID string |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 159 | ponPortNumber uint32 |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 160 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 161 | coreClient *vgrpc.Client |
| 162 | EventProxy eventif.EventProxy |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 163 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 164 | pmConfigs *voltha.PmConfigs |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 165 | config *config.AdapterFlags |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 166 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 167 | pOpenOnuAc *OpenONUAC |
| 168 | pDeviceStateFsm *fsm.FSM |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 169 | //pPonPort *voltha.Port |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 170 | deviceEntrySet chan bool //channel for DeviceEntry set event |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 171 | pOnuOmciDevice *mib.OnuDeviceEntry |
| 172 | pOnuTP *avcfg.OnuUniTechProf |
| 173 | pOnuMetricsMgr *pmmgr.OnuMetricsManager |
| 174 | pAlarmMgr *almgr.OnuAlarmManager |
| 175 | pSelfTestHdlr *otst.SelfTestControlBlock |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 176 | exitChannel chan int |
| 177 | lockDevice sync.RWMutex |
| 178 | pOnuIndication *oop.OnuIndication |
| 179 | deviceReason uint8 |
| 180 | mutexDeviceReason sync.RWMutex |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 181 | pLockStateFsm *uniprt.LockStateFsm |
| 182 | pUnlockStateFsm *uniprt.LockStateFsm |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 183 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 184 | //flowMgr *OpenOltFlowMgr |
| 185 | //eventMgr *OpenOltEventMgr |
| 186 | //resourceMgr *rsrcMgr.OpenOltResourceMgr |
| 187 | |
| 188 | //discOnus sync.Map |
| 189 | //onus sync.Map |
| 190 | //portStats *OpenOltStatisticsMgr |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 191 | collectorIsRunning bool |
| 192 | mutexCollectorFlag sync.RWMutex |
| 193 | stopCollector chan bool |
| 194 | alarmManagerIsRunning bool |
| 195 | mutextAlarmManagerFlag sync.RWMutex |
| 196 | stopAlarmManager chan bool |
| 197 | stopHeartbeatCheck chan bool |
| 198 | uniEntityMap cmn.OnuUniPortMap |
| 199 | mutexKvStoreContext sync.Mutex |
| 200 | lockVlanConfig sync.RWMutex |
| 201 | lockVlanAdd sync.RWMutex |
| 202 | UniVlanConfigFsmMap map[uint8]*avcfg.UniVlanConfigFsm |
| 203 | lockUpgradeFsm sync.RWMutex |
| 204 | pOnuUpradeFsm *swupg.OnuUpgradeFsm |
| 205 | upgradeCanceled bool |
| 206 | reconciling uint8 |
| 207 | mutexReconcilingFlag sync.RWMutex |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 208 | reconcilingFirstPass bool |
| 209 | mutexReconcilingFirstPassFlag sync.RWMutex |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 210 | reconcilingReasonUpdate bool |
| 211 | mutexReconcilingReasonUpdate sync.RWMutex |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 212 | chUniVlanConfigReconcilingDone chan uint16 //channel to indicate that VlanConfig reconciling for a specific UNI has been finished |
| 213 | chReconcilingFinished chan bool //channel to indicate that reconciling has been finished |
| 214 | reconcileExpiryComplete time.Duration |
| 215 | reconcileExpiryVlanConfig time.Duration |
| 216 | mutexReadyForOmciConfig sync.RWMutex |
| 217 | readyForOmciConfig bool |
| 218 | deletionInProgress bool |
| 219 | mutexDeletionInProgressFlag sync.RWMutex |
| 220 | pLastUpgradeImageState *voltha.ImageState |
| 221 | upgradeFsmChan chan struct{} |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 222 | |
| 223 | flowCbChan []chan FlowCb |
| 224 | mutexFlowMonitoringRoutineFlag sync.RWMutex |
ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame^] | 225 | mutexForDisableDeviceRequested sync.RWMutex |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 226 | stopFlowMonitoringRoutine []chan bool // length of slice equal to number of uni ports |
| 227 | isFlowMonitoringRoutineActive []bool // length of slice equal to number of uni ports |
ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame^] | 228 | disableDeviceRequested bool // this flag identify ONU received disable request or not |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 231 | //newDeviceHandler creates a new device handler |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 232 | 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] | 233 | var dh deviceHandler |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 234 | dh.coreClient = cc |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 235 | dh.EventProxy = ep |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 236 | dh.config = adapter.config |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 237 | cloned := (proto.Clone(device)).(*voltha.Device) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 238 | dh.DeviceID = cloned.Id |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 239 | dh.DeviceType = cloned.Type |
| 240 | dh.adminState = "up" |
| 241 | dh.device = cloned |
| 242 | dh.pOpenOnuAc = adapter |
| 243 | dh.exitChannel = make(chan int, 1) |
| 244 | dh.lockDevice = sync.RWMutex{} |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 245 | dh.deviceEntrySet = make(chan bool, 1) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 246 | dh.collectorIsRunning = false |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 247 | dh.stopCollector = make(chan bool, 2) |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 248 | dh.alarmManagerIsRunning = false |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 249 | dh.stopAlarmManager = make(chan bool, 2) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 250 | dh.stopHeartbeatCheck = make(chan bool, 2) |
| 251 | //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] | 252 | //TODO initialize the support classes. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 253 | dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 254 | dh.lockVlanConfig = sync.RWMutex{} |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 255 | dh.lockVlanAdd = sync.RWMutex{} |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 256 | dh.lockUpgradeFsm = sync.RWMutex{} |
ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame^] | 257 | dh.mutexForDisableDeviceRequested = sync.RWMutex{} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 258 | dh.UniVlanConfigFsmMap = make(map[uint8]*avcfg.UniVlanConfigFsm) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 259 | dh.reconciling = cNoReconciling |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 260 | dh.reconcilingReasonUpdate = false |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 261 | dh.reconcilingFirstPass = true |
ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame^] | 262 | dh.disableDeviceRequested = false |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 263 | dh.chReconcilingFinished = make(chan bool) |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 264 | dh.reconcileExpiryComplete = adapter.maxTimeoutReconciling //assumption is to have it as duration in s! |
| 265 | rECSeconds := int(dh.reconcileExpiryComplete / time.Second) |
| 266 | if rECSeconds < 2 { |
| 267 | dh.reconcileExpiryComplete = time.Duration(2) * time.Second //ensure a minimum expiry time of 2s for complete reconciling |
| 268 | rECSeconds = 2 |
| 269 | } |
| 270 | rEVCSeconds := rECSeconds / 2 |
| 271 | 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] | 272 | dh.readyForOmciConfig = false |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 273 | dh.deletionInProgress = false |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 274 | dh.pLastUpgradeImageState = &voltha.ImageState{ |
| 275 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 276 | Reason: voltha.ImageState_UNKNOWN_ERROR, |
| 277 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 278 | } |
| 279 | dh.upgradeFsmChan = make(chan struct{}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 280 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 281 | if dh.device.PmConfigs != nil { // can happen after onu adapter restart |
| 282 | dh.pmConfigs = cloned.PmConfigs |
| 283 | } /* else { |
| 284 | // will be populated when onu_metrics_mananger is initialized. |
| 285 | }*/ |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 286 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 287 | // Device related state machine |
| 288 | dh.pDeviceStateFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 289 | devStNull, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 290 | fsm.Events{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 291 | {Name: devEvDeviceInit, Src: []string{devStNull, devStDown}, Dst: devStInit}, |
| 292 | {Name: devEvGrpcConnected, Src: []string{devStInit}, Dst: devStConnected}, |
| 293 | {Name: devEvGrpcDisconnected, Src: []string{devStConnected, devStDown}, Dst: devStInit}, |
| 294 | {Name: devEvDeviceUpInd, Src: []string{devStConnected, devStDown}, Dst: devStUp}, |
| 295 | {Name: devEvDeviceDownInd, Src: []string{devStUp}, Dst: devStDown}, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 296 | }, |
| 297 | fsm.Callbacks{ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 298 | "before_event": func(e *fsm.Event) { dh.logStateChange(ctx, e) }, |
| 299 | ("before_" + devEvDeviceInit): func(e *fsm.Event) { dh.doStateInit(ctx, e) }, |
| 300 | ("after_" + devEvDeviceInit): func(e *fsm.Event) { dh.postInit(ctx, e) }, |
| 301 | ("before_" + devEvGrpcConnected): func(e *fsm.Event) { dh.doStateConnected(ctx, e) }, |
| 302 | ("before_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.doStateInit(ctx, e) }, |
| 303 | ("after_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.postInit(ctx, e) }, |
| 304 | ("before_" + devEvDeviceUpInd): func(e *fsm.Event) { dh.doStateUp(ctx, e) }, |
| 305 | ("before_" + devEvDeviceDownInd): func(e *fsm.Event) { dh.doStateDown(ctx, e) }, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 306 | }, |
| 307 | ) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 308 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 309 | return &dh |
| 310 | } |
| 311 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 312 | // start save the device to the data model |
| 313 | func (dh *deviceHandler) start(ctx context.Context) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 314 | 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] | 315 | // Add the initial device to the local model |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 316 | logger.Debugw(ctx, "device-handler-started", log.Fields{"device": dh.device}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 319 | /* |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 320 | // stop stops the device dh. Not much to do for now |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 321 | func (dh *deviceHandler) stop(ctx context.Context) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 322 | logger.Debug("stopping-device-handler") |
| 323 | dh.exitChannel <- 1 |
| 324 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 325 | */ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 326 | |
| 327 | // ########################################################################################## |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 328 | // deviceHandler methods that implement the adapters interface requests ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 329 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 330 | //adoptOrReconcileDevice adopts the ONU device |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 331 | func (dh *deviceHandler) adoptOrReconcileDevice(ctx context.Context, device *voltha.Device) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 332 | 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] | 333 | |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 334 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"device-id": device.Id, "state": string(dh.pDeviceStateFsm.Current())}) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 335 | if dh.pDeviceStateFsm.Is(devStNull) { |
| 336 | if err := dh.pDeviceStateFsm.Event(devEvDeviceInit); err != nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 337 | 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] | 338 | } |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 339 | 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] | 340 | // device.PmConfigs is not nil in cases when adapter restarts. We should not re-set the core again. |
| 341 | if device.PmConfigs == nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 342 | // Now, set the initial PM configuration for that device |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 343 | if err := dh.updatePMConfigInCore(ctx, dh.pmConfigs); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 344 | 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] | 345 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 346 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 347 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 348 | 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] | 349 | } |
| 350 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 351 | } |
| 352 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 353 | func (dh *deviceHandler) handleOMCIIndication(ctx context.Context, msg *ia.OmciMessage) error { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 354 | /* 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] | 355 | //assuming omci message content is hex coded! |
| 356 | // with restricted output of 16(?) bytes would be ...omciMsg.Message[:16] |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 357 | logger.Debugw(ctx, "inter-adapter-recv-omci", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 358 | "device-id": dh.DeviceID, "RxOmciMessage": hex.EncodeToString(omciMsg.Message)}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 359 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 360 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 361 | if pDevEntry != nil { |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 362 | if pDevEntry.PDevOmciCC != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 363 | return pDevEntry.PDevOmciCC.ReceiveMessage(log.WithSpanFromContext(context.TODO(), ctx), msg.Message) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 364 | } |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 365 | logger.Debugw(ctx, "omciCC not ready to receive omci messages - incoming omci message ignored", log.Fields{"device-id": dh.DeviceID, |
| 366 | "rxMsg": msg.Message}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 367 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 368 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 369 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 370 | } |
| 371 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 372 | func (dh *deviceHandler) handleTechProfileDownloadRequest(ctx context.Context, techProfMsg *ia.TechProfileDownloadMessage) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 373 | 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] | 374 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 375 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 376 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 377 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 378 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 379 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 380 | if dh.pOnuTP == nil { |
| 381 | //should normally not happen ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 382 | 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] | 383 | log.Fields{"device-id": dh.DeviceID}) |
| 384 | 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] | 385 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 386 | if !dh.IsReadyForOmciConfig() { |
| 387 | logger.Errorw(ctx, "TechProf-set rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 388 | "device-state": dh.GetDeviceReasonString()}) |
| 389 | 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] | 390 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 391 | //previous state test here was just this one, now extended for more states to reject the SetRequest: |
| 392 | // at least 'mib-downloaded' should be reached for processing of this specific ONU configuration |
| 393 | // if (dh.deviceReason == "stopping-openomci") || (dh.deviceReason == "omci-admin-lock") |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 394 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 395 | // 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] | 396 | // even to fast subsequent calls of the same messageType as well as OnuKVStore processing due |
| 397 | // to possible concurrent access by flow processing |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 398 | dh.pOnuTP.LockTpProcMutex() |
| 399 | defer dh.pOnuTP.UnlockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 400 | |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 401 | if techProfMsg.UniId >= platform.MaxUnisPerOnu { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 402 | return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 403 | techProfMsg.UniId, dh.DeviceID)) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 404 | } |
| 405 | uniID := uint8(techProfMsg.UniId) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 406 | tpID, err := cmn.GetTpIDFromTpPath(techProfMsg.TpInstancePath) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 407 | if err != nil { |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 408 | logger.Errorw(ctx, "error-parsing-tpid-from-tppath", log.Fields{"err": err, "tp-path": techProfMsg.TpInstancePath}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 409 | return err |
| 410 | } |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 411 | logger.Debugw(ctx, "unmarshal-techprof-msg-body", log.Fields{"device-id": dh.DeviceID, |
| 412 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 413 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 414 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, uint8(tpID), techProfMsg.TpInstancePath); bTpModify { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 415 | |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 416 | switch tpInst := techProfMsg.TechTpInstance.(type) { |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 417 | case *ia.TechProfileDownloadMessage_TpInstance: |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 418 | logger.Debugw(ctx, "onu-uni-tp-path-modified", log.Fields{"device-id": dh.DeviceID, |
| 419 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 420 | // if there has been some change for some uni TechProfilePath |
| 421 | //in order to allow concurrent calls to other dh instances we do not wait for execution here |
| 422 | //but doing so we can not indicate problems to the caller (who does what with that then?) |
| 423 | //by now we just assume straightforward successful execution |
| 424 | //TODO!!! Generally: In this scheme it would be good to have some means to indicate |
| 425 | // possible problems to the caller later autonomously |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 426 | |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 427 | // deadline context to ensure completion of background routines waited for |
| 428 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 429 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 430 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 431 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 432 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 433 | |
| 434 | var wg sync.WaitGroup |
| 435 | wg.Add(1) // for the 1 go routine to finish |
| 436 | // 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] | 437 | 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] | 438 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfDwld") //wait for background process to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 439 | if tpErr := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); tpErr != nil { |
| 440 | 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] | 441 | return tpErr |
| 442 | } |
| 443 | deadline = time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 444 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 445 | pDevEntry.ResetKvProcessingErrorIndication() |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 446 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 447 | go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 448 | dh.waitForCompletion(ctx, cancel2, &wg, "TechProfDwld") //wait for background process to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 449 | if kvErr := pDevEntry.GetKvProcessingErrorIndication(); kvErr != nil { |
| 450 | logger.Errorw(ctx, "error-updating-KV", log.Fields{"device-id": dh.DeviceID, "err": kvErr, "tp-path": techProfMsg.TpInstancePath}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 451 | return kvErr |
| 452 | } |
| 453 | return nil |
| 454 | default: |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 455 | 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] | 456 | return fmt.Errorf("unsupported-tp-instance-type--tp-id-%v", techProfMsg.TpInstancePath) |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 457 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 458 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 459 | // no change, nothing really to do - return success |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 460 | logger.Debugw(ctx, "onu-uni-tp-path-not-modified", log.Fields{"device-id": dh.DeviceID, |
| 461 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 462 | return nil |
| 463 | } |
| 464 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 465 | func (dh *deviceHandler) handleDeleteGemPortRequest(ctx context.Context, delGemPortMsg *ia.DeleteGemPortMessage) error { |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 466 | 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] | 467 | |
| 468 | if dh.pOnuTP == nil { |
| 469 | //should normally not happen ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 470 | 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] | 471 | log.Fields{"device-id": dh.DeviceID}) |
| 472 | 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] | 473 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 474 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 475 | dh.pOnuTP.LockTpProcMutex() |
| 476 | defer dh.pOnuTP.UnlockTpProcMutex() |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 477 | |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 478 | if delGemPortMsg.UniId >= platform.MaxUnisPerOnu { |
| 479 | logger.Errorw(ctx, "delete-gem-port UniId exceeds range", log.Fields{ |
| 480 | "device-id": dh.DeviceID, "uni-id": delGemPortMsg.UniId}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 481 | return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 482 | delGemPortMsg.UniId, dh.DeviceID)) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 483 | } |
| 484 | uniID := uint8(delGemPortMsg.UniId) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 485 | tpID, err := cmn.GetTpIDFromTpPath(delGemPortMsg.TpInstancePath) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 486 | if err != nil { |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 487 | logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{ |
| 488 | "device-id": dh.DeviceID, "err": err, "tp-path": delGemPortMsg.TpInstancePath}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 489 | return err |
| 490 | } |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 491 | logger.Infow(ctx, "delete-gem-port-request", log.Fields{ |
| 492 | "device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "gem": delGemPortMsg.GemPortId}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 493 | //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] | 494 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 495 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delGemPortMsg.TpInstancePath, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 496 | avcfg.CResourceGemPort, delGemPortMsg.GemPortId) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 497 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 498 | } |
| 499 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 500 | func (dh *deviceHandler) handleDeleteTcontRequest(ctx context.Context, delTcontMsg *ia.DeleteTcontMessage) error { |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 501 | logger.Infow(ctx, "delete-tcont-request start", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 502 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 503 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 504 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 505 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 506 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 507 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 508 | if dh.pOnuTP == nil { |
| 509 | //should normally not happen ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 510 | 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] | 511 | log.Fields{"device-id": dh.DeviceID}) |
| 512 | 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] | 513 | } |
| 514 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 515 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 516 | dh.pOnuTP.LockTpProcMutex() |
| 517 | defer dh.pOnuTP.UnlockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 518 | |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 519 | if delTcontMsg.UniId >= platform.MaxUnisPerOnu { |
| 520 | logger.Errorw(ctx, "delete-tcont UniId exceeds range", log.Fields{ |
| 521 | "device-id": dh.DeviceID, "uni-id": delTcontMsg.UniId}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 522 | return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 523 | delTcontMsg.UniId, dh.DeviceID)) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 524 | } |
| 525 | uniID := uint8(delTcontMsg.UniId) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 526 | tpPath := delTcontMsg.TpInstancePath |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 527 | tpID, err := cmn.GetTpIDFromTpPath(tpPath) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 528 | if err != nil { |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 529 | logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{ |
| 530 | "device-id": dh.DeviceID, "err": err, "tp-path": tpPath}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 531 | return err |
| 532 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 533 | logger.Infow(ctx, "delete-tcont-request", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "tcont": delTcontMsg.AllocId}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 534 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 535 | pDevEntry.FreeTcont(ctx, uint16(delTcontMsg.AllocId)) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 536 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 537 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delTcontMsg.TpInstancePath, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 538 | avcfg.CResourceTcont, delTcontMsg.AllocId) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 539 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 540 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 541 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 542 | func (dh *deviceHandler) deleteTechProfileResource(ctx context.Context, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 543 | uniID uint8, tpID uint8, pathString string, resource avcfg.ResourceEntry, entryID uint32) error { |
| 544 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 545 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 546 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 547 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 548 | } |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 549 | var resourceName string |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 550 | if avcfg.CResourceGemPort == resource { |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 551 | resourceName = "Gem" |
| 552 | } else { |
| 553 | resourceName = "Tcont" |
| 554 | } |
| 555 | |
| 556 | // deadline context to ensure completion of background routines waited for |
| 557 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 558 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 559 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 560 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 561 | |
| 562 | var wg sync.WaitGroup |
| 563 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 564 | go dh.pOnuTP.DeleteTpResource(log.WithSpanFromContext(dctx, ctx), uniID, tpID, pathString, |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 565 | resource, entryID, &wg) |
| 566 | 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] | 567 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); err != nil { |
| 568 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 569 | return err |
| 570 | } |
| 571 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 572 | if dh.pOnuTP.IsTechProfileConfigCleared(ctx, uniID, tpID) { |
| 573 | logger.Debugw(ctx, "techProfile-config-cleared", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID}) |
| 574 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, tpID, ""); bTpModify { |
| 575 | pDevEntry.ResetKvProcessingErrorIndication() |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 576 | var wg2 sync.WaitGroup |
| 577 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
| 578 | wg2.Add(1) |
| 579 | // Removal of the gem id mapping represents the removal of the tech profile |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 580 | logger.Infow(ctx, "remove-techProfile-indication-in-kv", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID}) |
| 581 | go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg2) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 582 | dh.waitForCompletion(ctx, cancel2, &wg2, "TechProfileDeleteOn"+resourceName) //wait for background process to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 583 | if err := pDevEntry.GetKvProcessingErrorIndication(); err != nil { |
| 584 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 585 | return err |
| 586 | } |
| 587 | } |
| 588 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 589 | 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] | 590 | "uni-id": uniID, "tpID": tpID, "resource-type": resourceName, "resource-id": entryID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 591 | return nil |
| 592 | } |
| 593 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 594 | //FlowUpdateIncremental removes and/or adds the flow changes on a given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 595 | func (dh *deviceHandler) FlowUpdateIncremental(ctx context.Context, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 596 | apOfFlowChanges *of.FlowChanges, |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 597 | apOfGroupChanges *of.FlowGroupChanges, apFlowMetaData *of.FlowMetadata) error { |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 598 | logger.Debugw(ctx, "FlowUpdateIncremental started", log.Fields{"device-id": dh.DeviceID, "flow": apOfFlowChanges, "metadata": apFlowMetaData}) |
| 599 | var errorsList []error |
| 600 | var retError error |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 601 | //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] | 602 | if apOfFlowChanges.ToRemove != nil { |
| 603 | for _, flowItem := range apOfFlowChanges.ToRemove.Items { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 604 | if flowItem.GetCookie() == 0 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 605 | 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] | 606 | "device-id": dh.DeviceID}) |
| 607 | retError = fmt.Errorf("flow-remove no cookie, device-id %s", dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 608 | errorsList = append(errorsList, retError) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 609 | continue |
| 610 | } |
| 611 | flowInPort := flow.GetInPort(flowItem) |
| 612 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 613 | logger.Warnw(ctx, "flow-remove inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 614 | retError = fmt.Errorf("flow-remove inPort invalid, device-id %s", dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 615 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 616 | continue |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 617 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 618 | } else if flowInPort == dh.ponPortNumber { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 619 | //this is some downstream flow, not regarded as error, just ignored |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 620 | 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] | 621 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 622 | continue |
| 623 | } else { |
| 624 | // this is the relevant upstream flow |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 625 | var loUniPort *cmn.OnuUniPort |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 626 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 627 | loUniPort = uniPort |
| 628 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 629 | 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] | 630 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 631 | 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] | 632 | flowInPort, dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 633 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 634 | continue |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 635 | } |
| 636 | flowOutPort := flow.GetOutPort(flowItem) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 637 | logger.Debugw(ctx, "flow-remove port indications", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 638 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 639 | "uniPortName": loUniPort.Name}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 640 | |
| 641 | if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) { |
| 642 | // Step1 : Fill flowControlBlock |
| 643 | // Step2 : Push the flowControlBlock to ONU channel |
| 644 | // Step3 : Wait on response channel for response |
| 645 | // Step4 : Return error value |
| 646 | startTime := time.Now() |
| 647 | respChan := make(chan error) |
| 648 | flowCb := FlowCb{ |
| 649 | ctx: ctx, |
| 650 | addFlow: false, |
| 651 | flowItem: flowItem, |
| 652 | flowMetaData: nil, |
| 653 | uniPort: loUniPort, |
| 654 | respChan: &respChan, |
| 655 | } |
| 656 | dh.flowCbChan[loUniPort.UniID] <- flowCb |
| 657 | logger.Infow(ctx, "process-flow-remove-start", log.Fields{"device-id": dh.DeviceID}) |
| 658 | // Wait on the channel for flow handlers return value |
| 659 | retError = <-respChan |
| 660 | logger.Infow(ctx, "process-flow-remove-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| 661 | if retError != nil { |
| 662 | logger.Warnw(ctx, "flow-delete processing error: continuing on checking further flows", |
| 663 | log.Fields{"device-id": dh.DeviceID, "error": retError}) |
| 664 | errorsList = append(errorsList, retError) |
| 665 | continue |
| 666 | } |
| 667 | } else { |
| 668 | retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID) |
| 669 | errorsList = append(errorsList, retError) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | } |
| 673 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 674 | if apOfFlowChanges.ToAdd != nil { |
| 675 | for _, flowItem := range apOfFlowChanges.ToAdd.Items { |
| 676 | if flowItem.GetCookie() == 0 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 677 | 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] | 678 | "device-id": dh.DeviceID}) |
| 679 | retError = fmt.Errorf("flow-add no cookie, device-id %s", dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 680 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 681 | continue |
| 682 | } |
| 683 | flowInPort := flow.GetInPort(flowItem) |
| 684 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 685 | logger.Warnw(ctx, "flow-add inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 686 | retError = fmt.Errorf("flow-add inPort invalid, device-id %s", dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 687 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 688 | continue |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 689 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 690 | } else if flowInPort == dh.ponPortNumber { |
| 691 | //this is some downstream flow |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 692 | 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] | 693 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 694 | continue |
| 695 | } else { |
| 696 | // this is the relevant upstream flow |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 697 | var loUniPort *cmn.OnuUniPort |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 698 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 699 | loUniPort = uniPort |
| 700 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 701 | 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] | 702 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 703 | 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] | 704 | flowInPort, dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 705 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 706 | continue |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 707 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 708 | // let's still assume that we receive the flow-add only in some 'active' device state (as so far observed) |
| 709 | // if not, we just throw some error here to have an indication about that, if we really need to support that |
| 710 | // then we would need to create some means to activate the internal stored flows |
| 711 | // after the device gets active automatically (and still with its dependency to the TechProfile) |
| 712 | // for state checking compare also code here: processInterAdapterTechProfileDownloadReqMessage |
| 713 | // also abort for the other still possible flows here |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 714 | if !dh.IsReadyForOmciConfig() { |
| 715 | logger.Errorw(ctx, "flow-add rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 716 | "last device-reason": dh.GetDeviceReasonString()}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 717 | retError = fmt.Errorf("improper device state on device %s", dh.DeviceID) |
| 718 | errorsList = append(errorsList, retError) |
| 719 | continue |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 720 | } |
| 721 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 722 | flowOutPort := flow.GetOutPort(flowItem) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 723 | logger.Debugw(ctx, "flow-add port indications", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 724 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 725 | "uniPortName": loUniPort.Name}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 726 | if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) { |
| 727 | // Step1 : Fill flowControlBlock |
| 728 | // Step2 : Push the flowControlBlock to ONU channel |
| 729 | // Step3 : Wait on response channel for response |
| 730 | // Step4 : Return error value |
| 731 | startTime := time.Now() |
| 732 | respChan := make(chan error) |
| 733 | flowCb := FlowCb{ |
| 734 | ctx: ctx, |
| 735 | addFlow: true, |
| 736 | flowItem: flowItem, |
| 737 | flowMetaData: apFlowMetaData, |
| 738 | uniPort: loUniPort, |
| 739 | respChan: &respChan, |
| 740 | } |
| 741 | dh.flowCbChan[loUniPort.UniID] <- flowCb |
| 742 | logger.Infow(ctx, "process-flow-add-start", log.Fields{"device-id": dh.DeviceID}) |
| 743 | // Wait on the channel for flow handlers return value |
| 744 | retError = <-respChan |
| 745 | logger.Infow(ctx, "process-flow-add-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| 746 | if retError != nil { |
| 747 | logger.Warnw(ctx, "flow-add processing error: continuing on checking further flows", |
| 748 | log.Fields{"device-id": dh.DeviceID, "error": retError}) |
| 749 | errorsList = append(errorsList, retError) |
| 750 | continue |
| 751 | } |
| 752 | } else { |
| 753 | retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID) |
| 754 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | } |
| 758 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 759 | if len(errorsList) > 0 { |
| 760 | logger.Errorw(ctx, "error-processing-flow", log.Fields{"device-id": dh.DeviceID, "errList": errorsList}) |
| 761 | return fmt.Errorf("errors-installing-one-or-more-flows-groups, errors:%v", errorsList) |
| 762 | } |
| 763 | return nil |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 764 | } |
| 765 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 766 | //disableDevice locks the ONU and its UNI/VEIP ports (admin lock via OMCI) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 767 | //following are the expected device states after this activity: |
| 768 | //Device Admin-State : down (on rwCore), Port-State: UNKNOWN, Conn-State: REACHABLE, Reason: omci-admin-lock |
| 769 | // (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] | 770 | func (dh *deviceHandler) disableDevice(ctx context.Context, device *voltha.Device) { |
| 771 | 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^] | 772 | dh.mutexForDisableDeviceRequested.Lock() |
| 773 | dh.disableDeviceRequested = true |
| 774 | dh.mutexForDisableDeviceRequested.Unlock() |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 775 | //admin-lock reason can also be used uniquely for setting the DeviceState accordingly |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 776 | //note that disableDevice sequences in some 'ONU active' state may yield also |
| 777 | // "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] | 778 | // - inblock state checking to prevent possibly unneeded processing (on command repitition) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 779 | if dh.getDeviceReason() != cmn.DrOmciAdminLock { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 780 | //disable-device shall be just a UNi/ONU-G related admin state setting |
| 781 | //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] | 782 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 783 | if dh.IsReadyForOmciConfig() { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 784 | // disable UNI ports/ONU |
| 785 | // *** should generate UniDisableStateDone event - used to disable the port(s) on success |
| 786 | if dh.pLockStateFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 787 | dh.createUniLockFsm(ctx, true, cmn.UniDisableStateDone) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 788 | } else { //LockStateFSM already init |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 789 | dh.pLockStateFsm.SetSuccessEvent(cmn.UniDisableStateDone) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 790 | dh.runUniLockFsm(ctx, true) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 791 | } |
| 792 | } else { |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 793 | logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 794 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID}) |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 795 | // disable device should have no impact on ConnStatus |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 796 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 797 | DeviceId: dh.DeviceID, |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 798 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 799 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 800 | }); err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 801 | //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] | 802 | 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] | 803 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 804 | // 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] | 805 | |
| 806 | //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] | 807 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciAdminLock, true) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 808 | } |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 809 | } |
| 810 | } |
| 811 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 812 | //reEnableDevice unlocks the ONU and its UNI/VEIP ports (admin unlock via OMCI) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 813 | func (dh *deviceHandler) reEnableDevice(ctx context.Context, device *voltha.Device) { |
| 814 | 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] | 815 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 816 | //setting readyForOmciConfig here is just a workaround for BBSIM testing in the sequence |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 817 | // OnuSoftReboot-disable-enable, because BBSIM does not generate a new OnuIndication-Up event after SoftReboot |
| 818 | // which is the assumption for real ONU's, where the ready-state is then set according to the following MibUpload/Download |
| 819 | // for real ONU's that should have nearly no influence |
| 820 | // Note that for real ONU's there is anyway a problematic situation with following sequence: |
| 821 | // OnuIndication-Dw (or not active at all) (- disable) - enable: here already the LockFsm may run into timeout (no OmciResponse) |
| 822 | // but that anyway is hopefully resolved by some OnuIndication-Up event (maybe to be tested) |
| 823 | // 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] | 824 | dh.SetReadyForOmciConfig(true) //needed to allow subsequent flow/techProf config (on BBSIM) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 825 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 826 | // enable ONU/UNI ports |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 827 | // *** should generate cmn.UniEnableStateDone event - used to disable the port(s) on success |
ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame^] | 828 | dh.mutexForDisableDeviceRequested.Lock() |
| 829 | dh.disableDeviceRequested = false |
| 830 | dh.mutexForDisableDeviceRequested.Unlock() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 831 | if dh.pUnlockStateFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 832 | dh.createUniLockFsm(ctx, false, cmn.UniEnableStateDone) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 833 | } else { //UnlockStateFSM already init |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 834 | dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniEnableStateDone) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 835 | dh.runUniLockFsm(ctx, false) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 836 | } |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 837 | } |
| 838 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 839 | func (dh *deviceHandler) reconcileDeviceOnuInd(ctx context.Context) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 840 | logger.Debugw(ctx, "reconciling - simulate onu indication", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 841 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 842 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 843 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 844 | 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] | 845 | return |
| 846 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 847 | if err := pDevEntry.RestoreDataFromOnuKvStore(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 848 | if err == fmt.Errorf("no-ONU-data-found") { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 849 | 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] | 850 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 851 | 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] | 852 | } |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 853 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 854 | return |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 855 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 856 | var onuIndication oop.OnuIndication |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 857 | pDevEntry.MutexPersOnuConfig.RLock() |
| 858 | onuIndication.IntfId = pDevEntry.SOnuPersistentData.PersIntfID |
| 859 | onuIndication.OnuId = pDevEntry.SOnuPersistentData.PersOnuID |
| 860 | onuIndication.OperState = pDevEntry.SOnuPersistentData.PersOperState |
| 861 | onuIndication.AdminState = pDevEntry.SOnuPersistentData.PersAdminState |
| 862 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 863 | _ = dh.createInterface(ctx, &onuIndication) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 864 | } |
| 865 | |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 866 | func (dh *deviceHandler) ReconcileDeviceTechProf(ctx context.Context) bool { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 867 | logger.Debugw(ctx, "reconciling - trigger tech profile config", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 868 | |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 869 | continueWithFlowConfig := false |
| 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 | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 873 | 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] | 874 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| 875 | return continueWithFlowConfig |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 876 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 877 | dh.pOnuTP.LockTpProcMutex() |
| 878 | defer dh.pOnuTP.UnlockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 879 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 880 | pDevEntry.MutexPersOnuConfig.RLock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 881 | persMutexLock := true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 882 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 883 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 884 | logger.Debugw(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] | 885 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 886 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| 887 | return continueWithFlowConfig |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 888 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 889 | flowsFound := false |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 890 | techProfsFound := false |
| 891 | techProfInstLoadFailed := false |
| 892 | outerLoop: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 893 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 894 | uniID := uniData.PersUniID |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 895 | //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] | 896 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 897 | logger.Debugw(ctx, "reconciling - no TPs stored for uniID", |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 898 | log.Fields{"uni-id": uniID, "device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 899 | continue |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 900 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 901 | //release MutexPersOnuConfig before TechProfile (ANIConfig) processing as otherwise the reception of |
| 902 | // 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] | 903 | // 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] | 904 | pDevEntry.MutexPersOnuConfig.RUnlock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 905 | persMutexLock = false |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 906 | 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] | 907 | var iaTechTpInst ia.TechProfileDownloadMessage |
| 908 | var ok bool |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 909 | for tpID := range uniData.PersTpPathMap { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 910 | pDevEntry.MutexReconciledTpInstances.RLock() |
| 911 | if iaTechTpInst, ok = pDevEntry.ReconciledTpInstances[uniID][tpID]; !ok { |
| 912 | logger.Errorw(ctx, "reconciling - no reconciled tp instance available", |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 913 | 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] | 914 | "device-id": dh.DeviceID}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 915 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 916 | pDevEntry.MutexReconciledTpInstances.RUnlock() |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 917 | break outerLoop |
| 918 | } |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 919 | pDevEntry.MutexReconciledTpInstances.RUnlock() |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 920 | continueWithFlowConfig = true // valid TP found - try flow configuration later |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 921 | var tpInst tech_profile.TechProfileInstance |
| 922 | switch techTpInst := iaTechTpInst.TechTpInstance.(type) { |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 923 | case *ia.TechProfileDownloadMessage_TpInstance: // supports only GPON, XGPON, XGS-PON |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 924 | tpInst = *techTpInst.TpInstance |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 925 | logger.Debugw(ctx, "reconciling - received-tp-instance-successfully-after-reconcile", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 926 | "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] | 927 | default: // do not support epon or other tech |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 928 | logger.Errorw(ctx, "reconciling - unsupported-tech-profile", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 929 | "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] | 930 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 931 | break outerLoop |
| 932 | } |
| 933 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 934 | // deadline context to ensure completion of background routines waited for |
| 935 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 936 | 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] | 937 | dctx, cancel := context.WithDeadline(ctx, deadline) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 938 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 939 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniData.PersUniID, tpID) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 940 | var wg sync.WaitGroup |
| 941 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 942 | 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] | 943 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfReconcile") //wait for background process to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 944 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniData.PersUniID, tpID); err != nil { |
| 945 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 946 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 947 | break outerLoop |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 948 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 949 | } // for all TpPath entries for this UNI |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 950 | if len(uniData.PersFlowParams) != 0 { |
| 951 | flowsFound = true |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 952 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 953 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 954 | persMutexLock = true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 955 | } // for all UNI entries from SOnuPersistentData |
| 956 | if persMutexLock { // if loop was left with MutexPersOnuConfig still set |
| 957 | pDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 958 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 959 | |
| 960 | //had to move techProf/flow result evaluation into separate function due to SCA complexity limit |
| 961 | dh.updateReconcileStates(ctx, techProfsFound, techProfInstLoadFailed, flowsFound) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 962 | |
| 963 | return continueWithFlowConfig |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | func (dh *deviceHandler) updateReconcileStates(ctx context.Context, |
| 967 | abTechProfsFound bool, abTechProfInstLoadFailed bool, abFlowsFound bool) { |
| 968 | if !abTechProfsFound { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 969 | logger.Debugw(ctx, "reconciling - no TPs have been stored before adapter restart - terminate reconcilement", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 970 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 971 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 972 | return |
| 973 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 974 | if abTechProfInstLoadFailed { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 975 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadFailed, dh.IsReconcilingReasonUpdate()) |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 976 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 977 | return |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 978 | } else if dh.IsSkipOnuConfigReconciling() { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 979 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, dh.IsReconcilingReasonUpdate()) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 980 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 981 | if !abFlowsFound { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 982 | logger.Debugw(ctx, "reconciling - no flows have been stored before adapter restart - terminate reconcilement", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 983 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 984 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 985 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 986 | } |
| 987 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 988 | func (dh *deviceHandler) ReconcileDeviceFlowConfig(ctx context.Context) { |
| 989 | 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] | 990 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 991 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 992 | if pDevEntry == nil { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 993 | 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] | 994 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 995 | return |
| 996 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 997 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 998 | pDevEntry.MutexPersOnuConfig.RLock() |
| 999 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 1000 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1001 | logger.Debugw(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] | 1002 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1003 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1004 | return |
| 1005 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1006 | flowsFound := false |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1007 | var uniVlanConfigEntries []uint8 |
| 1008 | var loWaitGroupWTO cmn.WaitGroupWithTimeOut |
| 1009 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1010 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1011 | //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support |
| 1012 | if len(uniData.PersFlowParams) == 0 { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1013 | logger.Debugw(ctx, "reconciling - no flows stored for uniID", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1014 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1015 | continue |
| 1016 | } |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1017 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1018 | logger.Warnw(ctx, "reconciling flows - but no TPs stored for uniID, abort", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1019 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 1020 | // It doesn't make sense to configure any flows if no TPs are available |
| 1021 | continue |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1022 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1023 | //release MutexPersOnuConfig before VlanConfig processing as otherwise the reception of |
| 1024 | // 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] | 1025 | // 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] | 1026 | pDevEntry.MutexPersOnuConfig.RUnlock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1027 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1028 | var uniPort *cmn.OnuUniPort |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1029 | var exist bool |
Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 1030 | 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] | 1031 | if uniPort, exist = dh.uniEntityMap[uniNo]; !exist { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1032 | logger.Errorw(ctx, "reconciling - OnuUniPort data not found - terminate reconcilement", |
| 1033 | log.Fields{"uniNo": uniNo, "device-id": dh.DeviceID}) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1034 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1035 | return |
| 1036 | } |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1037 | //needed to split up function due to sca complexity |
| 1038 | dh.updateReconcileFlowConfig(ctx, uniPort, uniData.PersFlowParams, uniVlanConfigEntries, &loWaitGroupWTO, &flowsFound) |
| 1039 | |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1040 | logger.Debugw(ctx, "reconciling - flows processed", log.Fields{ |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1041 | "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1042 | "NumUniFlows": dh.UniVlanConfigFsmMap[uniData.PersUniID].NumUniFlows, |
| 1043 | "ConfiguredUniFlow": dh.UniVlanConfigFsmMap[uniData.PersUniID].ConfiguredUniFlow}) |
Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 1044 | // this can't be used as global finished reconciling flag because |
| 1045 | // assumes is getting called before the state machines for the last flow is completed, |
| 1046 | // while this is not guaranteed. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1047 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| 1048 | } // for all UNI entries from SOnuPersistentData |
| 1049 | pDevEntry.MutexPersOnuConfig.RUnlock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1050 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1051 | if !flowsFound { |
| 1052 | logger.Debugw(ctx, "reconciling - no flows have been stored before adapter restart - terminate reconcilement", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1053 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1054 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1055 | return |
| 1056 | } |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1057 | logger.Debugw(ctx, "reconciling flows - waiting on ready indication of requested UNIs", log.Fields{ |
| 1058 | "device-id": dh.DeviceID, "expiry": dh.reconcileExpiryVlanConfig}) |
| 1059 | if executed := loWaitGroupWTO.WaitTimeout(dh.reconcileExpiryVlanConfig); executed { |
| 1060 | logger.Debugw(ctx, "reconciling flows for all UNI's has been finished in time", |
| 1061 | log.Fields{"device-id": dh.DeviceID}) |
| 1062 | dh.stopReconciling(ctx, true, cWaitReconcileFlowAbortOnSuccess) |
| 1063 | if pDevEntry != nil { |
| 1064 | pDevEntry.SendChReconcilingFlowsFinished(ctx, true) |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1065 | } |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1066 | } else { |
| 1067 | logger.Errorw(ctx, "reconciling - timeout waiting for reconciling flows for all UNI's to be finished!", |
| 1068 | log.Fields{"device-id": dh.DeviceID}) |
| 1069 | dh.stopReconciling(ctx, false, cWaitReconcileFlowAbortOnError) |
| 1070 | if pDevEntry != nil { |
| 1071 | pDevEntry.SendChReconcilingFlowsFinished(ctx, false) |
| 1072 | } |
| 1073 | return |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1074 | } |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1075 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsPushed, dh.IsReconcilingReasonUpdate()) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1078 | func (dh *deviceHandler) updateReconcileFlowConfig(ctx context.Context, apUniPort *cmn.OnuUniPort, |
| 1079 | aPersFlowParam []cmn.UniVlanFlowParams, aUniVlanConfigEntries []uint8, |
| 1080 | apWaitGroup *cmn.WaitGroupWithTimeOut, apFlowsFound *bool) { |
| 1081 | flowsProcessed := 0 |
| 1082 | lastFlowToReconcile := false |
| 1083 | loUniID := apUniPort.UniID |
| 1084 | for _, flowData := range aPersFlowParam { |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1085 | if !(*apFlowsFound) { |
| 1086 | *apFlowsFound = true |
| 1087 | syncChannel := make(chan struct{}) |
| 1088 | // start go routine with select() on reconciling vlan config channel before |
| 1089 | // starting vlan config reconciling process to prevent loss of any signal |
| 1090 | // this routine just collects all the received 'flow-reconciled' signals - possibly from different UNI's |
| 1091 | go dh.waitOnUniVlanConfigReconcilingReady(ctx, syncChannel, apWaitGroup) |
| 1092 | //block until the wait routine is really blocked on channel input |
| 1093 | // in order to prevent to early ready signal from VlanConfig processing |
| 1094 | <-syncChannel |
| 1095 | } |
| 1096 | if flowsProcessed == len(aPersFlowParam)-1 { |
| 1097 | var uniAdded bool |
| 1098 | lastFlowToReconcile = true |
| 1099 | if aUniVlanConfigEntries, uniAdded = dh.appendIfMissing(aUniVlanConfigEntries, loUniID); uniAdded { |
| 1100 | apWaitGroup.Add(1) //increment the waiting group |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1101 | } |
| 1102 | } |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1103 | logger.Debugw(ctx, "reconciling - add flow with cookie slice", log.Fields{ |
| 1104 | "device-id": dh.DeviceID, "uni-id": loUniID, |
| 1105 | "flowsProcessed": flowsProcessed, "cookies": flowData.CookieSlice}) |
| 1106 | dh.lockVlanConfig.Lock() |
| 1107 | //the CookieSlice can be passed 'by value' here, - which internally passes its reference |
| 1108 | if _, exist := dh.UniVlanConfigFsmMap[loUniID]; exist { |
| 1109 | if err := dh.UniVlanConfigFsmMap[loUniID].SetUniFlowParams(ctx, flowData.VlanRuleParams.TpID, |
| 1110 | flowData.CookieSlice, uint16(flowData.VlanRuleParams.MatchVid), uint16(flowData.VlanRuleParams.SetVid), |
| 1111 | uint8(flowData.VlanRuleParams.SetPcp), lastFlowToReconcile, flowData.Meter, nil); err != nil { |
| 1112 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1113 | } |
| 1114 | } else { |
| 1115 | if err := dh.createVlanFilterFsm(ctx, apUniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice, |
| 1116 | uint16(flowData.VlanRuleParams.MatchVid), uint16(flowData.VlanRuleParams.SetVid), |
| 1117 | uint8(flowData.VlanRuleParams.SetPcp), cmn.OmciVlanFilterAddDone, lastFlowToReconcile, flowData.Meter, nil); err != nil { |
| 1118 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1119 | } |
| 1120 | } |
| 1121 | dh.lockVlanConfig.Unlock() |
| 1122 | flowsProcessed++ |
| 1123 | } //for all flows of this UNI |
| 1124 | } |
| 1125 | |
| 1126 | //waitOnUniVlanConfigReconcilingReady collects all VlanConfigReady signals from VlanConfig FSM processing in reconciling |
| 1127 | // and decrements the according handler wait group waiting for these indications |
| 1128 | func (dh *deviceHandler) waitOnUniVlanConfigReconcilingReady(ctx context.Context, aSyncChannel chan<- struct{}, |
| 1129 | waitGroup *cmn.WaitGroupWithTimeOut) { |
| 1130 | var reconciledUniVlanConfigEntries []uint8 |
| 1131 | var appended bool |
| 1132 | expiry := dh.GetReconcileExpiryVlanConfigAbort() |
| 1133 | logger.Debugw(ctx, "start waiting on reconcile vlanConfig ready indications", log.Fields{ |
| 1134 | "device-id": dh.DeviceID, "expiry": expiry}) |
| 1135 | // indicate blocking on channel now to the caller |
| 1136 | aSyncChannel <- struct{}{} |
| 1137 | for { |
| 1138 | select { |
| 1139 | case uniIndication := <-dh.chUniVlanConfigReconcilingDone: |
| 1140 | switch uniIndication { |
| 1141 | // no activity requested (should normally not be received) - just continue waiting |
| 1142 | case cWaitReconcileFlowNoActivity: |
| 1143 | // waiting on channel inputs from VlanConfig for all UNI's to be aborted on error condition |
| 1144 | case cWaitReconcileFlowAbortOnError: |
| 1145 | logger.Debugw(ctx, "waitReconcileFlow aborted on error", |
| 1146 | log.Fields{"device-id": dh.DeviceID, "rxEntries": reconciledUniVlanConfigEntries}) |
| 1147 | return |
| 1148 | // waiting on channel inputs from VlanConfig for all UNI's to be aborted on success condition |
| 1149 | case cWaitReconcileFlowAbortOnSuccess: |
| 1150 | logger.Debugw(ctx, "waitReconcileFlow aborted on success", |
| 1151 | log.Fields{"device-id": dh.DeviceID, "rxEntries": reconciledUniVlanConfigEntries}) |
| 1152 | return |
| 1153 | // this should be a valid UNI vlan config done indication |
| 1154 | default: |
| 1155 | if uniIndication < platform.MaxUnisPerOnu { |
| 1156 | logger.Debugw(ctx, "reconciling flows has been finished in time for this UNI", |
| 1157 | log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| 1158 | if reconciledUniVlanConfigEntries, appended = |
| 1159 | dh.appendIfMissing(reconciledUniVlanConfigEntries, uint8(uniIndication)); appended { |
| 1160 | waitGroup.Done() |
| 1161 | } |
| 1162 | } else { |
| 1163 | logger.Errorw(ctx, "received unexpected UNI flowConfig done indication - is ignored", |
| 1164 | log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| 1165 | } |
| 1166 | } //switch uniIndication |
| 1167 | |
| 1168 | case <-time.After(expiry): //a bit longer than reconcileExpiryVlanConfig |
| 1169 | logger.Errorw(ctx, "timeout waiting for reconciling all UNI flows to be finished!", |
| 1170 | log.Fields{"device-id": dh.DeviceID}) |
| 1171 | return |
| 1172 | } |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | func (dh *deviceHandler) GetReconcileExpiryVlanConfigAbort() time.Duration { |
| 1177 | return dh.reconcileExpiryVlanConfig + (500 * time.Millisecond) |
| 1178 | } |
| 1179 | |
| 1180 | func (dh *deviceHandler) appendIfMissing(slice []uint8, val uint8) ([]uint8, bool) { |
| 1181 | for _, ele := range slice { |
| 1182 | if ele == val { |
| 1183 | return slice, false |
| 1184 | } |
| 1185 | } |
| 1186 | return append(slice, val), true |
| 1187 | } |
| 1188 | |
| 1189 | // sendChReconcileFinished - sends true or false on reconcileFinish channel |
| 1190 | func (dh *deviceHandler) sendChReconcileFinished(success bool) { |
| 1191 | if dh != nil { //if the object still exists (might have been already deleted in background) |
| 1192 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1193 | select { |
| 1194 | case dh.chReconcilingFinished <- success: |
| 1195 | default: |
| 1196 | } |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | // SendChUniVlanConfigFinished - sends the Uni number on channel if the flow reconcilement for this UNI is finished |
| 1201 | func (dh *deviceHandler) SendChUniVlanConfigFinished(value uint16) { |
| 1202 | if dh != nil { //if the object still exists (might have been already deleted in background) |
| 1203 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1204 | select { |
| 1205 | case dh.chUniVlanConfigReconcilingDone <- value: |
| 1206 | default: |
| 1207 | } |
| 1208 | } |
| 1209 | } |
| 1210 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1211 | func (dh *deviceHandler) deleteDevicePersistencyData(ctx context.Context) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1212 | 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] | 1213 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1214 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1215 | if pDevEntry == nil { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1216 | //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] | 1217 | 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] | 1218 | return nil |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1219 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1220 | |
| 1221 | // deadline context to ensure completion of background routines waited for |
| 1222 | //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] | 1223 | 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] | 1224 | dctx, cancel := context.WithDeadline(ctx, deadline) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1225 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1226 | pDevEntry.ResetKvProcessingErrorIndication() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1227 | |
| 1228 | var wg sync.WaitGroup |
| 1229 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1230 | go pDevEntry.DeleteDataFromOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1231 | dh.waitForCompletion(ctx, cancel, &wg, "DeleteDevice") //wait for background process to finish |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1232 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1233 | // TODO: further actions - stop metrics and FSMs, remove device ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1234 | return pDevEntry.GetKvProcessingErrorIndication() |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1237 | //func (dh *deviceHandler) rebootDevice(ctx context.Context, device *voltha.Device) error { |
| 1238 | // before this change here return like this was used: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1239 | // return fmt.Errorf("device-unreachable: %s, %s", dh.DeviceID, device.SerialNumber) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1240 | //was and is called in background - error return does not make sense |
| 1241 | func (dh *deviceHandler) rebootDevice(ctx context.Context, aCheckDeviceState bool, device *voltha.Device) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1242 | 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] | 1243 | if aCheckDeviceState && device.ConnectStatus != voltha.ConnectStatus_REACHABLE { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1244 | 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] | 1245 | return |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1246 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1247 | if err := dh.pOnuOmciDevice.Reboot(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1248 | //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] | 1249 | 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] | 1250 | return |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1251 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1252 | |
| 1253 | //transfer the possibly modified logical uni port state |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1254 | dh.DisableUniPortStateUpdate(ctx) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1255 | |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 1256 | logger.Debugw(ctx, "call DeviceStateUpdate upon reboot", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1257 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID}) |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 1258 | // 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] | 1259 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1260 | DeviceId: dh.DeviceID, |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 1261 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1262 | OperStatus: voltha.OperStatus_DISCOVERED, |
| 1263 | }); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1264 | //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] | 1265 | 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] | 1266 | return |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1267 | } |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 1268 | if err := dh.ReasonUpdate(ctx, cmn.DrRebooting, true); err != nil { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1269 | return |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1270 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1271 | dh.SetReadyForOmciConfig(false) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1272 | //no specific activity to synchronize any internal FSM to the 'rebooted' state is explicitly done here |
| 1273 | // the expectation ids for a real device, that it will be synced with the expected following 'down' indication |
| 1274 | // as BBSIM does not support this testing requires explicite disable/enable device calls in which sequence also |
| 1275 | // all other FSM's should be synchronized again |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1276 | } |
| 1277 | |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 1278 | //doOnuSwUpgrade initiates the SW download transfer to the ONU and on success activates the (inactive) image |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1279 | // used only for old - R2.7 style - upgrade API |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1280 | func (dh *deviceHandler) doOnuSwUpgrade(ctx context.Context, apImageDsc *voltha.ImageDownload, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1281 | apDownloadManager *swupg.AdapterDownloadManager) error { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1282 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1283 | "device-id": dh.DeviceID, "image-name": (*apImageDsc).Name}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1284 | |
| 1285 | var err error |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1286 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1287 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1288 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1289 | 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] | 1290 | } |
| 1291 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1292 | if dh.IsReadyForOmciConfig() { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1293 | var inactiveImageID uint16 |
| 1294 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1295 | dh.lockUpgradeFsm.Lock() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1296 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| 1297 | // but must be still locked at calling createOnuUpgradeFsm |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1298 | if dh.pOnuUpradeFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1299 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1300 | dh.lockUpgradeFsm.Unlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1301 | if err == nil { |
| 1302 | if err = dh.pOnuUpradeFsm.SetDownloadParams(ctx, inactiveImageID, apImageDsc, apDownloadManager); err != nil { |
| 1303 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1304 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1305 | } |
| 1306 | } else { |
| 1307 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1308 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1309 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1310 | } else { //OnuSw upgrade already running - restart (with possible abort of running) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1311 | dh.lockUpgradeFsm.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1312 | 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] | 1313 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1314 | dh.upgradeCanceled = true |
| 1315 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1316 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1317 | //no effort spent anymore for the old API to automatically cancel and restart the download |
| 1318 | // like done for the new API |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1319 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1320 | } else { |
| 1321 | 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] | 1322 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1323 | } |
| 1324 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1325 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no active OMCI connection", log.Fields{"device-id": dh.DeviceID}) |
| 1326 | 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] | 1327 | } |
| 1328 | return err |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1331 | //onuSwUpgradeAfterDownload initiates the SW download transfer to the ONU with activate and commit options |
| 1332 | // after the OnuImage has been downloaded to the adapter, called in background |
| 1333 | func (dh *deviceHandler) onuSwUpgradeAfterDownload(ctx context.Context, apImageRequest *voltha.DeviceImageDownloadRequest, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1334 | apDownloadManager *swupg.FileDownloadManager, aImageIdentifier string) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1335 | |
| 1336 | var err error |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1337 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1338 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1339 | 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] | 1340 | return |
| 1341 | } |
| 1342 | |
| 1343 | var inactiveImageID uint16 |
| 1344 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1345 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1346 | "device-id": dh.DeviceID, "image-version": apImageRequest.Image.Version, "to onu-image": inactiveImageID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1347 | |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1348 | dh.lockUpgradeFsm.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1349 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1350 | // but must be still locked at calling createOnuUpgradeFsm |
| 1351 | // (and working with a local pointer copy does not work here if asynchronous request are done to fast |
| 1352 | // [e.g.leaving the local pointer on nil even though a creation is already on the way]) |
| 1353 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1354 | //OnuSw upgrade already running on this device (e.g. with activate/commit not yet set) |
| 1355 | // abort the current processing, running upgrades are always aborted by newer request |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1356 | 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] | 1357 | //flush the remove upgradeFsmChan channel |
| 1358 | select { |
| 1359 | case <-dh.upgradeFsmChan: |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1360 | logger.Debugw(ctx, "flushed-upgrade-fsm-channel", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1361 | default: |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1362 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1363 | dh.lockUpgradeFsm.Unlock() |
| 1364 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1365 | dh.upgradeCanceled = true |
| 1366 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1367 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1368 | select { |
| 1369 | case <-time.After(cTimeOutRemoveUpgrade * time.Second): |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1370 | 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] | 1371 | //should not appear, can't proceed with new upgrade, perhaps operator can retry manually later |
| 1372 | return |
| 1373 | case <-dh.upgradeFsmChan: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1374 | 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] | 1375 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1376 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1377 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1378 | |
| 1379 | //here it can be assumed that no running upgrade processing exists (anymore) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1380 | //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] | 1381 | // but none yet defined |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1382 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1383 | dh.lockUpgradeFsm.Unlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1384 | if err == nil { |
| 1385 | if err = dh.pOnuUpradeFsm.SetDownloadParamsAfterDownload(ctx, inactiveImageID, |
| 1386 | apImageRequest, apDownloadManager, aImageIdentifier); err != nil { |
| 1387 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1388 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1389 | return |
| 1390 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1391 | } else { |
| 1392 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1393 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1394 | } |
| 1395 | return |
| 1396 | } |
| 1397 | 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] | 1398 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | //onuSwActivateRequest ensures activation of the requested image with commit options |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1402 | func (dh *deviceHandler) onuSwActivateRequest(ctx context.Context, |
| 1403 | aVersion string, aCommitRequest bool) (*voltha.ImageState, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1404 | var err error |
| 1405 | //SW activation for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1406 | // 1.) activation of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1407 | // 2.) activation of the inactive image |
| 1408 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1409 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1410 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1411 | logger.Errorw(ctx, "Onu image activation rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1412 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1413 | } |
| 1414 | dh.lockUpgradeFsm.RLock() |
| 1415 | if dh.pOnuUpradeFsm != nil { |
| 1416 | dh.lockUpgradeFsm.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1417 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1418 | if getErr != nil || onuVolthaDevice == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1419 | logger.Errorw(ctx, "Failed to fetch Onu device for image activation", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1420 | 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] | 1421 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1422 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1423 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1424 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1425 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1426 | // use the OnuVendor identification from this device for the internal unique name |
| 1427 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1428 | // 1.) check a started upgrade process and relay the activation request to it |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1429 | if err = dh.pOnuUpradeFsm.SetActivationParamsRunning(ctx, imageIdentifier, aCommitRequest); err != nil { |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1430 | //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] | 1431 | 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] | 1432 | "device-id": dh.DeviceID, "error": err}) |
| 1433 | 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] | 1434 | } |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1435 | logger.Debugw(ctx, "image activation acknowledged by onu upgrade processing", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1436 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1437 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1438 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1439 | } //else |
| 1440 | dh.lockUpgradeFsm.RUnlock() |
| 1441 | |
| 1442 | // 2.) check if requested image-version equals the inactive one and start its activation |
| 1443 | // (image version is not [yet] checked - would be possible, but with increased effort ...) |
| 1444 | var inactiveImageID uint16 |
| 1445 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err != nil || inactiveImageID > 1 { |
| 1446 | logger.Errorw(ctx, "get inactive image failed", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1447 | "device-id": dh.DeviceID, "err": err, "image-id": inactiveImageID}) |
| 1448 | 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] | 1449 | } |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1450 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1451 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1452 | dh.lockUpgradeFsm.Unlock() |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1453 | if err == nil { |
| 1454 | if err = dh.pOnuUpradeFsm.SetActivationParamsStart(ctx, aVersion, |
| 1455 | inactiveImageID, aCommitRequest); err != nil { |
| 1456 | 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] | 1457 | "device-id": dh.DeviceID, "error": err}) |
| 1458 | 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] | 1459 | } |
| 1460 | logger.Debugw(ctx, "inactive image activation acknowledged by onu upgrade", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1461 | "device-id": dh.DeviceID, "image-version": aVersion}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1462 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1463 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1464 | } //else |
| 1465 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1466 | "device-id": dh.DeviceID, "error": err}) |
| 1467 | 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] | 1468 | } |
| 1469 | |
| 1470 | //onuSwCommitRequest ensures commitment of the requested image |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1471 | func (dh *deviceHandler) onuSwCommitRequest(ctx context.Context, |
| 1472 | aVersion string) (*voltha.ImageState, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1473 | var err error |
| 1474 | //SW commitment for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1475 | // 1.) commitment of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1476 | // 2.) commitment of the active image |
| 1477 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1478 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1479 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1480 | logger.Errorw(ctx, "Onu image commitment rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1481 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1482 | } |
| 1483 | dh.lockUpgradeFsm.RLock() |
| 1484 | if dh.pOnuUpradeFsm != nil { |
| 1485 | dh.lockUpgradeFsm.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1486 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1487 | if getErr != nil || onuVolthaDevice == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1488 | logger.Errorw(ctx, "Failed to fetch Onu device for image commitment", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1489 | 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] | 1490 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1491 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1492 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1493 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1494 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1495 | // use the OnuVendor identification from this device for the internal unique name |
| 1496 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1497 | // 1.) check a started upgrade process and relay the commitment request to it |
| 1498 | // the running upgrade may be based either on the imageIdentifier (started from download) |
| 1499 | // or on the imageVersion (started from pure activation) |
| 1500 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsRunning(ctx, imageIdentifier, aVersion); err != nil { |
| 1501 | //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] | 1502 | 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] | 1503 | "device-id": dh.DeviceID, "error": err}) |
| 1504 | 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] | 1505 | } |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1506 | logger.Debugw(ctx, "image commitment acknowledged by onu upgrade processing", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1507 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1508 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1509 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1510 | } //else |
| 1511 | dh.lockUpgradeFsm.RUnlock() |
| 1512 | |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1513 | // 2.) use the active image to directly commit |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1514 | var activeImageID uint16 |
| 1515 | if activeImageID, err = pDevEntry.GetActiveImageMeID(ctx); err != nil || activeImageID > 1 { |
| 1516 | logger.Errorw(ctx, "get active image failed", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1517 | "device-id": dh.DeviceID, "err": err, "image-id": activeImageID}) |
| 1518 | 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] | 1519 | } |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1520 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1521 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1522 | dh.lockUpgradeFsm.Unlock() |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1523 | if err == nil { |
| 1524 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsStart(ctx, aVersion, activeImageID); err != nil { |
| 1525 | 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] | 1526 | "device-id": dh.DeviceID, "error": err}) |
| 1527 | 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] | 1528 | } |
| 1529 | logger.Debugw(ctx, "active image commitment acknowledged by onu upgrade", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1530 | "device-id": dh.DeviceID, "image-version": aVersion}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1531 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1532 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1533 | } //else |
| 1534 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1535 | "device-id": dh.DeviceID, "error": err}) |
| 1536 | 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] | 1537 | } |
| 1538 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1539 | func (dh *deviceHandler) requestOnuSwUpgradeState(ctx context.Context, aImageIdentifier string, |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1540 | aVersion string) *voltha.ImageState { |
| 1541 | var pImageState *voltha.ImageState |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1542 | dh.lockUpgradeFsm.RLock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1543 | defer dh.lockUpgradeFsm.RUnlock() |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1544 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1545 | pImageState = dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1546 | } else { //use the last stored ImageState (if the requested Imageversion coincides) |
| 1547 | if aVersion == dh.pLastUpgradeImageState.Version { |
| 1548 | pImageState = dh.pLastUpgradeImageState |
| 1549 | } else { //state request for an image version different from last processed image version |
| 1550 | pImageState = &voltha.ImageState{ |
| 1551 | Version: aVersion, |
| 1552 | //we cannot state something concerning this version |
| 1553 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 1554 | Reason: voltha.ImageState_NO_ERROR, |
| 1555 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 1556 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1557 | } |
| 1558 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1559 | return pImageState |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | func (dh *deviceHandler) cancelOnuSwUpgrade(ctx context.Context, aImageIdentifier string, |
| 1563 | aVersion string, pDeviceImageState *voltha.DeviceImageState) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1564 | pDeviceImageState.DeviceId = dh.DeviceID |
mpagenko | 7455fd4 | 2021-06-10 16:25:55 +0000 | [diff] [blame] | 1565 | pDeviceImageState.ImageState.Version = aVersion |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1566 | dh.lockUpgradeFsm.RLock() |
| 1567 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1568 | dh.lockUpgradeFsm.RUnlock() |
| 1569 | // so then we cancel the upgrade operation |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1570 | // but before we still request the actual upgrade states for the direct response |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1571 | pImageState := dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1572 | pDeviceImageState.ImageState.DownloadState = pImageState.DownloadState |
| 1573 | pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST |
| 1574 | pDeviceImageState.ImageState.ImageState = pImageState.ImageState |
| 1575 | if pImageState.DownloadState != voltha.ImageState_DOWNLOAD_UNKNOWN { |
| 1576 | //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] | 1577 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1578 | dh.upgradeCanceled = true |
| 1579 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1580 | } |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1581 | } //nothing to cancel (upgrade FSM for different image stays alive) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1582 | } else { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1583 | dh.lockUpgradeFsm.RUnlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1584 | // if no upgrade is ongoing, nothing is canceled and accordingly the states of the requested image are unknown |
| 1585 | // reset also the dh handler LastUpgradeImageState (not relevant anymore/cleared) |
| 1586 | (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1587 | (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR |
| 1588 | (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1589 | (*dh.pLastUpgradeImageState).Version = "" //reset to 'no (relevant) upgrade done' (like initial state) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1590 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1591 | pDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1592 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1593 | //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] | 1594 | } |
| 1595 | } |
| 1596 | |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1597 | func (dh *deviceHandler) getOnuImages(ctx context.Context) (*voltha.OnuImages, error) { |
| 1598 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1599 | var onuImageStatus *swupg.OnuImageStatus |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1600 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1601 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1602 | if pDevEntry != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1603 | onuImageStatus = swupg.NewOnuImageStatus(dh, pDevEntry) |
| 1604 | pDevEntry.MutexOnuImageStatus.Lock() |
| 1605 | pDevEntry.POnuImageStatus = onuImageStatus |
| 1606 | pDevEntry.MutexOnuImageStatus.Unlock() |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1607 | |
| 1608 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1609 | 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] | 1610 | return nil, fmt.Errorf("no-valid-OnuDevice-aborting") |
| 1611 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1612 | images, err := onuImageStatus.GetOnuImageStatus(ctx) |
| 1613 | pDevEntry.MutexOnuImageStatus.Lock() |
| 1614 | pDevEntry.POnuImageStatus = nil |
| 1615 | pDevEntry.MutexOnuImageStatus.Unlock() |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1616 | return images, err |
| 1617 | } |
| 1618 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1619 | // deviceHandler methods that implement the adapters interface requests## end ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1620 | // ##################################################################################### |
| 1621 | |
| 1622 | // ################ to be updated acc. needs of ONU Device ######################## |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1623 | // deviceHandler StateMachine related state transition methods ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1624 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1625 | func (dh *deviceHandler) logStateChange(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1626 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"event name": string(e.Event), |
| 1627 | "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] | 1628 | } |
| 1629 | |
| 1630 | // doStateInit provides the device update to the core |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1631 | func (dh *deviceHandler) doStateInit(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1632 | |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1633 | logger.Debugw(ctx, "doStateInit-started", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1634 | var err error |
| 1635 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1636 | // populate what we know. rest comes later after mib sync |
| 1637 | dh.device.Root = false |
| 1638 | dh.device.Vendor = "OpenONU" |
| 1639 | dh.device.Model = "go" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1640 | dh.device.Reason = cmn.DeviceReasonMap[cmn.DrActivatingOnu] |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 1641 | _ = dh.ReasonUpdate(ctx, cmn.DrActivatingOnu, false) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1642 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1643 | dh.logicalDeviceID = dh.DeviceID // really needed - what for ??? //TODO!!! |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1644 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1645 | if !dh.IsReconciling() { |
| 1646 | logger.Infow(ctx, "DeviceUpdate", log.Fields{"deviceReason": dh.device.Reason, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1647 | if err := dh.updateDeviceInCore(ctx, dh.device); err != nil { |
| 1648 | logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err}) |
| 1649 | } |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 1650 | //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] | 1651 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1652 | logger.Debugw(ctx, "reconciling - don't notify core about DeviceUpdate", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1653 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1654 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1655 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1656 | dh.parentID = dh.device.ParentId |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1657 | dh.ponPortNumber = dh.device.ParentPortNo |
| 1658 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1659 | // store proxy parameters for later communication - assumption: invariant, else they have to be requested dynamically!! |
| 1660 | dh.ProxyAddressID = dh.device.ProxyAddress.GetDeviceId() |
| 1661 | dh.ProxyAddressType = dh.device.ProxyAddress.GetDeviceType() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1662 | 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] | 1663 | "proxyAddressType": dh.ProxyAddressType, "SNR": dh.device.SerialNumber, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1664 | "ParentId": dh.parentID, "ParentPortNo": dh.ponPortNumber}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1665 | |
| 1666 | /* |
| 1667 | self._pon = PonPort.create(self, self._pon_port_number) |
| 1668 | self._pon.add_peer(self.parent_id, self._pon_port_number) |
| 1669 | self.logger.debug('adding-pon-port-to-agent', |
| 1670 | type=self._pon.get_port().type, |
| 1671 | admin_state=self._pon.get_port().admin_state, |
| 1672 | oper_status=self._pon.get_port().oper_status, |
| 1673 | ) |
| 1674 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1675 | if !dh.IsReconciling() { |
| 1676 | logger.Debugw(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] | 1677 | var ponPortNo uint32 = 1 |
| 1678 | if dh.ponPortNumber != 0 { |
| 1679 | ponPortNo = dh.ponPortNumber |
| 1680 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1681 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1682 | pPonPort := &voltha.Port{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1683 | DeviceId: dh.DeviceID, |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1684 | PortNo: ponPortNo, |
| 1685 | Label: fmt.Sprintf("pon-%d", ponPortNo), |
| 1686 | Type: voltha.Port_PON_ONU, |
| 1687 | OperStatus: voltha.OperStatus_ACTIVE, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1688 | Peers: []*voltha.Port_PeerPort{{DeviceId: dh.parentID, // Peer device is OLT |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1689 | PortNo: ponPortNo}}, // Peer port is parent's port number |
| 1690 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1691 | if err = dh.CreatePortInCore(ctx, pPonPort); err != nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1692 | logger.Fatalf(ctx, "Device FSM: PortCreated-failed-%s:%s", err, dh.DeviceID) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1693 | e.Cancel(err) |
| 1694 | return |
| 1695 | } |
| 1696 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1697 | logger.Debugw(ctx, "reconciling - pon-port already added", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1698 | } |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1699 | logger.Debugw(ctx, "doStateInit-done", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | // postInit setups the DeviceEntry for the conerned device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1703 | func (dh *deviceHandler) postInit(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1704 | |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1705 | logger.Debugw(ctx, "postInit-started", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1706 | var err error |
| 1707 | /* |
| 1708 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
| 1709 | dh.pTransitionMap.Handle(ctx, GrpcConnected) |
| 1710 | return nil |
| 1711 | */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1712 | if err = dh.addOnuDeviceEntry(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1713 | logger.Fatalf(ctx, "Device FSM: addOnuDeviceEntry-failed-%s:%s", err, dh.DeviceID) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1714 | e.Cancel(err) |
| 1715 | return |
| 1716 | } |
| 1717 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1718 | if dh.IsReconciling() { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1719 | go dh.reconcileDeviceOnuInd(ctx) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1720 | // reconcilement will be continued after mib download is done |
| 1721 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1722 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1723 | /* |
| 1724 | ############################################################################ |
| 1725 | # Setup Alarm handler |
| 1726 | self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id, |
| 1727 | device.serial_number) |
| 1728 | ############################################################################ |
| 1729 | # Setup PM configuration for this device |
| 1730 | # Pass in ONU specific options |
| 1731 | kwargs = { |
| 1732 | OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY, |
| 1733 | 'heartbeat': self.heartbeat, |
| 1734 | OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device |
| 1735 | } |
| 1736 | self.logger.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number) |
| 1737 | self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id, |
| 1738 | self.logical_device_id, device.serial_number, |
| 1739 | grouped=True, freq_override=False, **kwargs) |
| 1740 | pm_config = self._pm_metrics.make_proto() |
| 1741 | self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm) |
| 1742 | self.logger.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number) |
| 1743 | yield self.core_proxy.device_pm_config_update(pm_config, init=True) |
| 1744 | |
| 1745 | # Note, ONU ID and UNI intf set in add_uni_port method |
| 1746 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events, |
| 1747 | ani_ports=[self._pon]) |
| 1748 | |
| 1749 | # Code to Run OMCI Test Action |
| 1750 | kwargs_omci_test_action = { |
| 1751 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 1752 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 1753 | } |
| 1754 | serial_number = device.serial_number |
| 1755 | self._test_request = OmciTestRequest(self.core_proxy, |
| 1756 | self.omci_agent, self.device_id, |
| 1757 | AniG, serial_number, |
| 1758 | self.logical_device_id, |
| 1759 | exclusive=False, |
| 1760 | **kwargs_omci_test_action) |
| 1761 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1762 | self.Enabled = True |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1763 | else: |
| 1764 | self.logger.info('onu-already-activated') |
| 1765 | */ |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1766 | |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1767 | logger.Debugw(ctx, "postInit-done", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | // doStateConnected get the device info and update to voltha core |
| 1771 | // for comparison of the original method (not that easy to uncomment): compare here: |
| 1772 | // voltha-openolt-adapter/adaptercore/device_handler.go |
| 1773 | // -> this one obviously initiates all communication interfaces of the device ...? |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1774 | func (dh *deviceHandler) doStateConnected(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1775 | |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1776 | logger.Debugw(ctx, "doStateConnected-started", log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1777 | err := errors.New("device FSM: function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1778 | e.Cancel(err) |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1779 | logger.Debugw(ctx, "doStateConnected-done", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | // doStateUp handle the onu up indication and update to voltha core |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1783 | func (dh *deviceHandler) doStateUp(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1784 | |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1785 | logger.Debugw(ctx, "doStateUp-started", log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1786 | err := errors.New("device FSM: function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1787 | e.Cancel(err) |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1788 | logger.Debugw(ctx, "doStateUp-done", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1789 | |
| 1790 | /* |
| 1791 | // Synchronous call to update device state - this method is run in its own go routine |
| 1792 | if err := dh.coreProxy.DeviceStateUpdate(ctx, dh.device.Id, voltha.ConnectStatus_REACHABLE, |
| 1793 | voltha.OperStatus_ACTIVE); err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1794 | 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] | 1795 | return err |
| 1796 | } |
| 1797 | return nil |
| 1798 | */ |
| 1799 | } |
| 1800 | |
| 1801 | // doStateDown handle the onu down indication |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1802 | func (dh *deviceHandler) doStateDown(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1803 | |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1804 | logger.Debugw(ctx, "doStateDown-started", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1805 | var err error |
| 1806 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1807 | device := dh.device |
| 1808 | if device == nil { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1809 | /*TODO: needs to handle error scenarios */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1810 | 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] | 1811 | e.Cancel(err) |
| 1812 | return |
| 1813 | } |
| 1814 | |
| 1815 | cloned := proto.Clone(device).(*voltha.Device) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1816 | logger.Debugw(ctx, "do-state-down", log.Fields{"ClonedDeviceID": cloned.Id}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1817 | /* |
| 1818 | // Update the all ports state on that device to disable |
| 1819 | if er := dh.coreProxy.PortsStateUpdate(ctx, cloned.Id, voltha.OperStatus_UNKNOWN); er != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1820 | 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] | 1821 | return er |
| 1822 | } |
| 1823 | |
| 1824 | //Update the device oper state and connection status |
| 1825 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 1826 | cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE |
| 1827 | dh.device = cloned |
| 1828 | |
| 1829 | 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] | 1830 | 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] | 1831 | return er |
| 1832 | } |
| 1833 | |
| 1834 | //get the child device for the parent device |
| 1835 | onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id) |
| 1836 | if err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1837 | 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] | 1838 | return err |
| 1839 | } |
| 1840 | for _, onuDevice := range onuDevices.Items { |
| 1841 | |
| 1842 | // Update onu state as down in onu adapter |
| 1843 | onuInd := oop.OnuIndication{} |
| 1844 | onuInd.OperState = "down" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1845 | er := dh.adapterProxy.SendInterAdapterMessage(ctx, &onuInd, ca.InterAdapterMessageType_ONU_IND_REQUEST, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1846 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 1847 | if er != nil { |
| 1848 | logger.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1849 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "device-id": onuDevice.Id}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1850 | //Do not return here and continue to process other ONUs |
| 1851 | } |
| 1852 | } |
| 1853 | // * Discovered ONUs entries need to be cleared , since after OLT |
| 1854 | // is up, it starts sending discovery indications again* / |
| 1855 | dh.discOnus = sync.Map{} |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1856 | logger.Debugw("do-state-down-end", log.Fields{"device-id": device.Id}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1857 | return nil |
| 1858 | */ |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1859 | err = errors.New("device FSM: function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1860 | e.Cancel(err) |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1861 | logger.Debugw(ctx, "doStateDown-done", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1864 | // deviceHandler StateMachine related state transition methods ##### end ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1865 | // ################################################################################# |
| 1866 | |
| 1867 | // ################################################### |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1868 | // deviceHandler utility methods ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1869 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1870 | //GetOnuDeviceEntry gets the ONU device entry and may wait until its value is defined |
| 1871 | func (dh *deviceHandler) GetOnuDeviceEntry(ctx context.Context, aWait bool) *mib.OnuDeviceEntry { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1872 | dh.lockDevice.RLock() |
| 1873 | pOnuDeviceEntry := dh.pOnuOmciDevice |
| 1874 | if aWait && pOnuDeviceEntry == nil { |
| 1875 | //keep the read sema short to allow for subsequent write |
| 1876 | dh.lockDevice.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1877 | 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] | 1878 | // based on concurrent processing the deviceEntry setup may not yet be finished at his point |
| 1879 | // so it might be needed to wait here for that event with some timeout |
| 1880 | select { |
| 1881 | case <-time.After(60 * time.Second): //timer may be discussed ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1882 | 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] | 1883 | return nil |
| 1884 | case <-dh.deviceEntrySet: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1885 | logger.Debugw(ctx, "devicEntry ready now - continue", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1886 | // if written now, we can return the written value without sema |
| 1887 | return dh.pOnuOmciDevice |
| 1888 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1889 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1890 | dh.lockDevice.RUnlock() |
| 1891 | return pOnuDeviceEntry |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1892 | } |
| 1893 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1894 | //setDeviceHandlerEntries sets the ONU device entry within the handler |
| 1895 | func (dh *deviceHandler) setDeviceHandlerEntries(apDeviceEntry *mib.OnuDeviceEntry, apOnuTp *avcfg.OnuUniTechProf, |
| 1896 | apOnuMetricsMgr *pmmgr.OnuMetricsManager, apOnuAlarmMgr *almgr.OnuAlarmManager, apSelfTestHdlr *otst.SelfTestControlBlock) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1897 | dh.lockDevice.Lock() |
| 1898 | defer dh.lockDevice.Unlock() |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 1899 | dh.pOnuOmciDevice = apDeviceEntry |
| 1900 | dh.pOnuTP = apOnuTp |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1901 | dh.pOnuMetricsMgr = apOnuMetricsMgr |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 1902 | dh.pAlarmMgr = apOnuAlarmMgr |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 1903 | dh.pSelfTestHdlr = apSelfTestHdlr |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1906 | //addOnuDeviceEntry creates a new ONU device or returns the existing |
| 1907 | func (dh *deviceHandler) addOnuDeviceEntry(ctx context.Context) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1908 | logger.Debugw(ctx, "adding-deviceEntry", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1909 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1910 | deviceEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1911 | if deviceEntry == nil { |
| 1912 | /* costum_me_map in python code seems always to be None, |
| 1913 | we omit that here first (declaration unclear) -> todo at Adapter specialization ...*/ |
| 1914 | /* also no 'clock' argument - usage open ...*/ |
| 1915 | /* and no alarm_db yet (oo.alarm_db) */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1916 | deviceEntry = mib.NewOnuDeviceEntry(ctx, dh.coreClient, dh, dh.pOpenOnuAc) |
| 1917 | onuTechProfProc := avcfg.NewOnuUniTechProf(ctx, dh, deviceEntry) |
| 1918 | onuMetricsMgr := pmmgr.NewOnuMetricsManager(ctx, dh, deviceEntry) |
| 1919 | onuAlarmManager := almgr.NewAlarmManager(ctx, dh, deviceEntry) |
| 1920 | selfTestHdlr := otst.NewSelfTestMsgHandlerCb(ctx, dh, deviceEntry) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1921 | //error treatment possible //TODO!!! |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1922 | dh.setDeviceHandlerEntries(deviceEntry, onuTechProfProc, onuMetricsMgr, onuAlarmManager, selfTestHdlr) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1923 | // fire deviceEntry ready event to spread to possibly waiting processing |
| 1924 | dh.deviceEntrySet <- true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1925 | logger.Debugw(ctx, "onuDeviceEntry-added", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1926 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1927 | 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] | 1928 | } |
| 1929 | // might be updated with some error handling !!! |
| 1930 | return nil |
| 1931 | } |
| 1932 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1933 | func (dh *deviceHandler) createInterface(ctx context.Context, onuind *oop.OnuIndication) error { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1934 | 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] | 1935 | "OnuIntfId": onuind.GetIntfId(), "OnuSerialNumber": onuind.GetSerialNumber()}) |
| 1936 | |
| 1937 | dh.pOnuIndication = onuind // let's revise if storing the pointer is sufficient... |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1938 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1939 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1940 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1941 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 1942 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1943 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1944 | if !dh.IsReconciling() { |
| 1945 | if err := dh.StorePersistentData(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1946 | 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] | 1947 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1948 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1949 | 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] | 1950 | "OperStatus": voltha.OperStatus_ACTIVATING, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1951 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1952 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1953 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1954 | OperStatus: voltha.OperStatus_ACTIVATING, |
| 1955 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 1956 | }); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1957 | //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] | 1958 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1959 | } |
| 1960 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1961 | logger.Debugw(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVATING", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1962 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1963 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1964 | pDevEntry.MutexPersOnuConfig.RLock() |
| 1965 | if !pDevEntry.SOnuPersistentData.PersUniUnlockDone { |
| 1966 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1967 | 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] | 1968 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1969 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1970 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1971 | pDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1972 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1973 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1974 | // It does not look to me as if makes sense to work with the real core device here, (not the stored clone)? |
| 1975 | // in this code the GetDevice would just make a check if the DeviceID's Device still exists in core |
| 1976 | // 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] | 1977 | // 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] | 1978 | // so let's just try to keep it simple ... |
| 1979 | /* |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1980 | 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] | 1981 | if err != nil || device == nil { |
| 1982 | //TODO: needs to handle error scenarios |
| 1983 | logger.Errorw("Failed to fetch device device at creating If", log.Fields{"err": err}) |
| 1984 | return errors.New("Voltha Device not found") |
| 1985 | } |
| 1986 | */ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1987 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1988 | if err := pDevEntry.Start(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1989 | return err |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1990 | } |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1991 | _ = dh.ReasonUpdate(ctx, cmn.DrStartingOpenomci, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1992 | |
| 1993 | /* this might be a good time for Omci Verify message? */ |
| 1994 | verifyExec := make(chan bool) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1995 | omciVerify := otst.NewOmciTestRequest(log.WithSpanFromContext(context.TODO(), ctx), |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1996 | dh.device.Id, pDevEntry.PDevOmciCC, |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1997 | true, true) //exclusive and allowFailure (anyway not yet checked) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1998 | omciVerify.PerformOmciTest(log.WithSpanFromContext(context.TODO(), ctx), verifyExec) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1999 | |
| 2000 | /* give the handler some time here to wait for the OMCi verification result |
| 2001 | after Timeout start and try MibUpload FSM anyway |
| 2002 | (to prevent stopping on just not supported OMCI verification from ONU) */ |
| 2003 | select { |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 2004 | case <-time.After(pDevEntry.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2005 | logger.Warnw(ctx, "omci start-verification timed out (continue normal)", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2006 | case testresult := <-verifyExec: |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2007 | logger.Infow(ctx, "Omci start verification done", log.Fields{"device-id": dh.DeviceID, "result": testresult}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | /* In py code it looks earlier (on activate ..) |
| 2011 | # Code to Run OMCI Test Action |
| 2012 | kwargs_omci_test_action = { |
| 2013 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 2014 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 2015 | } |
| 2016 | serial_number = device.serial_number |
| 2017 | self._test_request = OmciTestRequest(self.core_proxy, |
| 2018 | self.omci_agent, self.device_id, |
| 2019 | AniG, serial_number, |
| 2020 | self.logical_device_id, |
| 2021 | exclusive=False, |
| 2022 | **kwargs_omci_test_action) |
| 2023 | ... |
| 2024 | # Start test requests after a brief pause |
| 2025 | if not self._test_request_started: |
| 2026 | self._test_request_started = True |
| 2027 | tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 2028 | reactor.callLater(tststart, self._test_request.start_collector) |
| 2029 | |
| 2030 | */ |
| 2031 | /* which is then: in omci_test_request.py : */ |
| 2032 | /* |
| 2033 | def start_collector(self, callback=None): |
| 2034 | """ |
| 2035 | Start the collection loop for an adapter if the frequency > 0 |
| 2036 | |
| 2037 | :param callback: (callable) Function to call to collect PM data |
| 2038 | """ |
| 2039 | self.logger.info("starting-pm-collection", device_name=self.name, default_freq=self.default_freq) |
| 2040 | if callback is None: |
| 2041 | callback = self.perform_test_omci |
| 2042 | |
| 2043 | if self.lc is None: |
| 2044 | self.lc = LoopingCall(callback) |
| 2045 | |
| 2046 | if self.default_freq > 0: |
| 2047 | self.lc.start(interval=self.default_freq / 10) |
| 2048 | |
| 2049 | def perform_test_omci(self): |
| 2050 | """ |
| 2051 | Perform the initial test request |
| 2052 | """ |
| 2053 | ani_g_entities = self._device.configuration.ani_g_entities |
| 2054 | ani_g_entities_ids = list(ani_g_entities.keys()) if ani_g_entities \ |
| 2055 | is not None else None |
| 2056 | self._entity_id = ani_g_entities_ids[0] |
| 2057 | self.logger.info('perform-test', entity_class=self._entity_class, |
| 2058 | entity_id=self._entity_id) |
| 2059 | try: |
| 2060 | frame = MEFrame(self._entity_class, self._entity_id, []).test() |
| 2061 | result = yield self._device.omci_cc.send(frame) |
| 2062 | if not result.fields['omci_message'].fields['success_code']: |
| 2063 | self.logger.info('Self-Test Submitted Successfully', |
| 2064 | code=result.fields[ |
| 2065 | 'omci_message'].fields['success_code']) |
| 2066 | else: |
| 2067 | raise TestFailure('Test Failure: {}'.format( |
| 2068 | result.fields['omci_message'].fields['success_code'])) |
| 2069 | except TimeoutError as e: |
| 2070 | self.deferred.errback(failure.Failure(e)) |
| 2071 | |
| 2072 | except Exception as e: |
| 2073 | self.logger.exception('perform-test-Error', e=e, |
| 2074 | class_id=self._entity_class, |
| 2075 | entity_id=self._entity_id) |
| 2076 | self.deferred.errback(failure.Failure(e)) |
| 2077 | |
| 2078 | */ |
| 2079 | |
| 2080 | // PM related heartbeat??? !!!TODO.... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2081 | //self._heartbeat.Enabled = True |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2082 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 2083 | /* Note: Even though FSM calls look 'synchronous' here, FSM is running in background with the effect that possible errors |
| 2084 | * within the MibUpload are not notified in the OnuIndication response, this might be acceptable here, |
| 2085 | * 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] | 2086 | * otherwise some processing synchronization would be required - cmp. e.g TechProfile processing |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 2087 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2088 | //call MibUploadFSM - transition up to state UlStInSync |
| 2089 | pMibUlFsm := pDevEntry.PMibUploadFsm.PFsm |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 2090 | if pMibUlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2091 | if pMibUlFsm.Is(mib.UlStDisabled) { |
| 2092 | if err := pMibUlFsm.Event(mib.UlEvStart); err != nil { |
| 2093 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2094 | return fmt.Errorf("can't go to state starting: %s", dh.DeviceID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2095 | } |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2096 | 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] | 2097 | //Determine ONU status and start/re-start MIB Synchronization tasks |
| 2098 | //Determine if this ONU has ever synchronized |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2099 | if pDevEntry.IsNewOnu() { |
| 2100 | if err := pMibUlFsm.Event(mib.UlEvResetMib); err != nil { |
| 2101 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state resetting_mib", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2102 | 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] | 2103 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2104 | } else { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2105 | if err := pMibUlFsm.Event(mib.UlEvVerifyAndStoreTPs); err != nil { |
| 2106 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state verify and store TPs", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 2107 | 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] | 2108 | } |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2109 | 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] | 2110 | } |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 2111 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2112 | 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] | 2113 | "device-id": dh.DeviceID}) |
| 2114 | return fmt.Errorf("wrong state of MibSyncFsm: %s", dh.DeviceID) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2115 | } |
| 2116 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2117 | logger.Errorw(ctx, "MibSyncFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID}) |
| 2118 | return fmt.Errorf("can't execute MibSync: %s", dh.DeviceID) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2119 | } |
| 2120 | return nil |
| 2121 | } |
| 2122 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2123 | func (dh *deviceHandler) updateInterface(ctx context.Context, onuind *oop.OnuIndication) error { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2124 | //state checking to prevent unneeded processing (eg. on ONU 'unreachable' and 'down') |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2125 | // (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] | 2126 | if dh.getDeviceReason() != cmn.DrStoppingOpenomci { |
| 2127 | logger.Debugw(ctx, "updateInterface-started - stopping-device", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 2128 | |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2129 | //stop all running FSM processing - make use of the DH-state as mirrored in the deviceReason |
| 2130 | //here no conflict with aborted FSM's should arise as a complete OMCI initialization is assumed on ONU-Up |
| 2131 | //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] | 2132 | if err := dh.resetFsms(ctx, true); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2133 | logger.Errorw(ctx, "error-updateInterface at FSM stop", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2134 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2135 | // abort: system behavior is just unstable ... |
| 2136 | return err |
| 2137 | } |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2138 | //all stored persistent data are not valid anymore (loosing knowledge about the connected ONU) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2139 | _ = dh.deleteDevicePersistencyData(ctx) //ignore possible errors here and continue, hope is that data is synchronized with new ONU-Up |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2140 | |
| 2141 | //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] | 2142 | //stop the device entry to allow for all system event transfers again |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2143 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2144 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2145 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 2146 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2147 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2148 | _ = pDevEntry.Stop(log.WithSpanFromContext(context.TODO(), ctx), false) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2149 | |
| 2150 | //TODO!!! remove existing traffic profiles |
| 2151 | /* from py code, if TP's exist, remove them - not yet implemented |
| 2152 | self._tp = dict() |
| 2153 | # Let TP download happen again |
| 2154 | for uni_id in self._tp_service_specific_task: |
| 2155 | self._tp_service_specific_task[uni_id].clear() |
| 2156 | for uni_id in self._tech_profile_download_done: |
| 2157 | self._tech_profile_download_done[uni_id].clear() |
| 2158 | */ |
| 2159 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2160 | dh.DisableUniPortStateUpdate(ctx) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2161 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2162 | dh.SetReadyForOmciConfig(false) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2163 | |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2164 | if err := dh.ReasonUpdate(ctx, cmn.DrStoppingOpenomci, true); err != nil { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2165 | // abort: system behavior is just unstable ... |
| 2166 | return err |
| 2167 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2168 | 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] | 2169 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID}) |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2170 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2171 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2172 | ConnStatus: voltha.ConnectStatus_UNREACHABLE, |
| 2173 | OperStatus: voltha.OperStatus_DISCOVERED, |
| 2174 | }); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2175 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2176 | logger.Errorw(ctx, "error-updating-device-state unreachable-discovered", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2177 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2178 | // abort: system behavior is just unstable ... |
| 2179 | return err |
| 2180 | } |
| 2181 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2182 | logger.Debugw(ctx, "updateInterface - device already stopped", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2183 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2184 | return nil |
| 2185 | } |
| 2186 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2187 | func (dh *deviceHandler) resetFsms(ctx context.Context, includingMibSyncFsm bool) error { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2188 | //all possible FSM's are stopped or reset here to ensure their transition to 'disabled' |
| 2189 | //it is not sufficient to stop/reset the latest running FSM as done in previous versions |
| 2190 | // as after down/up procedures all FSM's might be active/ongoing (in theory) |
| 2191 | // and using the stop/reset event should never harm |
| 2192 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2193 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2194 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2195 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 2196 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2197 | } |
Holger Hildebrandt | c8ece36 | 2021-05-17 12:01:10 +0000 | [diff] [blame] | 2198 | if pDevEntry.PDevOmciCC != nil { |
mpagenko | 8cd1bf7 | 2021-06-22 10:11:19 +0000 | [diff] [blame] | 2199 | pDevEntry.PDevOmciCC.CancelRequestMonitoring(ctx) |
Holger Hildebrandt | c8ece36 | 2021-05-17 12:01:10 +0000 | [diff] [blame] | 2200 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2201 | pDevEntry.MutexOnuImageStatus.RLock() |
| 2202 | if pDevEntry.POnuImageStatus != nil { |
| 2203 | pDevEntry.POnuImageStatus.CancelProcessing(ctx) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 2204 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2205 | pDevEntry.MutexOnuImageStatus.RUnlock() |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 2206 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2207 | if includingMibSyncFsm { |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 2208 | pDevEntry.CancelProcessing(ctx) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2209 | } |
| 2210 | //MibDownload may run |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2211 | pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2212 | if pMibDlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2213 | _ = pMibDlFsm.Event(mib.DlEvReset) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2214 | } |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 2215 | //stop any deviceHandler reconcile processing (if running) |
| 2216 | dh.stopReconciling(ctx, false, cWaitReconcileFlowAbortOnError) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2217 | //port lock/unlock FSM's may be active |
| 2218 | if dh.pUnlockStateFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2219 | _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2220 | } |
| 2221 | if dh.pLockStateFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2222 | _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2223 | } |
| 2224 | //techProfile related PonAniConfigFsm FSM may be active |
| 2225 | if dh.pOnuTP != nil { |
| 2226 | // should always be the case here |
| 2227 | // 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] | 2228 | if dh.pOnuTP.PAniConfigFsm != nil { |
| 2229 | for uniTP := range dh.pOnuTP.PAniConfigFsm { |
| 2230 | dh.pOnuTP.PAniConfigFsm[uniTP].CancelProcessing(ctx) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 2231 | } |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2232 | } |
| 2233 | for _, uniPort := range dh.uniEntityMap { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2234 | // reset the possibly existing VlanConfigFsm |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2235 | dh.lockVlanConfig.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2236 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniPort.UniID]; exist { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2237 | //VlanFilterFsm exists and was already started |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2238 | dh.lockVlanConfig.RUnlock() |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2239 | //ensure the FSM processing is stopped in case waiting for some response |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 2240 | pVlanFilterFsm.CancelProcessing(ctx) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2241 | } else { |
| 2242 | dh.lockVlanConfig.RUnlock() |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2243 | } |
| 2244 | } |
| 2245 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2246 | if dh.GetCollectorIsRunning() { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2247 | // Stop collector routine |
| 2248 | dh.stopCollector <- true |
| 2249 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2250 | if dh.GetAlarmManagerIsRunning(ctx) { |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2251 | dh.stopAlarmManager <- true |
| 2252 | } |
Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 2253 | if dh.pSelfTestHdlr.GetSelfTestHandlerIsRunning() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2254 | dh.pSelfTestHdlr.StopSelfTestModule <- true |
Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 2255 | } |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2256 | |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2257 | // Note: We want flow deletes to be processed on onu down, so do not stop flow monitoring routines |
| 2258 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2259 | //reset a possibly running upgrade FSM |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2260 | // (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] | 2261 | dh.lockUpgradeFsm.RLock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2262 | lopOnuUpradeFsm := dh.pOnuUpradeFsm |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2263 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2264 | dh.lockUpgradeFsm.RUnlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2265 | if lopOnuUpradeFsm != nil { |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2266 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 2267 | //here we do not expect intermediate cancelation, we still allow for other commands on this FSM |
| 2268 | // (even though it may also run into direct cancellation, a bit hard to verify here) |
| 2269 | // so don't set 'dh.upgradeCanceled = true' here! |
| 2270 | lopOnuUpradeFsm.CancelProcessing(ctx, false, voltha.ImageState_CANCELLED_ON_ONU_STATE) //conditional cancel |
| 2271 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2272 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2273 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2274 | logger.Infow(ctx, "resetFsms done", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2275 | return nil |
| 2276 | } |
| 2277 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2278 | func (dh *deviceHandler) processMibDatabaseSyncEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2279 | 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] | 2280 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2281 | // store persistent data collected during MIB upload processing |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2282 | if err := dh.StorePersistentData(ctx); err != nil { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2283 | 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] | 2284 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2285 | } |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2286 | _ = dh.ReasonUpdate(ctx, cmn.DrDiscoveryMibsyncComplete, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2287 | dh.AddAllUniPorts(ctx) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2288 | |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2289 | /* 200605: lock processing after initial MIBUpload removed now as the ONU should be in the lock state per default here */ |
| 2290 | /* 201117: build_dt-berlin-pod-openonugo_1T8GEM_voltha_DT_openonugo_master_test runs into error TC |
| 2291 | * 'Test Disable ONUs and OLT Then Delete ONUs and OLT for DT' with Sercom ONU, which obviously needs |
| 2292 | * disable/enable toggling here to allow traffic |
| 2293 | * but moreover it might be useful for tracking the interface operState changes if this will be implemented, |
| 2294 | * like the py comment says: |
| 2295 | * # start by locking all the unis till mib sync and initial mib is downloaded |
| 2296 | * # this way we can capture the port down/up events when we are ready |
| 2297 | */ |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2298 | |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2299 | // Init Uni Ports to Admin locked state |
| 2300 | // *** should generate UniLockStateDone event ***** |
| 2301 | if dh.pLockStateFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2302 | dh.createUniLockFsm(ctx, true, cmn.UniLockStateDone) |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2303 | } else { //LockStateFSM already init |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2304 | dh.pLockStateFsm.SetSuccessEvent(cmn.UniLockStateDone) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2305 | dh.runUniLockFsm(ctx, true) |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2306 | } |
| 2307 | } |
| 2308 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2309 | func (dh *deviceHandler) processUniLockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2310 | 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] | 2311 | /* Mib download procedure - |
| 2312 | ***** should run over 'downloaded' state and generate MibDownloadDone event ***** |
| 2313 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2314 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2315 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2316 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2317 | return |
| 2318 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2319 | pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2320 | if pMibDlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2321 | if pMibDlFsm.Is(mib.DlStDisabled) { |
| 2322 | if err := pMibDlFsm.Event(mib.DlEvStart); err != nil { |
| 2323 | 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] | 2324 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2325 | } else { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2326 | 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] | 2327 | // maybe use more specific states here for the specific download steps ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2328 | if err := pMibDlFsm.Event(mib.DlEvCreateGal); err != nil { |
| 2329 | 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] | 2330 | } else { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2331 | 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] | 2332 | //Begin MIB data download (running autonomously) |
| 2333 | } |
| 2334 | } |
| 2335 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2336 | 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] | 2337 | "device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2338 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2339 | } |
| 2340 | /***** Mib download started */ |
| 2341 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2342 | 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] | 2343 | } |
| 2344 | } |
| 2345 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2346 | func (dh *deviceHandler) processMibDownloadDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2347 | logger.Debugw(ctx, "MibDownloadDone event received, unlocking the ONU interfaces", log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2348 | //initiate DevStateUpdate |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2349 | if !dh.IsReconciling() { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2350 | logger.Debugw(ctx, "call DeviceStateUpdate upon mib-download done", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2351 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2352 | //we allow a possible OnuSw image commit only in the normal startup, not at reconciling |
| 2353 | // in case of adapter restart connected to an ONU upgrade I would not rely on the image quality |
| 2354 | // maybe some 'forced' commitment can be done in this situation from system management (or upgrade restarted) |
| 2355 | dh.checkOnOnuImageCommit(ctx) |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2356 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2357 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2358 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2359 | OperStatus: voltha.OperStatus_ACTIVE, |
| 2360 | }); err != nil { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2361 | //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] | 2362 | 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] | 2363 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2364 | 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] | 2365 | } |
| 2366 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2367 | logger.Debugw(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVE", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2368 | log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2369 | } |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2370 | _ = dh.ReasonUpdate(ctx, cmn.DrInitialMibDownloaded, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2371 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2372 | if !dh.GetCollectorIsRunning() { |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2373 | // Start PM collector routine |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2374 | go dh.StartCollector(ctx) |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2375 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2376 | if !dh.GetAlarmManagerIsRunning(ctx) { |
| 2377 | go dh.StartAlarmManager(ctx) |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2380 | // Start flow handler routines per UNI |
| 2381 | for _, uniPort := range dh.uniEntityMap { |
| 2382 | // only if this port was enabled for use by the operator at startup |
| 2383 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 2384 | if !dh.GetFlowMonitoringIsRunning(uniPort.UniID) { |
| 2385 | go dh.PerOnuFlowHandlerRoutine(uniPort.UniID) |
| 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2390 | // Initialize classical L2 PM Interval Counters |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2391 | if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventInit); err != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2392 | // There is no way we should be landing here, but if we do then |
| 2393 | // there is nothing much we can do about this other than log error |
| 2394 | logger.Errorw(ctx, "error starting l2 pm fsm", log.Fields{"device-id": dh.device.Id, "err": err}) |
| 2395 | } |
| 2396 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2397 | dh.SetReadyForOmciConfig(true) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2398 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2399 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2400 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2401 | 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] | 2402 | return |
| 2403 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2404 | pDevEntry.MutexPersOnuConfig.RLock() |
| 2405 | if dh.IsReconciling() && pDevEntry.SOnuPersistentData.PersUniDisableDone { |
| 2406 | pDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2407 | logger.Debugw(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] | 2408 | log.Fields{"device-id": dh.DeviceID}) |
ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame^] | 2409 | dh.mutexForDisableDeviceRequested.Lock() |
| 2410 | dh.disableDeviceRequested = true |
| 2411 | dh.mutexForDisableDeviceRequested.Unlock() |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 2412 | dh.ReconcileDeviceTechProf(ctx) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2413 | // reconcilement will be continued after ani config is done |
| 2414 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2415 | pDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2416 | // *** should generate UniUnlockStateDone event ***** |
ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame^] | 2417 | dh.mutexForDisableDeviceRequested.RLock() |
| 2418 | if !dh.disableDeviceRequested { |
| 2419 | if dh.pUnlockStateFsm == nil { |
| 2420 | dh.createUniLockFsm(ctx, false, cmn.UniUnlockStateDone) |
| 2421 | } else { //UnlockStateFSM already init |
| 2422 | dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniUnlockStateDone) |
| 2423 | dh.runUniLockFsm(ctx, false) |
| 2424 | } |
| 2425 | dh.mutexForDisableDeviceRequested.RUnlock() |
| 2426 | } else { |
| 2427 | dh.mutexForDisableDeviceRequested.RUnlock() |
| 2428 | logger.Debugw(ctx, "Uni already lock", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2429 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2430 | } |
| 2431 | } |
| 2432 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2433 | func (dh *deviceHandler) processUniUnlockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2434 | dh.EnableUniPortStateUpdate(ctx) //cmp python yield self.enable_ports() |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2435 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2436 | if !dh.IsReconciling() { |
| 2437 | 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] | 2438 | raisedTs := time.Now().Unix() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2439 | go dh.sendOnuOperStateEvent(ctx, voltha.OperStatus_ACTIVE, dh.DeviceID, raisedTs) //cmp python onu_active_event |
| 2440 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2441 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2442 | 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] | 2443 | return |
| 2444 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2445 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2446 | pDevEntry.SOnuPersistentData.PersUniUnlockDone = true |
| 2447 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2448 | if err := dh.StorePersistentData(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2449 | 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] | 2450 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2451 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2452 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2453 | logger.Debugw(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] | 2454 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 2455 | dh.ReconcileDeviceTechProf(ctx) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2456 | // reconcilement will be continued after ani config is done |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2457 | } |
| 2458 | } |
| 2459 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2460 | func (dh *deviceHandler) processUniDisableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2461 | logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2462 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2463 | |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2464 | // disable device should have no impact on ConnStatus |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2465 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2466 | DeviceId: dh.DeviceID, |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2467 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2468 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 2469 | }); err != nil { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2470 | //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] | 2471 | 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] | 2472 | } |
| 2473 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2474 | 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] | 2475 | // 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] | 2476 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciAdminLock, true) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2477 | |
| 2478 | //transfer the modified logical uni port state |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2479 | dh.DisableUniPortStateUpdate(ctx) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2480 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2481 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2482 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2483 | 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] | 2484 | return |
| 2485 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2486 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2487 | pDevEntry.SOnuPersistentData.PersUniDisableDone = true |
| 2488 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2489 | if err := dh.StorePersistentData(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2490 | 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] | 2491 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2492 | } |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2495 | func (dh *deviceHandler) processUniEnableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2496 | 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] | 2497 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID}) |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2498 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2499 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2500 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2501 | OperStatus: voltha.OperStatus_ACTIVE, |
| 2502 | }); err != nil { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2503 | //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] | 2504 | 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] | 2505 | } |
| 2506 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2507 | logger.Debugw(ctx, "DeviceReasonUpdate upon re-enable", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2508 | "reason": cmn.DeviceReasonMap[cmn.DrOnuReenabled], "device-id": dh.DeviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2509 | // 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] | 2510 | _ = dh.ReasonUpdate(ctx, cmn.DrOnuReenabled, true) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2511 | |
| 2512 | //transfer the modified logical uni port state |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2513 | dh.EnableUniPortStateUpdate(ctx) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2514 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2515 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2516 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2517 | 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] | 2518 | return |
| 2519 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2520 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2521 | pDevEntry.SOnuPersistentData.PersUniDisableDone = false |
| 2522 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2523 | if err := dh.StorePersistentData(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2524 | 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] | 2525 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2526 | } |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2527 | } |
| 2528 | |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 2529 | func (dh *deviceHandler) processUniEnableStateFailedEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2530 | logger.Debugw(ctx, "DeviceStateUpdate upon re-enable failure. ", log.Fields{ |
| 2531 | "OperStatus": voltha.OperStatus_FAILED, "device-id": dh.DeviceID}) |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2532 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 2533 | DeviceId: dh.DeviceID, |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 2534 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 2535 | OperStatus: voltha.OperStatus_FAILED, |
| 2536 | }); err != nil { |
| 2537 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| 2538 | } |
| 2539 | } |
| 2540 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2541 | func (dh *deviceHandler) processOmciAniConfigDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2542 | if devEvent == cmn.OmciAniConfigDone { |
| 2543 | logger.Debugw(ctx, "OmciAniConfigDone event received", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2544 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 2545 | // - which may cause some inconsistency |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2546 | if dh.getDeviceReason() != cmn.DrTechProfileConfigDownloadSuccess { |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2547 | // 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] | 2548 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2549 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2550 | if dh.IsReconciling() { |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 2551 | // during reconciling with OMCI configuration in TT multi-UNI scenario, OmciAniConfigDone is reached several times |
| 2552 | // therefore it must be ensured that reconciling of flow config is only started on the first pass of this code position |
| 2553 | dh.mutexReconcilingFirstPassFlag.Lock() |
| 2554 | if dh.reconcilingFirstPass { |
| 2555 | logger.Debugw(ctx, "reconciling - OmciAniConfigDone first pass, start flow processing", log.Fields{"device-id": dh.DeviceID}) |
| 2556 | dh.reconcilingFirstPass = false |
| 2557 | go dh.ReconcileDeviceFlowConfig(ctx) |
| 2558 | } |
| 2559 | dh.mutexReconcilingFirstPassFlag.Unlock() |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2560 | } |
| 2561 | } else { // should be the OmciAniResourceRemoved block |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2562 | logger.Debugw(ctx, "OmciAniResourceRemoved event received", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2563 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 2564 | // - which may cause some inconsistency |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2565 | if dh.getDeviceReason() != cmn.DrTechProfileConfigDeleteSuccess { |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2566 | // which may be the case from some previous activity even on this ONU port (but also other UNI ports) |
| 2567 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDeleteSuccess, true) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2568 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2569 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2570 | } |
| 2571 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2572 | func (dh *deviceHandler) processOmciVlanFilterDoneEvent(ctx context.Context, aDevEvent cmn.OnuDeviceEvent) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2573 | logger.Debugw(ctx, "OmciVlanFilterDone event received", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2574 | log.Fields{"device-id": dh.DeviceID, "event": aDevEvent}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2575 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 2576 | // - which may cause some inconsistency |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2577 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2578 | if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterAddDoneNoKvStore { |
| 2579 | if dh.getDeviceReason() != cmn.DrOmciFlowsPushed { |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2580 | // 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] | 2581 | // or even some previous flow add activity on the same port |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 2582 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsPushed, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate()) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2583 | } |
| 2584 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2585 | if dh.getDeviceReason() != cmn.DrOmciFlowsDeleted { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2586 | //not relevant for reconcile |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 2587 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsDeleted, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2588 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2589 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2590 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2591 | if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterRemDone { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2592 | //events that request KvStore write |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2593 | if err := dh.StorePersistentData(ctx); err != nil { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2594 | 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] | 2595 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2596 | } |
| 2597 | } else { |
| 2598 | logger.Debugw(ctx, "OmciVlanFilter*Done* - write to KvStore not requested", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2599 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2600 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2601 | } |
| 2602 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2603 | //DeviceProcStatusUpdate evaluates possible processing events and initiates according next activities |
| 2604 | func (dh *deviceHandler) DeviceProcStatusUpdate(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2605 | switch devEvent { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2606 | case cmn.MibDatabaseSync: |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2607 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2608 | dh.processMibDatabaseSyncEvent(ctx, devEvent) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2609 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2610 | case cmn.UniLockStateDone: |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2611 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2612 | dh.processUniLockStateDoneEvent(ctx, devEvent) |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2613 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2614 | case cmn.MibDownloadDone: |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2615 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2616 | dh.processMibDownloadDoneEvent(ctx, devEvent) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2617 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2618 | case cmn.UniUnlockStateDone: |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2619 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2620 | dh.processUniUnlockStateDoneEvent(ctx, devEvent) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2621 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2622 | case cmn.UniEnableStateDone: |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2623 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2624 | dh.processUniEnableStateDoneEvent(ctx, devEvent) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2625 | } |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 2626 | case cmn.UniEnableStateFailed: |
| 2627 | { |
| 2628 | dh.processUniEnableStateFailedEvent(ctx, devEvent) |
| 2629 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2630 | case cmn.UniDisableStateDone: |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2631 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2632 | dh.processUniDisableStateDoneEvent(ctx, devEvent) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2633 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2634 | case cmn.OmciAniConfigDone, cmn.OmciAniResourceRemoved: |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 2635 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2636 | dh.processOmciAniConfigDoneEvent(ctx, devEvent) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 2637 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2638 | case cmn.OmciVlanFilterAddDone, cmn.OmciVlanFilterAddDoneNoKvStore, cmn.OmciVlanFilterRemDone, cmn.OmciVlanFilterRemDoneNoKvStore: |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2639 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2640 | dh.processOmciVlanFilterDoneEvent(ctx, devEvent) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2641 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2642 | default: |
| 2643 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2644 | 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] | 2645 | } |
| 2646 | } //switch |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2647 | } |
| 2648 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2649 | 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] | 2650 | // parameters are IntfId, OnuId, uniId |
Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 2651 | uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2652 | uint32(aUniID)) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2653 | if _, present := dh.uniEntityMap[uniNo]; present { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2654 | 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] | 2655 | } else { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2656 | //with arguments aUniID, a_portNo, aPortType |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2657 | pUniPort := cmn.NewOnuUniPort(ctx, aUniID, uniNo, aUniInstNo, aPortType) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2658 | if pUniPort == nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2659 | 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] | 2660 | } else { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2661 | //store UniPort with the System-PortNumber key |
| 2662 | dh.uniEntityMap[uniNo] = pUniPort |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2663 | if !dh.IsReconciling() { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2664 | // create announce the UniPort to the core as VOLTHA Port object |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2665 | if err := pUniPort.CreateVolthaPort(ctx, dh); err == nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2666 | 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] | 2667 | } //error logging already within UniPort method |
| 2668 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2669 | logger.Debugw(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] | 2670 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2671 | } |
| 2672 | } |
| 2673 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2674 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2675 | func (dh *deviceHandler) AddAllUniPorts(ctx context.Context) { |
| 2676 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2677 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2678 | 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] | 2679 | return |
| 2680 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2681 | 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] | 2682 | if pptpInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2683 | ctx, me.PhysicalPathTerminationPointEthernetUniClassID); len(pptpInstKeys) > 0 { |
| 2684 | for _, mgmtEntityID := range pptpInstKeys { |
| 2685 | logger.Debugw(ctx, "Add PPTPEthUni port for MIB-stored instance:", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2686 | "device-id": dh.DeviceID, "PPTPEthUni EntityID": mgmtEntityID}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2687 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniPPTP) |
| 2688 | uniCnt++ |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2689 | } |
| 2690 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2691 | 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] | 2692 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2693 | if veipInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2694 | ctx, me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 { |
| 2695 | for _, mgmtEntityID := range veipInstKeys { |
| 2696 | logger.Debugw(ctx, "Add VEIP for MIB-stored instance:", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2697 | "device-id": dh.DeviceID, "VEIP EntityID": mgmtEntityID}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2698 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniVEIP) |
| 2699 | uniCnt++ |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2700 | } |
| 2701 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2702 | 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] | 2703 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2704 | if potsInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 2705 | ctx, me.PhysicalPathTerminationPointPotsUniClassID); len(potsInstKeys) > 0 { |
| 2706 | for _, mgmtEntityID := range potsInstKeys { |
| 2707 | 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] | 2708 | "device-id": dh.DeviceID, "PPTP Pots UNI EntityID": mgmtEntityID}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2709 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniPPTPPots) |
| 2710 | uniCnt++ |
ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 2711 | } |
| 2712 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2713 | 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] | 2714 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2715 | if uniCnt == 0 { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2716 | 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] | 2717 | return |
| 2718 | } |
| 2719 | |
mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 2720 | //Note: For the moment is is not required to include the (newly added) POTS ports into the range |
| 2721 | // of flowCall or reconcile channels. But some sort of flow and reconcile processing might get necessary |
| 2722 | // 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] | 2723 | dh.flowCbChan = make([]chan FlowCb, uniCnt) |
| 2724 | dh.stopFlowMonitoringRoutine = make([]chan bool, uniCnt) |
| 2725 | dh.isFlowMonitoringRoutineActive = make([]bool, uniCnt) |
mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 2726 | //chUniVlanConfigReconcilingDone needs to have the capacity of all UniPorts as flow reconcile may run parallel for all of them |
| 2727 | dh.chUniVlanConfigReconcilingDone = make(chan uint16, uniCnt) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2728 | for i := 0; i < int(uniCnt); i++ { |
| 2729 | dh.flowCbChan[i] = make(chan FlowCb, dh.pOpenOnuAc.config.MaxConcurrentFlowsPerUni) |
| 2730 | dh.stopFlowMonitoringRoutine[i] = make(chan bool) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2731 | } |
| 2732 | } |
| 2733 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2734 | // EnableUniPortStateUpdate enables UniPortState and update core port state accordingly |
| 2735 | func (dh *deviceHandler) EnableUniPortStateUpdate(ctx context.Context) { |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 2736 | // 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] | 2737 | // but towards core only the first port active state is signaled |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 2738 | // with following remark: |
| 2739 | // # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow |
| 2740 | // # load on the core |
| 2741 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2742 | // 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] | 2743 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2744 | for uniNo, uniPort := range dh.uniEntityMap { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2745 | // only if this port is validated for operState transfer |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2746 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 2747 | logger.Infow(ctx, "OnuUniPort-forced-OperState-ACTIVE", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID}) |
| 2748 | uniPort.SetOperState(vc.OperStatus_ACTIVE) |
| 2749 | if !dh.IsReconciling() { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2750 | //maybe also use getter functions on uniPort - perhaps later ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2751 | go func(port *cmn.OnuUniPort) { |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2752 | if err := dh.updatePortStateInCore(ctx, &ca.PortState{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2753 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2754 | PortType: voltha.Port_ETHERNET_UNI, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2755 | PortNo: port.PortNo, |
| 2756 | OperStatus: port.OperState, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2757 | }); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2758 | 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] | 2759 | } |
| 2760 | }(uniPort) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2761 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2762 | logger.Debugw(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] | 2763 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2764 | } |
| 2765 | } |
| 2766 | } |
| 2767 | |
| 2768 | // Disable UniPortState and update core port state accordingly |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2769 | func (dh *deviceHandler) DisableUniPortStateUpdate(ctx context.Context) { |
| 2770 | // compare EnableUniPortStateUpdate() above |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2771 | // -> use current restriction to operate only on first UNI port as inherited from actual Py code |
| 2772 | for uniNo, uniPort := range dh.uniEntityMap { |
| 2773 | // only if this port is validated for operState transfer |
Matteo Scandolo | 20d180c | 2021-06-10 17:20:21 +0200 | [diff] [blame] | 2774 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2775 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 2776 | logger.Infow(ctx, "OnuUniPort-forced-OperState-UNKNOWN", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID}) |
| 2777 | uniPort.SetOperState(vc.OperStatus_UNKNOWN) |
| 2778 | if !dh.IsReconciling() { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2779 | //maybe also use getter functions on uniPort - perhaps later ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2780 | go func(port *cmn.OnuUniPort) { |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 2781 | if err := dh.updatePortStateInCore(ctx, &ca.PortState{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2782 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2783 | PortType: voltha.Port_ETHERNET_UNI, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2784 | PortNo: port.PortNo, |
| 2785 | OperStatus: port.OperState, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2786 | }); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2787 | 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] | 2788 | } |
| 2789 | }(uniPort) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2790 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2791 | logger.Debugw(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] | 2792 | } |
| 2793 | |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 2794 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | // ONU_Active/Inactive announcement on system KAFKA bus |
| 2799 | // tried to re-use procedure of oltUpDownIndication from openolt_eventmgr.go with used values from Py code |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2800 | func (dh *deviceHandler) sendOnuOperStateEvent(ctx context.Context, aOperState vc.OperStatus_Types, aDeviceID string, raisedTs int64) { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2801 | var de voltha.DeviceEvent |
| 2802 | eventContext := make(map[string]string) |
| 2803 | //Populating event context |
| 2804 | // 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] | 2805 | parentDevice, err := dh.getDeviceFromCore(ctx, dh.parentID) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2806 | if err != nil || parentDevice == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2807 | logger.Errorw(ctx, "Failed to fetch parent device for OnuEvent", |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2808 | log.Fields{"device-id": dh.DeviceID, "parentID": dh.parentID, "err": err}) |
Holger Hildebrandt | 7ec14c4 | 2021-05-28 14:21:58 +0000 | [diff] [blame] | 2809 | 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] | 2810 | } |
| 2811 | oltSerialNumber := parentDevice.SerialNumber |
| 2812 | |
| 2813 | eventContext["pon-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.IntfId), 10) |
| 2814 | eventContext["onu-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.OnuId), 10) |
| 2815 | eventContext["serial-number"] = dh.device.SerialNumber |
ssiddiqui | 1221d1a | 2021-02-15 11:12:51 +0530 | [diff] [blame] | 2816 | eventContext["olt-serial-number"] = oltSerialNumber |
| 2817 | eventContext["device-id"] = aDeviceID |
| 2818 | eventContext["registration-id"] = aDeviceID //py: string(device_id)?? |
ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 2819 | eventContext["num-of-unis"] = strconv.Itoa(len(dh.uniEntityMap)) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2820 | if deviceEntry := dh.GetOnuDeviceEntry(ctx, false); deviceEntry != nil { |
| 2821 | deviceEntry.MutexPersOnuConfig.RLock() |
| 2822 | eventContext["equipment-id"] = deviceEntry.SOnuPersistentData.PersEquipmentID |
| 2823 | deviceEntry.MutexPersOnuConfig.RUnlock() |
| 2824 | eventContext["software-version"] = deviceEntry.GetActiveImageVersion(ctx) |
| 2825 | deviceEntry.MutexPersOnuConfig.RLock() |
| 2826 | eventContext["vendor"] = deviceEntry.SOnuPersistentData.PersVendorID |
| 2827 | deviceEntry.MutexPersOnuConfig.RUnlock() |
| 2828 | eventContext["inactive-software-version"] = deviceEntry.GetInactiveImageVersion(ctx) |
ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 2829 | logger.Debugw(ctx, "prepare ONU_ACTIVATED event", |
| 2830 | log.Fields{"device-id": aDeviceID, "EventContext": eventContext}) |
| 2831 | } else { |
| 2832 | logger.Errorw(ctx, "Failed to fetch device-entry. ONU_ACTIVATED event is not sent", |
| 2833 | log.Fields{"device-id": aDeviceID}) |
| 2834 | return |
| 2835 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2836 | |
| 2837 | /* Populating device event body */ |
| 2838 | de.Context = eventContext |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2839 | de.ResourceId = aDeviceID |
| 2840 | if aOperState == voltha.OperStatus_ACTIVE { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2841 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "RAISE_EVENT") |
| 2842 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 2843 | cEventObjectType, cOnuActivatedEvent, "Raised") |
| 2844 | } else { |
| 2845 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "CLEAR_EVENT") |
| 2846 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 2847 | cEventObjectType, cOnuActivatedEvent, "Cleared") |
| 2848 | } |
| 2849 | /* Send event to KAFKA */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2850 | if err := dh.EventProxy.SendDeviceEvent(ctx, &de, equipment, pon, raisedTs); err != nil { |
| 2851 | logger.Warnw(ctx, "could not send ONU_ACTIVATED event", |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2852 | log.Fields{"device-id": aDeviceID, "error": err}) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2853 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2854 | logger.Debugw(ctx, "ctx, ONU_ACTIVATED event sent to KAFKA", |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2855 | log.Fields{"device-id": aDeviceID, "with-EventName": de.DeviceEventName}) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2856 | } |
| 2857 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2858 | // 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] | 2859 | func (dh *deviceHandler) createUniLockFsm(ctx context.Context, aAdminState bool, devEvent cmn.OnuDeviceEvent) { |
| 2860 | chLSFsm := make(chan cmn.Message, 2048) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2861 | var sFsmName string |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2862 | if aAdminState { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2863 | logger.Debugw(ctx, "createLockStateFSM", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2864 | sFsmName = "LockStateFSM" |
| 2865 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2866 | logger.Debugw(ctx, "createUnlockStateFSM", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2867 | sFsmName = "UnLockStateFSM" |
| 2868 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2869 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2870 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2871 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2872 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2873 | return |
| 2874 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2875 | pLSFsm := uniprt.NewLockStateFsm(ctx, aAdminState, devEvent, sFsmName, dh, pDevEntry, chLSFsm) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2876 | if pLSFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2877 | if aAdminState { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2878 | dh.pLockStateFsm = pLSFsm |
| 2879 | } else { |
| 2880 | dh.pUnlockStateFsm = pLSFsm |
| 2881 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2882 | dh.runUniLockFsm(ctx, aAdminState) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2883 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2884 | 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] | 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | // 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] | 2889 | func (dh *deviceHandler) runUniLockFsm(ctx context.Context, aAdminState bool) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2890 | /* Uni Port lock/unlock procedure - |
| 2891 | ***** should run via 'adminDone' state and generate the argument requested event ***** |
| 2892 | */ |
| 2893 | var pLSStatemachine *fsm.FSM |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2894 | if aAdminState { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2895 | pLSStatemachine = dh.pLockStateFsm.PAdaptFsm.PFsm |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2896 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 2897 | if (dh.pUnlockStateFsm != nil) && |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2898 | (dh.pUnlockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) { |
| 2899 | _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2900 | } |
| 2901 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2902 | pLSStatemachine = dh.pUnlockStateFsm.PAdaptFsm.PFsm |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2903 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 2904 | if (dh.pLockStateFsm != nil) && |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2905 | (dh.pLockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) { |
| 2906 | _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2907 | } |
| 2908 | } |
| 2909 | if pLSStatemachine != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2910 | if pLSStatemachine.Is(uniprt.UniStDisabled) { |
| 2911 | if err := pLSStatemachine.Event(uniprt.UniEvStart); err != nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2912 | 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] | 2913 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2914 | } else { |
| 2915 | /***** LockStateFSM started */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2916 | logger.Debugw(ctx, "LockStateFSM started", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2917 | "state": pLSStatemachine.Current(), "device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2918 | } |
| 2919 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2920 | logger.Warnw(ctx, "wrong state of LockStateFSM - want: disabled", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2921 | "have": pLSStatemachine.Current(), "device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2922 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2923 | } |
| 2924 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2925 | 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] | 2926 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2927 | } |
| 2928 | } |
| 2929 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2930 | // createOnuUpgradeFsm initializes and runs the Onu Software upgrade FSM |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2931 | // precondition: lockUpgradeFsm is already locked from caller of this function |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2932 | func (dh *deviceHandler) createOnuUpgradeFsm(ctx context.Context, apDevEntry *mib.OnuDeviceEntry, aDevEvent cmn.OnuDeviceEvent) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2933 | chUpgradeFsm := make(chan cmn.Message, 2048) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2934 | var sFsmName = "OnuSwUpgradeFSM" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2935 | logger.Debugw(ctx, "create OnuSwUpgradeFSM", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2936 | if apDevEntry.PDevOmciCC == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2937 | logger.Errorw(ctx, "no valid OnuDevice or omciCC - abort", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2938 | return fmt.Errorf(fmt.Sprintf("no valid omciCC - abort for device-id: %s", dh.device.Id)) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2939 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2940 | dh.pOnuUpradeFsm = swupg.NewOnuUpgradeFsm(ctx, dh, apDevEntry, apDevEntry.GetOnuDB(), aDevEvent, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2941 | sFsmName, chUpgradeFsm) |
| 2942 | if dh.pOnuUpradeFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2943 | pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2944 | if pUpgradeStatemachine != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2945 | if pUpgradeStatemachine.Is(swupg.UpgradeStDisabled) { |
| 2946 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvStart); err != nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 2947 | 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] | 2948 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2949 | return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be started for device-id: %s", dh.device.Id)) |
| 2950 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2951 | /***** Upgrade FSM started */ |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 2952 | //reset the last stored upgrade states (which anyway should be don't care as long as the newly created FSM exists) |
| 2953 | (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2954 | (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR |
| 2955 | (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2956 | logger.Debugw(ctx, "OnuSwUpgradeFSM started", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2957 | "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2958 | } else { |
| 2959 | 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] | 2960 | "have": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2961 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2962 | return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be started for device-id: %s, wrong internal state", dh.device.Id)) |
| 2963 | } |
| 2964 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2965 | 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] | 2966 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2967 | return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM internal FSM could not be created for device-id: %s", dh.device.Id)) |
| 2968 | } |
| 2969 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2970 | logger.Errorw(ctx, "OnuSwUpgradeFSM could not be created - abort", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2971 | return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be created - abort for device-id: %s", dh.device.Id)) |
| 2972 | } |
| 2973 | return nil |
| 2974 | } |
| 2975 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2976 | // RemoveOnuUpgradeFsm clears the Onu Software upgrade FSM |
| 2977 | func (dh *deviceHandler) RemoveOnuUpgradeFsm(ctx context.Context, apImageState *voltha.ImageState) { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2978 | logger.Debugw(ctx, "remove OnuSwUpgradeFSM StateMachine", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2979 | "device-id": dh.DeviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2980 | dh.lockUpgradeFsm.Lock() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2981 | dh.pOnuUpradeFsm = nil //resource clearing is left to garbage collector |
| 2982 | dh.upgradeCanceled = false //cancelation done |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2983 | dh.pLastUpgradeImageState = apImageState |
| 2984 | dh.lockUpgradeFsm.Unlock() |
| 2985 | //signal upgradeFsm removed using non-blocking channel send |
| 2986 | select { |
| 2987 | case dh.upgradeFsmChan <- struct{}{}: |
| 2988 | default: |
| 2989 | 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] | 2990 | "device-id": dh.DeviceID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2991 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2992 | } |
| 2993 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2994 | // checkOnOnuImageCommit verifies if the ONU is in some upgrade state that allows for image commit and if tries to commit |
| 2995 | func (dh *deviceHandler) checkOnOnuImageCommit(ctx context.Context) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2996 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2997 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2998 | 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] | 2999 | return |
| 3000 | } |
| 3001 | |
| 3002 | dh.lockUpgradeFsm.RLock() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3003 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3004 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3005 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 3006 | dh.lockUpgradeFsm.RUnlock() |
| 3007 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 3008 | return |
| 3009 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3010 | pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3011 | if pUpgradeStatemachine != nil { |
| 3012 | // commit is only processed in case out upgrade FSM indicates the according state (for automatic commit) |
| 3013 | // (some manual forced commit could do without) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3014 | UpgradeState := pUpgradeStatemachine.Current() |
| 3015 | if (UpgradeState == swupg.UpgradeStWaitForCommit) || |
| 3016 | (UpgradeState == swupg.UpgradeStRequestingActivate) { |
| 3017 | // 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] | 3018 | // 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] | 3019 | if pDevEntry.IsImageToBeCommitted(ctx, dh.pOnuUpradeFsm.InactiveImageMeID) { |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3020 | activeImageID, errImg := pDevEntry.GetActiveImageMeID(ctx) |
| 3021 | if errImg != nil { |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3022 | dh.lockUpgradeFsm.RUnlock() |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3023 | logger.Errorw(ctx, "OnuSwUpgradeFSM abort - could not get active image after reboot", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3024 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3025 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 3026 | dh.upgradeCanceled = true |
| 3027 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 3028 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3029 | return |
| 3030 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3031 | dh.lockUpgradeFsm.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3032 | if activeImageID == dh.pOnuUpradeFsm.InactiveImageMeID { |
| 3033 | if (UpgradeState == swupg.UpgradeStRequestingActivate) && !dh.pOnuUpradeFsm.GetCommitFlag(ctx) { |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3034 | // 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] | 3035 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvActivationDone); err != nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3036 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call activate-done event", |
| 3037 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3038 | return |
| 3039 | } |
| 3040 | logger.Debugw(ctx, "OnuSwUpgradeFSM activate-done after reboot", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3041 | "state": UpgradeState, "device-id": dh.DeviceID}) |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3042 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3043 | //FSM in waitForCommit or (UpgradeStRequestingActivate [lost ActivateResp] and commit allowed) |
| 3044 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvCommitSw); err != nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3045 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call commit event", |
| 3046 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3047 | return |
| 3048 | } |
| 3049 | logger.Debugw(ctx, "OnuSwUpgradeFSM commit image requested", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3050 | "state": UpgradeState, "device-id": dh.DeviceID}) |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3051 | } |
| 3052 | } else { |
| 3053 | 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] | 3054 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 3055 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 3056 | dh.upgradeCanceled = true |
| 3057 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 3058 | } |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 3059 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3060 | return |
| 3061 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3062 | dh.lockUpgradeFsm.RUnlock() |
| 3063 | logger.Errorw(ctx, "OnuSwUpgradeFSM waiting to commit, but nothing to commit on ONU - abort upgrade", |
| 3064 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 3065 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 3066 | dh.upgradeCanceled = true |
| 3067 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 3068 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3069 | return |
| 3070 | } |
| 3071 | //upgrade FSM is active but not waiting for commit: maybe because commit flag is not set |
| 3072 | // upgrade FSM is to be informed if the current active image is the one that was used in upgrade for the download |
| 3073 | if activeImageID, err := pDevEntry.GetActiveImageMeID(ctx); err == nil { |
| 3074 | if dh.pOnuUpradeFsm.InactiveImageMeID == activeImageID { |
| 3075 | logger.Debugw(ctx, "OnuSwUpgradeFSM image state set to activated", log.Fields{ |
| 3076 | "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
| 3077 | dh.pOnuUpradeFsm.SetImageStateActive(ctx) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 3078 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3079 | } |
| 3080 | } |
| 3081 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3082 | 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] | 3083 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 3084 | dh.lockUpgradeFsm.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3085 | } |
| 3086 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3087 | //SetBackend provides a DB backend for the specified path on the existing KV client |
| 3088 | func (dh *deviceHandler) SetBackend(ctx context.Context, aBasePathKvStore string) *db.Backend { |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 3089 | |
| 3090 | logger.Debugw(ctx, "SetKVStoreBackend", log.Fields{"IpTarget": dh.pOpenOnuAc.KVStoreAddress, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3091 | "BasePathKvStore": aBasePathKvStore, "device-id": dh.DeviceID}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 3092 | // 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] | 3093 | kvbackend := &db.Backend{ |
| 3094 | Client: dh.pOpenOnuAc.kvClient, |
| 3095 | StoreType: dh.pOpenOnuAc.KVStoreType, |
| 3096 | /* address config update acc. to [VOL-2736] */ |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 3097 | Address: dh.pOpenOnuAc.KVStoreAddress, |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 3098 | Timeout: dh.pOpenOnuAc.KVStoreTimeout, |
| 3099 | PathPrefix: aBasePathKvStore} |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 3100 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 3101 | return kvbackend |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 3102 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3103 | func (dh *deviceHandler) getFlowOfbFields(ctx context.Context, apFlowItem *of.OfpFlowStats, loMatchVlan *uint16, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3104 | loAddPcp *uint8, loIPProto *uint32) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3105 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3106 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 3107 | switch field.Type { |
| 3108 | case of.OxmOfbFieldTypes_OFPXMT_OFB_ETH_TYPE: |
| 3109 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3110 | logger.Debugw(ctx, "flow type EthType", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3111 | "EthType": strconv.FormatInt(int64(field.GetEthType()), 16)}) |
| 3112 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3113 | /* TT related temporary workaround - should not be needed anymore |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3114 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO: |
| 3115 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3116 | *loIPProto = field.GetIpProto() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3117 | logger.Debugw("flow type IpProto", log.Fields{"device-id": dh.DeviceID, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3118 | "IpProto": strconv.FormatInt(int64(*loIPProto), 16)}) |
| 3119 | if *loIPProto == 2 { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3120 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 3121 | // avoids installing invalid EVTOCD rule |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3122 | logger.Debugw("flow type IpProto 2: TT workaround: ignore flow", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3123 | log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3124 | return |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3125 | } |
| 3126 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3127 | */ |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3128 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID: |
| 3129 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3130 | *loMatchVlan = uint16(field.GetVlanVid()) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3131 | loMatchVlanMask := uint16(field.GetVlanVidMask()) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3132 | if !(*loMatchVlan == uint16(of.OfpVlanId_OFPVID_PRESENT) && |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3133 | loMatchVlanMask == uint16(of.OfpVlanId_OFPVID_PRESENT)) { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3134 | *loMatchVlan = *loMatchVlan & 0xFFF // not transparent: copy only ID bits |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3135 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3136 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3137 | "VID": strconv.FormatInt(int64(*loMatchVlan), 16)}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3138 | } |
| 3139 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP: |
| 3140 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3141 | *loAddPcp = uint8(field.GetVlanPcp()) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3142 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3143 | "PCP": loAddPcp}) |
| 3144 | } |
| 3145 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_DST: |
| 3146 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3147 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3148 | "UDP-DST": strconv.FormatInt(int64(field.GetUdpDst()), 16)}) |
| 3149 | } |
| 3150 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_SRC: |
| 3151 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3152 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3153 | "UDP-SRC": strconv.FormatInt(int64(field.GetUdpSrc()), 16)}) |
| 3154 | } |
| 3155 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_DST: |
| 3156 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3157 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3158 | "IPv4-DST": field.GetIpv4Dst()}) |
| 3159 | } |
| 3160 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_SRC: |
| 3161 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3162 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3163 | "IPv4-SRC": field.GetIpv4Src()}) |
| 3164 | } |
| 3165 | case of.OxmOfbFieldTypes_OFPXMT_OFB_METADATA: |
| 3166 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3167 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3168 | "Metadata": field.GetTableMetadata()}) |
| 3169 | } |
| 3170 | /* |
| 3171 | default: |
| 3172 | { |
| 3173 | //all other entires ignored |
| 3174 | } |
| 3175 | */ |
| 3176 | } |
| 3177 | } //for all OfbFields |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3178 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3179 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3180 | 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] | 3181 | for _, action := range flow.GetActions(apFlowItem) { |
| 3182 | switch action.Type { |
| 3183 | /* not used: |
| 3184 | case of.OfpActionType_OFPAT_OUTPUT: |
| 3185 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3186 | logger.Debugw("flow action type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3187 | "Output": action.GetOutput()}) |
| 3188 | } |
| 3189 | */ |
| 3190 | case of.OfpActionType_OFPAT_PUSH_VLAN: |
| 3191 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3192 | logger.Debugw(ctx, "flow action type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3193 | "PushEthType": strconv.FormatInt(int64(action.GetPush().Ethertype), 16)}) |
| 3194 | } |
| 3195 | case of.OfpActionType_OFPAT_SET_FIELD: |
| 3196 | { |
| 3197 | pActionSetField := action.GetSetField() |
| 3198 | if pActionSetField.Field.OxmClass != of.OfpOxmClass_OFPXMC_OPENFLOW_BASIC { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3199 | 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] | 3200 | "OxcmClass": pActionSetField.Field.OxmClass}) |
| 3201 | } |
| 3202 | if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3203 | *loSetVlan = uint16(pActionSetField.Field.GetOfbField().GetVlanVid()) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3204 | 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] | 3205 | "SetVlan": strconv.FormatInt(int64(*loSetVlan), 16)}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3206 | } else if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3207 | *loSetPcp = uint8(pActionSetField.Field.GetOfbField().GetVlanPcp()) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3208 | 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] | 3209 | "SetPcp": *loSetPcp}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3210 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3211 | 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] | 3212 | "Type": pActionSetField.Field.GetOfbField().Type}) |
| 3213 | } |
| 3214 | } |
| 3215 | /* |
| 3216 | default: |
| 3217 | { |
| 3218 | //all other entires ignored |
| 3219 | } |
| 3220 | */ |
| 3221 | } |
| 3222 | } //for all Actions |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | //addFlowItemToUniPort parses the actual flow item to add it to the UniPort |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3226 | func (dh *deviceHandler) addFlowItemToUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort, |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3227 | apFlowMetaData *of.FlowMetadata, respChan *chan error) { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3228 | var loSetVlan uint16 = uint16(of.OfpVlanId_OFPVID_NONE) //noValidEntry |
| 3229 | var loMatchVlan uint16 = uint16(of.OfpVlanId_OFPVID_PRESENT) //reserved VLANID entry |
| 3230 | var loAddPcp, loSetPcp uint8 |
| 3231 | var loIPProto uint32 |
| 3232 | /* the TechProfileId is part of the flow Metadata - compare also comment within |
| 3233 | * OLT-Adapter:openolt_flowmgr.go |
| 3234 | * Metadata 8 bytes: |
| 3235 | * Most Significant 2 Bytes = Inner VLAN |
| 3236 | * Next 2 Bytes = Tech Profile ID(TPID) |
| 3237 | * Least Significant 4 Bytes = Port ID |
| 3238 | * Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all |
| 3239 | * subscriber related flows. |
| 3240 | */ |
| 3241 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3242 | metadata := flow.GetMetadataFromWriteMetadataAction(ctx, apFlowItem) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3243 | if metadata == 0 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3244 | logger.Debugw(ctx, "flow-add invalid metadata - abort", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3245 | log.Fields{"device-id": dh.DeviceID}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3246 | *respChan <- fmt.Errorf("flow-add invalid metadata: %s", dh.DeviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3247 | } |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3248 | loTpID := uint8(flow.GetTechProfileIDFromWriteMetaData(ctx, metadata)) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3249 | loCookie := apFlowItem.GetCookie() |
| 3250 | loCookieSlice := []uint64{loCookie} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3251 | logger.Debugw(ctx, "flow-add base indications", log.Fields{"device-id": dh.DeviceID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3252 | "TechProf-Id": loTpID, "cookie": loCookie}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3253 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3254 | dh.getFlowOfbFields(ctx, apFlowItem, &loMatchVlan, &loAddPcp, &loIPProto) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3255 | /* TT related temporary workaround - should not be needed anymore |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3256 | if loIPProto == 2 { |
| 3257 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 3258 | // avoids installing invalid EVTOCD rule |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3259 | logger.Debugw("flow-add type IpProto 2: TT workaround: ignore flow", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3260 | log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3261 | return nil |
| 3262 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3263 | */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3264 | dh.getFlowActions(ctx, apFlowItem, &loSetPcp, &loSetVlan) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3265 | |
| 3266 | if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3267 | 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] | 3268 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3269 | "set_vid": strconv.FormatInt(int64(loSetVlan), 16), |
| 3270 | "match_vid": strconv.FormatInt(int64(loMatchVlan), 16)}) |
| 3271 | //TODO!!: Use DeviceId within the error response to rwCore |
| 3272 | // 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] | 3273 | *respChan <- fmt.Errorf("flow-add Set/Match VlanId inconsistent: %s", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3274 | } |
| 3275 | 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] | 3276 | 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] | 3277 | loSetVlan = loMatchVlan //both 'transparent' (copy any) |
| 3278 | } else { |
| 3279 | //looks like OMCI value 4097 (copyFromOuter - for Uni double tagged) is not supported here |
| 3280 | if loSetVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
| 3281 | // not set to transparent |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3282 | loSetVlan &= 0x0FFF //mask VID bits as prerequisite for vlanConfigFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3283 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3284 | logger.Debugw(ctx, "flow-add vlan-set", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3285 | } |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3286 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3287 | var meter *of.OfpMeterConfig |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3288 | if apFlowMetaData != nil { |
| 3289 | meter = apFlowMetaData.Meters[0] |
| 3290 | } |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3291 | //mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities |
| 3292 | // must be set including the execution of createVlanFilterFsm() to avoid unintended creation of FSM's |
| 3293 | // when different rules are requested concurrently for the same uni |
| 3294 | // (also vlan persistency data does not support multiple FSM's on the same UNI correctly!) |
| 3295 | dh.lockVlanAdd.Lock() //prevent multiple add activities to start in parallel |
| 3296 | dh.lockVlanConfig.RLock() //read protection on UniVlanConfigFsmMap (removeFlowItemFromUniPort) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3297 | logger.Debugw(ctx, "flow-add got lock", log.Fields{"device-id": dh.DeviceID, "tpID": loTpID, "uniID": apUniPort.UniID}) |
| 3298 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3299 | //SetUniFlowParams() may block on some rule that is suspended-to-add |
| 3300 | // 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] | 3301 | // Also the error is returned to caller via response channel |
| 3302 | _ = dh.UniVlanConfigFsmMap[apUniPort.UniID].SetUniFlowParams(ctx, loTpID, loCookieSlice, |
| 3303 | loMatchVlan, loSetVlan, loSetPcp, false, meter, respChan) |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3304 | dh.lockVlanConfig.RUnlock() |
| 3305 | dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3306 | return |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3307 | } |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3308 | dh.lockVlanConfig.RUnlock() |
| 3309 | 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] | 3310 | err := dh.createVlanFilterFsm(ctx, apUniPort, loTpID, loCookieSlice, |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3311 | loMatchVlan, loSetVlan, loSetPcp, cmn.OmciVlanFilterAddDone, false, meter, respChan) |
mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3312 | dh.lockVlanConfig.Unlock() |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3313 | dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3314 | if err != nil { |
| 3315 | *respChan <- err |
| 3316 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | //removeFlowItemFromUniPort parses the actual flow item to remove it from the UniPort |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3320 | 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] | 3321 | //optimization and assumption: the flow cookie uniquely identifies the flow and with that the internal rule |
| 3322 | //hence only the cookie is used here to find the relevant flow and possibly remove the rule |
| 3323 | //no extra check is done on the rule parameters |
| 3324 | //accordingly the removal is done only once - for the first found flow with that cookie, even though |
| 3325 | // at flow creation is not assured, that the same cookie is not configured for different flows - just assumed |
| 3326 | //additionally it is assumed here, that removal can only be done for one cookie per flow in a sequence (different |
| 3327 | // 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] | 3328 | // - 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] | 3329 | loCookie := apFlowItem.GetCookie() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3330 | 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] | 3331 | |
| 3332 | /* TT related temporary workaround - should not be needed anymore |
| 3333 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 3334 | if field.Type == of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO { |
| 3335 | loIPProto := field.GetIpProto() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3336 | logger.Debugw(ctx, "flow type IpProto", log.Fields{"device-id": dh.DeviceID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3337 | "IpProto": strconv.FormatInt(int64(loIPProto), 16)}) |
| 3338 | if loIPProto == 2 { |
| 3339 | // 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] | 3340 | logger.Debugw(ctx, "flow-remove type IpProto 2: TT workaround: ignore flow", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3341 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3342 | return nil |
| 3343 | } |
| 3344 | } |
| 3345 | } //for all OfbFields |
| 3346 | */ |
| 3347 | |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3348 | //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] | 3349 | dh.lockVlanConfig.RLock() |
| 3350 | defer dh.lockVlanConfig.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3351 | logger.Debugw(ctx, "flow-remove got RLock", log.Fields{"device-id": dh.DeviceID, "uniID": apUniPort.UniID}) |
| 3352 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3353 | _ = dh.UniVlanConfigFsmMap[apUniPort.UniID].RemoveUniFlowParams(ctx, loCookie, respChan) |
| 3354 | return |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3355 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3356 | 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] | 3357 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3358 | //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] | 3359 | // 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] | 3360 | // Push response on the response channel |
| 3361 | if respChan != nil { |
| 3362 | // 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 |
| 3363 | select { |
| 3364 | case *respChan <- nil: |
| 3365 | logger.Debugw(ctx, "submitted-response-for-flow", log.Fields{"device-id": dh.DeviceID, "err": nil}) |
| 3366 | default: |
| 3367 | } |
| 3368 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3369 | go dh.DeviceProcStatusUpdate(ctx, cmn.OmciVlanFilterRemDone) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3370 | } |
| 3371 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3372 | // createVlanFilterFsm initializes and runs the VlanFilter FSM to transfer OMCI related VLAN config |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3373 | // 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] | 3374 | // precondition: dh.lockVlanConfig is locked by the caller! |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3375 | func (dh *deviceHandler) createVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8, aCookieSlice []uint64, |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3376 | aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8, aDevEvent cmn.OnuDeviceEvent, lastFlowToReconcile bool, aMeter *of.OfpMeterConfig, respChan *chan error) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3377 | chVlanFilterFsm := make(chan cmn.Message, 2048) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3378 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3379 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3380 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3381 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 3382 | return fmt.Errorf("no valid OnuDevice for device-id %x - aborting", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3383 | } |
| 3384 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3385 | pVlanFilterFsm := avcfg.NewUniVlanConfigFsm(ctx, dh, pDevEntry, pDevEntry.PDevOmciCC, apUniPort, dh.pOnuTP, |
| 3386 | pDevEntry.GetOnuDB(), aTpID, aDevEvent, "UniVlanConfigFsm", chVlanFilterFsm, |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3387 | dh.pOpenOnuAc.AcceptIncrementalEvto, aCookieSlice, aMatchVlan, aSetVlan, aSetPcp, lastFlowToReconcile, aMeter, respChan) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3388 | if pVlanFilterFsm != nil { |
mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3389 | //dh.lockVlanConfig is locked (by caller) throughout the state transition to 'starting' |
| 3390 | // to prevent unintended (ignored) events to be sent there (from parallel processing) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3391 | dh.UniVlanConfigFsmMap[apUniPort.UniID] = pVlanFilterFsm |
| 3392 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3393 | if pVlanFilterStatemachine != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3394 | if pVlanFilterStatemachine.Is(avcfg.VlanStDisabled) { |
| 3395 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvStart); err != nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3396 | logger.Warnw(ctx, "UniVlanConfigFsm: can't start", |
| 3397 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3398 | return fmt.Errorf("can't start UniVlanConfigFsm for device-id %x", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3399 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3400 | /***** UniVlanConfigFsm started */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3401 | logger.Debugw(ctx, "UniVlanConfigFsm started", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3402 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3403 | "UniPort": apUniPort.PortNo}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3404 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3405 | logger.Warnw(ctx, "wrong state of UniVlanConfigFsm - want: disabled", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3406 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID}) |
| 3407 | 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] | 3408 | } |
| 3409 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3410 | logger.Errorw(ctx, "UniVlanConfigFsm StateMachine invalid - cannot be executed!!", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3411 | "device-id": dh.DeviceID}) |
| 3412 | return fmt.Errorf("uniVlanConfigFsm invalid for device-id %x", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3413 | } |
| 3414 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3415 | logger.Errorw(ctx, "UniVlanConfigFsm could not be created - abort!!", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3416 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| 3417 | 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] | 3418 | } |
| 3419 | return nil |
| 3420 | } |
| 3421 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3422 | //VerifyVlanConfigRequest checks on existence of a given uniPort |
| 3423 | // and starts verification of flow config based on that |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3424 | func (dh *deviceHandler) VerifyVlanConfigRequest(ctx context.Context, aUniID uint8, aTpID uint8) { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3425 | //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] | 3426 | var pCurrentUniPort *cmn.OnuUniPort |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3427 | for _, uniPort := range dh.uniEntityMap { |
| 3428 | // only if this port is validated for operState transfer |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3429 | if uniPort.UniID == uint8(aUniID) { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3430 | pCurrentUniPort = uniPort |
| 3431 | break //found - end search loop |
| 3432 | } |
| 3433 | } |
| 3434 | if pCurrentUniPort == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3435 | logger.Debugw(ctx, "VerifyVlanConfig aborted: requested uniID not found in PortDB", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3436 | log.Fields{"device-id": dh.DeviceID, "uni-id": aUniID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3437 | return |
| 3438 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3439 | dh.VerifyUniVlanConfigRequest(ctx, pCurrentUniPort, aTpID) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3440 | } |
| 3441 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3442 | //VerifyUniVlanConfigRequest checks on existence of flow configuration and starts it accordingly |
| 3443 | func (dh *deviceHandler) VerifyUniVlanConfigRequest(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3444 | //TODO!! verify and start pending flow configuration |
| 3445 | //some pending config request my exist in case the UniVlanConfig FSM was already started - with internal data - |
| 3446 | //but execution was set to 'on hold' as first the TechProfile config had to be applied |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3447 | |
| 3448 | dh.lockVlanConfig.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3449 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3450 | dh.lockVlanConfig.RUnlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3451 | //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] | 3452 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3453 | if pVlanFilterStatemachine != nil { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3454 | //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] | 3455 | if pVlanFilterFsm.GetWaitingTpID(ctx) == aTpID { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3456 | if pVlanFilterStatemachine.Is(avcfg.VlanStWaitingTechProf) { |
| 3457 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvContinueConfig); err != nil { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3458 | logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3459 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3460 | } else { |
| 3461 | /***** UniVlanConfigFsm continued */ |
| 3462 | logger.Debugw(ctx, "UniVlanConfigFsm continued", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3463 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3464 | "UniPort": apUniPort.PortNo}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3465 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3466 | } else if pVlanFilterStatemachine.Is(avcfg.VlanStIncrFlowWaitTP) { |
| 3467 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvIncrFlowConfig); err != nil { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3468 | logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3469 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3470 | } else { |
| 3471 | /***** UniVlanConfigFsm continued */ |
| 3472 | logger.Debugw(ctx, "UniVlanConfigFsm continued with incremental flow", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3473 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3474 | "UniPort": apUniPort.PortNo}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3475 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3476 | } else { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3477 | logger.Debugw(ctx, "no state of UniVlanConfigFsm to be continued", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3478 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3479 | "UniPort": apUniPort.PortNo}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3480 | } |
| 3481 | } else { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3482 | 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] | 3483 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3484 | "UniPort": apUniPort.PortNo, "techprofile-id (done)": aTpID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3485 | } |
| 3486 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3487 | 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] | 3488 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3489 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3490 | } else { |
| 3491 | dh.lockVlanConfig.RUnlock() |
| 3492 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3493 | } |
| 3494 | |
| 3495 | //RemoveVlanFilterFsm deletes the stored pointer to the VlanConfigFsm |
| 3496 | // 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] | 3497 | func (dh *deviceHandler) RemoveVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3498 | logger.Debugw(ctx, "remove UniVlanConfigFsm StateMachine", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3499 | "device-id": dh.DeviceID, "uniPort": apUniPort.PortNo}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3500 | //save to do, even if entry dows not exist |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3501 | dh.lockVlanConfig.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3502 | delete(dh.UniVlanConfigFsmMap, apUniPort.UniID) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3503 | dh.lockVlanConfig.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3504 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3505 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3506 | //startWritingOnuDataToKvStore initiates the KVStore write of ONU persistent data |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3507 | func (dh *deviceHandler) startWritingOnuDataToKvStore(ctx context.Context, aPDevEntry *mib.OnuDeviceEntry) error { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3508 | dh.mutexKvStoreContext.Lock() //this write routine may (could) be called with the same context, |
| 3509 | defer dh.mutexKvStoreContext.Unlock() //this write routine may (could) be called with the same context, |
| 3510 | // obviously then parallel processing on the cancel must be avoided |
| 3511 | // deadline context to ensure completion of background routines waited for |
| 3512 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 3513 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 3514 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 3515 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3516 | aPDevEntry.ResetKvProcessingErrorIndication() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3517 | var wg sync.WaitGroup |
| 3518 | wg.Add(1) // for the 1 go routine to finish |
| 3519 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3520 | go aPDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3521 | dh.waitForCompletion(ctx, cancel, &wg, "UpdateKvStore") //wait for background process to finish |
| 3522 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3523 | return aPDevEntry.GetKvProcessingErrorIndication() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3524 | } |
| 3525 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3526 | //StorePersUniFlowConfig updates local storage of OnuUniFlowConfig and writes it into kv-store afterwards to have it |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3527 | //available for potential reconcilement |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3528 | func (dh *deviceHandler) StorePersUniFlowConfig(ctx context.Context, aUniID uint8, |
| 3529 | aUniVlanFlowParams *[]cmn.UniVlanFlowParams, aWriteToKvStore bool) error { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3530 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3531 | if dh.IsReconciling() { |
| 3532 | logger.Debugw(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] | 3533 | return nil |
| 3534 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3535 | 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] | 3536 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3537 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3538 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3539 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 3540 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3541 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3542 | pDevEntry.UpdateOnuUniFlowConfig(aUniID, aUniVlanFlowParams) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3543 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3544 | if aWriteToKvStore { |
| 3545 | return dh.startWritingOnuDataToKvStore(ctx, pDevEntry) |
| 3546 | } |
| 3547 | return nil |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3548 | } |
| 3549 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3550 | 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] | 3551 | defer cancel() //ensure termination of context (may be pro forma) |
| 3552 | wg.Wait() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3553 | logger.Debugw(ctx, "WaitGroup processing completed", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3554 | "device-id": dh.DeviceID, "called from": aCallerIdent}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3555 | } |
| 3556 | |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 3557 | //ReasonUpdate set the internally store device reason and if requested in notifyCore updates this state in the core |
| 3558 | // (renamed from previous deviceReasonUpdate to avoid confusing with the core function DeviceReasonUpdate) |
| 3559 | func (dh *deviceHandler) ReasonUpdate(ctx context.Context, deviceReason uint8, notifyCore bool) error { |
| 3560 | // acquire the deviceReason semaphore throughout this function including the possible update processing in core |
| 3561 | // in order to avoid reversion of the state sequence within core in case of quasi-parallel calls (eg. in multi UNI processing) |
| 3562 | dh.mutexDeviceReason.Lock() |
| 3563 | defer dh.mutexDeviceReason.Unlock() |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3564 | if notifyCore { |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 3565 | //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] | 3566 | if err := dh.updateDeviceReasonInCore(ctx, &ca.DeviceReason{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3567 | DeviceId: dh.DeviceID, |
| 3568 | Reason: cmn.DeviceReasonMap[deviceReason], |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3569 | }); err != nil { |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 3570 | logger.Errorf(ctx, "updating reason in core failed for: %s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3571 | log.Fields{"device-id": dh.DeviceID, "error": err}, cmn.DeviceReasonMap[deviceReason]) |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 3572 | return err |
| 3573 | } |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 3574 | } else { |
| 3575 | 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] | 3576 | } |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 3577 | dh.deviceReason = deviceReason |
| 3578 | logger.Infof(ctx, "reason update done for: %s - device-id: %s - with core update: %v", |
| 3579 | cmn.DeviceReasonMap[deviceReason], dh.DeviceID, notifyCore) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3580 | return nil |
| 3581 | } |
| 3582 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3583 | func (dh *deviceHandler) StorePersistentData(ctx context.Context) error { |
| 3584 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3585 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3586 | logger.Warnw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 3587 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3588 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3589 | return dh.startWritingOnuDataToKvStore(ctx, pDevEntry) |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 3590 | } |
| 3591 | |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3592 | // 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] | 3593 | // nolint: unused |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3594 | func (dh *deviceHandler) getUniPortMEEntityID(uniPortNo uint32) (uint16, error) { |
| 3595 | dh.lockDevice.RLock() |
| 3596 | defer dh.lockDevice.RUnlock() |
| 3597 | if uniPort, ok := dh.uniEntityMap[uniPortNo]; ok { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3598 | return uniPort.EntityID, nil |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3599 | } |
| 3600 | return 0, errors.New("error-fetching-uni-port") |
| 3601 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3602 | |
| 3603 | // updatePmConfig updates the pm metrics config. |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3604 | func (dh *deviceHandler) updatePmConfig(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 3605 | var errorsList []error |
| 3606 | 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] | 3607 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3608 | errorsList = append(dh.handleGlobalPmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 3609 | errorsList = append(dh.handleGroupPmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 3610 | errorsList = append(dh.handleStandalonePmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 3611 | |
| 3612 | // Note that if more than one pm config field is updated in a given call, it is possible that partial pm config is handled |
| 3613 | // successfully. |
| 3614 | // TODO: Although it is possible to revert to old config in case of partial failure, the code becomes quite complex. Needs more investigation |
| 3615 | // Is it possible the rw-core reverts to old config on partial failure but adapter retains a partial new config? |
| 3616 | if len(errorsList) > 0 { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3617 | 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] | 3618 | 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] | 3619 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3620 | 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] | 3621 | return nil |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3622 | } |
| 3623 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3624 | func (dh *deviceHandler) handleGlobalPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 3625 | var err error |
| 3626 | var errorsList []error |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3627 | 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] | 3628 | |
| 3629 | if pmConfigs.DefaultFreq != dh.pmConfigs.DefaultFreq { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3630 | if err = dh.pOnuMetricsMgr.UpdateDefaultFrequency(ctx, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3631 | errorsList = append(errorsList, err) |
| 3632 | } |
| 3633 | } |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3634 | 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] | 3635 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3636 | return errorsList |
| 3637 | } |
| 3638 | |
| 3639 | func (dh *deviceHandler) handleGroupPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 3640 | var err error |
| 3641 | var errorsList []error |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3642 | 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] | 3643 | // Check if group metric related config is updated |
| 3644 | for _, v := range pmConfigs.Groups { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3645 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() |
| 3646 | m, ok := dh.pOnuMetricsMgr.GroupMetricMap[v.GroupName] |
| 3647 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3648 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3649 | if ok && m.Frequency != v.GroupFreq { |
| 3650 | if err = dh.pOnuMetricsMgr.UpdateGroupFreq(ctx, v.GroupName, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3651 | errorsList = append(errorsList, err) |
| 3652 | } |
| 3653 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3654 | if ok && m.Enabled != v.Enabled { |
| 3655 | if err = dh.pOnuMetricsMgr.UpdateGroupSupport(ctx, v.GroupName, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3656 | errorsList = append(errorsList, err) |
| 3657 | } |
| 3658 | } |
| 3659 | } |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3660 | 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] | 3661 | return errorsList |
| 3662 | } |
| 3663 | |
| 3664 | func (dh *deviceHandler) handleStandalonePmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 3665 | var err error |
| 3666 | var errorsList []error |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3667 | 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] | 3668 | // Check if standalone metric related config is updated |
| 3669 | for _, v := range pmConfigs.Metrics { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3670 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() |
| 3671 | m, ok := dh.pOnuMetricsMgr.StandaloneMetricMap[v.Name] |
| 3672 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3673 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3674 | if ok && m.Frequency != v.SampleFreq { |
| 3675 | if err = dh.pOnuMetricsMgr.UpdateMetricFreq(ctx, v.Name, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3676 | errorsList = append(errorsList, err) |
| 3677 | } |
| 3678 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3679 | if ok && m.Enabled != v.Enabled { |
| 3680 | if err = dh.pOnuMetricsMgr.UpdateMetricSupport(ctx, v.Name, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3681 | errorsList = append(errorsList, err) |
| 3682 | } |
| 3683 | } |
| 3684 | } |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3685 | 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] | 3686 | return errorsList |
| 3687 | } |
| 3688 | |
| 3689 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3690 | func (dh *deviceHandler) StartCollector(ctx context.Context) { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3691 | logger.Debugw(ctx, "startingCollector", log.Fields{"device-id": dh.device.Id}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3692 | |
| 3693 | // Start routine to process OMCI GET Responses |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3694 | go dh.pOnuMetricsMgr.ProcessOmciMessages(ctx) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3695 | // Create Extended Frame PM ME |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3696 | go dh.pOnuMetricsMgr.CreateEthernetFrameExtendedPMME(ctx) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3697 | // Initialize the next metric collection time. |
| 3698 | // Normally done when the onu_metrics_manager is initialized the first time, but needed again later when ONU is |
| 3699 | // reset like onu rebooted. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3700 | dh.pOnuMetricsMgr.InitializeMetricCollectionTime(ctx) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3701 | dh.setCollectorIsRunning(true) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3702 | for { |
| 3703 | select { |
| 3704 | case <-dh.stopCollector: |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3705 | dh.setCollectorIsRunning(false) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3706 | 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] | 3707 | // Stop the L2 PM FSM |
| 3708 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3709 | if dh.pOnuMetricsMgr.PAdaptFsm != nil && dh.pOnuMetricsMgr.PAdaptFsm.PFsm != nil { |
| 3710 | if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventStop); err != nil { |
| 3711 | 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] | 3712 | } |
| 3713 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3714 | 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] | 3715 | } |
| 3716 | }() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3717 | if dh.pOnuMetricsMgr.GetOmciProcessingStatus() { |
| 3718 | dh.pOnuMetricsMgr.StopProcessingOmciResponses <- true // Stop the OMCI GET response processing routine |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 3719 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3720 | if dh.pOnuMetricsMgr.GetTickGenerationStatus() { |
| 3721 | dh.pOnuMetricsMgr.StopTicks <- true |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 3722 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 3723 | |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3724 | return |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3725 | case <-time.After(time.Duration(pmmgr.FrequencyGranularity) * time.Second): // Check every FrequencyGranularity to see if it is time for collecting metrics |
| 3726 | if !dh.pmConfigs.FreqOverride { // If FreqOverride is false, then NextGlobalMetricCollectionTime applies |
| 3727 | // If the current time is eqaul to or greater than the NextGlobalMetricCollectionTime, collect the group and standalone metrics |
| 3728 | if time.Now().Equal(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) || time.Now().After(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) { |
| 3729 | go dh.pOnuMetricsMgr.CollectAllGroupAndStandaloneMetrics(ctx) |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 3730 | // Update the next metric collection time. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3731 | dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime = time.Now().Add(time.Duration(dh.pmConfigs.DefaultFreq) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3732 | } |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3733 | } else { |
| 3734 | if dh.pmConfigs.Grouped { // metrics are managed as a group |
| 3735 | // 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] | 3736 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() // Rlock as we are reading GroupMetricMap and StandaloneMetricMap |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3737 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3738 | for n, g := range dh.pOnuMetricsMgr.GroupMetricMap { |
| 3739 | // 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] | 3740 | // 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] | 3741 | if g.Enabled && !g.IsL2PMCounter && (time.Now().Equal(g.NextCollectionInterval) || time.Now().After(g.NextCollectionInterval)) { |
| 3742 | go dh.pOnuMetricsMgr.CollectGroupMetric(ctx, n) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3743 | } |
| 3744 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3745 | for n, m := range dh.pOnuMetricsMgr.StandaloneMetricMap { |
| 3746 | // If the standalone is enabled AND (current time is equal to OR after NextCollectionInterval, collect the metric) |
| 3747 | if m.Enabled && (time.Now().Equal(m.NextCollectionInterval) || time.Now().After(m.NextCollectionInterval)) { |
| 3748 | go dh.pOnuMetricsMgr.CollectStandaloneMetric(ctx, n) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3749 | } |
| 3750 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3751 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3752 | |
| 3753 | // parse through the group and update the next metric collection time |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3754 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.Lock() // Lock as we are writing the next metric collection time |
| 3755 | for _, g := range dh.pOnuMetricsMgr.GroupMetricMap { |
| 3756 | // 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] | 3757 | // 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] | 3758 | if g.Enabled && !g.IsL2PMCounter && (g.NextCollectionInterval.Before(time.Now()) || g.NextCollectionInterval.Equal(time.Now())) { |
| 3759 | g.NextCollectionInterval = time.Now().Add(time.Duration(g.Frequency) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3760 | } |
| 3761 | } |
| 3762 | // parse through the standalone metrics and update the next metric collection time |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3763 | for _, m := range dh.pOnuMetricsMgr.StandaloneMetricMap { |
| 3764 | // If standalone metrics enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp |
| 3765 | if m.Enabled && (m.NextCollectionInterval.Before(time.Now()) || m.NextCollectionInterval.Equal(time.Now())) { |
| 3766 | m.NextCollectionInterval = time.Now().Add(time.Duration(m.Frequency) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3767 | } |
| 3768 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3769 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3770 | } /* else { // metrics are not managed as a group |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3771 | // 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] | 3772 | } */ |
| 3773 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3774 | } |
| 3775 | } |
| 3776 | } |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 3777 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3778 | func (dh *deviceHandler) GetUniPortStatus(ctx context.Context, uniInfo *extension.GetOnuUniInfoRequest) *extension.SingleGetValueResponse { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 3779 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3780 | portStatus := uniprt.NewUniPortStatus(dh, dh.pOnuOmciDevice.PDevOmciCC) |
| 3781 | return portStatus.GetUniPortStatus(ctx, uniInfo.UniIndex) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 3782 | } |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3783 | |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3784 | func (dh *deviceHandler) getOnuOMCICounters(ctx context.Context, onuInfo *extension.GetOmciEthernetFrameExtendedPmRequest) *extension.SingleGetValueResponse { |
| 3785 | if dh.pOnuMetricsMgr == nil { |
| 3786 | return &extension.SingleGetValueResponse{ |
| 3787 | Response: &extension.GetValueResponse{ |
| 3788 | Status: extension.GetValueResponse_ERROR, |
| 3789 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 3790 | }, |
| 3791 | } |
| 3792 | } |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3793 | resp := dh.pOnuMetricsMgr.CollectEthernetFrameExtendedPMCounters(ctx, onuInfo) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3794 | return resp |
| 3795 | } |
| 3796 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3797 | func (dh *deviceHandler) isFsmInOmciIdleState(ctx context.Context, PFsm *fsm.FSM, wantedState string) bool { |
| 3798 | if PFsm == nil { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3799 | return true //FSM not active - so there is no activity on omci |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3800 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3801 | return PFsm.Current() == wantedState |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3802 | } |
| 3803 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3804 | func (dh *deviceHandler) isFsmInOmciIdleStateDefault(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, wantedState string) bool { |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3805 | var pAdapterFsm *cmn.AdapterFsm |
| 3806 | //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] | 3807 | switch omciFsm { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3808 | case cmn.CUploadFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3809 | { |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3810 | if dh.pOnuOmciDevice != nil { |
| 3811 | pAdapterFsm = dh.pOnuOmciDevice.PMibUploadFsm |
| 3812 | } else { |
| 3813 | return true //FSM not active - so there is no activity on omci |
| 3814 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3815 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3816 | case cmn.CDownloadFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3817 | { |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3818 | if dh.pOnuOmciDevice != nil { |
| 3819 | pAdapterFsm = dh.pOnuOmciDevice.PMibDownloadFsm |
| 3820 | } else { |
| 3821 | return true //FSM not active - so there is no activity on omci |
| 3822 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3823 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3824 | case cmn.CUniLockFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3825 | { |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3826 | if dh.pLockStateFsm != nil { |
| 3827 | pAdapterFsm = dh.pLockStateFsm.PAdaptFsm |
| 3828 | } else { |
| 3829 | return true //FSM not active - so there is no activity on omci |
| 3830 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3831 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3832 | case cmn.CUniUnLockFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3833 | { |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3834 | if dh.pUnlockStateFsm != nil { |
| 3835 | pAdapterFsm = dh.pUnlockStateFsm.PAdaptFsm |
| 3836 | } else { |
| 3837 | return true //FSM not active - so there is no activity on omci |
| 3838 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3839 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3840 | case cmn.CL2PmFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3841 | { |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3842 | if dh.pOnuMetricsMgr != nil { |
| 3843 | pAdapterFsm = dh.pOnuMetricsMgr.PAdaptFsm |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3844 | } else { |
| 3845 | return true //FSM not active - so there is no activity on omci |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3846 | } |
| 3847 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3848 | case cmn.COnuUpgradeFsm: |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3849 | { |
| 3850 | dh.lockUpgradeFsm.RLock() |
| 3851 | defer dh.lockUpgradeFsm.RUnlock() |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3852 | if dh.pOnuUpradeFsm != nil { |
| 3853 | pAdapterFsm = dh.pOnuUpradeFsm.PAdaptFsm |
| 3854 | } else { |
| 3855 | return true //FSM not active - so there is no activity on omci |
| 3856 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3857 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3858 | default: |
| 3859 | { |
| 3860 | logger.Errorw(ctx, "invalid stateMachine selected for idle check", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3861 | "device-id": dh.DeviceID, "selectedFsm number": omciFsm}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3862 | 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] | 3863 | } |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3864 | } |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3865 | if pAdapterFsm != nil && pAdapterFsm.PFsm != nil { |
| 3866 | return dh.isFsmInOmciIdleState(ctx, pAdapterFsm.PFsm, wantedState) |
| 3867 | } |
| 3868 | return true //FSM not active - so there is no activity on omci |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3869 | } |
| 3870 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3871 | func (dh *deviceHandler) isAniConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool { |
| 3872 | for _, v := range dh.pOnuTP.PAniConfigFsm { |
| 3873 | if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3874 | return false |
| 3875 | } |
| 3876 | } |
| 3877 | return true |
| 3878 | } |
| 3879 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3880 | func (dh *deviceHandler) isUniVlanConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3881 | dh.lockVlanConfig.RLock() |
| 3882 | defer dh.lockVlanConfig.RUnlock() |
| 3883 | for _, v := range dh.UniVlanConfigFsmMap { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3884 | if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3885 | return false |
| 3886 | } |
| 3887 | } |
| 3888 | return true //FSM not active - so there is no activity on omci |
| 3889 | } |
| 3890 | |
| 3891 | func (dh *deviceHandler) checkUserServiceExists(ctx context.Context) bool { |
| 3892 | dh.lockVlanConfig.RLock() |
| 3893 | defer dh.lockVlanConfig.RUnlock() |
| 3894 | for _, v := range dh.UniVlanConfigFsmMap { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3895 | if v.PAdaptFsm.PFsm != nil { |
| 3896 | if v.PAdaptFsm.PFsm.Is(avcfg.CVlanFsmConfiguredState) { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3897 | return true //there is at least one VLAN FSM with some active configuration |
| 3898 | } |
| 3899 | } |
| 3900 | } |
| 3901 | return false //there is no VLAN FSM with some active configuration |
| 3902 | } |
| 3903 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3904 | func (dh *deviceHandler) CheckAuditStartCondition(ctx context.Context, callingFsm cmn.UsedOmciConfigFsms) bool { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3905 | for fsmName, fsmStruct := range fsmOmciIdleStateFuncMap { |
| 3906 | if fsmName != callingFsm && !fsmStruct.omciIdleCheckFunc(dh, ctx, fsmName, fsmStruct.omciIdleState) { |
| 3907 | return false |
| 3908 | } |
| 3909 | } |
| 3910 | // a further check is done to identify, if at least some data traffic related configuration exists |
| 3911 | // 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]) |
| 3912 | return dh.checkUserServiceExists(ctx) |
| 3913 | } |
| 3914 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3915 | func (dh *deviceHandler) PrepareReconcilingWithActiveAdapter(ctx context.Context) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3916 | logger.Debugw(ctx, "prepare to reconcile the ONU with adapter using persistency data", log.Fields{"device-id": dh.device.Id}) |
| 3917 | if err := dh.resetFsms(ctx, false); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3918 | 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] | 3919 | // TODO: fatal error reset ONU, delete deviceHandler! |
| 3920 | return |
| 3921 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3922 | dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort) |
| 3923 | dh.StartReconciling(ctx, false) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | func (dh *deviceHandler) setCollectorIsRunning(flagValue bool) { |
| 3927 | dh.mutexCollectorFlag.Lock() |
| 3928 | dh.collectorIsRunning = flagValue |
| 3929 | dh.mutexCollectorFlag.Unlock() |
| 3930 | } |
| 3931 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3932 | func (dh *deviceHandler) GetCollectorIsRunning() bool { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3933 | dh.mutexCollectorFlag.RLock() |
| 3934 | flagValue := dh.collectorIsRunning |
| 3935 | dh.mutexCollectorFlag.RUnlock() |
| 3936 | return flagValue |
| 3937 | } |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 3938 | |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 3939 | func (dh *deviceHandler) setAlarmManagerIsRunning(flagValue bool) { |
| 3940 | dh.mutextAlarmManagerFlag.Lock() |
| 3941 | dh.alarmManagerIsRunning = flagValue |
| 3942 | dh.mutextAlarmManagerFlag.Unlock() |
| 3943 | } |
| 3944 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3945 | func (dh *deviceHandler) GetAlarmManagerIsRunning(ctx context.Context) bool { |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 3946 | dh.mutextAlarmManagerFlag.RLock() |
| 3947 | flagValue := dh.alarmManagerIsRunning |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3948 | 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] | 3949 | dh.mutextAlarmManagerFlag.RUnlock() |
| 3950 | return flagValue |
| 3951 | } |
| 3952 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3953 | func (dh *deviceHandler) StartAlarmManager(ctx context.Context) { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3954 | logger.Debugw(ctx, "startingAlarmManager", log.Fields{"device-id": dh.device.Id}) |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 3955 | |
| 3956 | // Start routine to process OMCI GET Responses |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3957 | go dh.pAlarmMgr.StartOMCIAlarmMessageProcessing(ctx) |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 3958 | dh.setAlarmManagerIsRunning(true) |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 3959 | if stop := <-dh.stopAlarmManager; stop { |
| 3960 | logger.Debugw(ctx, "stopping-collector-for-onu", log.Fields{"device-id": dh.device.Id}) |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 3961 | dh.setAlarmManagerIsRunning(false) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 3962 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3963 | if dh.pAlarmMgr.AlarmSyncFsm != nil && dh.pAlarmMgr.AlarmSyncFsm.PFsm != nil { |
| 3964 | _ = dh.pAlarmMgr.AlarmSyncFsm.PFsm.Event(almgr.AsEvStop) |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 3965 | } |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 3966 | }() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3967 | dh.pAlarmMgr.StopProcessingOmciMessages <- true // Stop the OMCI routines if any(This will stop the fsms also) |
| 3968 | dh.pAlarmMgr.StopAlarmAuditTimer <- struct{}{} |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 3969 | 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] | 3970 | } |
| 3971 | } |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 3972 | |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3973 | func (dh *deviceHandler) setFlowMonitoringIsRunning(uniID uint8, flag bool) { |
| 3974 | dh.mutexFlowMonitoringRoutineFlag.Lock() |
| 3975 | defer dh.mutexFlowMonitoringRoutineFlag.Unlock() |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3976 | 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] | 3977 | dh.isFlowMonitoringRoutineActive[uniID] = flag |
| 3978 | } |
| 3979 | |
| 3980 | func (dh *deviceHandler) GetFlowMonitoringIsRunning(uniID uint8) bool { |
| 3981 | dh.mutexFlowMonitoringRoutineFlag.RLock() |
| 3982 | defer dh.mutexFlowMonitoringRoutineFlag.RUnlock() |
| 3983 | logger.Debugw(context.Background(), "get-flow-monitoring-routine", |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 3984 | log.Fields{"device-id": dh.device.Id, "isFlowMonitoringRoutineActive": dh.isFlowMonitoringRoutineActive}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3985 | return dh.isFlowMonitoringRoutineActive[uniID] |
| 3986 | } |
| 3987 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3988 | func (dh *deviceHandler) StartReconciling(ctx context.Context, skipOnuConfig bool) { |
| 3989 | logger.Debugw(ctx, "start reconciling", log.Fields{"skipOnuConfig": skipOnuConfig, "device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3990 | |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3991 | connectStatus := voltha.ConnectStatus_UNREACHABLE |
| 3992 | operState := voltha.OperStatus_UNKNOWN |
| 3993 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3994 | if !dh.IsReconciling() { |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3995 | go func() { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3996 | logger.Debugw(ctx, "wait for channel signal or timeout", |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 3997 | log.Fields{"timeout": dh.reconcileExpiryComplete, "device-id": dh.DeviceID}) |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3998 | select { |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 3999 | case success := <-dh.chReconcilingFinished: |
Holger Hildebrandt | f745925 | 2022-01-03 16:10:37 +0000 | [diff] [blame] | 4000 | logger.Debugw(ctx, "reconciling finished signal received", |
| 4001 | log.Fields{"device-id": dh.DeviceID, "dh.chReconcilingFinished": dh.chReconcilingFinished}) |
| 4002 | // To guarantee that the case-branch below is completely processed before reconciling processing is continued, |
| 4003 | // dh.mutexReconcilingFlag is locked already here. Thereby it is ensured, that further reconciling processing is stopped |
| 4004 | // at next call of dh.IsReconciling() until dh.reconciling is set after informing core about finished reconciling below. |
| 4005 | // This change addresses a problem described in VOL-4533 where the flag dh.reconciling not yet reset causes the uni ports |
| 4006 | // not to be created in ONOS in function dh.addUniPort(), when reconciling was started in reason "starting-openomci". |
| 4007 | // TODO: Keeping the mutex beyond an RPC towards core seems justifiable, as the effects here are easily overseeable. |
| 4008 | // However, a later refactoring of the functionality remains unaffected. |
| 4009 | dh.mutexReconcilingFlag.Lock() |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4010 | if success { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4011 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4012 | logger.Errorw(ctx, "No valid OnuDevice - aborting Core DeviceStateUpdate", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4013 | log.Fields{"device-id": dh.DeviceID}) |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4014 | } else { |
mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4015 | onuDevEntry.MutexPersOnuConfig.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4016 | if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4017 | connectStatus = voltha.ConnectStatus_REACHABLE |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4018 | if !onuDevEntry.SOnuPersistentData.PersUniDisableDone { |
| 4019 | if onuDevEntry.SOnuPersistentData.PersUniUnlockDone { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4020 | operState = voltha.OperStatus_ACTIVE |
| 4021 | } else { |
| 4022 | operState = voltha.OperStatus_ACTIVATING |
| 4023 | } |
| 4024 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4025 | } else if onuDevEntry.SOnuPersistentData.PersOperState == "down" || |
| 4026 | onuDevEntry.SOnuPersistentData.PersOperState == "unknown" || |
| 4027 | onuDevEntry.SOnuPersistentData.PersOperState == "" { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4028 | operState = voltha.OperStatus_DISCOVERED |
| 4029 | } |
mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4030 | onuDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4031 | logger.Debugw(ctx, "Core DeviceStateUpdate", |
| 4032 | log.Fields{"device-id": dh.device.Id, "connectStatus": connectStatus, "operState": operState}) |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4033 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4034 | logger.Debugw(ctx, "reconciling has been finished in time", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4035 | log.Fields{"device-id": dh.DeviceID}) |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4036 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4037 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4038 | ConnStatus: connectStatus, |
| 4039 | OperStatus: operState, |
| 4040 | }); err != nil { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4041 | logger.Errorw(ctx, "unable to update device state to core", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4042 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4043 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4044 | } else { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 4045 | logger.Errorw(ctx, "wait for reconciling aborted", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4046 | log.Fields{"device-id": dh.DeviceID}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4047 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4048 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4049 | logger.Errorw(ctx, "No valid OnuDevice", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4050 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4051 | } else { |
| 4052 | onuDevEntry.MutexPersOnuConfig.RLock() |
| 4053 | if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
| 4054 | connectStatus = voltha.ConnectStatus_REACHABLE |
| 4055 | } |
| 4056 | onuDevEntry.MutexPersOnuConfig.RUnlock() |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4057 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4058 | dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileCanceled, connectStatus) |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4059 | } |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4060 | case <-time.After(dh.reconcileExpiryComplete): |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4061 | logger.Errorw(ctx, "timeout waiting for reconciling to be finished!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4062 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | f745925 | 2022-01-03 16:10:37 +0000 | [diff] [blame] | 4063 | dh.mutexReconcilingFlag.Lock() |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4064 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4065 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4066 | logger.Errorw(ctx, "No valid OnuDevice", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4067 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 2c3f6c5 | 2021-11-23 11:22:10 +0000 | [diff] [blame] | 4068 | } else { |
| 4069 | onuDevEntry.MutexPersOnuConfig.RLock() |
| 4070 | if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
| 4071 | connectStatus = voltha.ConnectStatus_REACHABLE |
| 4072 | } |
| 4073 | onuDevEntry.MutexPersOnuConfig.RUnlock() |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4074 | } |
| 4075 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4076 | dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileMaxTimeout, connectStatus) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4077 | |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4078 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4079 | dh.reconciling = cNoReconciling |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4080 | dh.mutexReconcilingFlag.Unlock() |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4081 | dh.SetReconcilingReasonUpdate(false) |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 4082 | dh.SetReconcilingFirstPass(true) |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4083 | |
| 4084 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
| 4085 | logger.Errorw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 4086 | } else { |
| 4087 | onuDevEntry.MutexReconciledTpInstances.Lock() |
| 4088 | onuDevEntry.ReconciledTpInstances = make(map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage) |
| 4089 | onuDevEntry.MutexReconciledTpInstances.Unlock() |
| 4090 | } |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4091 | }() |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4092 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4093 | dh.mutexReconcilingFlag.Lock() |
| 4094 | if skipOnuConfig { |
| 4095 | dh.reconciling = cSkipOnuConfigReconciling |
| 4096 | } else { |
| 4097 | dh.reconciling = cOnuConfigReconciling |
| 4098 | } |
| 4099 | dh.mutexReconcilingFlag.Unlock() |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4100 | } |
| 4101 | |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4102 | func (dh *deviceHandler) stopReconciling(ctx context.Context, success bool, reconcileFlowResult uint16) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4103 | logger.Debugw(ctx, "stop reconciling", log.Fields{"device-id": dh.DeviceID, "success": success}) |
| 4104 | if dh.IsReconciling() { |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4105 | dh.sendChReconcileFinished(success) |
| 4106 | if reconcileFlowResult != cWaitReconcileFlowNoActivity { |
| 4107 | dh.SendChUniVlanConfigFinished(reconcileFlowResult) |
| 4108 | } |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4109 | } else { |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 4110 | 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] | 4111 | } |
| 4112 | } |
| 4113 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4114 | func (dh *deviceHandler) IsReconciling() bool { |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4115 | dh.mutexReconcilingFlag.RLock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4116 | defer dh.mutexReconcilingFlag.RUnlock() |
| 4117 | return dh.reconciling != cNoReconciling |
| 4118 | } |
| 4119 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4120 | func (dh *deviceHandler) IsSkipOnuConfigReconciling() bool { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4121 | dh.mutexReconcilingFlag.RLock() |
| 4122 | defer dh.mutexReconcilingFlag.RUnlock() |
| 4123 | return dh.reconciling == cSkipOnuConfigReconciling |
| 4124 | } |
| 4125 | |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 4126 | func (dh *deviceHandler) SetReconcilingFirstPass(value bool) { |
| 4127 | dh.mutexReconcilingFirstPassFlag.Lock() |
| 4128 | dh.reconcilingFirstPass = value |
| 4129 | dh.mutexReconcilingFirstPassFlag.Unlock() |
| 4130 | } |
| 4131 | |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4132 | func (dh *deviceHandler) SetReconcilingReasonUpdate(value bool) { |
| 4133 | dh.mutexReconcilingReasonUpdate.Lock() |
| 4134 | dh.reconcilingReasonUpdate = value |
| 4135 | dh.mutexReconcilingReasonUpdate.Unlock() |
| 4136 | } |
| 4137 | |
| 4138 | func (dh *deviceHandler) IsReconcilingReasonUpdate() bool { |
| 4139 | dh.mutexReconcilingReasonUpdate.RLock() |
| 4140 | defer dh.mutexReconcilingReasonUpdate.RUnlock() |
| 4141 | return dh.reconcilingReasonUpdate |
| 4142 | } |
| 4143 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4144 | func (dh *deviceHandler) getDeviceReason() uint8 { |
| 4145 | dh.mutexDeviceReason.RLock() |
| 4146 | value := dh.deviceReason |
| 4147 | dh.mutexDeviceReason.RUnlock() |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 4148 | return value |
| 4149 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4150 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4151 | func (dh *deviceHandler) GetDeviceReasonString() string { |
| 4152 | return cmn.DeviceReasonMap[dh.getDeviceReason()] |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 4153 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 4154 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4155 | func (dh *deviceHandler) SetReadyForOmciConfig(flagValue bool) { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 4156 | dh.mutexReadyForOmciConfig.Lock() |
| 4157 | dh.readyForOmciConfig = flagValue |
| 4158 | dh.mutexReadyForOmciConfig.Unlock() |
| 4159 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4160 | func (dh *deviceHandler) IsReadyForOmciConfig() bool { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 4161 | dh.mutexReadyForOmciConfig.RLock() |
| 4162 | flagValue := dh.readyForOmciConfig |
| 4163 | dh.mutexReadyForOmciConfig.RUnlock() |
| 4164 | return flagValue |
| 4165 | } |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4166 | |
| 4167 | func (dh *deviceHandler) deviceReconcileFailedUpdate(ctx context.Context, deviceReason uint8, connectStatus voltha.ConnectStatus_Types) { |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 4168 | if err := dh.ReasonUpdate(ctx, deviceReason, true); err != nil { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4169 | logger.Errorw(ctx, "unable to update device reason to core", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4170 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4171 | } |
| 4172 | |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4173 | logger.Debugw(ctx, "Core DeviceStateUpdate", |
| 4174 | 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] | 4175 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4176 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4177 | ConnStatus: connectStatus, |
| 4178 | OperStatus: voltha.OperStatus_RECONCILING_FAILED, |
| 4179 | }); err != nil { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4180 | logger.Errorw(ctx, "unable to update device state to core", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4181 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 4182 | } |
| 4183 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4184 | |
| 4185 | /* |
| 4186 | Helper functions to communicate with Core |
| 4187 | */ |
| 4188 | |
| 4189 | func (dh *deviceHandler) getDeviceFromCore(ctx context.Context, deviceID string) (*voltha.Device, error) { |
| 4190 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4191 | if err != nil || cClient == nil { |
| 4192 | return nil, err |
| 4193 | } |
| 4194 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4195 | defer cancel() |
| 4196 | logger.Debugw(subCtx, "get-device-from-core", log.Fields{"device-id": deviceID}) |
| 4197 | return cClient.GetDevice(subCtx, &vc.ID{Id: deviceID}) |
| 4198 | } |
| 4199 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4200 | func (dh *deviceHandler) updateDeviceStateInCore(ctx context.Context, deviceStateFilter *ca.DeviceStateFilter) error { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4201 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4202 | if err != nil || cClient == nil { |
| 4203 | return err |
| 4204 | } |
| 4205 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4206 | defer cancel() |
| 4207 | _, err = cClient.DeviceStateUpdate(subCtx, deviceStateFilter) |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4208 | logger.Debugw(subCtx, "device-updated-in-core", |
| 4209 | log.Fields{"device-id": dh.device.Id, "device-state": deviceStateFilter, "error": err}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4210 | return err |
| 4211 | } |
| 4212 | |
| 4213 | func (dh *deviceHandler) updatePMConfigInCore(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 4214 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4215 | if err != nil || cClient == nil { |
| 4216 | return err |
| 4217 | } |
| 4218 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4219 | defer cancel() |
| 4220 | _, err = cClient.DevicePMConfigUpdate(subCtx, pmConfigs) |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4221 | logger.Debugw(subCtx, "pmconfig-updated-in-core", |
| 4222 | log.Fields{"device-id": dh.device.Id, "pm-configs": pmConfigs, "error": err}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4223 | return err |
| 4224 | } |
| 4225 | |
| 4226 | func (dh *deviceHandler) updateDeviceInCore(ctx context.Context, device *voltha.Device) error { |
| 4227 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4228 | if err != nil || cClient == nil { |
| 4229 | return err |
| 4230 | } |
| 4231 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4232 | defer cancel() |
| 4233 | _, err = cClient.DeviceUpdate(subCtx, device) |
| 4234 | logger.Debugw(subCtx, "device-updated-in-core", log.Fields{"device-id": device.Id, "error": err}) |
| 4235 | return err |
| 4236 | } |
| 4237 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4238 | func (dh *deviceHandler) CreatePortInCore(ctx context.Context, port *voltha.Port) error { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4239 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4240 | if err != nil || cClient == nil { |
| 4241 | return err |
| 4242 | } |
| 4243 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4244 | defer cancel() |
| 4245 | _, err = cClient.PortCreated(subCtx, port) |
| 4246 | logger.Debugw(subCtx, "port-created-in-core", log.Fields{"port": port, "error": err}) |
| 4247 | return err |
| 4248 | } |
| 4249 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4250 | func (dh *deviceHandler) updatePortStateInCore(ctx context.Context, portState *ca.PortState) error { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4251 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4252 | if err != nil || cClient == nil { |
| 4253 | return err |
| 4254 | } |
| 4255 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4256 | defer cancel() |
| 4257 | _, err = cClient.PortStateUpdate(subCtx, portState) |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4258 | 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] | 4259 | return err |
| 4260 | } |
| 4261 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4262 | func (dh *deviceHandler) updateDeviceReasonInCore(ctx context.Context, reason *ca.DeviceReason) error { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4263 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4264 | if err != nil || cClient == nil { |
| 4265 | return err |
| 4266 | } |
| 4267 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4268 | defer cancel() |
| 4269 | _, err = cClient.DeviceReasonUpdate(subCtx, reason) |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4270 | 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] | 4271 | return err |
| 4272 | } |
| 4273 | |
| 4274 | /* |
| 4275 | Helper functions to communicate with parent adapter |
| 4276 | */ |
| 4277 | |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 4278 | func (dh *deviceHandler) GetTechProfileInstanceFromParentAdapter(ctx context.Context, aUniID uint8, |
| 4279 | aTpPath string) (*ia.TechProfileDownloadMessage, error) { |
| 4280 | |
| 4281 | var request = ia.TechProfileInstanceRequestMessage{ |
| 4282 | DeviceId: dh.DeviceID, |
| 4283 | TpInstancePath: aTpPath, |
| 4284 | ParentDeviceId: dh.parentID, |
| 4285 | ParentPonPort: dh.device.ParentPortNo, |
| 4286 | OnuId: dh.device.ProxyAddress.OnuId, |
| 4287 | UniId: uint32(aUniID), |
| 4288 | } |
| 4289 | |
| 4290 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(dh.device.ProxyAddress.AdapterEndpoint) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4291 | if err != nil || pgClient == nil { |
| 4292 | return nil, err |
| 4293 | } |
| 4294 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 4295 | defer cancel() |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4296 | logger.Debugw(subCtx, "get-tech-profile-instance", |
| 4297 | 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] | 4298 | return pgClient.GetTechProfileInstance(subCtx, &request) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4299 | } |
| 4300 | |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4301 | // This routine is unique per ONU ID and blocks on flowControlBlock channel for incoming flows |
| 4302 | // Each incoming flow is processed in a synchronous manner, i.e., the flow is processed to completion before picking another |
| 4303 | func (dh *deviceHandler) PerOnuFlowHandlerRoutine(uniID uint8) { |
| 4304 | logger.Infow(context.Background(), "starting-flow-handler-routine", log.Fields{"device-id": dh.DeviceID}) |
| 4305 | dh.setFlowMonitoringIsRunning(uniID, true) |
| 4306 | for { |
| 4307 | select { |
| 4308 | // block on the channel to receive an incoming flow |
| 4309 | // process the flow completely before proceeding to handle the next flow |
| 4310 | case flowCb := <-dh.flowCbChan[uniID]: |
| 4311 | startTime := time.Now() |
| 4312 | logger.Debugw(flowCb.ctx, "serial-flow-processor--start", log.Fields{"device-id": dh.DeviceID}) |
| 4313 | respChan := make(chan error) |
| 4314 | if flowCb.addFlow { |
| 4315 | go dh.addFlowItemToUniPort(flowCb.ctx, flowCb.flowItem, flowCb.uniPort, flowCb.flowMetaData, &respChan) |
| 4316 | } else { |
| 4317 | go dh.removeFlowItemFromUniPort(flowCb.ctx, flowCb.flowItem, flowCb.uniPort, &respChan) |
| 4318 | } |
| 4319 | // Block on response and tunnel it back to the caller |
| 4320 | *flowCb.respChan <- <-respChan |
| 4321 | logger.Debugw(flowCb.ctx, "serial-flow-processor--end", |
| 4322 | log.Fields{"device-id": dh.DeviceID, "absoluteTimeForFlowProcessingInSecs": time.Since(startTime).Seconds()}) |
| 4323 | case <-dh.stopFlowMonitoringRoutine[uniID]: |
| 4324 | logger.Infow(context.Background(), "stopping-flow-handler-routine", log.Fields{"device-id": dh.DeviceID}) |
| 4325 | dh.setFlowMonitoringIsRunning(uniID, false) |
| 4326 | return |
| 4327 | } |
| 4328 | } |
| 4329 | } |
| 4330 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 4331 | func (dh *deviceHandler) SendOMCIRequest(ctx context.Context, parentEndpoint string, request *ia.OmciMessage) error { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4332 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint) |
| 4333 | if err != nil || pgClient == nil { |
| 4334 | return err |
| 4335 | } |
| 4336 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 4337 | defer cancel() |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4338 | 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] | 4339 | _, err = pgClient.ProxyOmciRequest(subCtx, request) |
| 4340 | if err != nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 4341 | logger.Errorw(ctx, "omci-failure", |
| 4342 | log.Fields{"device-id": dh.device.Id, "request": request, "error": err, "request-parent": request.ParentDeviceId, |
| 4343 | "request-child": request.ChildDeviceId, "request-proxy": request.ProxyAddress}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4344 | } |
| 4345 | return err |
| 4346 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4347 | |
| 4348 | // GetDeviceID - TODO: add comment |
| 4349 | func (dh *deviceHandler) GetDeviceID() string { |
| 4350 | return dh.DeviceID |
| 4351 | } |
| 4352 | |
| 4353 | // GetProxyAddressID - TODO: add comment |
| 4354 | func (dh *deviceHandler) GetProxyAddressID() string { |
| 4355 | return dh.device.ProxyAddress.GetDeviceId() |
| 4356 | } |
| 4357 | |
| 4358 | // GetProxyAddressType - TODO: add comment |
| 4359 | func (dh *deviceHandler) GetProxyAddressType() string { |
| 4360 | return dh.device.ProxyAddress.GetDeviceType() |
| 4361 | } |
| 4362 | |
| 4363 | // GetProxyAddress - TODO: add comment |
| 4364 | func (dh *deviceHandler) GetProxyAddress() *voltha.Device_ProxyAddress { |
| 4365 | return dh.device.ProxyAddress |
| 4366 | } |
| 4367 | |
| 4368 | // GetEventProxy - TODO: add comment |
| 4369 | func (dh *deviceHandler) GetEventProxy() eventif.EventProxy { |
| 4370 | return dh.EventProxy |
| 4371 | } |
| 4372 | |
| 4373 | // GetOmciTimeout - TODO: add comment |
| 4374 | func (dh *deviceHandler) GetOmciTimeout() int { |
| 4375 | return dh.pOpenOnuAc.omciTimeout |
| 4376 | } |
| 4377 | |
| 4378 | // GetAlarmAuditInterval - TODO: add comment |
| 4379 | func (dh *deviceHandler) GetAlarmAuditInterval() time.Duration { |
| 4380 | return dh.pOpenOnuAc.alarmAuditInterval |
| 4381 | } |
| 4382 | |
| 4383 | // GetDlToOnuTimeout4M - TODO: add comment |
| 4384 | func (dh *deviceHandler) GetDlToOnuTimeout4M() time.Duration { |
| 4385 | return dh.pOpenOnuAc.dlToOnuTimeout4M |
| 4386 | } |
| 4387 | |
| 4388 | // GetUniEntityMap - TODO: add comment |
| 4389 | func (dh *deviceHandler) GetUniEntityMap() *cmn.OnuUniPortMap { |
| 4390 | return &dh.uniEntityMap |
| 4391 | } |
| 4392 | |
| 4393 | // GetPonPortNumber - TODO: add comment |
| 4394 | func (dh *deviceHandler) GetPonPortNumber() *uint32 { |
| 4395 | return &dh.ponPortNumber |
| 4396 | } |
| 4397 | |
| 4398 | // GetUniVlanConfigFsm - TODO: add comment |
| 4399 | func (dh *deviceHandler) GetUniVlanConfigFsm(uniID uint8) cmn.IuniVlanConfigFsm { |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 4400 | dh.lockVlanConfig.RLock() |
| 4401 | value := dh.UniVlanConfigFsmMap[uniID] |
| 4402 | dh.lockVlanConfig.RUnlock() |
| 4403 | return value |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4404 | } |
| 4405 | |
| 4406 | // GetOnuAlarmManager - TODO: add comment |
| 4407 | func (dh *deviceHandler) GetOnuAlarmManager() cmn.IonuAlarmManager { |
| 4408 | return dh.pAlarmMgr |
| 4409 | } |
| 4410 | |
| 4411 | // GetOnuMetricsManager - TODO: add comment |
| 4412 | func (dh *deviceHandler) GetOnuMetricsManager() cmn.IonuMetricsManager { |
| 4413 | return dh.pOnuMetricsMgr |
| 4414 | } |
| 4415 | |
| 4416 | // GetOnuTP - TODO: add comment |
| 4417 | func (dh *deviceHandler) GetOnuTP() cmn.IonuUniTechProf { |
| 4418 | return dh.pOnuTP |
| 4419 | } |
| 4420 | |
| 4421 | // GetBackendPathPrefix - TODO: add comment |
| 4422 | func (dh *deviceHandler) GetBackendPathPrefix() string { |
| 4423 | return dh.pOpenOnuAc.cm.Backend.PathPrefix |
| 4424 | } |
| 4425 | |
| 4426 | // GetOnuIndication - TODO: add comment |
| 4427 | func (dh *deviceHandler) GetOnuIndication() *openolt.OnuIndication { |
| 4428 | return dh.pOnuIndication |
| 4429 | } |
| 4430 | |
| 4431 | // RLockMutexDeletionInProgressFlag - TODO: add comment |
| 4432 | func (dh *deviceHandler) RLockMutexDeletionInProgressFlag() { |
| 4433 | dh.mutexDeletionInProgressFlag.RLock() |
| 4434 | } |
| 4435 | |
| 4436 | // RUnlockMutexDeletionInProgressFlag - TODO: add comment |
| 4437 | func (dh *deviceHandler) RUnlockMutexDeletionInProgressFlag() { |
| 4438 | dh.mutexDeletionInProgressFlag.RUnlock() |
| 4439 | } |
| 4440 | |
| 4441 | // GetDeletionInProgress - TODO: add comment |
| 4442 | func (dh *deviceHandler) GetDeletionInProgress() bool { |
| 4443 | return dh.deletionInProgress |
| 4444 | } |
| 4445 | |
| 4446 | // GetPmConfigs - TODO: add comment |
| 4447 | func (dh *deviceHandler) GetPmConfigs() *voltha.PmConfigs { |
| 4448 | return dh.pmConfigs |
| 4449 | } |
| 4450 | |
| 4451 | // GetDeviceType - TODO: add comment |
| 4452 | func (dh *deviceHandler) GetDeviceType() string { |
| 4453 | return dh.DeviceType |
| 4454 | } |
| 4455 | |
| 4456 | // GetLogicalDeviceID - TODO: add comment |
| 4457 | func (dh *deviceHandler) GetLogicalDeviceID() string { |
| 4458 | return dh.logicalDeviceID |
| 4459 | } |
| 4460 | |
| 4461 | // GetDevice - TODO: add comment |
| 4462 | func (dh *deviceHandler) GetDevice() *voltha.Device { |
| 4463 | return dh.device |
| 4464 | } |
| 4465 | |
| 4466 | // GetMetricsEnabled - TODO: add comment |
| 4467 | func (dh *deviceHandler) GetMetricsEnabled() bool { |
| 4468 | return dh.pOpenOnuAc.MetricsEnabled |
| 4469 | } |
| 4470 | |
| 4471 | // InitPmConfigs - TODO: add comment |
| 4472 | func (dh *deviceHandler) InitPmConfigs() { |
| 4473 | dh.pmConfigs = &voltha.PmConfigs{} |
| 4474 | } |
| 4475 | |
| 4476 | // GetUniPortMask - TODO: add comment |
| 4477 | func (dh *deviceHandler) GetUniPortMask() int { |
| 4478 | return dh.pOpenOnuAc.config.UniPortMask |
| 4479 | } |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 4480 | |
| 4481 | func (dh *deviceHandler) anyTpPathExists(aTpPathMap map[uint8]string) bool { |
| 4482 | tpPathFound := false |
| 4483 | for _, tpPath := range aTpPathMap { |
| 4484 | if tpPath != "" { |
| 4485 | tpPathFound = true |
| 4486 | } |
| 4487 | } |
| 4488 | return tpPathFound |
| 4489 | } |