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" |
kesavand | 011d516 | 2021-11-25 19:21:06 +0530 | [diff] [blame] | 47 | "github.com/opencord/voltha-protos/v5/go/common" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 48 | vc "github.com/opencord/voltha-protos/v5/go/common" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 49 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 50 | "github.com/opencord/voltha-protos/v5/go/extension" |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 51 | "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 52 | ia "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 53 | of "github.com/opencord/voltha-protos/v5/go/openflow_13" |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 54 | "github.com/opencord/voltha-protos/v5/go/openolt" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 55 | oop "github.com/opencord/voltha-protos/v5/go/openolt" |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 56 | "github.com/opencord/voltha-protos/v5/go/tech_profile" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 57 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame^] | 58 | "google.golang.org/grpc/codes" |
| 59 | "google.golang.org/grpc/status" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 60 | ) |
| 61 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 62 | const ( |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 63 | //constants for reconcile flow check channel |
| 64 | cWaitReconcileFlowAbortOnSuccess = 0xFFFD |
| 65 | cWaitReconcileFlowAbortOnError = 0xFFFE |
| 66 | cWaitReconcileFlowNoActivity = 0xFFFF |
| 67 | ) |
| 68 | |
| 69 | const ( |
| 70 | // constants for timeouts |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 71 | cTimeOutRemoveUpgrade = 1 //for usage in seconds |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 72 | ) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 73 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 74 | const ( |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 75 | // dummy constant - irregular value for ConnState - used to avoiding setting this state in the updateDeviceState() |
| 76 | // should better be defined in voltha protobuf or best solution would be to define an interface to just set the OperState |
| 77 | // as long as such is not available by the libraries - use this workaround |
| 78 | connectStatusINVALID = 255 // as long as not used as key in voltha.ConnectStatus_Types_name |
| 79 | ) |
| 80 | |
| 81 | const ( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 82 | // events of Device FSM |
| 83 | devEvDeviceInit = "devEvDeviceInit" |
| 84 | devEvGrpcConnected = "devEvGrpcConnected" |
| 85 | devEvGrpcDisconnected = "devEvGrpcDisconnected" |
| 86 | devEvDeviceUpInd = "devEvDeviceUpInd" |
| 87 | devEvDeviceDownInd = "devEvDeviceDownInd" |
| 88 | ) |
| 89 | const ( |
| 90 | // states of Device FSM |
| 91 | devStNull = "devStNull" |
| 92 | devStDown = "devStDown" |
| 93 | devStInit = "devStInit" |
| 94 | devStConnected = "devStConnected" |
| 95 | devStUp = "devStUp" |
| 96 | ) |
| 97 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 98 | //Event category and subcategory definitions - same as defiend for OLT in eventmgr.go - should be done more centrally |
| 99 | const ( |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 100 | pon = voltha.EventSubCategory_PON |
| 101 | //olt = voltha.EventSubCategory_OLT |
| 102 | //ont = voltha.EventSubCategory_ONT |
| 103 | //onu = voltha.EventSubCategory_ONU |
| 104 | //nni = voltha.EventSubCategory_NNI |
| 105 | //service = voltha.EventCategory_SERVICE |
| 106 | //security = voltha.EventCategory_SECURITY |
| 107 | equipment = voltha.EventCategory_EQUIPMENT |
| 108 | //processing = voltha.EventCategory_PROCESSING |
| 109 | //environment = voltha.EventCategory_ENVIRONMENT |
| 110 | //communication = voltha.EventCategory_COMMUNICATION |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 111 | ) |
| 112 | |
| 113 | const ( |
| 114 | cEventObjectType = "ONU" |
| 115 | ) |
| 116 | const ( |
| 117 | cOnuActivatedEvent = "ONU_ACTIVATED" |
| 118 | ) |
| 119 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 120 | type omciIdleCheckStruct struct { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 121 | omciIdleCheckFunc func(*deviceHandler, context.Context, cmn.UsedOmciConfigFsms, string) bool |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 122 | omciIdleState string |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 125 | var fsmOmciIdleStateFuncMap = map[cmn.UsedOmciConfigFsms]omciIdleCheckStruct{ |
| 126 | cmn.CUploadFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibUlFsmIdleState}, |
| 127 | cmn.CDownloadFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibDlFsmIdleState}, |
| 128 | cmn.CUniLockFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState}, |
| 129 | cmn.CUniUnLockFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState}, |
| 130 | cmn.CAniConfigFsm: {(*deviceHandler).isAniConfigFsmInOmciIdleState, avcfg.CAniFsmIdleState}, |
| 131 | cmn.CUniVlanConfigFsm: {(*deviceHandler).isUniVlanConfigFsmInOmciIdleState, avcfg.CVlanFsmIdleState}, |
| 132 | cmn.CL2PmFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, pmmgr.CL2PmFsmIdleState}, |
| 133 | cmn.COnuUpgradeFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, swupg.COnuUpgradeFsmIdleState}, |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 136 | const ( |
| 137 | cNoReconciling = iota |
| 138 | cOnuConfigReconciling |
| 139 | cSkipOnuConfigReconciling |
| 140 | ) |
| 141 | |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 142 | // FlowCb is the flow control block containing flow add/delete information along with a response channel |
| 143 | type FlowCb struct { |
| 144 | ctx context.Context // Flow handler context |
| 145 | addFlow bool // if true flow to be added, else removed |
| 146 | flowItem *of.OfpFlowStats |
| 147 | uniPort *cmn.OnuUniPort |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 148 | flowMetaData *of.FlowMetadata |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 149 | respChan *chan error // channel to report the Flow handling error |
| 150 | } |
| 151 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 152 | //deviceHandler will interact with the ONU ? device. |
| 153 | type deviceHandler struct { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 154 | DeviceID string |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 155 | DeviceType string |
| 156 | adminState string |
| 157 | device *voltha.Device |
| 158 | logicalDeviceID string |
| 159 | ProxyAddressID string |
| 160 | ProxyAddressType string |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 161 | parentID string |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 162 | ponPortNumber uint32 |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 163 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 164 | coreClient *vgrpc.Client |
| 165 | EventProxy eventif.EventProxy |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 166 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 167 | pmConfigs *voltha.PmConfigs |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 168 | config *config.AdapterFlags |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 169 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 170 | pOpenOnuAc *OpenONUAC |
| 171 | pDeviceStateFsm *fsm.FSM |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 172 | //pPonPort *voltha.Port |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 173 | deviceEntrySet chan bool //channel for DeviceEntry set event |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 174 | pOnuOmciDevice *mib.OnuDeviceEntry |
| 175 | pOnuTP *avcfg.OnuUniTechProf |
| 176 | pOnuMetricsMgr *pmmgr.OnuMetricsManager |
| 177 | pAlarmMgr *almgr.OnuAlarmManager |
| 178 | pSelfTestHdlr *otst.SelfTestControlBlock |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 179 | exitChannel chan int |
| 180 | lockDevice sync.RWMutex |
| 181 | pOnuIndication *oop.OnuIndication |
| 182 | deviceReason uint8 |
| 183 | mutexDeviceReason sync.RWMutex |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 184 | pLockStateFsm *uniprt.LockStateFsm |
| 185 | pUnlockStateFsm *uniprt.LockStateFsm |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 186 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 187 | //flowMgr *OpenOltFlowMgr |
| 188 | //eventMgr *OpenOltEventMgr |
| 189 | //resourceMgr *rsrcMgr.OpenOltResourceMgr |
| 190 | |
| 191 | //discOnus sync.Map |
| 192 | //onus sync.Map |
| 193 | //portStats *OpenOltStatisticsMgr |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 194 | collectorIsRunning bool |
| 195 | mutexCollectorFlag sync.RWMutex |
| 196 | stopCollector chan bool |
| 197 | alarmManagerIsRunning bool |
| 198 | mutextAlarmManagerFlag sync.RWMutex |
| 199 | stopAlarmManager chan bool |
| 200 | stopHeartbeatCheck chan bool |
| 201 | uniEntityMap cmn.OnuUniPortMap |
| 202 | mutexKvStoreContext sync.Mutex |
| 203 | lockVlanConfig sync.RWMutex |
| 204 | lockVlanAdd sync.RWMutex |
| 205 | UniVlanConfigFsmMap map[uint8]*avcfg.UniVlanConfigFsm |
| 206 | lockUpgradeFsm sync.RWMutex |
| 207 | pOnuUpradeFsm *swupg.OnuUpgradeFsm |
| 208 | upgradeCanceled bool |
| 209 | reconciling uint8 |
| 210 | mutexReconcilingFlag sync.RWMutex |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 211 | reconcilingFirstPass bool |
| 212 | mutexReconcilingFirstPassFlag sync.RWMutex |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 213 | reconcilingReasonUpdate bool |
| 214 | mutexReconcilingReasonUpdate sync.RWMutex |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 215 | chUniVlanConfigReconcilingDone chan uint16 //channel to indicate that VlanConfig reconciling for a specific UNI has been finished |
| 216 | chReconcilingFinished chan bool //channel to indicate that reconciling has been finished |
| 217 | reconcileExpiryComplete time.Duration |
| 218 | reconcileExpiryVlanConfig time.Duration |
| 219 | mutexReadyForOmciConfig sync.RWMutex |
| 220 | readyForOmciConfig bool |
| 221 | deletionInProgress bool |
| 222 | mutexDeletionInProgressFlag sync.RWMutex |
| 223 | pLastUpgradeImageState *voltha.ImageState |
| 224 | upgradeFsmChan chan struct{} |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 225 | |
| 226 | flowCbChan []chan FlowCb |
| 227 | mutexFlowMonitoringRoutineFlag sync.RWMutex |
ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 228 | mutexForDisableDeviceRequested sync.RWMutex |
Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame^] | 229 | mutexOltAvailable sync.RWMutex |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 230 | stopFlowMonitoringRoutine []chan bool // length of slice equal to number of uni ports |
| 231 | isFlowMonitoringRoutineActive []bool // length of slice equal to number of uni ports |
ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 232 | disableDeviceRequested bool // this flag identify ONU received disable request or not |
Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame^] | 233 | oltAvailable bool |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 236 | //newDeviceHandler creates a new device handler |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 237 | 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] | 238 | var dh deviceHandler |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 239 | dh.coreClient = cc |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 240 | dh.EventProxy = ep |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 241 | dh.config = adapter.config |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 242 | cloned := (proto.Clone(device)).(*voltha.Device) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 243 | dh.DeviceID = cloned.Id |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 244 | dh.DeviceType = cloned.Type |
| 245 | dh.adminState = "up" |
| 246 | dh.device = cloned |
| 247 | dh.pOpenOnuAc = adapter |
| 248 | dh.exitChannel = make(chan int, 1) |
| 249 | dh.lockDevice = sync.RWMutex{} |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 250 | dh.deviceEntrySet = make(chan bool, 1) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 251 | dh.collectorIsRunning = false |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 252 | dh.stopCollector = make(chan bool, 2) |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 253 | dh.alarmManagerIsRunning = false |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 254 | dh.stopAlarmManager = make(chan bool, 2) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 255 | dh.stopHeartbeatCheck = make(chan bool, 2) |
| 256 | //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] | 257 | //TODO initialize the support classes. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 258 | dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 259 | dh.lockVlanConfig = sync.RWMutex{} |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 260 | dh.lockVlanAdd = sync.RWMutex{} |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 261 | dh.lockUpgradeFsm = sync.RWMutex{} |
ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 262 | dh.mutexForDisableDeviceRequested = sync.RWMutex{} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 263 | dh.UniVlanConfigFsmMap = make(map[uint8]*avcfg.UniVlanConfigFsm) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 264 | dh.reconciling = cNoReconciling |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 265 | dh.reconcilingReasonUpdate = false |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 266 | dh.reconcilingFirstPass = true |
ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 267 | dh.disableDeviceRequested = false |
Holger Hildebrandt | 2b10764 | 2022-12-09 07:56:23 +0000 | [diff] [blame^] | 268 | dh.oltAvailable = false |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 269 | dh.chReconcilingFinished = make(chan bool) |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 270 | dh.reconcileExpiryComplete = adapter.maxTimeoutReconciling //assumption is to have it as duration in s! |
| 271 | rECSeconds := int(dh.reconcileExpiryComplete / time.Second) |
| 272 | if rECSeconds < 2 { |
| 273 | dh.reconcileExpiryComplete = time.Duration(2) * time.Second //ensure a minimum expiry time of 2s for complete reconciling |
| 274 | rECSeconds = 2 |
| 275 | } |
| 276 | rEVCSeconds := rECSeconds / 2 |
| 277 | 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] | 278 | dh.readyForOmciConfig = false |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 279 | dh.deletionInProgress = false |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 280 | dh.pLastUpgradeImageState = &voltha.ImageState{ |
| 281 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 282 | Reason: voltha.ImageState_UNKNOWN_ERROR, |
| 283 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 284 | } |
| 285 | dh.upgradeFsmChan = make(chan struct{}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 286 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 287 | if dh.device.PmConfigs != nil { // can happen after onu adapter restart |
| 288 | dh.pmConfigs = cloned.PmConfigs |
| 289 | } /* else { |
| 290 | // will be populated when onu_metrics_mananger is initialized. |
| 291 | }*/ |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 292 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 293 | // Device related state machine |
| 294 | dh.pDeviceStateFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 295 | devStNull, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 296 | fsm.Events{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 297 | {Name: devEvDeviceInit, Src: []string{devStNull, devStDown}, Dst: devStInit}, |
| 298 | {Name: devEvGrpcConnected, Src: []string{devStInit}, Dst: devStConnected}, |
| 299 | {Name: devEvGrpcDisconnected, Src: []string{devStConnected, devStDown}, Dst: devStInit}, |
| 300 | {Name: devEvDeviceUpInd, Src: []string{devStConnected, devStDown}, Dst: devStUp}, |
| 301 | {Name: devEvDeviceDownInd, Src: []string{devStUp}, Dst: devStDown}, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 302 | }, |
| 303 | fsm.Callbacks{ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 304 | "before_event": func(e *fsm.Event) { dh.logStateChange(ctx, e) }, |
| 305 | ("before_" + devEvDeviceInit): func(e *fsm.Event) { dh.doStateInit(ctx, e) }, |
| 306 | ("after_" + devEvDeviceInit): func(e *fsm.Event) { dh.postInit(ctx, e) }, |
| 307 | ("before_" + devEvGrpcConnected): func(e *fsm.Event) { dh.doStateConnected(ctx, e) }, |
| 308 | ("before_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.doStateInit(ctx, e) }, |
| 309 | ("after_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.postInit(ctx, e) }, |
| 310 | ("before_" + devEvDeviceUpInd): func(e *fsm.Event) { dh.doStateUp(ctx, e) }, |
| 311 | ("before_" + devEvDeviceDownInd): func(e *fsm.Event) { dh.doStateDown(ctx, e) }, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 312 | }, |
| 313 | ) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 314 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 315 | return &dh |
| 316 | } |
| 317 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 318 | // start save the device to the data model |
| 319 | func (dh *deviceHandler) start(ctx context.Context) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 320 | 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] | 321 | // Add the initial device to the local model |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 322 | logger.Debugw(ctx, "device-handler-started", log.Fields{"device": dh.device}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 323 | } |
| 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 | // stop stops the device dh. Not much to do for now |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 327 | func (dh *deviceHandler) stop(ctx context.Context) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 328 | logger.Debug("stopping-device-handler") |
| 329 | dh.exitChannel <- 1 |
| 330 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 331 | */ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 332 | |
| 333 | // ########################################################################################## |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 334 | // deviceHandler methods that implement the adapters interface requests ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 335 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 336 | //adoptOrReconcileDevice adopts the ONU device |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 337 | func (dh *deviceHandler) adoptOrReconcileDevice(ctx context.Context, device *voltha.Device) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 338 | 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] | 339 | |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 340 | 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] | 341 | if dh.pDeviceStateFsm.Is(devStNull) { |
| 342 | if err := dh.pDeviceStateFsm.Event(devEvDeviceInit); err != nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 343 | 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] | 344 | } |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 345 | 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] | 346 | // device.PmConfigs is not nil in cases when adapter restarts. We should not re-set the core again. |
| 347 | if device.PmConfigs == nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 348 | // Now, set the initial PM configuration for that device |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 349 | if err := dh.updatePMConfigInCore(ctx, dh.pmConfigs); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 350 | 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] | 351 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 352 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 353 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 354 | 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] | 355 | } |
| 356 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 357 | } |
| 358 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 359 | func (dh *deviceHandler) handleOMCIIndication(ctx context.Context, msg *ia.OmciMessage) error { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 360 | /* 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] | 361 | //assuming omci message content is hex coded! |
| 362 | // with restricted output of 16(?) bytes would be ...omciMsg.Message[:16] |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 363 | logger.Debugw(ctx, "inter-adapter-recv-omci", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 364 | "device-id": dh.DeviceID, "RxOmciMessage": hex.EncodeToString(omciMsg.Message)}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 365 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 366 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 367 | if pDevEntry != nil { |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 368 | if pDevEntry.PDevOmciCC != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 369 | return pDevEntry.PDevOmciCC.ReceiveMessage(log.WithSpanFromContext(context.TODO(), ctx), msg.Message) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 370 | } |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 371 | logger.Debugw(ctx, "omciCC not ready to receive omci messages - incoming omci message ignored", log.Fields{"device-id": dh.DeviceID, |
| 372 | "rxMsg": msg.Message}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 373 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 374 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 375 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 376 | } |
| 377 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 378 | func (dh *deviceHandler) handleTechProfileDownloadRequest(ctx context.Context, techProfMsg *ia.TechProfileDownloadMessage) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 379 | 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] | 380 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 381 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 382 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 383 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 384 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 385 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 386 | if dh.pOnuTP == nil { |
| 387 | //should normally not happen ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 388 | 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] | 389 | log.Fields{"device-id": dh.DeviceID}) |
| 390 | 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] | 391 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 392 | if !dh.IsReadyForOmciConfig() { |
| 393 | logger.Errorw(ctx, "TechProf-set rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 394 | "device-state": dh.GetDeviceReasonString()}) |
| 395 | 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] | 396 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 397 | //previous state test here was just this one, now extended for more states to reject the SetRequest: |
| 398 | // at least 'mib-downloaded' should be reached for processing of this specific ONU configuration |
| 399 | // if (dh.deviceReason == "stopping-openomci") || (dh.deviceReason == "omci-admin-lock") |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 400 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 401 | // 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] | 402 | // even to fast subsequent calls of the same messageType as well as OnuKVStore processing due |
| 403 | // to possible concurrent access by flow processing |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 404 | dh.pOnuTP.LockTpProcMutex() |
| 405 | defer dh.pOnuTP.UnlockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 406 | |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 407 | if techProfMsg.UniId >= platform.MaxUnisPerOnu { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 408 | 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] | 409 | techProfMsg.UniId, dh.DeviceID)) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 410 | } |
| 411 | uniID := uint8(techProfMsg.UniId) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 412 | tpID, err := cmn.GetTpIDFromTpPath(techProfMsg.TpInstancePath) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 413 | if err != nil { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 414 | logger.Errorw(ctx, "error-parsing-tpid-from-tppath", |
| 415 | log.Fields{"device-id": dh.DeviceID, "err": err, "tp-path": techProfMsg.TpInstancePath}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 416 | return err |
| 417 | } |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 418 | logger.Debugw(ctx, "unmarshal-techprof-msg-body", log.Fields{"device-id": dh.DeviceID, |
| 419 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 420 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 421 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, uint8(tpID), techProfMsg.TpInstancePath); bTpModify { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 422 | |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 423 | switch tpInst := techProfMsg.TechTpInstance.(type) { |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 424 | case *ia.TechProfileDownloadMessage_TpInstance: |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 425 | logger.Debugw(ctx, "onu-uni-tp-path-modified", log.Fields{"device-id": dh.DeviceID, |
| 426 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 427 | |
| 428 | err = dh.CheckAvailableOnuCapabilities(ctx, pDevEntry, *tpInst.TpInstance) |
| 429 | if err != nil { |
| 430 | logger.Errorw(ctx, "error-checking-available-onu-capabilities-stopping-device", |
| 431 | log.Fields{"device-id": dh.DeviceID, "err": err, "tp-path": techProfMsg.TpInstancePath}) |
| 432 | // stopping all further processing |
| 433 | _ = dh.UpdateInterface(ctx) |
| 434 | return err |
| 435 | } |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 436 | // if there has been some change for some uni TechProfilePath |
| 437 | //in order to allow concurrent calls to other dh instances we do not wait for execution here |
| 438 | //but doing so we can not indicate problems to the caller (who does what with that then?) |
| 439 | //by now we just assume straightforward successful execution |
| 440 | //TODO!!! Generally: In this scheme it would be good to have some means to indicate |
| 441 | // possible problems to the caller later autonomously |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 442 | |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 443 | // deadline context to ensure completion of background routines waited for |
| 444 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 445 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 446 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 447 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 448 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 449 | |
| 450 | var wg sync.WaitGroup |
| 451 | wg.Add(1) // for the 1 go routine to finish |
| 452 | // 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] | 453 | 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] | 454 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfDwld") //wait for background process to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 455 | if tpErr := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); tpErr != nil { |
| 456 | 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] | 457 | return tpErr |
| 458 | } |
| 459 | deadline = time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 460 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 461 | pDevEntry.ResetKvProcessingErrorIndication() |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 462 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 463 | go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 464 | dh.waitForCompletion(ctx, cancel2, &wg, "TechProfDwld") //wait for background process to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 465 | if kvErr := pDevEntry.GetKvProcessingErrorIndication(); kvErr != nil { |
| 466 | 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] | 467 | return kvErr |
| 468 | } |
| 469 | return nil |
| 470 | default: |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 471 | 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] | 472 | return fmt.Errorf("unsupported-tp-instance-type--tp-id-%v", techProfMsg.TpInstancePath) |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 473 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 474 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 475 | // no change, nothing really to do - return success |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 476 | logger.Debugw(ctx, "onu-uni-tp-path-not-modified", log.Fields{"device-id": dh.DeviceID, |
| 477 | "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 478 | return nil |
| 479 | } |
| 480 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 481 | func (dh *deviceHandler) handleDeleteGemPortRequest(ctx context.Context, delGemPortMsg *ia.DeleteGemPortMessage) error { |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 482 | 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] | 483 | |
| 484 | if dh.pOnuTP == nil { |
| 485 | //should normally not happen ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 486 | 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] | 487 | log.Fields{"device-id": dh.DeviceID}) |
| 488 | 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] | 489 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 490 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 491 | dh.pOnuTP.LockTpProcMutex() |
| 492 | defer dh.pOnuTP.UnlockTpProcMutex() |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 493 | |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 494 | if delGemPortMsg.UniId >= platform.MaxUnisPerOnu { |
| 495 | logger.Errorw(ctx, "delete-gem-port UniId exceeds range", log.Fields{ |
| 496 | "device-id": dh.DeviceID, "uni-id": delGemPortMsg.UniId}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 497 | 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] | 498 | delGemPortMsg.UniId, dh.DeviceID)) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 499 | } |
| 500 | uniID := uint8(delGemPortMsg.UniId) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 501 | tpID, err := cmn.GetTpIDFromTpPath(delGemPortMsg.TpInstancePath) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 502 | if err != nil { |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 503 | logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{ |
| 504 | "device-id": dh.DeviceID, "err": err, "tp-path": delGemPortMsg.TpInstancePath}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 505 | return err |
| 506 | } |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 507 | logger.Infow(ctx, "delete-gem-port-request", log.Fields{ |
| 508 | "device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "gem": delGemPortMsg.GemPortId}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 509 | //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] | 510 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 511 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delGemPortMsg.TpInstancePath, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 512 | avcfg.CResourceGemPort, delGemPortMsg.GemPortId) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 513 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 514 | } |
| 515 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 516 | func (dh *deviceHandler) handleDeleteTcontRequest(ctx context.Context, delTcontMsg *ia.DeleteTcontMessage) error { |
Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 517 | logger.Infow(ctx, "delete-tcont-request start", log.Fields{"device-id": dh.DeviceID, "uni-id": delTcontMsg.UniId, "tcont": delTcontMsg.AllocId}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 518 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 519 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 520 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 521 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 522 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 523 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 524 | if dh.pOnuTP == nil { |
| 525 | //should normally not happen ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 526 | 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] | 527 | log.Fields{"device-id": dh.DeviceID}) |
| 528 | 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] | 529 | } |
| 530 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 531 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 532 | dh.pOnuTP.LockTpProcMutex() |
| 533 | defer dh.pOnuTP.UnlockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 534 | |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 535 | if delTcontMsg.UniId >= platform.MaxUnisPerOnu { |
| 536 | logger.Errorw(ctx, "delete-tcont UniId exceeds range", log.Fields{ |
| 537 | "device-id": dh.DeviceID, "uni-id": delTcontMsg.UniId}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 538 | 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] | 539 | delTcontMsg.UniId, dh.DeviceID)) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 540 | } |
| 541 | uniID := uint8(delTcontMsg.UniId) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 542 | tpPath := delTcontMsg.TpInstancePath |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 543 | tpID, err := cmn.GetTpIDFromTpPath(tpPath) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 544 | if err != nil { |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 545 | logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{ |
| 546 | "device-id": dh.DeviceID, "err": err, "tp-path": tpPath}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 547 | return err |
| 548 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 549 | pDevEntry.FreeTcont(ctx, uint16(delTcontMsg.AllocId)) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 550 | |
Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 551 | var wg sync.WaitGroup |
| 552 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 553 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 554 | wg.Add(1) |
| 555 | logger.Debugw(ctx, "remove-tcont-in-kv", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "tcont": delTcontMsg.AllocId}) |
| 556 | go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg) |
| 557 | dh.waitForCompletion(ctx, cancel, &wg, "DeleteTcont") //wait for background process to finish |
| 558 | if err := pDevEntry.GetKvProcessingErrorIndication(); err != nil { |
| 559 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 560 | return err |
| 561 | } |
| 562 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 563 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delTcontMsg.TpInstancePath, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 564 | avcfg.CResourceTcont, delTcontMsg.AllocId) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 565 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 566 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 567 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 568 | func (dh *deviceHandler) deleteTechProfileResource(ctx context.Context, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 569 | uniID uint8, tpID uint8, pathString string, resource avcfg.ResourceEntry, entryID uint32) error { |
| 570 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 571 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 572 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 573 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 574 | } |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 575 | var resourceName string |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 576 | if avcfg.CResourceGemPort == resource { |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 577 | resourceName = "Gem" |
| 578 | } else { |
| 579 | resourceName = "Tcont" |
| 580 | } |
| 581 | |
| 582 | // deadline context to ensure completion of background routines waited for |
| 583 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 584 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 585 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 586 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 587 | |
| 588 | var wg sync.WaitGroup |
| 589 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 590 | go dh.pOnuTP.DeleteTpResource(log.WithSpanFromContext(dctx, ctx), uniID, tpID, pathString, |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 591 | resource, entryID, &wg) |
| 592 | 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] | 593 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); err != nil { |
| 594 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 595 | return err |
| 596 | } |
| 597 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 598 | if dh.pOnuTP.IsTechProfileConfigCleared(ctx, uniID, tpID) { |
| 599 | logger.Debugw(ctx, "techProfile-config-cleared", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID}) |
| 600 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, tpID, ""); bTpModify { |
| 601 | pDevEntry.ResetKvProcessingErrorIndication() |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 602 | var wg2 sync.WaitGroup |
| 603 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
| 604 | wg2.Add(1) |
| 605 | // Removal of the gem id mapping represents the removal of the tech profile |
Holger Hildebrandt | 6ec9cc1 | 2022-01-24 15:47:52 +0000 | [diff] [blame] | 606 | logger.Debugw(ctx, "remove-techProfile-indication-in-kv", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 607 | go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg2) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 608 | 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] | 609 | if err := pDevEntry.GetKvProcessingErrorIndication(); err != nil { |
| 610 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 611 | return err |
| 612 | } |
| 613 | } |
| 614 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 615 | 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] | 616 | "uni-id": uniID, "tpID": tpID, "resource-type": resourceName, "resource-id": entryID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 617 | return nil |
| 618 | } |
| 619 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 620 | //FlowUpdateIncremental removes and/or adds the flow changes on a given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 621 | func (dh *deviceHandler) FlowUpdateIncremental(ctx context.Context, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 622 | apOfFlowChanges *of.FlowChanges, |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 623 | apOfGroupChanges *of.FlowGroupChanges, apFlowMetaData *of.FlowMetadata) error { |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 624 | logger.Debugw(ctx, "FlowUpdateIncremental started", log.Fields{"device-id": dh.DeviceID, "flow": apOfFlowChanges, "metadata": apFlowMetaData}) |
| 625 | var errorsList []error |
| 626 | var retError error |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 627 | //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] | 628 | if apOfFlowChanges.ToRemove != nil { |
| 629 | for _, flowItem := range apOfFlowChanges.ToRemove.Items { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 630 | if flowItem.GetCookie() == 0 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 631 | 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] | 632 | "device-id": dh.DeviceID}) |
| 633 | retError = fmt.Errorf("flow-remove no cookie, device-id %s", dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 634 | errorsList = append(errorsList, retError) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 635 | continue |
| 636 | } |
| 637 | flowInPort := flow.GetInPort(flowItem) |
| 638 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 639 | logger.Warnw(ctx, "flow-remove inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 640 | retError = fmt.Errorf("flow-remove inPort invalid, device-id %s", dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 641 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 642 | continue |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 643 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 644 | } else if flowInPort == dh.ponPortNumber { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 645 | //this is some downstream flow, not regarded as error, just ignored |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 646 | 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] | 647 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 648 | continue |
| 649 | } else { |
| 650 | // this is the relevant upstream flow |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 651 | var loUniPort *cmn.OnuUniPort |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 652 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 653 | loUniPort = uniPort |
| 654 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 655 | 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] | 656 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 657 | 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] | 658 | flowInPort, dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 659 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 660 | continue |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 661 | } |
| 662 | flowOutPort := flow.GetOutPort(flowItem) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 663 | logger.Debugw(ctx, "flow-remove port indications", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 664 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 665 | "uniPortName": loUniPort.Name}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 666 | |
| 667 | if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) { |
| 668 | // Step1 : Fill flowControlBlock |
| 669 | // Step2 : Push the flowControlBlock to ONU channel |
| 670 | // Step3 : Wait on response channel for response |
| 671 | // Step4 : Return error value |
| 672 | startTime := time.Now() |
| 673 | respChan := make(chan error) |
| 674 | flowCb := FlowCb{ |
| 675 | ctx: ctx, |
| 676 | addFlow: false, |
| 677 | flowItem: flowItem, |
| 678 | flowMetaData: nil, |
| 679 | uniPort: loUniPort, |
| 680 | respChan: &respChan, |
| 681 | } |
| 682 | dh.flowCbChan[loUniPort.UniID] <- flowCb |
| 683 | logger.Infow(ctx, "process-flow-remove-start", log.Fields{"device-id": dh.DeviceID}) |
| 684 | // Wait on the channel for flow handlers return value |
| 685 | retError = <-respChan |
| 686 | logger.Infow(ctx, "process-flow-remove-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| 687 | if retError != nil { |
| 688 | logger.Warnw(ctx, "flow-delete processing error: continuing on checking further flows", |
| 689 | log.Fields{"device-id": dh.DeviceID, "error": retError}) |
| 690 | errorsList = append(errorsList, retError) |
| 691 | continue |
| 692 | } |
| 693 | } else { |
| 694 | retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID) |
| 695 | errorsList = append(errorsList, retError) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | } |
| 699 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 700 | if apOfFlowChanges.ToAdd != nil { |
| 701 | for _, flowItem := range apOfFlowChanges.ToAdd.Items { |
| 702 | if flowItem.GetCookie() == 0 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 703 | 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] | 704 | "device-id": dh.DeviceID}) |
| 705 | retError = fmt.Errorf("flow-add no cookie, device-id %s", dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 706 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 707 | continue |
| 708 | } |
| 709 | flowInPort := flow.GetInPort(flowItem) |
| 710 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 711 | logger.Warnw(ctx, "flow-add inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 712 | retError = fmt.Errorf("flow-add inPort invalid, device-id %s", dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 713 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 714 | continue |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 715 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 716 | } else if flowInPort == dh.ponPortNumber { |
| 717 | //this is some downstream flow |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 718 | 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] | 719 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 720 | continue |
| 721 | } else { |
| 722 | // this is the relevant upstream flow |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 723 | var loUniPort *cmn.OnuUniPort |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 724 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 725 | loUniPort = uniPort |
| 726 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 727 | 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] | 728 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 729 | 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] | 730 | flowInPort, dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 731 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 732 | continue |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 733 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 734 | // let's still assume that we receive the flow-add only in some 'active' device state (as so far observed) |
| 735 | // if not, we just throw some error here to have an indication about that, if we really need to support that |
| 736 | // then we would need to create some means to activate the internal stored flows |
| 737 | // after the device gets active automatically (and still with its dependency to the TechProfile) |
| 738 | // for state checking compare also code here: processInterAdapterTechProfileDownloadReqMessage |
| 739 | // also abort for the other still possible flows here |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 740 | if !dh.IsReadyForOmciConfig() { |
| 741 | logger.Errorw(ctx, "flow-add rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 742 | "last device-reason": dh.GetDeviceReasonString()}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 743 | retError = fmt.Errorf("improper device state on device %s", dh.DeviceID) |
| 744 | errorsList = append(errorsList, retError) |
| 745 | continue |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 746 | } |
| 747 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 748 | flowOutPort := flow.GetOutPort(flowItem) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 749 | logger.Debugw(ctx, "flow-add port indications", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 750 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 751 | "uniPortName": loUniPort.Name}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 752 | if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) { |
| 753 | // Step1 : Fill flowControlBlock |
| 754 | // Step2 : Push the flowControlBlock to ONU channel |
| 755 | // Step3 : Wait on response channel for response |
| 756 | // Step4 : Return error value |
| 757 | startTime := time.Now() |
| 758 | respChan := make(chan error) |
| 759 | flowCb := FlowCb{ |
| 760 | ctx: ctx, |
| 761 | addFlow: true, |
| 762 | flowItem: flowItem, |
| 763 | flowMetaData: apFlowMetaData, |
| 764 | uniPort: loUniPort, |
| 765 | respChan: &respChan, |
| 766 | } |
| 767 | dh.flowCbChan[loUniPort.UniID] <- flowCb |
| 768 | logger.Infow(ctx, "process-flow-add-start", log.Fields{"device-id": dh.DeviceID}) |
| 769 | // Wait on the channel for flow handlers return value |
| 770 | retError = <-respChan |
| 771 | logger.Infow(ctx, "process-flow-add-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| 772 | if retError != nil { |
| 773 | logger.Warnw(ctx, "flow-add processing error: continuing on checking further flows", |
| 774 | log.Fields{"device-id": dh.DeviceID, "error": retError}) |
| 775 | errorsList = append(errorsList, retError) |
| 776 | continue |
| 777 | } |
| 778 | } else { |
| 779 | retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID) |
| 780 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | } |
| 784 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 785 | if len(errorsList) > 0 { |
| 786 | logger.Errorw(ctx, "error-processing-flow", log.Fields{"device-id": dh.DeviceID, "errList": errorsList}) |
| 787 | return fmt.Errorf("errors-installing-one-or-more-flows-groups, errors:%v", errorsList) |
| 788 | } |
| 789 | return nil |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 790 | } |
| 791 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 792 | //disableDevice locks the ONU and its UNI/VEIP ports (admin lock via OMCI) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 793 | //following are the expected device states after this activity: |
| 794 | //Device Admin-State : down (on rwCore), Port-State: UNKNOWN, Conn-State: REACHABLE, Reason: omci-admin-lock |
| 795 | // (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] | 796 | func (dh *deviceHandler) disableDevice(ctx context.Context, device *voltha.Device) { |
| 797 | 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] | 798 | dh.mutexForDisableDeviceRequested.Lock() |
| 799 | dh.disableDeviceRequested = true |
| 800 | dh.mutexForDisableDeviceRequested.Unlock() |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 801 | //admin-lock reason can also be used uniquely for setting the DeviceState accordingly |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 802 | //note that disableDevice sequences in some 'ONU active' state may yield also |
| 803 | // "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] | 804 | // - inblock state checking to prevent possibly unneeded processing (on command repitition) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 805 | if dh.getDeviceReason() != cmn.DrOmciAdminLock { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 806 | //disable-device shall be just a UNi/ONU-G related admin state setting |
| 807 | //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] | 808 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 809 | if dh.IsReadyForOmciConfig() { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 810 | // disable UNI ports/ONU |
| 811 | // *** should generate UniDisableStateDone event - used to disable the port(s) on success |
| 812 | if dh.pLockStateFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 813 | dh.createUniLockFsm(ctx, true, cmn.UniDisableStateDone) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 814 | } else { //LockStateFSM already init |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 815 | dh.pLockStateFsm.SetSuccessEvent(cmn.UniDisableStateDone) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 816 | dh.runUniLockFsm(ctx, true) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 817 | } |
| 818 | } else { |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 819 | logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 820 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID}) |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 821 | // disable device should have no impact on ConnStatus |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 822 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 823 | DeviceId: dh.DeviceID, |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 824 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 825 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 826 | }); err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 827 | //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] | 828 | 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] | 829 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 830 | // 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] | 831 | |
| 832 | //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] | 833 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciAdminLock, true) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 834 | } |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 838 | //reEnableDevice unlocks the ONU and its UNI/VEIP ports (admin unlock via OMCI) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 839 | func (dh *deviceHandler) reEnableDevice(ctx context.Context, device *voltha.Device) { |
| 840 | 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] | 841 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 842 | //setting readyForOmciConfig here is just a workaround for BBSIM testing in the sequence |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 843 | // OnuSoftReboot-disable-enable, because BBSIM does not generate a new OnuIndication-Up event after SoftReboot |
| 844 | // which is the assumption for real ONU's, where the ready-state is then set according to the following MibUpload/Download |
| 845 | // for real ONU's that should have nearly no influence |
| 846 | // Note that for real ONU's there is anyway a problematic situation with following sequence: |
| 847 | // OnuIndication-Dw (or not active at all) (- disable) - enable: here already the LockFsm may run into timeout (no OmciResponse) |
| 848 | // but that anyway is hopefully resolved by some OnuIndication-Up event (maybe to be tested) |
| 849 | // 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] | 850 | dh.SetReadyForOmciConfig(true) //needed to allow subsequent flow/techProf config (on BBSIM) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 851 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 852 | // enable ONU/UNI ports |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 853 | // *** should generate cmn.UniEnableStateDone event - used to disable the port(s) on success |
ozgecanetsia | 5cbcfbe | 2022-01-14 10:32:34 +0300 | [diff] [blame] | 854 | dh.mutexForDisableDeviceRequested.Lock() |
| 855 | dh.disableDeviceRequested = false |
| 856 | dh.mutexForDisableDeviceRequested.Unlock() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 857 | if dh.pUnlockStateFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 858 | dh.createUniLockFsm(ctx, false, cmn.UniEnableStateDone) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 859 | } else { //UnlockStateFSM already init |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 860 | dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniEnableStateDone) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 861 | dh.runUniLockFsm(ctx, false) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 862 | } |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 863 | } |
| 864 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 865 | func (dh *deviceHandler) reconcileDeviceOnuInd(ctx context.Context) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 866 | 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] | 867 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 868 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 869 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 870 | 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] | 871 | return |
| 872 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 873 | if err := pDevEntry.RestoreDataFromOnuKvStore(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 874 | if err == fmt.Errorf("no-ONU-data-found") { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 875 | 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] | 876 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 877 | 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] | 878 | } |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 879 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 880 | return |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 881 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 882 | var onuIndication oop.OnuIndication |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 883 | pDevEntry.MutexPersOnuConfig.RLock() |
| 884 | onuIndication.IntfId = pDevEntry.SOnuPersistentData.PersIntfID |
| 885 | onuIndication.OnuId = pDevEntry.SOnuPersistentData.PersOnuID |
| 886 | onuIndication.OperState = pDevEntry.SOnuPersistentData.PersOperState |
| 887 | onuIndication.AdminState = pDevEntry.SOnuPersistentData.PersAdminState |
| 888 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 889 | _ = dh.createInterface(ctx, &onuIndication) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 890 | } |
| 891 | |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 892 | func (dh *deviceHandler) ReconcileDeviceTechProf(ctx context.Context) bool { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 893 | 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] | 894 | |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 895 | continueWithFlowConfig := false |
| 896 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 897 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 898 | if pDevEntry == nil { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 899 | 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] | 900 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
| 901 | return continueWithFlowConfig |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 902 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 903 | dh.pOnuTP.LockTpProcMutex() |
| 904 | defer dh.pOnuTP.UnlockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 905 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 906 | pDevEntry.MutexPersOnuConfig.RLock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 907 | persMutexLock := true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 908 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 909 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 910 | 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] | 911 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 912 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
| 913 | return continueWithFlowConfig |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 914 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 915 | flowsFound := false |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 916 | techProfsFound := false |
| 917 | techProfInstLoadFailed := false |
| 918 | outerLoop: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 919 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 920 | uniID := uniData.PersUniID |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 921 | //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] | 922 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 923 | logger.Debugw(ctx, "reconciling - no TPs stored for uniID", |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 924 | log.Fields{"uni-id": uniID, "device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 925 | continue |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 926 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 927 | //release MutexPersOnuConfig before TechProfile (ANIConfig) processing as otherwise the reception of |
| 928 | // 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] | 929 | // 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] | 930 | pDevEntry.MutexPersOnuConfig.RUnlock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 931 | persMutexLock = false |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 932 | 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] | 933 | var iaTechTpInst ia.TechProfileDownloadMessage |
| 934 | var ok bool |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 935 | for tpID := range uniData.PersTpPathMap { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 936 | pDevEntry.MutexReconciledTpInstances.RLock() |
| 937 | if iaTechTpInst, ok = pDevEntry.ReconciledTpInstances[uniID][tpID]; !ok { |
| 938 | logger.Errorw(ctx, "reconciling - no reconciled tp instance available", |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 939 | 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] | 940 | "device-id": dh.DeviceID}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 941 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 942 | pDevEntry.MutexReconciledTpInstances.RUnlock() |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 943 | break outerLoop |
| 944 | } |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 945 | pDevEntry.MutexReconciledTpInstances.RUnlock() |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 946 | continueWithFlowConfig = true // valid TP found - try flow configuration later |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 947 | var tpInst tech_profile.TechProfileInstance |
| 948 | switch techTpInst := iaTechTpInst.TechTpInstance.(type) { |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 949 | case *ia.TechProfileDownloadMessage_TpInstance: // supports only GPON, XGPON, XGS-PON |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 950 | tpInst = *techTpInst.TpInstance |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 951 | logger.Debugw(ctx, "reconciling - received-tp-instance-successfully-after-reconcile", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 952 | "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] | 953 | default: // do not support epon or other tech |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 954 | logger.Errorw(ctx, "reconciling - unsupported-tech-profile", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 955 | "tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 956 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 957 | break outerLoop |
| 958 | } |
| 959 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 960 | // deadline context to ensure completion of background routines waited for |
| 961 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 962 | 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] | 963 | dctx, cancel := context.WithDeadline(ctx, deadline) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 964 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 965 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniData.PersUniID, tpID) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 966 | var wg sync.WaitGroup |
| 967 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 968 | 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] | 969 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfReconcile") //wait for background process to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 970 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniData.PersUniID, tpID); err != nil { |
| 971 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 972 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 973 | break outerLoop |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 974 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 975 | } // for all TpPath entries for this UNI |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 976 | if len(uniData.PersFlowParams) != 0 { |
| 977 | flowsFound = true |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 978 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 979 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 980 | persMutexLock = true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 981 | } // for all UNI entries from SOnuPersistentData |
| 982 | if persMutexLock { // if loop was left with MutexPersOnuConfig still set |
| 983 | pDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 984 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 985 | |
| 986 | //had to move techProf/flow result evaluation into separate function due to SCA complexity limit |
| 987 | dh.updateReconcileStates(ctx, techProfsFound, techProfInstLoadFailed, flowsFound) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 988 | |
| 989 | return continueWithFlowConfig |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | func (dh *deviceHandler) updateReconcileStates(ctx context.Context, |
| 993 | abTechProfsFound bool, abTechProfInstLoadFailed bool, abFlowsFound bool) { |
| 994 | if !abTechProfsFound { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 995 | 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] | 996 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 997 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 998 | return |
| 999 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1000 | if abTechProfInstLoadFailed { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1001 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadFailed, dh.IsReconcilingReasonUpdate()) |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1002 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 1003 | return |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1004 | } else if dh.IsSkipOnuConfigReconciling() { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1005 | _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, dh.IsReconcilingReasonUpdate()) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1006 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1007 | if !abFlowsFound { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1008 | 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] | 1009 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1010 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1011 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1014 | func (dh *deviceHandler) ReconcileDeviceFlowConfig(ctx context.Context) { |
| 1015 | 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] | 1016 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1017 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1018 | if pDevEntry == nil { |
Holger Hildebrandt | 9afc158 | 2021-11-30 16:10:19 +0000 | [diff] [blame] | 1019 | 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] | 1020 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1021 | return |
| 1022 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1023 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1024 | pDevEntry.MutexPersOnuConfig.RLock() |
| 1025 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 1026 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1027 | 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] | 1028 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1029 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1030 | return |
| 1031 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1032 | flowsFound := false |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1033 | var uniVlanConfigEntries []uint8 |
| 1034 | var loWaitGroupWTO cmn.WaitGroupWithTimeOut |
| 1035 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1036 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1037 | //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support |
| 1038 | if len(uniData.PersFlowParams) == 0 { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1039 | logger.Debugw(ctx, "reconciling - no flows stored for uniID", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1040 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1041 | continue |
| 1042 | } |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1043 | if !dh.anyTpPathExists(uniData.PersTpPathMap) { |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1044 | logger.Warnw(ctx, "reconciling flows - but no TPs stored for uniID, abort", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1045 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 1046 | // It doesn't make sense to configure any flows if no TPs are available |
| 1047 | continue |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1048 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1049 | //release MutexPersOnuConfig before VlanConfig processing as otherwise the reception of |
| 1050 | // 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] | 1051 | // 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] | 1052 | pDevEntry.MutexPersOnuConfig.RUnlock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1053 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1054 | var uniPort *cmn.OnuUniPort |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1055 | var exist bool |
Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 1056 | 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] | 1057 | if uniPort, exist = dh.uniEntityMap[uniNo]; !exist { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1058 | logger.Errorw(ctx, "reconciling - OnuUniPort data not found - terminate reconcilement", |
| 1059 | log.Fields{"uniNo": uniNo, "device-id": dh.DeviceID}) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1060 | dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1061 | return |
| 1062 | } |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1063 | //needed to split up function due to sca complexity |
| 1064 | dh.updateReconcileFlowConfig(ctx, uniPort, uniData.PersFlowParams, uniVlanConfigEntries, &loWaitGroupWTO, &flowsFound) |
| 1065 | |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1066 | logger.Debugw(ctx, "reconciling - flows processed", log.Fields{ |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1067 | "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1068 | "NumUniFlows": dh.UniVlanConfigFsmMap[uniData.PersUniID].NumUniFlows, |
| 1069 | "ConfiguredUniFlow": dh.UniVlanConfigFsmMap[uniData.PersUniID].ConfiguredUniFlow}) |
Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 1070 | // this can't be used as global finished reconciling flag because |
| 1071 | // assumes is getting called before the state machines for the last flow is completed, |
| 1072 | // while this is not guaranteed. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1073 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| 1074 | } // for all UNI entries from SOnuPersistentData |
| 1075 | pDevEntry.MutexPersOnuConfig.RUnlock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1076 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1077 | if !flowsFound { |
| 1078 | 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] | 1079 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | b314f44 | 2021-11-24 12:03:10 +0000 | [diff] [blame] | 1080 | dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1081 | return |
| 1082 | } |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1083 | logger.Debugw(ctx, "reconciling flows - waiting on ready indication of requested UNIs", log.Fields{ |
| 1084 | "device-id": dh.DeviceID, "expiry": dh.reconcileExpiryVlanConfig}) |
| 1085 | if executed := loWaitGroupWTO.WaitTimeout(dh.reconcileExpiryVlanConfig); executed { |
| 1086 | logger.Debugw(ctx, "reconciling flows for all UNI's has been finished in time", |
| 1087 | log.Fields{"device-id": dh.DeviceID}) |
| 1088 | dh.stopReconciling(ctx, true, cWaitReconcileFlowAbortOnSuccess) |
| 1089 | if pDevEntry != nil { |
| 1090 | pDevEntry.SendChReconcilingFlowsFinished(ctx, true) |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1091 | } |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1092 | } else { |
| 1093 | logger.Errorw(ctx, "reconciling - timeout waiting for reconciling flows for all UNI's to be finished!", |
| 1094 | log.Fields{"device-id": dh.DeviceID}) |
| 1095 | dh.stopReconciling(ctx, false, cWaitReconcileFlowAbortOnError) |
| 1096 | if pDevEntry != nil { |
| 1097 | pDevEntry.SendChReconcilingFlowsFinished(ctx, false) |
| 1098 | } |
| 1099 | return |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1100 | } |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1101 | _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsPushed, dh.IsReconcilingReasonUpdate()) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1104 | func (dh *deviceHandler) updateReconcileFlowConfig(ctx context.Context, apUniPort *cmn.OnuUniPort, |
| 1105 | aPersFlowParam []cmn.UniVlanFlowParams, aUniVlanConfigEntries []uint8, |
| 1106 | apWaitGroup *cmn.WaitGroupWithTimeOut, apFlowsFound *bool) { |
| 1107 | flowsProcessed := 0 |
| 1108 | lastFlowToReconcile := false |
| 1109 | loUniID := apUniPort.UniID |
| 1110 | for _, flowData := range aPersFlowParam { |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1111 | if !(*apFlowsFound) { |
| 1112 | *apFlowsFound = true |
| 1113 | syncChannel := make(chan struct{}) |
| 1114 | // start go routine with select() on reconciling vlan config channel before |
| 1115 | // starting vlan config reconciling process to prevent loss of any signal |
| 1116 | // this routine just collects all the received 'flow-reconciled' signals - possibly from different UNI's |
| 1117 | go dh.waitOnUniVlanConfigReconcilingReady(ctx, syncChannel, apWaitGroup) |
| 1118 | //block until the wait routine is really blocked on channel input |
| 1119 | // in order to prevent to early ready signal from VlanConfig processing |
| 1120 | <-syncChannel |
| 1121 | } |
| 1122 | if flowsProcessed == len(aPersFlowParam)-1 { |
| 1123 | var uniAdded bool |
| 1124 | lastFlowToReconcile = true |
| 1125 | if aUniVlanConfigEntries, uniAdded = dh.appendIfMissing(aUniVlanConfigEntries, loUniID); uniAdded { |
| 1126 | apWaitGroup.Add(1) //increment the waiting group |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1127 | } |
| 1128 | } |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1129 | logger.Debugw(ctx, "reconciling - add flow with cookie slice", log.Fields{ |
| 1130 | "device-id": dh.DeviceID, "uni-id": loUniID, |
| 1131 | "flowsProcessed": flowsProcessed, "cookies": flowData.CookieSlice}) |
| 1132 | dh.lockVlanConfig.Lock() |
| 1133 | //the CookieSlice can be passed 'by value' here, - which internally passes its reference |
| 1134 | if _, exist := dh.UniVlanConfigFsmMap[loUniID]; exist { |
| 1135 | if err := dh.UniVlanConfigFsmMap[loUniID].SetUniFlowParams(ctx, flowData.VlanRuleParams.TpID, |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 1136 | flowData.CookieSlice, uint16(flowData.VlanRuleParams.MatchVid), uint8(flowData.VlanRuleParams.MatchPcp), uint16(flowData.VlanRuleParams.SetVid), uint8(flowData.VlanRuleParams.SetPcp), flowData.VlanRuleParams.InnerCvlan, lastFlowToReconcile, flowData.Meter, nil); err != nil { |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1137 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1138 | } |
| 1139 | } else { |
| 1140 | if err := dh.createVlanFilterFsm(ctx, apUniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice, |
Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 1141 | uint16(flowData.VlanRuleParams.MatchVid), uint8(flowData.VlanRuleParams.MatchPcp), uint16(flowData.VlanRuleParams.SetVid), |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 1142 | uint8(flowData.VlanRuleParams.SetPcp), flowData.VlanRuleParams.InnerCvlan, cmn.OmciVlanFilterAddDone, lastFlowToReconcile, flowData.Meter, nil); err != nil { |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1143 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
| 1144 | } |
| 1145 | } |
| 1146 | dh.lockVlanConfig.Unlock() |
| 1147 | flowsProcessed++ |
| 1148 | } //for all flows of this UNI |
| 1149 | } |
| 1150 | |
| 1151 | //waitOnUniVlanConfigReconcilingReady collects all VlanConfigReady signals from VlanConfig FSM processing in reconciling |
| 1152 | // and decrements the according handler wait group waiting for these indications |
| 1153 | func (dh *deviceHandler) waitOnUniVlanConfigReconcilingReady(ctx context.Context, aSyncChannel chan<- struct{}, |
| 1154 | waitGroup *cmn.WaitGroupWithTimeOut) { |
| 1155 | var reconciledUniVlanConfigEntries []uint8 |
| 1156 | var appended bool |
| 1157 | expiry := dh.GetReconcileExpiryVlanConfigAbort() |
| 1158 | logger.Debugw(ctx, "start waiting on reconcile vlanConfig ready indications", log.Fields{ |
| 1159 | "device-id": dh.DeviceID, "expiry": expiry}) |
| 1160 | // indicate blocking on channel now to the caller |
| 1161 | aSyncChannel <- struct{}{} |
| 1162 | for { |
| 1163 | select { |
| 1164 | case uniIndication := <-dh.chUniVlanConfigReconcilingDone: |
| 1165 | switch uniIndication { |
| 1166 | // no activity requested (should normally not be received) - just continue waiting |
| 1167 | case cWaitReconcileFlowNoActivity: |
| 1168 | // waiting on channel inputs from VlanConfig for all UNI's to be aborted on error condition |
| 1169 | case cWaitReconcileFlowAbortOnError: |
| 1170 | logger.Debugw(ctx, "waitReconcileFlow aborted on error", |
| 1171 | log.Fields{"device-id": dh.DeviceID, "rxEntries": reconciledUniVlanConfigEntries}) |
| 1172 | return |
| 1173 | // waiting on channel inputs from VlanConfig for all UNI's to be aborted on success condition |
| 1174 | case cWaitReconcileFlowAbortOnSuccess: |
| 1175 | logger.Debugw(ctx, "waitReconcileFlow aborted on success", |
| 1176 | log.Fields{"device-id": dh.DeviceID, "rxEntries": reconciledUniVlanConfigEntries}) |
| 1177 | return |
| 1178 | // this should be a valid UNI vlan config done indication |
| 1179 | default: |
| 1180 | if uniIndication < platform.MaxUnisPerOnu { |
| 1181 | logger.Debugw(ctx, "reconciling flows has been finished in time for this UNI", |
| 1182 | log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| 1183 | if reconciledUniVlanConfigEntries, appended = |
| 1184 | dh.appendIfMissing(reconciledUniVlanConfigEntries, uint8(uniIndication)); appended { |
| 1185 | waitGroup.Done() |
| 1186 | } |
| 1187 | } else { |
| 1188 | logger.Errorw(ctx, "received unexpected UNI flowConfig done indication - is ignored", |
| 1189 | log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication}) |
| 1190 | } |
| 1191 | } //switch uniIndication |
| 1192 | |
| 1193 | case <-time.After(expiry): //a bit longer than reconcileExpiryVlanConfig |
| 1194 | logger.Errorw(ctx, "timeout waiting for reconciling all UNI flows to be finished!", |
| 1195 | log.Fields{"device-id": dh.DeviceID}) |
| 1196 | return |
| 1197 | } |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | func (dh *deviceHandler) GetReconcileExpiryVlanConfigAbort() time.Duration { |
| 1202 | return dh.reconcileExpiryVlanConfig + (500 * time.Millisecond) |
| 1203 | } |
| 1204 | |
| 1205 | func (dh *deviceHandler) appendIfMissing(slice []uint8, val uint8) ([]uint8, bool) { |
| 1206 | for _, ele := range slice { |
| 1207 | if ele == val { |
| 1208 | return slice, false |
| 1209 | } |
| 1210 | } |
| 1211 | return append(slice, val), true |
| 1212 | } |
| 1213 | |
| 1214 | // sendChReconcileFinished - sends true or false on reconcileFinish channel |
| 1215 | func (dh *deviceHandler) sendChReconcileFinished(success bool) { |
| 1216 | if dh != nil { //if the object still exists (might have been already deleted in background) |
| 1217 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1218 | select { |
| 1219 | case dh.chReconcilingFinished <- success: |
| 1220 | default: |
| 1221 | } |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | // SendChUniVlanConfigFinished - sends the Uni number on channel if the flow reconcilement for this UNI is finished |
| 1226 | func (dh *deviceHandler) SendChUniVlanConfigFinished(value uint16) { |
| 1227 | if dh != nil { //if the object still exists (might have been already deleted in background) |
| 1228 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1229 | select { |
| 1230 | case dh.chUniVlanConfigReconcilingDone <- value: |
| 1231 | default: |
| 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1236 | func (dh *deviceHandler) deleteDevicePersistencyData(ctx context.Context) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1237 | 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] | 1238 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1239 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1240 | if pDevEntry == nil { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1241 | //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] | 1242 | 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] | 1243 | return nil |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1244 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1245 | |
| 1246 | // deadline context to ensure completion of background routines waited for |
| 1247 | //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] | 1248 | 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] | 1249 | dctx, cancel := context.WithDeadline(ctx, deadline) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1250 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1251 | pDevEntry.ResetKvProcessingErrorIndication() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1252 | |
| 1253 | var wg sync.WaitGroup |
| 1254 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1255 | go pDevEntry.DeleteDataFromOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1256 | dh.waitForCompletion(ctx, cancel, &wg, "DeleteDevice") //wait for background process to finish |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1257 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1258 | // TODO: further actions - stop metrics and FSMs, remove device ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1259 | return pDevEntry.GetKvProcessingErrorIndication() |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1262 | //func (dh *deviceHandler) rebootDevice(ctx context.Context, device *voltha.Device) error { |
| 1263 | // before this change here return like this was used: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1264 | // return fmt.Errorf("device-unreachable: %s, %s", dh.DeviceID, device.SerialNumber) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1265 | //was and is called in background - error return does not make sense |
| 1266 | func (dh *deviceHandler) rebootDevice(ctx context.Context, aCheckDeviceState bool, device *voltha.Device) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1267 | 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] | 1268 | if aCheckDeviceState && device.ConnectStatus != voltha.ConnectStatus_REACHABLE { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1269 | 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] | 1270 | return |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1271 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1272 | if err := dh.pOnuOmciDevice.Reboot(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1273 | //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] | 1274 | 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] | 1275 | return |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1276 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1277 | |
| 1278 | //transfer the possibly modified logical uni port state |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1279 | dh.DisableUniPortStateUpdate(ctx) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1280 | |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 1281 | logger.Debugw(ctx, "call DeviceStateUpdate upon reboot", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1282 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID}) |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 1283 | // 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] | 1284 | if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1285 | DeviceId: dh.DeviceID, |
mpagenko | 44bd836 | 2021-11-15 11:40:05 +0000 | [diff] [blame] | 1286 | ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1287 | OperStatus: voltha.OperStatus_DISCOVERED, |
| 1288 | }); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1289 | //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] | 1290 | 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] | 1291 | return |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1292 | } |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 1293 | if err := dh.ReasonUpdate(ctx, cmn.DrRebooting, true); err != nil { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1294 | return |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1295 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1296 | dh.SetReadyForOmciConfig(false) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1297 | //no specific activity to synchronize any internal FSM to the 'rebooted' state is explicitly done here |
| 1298 | // the expectation ids for a real device, that it will be synced with the expected following 'down' indication |
| 1299 | // as BBSIM does not support this testing requires explicite disable/enable device calls in which sequence also |
| 1300 | // all other FSM's should be synchronized again |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1301 | } |
| 1302 | |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 1303 | //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] | 1304 | // used only for old - R2.7 style - upgrade API |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1305 | func (dh *deviceHandler) doOnuSwUpgrade(ctx context.Context, apImageDsc *voltha.ImageDownload, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1306 | apDownloadManager *swupg.AdapterDownloadManager) error { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1307 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1308 | "device-id": dh.DeviceID, "image-name": (*apImageDsc).Name}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1309 | |
| 1310 | var err error |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1311 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1312 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1313 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1314 | 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] | 1315 | } |
| 1316 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1317 | if dh.IsReadyForOmciConfig() { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1318 | var inactiveImageID uint16 |
| 1319 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1320 | dh.lockUpgradeFsm.Lock() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1321 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| 1322 | // but must be still locked at calling createOnuUpgradeFsm |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1323 | if dh.pOnuUpradeFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1324 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1325 | dh.lockUpgradeFsm.Unlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1326 | if err == nil { |
| 1327 | if err = dh.pOnuUpradeFsm.SetDownloadParams(ctx, inactiveImageID, apImageDsc, apDownloadManager); err != nil { |
| 1328 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1329 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1330 | } |
| 1331 | } else { |
| 1332 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1333 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1334 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1335 | } else { //OnuSw upgrade already running - restart (with possible abort of running) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1336 | dh.lockUpgradeFsm.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1337 | 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] | 1338 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1339 | dh.upgradeCanceled = true |
| 1340 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1341 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1342 | //no effort spent anymore for the old API to automatically cancel and restart the download |
| 1343 | // like done for the new API |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1344 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1345 | } else { |
| 1346 | 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] | 1347 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1348 | } |
| 1349 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1350 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no active OMCI connection", log.Fields{"device-id": dh.DeviceID}) |
| 1351 | 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] | 1352 | } |
| 1353 | return err |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1356 | //onuSwUpgradeAfterDownload initiates the SW download transfer to the ONU with activate and commit options |
| 1357 | // after the OnuImage has been downloaded to the adapter, called in background |
| 1358 | func (dh *deviceHandler) onuSwUpgradeAfterDownload(ctx context.Context, apImageRequest *voltha.DeviceImageDownloadRequest, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1359 | apDownloadManager *swupg.FileDownloadManager, aImageIdentifier string) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1360 | |
| 1361 | var err error |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1362 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1363 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1364 | 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] | 1365 | return |
| 1366 | } |
| 1367 | |
| 1368 | var inactiveImageID uint16 |
| 1369 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1370 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1371 | "device-id": dh.DeviceID, "image-version": apImageRequest.Image.Version, "to onu-image": inactiveImageID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1372 | |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1373 | dh.lockUpgradeFsm.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1374 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1375 | // but must be still locked at calling createOnuUpgradeFsm |
| 1376 | // (and working with a local pointer copy does not work here if asynchronous request are done to fast |
| 1377 | // [e.g.leaving the local pointer on nil even though a creation is already on the way]) |
| 1378 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1379 | //OnuSw upgrade already running on this device (e.g. with activate/commit not yet set) |
| 1380 | // abort the current processing, running upgrades are always aborted by newer request |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1381 | 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] | 1382 | //flush the remove upgradeFsmChan channel |
| 1383 | select { |
| 1384 | case <-dh.upgradeFsmChan: |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1385 | logger.Debugw(ctx, "flushed-upgrade-fsm-channel", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1386 | default: |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1387 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1388 | dh.lockUpgradeFsm.Unlock() |
| 1389 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1390 | dh.upgradeCanceled = true |
| 1391 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1392 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1393 | select { |
| 1394 | case <-time.After(cTimeOutRemoveUpgrade * time.Second): |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1395 | 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] | 1396 | //should not appear, can't proceed with new upgrade, perhaps operator can retry manually later |
| 1397 | return |
| 1398 | case <-dh.upgradeFsmChan: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1399 | 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] | 1400 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1401 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1402 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1403 | |
| 1404 | //here it can be assumed that no running upgrade processing exists (anymore) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1405 | //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] | 1406 | // but none yet defined |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1407 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1408 | dh.lockUpgradeFsm.Unlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1409 | if err == nil { |
| 1410 | if err = dh.pOnuUpradeFsm.SetDownloadParamsAfterDownload(ctx, inactiveImageID, |
| 1411 | apImageRequest, apDownloadManager, aImageIdentifier); err != nil { |
| 1412 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1413 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1414 | return |
| 1415 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1416 | } else { |
| 1417 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1418 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1419 | } |
| 1420 | return |
| 1421 | } |
| 1422 | 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] | 1423 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | //onuSwActivateRequest ensures activation of the requested image with commit options |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1427 | func (dh *deviceHandler) onuSwActivateRequest(ctx context.Context, |
| 1428 | aVersion string, aCommitRequest bool) (*voltha.ImageState, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1429 | var err error |
| 1430 | //SW activation for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1431 | // 1.) activation of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1432 | // 2.) activation of the inactive image |
| 1433 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1434 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1435 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1436 | logger.Errorw(ctx, "Onu image activation rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1437 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1438 | } |
| 1439 | dh.lockUpgradeFsm.RLock() |
| 1440 | if dh.pOnuUpradeFsm != nil { |
| 1441 | dh.lockUpgradeFsm.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1442 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1443 | if getErr != nil || onuVolthaDevice == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1444 | logger.Errorw(ctx, "Failed to fetch Onu device for image activation", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1445 | 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] | 1446 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1447 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1448 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1449 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1450 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1451 | // use the OnuVendor identification from this device for the internal unique name |
| 1452 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1453 | // 1.) check a started upgrade process and relay the activation request to it |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1454 | if err = dh.pOnuUpradeFsm.SetActivationParamsRunning(ctx, imageIdentifier, aCommitRequest); err != nil { |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1455 | //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] | 1456 | 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] | 1457 | "device-id": dh.DeviceID, "error": err}) |
| 1458 | 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] | 1459 | } |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1460 | logger.Debugw(ctx, "image activation acknowledged by onu upgrade processing", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1461 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
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 | dh.lockUpgradeFsm.RUnlock() |
| 1466 | |
| 1467 | // 2.) check if requested image-version equals the inactive one and start its activation |
| 1468 | // (image version is not [yet] checked - would be possible, but with increased effort ...) |
| 1469 | var inactiveImageID uint16 |
| 1470 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err != nil || inactiveImageID > 1 { |
| 1471 | logger.Errorw(ctx, "get inactive image failed", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1472 | "device-id": dh.DeviceID, "err": err, "image-id": inactiveImageID}) |
| 1473 | 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] | 1474 | } |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1475 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1476 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1477 | dh.lockUpgradeFsm.Unlock() |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1478 | if err == nil { |
| 1479 | if err = dh.pOnuUpradeFsm.SetActivationParamsStart(ctx, aVersion, |
| 1480 | inactiveImageID, aCommitRequest); err != nil { |
| 1481 | 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] | 1482 | "device-id": dh.DeviceID, "error": err}) |
| 1483 | 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] | 1484 | } |
| 1485 | logger.Debugw(ctx, "inactive image activation acknowledged by onu upgrade", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1486 | "device-id": dh.DeviceID, "image-version": aVersion}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1487 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1488 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1489 | } //else |
| 1490 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1491 | "device-id": dh.DeviceID, "error": err}) |
| 1492 | 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] | 1493 | } |
| 1494 | |
| 1495 | //onuSwCommitRequest ensures commitment of the requested image |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1496 | func (dh *deviceHandler) onuSwCommitRequest(ctx context.Context, |
| 1497 | aVersion string) (*voltha.ImageState, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1498 | var err error |
| 1499 | //SW commitment for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1500 | // 1.) commitment of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1501 | // 2.) commitment of the active image |
| 1502 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1503 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1504 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1505 | logger.Errorw(ctx, "Onu image commitment rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1506 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1507 | } |
| 1508 | dh.lockUpgradeFsm.RLock() |
| 1509 | if dh.pOnuUpradeFsm != nil { |
| 1510 | dh.lockUpgradeFsm.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1511 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1512 | if getErr != nil || onuVolthaDevice == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1513 | logger.Errorw(ctx, "Failed to fetch Onu device for image commitment", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1514 | 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] | 1515 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1516 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1517 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1518 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1519 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1520 | // use the OnuVendor identification from this device for the internal unique name |
| 1521 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1522 | // 1.) check a started upgrade process and relay the commitment request to it |
| 1523 | // the running upgrade may be based either on the imageIdentifier (started from download) |
| 1524 | // or on the imageVersion (started from pure activation) |
| 1525 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsRunning(ctx, imageIdentifier, aVersion); err != nil { |
| 1526 | //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] | 1527 | 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] | 1528 | "device-id": dh.DeviceID, "error": err}) |
| 1529 | 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] | 1530 | } |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1531 | logger.Debugw(ctx, "image commitment acknowledged by onu upgrade processing", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1532 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1533 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1534 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1535 | } //else |
| 1536 | dh.lockUpgradeFsm.RUnlock() |
| 1537 | |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1538 | // 2.) use the active image to directly commit |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1539 | var activeImageID uint16 |
| 1540 | if activeImageID, err = pDevEntry.GetActiveImageMeID(ctx); err != nil || activeImageID > 1 { |
| 1541 | logger.Errorw(ctx, "get active image failed", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1542 | "device-id": dh.DeviceID, "err": err, "image-id": activeImageID}) |
| 1543 | 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] | 1544 | } |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1545 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1546 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1547 | dh.lockUpgradeFsm.Unlock() |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1548 | if err == nil { |
| 1549 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsStart(ctx, aVersion, activeImageID); err != nil { |
| 1550 | 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] | 1551 | "device-id": dh.DeviceID, "error": err}) |
| 1552 | 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] | 1553 | } |
| 1554 | logger.Debugw(ctx, "active image commitment acknowledged by onu upgrade", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1555 | "device-id": dh.DeviceID, "image-version": aVersion}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1556 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1557 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1558 | } //else |
| 1559 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1560 | "device-id": dh.DeviceID, "error": err}) |
| 1561 | 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] | 1562 | } |
| 1563 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1564 | func (dh *deviceHandler) requestOnuSwUpgradeState(ctx context.Context, aImageIdentifier string, |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1565 | aVersion string) *voltha.ImageState { |
| 1566 | var pImageState *voltha.ImageState |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1567 | dh.lockUpgradeFsm.RLock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1568 | defer dh.lockUpgradeFsm.RUnlock() |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1569 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1570 | pImageState = dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1571 | } else { //use the last stored ImageState (if the requested Imageversion coincides) |
| 1572 | if aVersion == dh.pLastUpgradeImageState.Version { |
| 1573 | pImageState = dh.pLastUpgradeImageState |
| 1574 | } else { //state request for an image version different from last processed image version |
| 1575 | pImageState = &voltha.ImageState{ |
| 1576 | Version: aVersion, |
| 1577 | //we cannot state something concerning this version |
| 1578 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 1579 | Reason: voltha.ImageState_NO_ERROR, |
| 1580 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 1581 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1582 | } |
| 1583 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1584 | return pImageState |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | func (dh *deviceHandler) cancelOnuSwUpgrade(ctx context.Context, aImageIdentifier string, |
| 1588 | aVersion string, pDeviceImageState *voltha.DeviceImageState) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1589 | pDeviceImageState.DeviceId = dh.DeviceID |
mpagenko | 7455fd4 | 2021-06-10 16:25:55 +0000 | [diff] [blame] | 1590 | pDeviceImageState.ImageState.Version = aVersion |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1591 | dh.lockUpgradeFsm.RLock() |
| 1592 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1593 | dh.lockUpgradeFsm.RUnlock() |
| 1594 | // so then we cancel the upgrade operation |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1595 | // but before we still request the actual upgrade states for the direct response |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1596 | pImageState := dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1597 | pDeviceImageState.ImageState.DownloadState = pImageState.DownloadState |
| 1598 | pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST |
| 1599 | pDeviceImageState.ImageState.ImageState = pImageState.ImageState |
| 1600 | if pImageState.DownloadState != voltha.ImageState_DOWNLOAD_UNKNOWN { |
| 1601 | //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] | 1602 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1603 | dh.upgradeCanceled = true |
| 1604 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1605 | } |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1606 | } //nothing to cancel (upgrade FSM for different image stays alive) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1607 | } else { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1608 | dh.lockUpgradeFsm.RUnlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1609 | // if no upgrade is ongoing, nothing is canceled and accordingly the states of the requested image are unknown |
| 1610 | // reset also the dh handler LastUpgradeImageState (not relevant anymore/cleared) |
| 1611 | (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1612 | (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR |
| 1613 | (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1614 | (*dh.pLastUpgradeImageState).Version = "" //reset to 'no (relevant) upgrade done' (like initial state) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1615 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1616 | pDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1617 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1618 | //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] | 1619 | } |
| 1620 | } |
| 1621 | |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1622 | func (dh *deviceHandler) getOnuImages(ctx context.Context) (*voltha.OnuImages, error) { |
| 1623 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1624 | var onuImageStatus *swupg.OnuImageStatus |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1625 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1626 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1627 | if pDevEntry != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1628 | onuImageStatus = swupg.NewOnuImageStatus(dh, pDevEntry) |
| 1629 | pDevEntry.MutexOnuImageStatus.Lock() |
| 1630 | pDevEntry.POnuImageStatus = onuImageStatus |
| 1631 | pDevEntry.MutexOnuImageStatus.Unlock() |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1632 | |
| 1633 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1634 | 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] | 1635 | return nil, fmt.Errorf("no-valid-OnuDevice-aborting") |
| 1636 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1637 | images, err := onuImageStatus.GetOnuImageStatus(ctx) |
| 1638 | pDevEntry.MutexOnuImageStatus.Lock() |
| 1639 | pDevEntry.POnuImageStatus = nil |
| 1640 | pDevEntry.MutexOnuImageStatus.Unlock() |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1641 | return images, err |
| 1642 | } |
| 1643 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1644 | // deviceHandler methods that implement the adapters interface requests## end ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1645 | // ##################################################################################### |
| 1646 | |
| 1647 | // ################ to be updated acc. needs of ONU Device ######################## |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1648 | // deviceHandler StateMachine related state transition methods ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1649 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1650 | func (dh *deviceHandler) logStateChange(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1651 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"event name": string(e.Event), |
| 1652 | "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] | 1653 | } |
| 1654 | |
| 1655 | // doStateInit provides the device update to the core |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1656 | func (dh *deviceHandler) doStateInit(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1657 | |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1658 | logger.Debugw(ctx, "doStateInit-started", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1659 | var err error |
| 1660 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1661 | // populate what we know. rest comes later after mib sync |
| 1662 | dh.device.Root = false |
| 1663 | dh.device.Vendor = "OpenONU" |
| 1664 | dh.device.Model = "go" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1665 | dh.device.Reason = cmn.DeviceReasonMap[cmn.DrActivatingOnu] |
mpagenko | e478208 | 2021-11-25 12:04:26 +0000 | [diff] [blame] | 1666 | _ = dh.ReasonUpdate(ctx, cmn.DrActivatingOnu, false) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1667 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1668 | dh.logicalDeviceID = dh.DeviceID // really needed - what for ??? //TODO!!! |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1669 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1670 | if !dh.IsReconciling() { |
| 1671 | 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] | 1672 | if err := dh.updateDeviceInCore(ctx, dh.device); err != nil { |
| 1673 | logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err}) |
| 1674 | } |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 1675 | //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] | 1676 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1677 | logger.Debugw(ctx, "reconciling - don't notify core about DeviceUpdate", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1678 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1679 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1680 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1681 | dh.parentID = dh.device.ParentId |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1682 | dh.ponPortNumber = dh.device.ParentPortNo |
| 1683 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1684 | // store proxy parameters for later communication - assumption: invariant, else they have to be requested dynamically!! |
| 1685 | dh.ProxyAddressID = dh.device.ProxyAddress.GetDeviceId() |
| 1686 | dh.ProxyAddressType = dh.device.ProxyAddress.GetDeviceType() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1687 | 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] | 1688 | "proxyAddressType": dh.ProxyAddressType, "SNR": dh.device.SerialNumber, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1689 | "ParentId": dh.parentID, "ParentPortNo": dh.ponPortNumber}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1690 | |
| 1691 | /* |
| 1692 | self._pon = PonPort.create(self, self._pon_port_number) |
| 1693 | self._pon.add_peer(self.parent_id, self._pon_port_number) |
| 1694 | self.logger.debug('adding-pon-port-to-agent', |
| 1695 | type=self._pon.get_port().type, |
| 1696 | admin_state=self._pon.get_port().admin_state, |
| 1697 | oper_status=self._pon.get_port().oper_status, |
| 1698 | ) |
| 1699 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1700 | if !dh.IsReconciling() { |
| 1701 | 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] | 1702 | var ponPortNo uint32 = 1 |
| 1703 | if dh.ponPortNumber != 0 { |
| 1704 | ponPortNo = dh.ponPortNumber |
| 1705 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1706 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1707 | pPonPort := &voltha.Port{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1708 | DeviceId: dh.DeviceID, |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1709 | PortNo: ponPortNo, |
| 1710 | Label: fmt.Sprintf("pon-%d", ponPortNo), |
| 1711 | Type: voltha.Port_PON_ONU, |
| 1712 | OperStatus: voltha.OperStatus_ACTIVE, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1713 | Peers: []*voltha.Port_PeerPort{{DeviceId: dh.parentID, // Peer device is OLT |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1714 | PortNo: ponPortNo}}, // Peer port is parent's port number |
| 1715 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1716 | if err = dh.CreatePortInCore(ctx, pPonPort); err != nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1717 | logger.Fatalf(ctx, "Device FSM: PortCreated-failed-%s:%s", err, dh.DeviceID) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1718 | e.Cancel(err) |
| 1719 | return |
| 1720 | } |
| 1721 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1722 | 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] | 1723 | } |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1724 | logger.Debugw(ctx, "doStateInit-done", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | // postInit setups the DeviceEntry for the conerned device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1728 | func (dh *deviceHandler) postInit(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1729 | |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1730 | logger.Debugw(ctx, "postInit-started", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1731 | var err error |
| 1732 | /* |
| 1733 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
| 1734 | dh.pTransitionMap.Handle(ctx, GrpcConnected) |
| 1735 | return nil |
| 1736 | */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1737 | if err = dh.addOnuDeviceEntry(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1738 | logger.Fatalf(ctx, "Device FSM: addOnuDeviceEntry-failed-%s:%s", err, dh.DeviceID) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1739 | e.Cancel(err) |
| 1740 | return |
| 1741 | } |
| 1742 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1743 | if dh.IsReconciling() { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1744 | go dh.reconcileDeviceOnuInd(ctx) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1745 | // reconcilement will be continued after mib download is done |
| 1746 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1747 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1748 | /* |
| 1749 | ############################################################################ |
| 1750 | # Setup Alarm handler |
| 1751 | self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id, |
| 1752 | device.serial_number) |
| 1753 | ############################################################################ |
| 1754 | # Setup PM configuration for this device |
| 1755 | # Pass in ONU specific options |
| 1756 | kwargs = { |
| 1757 | OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY, |
| 1758 | 'heartbeat': self.heartbeat, |
| 1759 | OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device |
| 1760 | } |
| 1761 | self.logger.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number) |
| 1762 | self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id, |
| 1763 | self.logical_device_id, device.serial_number, |
| 1764 | grouped=True, freq_override=False, **kwargs) |
| 1765 | pm_config = self._pm_metrics.make_proto() |
| 1766 | self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm) |
| 1767 | self.logger.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number) |
| 1768 | yield self.core_proxy.device_pm_config_update(pm_config, init=True) |
| 1769 | |
| 1770 | # Note, ONU ID and UNI intf set in add_uni_port method |
| |