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" |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 32 | me "github.com/opencord/omci-lib-go/generated" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 33 | "github.com/opencord/voltha-lib-go/v7/pkg/db" |
| 34 | "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif" |
| 35 | flow "github.com/opencord/voltha-lib-go/v7/pkg/flows" |
| 36 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| 37 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 38 | platform "github.com/opencord/voltha-lib-go/v7/pkg/platform" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 39 | almgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/almgr" |
| 40 | avcfg "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/avcfg" |
| 41 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
| 42 | mib "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/mib" |
| 43 | otst "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/omcitst" |
| 44 | pmmgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/pmmgr" |
| 45 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/swupg" |
| 46 | uniprt "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/uniprt" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 47 | vc "github.com/opencord/voltha-protos/v5/go/common" |
| 48 | "github.com/opencord/voltha-protos/v5/go/extension" |
| 49 | ic "github.com/opencord/voltha-protos/v5/go/inter_container" |
| 50 | of "github.com/opencord/voltha-protos/v5/go/openflow_13" |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 51 | "github.com/opencord/voltha-protos/v5/go/openolt" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 52 | oop "github.com/opencord/voltha-protos/v5/go/openolt" |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 53 | "github.com/opencord/voltha-protos/v5/go/tech_profile" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 54 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 55 | ) |
| 56 | |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 57 | // Constants for timeouts |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 58 | const ( |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 59 | cTimeOutRemoveUpgrade = 1 //for usage in seconds |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 60 | ) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 61 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 62 | const ( |
| 63 | // events of Device FSM |
| 64 | devEvDeviceInit = "devEvDeviceInit" |
| 65 | devEvGrpcConnected = "devEvGrpcConnected" |
| 66 | devEvGrpcDisconnected = "devEvGrpcDisconnected" |
| 67 | devEvDeviceUpInd = "devEvDeviceUpInd" |
| 68 | devEvDeviceDownInd = "devEvDeviceDownInd" |
| 69 | ) |
| 70 | const ( |
| 71 | // states of Device FSM |
| 72 | devStNull = "devStNull" |
| 73 | devStDown = "devStDown" |
| 74 | devStInit = "devStInit" |
| 75 | devStConnected = "devStConnected" |
| 76 | devStUp = "devStUp" |
| 77 | ) |
| 78 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 79 | //Event category and subcategory definitions - same as defiend for OLT in eventmgr.go - should be done more centrally |
| 80 | const ( |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 81 | pon = voltha.EventSubCategory_PON |
| 82 | //olt = voltha.EventSubCategory_OLT |
| 83 | //ont = voltha.EventSubCategory_ONT |
| 84 | //onu = voltha.EventSubCategory_ONU |
| 85 | //nni = voltha.EventSubCategory_NNI |
| 86 | //service = voltha.EventCategory_SERVICE |
| 87 | //security = voltha.EventCategory_SECURITY |
| 88 | equipment = voltha.EventCategory_EQUIPMENT |
| 89 | //processing = voltha.EventCategory_PROCESSING |
| 90 | //environment = voltha.EventCategory_ENVIRONMENT |
| 91 | //communication = voltha.EventCategory_COMMUNICATION |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 92 | ) |
| 93 | |
| 94 | const ( |
| 95 | cEventObjectType = "ONU" |
| 96 | ) |
| 97 | const ( |
| 98 | cOnuActivatedEvent = "ONU_ACTIVATED" |
| 99 | ) |
| 100 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 101 | type omciIdleCheckStruct struct { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 102 | omciIdleCheckFunc func(*deviceHandler, context.Context, cmn.UsedOmciConfigFsms, string) bool |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 103 | omciIdleState string |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 106 | var fsmOmciIdleStateFuncMap = map[cmn.UsedOmciConfigFsms]omciIdleCheckStruct{ |
| 107 | cmn.CUploadFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibUlFsmIdleState}, |
| 108 | cmn.CDownloadFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibDlFsmIdleState}, |
| 109 | cmn.CUniLockFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState}, |
| 110 | cmn.CUniUnLockFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState}, |
| 111 | cmn.CAniConfigFsm: {(*deviceHandler).isAniConfigFsmInOmciIdleState, avcfg.CAniFsmIdleState}, |
| 112 | cmn.CUniVlanConfigFsm: {(*deviceHandler).isUniVlanConfigFsmInOmciIdleState, avcfg.CVlanFsmIdleState}, |
| 113 | cmn.CL2PmFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, pmmgr.CL2PmFsmIdleState}, |
| 114 | cmn.COnuUpgradeFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, swupg.COnuUpgradeFsmIdleState}, |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 117 | const ( |
| 118 | cNoReconciling = iota |
| 119 | cOnuConfigReconciling |
| 120 | cSkipOnuConfigReconciling |
| 121 | ) |
| 122 | |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 123 | // FlowCb is the flow control block containing flow add/delete information along with a response channel |
| 124 | type FlowCb struct { |
| 125 | ctx context.Context // Flow handler context |
| 126 | addFlow bool // if true flow to be added, else removed |
| 127 | flowItem *of.OfpFlowStats |
| 128 | uniPort *cmn.OnuUniPort |
| 129 | flowMetaData *voltha.FlowMetadata |
| 130 | respChan *chan error // channel to report the Flow handling error |
| 131 | } |
| 132 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 133 | //deviceHandler will interact with the ONU ? device. |
| 134 | type deviceHandler struct { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 135 | DeviceID string |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 136 | DeviceType string |
| 137 | adminState string |
| 138 | device *voltha.Device |
| 139 | logicalDeviceID string |
| 140 | ProxyAddressID string |
| 141 | ProxyAddressType string |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 142 | parentID string |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 143 | ponPortNumber uint32 |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 144 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 145 | coreClient *vgrpc.Client |
| 146 | EventProxy eventif.EventProxy |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 147 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 148 | pmConfigs *voltha.PmConfigs |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 149 | config *config.AdapterFlags |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 150 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 151 | pOpenOnuAc *OpenONUAC |
| 152 | pDeviceStateFsm *fsm.FSM |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 153 | //pPonPort *voltha.Port |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 154 | deviceEntrySet chan bool //channel for DeviceEntry set event |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 155 | pOnuOmciDevice *mib.OnuDeviceEntry |
| 156 | pOnuTP *avcfg.OnuUniTechProf |
| 157 | pOnuMetricsMgr *pmmgr.OnuMetricsManager |
| 158 | pAlarmMgr *almgr.OnuAlarmManager |
| 159 | pSelfTestHdlr *otst.SelfTestControlBlock |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 160 | exitChannel chan int |
| 161 | lockDevice sync.RWMutex |
| 162 | pOnuIndication *oop.OnuIndication |
| 163 | deviceReason uint8 |
| 164 | mutexDeviceReason sync.RWMutex |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 165 | pLockStateFsm *uniprt.LockStateFsm |
| 166 | pUnlockStateFsm *uniprt.LockStateFsm |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 167 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 168 | //flowMgr *OpenOltFlowMgr |
| 169 | //eventMgr *OpenOltEventMgr |
| 170 | //resourceMgr *rsrcMgr.OpenOltResourceMgr |
| 171 | |
| 172 | //discOnus sync.Map |
| 173 | //onus sync.Map |
| 174 | //portStats *OpenOltStatisticsMgr |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 175 | collectorIsRunning bool |
| 176 | mutexCollectorFlag sync.RWMutex |
| 177 | stopCollector chan bool |
| 178 | alarmManagerIsRunning bool |
| 179 | mutextAlarmManagerFlag sync.RWMutex |
| 180 | stopAlarmManager chan bool |
| 181 | stopHeartbeatCheck chan bool |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 182 | uniEntityMap cmn.OnuUniPortMap |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 183 | mutexKvStoreContext sync.Mutex |
| 184 | lockVlanConfig sync.RWMutex |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 185 | lockVlanAdd sync.RWMutex |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 186 | UniVlanConfigFsmMap map[uint8]*avcfg.UniVlanConfigFsm |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 187 | lockUpgradeFsm sync.RWMutex |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 188 | pOnuUpradeFsm *swupg.OnuUpgradeFsm |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 189 | upgradeCanceled bool |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 190 | reconciling uint8 |
| 191 | mutexReconcilingFlag sync.RWMutex |
| 192 | chReconcilingFinished chan bool //channel to indicate that reconciling has been finished |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 193 | mutexReadyForOmciConfig sync.RWMutex |
| 194 | readyForOmciConfig bool |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 195 | deletionInProgress bool |
| 196 | mutexDeletionInProgressFlag sync.RWMutex |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 197 | pLastUpgradeImageState *voltha.ImageState |
| 198 | upgradeFsmChan chan struct{} |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 199 | |
| 200 | flowCbChan []chan FlowCb |
| 201 | mutexFlowMonitoringRoutineFlag sync.RWMutex |
| 202 | stopFlowMonitoringRoutine []chan bool // length of slice equal to number of uni ports |
| 203 | isFlowMonitoringRoutineActive []bool // length of slice equal to number of uni ports |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 206 | //newDeviceHandler creates a new device handler |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 207 | 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] | 208 | var dh deviceHandler |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 209 | dh.coreClient = cc |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 210 | dh.EventProxy = ep |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 211 | dh.config = adapter.config |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 212 | cloned := (proto.Clone(device)).(*voltha.Device) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 213 | dh.DeviceID = cloned.Id |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 214 | dh.DeviceType = cloned.Type |
| 215 | dh.adminState = "up" |
| 216 | dh.device = cloned |
| 217 | dh.pOpenOnuAc = adapter |
| 218 | dh.exitChannel = make(chan int, 1) |
| 219 | dh.lockDevice = sync.RWMutex{} |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 220 | dh.deviceEntrySet = make(chan bool, 1) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 221 | dh.collectorIsRunning = false |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 222 | dh.stopCollector = make(chan bool, 2) |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 223 | dh.alarmManagerIsRunning = false |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 224 | dh.stopAlarmManager = make(chan bool, 2) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 225 | dh.stopHeartbeatCheck = make(chan bool, 2) |
| 226 | //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] | 227 | //TODO initialize the support classes. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 228 | dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 229 | dh.lockVlanConfig = sync.RWMutex{} |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 230 | dh.lockVlanAdd = sync.RWMutex{} |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 231 | dh.lockUpgradeFsm = sync.RWMutex{} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 232 | dh.UniVlanConfigFsmMap = make(map[uint8]*avcfg.UniVlanConfigFsm) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 233 | dh.reconciling = cNoReconciling |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 234 | dh.chReconcilingFinished = make(chan bool) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 235 | dh.readyForOmciConfig = false |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 236 | dh.deletionInProgress = false |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 237 | dh.pLastUpgradeImageState = &voltha.ImageState{ |
| 238 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 239 | Reason: voltha.ImageState_UNKNOWN_ERROR, |
| 240 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 241 | } |
| 242 | dh.upgradeFsmChan = make(chan struct{}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 243 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 244 | if dh.device.PmConfigs != nil { // can happen after onu adapter restart |
| 245 | dh.pmConfigs = cloned.PmConfigs |
| 246 | } /* else { |
| 247 | // will be populated when onu_metrics_mananger is initialized. |
| 248 | }*/ |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 249 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 250 | // Device related state machine |
| 251 | dh.pDeviceStateFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 252 | devStNull, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 253 | fsm.Events{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 254 | {Name: devEvDeviceInit, Src: []string{devStNull, devStDown}, Dst: devStInit}, |
| 255 | {Name: devEvGrpcConnected, Src: []string{devStInit}, Dst: devStConnected}, |
| 256 | {Name: devEvGrpcDisconnected, Src: []string{devStConnected, devStDown}, Dst: devStInit}, |
| 257 | {Name: devEvDeviceUpInd, Src: []string{devStConnected, devStDown}, Dst: devStUp}, |
| 258 | {Name: devEvDeviceDownInd, Src: []string{devStUp}, Dst: devStDown}, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 259 | }, |
| 260 | fsm.Callbacks{ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 261 | "before_event": func(e *fsm.Event) { dh.logStateChange(ctx, e) }, |
| 262 | ("before_" + devEvDeviceInit): func(e *fsm.Event) { dh.doStateInit(ctx, e) }, |
| 263 | ("after_" + devEvDeviceInit): func(e *fsm.Event) { dh.postInit(ctx, e) }, |
| 264 | ("before_" + devEvGrpcConnected): func(e *fsm.Event) { dh.doStateConnected(ctx, e) }, |
| 265 | ("before_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.doStateInit(ctx, e) }, |
| 266 | ("after_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.postInit(ctx, e) }, |
| 267 | ("before_" + devEvDeviceUpInd): func(e *fsm.Event) { dh.doStateUp(ctx, e) }, |
| 268 | ("before_" + devEvDeviceDownInd): func(e *fsm.Event) { dh.doStateDown(ctx, e) }, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 269 | }, |
| 270 | ) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 271 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 272 | return &dh |
| 273 | } |
| 274 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 275 | // start save the device to the data model |
| 276 | func (dh *deviceHandler) start(ctx context.Context) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 277 | 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] | 278 | // Add the initial device to the local model |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 279 | logger.Debug(ctx, "device-handler-started") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 282 | /* |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 283 | // stop stops the device dh. Not much to do for now |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 284 | func (dh *deviceHandler) stop(ctx context.Context) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 285 | logger.Debug("stopping-device-handler") |
| 286 | dh.exitChannel <- 1 |
| 287 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 288 | */ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 289 | |
| 290 | // ########################################################################################## |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 291 | // deviceHandler methods that implement the adapters interface requests ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 292 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 293 | //adoptOrReconcileDevice adopts the ONU device |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 294 | func (dh *deviceHandler) adoptOrReconcileDevice(ctx context.Context, device *voltha.Device) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 295 | 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] | 296 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 297 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"state": string(dh.pDeviceStateFsm.Current())}) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 298 | if dh.pDeviceStateFsm.Is(devStNull) { |
| 299 | if err := dh.pDeviceStateFsm.Event(devEvDeviceInit); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 300 | logger.Errorw(ctx, "Device FSM: Can't go to state DeviceInit", log.Fields{"err": err}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 301 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 302 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"state": string(dh.pDeviceStateFsm.Current())}) |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 303 | // device.PmConfigs is not nil in cases when adapter restarts. We should not re-set the core again. |
| 304 | if device.PmConfigs == nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 305 | // Now, set the initial PM configuration for that device |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 306 | if err := dh.updatePMConfigInCore(ctx, dh.pmConfigs); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 307 | 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] | 308 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 309 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 310 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 311 | 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] | 312 | } |
| 313 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 314 | } |
| 315 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 316 | func (dh *deviceHandler) handleOMCIIndication(ctx context.Context, msg *ic.OmciMessage) error { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 317 | /* 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] | 318 | //assuming omci message content is hex coded! |
| 319 | // with restricted output of 16(?) bytes would be ...omciMsg.Message[:16] |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 320 | logger.Debugw(ctx, "inter-adapter-recv-omci", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 321 | "device-id": dh.DeviceID, "RxOmciMessage": hex.EncodeToString(omciMsg.Message)}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 322 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 323 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 324 | if pDevEntry != nil { |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 325 | if pDevEntry.PDevOmciCC != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 326 | return pDevEntry.PDevOmciCC.ReceiveMessage(log.WithSpanFromContext(context.TODO(), ctx), msg.Message) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 327 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 328 | logger.Debugw(ctx, "omciCC not ready to receive omci messages - incoming omci message ignored", log.Fields{"rxMsg": msg.Message}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 329 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 330 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 331 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 332 | } |
| 333 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 334 | func (dh *deviceHandler) handleTechProfileDownloadRequest(ctx context.Context, techProfMsg *ic.TechProfileDownloadMessage) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 335 | 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] | 336 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 337 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 338 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 339 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 340 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 341 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 342 | if dh.pOnuTP == nil { |
| 343 | //should normally not happen ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 344 | 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] | 345 | log.Fields{"device-id": dh.DeviceID}) |
| 346 | 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] | 347 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 348 | if !dh.IsReadyForOmciConfig() { |
| 349 | logger.Errorw(ctx, "TechProf-set rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 350 | "device-state": dh.GetDeviceReasonString()}) |
| 351 | 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] | 352 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 353 | //previous state test here was just this one, now extended for more states to reject the SetRequest: |
| 354 | // at least 'mib-downloaded' should be reached for processing of this specific ONU configuration |
| 355 | // if (dh.deviceReason == "stopping-openomci") || (dh.deviceReason == "omci-admin-lock") |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 356 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 357 | // 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] | 358 | // even to fast subsequent calls of the same messageType as well as OnuKVStore processing due |
| 359 | // to possible concurrent access by flow processing |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 360 | dh.pOnuTP.LockTpProcMutex() |
| 361 | defer dh.pOnuTP.UnlockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 362 | |
| 363 | if techProfMsg.UniId > 255 { |
| 364 | 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] | 365 | techProfMsg.UniId, dh.DeviceID)) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 366 | } |
| 367 | uniID := uint8(techProfMsg.UniId) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 368 | tpID, err := cmn.GetTpIDFromTpPath(techProfMsg.TpInstancePath) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 369 | if err != nil { |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 370 | logger.Errorw(ctx, "error-parsing-tpid-from-tppath", log.Fields{"err": err, "tp-path": techProfMsg.TpInstancePath}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 371 | return err |
| 372 | } |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 373 | logger.Debugw(ctx, "unmarshal-techprof-msg-body", log.Fields{"uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 374 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 375 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, uint8(tpID), techProfMsg.TpInstancePath); bTpModify { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 376 | |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 377 | switch tpInst := techProfMsg.TechTpInstance.(type) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 378 | case *ic.TechProfileDownloadMessage_TpInstance: |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 379 | logger.Debugw(ctx, "onu-uni-tp-path-modified", log.Fields{"uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
| 380 | // if there has been some change for some uni TechProfilePath |
| 381 | //in order to allow concurrent calls to other dh instances we do not wait for execution here |
| 382 | //but doing so we can not indicate problems to the caller (who does what with that then?) |
| 383 | //by now we just assume straightforward successful execution |
| 384 | //TODO!!! Generally: In this scheme it would be good to have some means to indicate |
| 385 | // possible problems to the caller later autonomously |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 386 | |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 387 | // deadline context to ensure completion of background routines waited for |
| 388 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 389 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 390 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 391 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 392 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 393 | |
| 394 | var wg sync.WaitGroup |
| 395 | wg.Add(1) // for the 1 go routine to finish |
| 396 | // 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] | 397 | 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] | 398 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfDwld") //wait for background process to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 399 | if tpErr := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); tpErr != nil { |
| 400 | 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] | 401 | return tpErr |
| 402 | } |
| 403 | deadline = time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 404 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 405 | pDevEntry.ResetKvProcessingErrorIndication() |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 406 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 407 | go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 408 | dh.waitForCompletion(ctx, cancel2, &wg, "TechProfDwld") //wait for background process to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 409 | if kvErr := pDevEntry.GetKvProcessingErrorIndication(); kvErr != nil { |
| 410 | 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] | 411 | return kvErr |
| 412 | } |
| 413 | return nil |
| 414 | default: |
| 415 | logger.Errorw(ctx, "unsupported-tp-instance-type", log.Fields{"tp-path": techProfMsg.TpInstancePath}) |
| 416 | return fmt.Errorf("unsupported-tp-instance-type--tp-id-%v", techProfMsg.TpInstancePath) |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 417 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 418 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 419 | // no change, nothing really to do - return success |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 420 | logger.Debugw(ctx, "onu-uni-tp-path-not-modified", log.Fields{"uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 421 | return nil |
| 422 | } |
| 423 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 424 | func (dh *deviceHandler) handleDeleteGemPortRequest(ctx context.Context, delGemPortMsg *ic.DeleteGemPortMessage) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 425 | logger.Infow(ctx, "delete-gem-port-request", log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 426 | |
| 427 | if dh.pOnuTP == nil { |
| 428 | //should normally not happen ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 429 | 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] | 430 | log.Fields{"device-id": dh.DeviceID}) |
| 431 | 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] | 432 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 433 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 434 | dh.pOnuTP.LockTpProcMutex() |
| 435 | defer dh.pOnuTP.UnlockTpProcMutex() |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 436 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 437 | if delGemPortMsg.UniId > 255 { |
| 438 | 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] | 439 | delGemPortMsg.UniId, dh.DeviceID)) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 440 | } |
| 441 | uniID := uint8(delGemPortMsg.UniId) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 442 | tpID, err := cmn.GetTpIDFromTpPath(delGemPortMsg.TpInstancePath) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 443 | if err != nil { |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 444 | logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{"err": err, "tp-path": delGemPortMsg.TpInstancePath}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 445 | return err |
| 446 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 447 | logger.Infow(ctx, "delete-gem-port-request", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "gem": delGemPortMsg.GemPortId}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 448 | //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] | 449 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 450 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delGemPortMsg.TpInstancePath, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 451 | avcfg.CResourceGemPort, delGemPortMsg.GemPortId) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 452 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 453 | } |
| 454 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 455 | func (dh *deviceHandler) handleDeleteTcontRequest(ctx context.Context, delTcontMsg *ic.DeleteTcontMessage) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 456 | logger.Infow(ctx, "delete-tcont-request", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 457 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 458 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 459 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 460 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 461 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 462 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 463 | if dh.pOnuTP == nil { |
| 464 | //should normally not happen ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 465 | 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] | 466 | log.Fields{"device-id": dh.DeviceID}) |
| 467 | 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] | 468 | } |
| 469 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 470 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 471 | dh.pOnuTP.LockTpProcMutex() |
| 472 | defer dh.pOnuTP.UnlockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 473 | |
| 474 | if delTcontMsg.UniId > 255 { |
| 475 | 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] | 476 | delTcontMsg.UniId, dh.DeviceID)) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 477 | } |
| 478 | uniID := uint8(delTcontMsg.UniId) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 479 | tpPath := delTcontMsg.TpInstancePath |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 480 | tpID, err := cmn.GetTpIDFromTpPath(tpPath) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 481 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 482 | logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{"err": err, "tp-path": tpPath}) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 483 | return err |
| 484 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 485 | logger.Infow(ctx, "delete-tcont-request", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "tcont": delTcontMsg.AllocId}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 486 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 487 | pDevEntry.FreeTcont(ctx, uint16(delTcontMsg.AllocId)) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 488 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 489 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delTcontMsg.TpInstancePath, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 490 | avcfg.CResourceTcont, delTcontMsg.AllocId) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 491 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 492 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 493 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 494 | func (dh *deviceHandler) deleteTechProfileResource(ctx context.Context, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 495 | uniID uint8, tpID uint8, pathString string, resource avcfg.ResourceEntry, entryID uint32) error { |
| 496 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 497 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 498 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 499 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 500 | } |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 501 | var resourceName string |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 502 | if avcfg.CResourceGemPort == resource { |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 503 | resourceName = "Gem" |
| 504 | } else { |
| 505 | resourceName = "Tcont" |
| 506 | } |
| 507 | |
| 508 | // deadline context to ensure completion of background routines waited for |
| 509 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 510 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 511 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 512 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 513 | |
| 514 | var wg sync.WaitGroup |
| 515 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 516 | go dh.pOnuTP.DeleteTpResource(log.WithSpanFromContext(dctx, ctx), uniID, tpID, pathString, |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 517 | resource, entryID, &wg) |
| 518 | 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] | 519 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); err != nil { |
| 520 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 521 | return err |
| 522 | } |
| 523 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 524 | if dh.pOnuTP.IsTechProfileConfigCleared(ctx, uniID, tpID) { |
| 525 | logger.Debugw(ctx, "techProfile-config-cleared", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID}) |
| 526 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, tpID, ""); bTpModify { |
| 527 | pDevEntry.ResetKvProcessingErrorIndication() |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 528 | var wg2 sync.WaitGroup |
| 529 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
| 530 | wg2.Add(1) |
| 531 | // Removal of the gem id mapping represents the removal of the tech profile |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 532 | logger.Infow(ctx, "remove-techProfile-indication-in-kv", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID}) |
| 533 | go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg2) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 534 | 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] | 535 | if err := pDevEntry.GetKvProcessingErrorIndication(); err != nil { |
| 536 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 537 | return err |
| 538 | } |
| 539 | } |
| 540 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 541 | 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] | 542 | "uni-id": uniID, "tpID": tpID, "resource-type": resourceName, "resource-id": entryID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 543 | return nil |
| 544 | } |
| 545 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 546 | //FlowUpdateIncremental removes and/or adds the flow changes on a given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 547 | func (dh *deviceHandler) FlowUpdateIncremental(ctx context.Context, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 548 | apOfFlowChanges *of.FlowChanges, |
| 549 | apOfGroupChanges *of.FlowGroupChanges, apFlowMetaData *voltha.FlowMetadata) error { |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 550 | logger.Debugw(ctx, "FlowUpdateIncremental started", log.Fields{"device-id": dh.DeviceID, "flow": apOfFlowChanges, "metadata": apFlowMetaData}) |
| 551 | var errorsList []error |
| 552 | var retError error |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 553 | //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] | 554 | if apOfFlowChanges.ToRemove != nil { |
| 555 | for _, flowItem := range apOfFlowChanges.ToRemove.Items { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 556 | if flowItem.GetCookie() == 0 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 557 | 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] | 558 | "device-id": dh.DeviceID}) |
| 559 | retError = fmt.Errorf("flow-remove no cookie, device-id %s", dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 560 | errorsList = append(errorsList, retError) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 561 | continue |
| 562 | } |
| 563 | flowInPort := flow.GetInPort(flowItem) |
| 564 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 565 | logger.Warnw(ctx, "flow-remove inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 566 | retError = fmt.Errorf("flow-remove inPort invalid, device-id %s", dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 567 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 568 | continue |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 569 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 570 | } else if flowInPort == dh.ponPortNumber { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 571 | //this is some downstream flow, not regarded as error, just ignored |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 572 | 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] | 573 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 574 | continue |
| 575 | } else { |
| 576 | // this is the relevant upstream flow |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 577 | var loUniPort *cmn.OnuUniPort |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 578 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 579 | loUniPort = uniPort |
| 580 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 581 | 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] | 582 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 583 | 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] | 584 | flowInPort, dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 585 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 586 | continue |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 587 | } |
| 588 | flowOutPort := flow.GetOutPort(flowItem) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 589 | logger.Debugw(ctx, "flow-remove port indications", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 590 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 591 | "uniPortName": loUniPort.Name}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 592 | |
| 593 | if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) { |
| 594 | // Step1 : Fill flowControlBlock |
| 595 | // Step2 : Push the flowControlBlock to ONU channel |
| 596 | // Step3 : Wait on response channel for response |
| 597 | // Step4 : Return error value |
| 598 | startTime := time.Now() |
| 599 | respChan := make(chan error) |
| 600 | flowCb := FlowCb{ |
| 601 | ctx: ctx, |
| 602 | addFlow: false, |
| 603 | flowItem: flowItem, |
| 604 | flowMetaData: nil, |
| 605 | uniPort: loUniPort, |
| 606 | respChan: &respChan, |
| 607 | } |
| 608 | dh.flowCbChan[loUniPort.UniID] <- flowCb |
| 609 | logger.Infow(ctx, "process-flow-remove-start", log.Fields{"device-id": dh.DeviceID}) |
| 610 | // Wait on the channel for flow handlers return value |
| 611 | retError = <-respChan |
| 612 | logger.Infow(ctx, "process-flow-remove-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| 613 | if retError != nil { |
| 614 | logger.Warnw(ctx, "flow-delete processing error: continuing on checking further flows", |
| 615 | log.Fields{"device-id": dh.DeviceID, "error": retError}) |
| 616 | errorsList = append(errorsList, retError) |
| 617 | continue |
| 618 | } |
| 619 | } else { |
| 620 | retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID) |
| 621 | errorsList = append(errorsList, retError) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | } |
| 625 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 626 | if apOfFlowChanges.ToAdd != nil { |
| 627 | for _, flowItem := range apOfFlowChanges.ToAdd.Items { |
| 628 | if flowItem.GetCookie() == 0 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 629 | 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] | 630 | "device-id": dh.DeviceID}) |
| 631 | retError = fmt.Errorf("flow-add no cookie, device-id %s", dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 632 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 633 | continue |
| 634 | } |
| 635 | flowInPort := flow.GetInPort(flowItem) |
| 636 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 637 | logger.Warnw(ctx, "flow-add inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 638 | retError = fmt.Errorf("flow-add inPort invalid, device-id %s", dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 639 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 640 | continue |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 641 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 642 | } else if flowInPort == dh.ponPortNumber { |
| 643 | //this is some downstream flow |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 644 | 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] | 645 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 646 | continue |
| 647 | } else { |
| 648 | // this is the relevant upstream flow |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 649 | var loUniPort *cmn.OnuUniPort |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 650 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 651 | loUniPort = uniPort |
| 652 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 653 | 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] | 654 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 655 | 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] | 656 | flowInPort, dh.DeviceID) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 657 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 658 | continue |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 659 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 660 | // let's still assume that we receive the flow-add only in some 'active' device state (as so far observed) |
| 661 | // if not, we just throw some error here to have an indication about that, if we really need to support that |
| 662 | // then we would need to create some means to activate the internal stored flows |
| 663 | // after the device gets active automatically (and still with its dependency to the TechProfile) |
| 664 | // for state checking compare also code here: processInterAdapterTechProfileDownloadReqMessage |
| 665 | // also abort for the other still possible flows here |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 666 | if !dh.IsReadyForOmciConfig() { |
| 667 | logger.Errorw(ctx, "flow-add rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 668 | "last device-reason": dh.GetDeviceReasonString()}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 669 | retError = fmt.Errorf("improper device state on device %s", dh.DeviceID) |
| 670 | errorsList = append(errorsList, retError) |
| 671 | continue |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 672 | } |
| 673 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 674 | flowOutPort := flow.GetOutPort(flowItem) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 675 | logger.Debugw(ctx, "flow-add port indications", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 676 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 677 | "uniPortName": loUniPort.Name}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 678 | if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) { |
| 679 | // Step1 : Fill flowControlBlock |
| 680 | // Step2 : Push the flowControlBlock to ONU channel |
| 681 | // Step3 : Wait on response channel for response |
| 682 | // Step4 : Return error value |
| 683 | startTime := time.Now() |
| 684 | respChan := make(chan error) |
| 685 | flowCb := FlowCb{ |
| 686 | ctx: ctx, |
| 687 | addFlow: true, |
| 688 | flowItem: flowItem, |
| 689 | flowMetaData: apFlowMetaData, |
| 690 | uniPort: loUniPort, |
| 691 | respChan: &respChan, |
| 692 | } |
| 693 | dh.flowCbChan[loUniPort.UniID] <- flowCb |
| 694 | logger.Infow(ctx, "process-flow-add-start", log.Fields{"device-id": dh.DeviceID}) |
| 695 | // Wait on the channel for flow handlers return value |
| 696 | retError = <-respChan |
| 697 | logger.Infow(ctx, "process-flow-add-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| 698 | if retError != nil { |
| 699 | logger.Warnw(ctx, "flow-add processing error: continuing on checking further flows", |
| 700 | log.Fields{"device-id": dh.DeviceID, "error": retError}) |
| 701 | errorsList = append(errorsList, retError) |
| 702 | continue |
| 703 | } |
| 704 | } else { |
| 705 | retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID) |
| 706 | errorsList = append(errorsList, retError) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | } |
| 710 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 711 | if len(errorsList) > 0 { |
| 712 | logger.Errorw(ctx, "error-processing-flow", log.Fields{"device-id": dh.DeviceID, "errList": errorsList}) |
| 713 | return fmt.Errorf("errors-installing-one-or-more-flows-groups, errors:%v", errorsList) |
| 714 | } |
| 715 | return nil |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 718 | //disableDevice locks the ONU and its UNI/VEIP ports (admin lock via OMCI) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 719 | //following are the expected device states after this activity: |
| 720 | //Device Admin-State : down (on rwCore), Port-State: UNKNOWN, Conn-State: REACHABLE, Reason: omci-admin-lock |
| 721 | // (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] | 722 | func (dh *deviceHandler) disableDevice(ctx context.Context, device *voltha.Device) { |
| 723 | logger.Debugw(ctx, "disable-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 724 | |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 725 | //admin-lock reason can also be used uniquely for setting the DeviceState accordingly |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 726 | //note that disableDevice sequences in some 'ONU active' state may yield also |
| 727 | // "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] | 728 | // - inblock state checking to prevent possibly unneeded processing (on command repitition) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 729 | if dh.getDeviceReason() != cmn.DrOmciAdminLock { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 730 | //disable-device shall be just a UNi/ONU-G related admin state setting |
| 731 | //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] | 732 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 733 | if dh.IsReadyForOmciConfig() { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 734 | // disable UNI ports/ONU |
| 735 | // *** should generate UniDisableStateDone event - used to disable the port(s) on success |
| 736 | if dh.pLockStateFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 737 | dh.createUniLockFsm(ctx, true, cmn.UniDisableStateDone) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 738 | } else { //LockStateFSM already init |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 739 | dh.pLockStateFsm.SetSuccessEvent(cmn.UniDisableStateDone) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 740 | dh.runUniLockFsm(ctx, true) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 741 | } |
| 742 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 743 | logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 744 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 745 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 746 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 747 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 748 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 749 | }); err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 750 | //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] | 751 | 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] | 752 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 753 | // 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] | 754 | |
| 755 | //TODO with VOL-3045/VOL-3046: catch and return error, valid for all occurrences in the codebase |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 756 | _ = dh.deviceReasonUpdate(ctx, cmn.DrOmciAdminLock, true) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 757 | } |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 761 | //reEnableDevice unlocks the ONU and its UNI/VEIP ports (admin unlock via OMCI) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 762 | func (dh *deviceHandler) reEnableDevice(ctx context.Context, device *voltha.Device) { |
| 763 | 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] | 764 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 765 | //setting readyForOmciConfig here is just a workaround for BBSIM testing in the sequence |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 766 | // OnuSoftReboot-disable-enable, because BBSIM does not generate a new OnuIndication-Up event after SoftReboot |
| 767 | // which is the assumption for real ONU's, where the ready-state is then set according to the following MibUpload/Download |
| 768 | // for real ONU's that should have nearly no influence |
| 769 | // Note that for real ONU's there is anyway a problematic situation with following sequence: |
| 770 | // OnuIndication-Dw (or not active at all) (- disable) - enable: here already the LockFsm may run into timeout (no OmciResponse) |
| 771 | // but that anyway is hopefully resolved by some OnuIndication-Up event (maybe to be tested) |
| 772 | // 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] | 773 | dh.SetReadyForOmciConfig(true) //needed to allow subsequent flow/techProf config (on BBSIM) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 774 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 775 | // enable ONU/UNI ports |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 776 | // *** should generate cmn.UniEnableStateDone event - used to disable the port(s) on success |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 777 | if dh.pUnlockStateFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 778 | dh.createUniLockFsm(ctx, false, cmn.UniEnableStateDone) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 779 | } else { //UnlockStateFSM already init |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 780 | dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniEnableStateDone) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 781 | dh.runUniLockFsm(ctx, false) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 782 | } |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 783 | } |
| 784 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 785 | func (dh *deviceHandler) reconcileDeviceOnuInd(ctx context.Context) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 786 | 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] | 787 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 788 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 789 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 790 | 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] | 791 | return |
| 792 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 793 | if err := pDevEntry.RestoreDataFromOnuKvStore(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 794 | if err == fmt.Errorf("no-ONU-data-found") { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 795 | 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] | 796 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 797 | 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] | 798 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 799 | dh.StopReconciling(ctx, false) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 800 | return |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 801 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 802 | var onuIndication oop.OnuIndication |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 803 | pDevEntry.MutexPersOnuConfig.RLock() |
| 804 | onuIndication.IntfId = pDevEntry.SOnuPersistentData.PersIntfID |
| 805 | onuIndication.OnuId = pDevEntry.SOnuPersistentData.PersOnuID |
| 806 | onuIndication.OperState = pDevEntry.SOnuPersistentData.PersOperState |
| 807 | onuIndication.AdminState = pDevEntry.SOnuPersistentData.PersAdminState |
| 808 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 809 | _ = dh.createInterface(ctx, &onuIndication) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 812 | func (dh *deviceHandler) ReconcileDeviceTechProf(ctx context.Context) { |
| 813 | 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] | 814 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 815 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 816 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 817 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 818 | if !dh.IsSkipOnuConfigReconciling() { |
| 819 | dh.StopReconciling(ctx, false) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 820 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 821 | return |
| 822 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 823 | dh.pOnuTP.LockTpProcMutex() |
| 824 | defer dh.pOnuTP.UnlockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 825 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 826 | pDevEntry.MutexPersOnuConfig.RLock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 827 | persMutexLock := true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 828 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 829 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 830 | 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] | 831 | log.Fields{"device-id": dh.DeviceID}) |
| 832 | if !dh.IsSkipOnuConfigReconciling() { |
| 833 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 834 | } |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 835 | return |
| 836 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 837 | flowsFound := false |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 838 | techProfsFound := false |
| 839 | techProfInstLoadFailed := false |
| 840 | outerLoop: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 841 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 842 | //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support |
| 843 | if len(uniData.PersTpPathMap) == 0 { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 844 | logger.Debugw(ctx, "reconciling - no TPs stored for uniID", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 845 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 846 | continue |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 847 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 848 | //release MutexPersOnuConfig before TechProfile (ANIConfig) processing as otherwise the reception of |
| 849 | // 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] | 850 | // 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] | 851 | pDevEntry.MutexPersOnuConfig.RUnlock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 852 | persMutexLock = false |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 853 | techProfsFound = true // set to true if we found TP once for any UNI port |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 854 | for tpID := range uniData.PersTpPathMap { |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 855 | // Request the TpInstance again from the openolt adapter in case of reconcile |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 856 | iaTechTpInst, err := dh.getTechProfileInstanceFromParentAdapter(ctx, |
| 857 | dh.device.ProxyAddress.AdapterEndpoint, |
| 858 | &ic.TechProfileInstanceRequestMessage{ |
| 859 | DeviceId: dh.device.Id, |
| 860 | TpInstancePath: uniData.PersTpPathMap[tpID], |
| 861 | ParentDeviceId: dh.parentID, |
| 862 | ParentPonPort: dh.device.ParentPortNo, |
| 863 | OnuId: dh.device.ProxyAddress.OnuId, |
| 864 | UniId: uint32(uniData.PersUniID), |
| 865 | }) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 866 | if err != nil || iaTechTpInst == nil { |
| 867 | logger.Errorw(ctx, "error fetching tp instance", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 868 | log.Fields{"tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID, "err": err}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 869 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 870 | break outerLoop |
| 871 | } |
| 872 | var tpInst tech_profile.TechProfileInstance |
| 873 | switch techTpInst := iaTechTpInst.TechTpInstance.(type) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 874 | case *ic.TechProfileDownloadMessage_TpInstance: // supports only GPON, XGPON, XGS-PON |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 875 | tpInst = *techTpInst.TpInstance |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 876 | logger.Debugw(ctx, "received-tp-instance-successfully-after-reconcile", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 877 | "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] | 878 | default: // do not support epon or other tech |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 879 | logger.Errorw(ctx, "unsupported-tech-profile", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 880 | "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] | 881 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 882 | break outerLoop |
| 883 | } |
| 884 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 885 | // deadline context to ensure completion of background routines waited for |
| 886 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 887 | 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] | 888 | dctx, cancel := context.WithDeadline(ctx, deadline) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 889 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 890 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniData.PersUniID, tpID) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 891 | var wg sync.WaitGroup |
| 892 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 893 | 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] | 894 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfReconcile") //wait for background process to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 895 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniData.PersUniID, tpID); err != nil { |
| 896 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 897 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 898 | break outerLoop |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 899 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 900 | } // for all TpPath entries for this UNI |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 901 | if len(uniData.PersFlowParams) != 0 { |
| 902 | flowsFound = true |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 903 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 904 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 905 | persMutexLock = true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 906 | } // for all UNI entries from SOnuPersistentData |
| 907 | if persMutexLock { // if loop was left with MutexPersOnuConfig still set |
| 908 | pDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 909 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 910 | |
| 911 | //had to move techProf/flow result evaluation into separate function due to SCA complexity limit |
| 912 | dh.updateReconcileStates(ctx, techProfsFound, techProfInstLoadFailed, flowsFound) |
| 913 | } |
| 914 | |
| 915 | func (dh *deviceHandler) updateReconcileStates(ctx context.Context, |
| 916 | abTechProfsFound bool, abTechProfInstLoadFailed bool, abFlowsFound bool) { |
| 917 | if !abTechProfsFound { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 918 | 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] | 919 | log.Fields{"device-id": dh.DeviceID}) |
| 920 | if !dh.IsSkipOnuConfigReconciling() { |
| 921 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 922 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 923 | return |
| 924 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 925 | if abTechProfInstLoadFailed { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 926 | dh.SetDeviceReason(cmn.DrTechProfileConfigDownloadFailed) |
| 927 | dh.StopReconciling(ctx, false) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 928 | return |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 929 | } else if dh.IsSkipOnuConfigReconciling() { |
| 930 | dh.SetDeviceReason(cmn.DrTechProfileConfigDownloadSuccess) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 931 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 932 | if !abFlowsFound { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 933 | 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] | 934 | log.Fields{"device-id": dh.DeviceID}) |
| 935 | if !dh.IsSkipOnuConfigReconciling() { |
| 936 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 937 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 938 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 939 | } |
| 940 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 941 | func (dh *deviceHandler) ReconcileDeviceFlowConfig(ctx context.Context) { |
| 942 | 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] | 943 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 944 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 945 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 946 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 947 | if !dh.IsSkipOnuConfigReconciling() { |
| 948 | dh.StopReconciling(ctx, false) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 949 | } |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 950 | return |
| 951 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 952 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 953 | pDevEntry.MutexPersOnuConfig.RLock() |
| 954 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 955 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 956 | 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] | 957 | log.Fields{"device-id": dh.DeviceID}) |
| 958 | if !dh.IsSkipOnuConfigReconciling() { |
| 959 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 960 | } |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 961 | return |
| 962 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 963 | flowsFound := false |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 964 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 965 | //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support |
| 966 | if len(uniData.PersFlowParams) == 0 { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 967 | logger.Debugw(ctx, "reconciling - no flows stored for uniID", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 968 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 969 | continue |
| 970 | } |
| 971 | if len(uniData.PersTpPathMap) == 0 { |
| 972 | logger.Warnw(ctx, "reconciling - flows but no TPs stored for uniID", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 973 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 974 | // It doesn't make sense to configure any flows if no TPs are available |
| 975 | continue |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 976 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 977 | //release MutexPersOnuConfig before VlanConfig processing as otherwise the reception of |
| 978 | // 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] | 979 | // 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] | 980 | pDevEntry.MutexPersOnuConfig.RUnlock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 981 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 982 | var uniPort *cmn.OnuUniPort |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 983 | var exist bool |
Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 984 | 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] | 985 | if uniPort, exist = dh.uniEntityMap[uniNo]; !exist { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 986 | logger.Errorw(ctx, "reconciling - OnuUniPort data not found - terminate reconcilement", |
| 987 | log.Fields{"uniNo": uniNo, "device-id": dh.DeviceID}) |
| 988 | if !dh.IsSkipOnuConfigReconciling() { |
| 989 | dh.StopReconciling(ctx, false) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 990 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 991 | return |
| 992 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 993 | flowsFound = true |
Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 994 | lastFlowToReconcile := false |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 995 | flowsProcessed := 0 |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 996 | pDevEntry.SetReconcilingFlows(true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 997 | for _, flowData := range uniData.PersFlowParams { |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 998 | logger.Debugw(ctx, "reconciling - add flow with cookie slice", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 999 | "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, "cookies": flowData.CookieSlice}) |
Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 1000 | if flowsProcessed == len(uniData.PersFlowParams)-1 { |
| 1001 | lastFlowToReconcile = true |
| 1002 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1003 | //the slice can be passed 'by value' here, - which internally passes its reference copy |
mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 1004 | dh.lockVlanConfig.Lock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1005 | if _, exist = dh.UniVlanConfigFsmMap[uniData.PersUniID]; exist { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1006 | if err := dh.UniVlanConfigFsmMap[uniData.PersUniID].SetUniFlowParams(ctx, flowData.VlanRuleParams.TpID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1007 | flowData.CookieSlice, uint16(flowData.VlanRuleParams.MatchVid), uint16(flowData.VlanRuleParams.SetVid), |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1008 | uint8(flowData.VlanRuleParams.SetPcp), lastFlowToReconcile, flowData.Meter, nil); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1009 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1010 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1011 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1012 | if err := dh.createVlanFilterFsm(ctx, uniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1013 | uint16(flowData.VlanRuleParams.MatchVid), uint16(flowData.VlanRuleParams.SetVid), |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1014 | uint8(flowData.VlanRuleParams.SetPcp), cmn.OmciVlanFilterAddDone, lastFlowToReconcile, flowData.Meter, nil); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1015 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1016 | } |
| 1017 | } |
mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 1018 | dh.lockVlanConfig.Unlock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1019 | flowsProcessed++ |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1020 | } //for all flows of this UNI |
| 1021 | logger.Debugw(ctx, "reconciling - flows processed", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1022 | "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, "flowsProcessed": flowsProcessed, |
| 1023 | "NumUniFlows": dh.UniVlanConfigFsmMap[uniData.PersUniID].NumUniFlows, |
| 1024 | "ConfiguredUniFlow": dh.UniVlanConfigFsmMap[uniData.PersUniID].ConfiguredUniFlow}) |
Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 1025 | // this can't be used as global finished reconciling flag because |
| 1026 | // assumes is getting called before the state machines for the last flow is completed, |
| 1027 | // while this is not guaranteed. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1028 | //dh.SetReconcilingFlows(false) |
| 1029 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| 1030 | } // for all UNI entries from SOnuPersistentData |
| 1031 | pDevEntry.MutexPersOnuConfig.RUnlock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 1032 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1033 | if !flowsFound { |
| 1034 | 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] | 1035 | log.Fields{"device-id": dh.DeviceID}) |
| 1036 | if !dh.IsSkipOnuConfigReconciling() { |
| 1037 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 1038 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1039 | return |
| 1040 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1041 | if dh.IsSkipOnuConfigReconciling() { |
| 1042 | dh.SetDeviceReason(cmn.DrOmciFlowsPushed) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1043 | } |
| 1044 | } |
| 1045 | |
Holger Hildebrandt | 1b8f4ad | 2021-03-25 15:53:51 +0000 | [diff] [blame] | 1046 | func (dh *deviceHandler) reconcileEnd(ctx context.Context) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1047 | logger.Debugw(ctx, "reconciling - completed!", log.Fields{"device-id": dh.DeviceID}) |
| 1048 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1051 | func (dh *deviceHandler) deleteDevicePersistencyData(ctx context.Context) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1052 | 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] | 1053 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1054 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1055 | if pDevEntry == nil { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1056 | //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] | 1057 | 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] | 1058 | return nil |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1059 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1060 | |
| 1061 | // deadline context to ensure completion of background routines waited for |
| 1062 | //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] | 1063 | 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] | 1064 | dctx, cancel := context.WithDeadline(ctx, deadline) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1065 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1066 | pDevEntry.ResetKvProcessingErrorIndication() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1067 | |
| 1068 | var wg sync.WaitGroup |
| 1069 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1070 | go pDevEntry.DeleteDataFromOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1071 | dh.waitForCompletion(ctx, cancel, &wg, "DeleteDevice") //wait for background process to finish |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1072 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1073 | // TODO: further actions - stop metrics and FSMs, remove device ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1074 | return pDevEntry.GetKvProcessingErrorIndication() |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1077 | //func (dh *deviceHandler) rebootDevice(ctx context.Context, device *voltha.Device) error { |
| 1078 | // before this change here return like this was used: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1079 | // return fmt.Errorf("device-unreachable: %s, %s", dh.DeviceID, device.SerialNumber) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1080 | //was and is called in background - error return does not make sense |
| 1081 | func (dh *deviceHandler) rebootDevice(ctx context.Context, aCheckDeviceState bool, device *voltha.Device) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1082 | 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] | 1083 | if aCheckDeviceState && device.ConnectStatus != voltha.ConnectStatus_REACHABLE { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1084 | 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] | 1085 | return |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1086 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1087 | if err := dh.pOnuOmciDevice.Reboot(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1088 | //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] | 1089 | 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] | 1090 | return |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1091 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1092 | |
| 1093 | //transfer the possibly modified logical uni port state |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1094 | dh.DisableUniPortStateUpdate(ctx) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1095 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1096 | logger.Debugw(ctx, "call DeviceStateUpdate upon reboot", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1097 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1098 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1099 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1100 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 1101 | OperStatus: voltha.OperStatus_DISCOVERED, |
| 1102 | }); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1103 | //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] | 1104 | 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] | 1105 | return |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1106 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1107 | if err := dh.deviceReasonUpdate(ctx, cmn.DrRebooting, true); err != nil { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1108 | return |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1109 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1110 | dh.SetReadyForOmciConfig(false) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1111 | //no specific activity to synchronize any internal FSM to the 'rebooted' state is explicitly done here |
| 1112 | // the expectation ids for a real device, that it will be synced with the expected following 'down' indication |
| 1113 | // as BBSIM does not support this testing requires explicite disable/enable device calls in which sequence also |
| 1114 | // all other FSM's should be synchronized again |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1115 | } |
| 1116 | |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 1117 | //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] | 1118 | // used only for old - R2.7 style - upgrade API |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1119 | func (dh *deviceHandler) doOnuSwUpgrade(ctx context.Context, apImageDsc *voltha.ImageDownload, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1120 | apDownloadManager *swupg.AdapterDownloadManager) error { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1121 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1122 | "device-id": dh.DeviceID, "image-name": (*apImageDsc).Name}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1123 | |
| 1124 | var err error |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1125 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1126 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1127 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1128 | 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] | 1129 | } |
| 1130 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1131 | if dh.IsReadyForOmciConfig() { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1132 | var inactiveImageID uint16 |
| 1133 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1134 | dh.lockUpgradeFsm.Lock() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1135 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| 1136 | // but must be still locked at calling createOnuUpgradeFsm |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1137 | if dh.pOnuUpradeFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1138 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1139 | dh.lockUpgradeFsm.Unlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1140 | if err == nil { |
| 1141 | if err = dh.pOnuUpradeFsm.SetDownloadParams(ctx, inactiveImageID, apImageDsc, apDownloadManager); err != nil { |
| 1142 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1143 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1144 | } |
| 1145 | } else { |
| 1146 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1147 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1148 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1149 | } else { //OnuSw upgrade already running - restart (with possible abort of running) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1150 | dh.lockUpgradeFsm.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1151 | 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] | 1152 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1153 | dh.upgradeCanceled = true |
| 1154 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1155 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1156 | //no effort spent anymore for the old API to automatically cancel and restart the download |
| 1157 | // like done for the new API |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1158 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1159 | } else { |
| 1160 | 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] | 1161 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1162 | } |
| 1163 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1164 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no active OMCI connection", log.Fields{"device-id": dh.DeviceID}) |
| 1165 | 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] | 1166 | } |
| 1167 | return err |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1170 | //onuSwUpgradeAfterDownload initiates the SW download transfer to the ONU with activate and commit options |
| 1171 | // after the OnuImage has been downloaded to the adapter, called in background |
| 1172 | func (dh *deviceHandler) onuSwUpgradeAfterDownload(ctx context.Context, apImageRequest *voltha.DeviceImageDownloadRequest, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1173 | apDownloadManager *swupg.FileDownloadManager, aImageIdentifier string) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1174 | |
| 1175 | var err error |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1176 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1177 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1178 | 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] | 1179 | return |
| 1180 | } |
| 1181 | |
| 1182 | var inactiveImageID uint16 |
| 1183 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1184 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1185 | "device-id": dh.DeviceID, "image-version": apImageRequest.Image.Version, "to onu-image": inactiveImageID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1186 | |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1187 | dh.lockUpgradeFsm.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1188 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1189 | // but must be still locked at calling createOnuUpgradeFsm |
| 1190 | // (and working with a local pointer copy does not work here if asynchronous request are done to fast |
| 1191 | // [e.g.leaving the local pointer on nil even though a creation is already on the way]) |
| 1192 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1193 | //OnuSw upgrade already running on this device (e.g. with activate/commit not yet set) |
| 1194 | // abort the current processing, running upgrades are always aborted by newer request |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1195 | 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] | 1196 | //flush the remove upgradeFsmChan channel |
| 1197 | select { |
| 1198 | case <-dh.upgradeFsmChan: |
| 1199 | logger.Debug(ctx, "flushed-upgrade-fsm-channel") |
| 1200 | default: |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1201 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1202 | dh.lockUpgradeFsm.Unlock() |
| 1203 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1204 | dh.upgradeCanceled = true |
| 1205 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1206 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1207 | select { |
| 1208 | case <-time.After(cTimeOutRemoveUpgrade * time.Second): |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1209 | 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] | 1210 | //should not appear, can't proceed with new upgrade, perhaps operator can retry manually later |
| 1211 | return |
| 1212 | case <-dh.upgradeFsmChan: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1213 | 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] | 1214 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1215 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1216 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1217 | |
| 1218 | //here it can be assumed that no running upgrade processing exists (anymore) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1219 | //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] | 1220 | // but none yet defined |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1221 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1222 | dh.lockUpgradeFsm.Unlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1223 | if err == nil { |
| 1224 | if err = dh.pOnuUpradeFsm.SetDownloadParamsAfterDownload(ctx, inactiveImageID, |
| 1225 | apImageRequest, apDownloadManager, aImageIdentifier); err != nil { |
| 1226 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1227 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1228 | return |
| 1229 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1230 | } else { |
| 1231 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1232 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1233 | } |
| 1234 | return |
| 1235 | } |
| 1236 | 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] | 1237 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | //onuSwActivateRequest ensures activation of the requested image with commit options |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1241 | func (dh *deviceHandler) onuSwActivateRequest(ctx context.Context, |
| 1242 | aVersion string, aCommitRequest bool) (*voltha.ImageState, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1243 | var err error |
| 1244 | //SW activation for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1245 | // 1.) activation of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1246 | // 2.) activation of the inactive image |
| 1247 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1248 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1249 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1250 | logger.Errorw(ctx, "Onu image activation rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1251 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1252 | } |
| 1253 | dh.lockUpgradeFsm.RLock() |
| 1254 | if dh.pOnuUpradeFsm != nil { |
| 1255 | dh.lockUpgradeFsm.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1256 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1257 | if getErr != nil || onuVolthaDevice == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1258 | logger.Errorw(ctx, "Failed to fetch Onu device for image activation", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1259 | 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] | 1260 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1261 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1262 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1263 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1264 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1265 | // use the OnuVendor identification from this device for the internal unique name |
| 1266 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1267 | // 1.) check a started upgrade process and relay the activation request to it |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1268 | if err = dh.pOnuUpradeFsm.SetActivationParamsRunning(ctx, imageIdentifier, aCommitRequest); err != nil { |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1269 | //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] | 1270 | 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] | 1271 | "device-id": dh.DeviceID, "error": err}) |
| 1272 | 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] | 1273 | } |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1274 | logger.Debugw(ctx, "image activation acknowledged by onu upgrade processing", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1275 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1276 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1277 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1278 | } //else |
| 1279 | dh.lockUpgradeFsm.RUnlock() |
| 1280 | |
| 1281 | // 2.) check if requested image-version equals the inactive one and start its activation |
| 1282 | // (image version is not [yet] checked - would be possible, but with increased effort ...) |
| 1283 | var inactiveImageID uint16 |
| 1284 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err != nil || inactiveImageID > 1 { |
| 1285 | logger.Errorw(ctx, "get inactive image failed", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1286 | "device-id": dh.DeviceID, "err": err, "image-id": inactiveImageID}) |
| 1287 | 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] | 1288 | } |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1289 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1290 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1291 | dh.lockUpgradeFsm.Unlock() |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1292 | if err == nil { |
| 1293 | if err = dh.pOnuUpradeFsm.SetActivationParamsStart(ctx, aVersion, |
| 1294 | inactiveImageID, aCommitRequest); err != nil { |
| 1295 | 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] | 1296 | "device-id": dh.DeviceID, "error": err}) |
| 1297 | 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] | 1298 | } |
| 1299 | logger.Debugw(ctx, "inactive image activation acknowledged by onu upgrade", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1300 | "device-id": dh.DeviceID, "image-version": aVersion}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1301 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1302 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1303 | } //else |
| 1304 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1305 | "device-id": dh.DeviceID, "error": err}) |
| 1306 | 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] | 1307 | } |
| 1308 | |
| 1309 | //onuSwCommitRequest ensures commitment of the requested image |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1310 | func (dh *deviceHandler) onuSwCommitRequest(ctx context.Context, |
| 1311 | aVersion string) (*voltha.ImageState, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1312 | var err error |
| 1313 | //SW commitment for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1314 | // 1.) commitment of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1315 | // 2.) commitment of the active image |
| 1316 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1317 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1318 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1319 | logger.Errorw(ctx, "Onu image commitment rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1320 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1321 | } |
| 1322 | dh.lockUpgradeFsm.RLock() |
| 1323 | if dh.pOnuUpradeFsm != nil { |
| 1324 | dh.lockUpgradeFsm.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1325 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1326 | if getErr != nil || onuVolthaDevice == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1327 | logger.Errorw(ctx, "Failed to fetch Onu device for image commitment", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1328 | 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] | 1329 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 1330 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1331 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1332 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1333 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1334 | // use the OnuVendor identification from this device for the internal unique name |
| 1335 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1336 | // 1.) check a started upgrade process and relay the commitment request to it |
| 1337 | // the running upgrade may be based either on the imageIdentifier (started from download) |
| 1338 | // or on the imageVersion (started from pure activation) |
| 1339 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsRunning(ctx, imageIdentifier, aVersion); err != nil { |
| 1340 | //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] | 1341 | 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] | 1342 | "device-id": dh.DeviceID, "error": err}) |
| 1343 | 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] | 1344 | } |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1345 | logger.Debugw(ctx, "image commitment acknowledged by onu upgrade processing", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1346 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1347 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1348 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1349 | } //else |
| 1350 | dh.lockUpgradeFsm.RUnlock() |
| 1351 | |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1352 | // 2.) use the active image to directly commit |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1353 | var activeImageID uint16 |
| 1354 | if activeImageID, err = pDevEntry.GetActiveImageMeID(ctx); err != nil || activeImageID > 1 { |
| 1355 | logger.Errorw(ctx, "get active image failed", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1356 | "device-id": dh.DeviceID, "err": err, "image-id": activeImageID}) |
| 1357 | 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] | 1358 | } |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1359 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1360 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1361 | dh.lockUpgradeFsm.Unlock() |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1362 | if err == nil { |
| 1363 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsStart(ctx, aVersion, activeImageID); err != nil { |
| 1364 | 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] | 1365 | "device-id": dh.DeviceID, "error": err}) |
| 1366 | 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] | 1367 | } |
| 1368 | logger.Debugw(ctx, "active image commitment acknowledged by onu upgrade", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1369 | "device-id": dh.DeviceID, "image-version": aVersion}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1370 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1371 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1372 | } //else |
| 1373 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1374 | "device-id": dh.DeviceID, "error": err}) |
| 1375 | 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] | 1376 | } |
| 1377 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1378 | func (dh *deviceHandler) requestOnuSwUpgradeState(ctx context.Context, aImageIdentifier string, |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1379 | aVersion string) *voltha.ImageState { |
| 1380 | var pImageState *voltha.ImageState |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1381 | dh.lockUpgradeFsm.RLock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1382 | defer dh.lockUpgradeFsm.RUnlock() |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1383 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1384 | pImageState = dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1385 | } else { //use the last stored ImageState (if the requested Imageversion coincides) |
| 1386 | if aVersion == dh.pLastUpgradeImageState.Version { |
| 1387 | pImageState = dh.pLastUpgradeImageState |
| 1388 | } else { //state request for an image version different from last processed image version |
| 1389 | pImageState = &voltha.ImageState{ |
| 1390 | Version: aVersion, |
| 1391 | //we cannot state something concerning this version |
| 1392 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 1393 | Reason: voltha.ImageState_NO_ERROR, |
| 1394 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 1395 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1396 | } |
| 1397 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1398 | return pImageState |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | func (dh *deviceHandler) cancelOnuSwUpgrade(ctx context.Context, aImageIdentifier string, |
| 1402 | aVersion string, pDeviceImageState *voltha.DeviceImageState) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1403 | pDeviceImageState.DeviceId = dh.DeviceID |
mpagenko | 7455fd4 | 2021-06-10 16:25:55 +0000 | [diff] [blame] | 1404 | pDeviceImageState.ImageState.Version = aVersion |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1405 | dh.lockUpgradeFsm.RLock() |
| 1406 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1407 | dh.lockUpgradeFsm.RUnlock() |
| 1408 | // so then we cancel the upgrade operation |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 1409 | // but before we still request the actual upgrade states for the direct response |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1410 | pImageState := dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1411 | pDeviceImageState.ImageState.DownloadState = pImageState.DownloadState |
| 1412 | pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST |
| 1413 | pDeviceImageState.ImageState.ImageState = pImageState.ImageState |
| 1414 | if pImageState.DownloadState != voltha.ImageState_DOWNLOAD_UNKNOWN { |
| 1415 | //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] | 1416 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1417 | dh.upgradeCanceled = true |
| 1418 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1419 | } |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1420 | } //nothing to cancel (upgrade FSM for different image stays alive) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1421 | } else { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1422 | dh.lockUpgradeFsm.RUnlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1423 | // if no upgrade is ongoing, nothing is canceled and accordingly the states of the requested image are unknown |
| 1424 | // reset also the dh handler LastUpgradeImageState (not relevant anymore/cleared) |
| 1425 | (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1426 | (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR |
| 1427 | (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1428 | (*dh.pLastUpgradeImageState).Version = "" //reset to 'no (relevant) upgrade done' (like initial state) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1429 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1430 | pDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1431 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1432 | //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] | 1433 | } |
| 1434 | } |
| 1435 | |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1436 | func (dh *deviceHandler) getOnuImages(ctx context.Context) (*voltha.OnuImages, error) { |
| 1437 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1438 | var onuImageStatus *swupg.OnuImageStatus |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1439 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1440 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1441 | if pDevEntry != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1442 | onuImageStatus = swupg.NewOnuImageStatus(dh, pDevEntry) |
| 1443 | pDevEntry.MutexOnuImageStatus.Lock() |
| 1444 | pDevEntry.POnuImageStatus = onuImageStatus |
| 1445 | pDevEntry.MutexOnuImageStatus.Unlock() |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1446 | |
| 1447 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1448 | 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] | 1449 | return nil, fmt.Errorf("no-valid-OnuDevice-aborting") |
| 1450 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1451 | images, err := onuImageStatus.GetOnuImageStatus(ctx) |
| 1452 | pDevEntry.MutexOnuImageStatus.Lock() |
| 1453 | pDevEntry.POnuImageStatus = nil |
| 1454 | pDevEntry.MutexOnuImageStatus.Unlock() |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1455 | return images, err |
| 1456 | } |
| 1457 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1458 | // deviceHandler methods that implement the adapters interface requests## end ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1459 | // ##################################################################################### |
| 1460 | |
| 1461 | // ################ to be updated acc. needs of ONU Device ######################## |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1462 | // deviceHandler StateMachine related state transition methods ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1463 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1464 | func (dh *deviceHandler) logStateChange(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1465 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"event name": string(e.Event), "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] | 1466 | } |
| 1467 | |
| 1468 | // doStateInit provides the device update to the core |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1469 | func (dh *deviceHandler) doStateInit(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1470 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1471 | logger.Debug(ctx, "doStateInit-started") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1472 | var err error |
| 1473 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1474 | // populate what we know. rest comes later after mib sync |
| 1475 | dh.device.Root = false |
| 1476 | dh.device.Vendor = "OpenONU" |
| 1477 | dh.device.Model = "go" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1478 | dh.device.Reason = cmn.DeviceReasonMap[cmn.DrActivatingOnu] |
| 1479 | dh.SetDeviceReason(cmn.DrActivatingOnu) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1480 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1481 | dh.logicalDeviceID = dh.DeviceID // really needed - what for ??? //TODO!!! |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1482 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1483 | if !dh.IsReconciling() { |
| 1484 | 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] | 1485 | if err := dh.updateDeviceInCore(ctx, dh.device); err != nil { |
| 1486 | logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err}) |
| 1487 | } |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 1488 | //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] | 1489 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1490 | logger.Debugw(ctx, "reconciling - don't notify core about DeviceUpdate", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1491 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1492 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1493 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1494 | dh.parentID = dh.device.ParentId |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1495 | dh.ponPortNumber = dh.device.ParentPortNo |
| 1496 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1497 | // store proxy parameters for later communication - assumption: invariant, else they have to be requested dynamically!! |
| 1498 | dh.ProxyAddressID = dh.device.ProxyAddress.GetDeviceId() |
| 1499 | dh.ProxyAddressType = dh.device.ProxyAddress.GetDeviceType() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1500 | 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] | 1501 | "proxyAddressType": dh.ProxyAddressType, "SNR": dh.device.SerialNumber, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1502 | "ParentId": dh.parentID, "ParentPortNo": dh.ponPortNumber}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1503 | |
| 1504 | /* |
| 1505 | self._pon = PonPort.create(self, self._pon_port_number) |
| 1506 | self._pon.add_peer(self.parent_id, self._pon_port_number) |
| 1507 | self.logger.debug('adding-pon-port-to-agent', |
| 1508 | type=self._pon.get_port().type, |
| 1509 | admin_state=self._pon.get_port().admin_state, |
| 1510 | oper_status=self._pon.get_port().oper_status, |
| 1511 | ) |
| 1512 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1513 | if !dh.IsReconciling() { |
| 1514 | 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] | 1515 | var ponPortNo uint32 = 1 |
| 1516 | if dh.ponPortNumber != 0 { |
| 1517 | ponPortNo = dh.ponPortNumber |
| 1518 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1519 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1520 | pPonPort := &voltha.Port{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1521 | DeviceId: dh.DeviceID, |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1522 | PortNo: ponPortNo, |
| 1523 | Label: fmt.Sprintf("pon-%d", ponPortNo), |
| 1524 | Type: voltha.Port_PON_ONU, |
| 1525 | OperStatus: voltha.OperStatus_ACTIVE, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1526 | Peers: []*voltha.Port_PeerPort{{DeviceId: dh.parentID, // Peer device is OLT |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1527 | PortNo: ponPortNo}}, // Peer port is parent's port number |
| 1528 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1529 | if err = dh.CreatePortInCore(ctx, pPonPort); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1530 | logger.Fatalf(ctx, "Device FSM: PortCreated-failed-%s", err) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1531 | e.Cancel(err) |
| 1532 | return |
| 1533 | } |
| 1534 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1535 | 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] | 1536 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1537 | logger.Debug(ctx, "doStateInit-done") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | // postInit setups the DeviceEntry for the conerned device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1541 | func (dh *deviceHandler) postInit(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1542 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1543 | logger.Debug(ctx, "postInit-started") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1544 | var err error |
| 1545 | /* |
| 1546 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
| 1547 | dh.pTransitionMap.Handle(ctx, GrpcConnected) |
| 1548 | return nil |
| 1549 | */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1550 | if err = dh.addOnuDeviceEntry(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| 1551 | logger.Fatalf(ctx, "Device FSM: addOnuDeviceEntry-failed-%s", err) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1552 | e.Cancel(err) |
| 1553 | return |
| 1554 | } |
| 1555 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1556 | if dh.IsReconciling() { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1557 | go dh.reconcileDeviceOnuInd(ctx) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1558 | // reconcilement will be continued after mib download is done |
| 1559 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1560 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1561 | /* |
| 1562 | ############################################################################ |
| 1563 | # Setup Alarm handler |
| 1564 | self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id, |
| 1565 | device.serial_number) |
| 1566 | ############################################################################ |
| 1567 | # Setup PM configuration for this device |
| 1568 | # Pass in ONU specific options |
| 1569 | kwargs = { |
| 1570 | OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY, |
| 1571 | 'heartbeat': self.heartbeat, |
| 1572 | OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device |
| 1573 | } |
| 1574 | self.logger.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number) |
| 1575 | self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id, |
| 1576 | self.logical_device_id, device.serial_number, |
| 1577 | grouped=True, freq_override=False, **kwargs) |
| 1578 | pm_config = self._pm_metrics.make_proto() |
| 1579 | self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm) |
| 1580 | self.logger.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number) |
| 1581 | yield self.core_proxy.device_pm_config_update(pm_config, init=True) |
| 1582 | |
| 1583 | # Note, ONU ID and UNI intf set in add_uni_port method |
| 1584 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events, |
| 1585 | ani_ports=[self._pon]) |
| 1586 | |
| 1587 | # Code to Run OMCI Test Action |
| 1588 | kwargs_omci_test_action = { |
| 1589 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 1590 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 1591 | } |
| 1592 | serial_number = device.serial_number |
| 1593 | self._test_request = OmciTestRequest(self.core_proxy, |
| 1594 | self.omci_agent, self.device_id, |
| 1595 | AniG, serial_number, |
| 1596 | self.logical_device_id, |
| 1597 | exclusive=False, |
| 1598 | **kwargs_omci_test_action) |
| 1599 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1600 | self.Enabled = True |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1601 | else: |
| 1602 | self.logger.info('onu-already-activated') |
| 1603 | */ |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1604 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1605 | logger.Debug(ctx, "postInit-done") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | // doStateConnected get the device info and update to voltha core |
| 1609 | // for comparison of the original method (not that easy to uncomment): compare here: |
| 1610 | // voltha-openolt-adapter/adaptercore/device_handler.go |
| 1611 | // -> this one obviously initiates all communication interfaces of the device ...? |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1612 | func (dh *deviceHandler) doStateConnected(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1613 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1614 | logger.Debug(ctx, "doStateConnected-started") |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1615 | err := errors.New("device FSM: function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1616 | e.Cancel(err) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1617 | logger.Debug(ctx, "doStateConnected-done") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | // doStateUp handle the onu up indication and update to voltha core |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1621 | func (dh *deviceHandler) doStateUp(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1622 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1623 | logger.Debug(ctx, "doStateUp-started") |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1624 | err := errors.New("device FSM: function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1625 | e.Cancel(err) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1626 | logger.Debug(ctx, "doStateUp-done") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1627 | |
| 1628 | /* |
| 1629 | // Synchronous call to update device state - this method is run in its own go routine |
| 1630 | if err := dh.coreProxy.DeviceStateUpdate(ctx, dh.device.Id, voltha.ConnectStatus_REACHABLE, |
| 1631 | voltha.OperStatus_ACTIVE); err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1632 | logger.Errorw("Failed to update device with OLT UP indication", log.Fields{"device-id": dh.device.Id, "error": err}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1633 | return err |
| 1634 | } |
| 1635 | return nil |
| 1636 | */ |
| 1637 | } |
| 1638 | |
| 1639 | // doStateDown handle the onu down indication |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1640 | func (dh *deviceHandler) doStateDown(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1641 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1642 | logger.Debug(ctx, "doStateDown-started") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1643 | var err error |
| 1644 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1645 | device := dh.device |
| 1646 | if device == nil { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1647 | /*TODO: needs to handle error scenarios */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1648 | logger.Errorw(ctx, "Failed to fetch handler device", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1649 | e.Cancel(err) |
| 1650 | return |
| 1651 | } |
| 1652 | |
| 1653 | cloned := proto.Clone(device).(*voltha.Device) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1654 | logger.Debugw(ctx, "do-state-down", log.Fields{"ClonedDeviceID": cloned.Id}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1655 | /* |
| 1656 | // Update the all ports state on that device to disable |
| 1657 | if er := dh.coreProxy.PortsStateUpdate(ctx, cloned.Id, voltha.OperStatus_UNKNOWN); er != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1658 | logger.Errorw("updating-ports-failed", log.Fields{"device-id": device.Id, "error": er}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1659 | return er |
| 1660 | } |
| 1661 | |
| 1662 | //Update the device oper state and connection status |
| 1663 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 1664 | cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE |
| 1665 | dh.device = cloned |
| 1666 | |
| 1667 | if er := dh.coreProxy.DeviceStateUpdate(ctx, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); er != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1668 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": device.Id, "error": er}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1669 | return er |
| 1670 | } |
| 1671 | |
| 1672 | //get the child device for the parent device |
| 1673 | onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id) |
| 1674 | if err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1675 | logger.Errorw("failed to get child devices information", log.Fields{"device-id": dh.device.Id, "error": err}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1676 | return err |
| 1677 | } |
| 1678 | for _, onuDevice := range onuDevices.Items { |
| 1679 | |
| 1680 | // Update onu state as down in onu adapter |
| 1681 | onuInd := oop.OnuIndication{} |
| 1682 | onuInd.OperState = "down" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1683 | er := dh.adapterProxy.SendInterAdapterMessage(ctx, &onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1684 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 1685 | if er != nil { |
| 1686 | logger.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1687 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "device-id": onuDevice.Id}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1688 | //Do not return here and continue to process other ONUs |
| 1689 | } |
| 1690 | } |
| 1691 | // * Discovered ONUs entries need to be cleared , since after OLT |
| 1692 | // is up, it starts sending discovery indications again* / |
| 1693 | dh.discOnus = sync.Map{} |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1694 | logger.Debugw("do-state-down-end", log.Fields{"device-id": device.Id}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1695 | return nil |
| 1696 | */ |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1697 | err = errors.New("device FSM: function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1698 | e.Cancel(err) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1699 | logger.Debug(ctx, "doStateDown-done") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1702 | // deviceHandler StateMachine related state transition methods ##### end ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1703 | // ################################################################################# |
| 1704 | |
| 1705 | // ################################################### |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1706 | // deviceHandler utility methods ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1707 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1708 | //GetOnuDeviceEntry gets the ONU device entry and may wait until its value is defined |
| 1709 | func (dh *deviceHandler) GetOnuDeviceEntry(ctx context.Context, aWait bool) *mib.OnuDeviceEntry { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1710 | dh.lockDevice.RLock() |
| 1711 | pOnuDeviceEntry := dh.pOnuOmciDevice |
| 1712 | if aWait && pOnuDeviceEntry == nil { |
| 1713 | //keep the read sema short to allow for subsequent write |
| 1714 | dh.lockDevice.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1715 | logger.Debugw(ctx, "Waiting for DeviceEntry to be set ...", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1716 | // based on concurrent processing the deviceEntry setup may not yet be finished at his point |
| 1717 | // so it might be needed to wait here for that event with some timeout |
| 1718 | select { |
| 1719 | case <-time.After(60 * time.Second): //timer may be discussed ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1720 | logger.Errorw(ctx, "No valid DeviceEntry set after maxTime", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1721 | return nil |
| 1722 | case <-dh.deviceEntrySet: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1723 | logger.Debugw(ctx, "devicEntry ready now - continue", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1724 | // if written now, we can return the written value without sema |
| 1725 | return dh.pOnuOmciDevice |
| 1726 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1727 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1728 | dh.lockDevice.RUnlock() |
| 1729 | return pOnuDeviceEntry |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1732 | //setDeviceHandlerEntries sets the ONU device entry within the handler |
| 1733 | func (dh *deviceHandler) setDeviceHandlerEntries(apDeviceEntry *mib.OnuDeviceEntry, apOnuTp *avcfg.OnuUniTechProf, |
| 1734 | apOnuMetricsMgr *pmmgr.OnuMetricsManager, apOnuAlarmMgr *almgr.OnuAlarmManager, apSelfTestHdlr *otst.SelfTestControlBlock) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1735 | dh.lockDevice.Lock() |
| 1736 | defer dh.lockDevice.Unlock() |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 1737 | dh.pOnuOmciDevice = apDeviceEntry |
| 1738 | dh.pOnuTP = apOnuTp |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1739 | dh.pOnuMetricsMgr = apOnuMetricsMgr |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 1740 | dh.pAlarmMgr = apOnuAlarmMgr |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 1741 | dh.pSelfTestHdlr = apSelfTestHdlr |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1742 | } |
| 1743 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1744 | //addOnuDeviceEntry creates a new ONU device or returns the existing |
| 1745 | func (dh *deviceHandler) addOnuDeviceEntry(ctx context.Context) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1746 | logger.Debugw(ctx, "adding-deviceEntry", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1747 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1748 | deviceEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1749 | if deviceEntry == nil { |
| 1750 | /* costum_me_map in python code seems always to be None, |
| 1751 | we omit that here first (declaration unclear) -> todo at Adapter specialization ...*/ |
| 1752 | /* also no 'clock' argument - usage open ...*/ |
| 1753 | /* and no alarm_db yet (oo.alarm_db) */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1754 | deviceEntry = mib.NewOnuDeviceEntry(ctx, dh.coreClient, dh, dh.pOpenOnuAc) |
| 1755 | onuTechProfProc := avcfg.NewOnuUniTechProf(ctx, dh, deviceEntry) |
| 1756 | onuMetricsMgr := pmmgr.NewOnuMetricsManager(ctx, dh, deviceEntry) |
| 1757 | onuAlarmManager := almgr.NewAlarmManager(ctx, dh, deviceEntry) |
| 1758 | selfTestHdlr := otst.NewSelfTestMsgHandlerCb(ctx, dh, deviceEntry) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1759 | //error treatment possible //TODO!!! |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1760 | dh.setDeviceHandlerEntries(deviceEntry, onuTechProfProc, onuMetricsMgr, onuAlarmManager, selfTestHdlr) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1761 | // fire deviceEntry ready event to spread to possibly waiting processing |
| 1762 | dh.deviceEntrySet <- true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1763 | logger.Debugw(ctx, "onuDeviceEntry-added", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1764 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1765 | logger.Debugw(ctx, "onuDeviceEntry-add: Device already exists", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1766 | } |
| 1767 | // might be updated with some error handling !!! |
| 1768 | return nil |
| 1769 | } |
| 1770 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1771 | func (dh *deviceHandler) createInterface(ctx context.Context, onuind *oop.OnuIndication) error { |
| 1772 | logger.Debugw(ctx, "create_interface-started", log.Fields{"OnuId": onuind.GetOnuId(), |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1773 | "OnuIntfId": onuind.GetIntfId(), "OnuSerialNumber": onuind.GetSerialNumber()}) |
| 1774 | |
| 1775 | dh.pOnuIndication = onuind // let's revise if storing the pointer is sufficient... |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1776 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1777 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1778 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1779 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 1780 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1781 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1782 | if !dh.IsReconciling() { |
| 1783 | if err := dh.StorePersistentData(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1784 | logger.Warnw(ctx, "store persistent data error - continue as there will be additional write attempts", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1785 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1786 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1787 | logger.Debugw(ctx, "call DeviceStateUpdate upon create interface", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1788 | "OperStatus": voltha.OperStatus_ACTIVATING, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1789 | |
| 1790 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1791 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1792 | OperStatus: voltha.OperStatus_ACTIVATING, |
| 1793 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 1794 | }); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1795 | //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] | 1796 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1797 | } |
| 1798 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1799 | logger.Debugw(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVATING", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1800 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1801 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1802 | pDevEntry.MutexPersOnuConfig.RLock() |
| 1803 | if !pDevEntry.SOnuPersistentData.PersUniUnlockDone { |
| 1804 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1805 | logger.Debugw(ctx, "reconciling - uni-ports were not unlocked before adapter restart - resume with a normal start-up", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1806 | log.Fields{"device-id": dh.DeviceID}) |
| 1807 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1808 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1809 | pDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1810 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1811 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1812 | // It does not look to me as if makes sense to work with the real core device here, (not the stored clone)? |
| 1813 | // in this code the GetDevice would just make a check if the DeviceID's Device still exists in core |
| 1814 | // in python code it looks as the started onu_omci_device might have been updated with some new instance state of the core device |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1815 | // but I would not know why, and the go code anyway does not work with the device directly anymore in the mib.OnuDeviceEntry |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1816 | // so let's just try to keep it simple ... |
| 1817 | /* |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1818 | device, err := dh.coreProxy.GetDevice(log.WithSpanFromContext(context.TODO(), ctx), dh.device.Id, dh.device.Id) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1819 | if err != nil || device == nil { |
| 1820 | //TODO: needs to handle error scenarios |
| 1821 | logger.Errorw("Failed to fetch device device at creating If", log.Fields{"err": err}) |
| 1822 | return errors.New("Voltha Device not found") |
| 1823 | } |
| 1824 | */ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1825 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1826 | if err := pDevEntry.Start(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1827 | return err |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1828 | } |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1829 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1830 | _ = dh.deviceReasonUpdate(ctx, cmn.DrStartingOpenomci, !dh.IsReconciling()) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1831 | |
| 1832 | /* this might be a good time for Omci Verify message? */ |
| 1833 | verifyExec := make(chan bool) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1834 | omciVerify := otst.NewOmciTestRequest(log.WithSpanFromContext(context.TODO(), ctx), |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1835 | dh.device.Id, pDevEntry.PDevOmciCC, |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1836 | true, true) //exclusive and allowFailure (anyway not yet checked) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1837 | omciVerify.PerformOmciTest(log.WithSpanFromContext(context.TODO(), ctx), verifyExec) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1838 | |
| 1839 | /* give the handler some time here to wait for the OMCi verification result |
| 1840 | after Timeout start and try MibUpload FSM anyway |
| 1841 | (to prevent stopping on just not supported OMCI verification from ONU) */ |
| 1842 | select { |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 1843 | case <-time.After(pDevEntry.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1844 | logger.Warn(ctx, "omci start-verification timed out (continue normal)") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1845 | case testresult := <-verifyExec: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1846 | logger.Infow(ctx, "Omci start verification done", log.Fields{"result": testresult}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | /* In py code it looks earlier (on activate ..) |
| 1850 | # Code to Run OMCI Test Action |
| 1851 | kwargs_omci_test_action = { |
| 1852 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 1853 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 1854 | } |
| 1855 | serial_number = device.serial_number |
| 1856 | self._test_request = OmciTestRequest(self.core_proxy, |
| 1857 | self.omci_agent, self.device_id, |
| 1858 | AniG, serial_number, |
| 1859 | self.logical_device_id, |
| 1860 | exclusive=False, |
| 1861 | **kwargs_omci_test_action) |
| 1862 | ... |
| 1863 | # Start test requests after a brief pause |
| 1864 | if not self._test_request_started: |
| 1865 | self._test_request_started = True |
| 1866 | tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 1867 | reactor.callLater(tststart, self._test_request.start_collector) |
| 1868 | |
| 1869 | */ |
| 1870 | /* which is then: in omci_test_request.py : */ |
| 1871 | /* |
| 1872 | def start_collector(self, callback=None): |
| 1873 | """ |
| 1874 | Start the collection loop for an adapter if the frequency > 0 |
| 1875 | |
| 1876 | :param callback: (callable) Function to call to collect PM data |
| 1877 | """ |
| 1878 | self.logger.info("starting-pm-collection", device_name=self.name, default_freq=self.default_freq) |
| 1879 | if callback is None: |
| 1880 | callback = self.perform_test_omci |
| 1881 | |
| 1882 | if self.lc is None: |
| 1883 | self.lc = LoopingCall(callback) |
| 1884 | |
| 1885 | if self.default_freq > 0: |
| 1886 | self.lc.start(interval=self.default_freq / 10) |
| 1887 | |
| 1888 | def perform_test_omci(self): |
| 1889 | """ |
| 1890 | Perform the initial test request |
| 1891 | """ |
| 1892 | ani_g_entities = self._device.configuration.ani_g_entities |
| 1893 | ani_g_entities_ids = list(ani_g_entities.keys()) if ani_g_entities \ |
| 1894 | is not None else None |
| 1895 | self._entity_id = ani_g_entities_ids[0] |
| 1896 | self.logger.info('perform-test', entity_class=self._entity_class, |
| 1897 | entity_id=self._entity_id) |
| 1898 | try: |
| 1899 | frame = MEFrame(self._entity_class, self._entity_id, []).test() |
| 1900 | result = yield self._device.omci_cc.send(frame) |
| 1901 | if not result.fields['omci_message'].fields['success_code']: |
| 1902 | self.logger.info('Self-Test Submitted Successfully', |
| 1903 | code=result.fields[ |
| 1904 | 'omci_message'].fields['success_code']) |
| 1905 | else: |
| 1906 | raise TestFailure('Test Failure: {}'.format( |
| 1907 | result.fields['omci_message'].fields['success_code'])) |
| 1908 | except TimeoutError as e: |
| 1909 | self.deferred.errback(failure.Failure(e)) |
| 1910 | |
| 1911 | except Exception as e: |
| 1912 | self.logger.exception('perform-test-Error', e=e, |
| 1913 | class_id=self._entity_class, |
| 1914 | entity_id=self._entity_id) |
| 1915 | self.deferred.errback(failure.Failure(e)) |
| 1916 | |
| 1917 | */ |
| 1918 | |
| 1919 | // PM related heartbeat??? !!!TODO.... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1920 | //self._heartbeat.Enabled = True |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1921 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1922 | /* Note: Even though FSM calls look 'synchronous' here, FSM is running in background with the effect that possible errors |
| 1923 | * within the MibUpload are not notified in the OnuIndication response, this might be acceptable here, |
| 1924 | * as further OltAdapter processing may rely on the deviceReason event 'MibUploadDone' as a result of the FSM processing |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1925 | * otherwise some processing synchronization would be required - cmp. e.g TechProfile processing |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1926 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1927 | //call MibUploadFSM - transition up to state UlStInSync |
| 1928 | pMibUlFsm := pDevEntry.PMibUploadFsm.PFsm |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1929 | if pMibUlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1930 | if pMibUlFsm.Is(mib.UlStDisabled) { |
| 1931 | if err := pMibUlFsm.Event(mib.UlEvStart); err != nil { |
| 1932 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 1933 | return fmt.Errorf("can't go to state starting: %s", dh.DeviceID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1934 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1935 | logger.Debugw(ctx, "MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1936 | //Determine ONU status and start/re-start MIB Synchronization tasks |
| 1937 | //Determine if this ONU has ever synchronized |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1938 | if pDevEntry.IsNewOnu() { |
| 1939 | if err := pMibUlFsm.Event(mib.UlEvResetMib); err != nil { |
| 1940 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state resetting_mib", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 1941 | return fmt.Errorf("can't go to state resetting_mib: %s", dh.DeviceID) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1942 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1943 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1944 | if err := pMibUlFsm.Event(mib.UlEvExamineMds); err != nil { |
| 1945 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state examine_mds", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 1946 | return fmt.Errorf("can't go to examine_mds: %s", dh.DeviceID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1947 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1948 | logger.Debugw(ctx, "state of MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1949 | } |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1950 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1951 | logger.Errorw(ctx, "wrong state of MibSyncFsm - want: disabled", log.Fields{"have": string(pMibUlFsm.Current()), |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1952 | "device-id": dh.DeviceID}) |
| 1953 | return fmt.Errorf("wrong state of MibSyncFsm: %s", dh.DeviceID) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1954 | } |
| 1955 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1956 | logger.Errorw(ctx, "MibSyncFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID}) |
| 1957 | return fmt.Errorf("can't execute MibSync: %s", dh.DeviceID) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1958 | } |
| 1959 | return nil |
| 1960 | } |
| 1961 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1962 | func (dh *deviceHandler) updateInterface(ctx context.Context, onuind *oop.OnuIndication) error { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1963 | //state checking to prevent unneeded processing (eg. on ONU 'unreachable' and 'down') |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1964 | // (but note that the deviceReason may also have changed to e.g. TechProf*Delete_Success in between) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1965 | if dh.getDeviceReason() != cmn.DrStoppingOpenomci { |
| 1966 | logger.Debugw(ctx, "updateInterface-started - stopping-device", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1967 | |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1968 | //stop all running FSM processing - make use of the DH-state as mirrored in the deviceReason |
| 1969 | //here no conflict with aborted FSM's should arise as a complete OMCI initialization is assumed on ONU-Up |
| 1970 | //but that might change with some simple MDS check on ONU-Up treatment -> attention!!! |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1971 | if err := dh.resetFsms(ctx, true); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1972 | logger.Errorw(ctx, "error-updateInterface at FSM stop", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1973 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1974 | // abort: system behavior is just unstable ... |
| 1975 | return err |
| 1976 | } |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 1977 | //all stored persistent data are not valid anymore (loosing knowledge about the connected ONU) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1978 | _ = dh.deleteDevicePersistencyData(ctx) //ignore possible errors here and continue, hope is that data is synchronized with new ONU-Up |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1979 | |
| 1980 | //deviceEntry stop without omciCC reset here, regarding the OMCI_CC still valid for this ONU |
| 1981 | // - in contrary to disableDevice - compare with processUniDisableStateDoneEvent |
| 1982 | //stop the device entry which resets the attached omciCC |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1983 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1984 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1985 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 1986 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1987 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1988 | _ = pDevEntry.Stop(log.WithSpanFromContext(context.TODO(), ctx), false) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1989 | |
| 1990 | //TODO!!! remove existing traffic profiles |
| 1991 | /* from py code, if TP's exist, remove them - not yet implemented |
| 1992 | self._tp = dict() |
| 1993 | # Let TP download happen again |
| 1994 | for uni_id in self._tp_service_specific_task: |
| 1995 | self._tp_service_specific_task[uni_id].clear() |
| 1996 | for uni_id in self._tech_profile_download_done: |
| 1997 | self._tech_profile_download_done[uni_id].clear() |
| 1998 | */ |
| 1999 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2000 | dh.DisableUniPortStateUpdate(ctx) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2001 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2002 | dh.SetReadyForOmciConfig(false) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2003 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2004 | if err := dh.deviceReasonUpdate(ctx, cmn.DrStoppingOpenomci, true); err != nil { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2005 | // abort: system behavior is just unstable ... |
| 2006 | return err |
| 2007 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2008 | logger.Debugw(ctx, "call DeviceStateUpdate upon update interface", log.Fields{"ConnectStatus": voltha.ConnectStatus_UNREACHABLE, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2009 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2010 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2011 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2012 | ConnStatus: voltha.ConnectStatus_UNREACHABLE, |
| 2013 | OperStatus: voltha.OperStatus_DISCOVERED, |
| 2014 | }); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2015 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2016 | logger.Errorw(ctx, "error-updating-device-state unreachable-discovered", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2017 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2018 | // abort: system behavior is just unstable ... |
| 2019 | return err |
| 2020 | } |
| 2021 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2022 | logger.Debugw(ctx, "updateInterface - device already stopped", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2023 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2024 | return nil |
| 2025 | } |
| 2026 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2027 | func (dh *deviceHandler) resetFsms(ctx context.Context, includingMibSyncFsm bool) error { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2028 | //all possible FSM's are stopped or reset here to ensure their transition to 'disabled' |
| 2029 | //it is not sufficient to stop/reset the latest running FSM as done in previous versions |
| 2030 | // as after down/up procedures all FSM's might be active/ongoing (in theory) |
| 2031 | // and using the stop/reset event should never harm |
| 2032 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2033 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2034 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2035 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 2036 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2037 | } |
Holger Hildebrandt | c8ece36 | 2021-05-17 12:01:10 +0000 | [diff] [blame] | 2038 | if pDevEntry.PDevOmciCC != nil { |
mpagenko | 8cd1bf7 | 2021-06-22 10:11:19 +0000 | [diff] [blame] | 2039 | pDevEntry.PDevOmciCC.CancelRequestMonitoring(ctx) |
Holger Hildebrandt | c8ece36 | 2021-05-17 12:01:10 +0000 | [diff] [blame] | 2040 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2041 | pDevEntry.MutexOnuImageStatus.RLock() |
| 2042 | if pDevEntry.POnuImageStatus != nil { |
| 2043 | pDevEntry.POnuImageStatus.CancelProcessing(ctx) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 2044 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2045 | pDevEntry.MutexOnuImageStatus.RUnlock() |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 2046 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2047 | if includingMibSyncFsm { |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 2048 | pDevEntry.CancelProcessing(ctx) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2049 | } |
| 2050 | //MibDownload may run |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2051 | pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2052 | if pMibDlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2053 | _ = pMibDlFsm.Event(mib.DlEvReset) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2054 | } |
| 2055 | //port lock/unlock FSM's may be active |
| 2056 | if dh.pUnlockStateFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2057 | _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2058 | } |
| 2059 | if dh.pLockStateFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2060 | _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2061 | } |
| 2062 | //techProfile related PonAniConfigFsm FSM may be active |
| 2063 | if dh.pOnuTP != nil { |
| 2064 | // should always be the case here |
| 2065 | // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2066 | if dh.pOnuTP.PAniConfigFsm != nil { |
| 2067 | for uniTP := range dh.pOnuTP.PAniConfigFsm { |
| 2068 | dh.pOnuTP.PAniConfigFsm[uniTP].CancelProcessing(ctx) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 2069 | } |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2070 | } |
| 2071 | for _, uniPort := range dh.uniEntityMap { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2072 | // reset the possibly existing VlanConfigFsm |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2073 | dh.lockVlanConfig.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2074 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniPort.UniID]; exist { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2075 | //VlanFilterFsm exists and was already started |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2076 | dh.lockVlanConfig.RUnlock() |
| 2077 | //reset of all Fsm is always accompanied by global persistency data removal |
| 2078 | // no need to remove specific data |
| 2079 | pVlanFilterFsm.RequestClearPersistency(false) |
| 2080 | //ensure the FSM processing is stopped in case waiting for some response |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 2081 | pVlanFilterFsm.CancelProcessing(ctx) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2082 | } else { |
| 2083 | dh.lockVlanConfig.RUnlock() |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2084 | } |
| 2085 | } |
| 2086 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2087 | if dh.GetCollectorIsRunning() { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2088 | // Stop collector routine |
| 2089 | dh.stopCollector <- true |
| 2090 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2091 | if dh.GetAlarmManagerIsRunning(ctx) { |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2092 | dh.stopAlarmManager <- true |
| 2093 | } |
Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 2094 | if dh.pSelfTestHdlr.GetSelfTestHandlerIsRunning() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2095 | dh.pSelfTestHdlr.StopSelfTestModule <- true |
Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 2096 | } |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2097 | |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2098 | // Note: We want flow deletes to be processed on onu down, so do not stop flow monitoring routines |
| 2099 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2100 | //reset a possibly running upgrade FSM |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2101 | // (note the Upgrade FSM may stay alive e.g. in state UpgradeStWaitForCommit to endure the ONU reboot) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2102 | dh.lockUpgradeFsm.RLock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2103 | lopOnuUpradeFsm := dh.pOnuUpradeFsm |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2104 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2105 | dh.lockUpgradeFsm.RUnlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2106 | if lopOnuUpradeFsm != nil { |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2107 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 2108 | //here we do not expect intermediate cancelation, we still allow for other commands on this FSM |
| 2109 | // (even though it may also run into direct cancellation, a bit hard to verify here) |
| 2110 | // so don't set 'dh.upgradeCanceled = true' here! |
| 2111 | lopOnuUpradeFsm.CancelProcessing(ctx, false, voltha.ImageState_CANCELLED_ON_ONU_STATE) //conditional cancel |
| 2112 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2113 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2114 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2115 | logger.Infow(ctx, "resetFsms done", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2116 | return nil |
| 2117 | } |
| 2118 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2119 | func (dh *deviceHandler) processMibDatabaseSyncEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2120 | logger.Debugw(ctx, "MibInSync event received, adding uni ports and locking the ONU interfaces", log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2121 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2122 | // store persistent data collected during MIB upload processing |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2123 | if err := dh.StorePersistentData(ctx); err != nil { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2124 | logger.Warnw(ctx, "store persistent data error - continue as there will be additional write attempts", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2125 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2126 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2127 | _ = dh.deviceReasonUpdate(ctx, cmn.DrDiscoveryMibsyncComplete, !dh.IsReconciling()) |
| 2128 | dh.AddAllUniPorts(ctx) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2129 | |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2130 | /* 200605: lock processing after initial MIBUpload removed now as the ONU should be in the lock state per default here */ |
| 2131 | /* 201117: build_dt-berlin-pod-openonugo_1T8GEM_voltha_DT_openonugo_master_test runs into error TC |
| 2132 | * 'Test Disable ONUs and OLT Then Delete ONUs and OLT for DT' with Sercom ONU, which obviously needs |
| 2133 | * disable/enable toggling here to allow traffic |
| 2134 | * but moreover it might be useful for tracking the interface operState changes if this will be implemented, |
| 2135 | * like the py comment says: |
| 2136 | * # start by locking all the unis till mib sync and initial mib is downloaded |
| 2137 | * # this way we can capture the port down/up events when we are ready |
| 2138 | */ |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2139 | |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2140 | // Init Uni Ports to Admin locked state |
| 2141 | // *** should generate UniLockStateDone event ***** |
| 2142 | if dh.pLockStateFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2143 | dh.createUniLockFsm(ctx, true, cmn.UniLockStateDone) |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2144 | } else { //LockStateFSM already init |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2145 | dh.pLockStateFsm.SetSuccessEvent(cmn.UniLockStateDone) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2146 | dh.runUniLockFsm(ctx, true) |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2147 | } |
| 2148 | } |
| 2149 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2150 | func (dh *deviceHandler) processUniLockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2151 | logger.Infow(ctx, "UniLockStateDone event: Starting MIB download", log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2152 | /* Mib download procedure - |
| 2153 | ***** should run over 'downloaded' state and generate MibDownloadDone event ***** |
| 2154 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2155 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2156 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2157 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2158 | return |
| 2159 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2160 | pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2161 | if pMibDlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2162 | if pMibDlFsm.Is(mib.DlStDisabled) { |
| 2163 | if err := pMibDlFsm.Event(mib.DlEvStart); err != nil { |
| 2164 | logger.Errorw(ctx, "MibDownloadFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2165 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2166 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2167 | logger.Debugw(ctx, "MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2168 | // maybe use more specific states here for the specific download steps ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2169 | if err := pMibDlFsm.Event(mib.DlEvCreateGal); err != nil { |
| 2170 | logger.Errorw(ctx, "MibDownloadFsm: Can't start CreateGal", log.Fields{"device-id": dh.DeviceID, "err": err}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2171 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2172 | logger.Debugw(ctx, "state of MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2173 | //Begin MIB data download (running autonomously) |
| 2174 | } |
| 2175 | } |
| 2176 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2177 | logger.Errorw(ctx, "wrong state of MibDownloadFsm - want: disabled", log.Fields{"have": string(pMibDlFsm.Current()), |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2178 | "device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2179 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2180 | } |
| 2181 | /***** Mib download started */ |
| 2182 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2183 | logger.Errorw(ctx, "MibDownloadFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2184 | } |
| 2185 | } |
| 2186 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2187 | func (dh *deviceHandler) processMibDownloadDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2188 | logger.Debugw(ctx, "MibDownloadDone event received, unlocking the ONU interfaces", log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2189 | //initiate DevStateUpdate |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2190 | if !dh.IsReconciling() { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2191 | logger.Debugw(ctx, "call DeviceStateUpdate upon mib-download done", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2192 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2193 | //we allow a possible OnuSw image commit only in the normal startup, not at reconciling |
| 2194 | // in case of adapter restart connected to an ONU upgrade I would not rely on the image quality |
| 2195 | // maybe some 'forced' commitment can be done in this situation from system management (or upgrade restarted) |
| 2196 | dh.checkOnOnuImageCommit(ctx) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2197 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2198 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2199 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2200 | OperStatus: voltha.OperStatus_ACTIVE, |
| 2201 | }); err != nil { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2202 | //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] | 2203 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2204 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2205 | logger.Debugw(ctx, "dev state updated to 'Oper.Active'", log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2206 | } |
| 2207 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2208 | logger.Debugw(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVE", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2209 | log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2210 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2211 | _ = dh.deviceReasonUpdate(ctx, cmn.DrInitialMibDownloaded, !dh.IsReconciling()) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2212 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2213 | if !dh.GetCollectorIsRunning() { |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2214 | // Start PM collector routine |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2215 | go dh.StartCollector(ctx) |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2216 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2217 | if !dh.GetAlarmManagerIsRunning(ctx) { |
| 2218 | go dh.StartAlarmManager(ctx) |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2221 | // Start flow handler routines per UNI |
| 2222 | for _, uniPort := range dh.uniEntityMap { |
| 2223 | // only if this port was enabled for use by the operator at startup |
| 2224 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 2225 | if !dh.GetFlowMonitoringIsRunning(uniPort.UniID) { |
| 2226 | go dh.PerOnuFlowHandlerRoutine(uniPort.UniID) |
| 2227 | } |
| 2228 | } |
| 2229 | } |
| 2230 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2231 | // Initialize classical L2 PM Interval Counters |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2232 | if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventInit); err != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2233 | // There is no way we should be landing here, but if we do then |
| 2234 | // there is nothing much we can do about this other than log error |
| 2235 | logger.Errorw(ctx, "error starting l2 pm fsm", log.Fields{"device-id": dh.device.Id, "err": err}) |
| 2236 | } |
| 2237 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2238 | dh.SetReadyForOmciConfig(true) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2239 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2240 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2241 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2242 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2243 | return |
| 2244 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2245 | pDevEntry.MutexPersOnuConfig.RLock() |
| 2246 | if dh.IsReconciling() && pDevEntry.SOnuPersistentData.PersUniDisableDone { |
| 2247 | pDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2248 | logger.Debugw(ctx, "reconciling - uni-ports were disabled by admin before adapter restart - keep the ports locked", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2249 | log.Fields{"device-id": dh.DeviceID}) |
| 2250 | go dh.ReconcileDeviceTechProf(ctx) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2251 | // reconcilement will be continued after ani config is done |
| 2252 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2253 | pDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2254 | // *** should generate UniUnlockStateDone event ***** |
| 2255 | if dh.pUnlockStateFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2256 | dh.createUniLockFsm(ctx, false, cmn.UniUnlockStateDone) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2257 | } else { //UnlockStateFSM already init |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2258 | dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniUnlockStateDone) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2259 | dh.runUniLockFsm(ctx, false) |
| 2260 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2261 | } |
| 2262 | } |
| 2263 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2264 | func (dh *deviceHandler) processUniUnlockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2265 | dh.EnableUniPortStateUpdate(ctx) //cmp python yield self.enable_ports() |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2266 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2267 | if !dh.IsReconciling() { |
| 2268 | logger.Infow(ctx, "UniUnlockStateDone event: Sending OnuUp event", log.Fields{"device-id": dh.DeviceID}) |
ozgecanetsia | 2f05ed3 | 2021-05-31 17:13:48 +0300 | [diff] [blame] | 2269 | raisedTs := time.Now().Unix() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2270 | go dh.sendOnuOperStateEvent(ctx, voltha.OperStatus_ACTIVE, dh.DeviceID, raisedTs) //cmp python onu_active_event |
| 2271 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2272 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2273 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2274 | return |
| 2275 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2276 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2277 | pDevEntry.SOnuPersistentData.PersUniUnlockDone = true |
| 2278 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2279 | if err := dh.StorePersistentData(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2280 | logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2281 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2282 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2283 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2284 | logger.Debugw(ctx, "reconciling - don't notify core that onu went to active but trigger tech profile config", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2285 | log.Fields{"device-id": dh.DeviceID}) |
| 2286 | go dh.ReconcileDeviceTechProf(ctx) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2287 | // reconcilement will be continued after ani config is done |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2288 | } |
| 2289 | } |
| 2290 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2291 | func (dh *deviceHandler) processUniDisableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2292 | logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2293 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2294 | |
| 2295 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2296 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2297 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2298 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 2299 | }); err != nil { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2300 | //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] | 2301 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2302 | } |
| 2303 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2304 | logger.Debugw(ctx, "DeviceReasonUpdate upon disable", log.Fields{"reason": cmn.DeviceReasonMap[cmn.DrOmciAdminLock], "device-id": dh.DeviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2305 | // DeviceReason to update acc.to modified py code as per beginning of Sept 2020 |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2306 | _ = dh.deviceReasonUpdate(ctx, cmn.DrOmciAdminLock, true) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2307 | |
| 2308 | //transfer the modified logical uni port state |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2309 | dh.DisableUniPortStateUpdate(ctx) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2310 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2311 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2312 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2313 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2314 | return |
| 2315 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2316 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2317 | pDevEntry.SOnuPersistentData.PersUniDisableDone = true |
| 2318 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2319 | if err := dh.StorePersistentData(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2320 | logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2321 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2322 | } |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2325 | func (dh *deviceHandler) processUniEnableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2326 | logger.Debugw(ctx, "DeviceStateUpdate upon re-enable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2327 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2328 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2329 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2330 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2331 | OperStatus: voltha.OperStatus_ACTIVE, |
| 2332 | }); err != nil { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2333 | //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] | 2334 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2337 | logger.Debugw(ctx, "DeviceReasonUpdate upon re-enable", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2338 | "reason": cmn.DeviceReasonMap[cmn.DrOnuReenabled], "device-id": dh.DeviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2339 | // DeviceReason to update acc.to modified py code as per beginning of Sept 2020 |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2340 | _ = dh.deviceReasonUpdate(ctx, cmn.DrOnuReenabled, true) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2341 | |
| 2342 | //transfer the modified logical uni port state |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2343 | dh.EnableUniPortStateUpdate(ctx) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2344 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2345 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2346 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2347 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2348 | return |
| 2349 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2350 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2351 | pDevEntry.SOnuPersistentData.PersUniDisableDone = false |
| 2352 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2353 | if err := dh.StorePersistentData(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2354 | logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2355 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2356 | } |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2357 | } |
| 2358 | |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 2359 | func (dh *deviceHandler) processUniEnableStateFailedEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2360 | logger.Debugw(ctx, "DeviceStateUpdate upon re-enable failure. ", log.Fields{ |
| 2361 | "OperStatus": voltha.OperStatus_FAILED, "device-id": dh.DeviceID}) |
| 2362 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
| 2363 | DeviceId: dh.DeviceID, |
| 2364 | OperStatus: voltha.OperStatus_FAILED, |
| 2365 | }); err != nil { |
| 2366 | logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err}) |
| 2367 | } |
| 2368 | } |
| 2369 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2370 | func (dh *deviceHandler) processOmciAniConfigDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2371 | if devEvent == cmn.OmciAniConfigDone { |
| 2372 | logger.Debugw(ctx, "OmciAniConfigDone event received", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2373 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 2374 | // - which may cause some inconsistency |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2375 | if dh.getDeviceReason() != cmn.DrTechProfileConfigDownloadSuccess { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2376 | // which may be the case from some previous actvity even on this UNI Port (but also other UNI ports) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2377 | _ = dh.deviceReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, !dh.IsReconciling()) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2378 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2379 | if dh.IsReconciling() { |
| 2380 | go dh.ReconcileDeviceFlowConfig(ctx) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2381 | } |
| 2382 | } else { // should be the OmciAniResourceRemoved block |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2383 | logger.Debugw(ctx, "OmciAniResourceRemoved event received", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2384 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 2385 | // - which may cause some inconsistency |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2386 | if dh.getDeviceReason() != cmn.DrTechProfileConfigDeleteSuccess { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2387 | // which may be the case from some previous actvity even on this ONU port (but also other UNI ports) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2388 | _ = dh.deviceReasonUpdate(ctx, cmn.DrTechProfileConfigDeleteSuccess, true) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2389 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2390 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2391 | } |
| 2392 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2393 | func (dh *deviceHandler) processOmciVlanFilterDoneEvent(ctx context.Context, aDevEvent cmn.OnuDeviceEvent) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2394 | logger.Debugw(ctx, "OmciVlanFilterDone event received", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2395 | log.Fields{"device-id": dh.DeviceID, "event": aDevEvent}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2396 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 2397 | // - which may cause some inconsistency |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2398 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2399 | if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterAddDoneNoKvStore { |
| 2400 | if dh.getDeviceReason() != cmn.DrOmciFlowsPushed { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2401 | // which may be the case from some previous actvity on another UNI Port of the ONU |
| 2402 | // or even some previous flow add activity on the same port |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2403 | _ = dh.deviceReasonUpdate(ctx, cmn.DrOmciFlowsPushed, !dh.IsReconciling()) |
| 2404 | if dh.IsReconciling() { |
Holger Hildebrandt | 1b8f4ad | 2021-03-25 15:53:51 +0000 | [diff] [blame] | 2405 | go dh.reconcileEnd(ctx) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2406 | } |
| 2407 | } |
| 2408 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2409 | if dh.getDeviceReason() != cmn.DrOmciFlowsDeleted { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2410 | //not relevant for reconcile |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2411 | _ = dh.deviceReasonUpdate(ctx, cmn.DrOmciFlowsDeleted, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2412 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2413 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2414 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2415 | if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterRemDone { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2416 | //events that request KvStore write |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2417 | if err := dh.StorePersistentData(ctx); err != nil { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2418 | logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2419 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2420 | } |
| 2421 | } else { |
| 2422 | logger.Debugw(ctx, "OmciVlanFilter*Done* - write to KvStore not requested", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2423 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2424 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2425 | } |
| 2426 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2427 | //DeviceProcStatusUpdate evaluates possible processing events and initiates according next activities |
| 2428 | func (dh *deviceHandler) DeviceProcStatusUpdate(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2429 | switch devEvent { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2430 | case cmn.MibDatabaseSync: |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2431 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2432 | dh.processMibDatabaseSyncEvent(ctx, devEvent) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2433 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2434 | case cmn.UniLockStateDone: |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2435 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2436 | dh.processUniLockStateDoneEvent(ctx, devEvent) |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2437 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2438 | case cmn.MibDownloadDone: |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2439 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2440 | dh.processMibDownloadDoneEvent(ctx, devEvent) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2441 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2442 | case cmn.UniUnlockStateDone: |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2443 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2444 | dh.processUniUnlockStateDoneEvent(ctx, devEvent) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2445 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2446 | case cmn.UniEnableStateDone: |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2447 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2448 | dh.processUniEnableStateDoneEvent(ctx, devEvent) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2449 | } |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 2450 | case cmn.UniEnableStateFailed: |
| 2451 | { |
| 2452 | dh.processUniEnableStateFailedEvent(ctx, devEvent) |
| 2453 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2454 | case cmn.UniDisableStateDone: |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2455 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2456 | dh.processUniDisableStateDoneEvent(ctx, devEvent) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2457 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2458 | case cmn.OmciAniConfigDone, cmn.OmciAniResourceRemoved: |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 2459 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2460 | dh.processOmciAniConfigDoneEvent(ctx, devEvent) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 2461 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2462 | case cmn.OmciVlanFilterAddDone, cmn.OmciVlanFilterAddDoneNoKvStore, cmn.OmciVlanFilterRemDone, cmn.OmciVlanFilterRemDoneNoKvStore: |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2463 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2464 | dh.processOmciVlanFilterDoneEvent(ctx, devEvent) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2465 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2466 | default: |
| 2467 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2468 | logger.Debugw(ctx, "unhandled-device-event", log.Fields{"device-id": dh.DeviceID, "event": devEvent}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2469 | } |
| 2470 | } //switch |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2471 | } |
| 2472 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2473 | func (dh *deviceHandler) addUniPort(ctx context.Context, aUniInstNo uint16, aUniID uint8, aPortType cmn.UniPortType) { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2474 | // parameters are IntfId, OnuId, uniId |
Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 2475 | uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2476 | uint32(aUniID)) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2477 | if _, present := dh.uniEntityMap[uniNo]; present { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2478 | logger.Warnw(ctx, "OnuUniPort-add: Port already exists", log.Fields{"for InstanceId": aUniInstNo}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2479 | } else { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2480 | //with arguments aUniID, a_portNo, aPortType |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2481 | pUniPort := cmn.NewOnuUniPort(ctx, aUniID, uniNo, aUniInstNo, aPortType) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2482 | if pUniPort == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2483 | logger.Warnw(ctx, "OnuUniPort-add: Could not create Port", log.Fields{"for InstanceId": aUniInstNo}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2484 | } else { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2485 | //store UniPort with the System-PortNumber key |
| 2486 | dh.uniEntityMap[uniNo] = pUniPort |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2487 | if !dh.IsReconciling() { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2488 | // create announce the UniPort to the core as VOLTHA Port object |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2489 | if err := pUniPort.CreateVolthaPort(ctx, dh); err == nil { |
| 2490 | logger.Infow(ctx, "OnuUniPort-added", log.Fields{"for PortNo": uniNo}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2491 | } //error logging already within UniPort method |
| 2492 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2493 | logger.Debugw(ctx, "reconciling - OnuUniPort already added", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2494 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2495 | } |
| 2496 | } |
| 2497 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2498 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2499 | func (dh *deviceHandler) AddAllUniPorts(ctx context.Context) { |
| 2500 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2501 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2502 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2503 | return |
| 2504 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2505 | uniCnt := uint8(0) //UNI Port limit: see MaxUnisPerOnu (by now 16) (OMCI supports max 255 p.b.) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2506 | if pptpInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2507 | ctx, me.PhysicalPathTerminationPointEthernetUniClassID); len(pptpInstKeys) > 0 { |
| 2508 | for _, mgmtEntityID := range pptpInstKeys { |
| 2509 | logger.Debugw(ctx, "Add PPTPEthUni port for MIB-stored instance:", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2510 | "device-id": dh.DeviceID, "PPTPEthUni EntityID": mgmtEntityID}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2511 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniPPTP) |
| 2512 | uniCnt++ |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2513 | } |
| 2514 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2515 | logger.Debugw(ctx, "No PPTP instances found", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2516 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2517 | if veipInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2518 | ctx, me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 { |
| 2519 | for _, mgmtEntityID := range veipInstKeys { |
| 2520 | logger.Debugw(ctx, "Add VEIP for MIB-stored instance:", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2521 | "device-id": dh.DeviceID, "VEIP EntityID": mgmtEntityID}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2522 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniVEIP) |
| 2523 | uniCnt++ |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2524 | } |
| 2525 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2526 | logger.Debugw(ctx, "No VEIP instances found", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2527 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2528 | if potsInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 2529 | ctx, me.PhysicalPathTerminationPointPotsUniClassID); len(potsInstKeys) > 0 { |
| 2530 | for _, mgmtEntityID := range potsInstKeys { |
| 2531 | logger.Debugw(ctx, "Add PPTP Pots UNI for MIB-stored instance:", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2532 | "device-id": dh.DeviceID, "PPTP Pots UNI EntityID": mgmtEntityID}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2533 | dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniPPTPPots) |
| 2534 | uniCnt++ |
ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 2535 | } |
| 2536 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2537 | logger.Debugw(ctx, "No PPTP Pots UNI instances found", log.Fields{"device-id": dh.DeviceID}) |
ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 2538 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2539 | if uniCnt == 0 { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2540 | logger.Warnw(ctx, "No UniG instances found", log.Fields{"device-id": dh.DeviceID}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2541 | return |
| 2542 | } |
| 2543 | |
| 2544 | dh.flowCbChan = make([]chan FlowCb, uniCnt) |
| 2545 | dh.stopFlowMonitoringRoutine = make([]chan bool, uniCnt) |
| 2546 | dh.isFlowMonitoringRoutineActive = make([]bool, uniCnt) |
| 2547 | for i := 0; i < int(uniCnt); i++ { |
| 2548 | dh.flowCbChan[i] = make(chan FlowCb, dh.pOpenOnuAc.config.MaxConcurrentFlowsPerUni) |
| 2549 | dh.stopFlowMonitoringRoutine[i] = make(chan bool) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2550 | } |
| 2551 | } |
| 2552 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2553 | // EnableUniPortStateUpdate enables UniPortState and update core port state accordingly |
| 2554 | func (dh *deviceHandler) EnableUniPortStateUpdate(ctx context.Context) { |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 2555 | // py code was updated 2003xx to activate the real ONU UNI ports per OMCI (VEIP or PPTP) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2556 | // but towards core only the first port active state is signaled |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 2557 | // with following remark: |
| 2558 | // # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow |
| 2559 | // # load on the core |
| 2560 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2561 | // lock_ports(false) as done in py code here is shifted to separate call from device event processing |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 2562 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2563 | for uniNo, uniPort := range dh.uniEntityMap { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2564 | // only if this port is validated for operState transfer |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2565 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 2566 | logger.Infow(ctx, "OnuUniPort-forced-OperState-ACTIVE", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID}) |
| 2567 | uniPort.SetOperState(vc.OperStatus_ACTIVE) |
| 2568 | if !dh.IsReconciling() { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2569 | //maybe also use getter functions on uniPort - perhaps later ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2570 | go func(port *cmn.OnuUniPort) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2571 | if err := dh.updatePortStateInCore(ctx, &ic.PortState{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2572 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2573 | PortType: voltha.Port_ETHERNET_UNI, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2574 | PortNo: port.PortNo, |
| 2575 | OperStatus: port.OperState, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2576 | }); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2577 | logger.Errorw(ctx, "port-state-update-failed", log.Fields{"error": err, "port-no": uniPort.PortNo, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2578 | } |
| 2579 | }(uniPort) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2580 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2581 | logger.Debugw(ctx, "reconciling - don't notify core about PortStateUpdate", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2582 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2583 | } |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | // Disable UniPortState and update core port state accordingly |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2588 | func (dh *deviceHandler) DisableUniPortStateUpdate(ctx context.Context) { |
| 2589 | // compare EnableUniPortStateUpdate() above |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2590 | // -> use current restriction to operate only on first UNI port as inherited from actual Py code |
| 2591 | for uniNo, uniPort := range dh.uniEntityMap { |
| 2592 | // only if this port is validated for operState transfer |
Matteo Scandolo | 20d180c | 2021-06-10 17:20:21 +0200 | [diff] [blame] | 2593 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2594 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 2595 | logger.Infow(ctx, "OnuUniPort-forced-OperState-UNKNOWN", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID}) |
| 2596 | uniPort.SetOperState(vc.OperStatus_UNKNOWN) |
| 2597 | if !dh.IsReconciling() { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2598 | //maybe also use getter functions on uniPort - perhaps later ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2599 | go func(port *cmn.OnuUniPort) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2600 | if err := dh.updatePortStateInCore(ctx, &ic.PortState{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2601 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2602 | PortType: voltha.Port_ETHERNET_UNI, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2603 | PortNo: port.PortNo, |
| 2604 | OperStatus: port.OperState, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2605 | }); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2606 | logger.Errorw(ctx, "port-state-update-failed", log.Fields{"error": err, "port-no": uniPort.PortNo, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2607 | } |
| 2608 | }(uniPort) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2609 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2610 | logger.Debugw(ctx, "reconciling - don't notify core about PortStateUpdate", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2611 | } |
| 2612 | |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 2613 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2614 | } |
| 2615 | } |
| 2616 | |
| 2617 | // ONU_Active/Inactive announcement on system KAFKA bus |
| 2618 | // tried to re-use procedure of oltUpDownIndication from openolt_eventmgr.go with used values from Py code |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2619 | func (dh *deviceHandler) sendOnuOperStateEvent(ctx context.Context, aOperState vc.OperStatus_Types, aDeviceID string, raisedTs int64) { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2620 | var de voltha.DeviceEvent |
| 2621 | eventContext := make(map[string]string) |
| 2622 | //Populating event context |
| 2623 | // assume giving ParentId in GetDevice twice really gives the ParentDevice (there is no GetParentDevice()...) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2624 | parentDevice, err := dh.getDeviceFromCore(ctx, dh.parentID) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2625 | if err != nil || parentDevice == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2626 | logger.Errorw(ctx, "Failed to fetch parent device for OnuEvent", |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2627 | log.Fields{"parentID": dh.parentID, "err": err}) |
Holger Hildebrandt | 7ec14c4 | 2021-05-28 14:21:58 +0000 | [diff] [blame] | 2628 | return //TODO with VOL-3045: rw-core is unresponsive: report error and/or perform self-initiated onu-reset? |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2629 | } |
| 2630 | oltSerialNumber := parentDevice.SerialNumber |
| 2631 | |
| 2632 | eventContext["pon-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.IntfId), 10) |
| 2633 | eventContext["onu-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.OnuId), 10) |
| 2634 | eventContext["serial-number"] = dh.device.SerialNumber |
ssiddiqui | 1221d1a | 2021-02-15 11:12:51 +0530 | [diff] [blame] | 2635 | eventContext["olt-serial-number"] = oltSerialNumber |
| 2636 | eventContext["device-id"] = aDeviceID |
| 2637 | eventContext["registration-id"] = aDeviceID //py: string(device_id)?? |
ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 2638 | eventContext["num-of-unis"] = strconv.Itoa(len(dh.uniEntityMap)) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2639 | if deviceEntry := dh.GetOnuDeviceEntry(ctx, false); deviceEntry != nil { |
| 2640 | deviceEntry.MutexPersOnuConfig.RLock() |
| 2641 | eventContext["equipment-id"] = deviceEntry.SOnuPersistentData.PersEquipmentID |
| 2642 | deviceEntry.MutexPersOnuConfig.RUnlock() |
| 2643 | eventContext["software-version"] = deviceEntry.GetActiveImageVersion(ctx) |
| 2644 | deviceEntry.MutexPersOnuConfig.RLock() |
| 2645 | eventContext["vendor"] = deviceEntry.SOnuPersistentData.PersVendorID |
| 2646 | deviceEntry.MutexPersOnuConfig.RUnlock() |
| 2647 | eventContext["inactive-software-version"] = deviceEntry.GetInactiveImageVersion(ctx) |
ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 2648 | logger.Debugw(ctx, "prepare ONU_ACTIVATED event", |
| 2649 | log.Fields{"device-id": aDeviceID, "EventContext": eventContext}) |
| 2650 | } else { |
| 2651 | logger.Errorw(ctx, "Failed to fetch device-entry. ONU_ACTIVATED event is not sent", |
| 2652 | log.Fields{"device-id": aDeviceID}) |
| 2653 | return |
| 2654 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2655 | |
| 2656 | /* Populating device event body */ |
| 2657 | de.Context = eventContext |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2658 | de.ResourceId = aDeviceID |
| 2659 | if aOperState == voltha.OperStatus_ACTIVE { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2660 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "RAISE_EVENT") |
| 2661 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 2662 | cEventObjectType, cOnuActivatedEvent, "Raised") |
| 2663 | } else { |
| 2664 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "CLEAR_EVENT") |
| 2665 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 2666 | cEventObjectType, cOnuActivatedEvent, "Cleared") |
| 2667 | } |
| 2668 | /* Send event to KAFKA */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2669 | if err := dh.EventProxy.SendDeviceEvent(ctx, &de, equipment, pon, raisedTs); err != nil { |
| 2670 | logger.Warnw(ctx, "could not send ONU_ACTIVATED event", |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2671 | log.Fields{"device-id": aDeviceID, "error": err}) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2672 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2673 | logger.Debugw(ctx, "ctx, ONU_ACTIVATED event sent to KAFKA", |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2674 | log.Fields{"device-id": aDeviceID, "with-EventName": de.DeviceEventName}) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2677 | // createUniLockFsm initializes and runs the UniLock FSM to transfer the OMCI related commands for port lock/unlock |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2678 | func (dh *deviceHandler) createUniLockFsm(ctx context.Context, aAdminState bool, devEvent cmn.OnuDeviceEvent) { |
| 2679 | chLSFsm := make(chan cmn.Message, 2048) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2680 | var sFsmName string |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2681 | if aAdminState { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2682 | logger.Debugw(ctx, "createLockStateFSM", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2683 | sFsmName = "LockStateFSM" |
| 2684 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2685 | logger.Debugw(ctx, "createUnlockStateFSM", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2686 | sFsmName = "UnLockStateFSM" |
| 2687 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2688 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2689 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2690 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2691 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2692 | return |
| 2693 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2694 | pLSFsm := uniprt.NewLockStateFsm(ctx, aAdminState, devEvent, sFsmName, dh, pDevEntry, chLSFsm) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2695 | if pLSFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2696 | if aAdminState { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2697 | dh.pLockStateFsm = pLSFsm |
| 2698 | } else { |
| 2699 | dh.pUnlockStateFsm = pLSFsm |
| 2700 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2701 | dh.runUniLockFsm(ctx, aAdminState) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2702 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2703 | logger.Errorw(ctx, "LockStateFSM could not be created - abort!!", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | // runUniLockFsm starts the UniLock FSM to transfer the OMCI related commands for port lock/unlock |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2708 | func (dh *deviceHandler) runUniLockFsm(ctx context.Context, aAdminState bool) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2709 | /* Uni Port lock/unlock procedure - |
| 2710 | ***** should run via 'adminDone' state and generate the argument requested event ***** |
| 2711 | */ |
| 2712 | var pLSStatemachine *fsm.FSM |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2713 | if aAdminState { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2714 | pLSStatemachine = dh.pLockStateFsm.PAdaptFsm.PFsm |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2715 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 2716 | if (dh.pUnlockStateFsm != nil) && |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2717 | (dh.pUnlockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) { |
| 2718 | _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2719 | } |
| 2720 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2721 | pLSStatemachine = dh.pUnlockStateFsm.PAdaptFsm.PFsm |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2722 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 2723 | if (dh.pLockStateFsm != nil) && |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2724 | (dh.pLockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) { |
| 2725 | _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2726 | } |
| 2727 | } |
| 2728 | if pLSStatemachine != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2729 | if pLSStatemachine.Is(uniprt.UniStDisabled) { |
| 2730 | if err := pLSStatemachine.Event(uniprt.UniEvStart); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2731 | logger.Warnw(ctx, "LockStateFSM: can't start", log.Fields{"err": err}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2732 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2733 | } else { |
| 2734 | /***** LockStateFSM started */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2735 | logger.Debugw(ctx, "LockStateFSM started", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2736 | "state": pLSStatemachine.Current(), "device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2737 | } |
| 2738 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2739 | logger.Warnw(ctx, "wrong state of LockStateFSM - want: disabled", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2740 | "have": pLSStatemachine.Current(), "device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2741 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2742 | } |
| 2743 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2744 | logger.Errorw(ctx, "LockStateFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2745 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2746 | } |
| 2747 | } |
| 2748 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2749 | // createOnuUpgradeFsm initializes and runs the Onu Software upgrade FSM |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2750 | // precondition: lockUpgradeFsm is already locked from caller of this function |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2751 | func (dh *deviceHandler) createOnuUpgradeFsm(ctx context.Context, apDevEntry *mib.OnuDeviceEntry, aDevEvent cmn.OnuDeviceEvent) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2752 | chUpgradeFsm := make(chan cmn.Message, 2048) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2753 | var sFsmName = "OnuSwUpgradeFSM" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2754 | logger.Debugw(ctx, "create OnuSwUpgradeFSM", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2755 | if apDevEntry.PDevOmciCC == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2756 | logger.Errorw(ctx, "no valid OnuDevice or omciCC - abort", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2757 | return fmt.Errorf(fmt.Sprintf("no valid omciCC - abort for device-id: %s", dh.device.Id)) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2758 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2759 | dh.pOnuUpradeFsm = swupg.NewOnuUpgradeFsm(ctx, dh, apDevEntry, apDevEntry.GetOnuDB(), aDevEvent, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2760 | sFsmName, chUpgradeFsm) |
| 2761 | if dh.pOnuUpradeFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2762 | pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2763 | if pUpgradeStatemachine != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2764 | if pUpgradeStatemachine.Is(swupg.UpgradeStDisabled) { |
| 2765 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvStart); err != nil { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2766 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't start", log.Fields{"err": err}) |
| 2767 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2768 | return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be started for device-id: %s", dh.device.Id)) |
| 2769 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2770 | /***** Upgrade FSM started */ |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 2771 | //reset the last stored upgrade states (which anyway should be don't care as long as the newly created FSM exists) |
| 2772 | (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2773 | (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR |
| 2774 | (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2775 | logger.Debugw(ctx, "OnuSwUpgradeFSM started", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2776 | "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2777 | } else { |
| 2778 | logger.Errorw(ctx, "wrong state of OnuSwUpgradeFSM to start - want: disabled", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2779 | "have": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2780 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2781 | return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be started for device-id: %s, wrong internal state", dh.device.Id)) |
| 2782 | } |
| 2783 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2784 | logger.Errorw(ctx, "OnuSwUpgradeFSM internal FSM invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2785 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2786 | return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM internal FSM could not be created for device-id: %s", dh.device.Id)) |
| 2787 | } |
| 2788 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2789 | logger.Errorw(ctx, "OnuSwUpgradeFSM could not be created - abort", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2790 | return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be created - abort for device-id: %s", dh.device.Id)) |
| 2791 | } |
| 2792 | return nil |
| 2793 | } |
| 2794 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2795 | // RemoveOnuUpgradeFsm clears the Onu Software upgrade FSM |
| 2796 | func (dh *deviceHandler) RemoveOnuUpgradeFsm(ctx context.Context, apImageState *voltha.ImageState) { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2797 | logger.Debugw(ctx, "remove OnuSwUpgradeFSM StateMachine", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2798 | "device-id": dh.DeviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2799 | dh.lockUpgradeFsm.Lock() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2800 | dh.pOnuUpradeFsm = nil //resource clearing is left to garbage collector |
| 2801 | dh.upgradeCanceled = false //cancelation done |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2802 | dh.pLastUpgradeImageState = apImageState |
| 2803 | dh.lockUpgradeFsm.Unlock() |
| 2804 | //signal upgradeFsm removed using non-blocking channel send |
| 2805 | select { |
| 2806 | case dh.upgradeFsmChan <- struct{}{}: |
| 2807 | default: |
| 2808 | logger.Debugw(ctx, "removed-UpgradeFsm signal not send on upgradeFsmChan (no receiver)", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2809 | "device-id": dh.DeviceID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2810 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2811 | } |
| 2812 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2813 | // checkOnOnuImageCommit verifies if the ONU is in some upgrade state that allows for image commit and if tries to commit |
| 2814 | func (dh *deviceHandler) checkOnOnuImageCommit(ctx context.Context) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2815 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2816 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2817 | logger.Errorw(ctx, "No valid OnuDevice -aborting checkOnOnuImageCommit", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2818 | return |
| 2819 | } |
| 2820 | |
| 2821 | dh.lockUpgradeFsm.RLock() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2822 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2823 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2824 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 2825 | dh.lockUpgradeFsm.RUnlock() |
| 2826 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 2827 | return |
| 2828 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2829 | pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2830 | if pUpgradeStatemachine != nil { |
| 2831 | // commit is only processed in case out upgrade FSM indicates the according state (for automatic commit) |
| 2832 | // (some manual forced commit could do without) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2833 | UpgradeState := pUpgradeStatemachine.Current() |
| 2834 | if (UpgradeState == swupg.UpgradeStWaitForCommit) || |
| 2835 | (UpgradeState == swupg.UpgradeStRequestingActivate) { |
| 2836 | // also include UpgradeStRequestingActivate as it may be left in case the ActivateResponse just got lost |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 2837 | // here no need to update the upgrade image state to activated as the state will be immediately be set to committing |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2838 | if pDevEntry.IsImageToBeCommitted(ctx, dh.pOnuUpradeFsm.InactiveImageMeID) { |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2839 | activeImageID, errImg := pDevEntry.GetActiveImageMeID(ctx) |
| 2840 | if errImg != nil { |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2841 | dh.lockUpgradeFsm.RUnlock() |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2842 | logger.Errorw(ctx, "OnuSwUpgradeFSM abort - could not get active image after reboot", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2843 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2844 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 2845 | dh.upgradeCanceled = true |
| 2846 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 2847 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2848 | return |
| 2849 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2850 | dh.lockUpgradeFsm.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2851 | if activeImageID == dh.pOnuUpradeFsm.InactiveImageMeID { |
| 2852 | if (UpgradeState == swupg.UpgradeStRequestingActivate) && !dh.pOnuUpradeFsm.GetCommitFlag(ctx) { |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2853 | // if FSM was waiting on activateResponse, new image is active, but FSM shall not commit, then: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2854 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvActivationDone); err != nil { |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2855 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call activate-done event", log.Fields{"err": err}) |
| 2856 | return |
| 2857 | } |
| 2858 | logger.Debugw(ctx, "OnuSwUpgradeFSM activate-done after reboot", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2859 | "state": UpgradeState, "device-id": dh.DeviceID}) |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2860 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2861 | //FSM in waitForCommit or (UpgradeStRequestingActivate [lost ActivateResp] and commit allowed) |
| 2862 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvCommitSw); err != nil { |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2863 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call commit event", log.Fields{"err": err}) |
| 2864 | return |
| 2865 | } |
| 2866 | logger.Debugw(ctx, "OnuSwUpgradeFSM commit image requested", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2867 | "state": UpgradeState, "device-id": dh.DeviceID}) |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2868 | } |
| 2869 | } else { |
| 2870 | logger.Errorw(ctx, "OnuSwUpgradeFSM waiting to commit/on ActivateResponse, but load did not start with expected image Id", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2871 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 2872 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 2873 | dh.upgradeCanceled = true |
| 2874 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 2875 | } |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2876 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2877 | return |
| 2878 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2879 | dh.lockUpgradeFsm.RUnlock() |
| 2880 | logger.Errorw(ctx, "OnuSwUpgradeFSM waiting to commit, but nothing to commit on ONU - abort upgrade", |
| 2881 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | a2b288f | 2021-10-21 11:25:27 +0000 | [diff] [blame] | 2882 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 2883 | dh.upgradeCanceled = true |
| 2884 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 2885 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2886 | return |
| 2887 | } |
| 2888 | //upgrade FSM is active but not waiting for commit: maybe because commit flag is not set |
| 2889 | // upgrade FSM is to be informed if the current active image is the one that was used in upgrade for the download |
| 2890 | if activeImageID, err := pDevEntry.GetActiveImageMeID(ctx); err == nil { |
| 2891 | if dh.pOnuUpradeFsm.InactiveImageMeID == activeImageID { |
| 2892 | logger.Debugw(ctx, "OnuSwUpgradeFSM image state set to activated", log.Fields{ |
| 2893 | "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
| 2894 | dh.pOnuUpradeFsm.SetImageStateActive(ctx) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 2895 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2896 | } |
| 2897 | } |
| 2898 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2899 | logger.Debugw(ctx, "no ONU image to be committed", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2900 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 2901 | dh.lockUpgradeFsm.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2902 | } |
| 2903 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2904 | //SetBackend provides a DB backend for the specified path on the existing KV client |
| 2905 | func (dh *deviceHandler) SetBackend(ctx context.Context, aBasePathKvStore string) *db.Backend { |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 2906 | |
| 2907 | logger.Debugw(ctx, "SetKVStoreBackend", log.Fields{"IpTarget": dh.pOpenOnuAc.KVStoreAddress, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2908 | "BasePathKvStore": aBasePathKvStore, "device-id": dh.DeviceID}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 2909 | // kvbackend := db.NewBackend(ctx, dh.pOpenOnuAc.KVStoreType, dh.pOpenOnuAc.KVStoreAddress, dh.pOpenOnuAc.KVStoreTimeout, aBasePathKvStore) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 2910 | kvbackend := &db.Backend{ |
| 2911 | Client: dh.pOpenOnuAc.kvClient, |
| 2912 | StoreType: dh.pOpenOnuAc.KVStoreType, |
| 2913 | /* address config update acc. to [VOL-2736] */ |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 2914 | Address: dh.pOpenOnuAc.KVStoreAddress, |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 2915 | Timeout: dh.pOpenOnuAc.KVStoreTimeout, |
| 2916 | PathPrefix: aBasePathKvStore} |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 2917 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 2918 | return kvbackend |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2919 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2920 | func (dh *deviceHandler) getFlowOfbFields(ctx context.Context, apFlowItem *of.OfpFlowStats, loMatchVlan *uint16, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2921 | loAddPcp *uint8, loIPProto *uint32) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2922 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2923 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 2924 | switch field.Type { |
| 2925 | case of.OxmOfbFieldTypes_OFPXMT_OFB_ETH_TYPE: |
| 2926 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2927 | logger.Debugw(ctx, "flow type EthType", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2928 | "EthType": strconv.FormatInt(int64(field.GetEthType()), 16)}) |
| 2929 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2930 | /* TT related temporary workaround - should not be needed anymore |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2931 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO: |
| 2932 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2933 | *loIPProto = field.GetIpProto() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2934 | logger.Debugw("flow type IpProto", log.Fields{"device-id": dh.DeviceID, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2935 | "IpProto": strconv.FormatInt(int64(*loIPProto), 16)}) |
| 2936 | if *loIPProto == 2 { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2937 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 2938 | // avoids installing invalid EVTOCD rule |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2939 | logger.Debugw("flow type IpProto 2: TT workaround: ignore flow", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2940 | log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2941 | return |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2942 | } |
| 2943 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2944 | */ |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2945 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID: |
| 2946 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2947 | *loMatchVlan = uint16(field.GetVlanVid()) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2948 | loMatchVlanMask := uint16(field.GetVlanVidMask()) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2949 | if !(*loMatchVlan == uint16(of.OfpVlanId_OFPVID_PRESENT) && |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2950 | loMatchVlanMask == uint16(of.OfpVlanId_OFPVID_PRESENT)) { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2951 | *loMatchVlan = *loMatchVlan & 0xFFF // not transparent: copy only ID bits |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2952 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2953 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2954 | "VID": strconv.FormatInt(int64(*loMatchVlan), 16)}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2955 | } |
| 2956 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP: |
| 2957 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2958 | *loAddPcp = uint8(field.GetVlanPcp()) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2959 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2960 | "PCP": loAddPcp}) |
| 2961 | } |
| 2962 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_DST: |
| 2963 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2964 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2965 | "UDP-DST": strconv.FormatInt(int64(field.GetUdpDst()), 16)}) |
| 2966 | } |
| 2967 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_SRC: |
| 2968 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2969 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2970 | "UDP-SRC": strconv.FormatInt(int64(field.GetUdpSrc()), 16)}) |
| 2971 | } |
| 2972 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_DST: |
| 2973 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2974 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2975 | "IPv4-DST": field.GetIpv4Dst()}) |
| 2976 | } |
| 2977 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_SRC: |
| 2978 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2979 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2980 | "IPv4-SRC": field.GetIpv4Src()}) |
| 2981 | } |
| 2982 | case of.OxmOfbFieldTypes_OFPXMT_OFB_METADATA: |
| 2983 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2984 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2985 | "Metadata": field.GetTableMetadata()}) |
| 2986 | } |
| 2987 | /* |
| 2988 | default: |
| 2989 | { |
| 2990 | //all other entires ignored |
| 2991 | } |
| 2992 | */ |
| 2993 | } |
| 2994 | } //for all OfbFields |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2995 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2996 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2997 | func (dh *deviceHandler) getFlowActions(ctx context.Context, apFlowItem *of.OfpFlowStats, loSetPcp *uint8, loSetVlan *uint16) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2998 | for _, action := range flow.GetActions(apFlowItem) { |
| 2999 | switch action.Type { |
| 3000 | /* not used: |
| 3001 | case of.OfpActionType_OFPAT_OUTPUT: |
| 3002 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3003 | logger.Debugw("flow action type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3004 | "Output": action.GetOutput()}) |
| 3005 | } |
| 3006 | */ |
| 3007 | case of.OfpActionType_OFPAT_PUSH_VLAN: |
| 3008 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3009 | logger.Debugw(ctx, "flow action type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3010 | "PushEthType": strconv.FormatInt(int64(action.GetPush().Ethertype), 16)}) |
| 3011 | } |
| 3012 | case of.OfpActionType_OFPAT_SET_FIELD: |
| 3013 | { |
| 3014 | pActionSetField := action.GetSetField() |
| 3015 | if pActionSetField.Field.OxmClass != of.OfpOxmClass_OFPXMC_OPENFLOW_BASIC { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3016 | logger.Warnw(ctx, "flow action SetField invalid OxmClass (ignored)", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3017 | "OxcmClass": pActionSetField.Field.OxmClass}) |
| 3018 | } |
| 3019 | if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3020 | *loSetVlan = uint16(pActionSetField.Field.GetOfbField().GetVlanVid()) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3021 | logger.Debugw(ctx, "flow Set VLAN from SetField action", log.Fields{"device-id": dh.DeviceID, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3022 | "SetVlan": strconv.FormatInt(int64(*loSetVlan), 16)}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3023 | } else if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3024 | *loSetPcp = uint8(pActionSetField.Field.GetOfbField().GetVlanPcp()) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3025 | logger.Debugw(ctx, "flow Set PCP from SetField action", log.Fields{"device-id": dh.DeviceID, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3026 | "SetPcp": *loSetPcp}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3027 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3028 | logger.Warnw(ctx, "flow action SetField invalid FieldType", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3029 | "Type": pActionSetField.Field.GetOfbField().Type}) |
| 3030 | } |
| 3031 | } |
| 3032 | /* |
| 3033 | default: |
| 3034 | { |
| 3035 | //all other entires ignored |
| 3036 | } |
| 3037 | */ |
| 3038 | } |
| 3039 | } //for all Actions |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | //addFlowItemToUniPort parses the actual flow item to add it to the UniPort |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3043 | func (dh *deviceHandler) addFlowItemToUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort, |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3044 | apFlowMetaData *voltha.FlowMetadata, respChan *chan error) { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3045 | var loSetVlan uint16 = uint16(of.OfpVlanId_OFPVID_NONE) //noValidEntry |
| 3046 | var loMatchVlan uint16 = uint16(of.OfpVlanId_OFPVID_PRESENT) //reserved VLANID entry |
| 3047 | var loAddPcp, loSetPcp uint8 |
| 3048 | var loIPProto uint32 |
| 3049 | /* the TechProfileId is part of the flow Metadata - compare also comment within |
| 3050 | * OLT-Adapter:openolt_flowmgr.go |
| 3051 | * Metadata 8 bytes: |
| 3052 | * Most Significant 2 Bytes = Inner VLAN |
| 3053 | * Next 2 Bytes = Tech Profile ID(TPID) |
| 3054 | * Least Significant 4 Bytes = Port ID |
| 3055 | * Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all |
| 3056 | * subscriber related flows. |
| 3057 | */ |
| 3058 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3059 | metadata := flow.GetMetadataFromWriteMetadataAction(ctx, apFlowItem) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3060 | if metadata == 0 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3061 | logger.Debugw(ctx, "flow-add invalid metadata - abort", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3062 | log.Fields{"device-id": dh.DeviceID}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3063 | *respChan <- fmt.Errorf("flow-add invalid metadata: %s", dh.DeviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3064 | } |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3065 | loTpID := uint8(flow.GetTechProfileIDFromWriteMetaData(ctx, metadata)) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3066 | loCookie := apFlowItem.GetCookie() |
| 3067 | loCookieSlice := []uint64{loCookie} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3068 | logger.Debugw(ctx, "flow-add base indications", log.Fields{"device-id": dh.DeviceID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3069 | "TechProf-Id": loTpID, "cookie": loCookie}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3070 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3071 | dh.getFlowOfbFields(ctx, apFlowItem, &loMatchVlan, &loAddPcp, &loIPProto) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3072 | /* TT related temporary workaround - should not be needed anymore |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3073 | if loIPProto == 2 { |
| 3074 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 3075 | // avoids installing invalid EVTOCD rule |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3076 | logger.Debugw("flow-add type IpProto 2: TT workaround: ignore flow", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3077 | log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3078 | return nil |
| 3079 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3080 | */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3081 | dh.getFlowActions(ctx, apFlowItem, &loSetPcp, &loSetVlan) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3082 | |
| 3083 | if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3084 | logger.Errorw(ctx, "flow-add aborted - SetVlanId undefined, but MatchVid set", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3085 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3086 | "set_vid": strconv.FormatInt(int64(loSetVlan), 16), |
| 3087 | "match_vid": strconv.FormatInt(int64(loMatchVlan), 16)}) |
| 3088 | //TODO!!: Use DeviceId within the error response to rwCore |
| 3089 | // likewise also in other error response cases to calling components as requested in [VOL-3458] |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3090 | *respChan <- fmt.Errorf("flow-add Set/Match VlanId inconsistent: %s", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3091 | } |
| 3092 | if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan == uint16(of.OfpVlanId_OFPVID_PRESENT) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3093 | logger.Debugw(ctx, "flow-add vlan-any/copy", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3094 | loSetVlan = loMatchVlan //both 'transparent' (copy any) |
| 3095 | } else { |
| 3096 | //looks like OMCI value 4097 (copyFromOuter - for Uni double tagged) is not supported here |
| 3097 | if loSetVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
| 3098 | // not set to transparent |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3099 | loSetVlan &= 0x0FFF //mask VID bits as prerequisite for vlanConfigFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3100 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3101 | logger.Debugw(ctx, "flow-add vlan-set", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3102 | } |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3103 | |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3104 | var meter *voltha.OfpMeterConfig |
| 3105 | if apFlowMetaData != nil { |
| 3106 | meter = apFlowMetaData.Meters[0] |
| 3107 | } |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3108 | //mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities |
| 3109 | // must be set including the execution of createVlanFilterFsm() to avoid unintended creation of FSM's |
| 3110 | // when different rules are requested concurrently for the same uni |
| 3111 | // (also vlan persistency data does not support multiple FSM's on the same UNI correctly!) |
| 3112 | dh.lockVlanAdd.Lock() //prevent multiple add activities to start in parallel |
| 3113 | dh.lockVlanConfig.RLock() //read protection on UniVlanConfigFsmMap (removeFlowItemFromUniPort) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3114 | logger.Debugw(ctx, "flow-add got lock", log.Fields{"device-id": dh.DeviceID, "tpID": loTpID, "uniID": apUniPort.UniID}) |
| 3115 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3116 | //SetUniFlowParams() may block on some rule that is suspended-to-add |
| 3117 | // in order to allow for according flow removal lockVlanConfig may only be used with RLock here |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3118 | // Also the error is returned to caller via response channel |
| 3119 | _ = dh.UniVlanConfigFsmMap[apUniPort.UniID].SetUniFlowParams(ctx, loTpID, loCookieSlice, |
| 3120 | loMatchVlan, loSetVlan, loSetPcp, false, meter, respChan) |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3121 | dh.lockVlanConfig.RUnlock() |
| 3122 | dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3123 | return |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3124 | } |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3125 | dh.lockVlanConfig.RUnlock() |
| 3126 | dh.lockVlanConfig.Lock() //createVlanFilterFsm should always be a non-blocking operation and requires r+w lock |
mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3127 | err := dh.createVlanFilterFsm(ctx, apUniPort, loTpID, loCookieSlice, |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3128 | loMatchVlan, loSetVlan, loSetPcp, cmn.OmciVlanFilterAddDone, false, meter, respChan) |
mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3129 | dh.lockVlanConfig.Unlock() |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3130 | dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3131 | if err != nil { |
| 3132 | *respChan <- err |
| 3133 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | //removeFlowItemFromUniPort parses the actual flow item to remove it from the UniPort |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3137 | func (dh *deviceHandler) removeFlowItemFromUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort, respChan *chan error) { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3138 | //optimization and assumption: the flow cookie uniquely identifies the flow and with that the internal rule |
| 3139 | //hence only the cookie is used here to find the relevant flow and possibly remove the rule |
| 3140 | //no extra check is done on the rule parameters |
| 3141 | //accordingly the removal is done only once - for the first found flow with that cookie, even though |
| 3142 | // at flow creation is not assured, that the same cookie is not configured for different flows - just assumed |
| 3143 | //additionally it is assumed here, that removal can only be done for one cookie per flow in a sequence (different |
| 3144 | // from addFlow - where at reconcilement multiple cookies per flow ) can be configured in one sequence) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3145 | // - some possible 'delete-all' sequence would have to be implemented separately (where the cookies are don't care anyway) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3146 | loCookie := apFlowItem.GetCookie() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3147 | logger.Debugw(ctx, "flow-remove base indications", log.Fields{"device-id": dh.DeviceID, "cookie": loCookie}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3148 | |
| 3149 | /* TT related temporary workaround - should not be needed anymore |
| 3150 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 3151 | if field.Type == of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO { |
| 3152 | loIPProto := field.GetIpProto() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3153 | logger.Debugw(ctx, "flow type IpProto", log.Fields{"device-id": dh.DeviceID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3154 | "IpProto": strconv.FormatInt(int64(loIPProto), 16)}) |
| 3155 | if loIPProto == 2 { |
| 3156 | // some workaround for TT workflow on proto == 2 (IGMP trap) -> the flow was not added, no need to remove |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3157 | logger.Debugw(ctx, "flow-remove type IpProto 2: TT workaround: ignore flow", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3158 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3159 | return nil |
| 3160 | } |
| 3161 | } |
| 3162 | } //for all OfbFields |
| 3163 | */ |
| 3164 | |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3165 | //mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3166 | dh.lockVlanConfig.RLock() |
| 3167 | defer dh.lockVlanConfig.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3168 | logger.Debugw(ctx, "flow-remove got RLock", log.Fields{"device-id": dh.DeviceID, "uniID": apUniPort.UniID}) |
| 3169 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3170 | _ = dh.UniVlanConfigFsmMap[apUniPort.UniID].RemoveUniFlowParams(ctx, loCookie, respChan) |
| 3171 | return |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3172 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3173 | logger.Debugw(ctx, "flow-remove called, but no flow is configured (no VlanConfigFsm, flow already removed) ", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3174 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3175 | //but as we regard the flow as not existing = removed we respond just ok |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3176 | // and treat the reason accordingly (which in the normal removal procedure is initiated by the FSM) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3177 | // Push response on the response channel |
| 3178 | if respChan != nil { |
| 3179 | // Do it in a non blocking fashion, so that in case the flow handler routine has shutdown for any reason, we do not block here |
| 3180 | select { |
| 3181 | case *respChan <- nil: |
| 3182 | logger.Debugw(ctx, "submitted-response-for-flow", log.Fields{"device-id": dh.DeviceID, "err": nil}) |
| 3183 | default: |
| 3184 | } |
| 3185 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3186 | go dh.DeviceProcStatusUpdate(ctx, cmn.OmciVlanFilterRemDone) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3187 | } |
| 3188 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3189 | // createVlanFilterFsm initializes and runs the VlanFilter FSM to transfer OMCI related VLAN config |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3190 | // if this function is called from possibly concurrent processes it must be mutex-protected from the caller! |
mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3191 | // precondition: dh.lockVlanConfig is locked by the caller! |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3192 | func (dh *deviceHandler) createVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8, aCookieSlice []uint64, |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3193 | aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8, aDevEvent cmn.OnuDeviceEvent, lastFlowToReconcile bool, aMeter *voltha.OfpMeterConfig, respChan *chan error) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3194 | chVlanFilterFsm := make(chan cmn.Message, 2048) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3195 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3196 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3197 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3198 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 3199 | return fmt.Errorf("no valid OnuDevice for device-id %x - aborting", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3200 | } |
| 3201 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3202 | pVlanFilterFsm := avcfg.NewUniVlanConfigFsm(ctx, dh, pDevEntry, pDevEntry.PDevOmciCC, apUniPort, dh.pOnuTP, |
| 3203 | pDevEntry.GetOnuDB(), aTpID, aDevEvent, "UniVlanConfigFsm", chVlanFilterFsm, |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3204 | dh.pOpenOnuAc.AcceptIncrementalEvto, aCookieSlice, aMatchVlan, aSetVlan, aSetPcp, lastFlowToReconcile, aMeter, respChan) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3205 | if pVlanFilterFsm != nil { |
mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3206 | //dh.lockVlanConfig is locked (by caller) throughout the state transition to 'starting' |
| 3207 | // to prevent unintended (ignored) events to be sent there (from parallel processing) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3208 | dh.UniVlanConfigFsmMap[apUniPort.UniID] = pVlanFilterFsm |
| 3209 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3210 | if pVlanFilterStatemachine != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3211 | if pVlanFilterStatemachine.Is(avcfg.VlanStDisabled) { |
| 3212 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvStart); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3213 | logger.Warnw(ctx, "UniVlanConfigFsm: can't start", log.Fields{"err": err}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3214 | return fmt.Errorf("can't start UniVlanConfigFsm for device-id %x", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3215 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3216 | /***** UniVlanConfigFsm started */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3217 | logger.Debugw(ctx, "UniVlanConfigFsm started", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3218 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3219 | "UniPort": apUniPort.PortNo}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3220 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3221 | logger.Warnw(ctx, "wrong state of UniVlanConfigFsm - want: disabled", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3222 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID}) |
| 3223 | return fmt.Errorf("uniVlanConfigFsm not in expected disabled state for device-id %x", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3224 | } |
| 3225 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3226 | logger.Errorw(ctx, "UniVlanConfigFsm StateMachine invalid - cannot be executed!!", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3227 | "device-id": dh.DeviceID}) |
| 3228 | return fmt.Errorf("uniVlanConfigFsm invalid for device-id %x", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3229 | } |
| 3230 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3231 | logger.Errorw(ctx, "UniVlanConfigFsm could not be created - abort!!", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3232 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| 3233 | return fmt.Errorf("uniVlanConfigFsm could not be created for device-id %x", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3234 | } |
| 3235 | return nil |
| 3236 | } |
| 3237 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3238 | //VerifyVlanConfigRequest checks on existence of a given uniPort |
| 3239 | // and starts verification of flow config based on that |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3240 | func (dh *deviceHandler) VerifyVlanConfigRequest(ctx context.Context, aUniID uint8, aTpID uint8) { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3241 | //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3242 | var pCurrentUniPort *cmn.OnuUniPort |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3243 | for _, uniPort := range dh.uniEntityMap { |
| 3244 | // only if this port is validated for operState transfer |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3245 | if uniPort.UniID == uint8(aUniID) { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3246 | pCurrentUniPort = uniPort |
| 3247 | break //found - end search loop |
| 3248 | } |
| 3249 | } |
| 3250 | if pCurrentUniPort == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3251 | logger.Debugw(ctx, "VerifyVlanConfig aborted: requested uniID not found in PortDB", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3252 | log.Fields{"device-id": dh.DeviceID, "uni-id": aUniID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3253 | return |
| 3254 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3255 | dh.VerifyUniVlanConfigRequest(ctx, pCurrentUniPort, aTpID) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3256 | } |
| 3257 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3258 | //VerifyUniVlanConfigRequest checks on existence of flow configuration and starts it accordingly |
| 3259 | func (dh *deviceHandler) VerifyUniVlanConfigRequest(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3260 | //TODO!! verify and start pending flow configuration |
| 3261 | //some pending config request my exist in case the UniVlanConfig FSM was already started - with internal data - |
| 3262 | //but execution was set to 'on hold' as first the TechProfile config had to be applied |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3263 | |
| 3264 | dh.lockVlanConfig.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3265 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3266 | dh.lockVlanConfig.RUnlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3267 | //VlanFilterFsm exists and was already started (assumed to wait for TechProfile execution here) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3268 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3269 | if pVlanFilterStatemachine != nil { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3270 | //if this was an event of the TP processing that was waited for in the VlanFilterFsm |
| 3271 | if pVlanFilterFsm.GetWaitingTpID() == aTpID { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3272 | if pVlanFilterStatemachine.Is(avcfg.VlanStWaitingTechProf) { |
| 3273 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvContinueConfig); err != nil { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3274 | logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3275 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3276 | } else { |
| 3277 | /***** UniVlanConfigFsm continued */ |
| 3278 | logger.Debugw(ctx, "UniVlanConfigFsm continued", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3279 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3280 | "UniPort": apUniPort.PortNo}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3281 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3282 | } else if pVlanFilterStatemachine.Is(avcfg.VlanStIncrFlowWaitTP) { |
| 3283 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvIncrFlowConfig); err != nil { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3284 | logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3285 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3286 | } else { |
| 3287 | /***** UniVlanConfigFsm continued */ |
| 3288 | logger.Debugw(ctx, "UniVlanConfigFsm continued with incremental flow", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3289 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3290 | "UniPort": apUniPort.PortNo}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3291 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3292 | } else { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3293 | logger.Debugw(ctx, "no state of UniVlanConfigFsm to be continued", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3294 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3295 | "UniPort": apUniPort.PortNo}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3296 | } |
| 3297 | } else { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3298 | logger.Debugw(ctx, "TechProfile Ready event for TpId that was not waited for in the VlanConfigFsm - continue waiting", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3299 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3300 | "UniPort": apUniPort.PortNo, "techprofile-id (done)": aTpID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3301 | } |
| 3302 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3303 | logger.Debugw(ctx, "UniVlanConfigFsm StateMachine does not exist, no flow processing", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3304 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3305 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3306 | } else { |
| 3307 | dh.lockVlanConfig.RUnlock() |
| 3308 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3309 | } |
| 3310 | |
| 3311 | //RemoveVlanFilterFsm deletes the stored pointer to the VlanConfigFsm |
| 3312 | // intention is to provide this method to be called from VlanConfigFsm itself, when resources (and methods!) are cleaned up |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3313 | func (dh *deviceHandler) RemoveVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3314 | logger.Debugw(ctx, "remove UniVlanConfigFsm StateMachine", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3315 | "device-id": dh.DeviceID, "uniPort": apUniPort.PortNo}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3316 | //save to do, even if entry dows not exist |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3317 | dh.lockVlanConfig.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3318 | delete(dh.UniVlanConfigFsmMap, apUniPort.UniID) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3319 | dh.lockVlanConfig.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3320 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3321 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3322 | //startWritingOnuDataToKvStore initiates the KVStore write of ONU persistent data |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3323 | func (dh *deviceHandler) startWritingOnuDataToKvStore(ctx context.Context, aPDevEntry *mib.OnuDeviceEntry) error { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3324 | dh.mutexKvStoreContext.Lock() //this write routine may (could) be called with the same context, |
| 3325 | defer dh.mutexKvStoreContext.Unlock() //this write routine may (could) be called with the same context, |
| 3326 | // obviously then parallel processing on the cancel must be avoided |
| 3327 | // deadline context to ensure completion of background routines waited for |
| 3328 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 3329 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 3330 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 3331 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3332 | aPDevEntry.ResetKvProcessingErrorIndication() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3333 | var wg sync.WaitGroup |
| 3334 | wg.Add(1) // for the 1 go routine to finish |
| 3335 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3336 | go aPDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3337 | dh.waitForCompletion(ctx, cancel, &wg, "UpdateKvStore") //wait for background process to finish |
| 3338 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3339 | return aPDevEntry.GetKvProcessingErrorIndication() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3340 | } |
| 3341 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3342 | //StorePersUniFlowConfig updates local storage of OnuUniFlowConfig and writes it into kv-store afterwards to have it |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3343 | //available for potential reconcilement |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3344 | func (dh *deviceHandler) StorePersUniFlowConfig(ctx context.Context, aUniID uint8, |
| 3345 | aUniVlanFlowParams *[]cmn.UniVlanFlowParams, aWriteToKvStore bool) error { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3346 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3347 | if dh.IsReconciling() { |
| 3348 | logger.Debugw(ctx, "reconciling - don't store persistent UniFlowConfig", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3349 | return nil |
| 3350 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3351 | logger.Debugw(ctx, "Store or clear persistent UniFlowConfig", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3352 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3353 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3354 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3355 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 3356 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3357 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3358 | pDevEntry.UpdateOnuUniFlowConfig(aUniID, aUniVlanFlowParams) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3359 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3360 | if aWriteToKvStore { |
| 3361 | return dh.startWritingOnuDataToKvStore(ctx, pDevEntry) |
| 3362 | } |
| 3363 | return nil |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3364 | } |
| 3365 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3366 | func (dh *deviceHandler) waitForCompletion(ctx context.Context, cancel context.CancelFunc, wg *sync.WaitGroup, aCallerIdent string) { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3367 | defer cancel() //ensure termination of context (may be pro forma) |
| 3368 | wg.Wait() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3369 | logger.Debugw(ctx, "WaitGroup processing completed", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3370 | "device-id": dh.DeviceID, "called from": aCallerIdent}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3371 | } |
| 3372 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3373 | func (dh *deviceHandler) deviceReasonUpdate(ctx context.Context, deviceReason uint8, notifyCore bool) error { |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 3374 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3375 | dh.SetDeviceReason(deviceReason) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3376 | if notifyCore { |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 3377 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing at calling position |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3378 | if err := dh.updateDeviceReasonInCore(ctx, &ic.DeviceReason{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3379 | DeviceId: dh.DeviceID, |
| 3380 | Reason: cmn.DeviceReasonMap[deviceReason], |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3381 | }); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3382 | logger.Errorf(ctx, "DeviceReasonUpdate error: %s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3383 | log.Fields{"device-id": dh.DeviceID, "error": err}, cmn.DeviceReasonMap[deviceReason]) |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 3384 | return err |
| 3385 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3386 | logger.Infof(ctx, "DeviceReasonUpdate success: %s - device-id: %s", cmn.DeviceReasonMap[deviceReason], dh.DeviceID) |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 3387 | return nil |
| 3388 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3389 | logger.Infof(ctx, "Don't notify core about DeviceReasonUpdate: %s - device-id: %s", cmn.DeviceReasonMap[deviceReason], dh.DeviceID) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3390 | return nil |
| 3391 | } |
| 3392 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3393 | func (dh *deviceHandler) StorePersistentData(ctx context.Context) error { |
| 3394 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3395 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3396 | logger.Warnw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 3397 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3398 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3399 | return dh.startWritingOnuDataToKvStore(ctx, pDevEntry) |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 3400 | } |
| 3401 | |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3402 | // getUniPortMEEntityID takes uniPortNo as the input and returns the Entity ID corresponding to this UNI-G ME Instance |
ozgecanetsia | 72e1c9f | 2021-05-26 17:26:29 +0300 | [diff] [blame] | 3403 | // nolint: unused |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3404 | func (dh *deviceHandler) getUniPortMEEntityID(uniPortNo uint32) (uint16, error) { |
| 3405 | dh.lockDevice.RLock() |
| 3406 | defer dh.lockDevice.RUnlock() |
| 3407 | if uniPort, ok := dh.uniEntityMap[uniPortNo]; ok { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3408 | return uniPort.EntityID, nil |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3409 | } |
| 3410 | return 0, errors.New("error-fetching-uni-port") |
| 3411 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3412 | |
| 3413 | // updatePmConfig updates the pm metrics config. |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3414 | func (dh *deviceHandler) updatePmConfig(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 3415 | var errorsList []error |
| 3416 | logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": dh.device.Id, "new-pm-configs": pmConfigs, "old-pm-config": dh.pmConfigs}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3417 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3418 | errorsList = append(dh.handleGlobalPmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 3419 | errorsList = append(dh.handleGroupPmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 3420 | errorsList = append(dh.handleStandalonePmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 3421 | |
| 3422 | // Note that if more than one pm config field is updated in a given call, it is possible that partial pm config is handled |
| 3423 | // successfully. |
| 3424 | // TODO: Although it is possible to revert to old config in case of partial failure, the code becomes quite complex. Needs more investigation |
| 3425 | // Is it possible the rw-core reverts to old config on partial failure but adapter retains a partial new config? |
| 3426 | if len(errorsList) > 0 { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3427 | logger.Errorw(ctx, "one-or-more-pm-config-failed", log.Fields{"device-id": dh.DeviceID, "pmConfig": dh.pmConfigs}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3428 | return fmt.Errorf("errors-handling-one-or-more-pm-config, errors:%v", errorsList) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3429 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3430 | logger.Infow(ctx, "pm-config-updated", log.Fields{"device-id": dh.DeviceID, "pmConfig": dh.pmConfigs}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3431 | return nil |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3432 | } |
| 3433 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3434 | func (dh *deviceHandler) handleGlobalPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 3435 | var err error |
| 3436 | var errorsList []error |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3437 | logger.Infow(ctx, "handling-global-pm-config-params - start", log.Fields{"device-id": dh.device.Id}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3438 | |
| 3439 | if pmConfigs.DefaultFreq != dh.pmConfigs.DefaultFreq { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3440 | if err = dh.pOnuMetricsMgr.UpdateDefaultFrequency(ctx, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3441 | errorsList = append(errorsList, err) |
| 3442 | } |
| 3443 | } |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3444 | logger.Infow(ctx, "handling-global-pm-config-params - done", log.Fields{"device-id": dh.device.Id}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 3445 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3446 | return errorsList |
| 3447 | } |
| 3448 | |
| 3449 | func (dh *deviceHandler) handleGroupPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 3450 | var err error |
| 3451 | var errorsList []error |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3452 | logger.Debugw(ctx, "handling-group-pm-config-params - start", log.Fields{"device-id": dh.device.Id}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3453 | // Check if group metric related config is updated |
| 3454 | for _, v := range pmConfigs.Groups { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3455 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() |
| 3456 | m, ok := dh.pOnuMetricsMgr.GroupMetricMap[v.GroupName] |
| 3457 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3458 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3459 | if ok && m.Frequency != v.GroupFreq { |
| 3460 | if err = dh.pOnuMetricsMgr.UpdateGroupFreq(ctx, v.GroupName, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3461 | errorsList = append(errorsList, err) |
| 3462 | } |
| 3463 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3464 | if ok && m.Enabled != v.Enabled { |
| 3465 | if err = dh.pOnuMetricsMgr.UpdateGroupSupport(ctx, v.GroupName, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3466 | errorsList = append(errorsList, err) |
| 3467 | } |
| 3468 | } |
| 3469 | } |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3470 | logger.Debugw(ctx, "handling-group-pm-config-params - done", log.Fields{"device-id": dh.device.Id}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3471 | return errorsList |
| 3472 | } |
| 3473 | |
| 3474 | func (dh *deviceHandler) handleStandalonePmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 3475 | var err error |
| 3476 | var errorsList []error |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3477 | logger.Debugw(ctx, "handling-individual-pm-config-params - start", log.Fields{"device-id": dh.device.Id}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3478 | // Check if standalone metric related config is updated |
| 3479 | for _, v := range pmConfigs.Metrics { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3480 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() |
| 3481 | m, ok := dh.pOnuMetricsMgr.StandaloneMetricMap[v.Name] |
| 3482 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3483 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3484 | if ok && m.Frequency != v.SampleFreq { |
| 3485 | if err = dh.pOnuMetricsMgr.UpdateMetricFreq(ctx, v.Name, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3486 | errorsList = append(errorsList, err) |
| 3487 | } |
| 3488 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3489 | if ok && m.Enabled != v.Enabled { |
| 3490 | if err = dh.pOnuMetricsMgr.UpdateMetricSupport(ctx, v.Name, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3491 | errorsList = append(errorsList, err) |
| 3492 | } |
| 3493 | } |
| 3494 | } |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3495 | logger.Debugw(ctx, "handling-individual-pm-config-params - done", log.Fields{"device-id": dh.device.Id}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3496 | return errorsList |
| 3497 | } |
| 3498 | |
| 3499 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3500 | func (dh *deviceHandler) StartCollector(ctx context.Context) { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3501 | logger.Debugf(ctx, "startingCollector") |
| 3502 | |
| 3503 | // Start routine to process OMCI GET Responses |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3504 | go dh.pOnuMetricsMgr.ProcessOmciMessages(ctx) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3505 | // Create Extended Frame PM ME |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3506 | go dh.pOnuMetricsMgr.CreateEthernetFrameExtendedPMME(ctx) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3507 | // Initialize the next metric collection time. |
| 3508 | // Normally done when the onu_metrics_manager is initialized the first time, but needed again later when ONU is |
| 3509 | // reset like onu rebooted. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3510 | dh.pOnuMetricsMgr.InitializeMetricCollectionTime(ctx) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3511 | dh.setCollectorIsRunning(true) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3512 | for { |
| 3513 | select { |
| 3514 | case <-dh.stopCollector: |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3515 | dh.setCollectorIsRunning(false) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3516 | logger.Debugw(ctx, "stopping-collector-for-onu", log.Fields{"device-id": dh.device.Id}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 3517 | // Stop the L2 PM FSM |
| 3518 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3519 | if dh.pOnuMetricsMgr.PAdaptFsm != nil && dh.pOnuMetricsMgr.PAdaptFsm.PFsm != nil { |
| 3520 | if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventStop); err != nil { |
| 3521 | logger.Errorw(ctx, "error calling event", log.Fields{"device-id": dh.DeviceID, "err": err}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 3522 | } |
| 3523 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3524 | logger.Errorw(ctx, "metrics manager fsm not initialized", log.Fields{"device-id": dh.DeviceID}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 3525 | } |
| 3526 | }() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3527 | if dh.pOnuMetricsMgr.GetOmciProcessingStatus() { |
| 3528 | dh.pOnuMetricsMgr.StopProcessingOmciResponses <- true // Stop the OMCI GET response processing routine |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 3529 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3530 | if dh.pOnuMetricsMgr.GetTickGenerationStatus() { |
| 3531 | dh.pOnuMetricsMgr.StopTicks <- true |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 3532 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 3533 | |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3534 | return |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3535 | case <-time.After(time.Duration(pmmgr.FrequencyGranularity) * time.Second): // Check every FrequencyGranularity to see if it is time for collecting metrics |
| 3536 | if !dh.pmConfigs.FreqOverride { // If FreqOverride is false, then NextGlobalMetricCollectionTime applies |
| 3537 | // If the current time is eqaul to or greater than the NextGlobalMetricCollectionTime, collect the group and standalone metrics |
| 3538 | if time.Now().Equal(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) || time.Now().After(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) { |
| 3539 | go dh.pOnuMetricsMgr.CollectAllGroupAndStandaloneMetrics(ctx) |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 3540 | // Update the next metric collection time. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3541 | dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime = time.Now().Add(time.Duration(dh.pmConfigs.DefaultFreq) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3542 | } |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3543 | } else { |
| 3544 | if dh.pmConfigs.Grouped { // metrics are managed as a group |
| 3545 | // parse through the group and standalone metrics to see it is time to collect their metrics |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3546 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() // Rlock as we are reading GroupMetricMap and StandaloneMetricMap |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3547 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3548 | for n, g := range dh.pOnuMetricsMgr.GroupMetricMap { |
| 3549 | // If the group is enabled AND (current time is equal to OR after NextCollectionInterval, collect the group metric) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 3550 | // Since the L2 PM counters are collected in a separate FSM, we should avoid those counters in the check. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3551 | if g.Enabled && !g.IsL2PMCounter && (time.Now().Equal(g.NextCollectionInterval) || time.Now().After(g.NextCollectionInterval)) { |
| 3552 | go dh.pOnuMetricsMgr.CollectGroupMetric(ctx, n) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3553 | } |
| 3554 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3555 | for n, m := range dh.pOnuMetricsMgr.StandaloneMetricMap { |
| 3556 | // If the standalone is enabled AND (current time is equal to OR after NextCollectionInterval, collect the metric) |
| 3557 | if m.Enabled && (time.Now().Equal(m.NextCollectionInterval) || time.Now().After(m.NextCollectionInterval)) { |
| 3558 | go dh.pOnuMetricsMgr.CollectStandaloneMetric(ctx, n) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3559 | } |
| 3560 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3561 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3562 | |
| 3563 | // parse through the group and update the next metric collection time |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3564 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.Lock() // Lock as we are writing the next metric collection time |
| 3565 | for _, g := range dh.pOnuMetricsMgr.GroupMetricMap { |
| 3566 | // If group enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 3567 | // Since the L2 PM counters are collected and managed in a separate FSM, we should avoid those counters in the check. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3568 | if g.Enabled && !g.IsL2PMCounter && (g.NextCollectionInterval.Before(time.Now()) || g.NextCollectionInterval.Equal(time.Now())) { |
| 3569 | g.NextCollectionInterval = time.Now().Add(time.Duration(g.Frequency) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3570 | } |
| 3571 | } |
| 3572 | // parse through the standalone metrics and update the next metric collection time |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3573 | for _, m := range dh.pOnuMetricsMgr.StandaloneMetricMap { |
| 3574 | // If standalone metrics enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp |
| 3575 | if m.Enabled && (m.NextCollectionInterval.Before(time.Now()) || m.NextCollectionInterval.Equal(time.Now())) { |
| 3576 | m.NextCollectionInterval = time.Now().Add(time.Duration(m.Frequency) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3577 | } |
| 3578 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3579 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3580 | } /* else { // metrics are not managed as a group |
| 3581 | // TODO: We currently do not have standalone metrics. When available, add code here to fetch the metric. |
| 3582 | } */ |
| 3583 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3584 | } |
| 3585 | } |
| 3586 | } |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 3587 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3588 | func (dh *deviceHandler) GetUniPortStatus(ctx context.Context, uniInfo *extension.GetOnuUniInfoRequest) *extension.SingleGetValueResponse { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 3589 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3590 | portStatus := uniprt.NewUniPortStatus(dh, dh.pOnuOmciDevice.PDevOmciCC) |
| 3591 | return portStatus.GetUniPortStatus(ctx, uniInfo.UniIndex) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 3592 | } |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3593 | |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3594 | func (dh *deviceHandler) getOnuOMCICounters(ctx context.Context, onuInfo *extension.GetOmciEthernetFrameExtendedPmRequest) *extension.SingleGetValueResponse { |
| 3595 | if dh.pOnuMetricsMgr == nil { |
| 3596 | return &extension.SingleGetValueResponse{ |
| 3597 | Response: &extension.GetValueResponse{ |
| 3598 | Status: extension.GetValueResponse_ERROR, |
| 3599 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 3600 | }, |
| 3601 | } |
| 3602 | } |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame^] | 3603 | resp := dh.pOnuMetricsMgr.CollectEthernetFrameExtendedPMCounters(ctx, onuInfo) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3604 | return resp |
| 3605 | } |
| 3606 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3607 | func (dh *deviceHandler) isFsmInOmciIdleState(ctx context.Context, PFsm *fsm.FSM, wantedState string) bool { |
| 3608 | if PFsm == nil { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3609 | return true //FSM not active - so there is no activity on omci |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3610 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3611 | return PFsm.Current() == wantedState |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3612 | } |
| 3613 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3614 | func (dh *deviceHandler) isFsmInOmciIdleStateDefault(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, wantedState string) bool { |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3615 | var pAdapterFsm *cmn.AdapterFsm |
| 3616 | //note/TODO!!: might be that access to all these specific FSM pointers need a semaphore protection as well, cmp lockUpgradeFsm |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3617 | switch omciFsm { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3618 | case cmn.CUploadFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3619 | { |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3620 | if dh.pOnuOmciDevice != nil { |
| 3621 | pAdapterFsm = dh.pOnuOmciDevice.PMibUploadFsm |
| 3622 | } else { |
| 3623 | return true //FSM not active - so there is no activity on omci |
| 3624 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3625 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3626 | case cmn.CDownloadFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3627 | { |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3628 | if dh.pOnuOmciDevice != nil { |
| 3629 | pAdapterFsm = dh.pOnuOmciDevice.PMibDownloadFsm |
| 3630 | } else { |
| 3631 | return true //FSM not active - so there is no activity on omci |
| 3632 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3633 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3634 | case cmn.CUniLockFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3635 | { |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3636 | if dh.pLockStateFsm != nil { |
| 3637 | pAdapterFsm = dh.pLockStateFsm.PAdaptFsm |
| 3638 | } else { |
| 3639 | return true //FSM not active - so there is no activity on omci |
| 3640 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3641 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3642 | case cmn.CUniUnLockFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3643 | { |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3644 | if dh.pUnlockStateFsm != nil { |
| 3645 | pAdapterFsm = dh.pUnlockStateFsm.PAdaptFsm |
| 3646 | } else { |
| 3647 | return true //FSM not active - so there is no activity on omci |
| 3648 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3649 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3650 | case cmn.CL2PmFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3651 | { |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3652 | if dh.pOnuMetricsMgr != nil { |
| 3653 | pAdapterFsm = dh.pOnuMetricsMgr.PAdaptFsm |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3654 | } else { |
| 3655 | return true //FSM not active - so there is no activity on omci |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3656 | } |
| 3657 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3658 | case cmn.COnuUpgradeFsm: |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3659 | { |
| 3660 | dh.lockUpgradeFsm.RLock() |
| 3661 | defer dh.lockUpgradeFsm.RUnlock() |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3662 | if dh.pOnuUpradeFsm != nil { |
| 3663 | pAdapterFsm = dh.pOnuUpradeFsm.PAdaptFsm |
| 3664 | } else { |
| 3665 | return true //FSM not active - so there is no activity on omci |
| 3666 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3667 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3668 | default: |
| 3669 | { |
| 3670 | logger.Errorw(ctx, "invalid stateMachine selected for idle check", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3671 | "device-id": dh.DeviceID, "selectedFsm number": omciFsm}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3672 | return false //logical error in FSM check, do not not indicate 'idle' - we can't be sure |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3673 | } |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3674 | } |
mpagenko | fbf577d | 2021-10-12 11:44:33 +0000 | [diff] [blame] | 3675 | if pAdapterFsm != nil && pAdapterFsm.PFsm != nil { |
| 3676 | return dh.isFsmInOmciIdleState(ctx, pAdapterFsm.PFsm, wantedState) |
| 3677 | } |
| 3678 | return true //FSM not active - so there is no activity on omci |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3679 | } |
| 3680 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3681 | func (dh *deviceHandler) isAniConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool { |
| 3682 | for _, v := range dh.pOnuTP.PAniConfigFsm { |
| 3683 | if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3684 | return false |
| 3685 | } |
| 3686 | } |
| 3687 | return true |
| 3688 | } |
| 3689 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3690 | func (dh *deviceHandler) isUniVlanConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3691 | dh.lockVlanConfig.RLock() |
| 3692 | defer dh.lockVlanConfig.RUnlock() |
| 3693 | for _, v := range dh.UniVlanConfigFsmMap { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3694 | if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3695 | return false |
| 3696 | } |
| 3697 | } |
| 3698 | return true //FSM not active - so there is no activity on omci |
| 3699 | } |
| 3700 | |
| 3701 | func (dh *deviceHandler) checkUserServiceExists(ctx context.Context) bool { |
| 3702 | dh.lockVlanConfig.RLock() |
| 3703 | defer dh.lockVlanConfig.RUnlock() |
| 3704 | for _, v := range dh.UniVlanConfigFsmMap { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3705 | if v.PAdaptFsm.PFsm != nil { |
| 3706 | if v.PAdaptFsm.PFsm.Is(avcfg.CVlanFsmConfiguredState) { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3707 | return true //there is at least one VLAN FSM with some active configuration |
| 3708 | } |
| 3709 | } |
| 3710 | } |
| 3711 | return false //there is no VLAN FSM with some active configuration |
| 3712 | } |
| 3713 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3714 | func (dh *deviceHandler) CheckAuditStartCondition(ctx context.Context, callingFsm cmn.UsedOmciConfigFsms) bool { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3715 | for fsmName, fsmStruct := range fsmOmciIdleStateFuncMap { |
| 3716 | if fsmName != callingFsm && !fsmStruct.omciIdleCheckFunc(dh, ctx, fsmName, fsmStruct.omciIdleState) { |
| 3717 | return false |
| 3718 | } |
| 3719 | } |
| 3720 | // a further check is done to identify, if at least some data traffic related configuration exists |
| 3721 | // so that a user of this ONU could be 'online' (otherwise it makes no sense to check the MDS [with the intention to keep the user service up]) |
| 3722 | return dh.checkUserServiceExists(ctx) |
| 3723 | } |
| 3724 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3725 | func (dh *deviceHandler) PrepareReconcilingWithActiveAdapter(ctx context.Context) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3726 | logger.Debugw(ctx, "prepare to reconcile the ONU with adapter using persistency data", log.Fields{"device-id": dh.device.Id}) |
| 3727 | if err := dh.resetFsms(ctx, false); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3728 | logger.Errorw(ctx, "reset of FSMs failed!", log.Fields{"device-id": dh.DeviceID, "error": err}) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3729 | // TODO: fatal error reset ONU, delete deviceHandler! |
| 3730 | return |
| 3731 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3732 | dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort) |
| 3733 | dh.StartReconciling(ctx, false) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3734 | } |
| 3735 | |
| 3736 | func (dh *deviceHandler) setCollectorIsRunning(flagValue bool) { |
| 3737 | dh.mutexCollectorFlag.Lock() |
| 3738 | dh.collectorIsRunning = flagValue |
| 3739 | dh.mutexCollectorFlag.Unlock() |
| 3740 | } |
| 3741 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3742 | func (dh *deviceHandler) GetCollectorIsRunning() bool { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3743 | dh.mutexCollectorFlag.RLock() |
| 3744 | flagValue := dh.collectorIsRunning |
| 3745 | dh.mutexCollectorFlag.RUnlock() |
| 3746 | return flagValue |
| 3747 | } |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 3748 | |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 3749 | func (dh *deviceHandler) setAlarmManagerIsRunning(flagValue bool) { |
| 3750 | dh.mutextAlarmManagerFlag.Lock() |
| 3751 | dh.alarmManagerIsRunning = flagValue |
| 3752 | dh.mutextAlarmManagerFlag.Unlock() |
| 3753 | } |
| 3754 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3755 | func (dh *deviceHandler) GetAlarmManagerIsRunning(ctx context.Context) bool { |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 3756 | dh.mutextAlarmManagerFlag.RLock() |
| 3757 | flagValue := dh.alarmManagerIsRunning |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 3758 | logger.Debugw(ctx, "alarm-manager-is-running", log.Fields{"flag": dh.alarmManagerIsRunning}) |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 3759 | dh.mutextAlarmManagerFlag.RUnlock() |
| 3760 | return flagValue |
| 3761 | } |
| 3762 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3763 | func (dh *deviceHandler) StartAlarmManager(ctx context.Context) { |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 3764 | logger.Debugf(ctx, "startingAlarmManager") |
| 3765 | |
| 3766 | // Start routine to process OMCI GET Responses |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3767 | go dh.pAlarmMgr.StartOMCIAlarmMessageProcessing(ctx) |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 3768 | dh.setAlarmManagerIsRunning(true) |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 3769 | if stop := <-dh.stopAlarmManager; stop { |
| 3770 | logger.Debugw(ctx, "stopping-collector-for-onu", log.Fields{"device-id": dh.device.Id}) |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 3771 | dh.setAlarmManagerIsRunning(false) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 3772 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3773 | if dh.pAlarmMgr.AlarmSyncFsm != nil && dh.pAlarmMgr.AlarmSyncFsm.PFsm != nil { |
| 3774 | _ = dh.pAlarmMgr.AlarmSyncFsm.PFsm.Event(almgr.AsEvStop) |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 3775 | } |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 3776 | }() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3777 | dh.pAlarmMgr.StopProcessingOmciMessages <- true // Stop the OMCI routines if any(This will stop the fsms also) |
| 3778 | dh.pAlarmMgr.StopAlarmAuditTimer <- struct{}{} |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 3779 | logger.Debugw(ctx, "sent-all-stop-signals-to-alarm-manager", log.Fields{"device-id": dh.device.Id}) |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 3780 | } |
| 3781 | } |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 3782 | |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3783 | func (dh *deviceHandler) setFlowMonitoringIsRunning(uniID uint8, flag bool) { |
| 3784 | dh.mutexFlowMonitoringRoutineFlag.Lock() |
| 3785 | defer dh.mutexFlowMonitoringRoutineFlag.Unlock() |
| 3786 | logger.Debugw(context.Background(), "set-flow-monitoring-routine", log.Fields{"flag": flag}) |
| 3787 | dh.isFlowMonitoringRoutineActive[uniID] = flag |
| 3788 | } |
| 3789 | |
| 3790 | func (dh *deviceHandler) GetFlowMonitoringIsRunning(uniID uint8) bool { |
| 3791 | dh.mutexFlowMonitoringRoutineFlag.RLock() |
| 3792 | defer dh.mutexFlowMonitoringRoutineFlag.RUnlock() |
| 3793 | logger.Debugw(context.Background(), "get-flow-monitoring-routine", |
| 3794 | log.Fields{"isFlowMonitoringRoutineActive": dh.isFlowMonitoringRoutineActive}) |
| 3795 | return dh.isFlowMonitoringRoutineActive[uniID] |
| 3796 | } |
| 3797 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3798 | func (dh *deviceHandler) StartReconciling(ctx context.Context, skipOnuConfig bool) { |
| 3799 | logger.Debugw(ctx, "start reconciling", log.Fields{"skipOnuConfig": skipOnuConfig, "device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3800 | |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3801 | connectStatus := voltha.ConnectStatus_UNREACHABLE |
| 3802 | operState := voltha.OperStatus_UNKNOWN |
| 3803 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3804 | if !dh.IsReconciling() { |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3805 | go func() { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3806 | logger.Debugw(ctx, "wait for channel signal or timeout", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3807 | log.Fields{"timeout": dh.pOpenOnuAc.maxTimeoutReconciling, "device-id": dh.DeviceID}) |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3808 | select { |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 3809 | case success := <-dh.chReconcilingFinished: |
| 3810 | if success { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3811 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3812 | logger.Errorw(ctx, "No valid OnuDevice - aborting Core DeviceStateUpdate", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3813 | log.Fields{"device-id": dh.DeviceID}) |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3814 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3815 | if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3816 | connectStatus = voltha.ConnectStatus_REACHABLE |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3817 | if !onuDevEntry.SOnuPersistentData.PersUniDisableDone { |
| 3818 | if onuDevEntry.SOnuPersistentData.PersUniUnlockDone { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3819 | operState = voltha.OperStatus_ACTIVE |
| 3820 | } else { |
| 3821 | operState = voltha.OperStatus_ACTIVATING |
| 3822 | } |
| 3823 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3824 | } else if onuDevEntry.SOnuPersistentData.PersOperState == "down" || |
| 3825 | onuDevEntry.SOnuPersistentData.PersOperState == "unknown" || |
| 3826 | onuDevEntry.SOnuPersistentData.PersOperState == "" { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3827 | operState = voltha.OperStatus_DISCOVERED |
| 3828 | } |
| 3829 | |
| 3830 | logger.Debugw(ctx, "Core DeviceStateUpdate", log.Fields{"connectStatus": connectStatus, "operState": operState}) |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3831 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 3832 | logger.Debugw(ctx, "reconciling has been finished in time", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3833 | log.Fields{"device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3834 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3835 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3836 | ConnStatus: connectStatus, |
| 3837 | OperStatus: operState, |
| 3838 | }); err != nil { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3839 | logger.Errorw(ctx, "unable to update device state to core", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3840 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3841 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 3842 | } else { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3843 | logger.Errorw(ctx, "wait for reconciling aborted", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3844 | log.Fields{"device-id": dh.DeviceID}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3845 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3846 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3847 | logger.Errorw(ctx, "No valid OnuDevice", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3848 | log.Fields{"device-id": dh.DeviceID}) |
| 3849 | } else if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3850 | connectStatus = voltha.ConnectStatus_REACHABLE |
| 3851 | } |
| 3852 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3853 | dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileCanceled, connectStatus) |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 3854 | } |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 3855 | case <-time.After(dh.pOpenOnuAc.maxTimeoutReconciling): |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3856 | logger.Errorw(ctx, "timeout waiting for reconciling to be finished!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3857 | log.Fields{"device-id": dh.DeviceID}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3858 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3859 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3860 | logger.Errorw(ctx, "No valid OnuDevice", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3861 | log.Fields{"device-id": dh.DeviceID}) |
| 3862 | } else if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3863 | connectStatus = voltha.ConnectStatus_REACHABLE |
| 3864 | } |
| 3865 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3866 | dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileMaxTimeout, connectStatus) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3867 | |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3868 | } |
| 3869 | dh.mutexReconcilingFlag.Lock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3870 | dh.reconciling = cNoReconciling |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3871 | dh.mutexReconcilingFlag.Unlock() |
| 3872 | }() |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3873 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3874 | dh.mutexReconcilingFlag.Lock() |
| 3875 | if skipOnuConfig { |
| 3876 | dh.reconciling = cSkipOnuConfigReconciling |
| 3877 | } else { |
| 3878 | dh.reconciling = cOnuConfigReconciling |
| 3879 | } |
| 3880 | dh.mutexReconcilingFlag.Unlock() |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3881 | } |
| 3882 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3883 | func (dh *deviceHandler) StopReconciling(ctx context.Context, success bool) { |
| 3884 | logger.Debugw(ctx, "stop reconciling", log.Fields{"device-id": dh.DeviceID, "success": success}) |
| 3885 | if dh.IsReconciling() { |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 3886 | dh.chReconcilingFinished <- success |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3887 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3888 | logger.Infow(ctx, "reconciling is not running", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3889 | } |
| 3890 | } |
| 3891 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3892 | func (dh *deviceHandler) IsReconciling() bool { |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3893 | dh.mutexReconcilingFlag.RLock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3894 | defer dh.mutexReconcilingFlag.RUnlock() |
| 3895 | return dh.reconciling != cNoReconciling |
| 3896 | } |
| 3897 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3898 | func (dh *deviceHandler) IsSkipOnuConfigReconciling() bool { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3899 | dh.mutexReconcilingFlag.RLock() |
| 3900 | defer dh.mutexReconcilingFlag.RUnlock() |
| 3901 | return dh.reconciling == cSkipOnuConfigReconciling |
| 3902 | } |
| 3903 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3904 | func (dh *deviceHandler) SetDeviceReason(value uint8) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3905 | dh.mutexDeviceReason.Lock() |
| 3906 | dh.deviceReason = value |
| 3907 | dh.mutexDeviceReason.Unlock() |
| 3908 | } |
| 3909 | |
| 3910 | func (dh *deviceHandler) getDeviceReason() uint8 { |
| 3911 | dh.mutexDeviceReason.RLock() |
| 3912 | value := dh.deviceReason |
| 3913 | dh.mutexDeviceReason.RUnlock() |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3914 | return value |
| 3915 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3916 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3917 | func (dh *deviceHandler) GetDeviceReasonString() string { |
| 3918 | return cmn.DeviceReasonMap[dh.getDeviceReason()] |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3919 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 3920 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3921 | func (dh *deviceHandler) SetReadyForOmciConfig(flagValue bool) { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3922 | dh.mutexReadyForOmciConfig.Lock() |
| 3923 | dh.readyForOmciConfig = flagValue |
| 3924 | dh.mutexReadyForOmciConfig.Unlock() |
| 3925 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3926 | func (dh *deviceHandler) IsReadyForOmciConfig() bool { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3927 | dh.mutexReadyForOmciConfig.RLock() |
| 3928 | flagValue := dh.readyForOmciConfig |
| 3929 | dh.mutexReadyForOmciConfig.RUnlock() |
| 3930 | return flagValue |
| 3931 | } |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3932 | |
| 3933 | func (dh *deviceHandler) deviceReconcileFailedUpdate(ctx context.Context, deviceReason uint8, connectStatus voltha.ConnectStatus_Types) { |
| 3934 | if err := dh.deviceReasonUpdate(ctx, deviceReason, true); err != nil { |
| 3935 | logger.Errorw(ctx, "unable to update device reason to core", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3936 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | logger.Debugw(ctx, "Core DeviceStateUpdate", log.Fields{"connectStatus": connectStatus, "operState": voltha.OperStatus_RECONCILING_FAILED}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3940 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3941 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3942 | ConnStatus: connectStatus, |
| 3943 | OperStatus: voltha.OperStatus_RECONCILING_FAILED, |
| 3944 | }); err != nil { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3945 | logger.Errorw(ctx, "unable to update device state to core", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3946 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3947 | } |
| 3948 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3949 | |
| 3950 | /* |
| 3951 | Helper functions to communicate with Core |
| 3952 | */ |
| 3953 | |
| 3954 | func (dh *deviceHandler) getDeviceFromCore(ctx context.Context, deviceID string) (*voltha.Device, error) { |
| 3955 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3956 | if err != nil || cClient == nil { |
| 3957 | return nil, err |
| 3958 | } |
| 3959 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 3960 | defer cancel() |
| 3961 | logger.Debugw(subCtx, "get-device-from-core", log.Fields{"device-id": deviceID}) |
| 3962 | return cClient.GetDevice(subCtx, &vc.ID{Id: deviceID}) |
| 3963 | } |
| 3964 | |
| 3965 | func (dh *deviceHandler) updateDeviceStateInCore(ctx context.Context, deviceStateFilter *ic.DeviceStateFilter) error { |
| 3966 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3967 | if err != nil || cClient == nil { |
| 3968 | return err |
| 3969 | } |
| 3970 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 3971 | defer cancel() |
| 3972 | _, err = cClient.DeviceStateUpdate(subCtx, deviceStateFilter) |
| 3973 | logger.Debugw(subCtx, "device-updated-in-core", log.Fields{"device-state": deviceStateFilter, "error": err}) |
| 3974 | return err |
| 3975 | } |
| 3976 | |
| 3977 | func (dh *deviceHandler) updatePMConfigInCore(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 3978 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3979 | if err != nil || cClient == nil { |
| 3980 | return err |
| 3981 | } |
| 3982 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 3983 | defer cancel() |
| 3984 | _, err = cClient.DevicePMConfigUpdate(subCtx, pmConfigs) |
| 3985 | logger.Debugw(subCtx, "pmconfig-updated-in-core", log.Fields{"pm-configs": pmConfigs, "error": err}) |
| 3986 | return err |
| 3987 | } |
| 3988 | |
| 3989 | func (dh *deviceHandler) updateDeviceInCore(ctx context.Context, device *voltha.Device) error { |
| 3990 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3991 | if err != nil || cClient == nil { |
| 3992 | return err |
| 3993 | } |
| 3994 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 3995 | defer cancel() |
| 3996 | _, err = cClient.DeviceUpdate(subCtx, device) |
| 3997 | logger.Debugw(subCtx, "device-updated-in-core", log.Fields{"device-id": device.Id, "error": err}) |
| 3998 | return err |
| 3999 | } |
| 4000 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4001 | func (dh *deviceHandler) CreatePortInCore(ctx context.Context, port *voltha.Port) error { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4002 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4003 | if err != nil || cClient == nil { |
| 4004 | return err |
| 4005 | } |
| 4006 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4007 | defer cancel() |
| 4008 | _, err = cClient.PortCreated(subCtx, port) |
| 4009 | logger.Debugw(subCtx, "port-created-in-core", log.Fields{"port": port, "error": err}) |
| 4010 | return err |
| 4011 | } |
| 4012 | |
| 4013 | func (dh *deviceHandler) updatePortStateInCore(ctx context.Context, portState *ic.PortState) error { |
| 4014 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4015 | if err != nil || cClient == nil { |
| 4016 | return err |
| 4017 | } |
| 4018 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4019 | defer cancel() |
| 4020 | _, err = cClient.PortStateUpdate(subCtx, portState) |
| 4021 | logger.Debugw(subCtx, "port-state-updated-in-core", log.Fields{"port-state": portState, "error": err}) |
| 4022 | return err |
| 4023 | } |
| 4024 | |
| 4025 | func (dh *deviceHandler) updateDeviceReasonInCore(ctx context.Context, reason *ic.DeviceReason) error { |
| 4026 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 4027 | if err != nil || cClient == nil { |
| 4028 | return err |
| 4029 | } |
| 4030 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 4031 | defer cancel() |
| 4032 | _, err = cClient.DeviceReasonUpdate(subCtx, reason) |
| 4033 | logger.Debugw(subCtx, "device-reason-updated-in-core", log.Fields{"reason": reason, "error": err}) |
| 4034 | return err |
| 4035 | } |
| 4036 | |
| 4037 | /* |
| 4038 | Helper functions to communicate with parent adapter |
| 4039 | */ |
| 4040 | |
| 4041 | func (dh *deviceHandler) getTechProfileInstanceFromParentAdapter(ctx context.Context, parentEndpoint string, |
| 4042 | request *ic.TechProfileInstanceRequestMessage) (*ic.TechProfileDownloadMessage, error) { |
| 4043 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint) |
| 4044 | if err != nil || pgClient == nil { |
| 4045 | return nil, err |
| 4046 | } |
| 4047 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 4048 | defer cancel() |
| 4049 | logger.Debugw(subCtx, "get-tech-profile-instance", log.Fields{"request": request, "parent-endpoint": parentEndpoint}) |
| 4050 | return pgClient.GetTechProfileInstance(subCtx, request) |
| 4051 | } |
| 4052 | |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 4053 | // This routine is unique per ONU ID and blocks on flowControlBlock channel for incoming flows |
| 4054 | // Each incoming flow is processed in a synchronous manner, i.e., the flow is processed to completion before picking another |
| 4055 | func (dh *deviceHandler) PerOnuFlowHandlerRoutine(uniID uint8) { |
| 4056 | logger.Infow(context.Background(), "starting-flow-handler-routine", log.Fields{"device-id": dh.DeviceID}) |
| 4057 | dh.setFlowMonitoringIsRunning(uniID, true) |
| 4058 | for { |
| 4059 | select { |
| 4060 | // block on the channel to receive an incoming flow |
| 4061 | // process the flow completely before proceeding to handle the next flow |
| 4062 | case flowCb := <-dh.flowCbChan[uniID]: |
| 4063 | startTime := time.Now() |
| 4064 | logger.Debugw(flowCb.ctx, "serial-flow-processor--start", log.Fields{"device-id": dh.DeviceID}) |
| 4065 | respChan := make(chan error) |
| 4066 | if flowCb.addFlow { |
| 4067 | go dh.addFlowItemToUniPort(flowCb.ctx, flowCb.flowItem, flowCb.uniPort, flowCb.flowMetaData, &respChan) |
| 4068 | } else { |
| 4069 | go dh.removeFlowItemFromUniPort(flowCb.ctx, flowCb.flowItem, flowCb.uniPort, &respChan) |
| 4070 | } |
| 4071 | // Block on response and tunnel it back to the caller |
| 4072 | *flowCb.respChan <- <-respChan |
| 4073 | logger.Debugw(flowCb.ctx, "serial-flow-processor--end", |
| 4074 | log.Fields{"device-id": dh.DeviceID, "absoluteTimeForFlowProcessingInSecs": time.Since(startTime).Seconds()}) |
| 4075 | case <-dh.stopFlowMonitoringRoutine[uniID]: |
| 4076 | logger.Infow(context.Background(), "stopping-flow-handler-routine", log.Fields{"device-id": dh.DeviceID}) |
| 4077 | dh.setFlowMonitoringIsRunning(uniID, false) |
| 4078 | return |
| 4079 | } |
| 4080 | } |
| 4081 | } |
| 4082 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4083 | func (dh *deviceHandler) SendOMCIRequest(ctx context.Context, parentEndpoint string, request *ic.OmciMessage) error { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 4084 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint) |
| 4085 | if err != nil || pgClient == nil { |
| 4086 | return err |
| 4087 | } |
| 4088 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 4089 | defer cancel() |
| 4090 | logger.Debugw(subCtx, "send-omci-request", log.Fields{"request": request, "parent-endpoint": parentEndpoint}) |
| 4091 | _, err = pgClient.ProxyOmciRequest(subCtx, request) |
| 4092 | if err != nil { |
| 4093 | logger.Errorw(ctx, "omci-failure", log.Fields{"request": request, "error": err, "request-parent": request.ParentDeviceId, "request-child": request.ChildDeviceId, "request-proxy": request.ProxyAddress}) |
| 4094 | } |
| 4095 | return err |
| 4096 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 4097 | |
| 4098 | // GetDeviceID - TODO: add comment |
| 4099 | func (dh *deviceHandler) GetDeviceID() string { |
| 4100 | return dh.DeviceID |
| 4101 | } |
| 4102 | |
| 4103 | // GetProxyAddressID - TODO: add comment |
| 4104 | func (dh *deviceHandler) GetProxyAddressID() string { |
| 4105 | return dh.device.ProxyAddress.GetDeviceId() |
| 4106 | } |
| 4107 | |
| 4108 | // GetProxyAddressType - TODO: add comment |
| 4109 | func (dh *deviceHandler) GetProxyAddressType() string { |
| 4110 | return dh.device.ProxyAddress.GetDeviceType() |
| 4111 | } |
| 4112 | |
| 4113 | // GetProxyAddress - TODO: add comment |
| 4114 | func (dh *deviceHandler) GetProxyAddress() *voltha.Device_ProxyAddress { |
| 4115 | return dh.device.ProxyAddress |
| 4116 | } |
| 4117 | |
| 4118 | // GetEventProxy - TODO: add comment |
| 4119 | func (dh *deviceHandler) GetEventProxy() eventif.EventProxy { |
| 4120 | return dh.EventProxy |
| 4121 | } |
| 4122 | |
| 4123 | // GetOmciTimeout - TODO: add comment |
| 4124 | func (dh *deviceHandler) GetOmciTimeout() int { |
| 4125 | return dh.pOpenOnuAc.omciTimeout |
| 4126 | } |
| 4127 | |
| 4128 | // GetAlarmAuditInterval - TODO: add comment |
| 4129 | func (dh *deviceHandler) GetAlarmAuditInterval() time.Duration { |
| 4130 | return dh.pOpenOnuAc.alarmAuditInterval |
| 4131 | } |
| 4132 | |
| 4133 | // GetDlToOnuTimeout4M - TODO: add comment |
| 4134 | func (dh *deviceHandler) GetDlToOnuTimeout4M() time.Duration { |
| 4135 | return dh.pOpenOnuAc.dlToOnuTimeout4M |
| 4136 | } |
| 4137 | |
| 4138 | // GetUniEntityMap - TODO: add comment |
| 4139 | func (dh *deviceHandler) GetUniEntityMap() *cmn.OnuUniPortMap { |
| 4140 | return &dh.uniEntityMap |
| 4141 | } |
| 4142 | |
| 4143 | // GetPonPortNumber - TODO: add comment |
| 4144 | func (dh *deviceHandler) GetPonPortNumber() *uint32 { |
| 4145 | return &dh.ponPortNumber |
| 4146 | } |
| 4147 | |
| 4148 | // GetUniVlanConfigFsm - TODO: add comment |
| 4149 | func (dh *deviceHandler) GetUniVlanConfigFsm(uniID uint8) cmn.IuniVlanConfigFsm { |
| 4150 | return dh.UniVlanConfigFsmMap[uniID] |
| 4151 | } |
| 4152 | |
| 4153 | // GetOnuAlarmManager - TODO: add comment |
| 4154 | func (dh *deviceHandler) GetOnuAlarmManager() cmn.IonuAlarmManager { |
| 4155 | return dh.pAlarmMgr |
| 4156 | } |
| 4157 | |
| 4158 | // GetOnuMetricsManager - TODO: add comment |
| 4159 | func (dh *deviceHandler) GetOnuMetricsManager() cmn.IonuMetricsManager { |
| 4160 | return dh.pOnuMetricsMgr |
| 4161 | } |
| 4162 | |
| 4163 | // GetOnuTP - TODO: add comment |
| 4164 | func (dh *deviceHandler) GetOnuTP() cmn.IonuUniTechProf { |
| 4165 | return dh.pOnuTP |
| 4166 | } |
| 4167 | |
| 4168 | // GetBackendPathPrefix - TODO: add comment |
| 4169 | func (dh *deviceHandler) GetBackendPathPrefix() string { |
| 4170 | return dh.pOpenOnuAc.cm.Backend.PathPrefix |
| 4171 | } |
| 4172 | |
| 4173 | // GetOnuIndication - TODO: add comment |
| 4174 | func (dh *deviceHandler) GetOnuIndication() *openolt.OnuIndication { |
| 4175 | return dh.pOnuIndication |
| 4176 | } |
| 4177 | |
| 4178 | // RLockMutexDeletionInProgressFlag - TODO: add comment |
| 4179 | func (dh *deviceHandler) RLockMutexDeletionInProgressFlag() { |
| 4180 | dh.mutexDeletionInProgressFlag.RLock() |
| 4181 | } |
| 4182 | |
| 4183 | // RUnlockMutexDeletionInProgressFlag - TODO: add comment |
| 4184 | func (dh *deviceHandler) RUnlockMutexDeletionInProgressFlag() { |
| 4185 | dh.mutexDeletionInProgressFlag.RUnlock() |
| 4186 | } |
| 4187 | |
| 4188 | // GetDeletionInProgress - TODO: add comment |
| 4189 | func (dh *deviceHandler) GetDeletionInProgress() bool { |
| 4190 | return dh.deletionInProgress |
| 4191 | } |
| 4192 | |
| 4193 | // GetPmConfigs - TODO: add comment |
| 4194 | func (dh *deviceHandler) GetPmConfigs() *voltha.PmConfigs { |
| 4195 | return dh.pmConfigs |
| 4196 | } |
| 4197 | |
| 4198 | // GetDeviceType - TODO: add comment |
| 4199 | func (dh *deviceHandler) GetDeviceType() string { |
| 4200 | return dh.DeviceType |
| 4201 | } |
| 4202 | |
| 4203 | // GetLogicalDeviceID - TODO: add comment |
| 4204 | func (dh *deviceHandler) GetLogicalDeviceID() string { |
| 4205 | return dh.logicalDeviceID |
| 4206 | } |
| 4207 | |
| 4208 | // GetDevice - TODO: add comment |
| 4209 | func (dh *deviceHandler) GetDevice() *voltha.Device { |
| 4210 | return dh.device |
| 4211 | } |
| 4212 | |
| 4213 | // GetMetricsEnabled - TODO: add comment |
| 4214 | func (dh *deviceHandler) GetMetricsEnabled() bool { |
| 4215 | return dh.pOpenOnuAc.MetricsEnabled |
| 4216 | } |
| 4217 | |
| 4218 | // InitPmConfigs - TODO: add comment |
| 4219 | func (dh *deviceHandler) InitPmConfigs() { |
| 4220 | dh.pmConfigs = &voltha.PmConfigs{} |
| 4221 | } |
| 4222 | |
| 4223 | // GetUniPortMask - TODO: add comment |
| 4224 | func (dh *deviceHandler) GetUniPortMask() int { |
| 4225 | return dh.pOpenOnuAc.config.UniPortMask |
| 4226 | } |