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 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 123 | //deviceHandler will interact with the ONU ? device. |
| 124 | type deviceHandler struct { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 125 | DeviceID string |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 126 | DeviceType string |
| 127 | adminState string |
| 128 | device *voltha.Device |
| 129 | logicalDeviceID string |
| 130 | ProxyAddressID string |
| 131 | ProxyAddressType string |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 132 | parentID string |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 133 | ponPortNumber uint32 |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 134 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 135 | coreClient *vgrpc.Client |
| 136 | EventProxy eventif.EventProxy |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 137 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 138 | pmConfigs *voltha.PmConfigs |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 139 | config *config.AdapterFlags |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 140 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 141 | pOpenOnuAc *OpenONUAC |
| 142 | pDeviceStateFsm *fsm.FSM |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 143 | //pPonPort *voltha.Port |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 144 | deviceEntrySet chan bool //channel for DeviceEntry set event |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 145 | pOnuOmciDevice *mib.OnuDeviceEntry |
| 146 | pOnuTP *avcfg.OnuUniTechProf |
| 147 | pOnuMetricsMgr *pmmgr.OnuMetricsManager |
| 148 | pAlarmMgr *almgr.OnuAlarmManager |
| 149 | pSelfTestHdlr *otst.SelfTestControlBlock |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 150 | exitChannel chan int |
| 151 | lockDevice sync.RWMutex |
| 152 | pOnuIndication *oop.OnuIndication |
| 153 | deviceReason uint8 |
| 154 | mutexDeviceReason sync.RWMutex |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 155 | pLockStateFsm *uniprt.LockStateFsm |
| 156 | pUnlockStateFsm *uniprt.LockStateFsm |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 157 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 158 | //flowMgr *OpenOltFlowMgr |
| 159 | //eventMgr *OpenOltEventMgr |
| 160 | //resourceMgr *rsrcMgr.OpenOltResourceMgr |
| 161 | |
| 162 | //discOnus sync.Map |
| 163 | //onus sync.Map |
| 164 | //portStats *OpenOltStatisticsMgr |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 165 | collectorIsRunning bool |
| 166 | mutexCollectorFlag sync.RWMutex |
| 167 | stopCollector chan bool |
| 168 | alarmManagerIsRunning bool |
| 169 | mutextAlarmManagerFlag sync.RWMutex |
| 170 | stopAlarmManager chan bool |
| 171 | stopHeartbeatCheck chan bool |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 172 | uniEntityMap cmn.OnuUniPortMap |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 173 | mutexKvStoreContext sync.Mutex |
| 174 | lockVlanConfig sync.RWMutex |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 175 | lockVlanAdd sync.RWMutex |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 176 | UniVlanConfigFsmMap map[uint8]*avcfg.UniVlanConfigFsm |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 177 | lockUpgradeFsm sync.RWMutex |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 178 | pOnuUpradeFsm *swupg.OnuUpgradeFsm |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 179 | upgradeCanceled bool |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 180 | reconciling uint8 |
| 181 | mutexReconcilingFlag sync.RWMutex |
| 182 | chReconcilingFinished chan bool //channel to indicate that reconciling has been finished |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 183 | mutexReadyForOmciConfig sync.RWMutex |
| 184 | readyForOmciConfig bool |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 185 | deletionInProgress bool |
| 186 | mutexDeletionInProgressFlag sync.RWMutex |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 187 | pLastUpgradeImageState *voltha.ImageState |
| 188 | upgradeFsmChan chan struct{} |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 191 | //newDeviceHandler creates a new device handler |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 192 | 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] | 193 | var dh deviceHandler |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 194 | dh.coreClient = cc |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 195 | dh.EventProxy = ep |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 196 | dh.config = adapter.config |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 197 | cloned := (proto.Clone(device)).(*voltha.Device) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 198 | dh.DeviceID = cloned.Id |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 199 | dh.DeviceType = cloned.Type |
| 200 | dh.adminState = "up" |
| 201 | dh.device = cloned |
| 202 | dh.pOpenOnuAc = adapter |
| 203 | dh.exitChannel = make(chan int, 1) |
| 204 | dh.lockDevice = sync.RWMutex{} |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 205 | dh.deviceEntrySet = make(chan bool, 1) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 206 | dh.collectorIsRunning = false |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 207 | dh.stopCollector = make(chan bool, 2) |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 208 | dh.alarmManagerIsRunning = false |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 209 | dh.stopAlarmManager = make(chan bool, 2) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 210 | dh.stopHeartbeatCheck = make(chan bool, 2) |
| 211 | //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] | 212 | //TODO initialize the support classes. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 213 | dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 214 | dh.lockVlanConfig = sync.RWMutex{} |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 215 | dh.lockVlanAdd = sync.RWMutex{} |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 216 | dh.lockUpgradeFsm = sync.RWMutex{} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 217 | dh.UniVlanConfigFsmMap = make(map[uint8]*avcfg.UniVlanConfigFsm) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 218 | dh.reconciling = cNoReconciling |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 219 | dh.chReconcilingFinished = make(chan bool) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 220 | dh.readyForOmciConfig = false |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 221 | dh.deletionInProgress = false |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 222 | dh.pLastUpgradeImageState = &voltha.ImageState{ |
| 223 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 224 | Reason: voltha.ImageState_UNKNOWN_ERROR, |
| 225 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 226 | } |
| 227 | dh.upgradeFsmChan = make(chan struct{}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 228 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 229 | if dh.device.PmConfigs != nil { // can happen after onu adapter restart |
| 230 | dh.pmConfigs = cloned.PmConfigs |
| 231 | } /* else { |
| 232 | // will be populated when onu_metrics_mananger is initialized. |
| 233 | }*/ |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 234 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 235 | // Device related state machine |
| 236 | dh.pDeviceStateFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 237 | devStNull, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 238 | fsm.Events{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 239 | {Name: devEvDeviceInit, Src: []string{devStNull, devStDown}, Dst: devStInit}, |
| 240 | {Name: devEvGrpcConnected, Src: []string{devStInit}, Dst: devStConnected}, |
| 241 | {Name: devEvGrpcDisconnected, Src: []string{devStConnected, devStDown}, Dst: devStInit}, |
| 242 | {Name: devEvDeviceUpInd, Src: []string{devStConnected, devStDown}, Dst: devStUp}, |
| 243 | {Name: devEvDeviceDownInd, Src: []string{devStUp}, Dst: devStDown}, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 244 | }, |
| 245 | fsm.Callbacks{ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 246 | "before_event": func(e *fsm.Event) { dh.logStateChange(ctx, e) }, |
| 247 | ("before_" + devEvDeviceInit): func(e *fsm.Event) { dh.doStateInit(ctx, e) }, |
| 248 | ("after_" + devEvDeviceInit): func(e *fsm.Event) { dh.postInit(ctx, e) }, |
| 249 | ("before_" + devEvGrpcConnected): func(e *fsm.Event) { dh.doStateConnected(ctx, e) }, |
| 250 | ("before_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.doStateInit(ctx, e) }, |
| 251 | ("after_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.postInit(ctx, e) }, |
| 252 | ("before_" + devEvDeviceUpInd): func(e *fsm.Event) { dh.doStateUp(ctx, e) }, |
| 253 | ("before_" + devEvDeviceDownInd): func(e *fsm.Event) { dh.doStateDown(ctx, e) }, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 254 | }, |
| 255 | ) |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 256 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 257 | return &dh |
| 258 | } |
| 259 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 260 | // start save the device to the data model |
| 261 | func (dh *deviceHandler) start(ctx context.Context) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 262 | 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] | 263 | // Add the initial device to the local model |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 264 | logger.Debug(ctx, "device-handler-started") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 267 | /* |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 268 | // stop stops the device dh. Not much to do for now |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 269 | func (dh *deviceHandler) stop(ctx context.Context) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 270 | logger.Debug("stopping-device-handler") |
| 271 | dh.exitChannel <- 1 |
| 272 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 273 | */ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 274 | |
| 275 | // ########################################################################################## |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 276 | // deviceHandler methods that implement the adapters interface requests ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 277 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 278 | //adoptOrReconcileDevice adopts the ONU device |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 279 | func (dh *deviceHandler) adoptOrReconcileDevice(ctx context.Context, device *voltha.Device) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 280 | 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] | 281 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 282 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"state": string(dh.pDeviceStateFsm.Current())}) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 283 | if dh.pDeviceStateFsm.Is(devStNull) { |
| 284 | if err := dh.pDeviceStateFsm.Event(devEvDeviceInit); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 285 | 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] | 286 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 287 | logger.Debugw(ctx, "Device FSM: ", log.Fields{"state": string(dh.pDeviceStateFsm.Current())}) |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 288 | // device.PmConfigs is not nil in cases when adapter restarts. We should not re-set the core again. |
| 289 | if device.PmConfigs == nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 290 | // Now, set the initial PM configuration for that device |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 291 | if err := dh.updatePMConfigInCore(ctx, dh.pmConfigs); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 292 | 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] | 293 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 294 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 295 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 296 | 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] | 297 | } |
| 298 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 299 | } |
| 300 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 301 | func (dh *deviceHandler) handleOMCIIndication(ctx context.Context, msg *ic.OmciMessage) error { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 302 | /* 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] | 303 | //assuming omci message content is hex coded! |
| 304 | // with restricted output of 16(?) bytes would be ...omciMsg.Message[:16] |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 305 | logger.Debugw(ctx, "inter-adapter-recv-omci", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 306 | "device-id": dh.DeviceID, "RxOmciMessage": hex.EncodeToString(omciMsg.Message)}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 307 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 308 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 309 | if pDevEntry != nil { |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 310 | if pDevEntry.PDevOmciCC != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 311 | return pDevEntry.PDevOmciCC.ReceiveMessage(log.WithSpanFromContext(context.TODO(), ctx), msg.Message) |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 312 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 313 | 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] | 314 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 315 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 316 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 317 | } |
| 318 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 319 | func (dh *deviceHandler) handleTechProfileDownloadRequest(ctx context.Context, techProfMsg *ic.TechProfileDownloadMessage) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 320 | 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] | 321 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 322 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 323 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 324 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 325 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 326 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 327 | if dh.pOnuTP == nil { |
| 328 | //should normally not happen ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 329 | 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] | 330 | log.Fields{"device-id": dh.DeviceID}) |
| 331 | 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] | 332 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 333 | if !dh.IsReadyForOmciConfig() { |
| 334 | logger.Errorw(ctx, "TechProf-set rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 335 | "device-state": dh.GetDeviceReasonString()}) |
| 336 | 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] | 337 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 338 | //previous state test here was just this one, now extended for more states to reject the SetRequest: |
| 339 | // at least 'mib-downloaded' should be reached for processing of this specific ONU configuration |
| 340 | // if (dh.deviceReason == "stopping-openomci") || (dh.deviceReason == "omci-admin-lock") |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 341 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 342 | // 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] | 343 | // even to fast subsequent calls of the same messageType as well as OnuKVStore processing due |
| 344 | // to possible concurrent access by flow processing |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 345 | dh.pOnuTP.LockTpProcMutex() |
| 346 | defer dh.pOnuTP.UnlockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 347 | |
| 348 | if techProfMsg.UniId > 255 { |
| 349 | 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] | 350 | techProfMsg.UniId, dh.DeviceID)) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 351 | } |
| 352 | uniID := uint8(techProfMsg.UniId) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 353 | tpID, err := cmn.GetTpIDFromTpPath(techProfMsg.TpInstancePath) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 354 | if err != nil { |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 355 | 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] | 356 | return err |
| 357 | } |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 358 | 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] | 359 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 360 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, uint8(tpID), techProfMsg.TpInstancePath); bTpModify { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 361 | |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 362 | switch tpInst := techProfMsg.TechTpInstance.(type) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 363 | case *ic.TechProfileDownloadMessage_TpInstance: |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 364 | logger.Debugw(ctx, "onu-uni-tp-path-modified", log.Fields{"uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID}) |
| 365 | // if there has been some change for some uni TechProfilePath |
| 366 | //in order to allow concurrent calls to other dh instances we do not wait for execution here |
| 367 | //but doing so we can not indicate problems to the caller (who does what with that then?) |
| 368 | //by now we just assume straightforward successful execution |
| 369 | //TODO!!! Generally: In this scheme it would be good to have some means to indicate |
| 370 | // possible problems to the caller later autonomously |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 371 | |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 372 | // deadline context to ensure completion of background routines waited for |
| 373 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 374 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 375 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 376 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 377 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 378 | |
| 379 | var wg sync.WaitGroup |
| 380 | wg.Add(1) // for the 1 go routine to finish |
| 381 | // 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] | 382 | 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] | 383 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfDwld") //wait for background process to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 384 | if tpErr := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); tpErr != nil { |
| 385 | 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] | 386 | return tpErr |
| 387 | } |
| 388 | deadline = time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 389 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 390 | pDevEntry.ResetKvProcessingErrorIndication() |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 391 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 392 | go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 393 | dh.waitForCompletion(ctx, cancel2, &wg, "TechProfDwld") //wait for background process to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 394 | if kvErr := pDevEntry.GetKvProcessingErrorIndication(); kvErr != nil { |
| 395 | 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] | 396 | return kvErr |
| 397 | } |
| 398 | return nil |
| 399 | default: |
| 400 | logger.Errorw(ctx, "unsupported-tp-instance-type", log.Fields{"tp-path": techProfMsg.TpInstancePath}) |
| 401 | return fmt.Errorf("unsupported-tp-instance-type--tp-id-%v", techProfMsg.TpInstancePath) |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 402 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 403 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 404 | // no change, nothing really to do - return success |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 405 | 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] | 406 | return nil |
| 407 | } |
| 408 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 409 | func (dh *deviceHandler) handleDeleteGemPortRequest(ctx context.Context, delGemPortMsg *ic.DeleteGemPortMessage) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 410 | 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] | 411 | |
| 412 | if dh.pOnuTP == nil { |
| 413 | //should normally not happen ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 414 | 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] | 415 | log.Fields{"device-id": dh.DeviceID}) |
| 416 | 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] | 417 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 418 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 419 | dh.pOnuTP.LockTpProcMutex() |
| 420 | defer dh.pOnuTP.UnlockTpProcMutex() |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 421 | |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 422 | if delGemPortMsg.UniId > 255 { |
| 423 | 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] | 424 | delGemPortMsg.UniId, dh.DeviceID)) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 425 | } |
| 426 | uniID := uint8(delGemPortMsg.UniId) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 427 | tpID, err := cmn.GetTpIDFromTpPath(delGemPortMsg.TpInstancePath) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 428 | if err != nil { |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 429 | 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] | 430 | return err |
| 431 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 432 | 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] | 433 | //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] | 434 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 435 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delGemPortMsg.TpInstancePath, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 436 | avcfg.CResourceGemPort, delGemPortMsg.GemPortId) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 437 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 438 | } |
| 439 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 440 | func (dh *deviceHandler) handleDeleteTcontRequest(ctx context.Context, delTcontMsg *ic.DeleteTcontMessage) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 441 | logger.Infow(ctx, "delete-tcont-request", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 442 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 443 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 444 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 445 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 446 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 447 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 448 | if dh.pOnuTP == nil { |
| 449 | //should normally not happen ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 450 | 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] | 451 | log.Fields{"device-id": dh.DeviceID}) |
| 452 | 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] | 453 | } |
| 454 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 455 | //compare TECH_PROFILE_DOWNLOAD_REQUEST |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 456 | dh.pOnuTP.LockTpProcMutex() |
| 457 | defer dh.pOnuTP.UnlockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 458 | |
| 459 | if delTcontMsg.UniId > 255 { |
| 460 | 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] | 461 | delTcontMsg.UniId, dh.DeviceID)) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 462 | } |
| 463 | uniID := uint8(delTcontMsg.UniId) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 464 | tpPath := delTcontMsg.TpInstancePath |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 465 | tpID, err := cmn.GetTpIDFromTpPath(tpPath) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 466 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 467 | 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] | 468 | return err |
| 469 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 470 | 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] | 471 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 472 | pDevEntry.FreeTcont(ctx, uint16(delTcontMsg.AllocId)) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 473 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 474 | return dh.deleteTechProfileResource(ctx, uniID, tpID, delTcontMsg.TpInstancePath, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 475 | avcfg.CResourceTcont, delTcontMsg.AllocId) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 476 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 477 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 478 | |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 479 | func (dh *deviceHandler) deleteTechProfileResource(ctx context.Context, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 480 | uniID uint8, tpID uint8, pathString string, resource avcfg.ResourceEntry, entryID uint32) error { |
| 481 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 482 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 483 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 484 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 485 | } |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 486 | var resourceName string |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 487 | if avcfg.CResourceGemPort == resource { |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 488 | resourceName = "Gem" |
| 489 | } else { |
| 490 | resourceName = "Tcont" |
| 491 | } |
| 492 | |
| 493 | // deadline context to ensure completion of background routines waited for |
| 494 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 495 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 496 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 497 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 498 | |
| 499 | var wg sync.WaitGroup |
| 500 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 501 | go dh.pOnuTP.DeleteTpResource(log.WithSpanFromContext(dctx, ctx), uniID, tpID, pathString, |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 502 | resource, entryID, &wg) |
| 503 | 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] | 504 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); err != nil { |
| 505 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 506 | return err |
| 507 | } |
| 508 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 509 | if dh.pOnuTP.IsTechProfileConfigCleared(ctx, uniID, tpID) { |
| 510 | logger.Debugw(ctx, "techProfile-config-cleared", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID}) |
| 511 | if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, tpID, ""); bTpModify { |
| 512 | pDevEntry.ResetKvProcessingErrorIndication() |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 513 | var wg2 sync.WaitGroup |
| 514 | dctx2, cancel2 := context.WithDeadline(context.Background(), deadline) |
| 515 | wg2.Add(1) |
| 516 | // 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] | 517 | logger.Infow(ctx, "remove-techProfile-indication-in-kv", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID}) |
| 518 | go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg2) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 519 | 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] | 520 | if err := pDevEntry.GetKvProcessingErrorIndication(); err != nil { |
| 521 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Mahir Gunyel | 9545be2 | 2021-07-04 15:53:16 -0700 | [diff] [blame] | 522 | return err |
| 523 | } |
| 524 | } |
| 525 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 526 | 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] | 527 | "uni-id": uniID, "tpID": tpID, "resource-type": resourceName, "resource-id": entryID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 528 | return nil |
| 529 | } |
| 530 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 531 | //FlowUpdateIncremental removes and/or adds the flow changes on a given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 532 | func (dh *deviceHandler) FlowUpdateIncremental(ctx context.Context, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 533 | apOfFlowChanges *of.FlowChanges, |
| 534 | apOfGroupChanges *of.FlowGroupChanges, apFlowMetaData *voltha.FlowMetadata) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 535 | logger.Debugw(ctx, "FlowUpdateIncremental started", log.Fields{"device-id": dh.DeviceID, "metadata": apFlowMetaData}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 536 | var retError error = nil |
| 537 | //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] | 538 | if apOfFlowChanges.ToRemove != nil { |
| 539 | for _, flowItem := range apOfFlowChanges.ToRemove.Items { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 540 | if flowItem.GetCookie() == 0 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 541 | 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] | 542 | "device-id": dh.DeviceID}) |
| 543 | retError = fmt.Errorf("flow-remove no cookie, device-id %s", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 544 | continue |
| 545 | } |
| 546 | flowInPort := flow.GetInPort(flowItem) |
| 547 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 548 | logger.Warnw(ctx, "flow-remove inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 549 | retError = fmt.Errorf("flow-remove inPort invalid, device-id %s", dh.DeviceID) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 550 | continue |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 551 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 552 | } else if flowInPort == dh.ponPortNumber { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 553 | //this is some downstream flow, not regarded as error, just ignored |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 554 | 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] | 555 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 556 | continue |
| 557 | } else { |
| 558 | // this is the relevant upstream flow |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 559 | var loUniPort *cmn.OnuUniPort |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 560 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 561 | loUniPort = uniPort |
| 562 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 563 | 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] | 564 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 565 | 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] | 566 | flowInPort, dh.DeviceID) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 567 | continue |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 568 | } |
| 569 | flowOutPort := flow.GetOutPort(flowItem) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 570 | logger.Debugw(ctx, "flow-remove port indications", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 571 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 572 | "uniPortName": loUniPort.Name}) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 573 | err := dh.removeFlowItemFromUniPort(ctx, flowItem, loUniPort) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 574 | //try next flow after processing error |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 575 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 576 | logger.Warnw(ctx, "flow-remove processing error: continuing on checking further flows", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 577 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 578 | retError = err |
| 579 | continue |
| 580 | //return err |
| 581 | } else { // if last setting succeeds, overwrite possibly previously set error |
| 582 | retError = nil |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | } |
| 586 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 587 | if apOfFlowChanges.ToAdd != nil { |
| 588 | for _, flowItem := range apOfFlowChanges.ToAdd.Items { |
| 589 | if flowItem.GetCookie() == 0 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 590 | 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] | 591 | "device-id": dh.DeviceID}) |
| 592 | retError = fmt.Errorf("flow-add no cookie, device-id %s", dh.DeviceID) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 593 | continue |
| 594 | } |
| 595 | flowInPort := flow.GetInPort(flowItem) |
| 596 | if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 597 | logger.Warnw(ctx, "flow-add inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID}) |
| 598 | retError = fmt.Errorf("flow-add inPort invalid, device-id %s", dh.DeviceID) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 599 | continue |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 600 | //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 601 | } else if flowInPort == dh.ponPortNumber { |
| 602 | //this is some downstream flow |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 603 | 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] | 604 | "device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 605 | continue |
| 606 | } else { |
| 607 | // this is the relevant upstream flow |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 608 | var loUniPort *cmn.OnuUniPort |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 609 | if uniPort, exist := dh.uniEntityMap[flowInPort]; exist { |
| 610 | loUniPort = uniPort |
| 611 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 612 | 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] | 613 | log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 614 | 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] | 615 | flowInPort, dh.DeviceID) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 616 | continue |
| 617 | //return fmt.Errorf("flow-parameter inPort %d not found in internal UniPorts", flowInPort) |
| 618 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 619 | // let's still assume that we receive the flow-add only in some 'active' device state (as so far observed) |
| 620 | // if not, we just throw some error here to have an indication about that, if we really need to support that |
| 621 | // then we would need to create some means to activate the internal stored flows |
| 622 | // after the device gets active automatically (and still with its dependency to the TechProfile) |
| 623 | // for state checking compare also code here: processInterAdapterTechProfileDownloadReqMessage |
| 624 | // also abort for the other still possible flows here |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 625 | if !dh.IsReadyForOmciConfig() { |
| 626 | logger.Errorw(ctx, "flow-add rejected: improper device state", log.Fields{"device-id": dh.DeviceID, |
| 627 | "last device-reason": dh.GetDeviceReasonString()}) |
| 628 | return fmt.Errorf("improper device state on device %s", dh.DeviceID) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 629 | } |
| 630 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 631 | flowOutPort := flow.GetOutPort(flowItem) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 632 | logger.Debugw(ctx, "flow-add port indications", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 633 | "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort, |
| 634 | "uniPortName": loUniPort.Name}) |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 635 | err := dh.addFlowItemToUniPort(ctx, flowItem, loUniPort, apFlowMetaData) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 636 | //try next flow after processing error |
| 637 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 638 | logger.Warnw(ctx, "flow-add processing error: continuing on checking further flows", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 639 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 640 | retError = err |
| 641 | continue |
| 642 | //return err |
| 643 | } else { // if last setting succeeds, overwrite possibly previously set error |
| 644 | retError = nil |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | return retError |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 652 | //disableDevice locks the ONU and its UNI/VEIP ports (admin lock via OMCI) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 653 | //following are the expected device states after this activity: |
| 654 | //Device Admin-State : down (on rwCore), Port-State: UNKNOWN, Conn-State: REACHABLE, Reason: omci-admin-lock |
| 655 | // (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] | 656 | func (dh *deviceHandler) disableDevice(ctx context.Context, device *voltha.Device) { |
| 657 | 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] | 658 | |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 659 | //admin-lock reason can also be used uniquely for setting the DeviceState accordingly |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 660 | //note that disableDevice sequences in some 'ONU active' state may yield also |
| 661 | // "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] | 662 | // - inblock state checking to prevent possibly unneeded processing (on command repitition) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 663 | if dh.getDeviceReason() != cmn.DrOmciAdminLock { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 664 | //disable-device shall be just a UNi/ONU-G related admin state setting |
| 665 | //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] | 666 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 667 | if dh.IsReadyForOmciConfig() { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 668 | // disable UNI ports/ONU |
| 669 | // *** should generate UniDisableStateDone event - used to disable the port(s) on success |
| 670 | if dh.pLockStateFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 671 | dh.createUniLockFsm(ctx, true, cmn.UniDisableStateDone) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 672 | } else { //LockStateFSM already init |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 673 | dh.pLockStateFsm.SetSuccessEvent(cmn.UniDisableStateDone) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 674 | dh.runUniLockFsm(ctx, true) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 675 | } |
| 676 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 677 | logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 678 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 679 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 680 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 681 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 682 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 683 | }); err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 684 | //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] | 685 | 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] | 686 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 687 | // 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] | 688 | |
| 689 | //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] | 690 | _ = dh.deviceReasonUpdate(ctx, cmn.DrOmciAdminLock, true) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 691 | } |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 695 | //reEnableDevice unlocks the ONU and its UNI/VEIP ports (admin unlock via OMCI) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 696 | func (dh *deviceHandler) reEnableDevice(ctx context.Context, device *voltha.Device) { |
| 697 | 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] | 698 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 699 | //setting readyForOmciConfig here is just a workaround for BBSIM testing in the sequence |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 700 | // OnuSoftReboot-disable-enable, because BBSIM does not generate a new OnuIndication-Up event after SoftReboot |
| 701 | // which is the assumption for real ONU's, where the ready-state is then set according to the following MibUpload/Download |
| 702 | // for real ONU's that should have nearly no influence |
| 703 | // Note that for real ONU's there is anyway a problematic situation with following sequence: |
| 704 | // OnuIndication-Dw (or not active at all) (- disable) - enable: here already the LockFsm may run into timeout (no OmciResponse) |
| 705 | // but that anyway is hopefully resolved by some OnuIndication-Up event (maybe to be tested) |
| 706 | // 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] | 707 | dh.SetReadyForOmciConfig(true) //needed to allow subsequent flow/techProf config (on BBSIM) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 708 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 709 | // enable ONU/UNI ports |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 710 | // *** 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] | 711 | if dh.pUnlockStateFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 712 | dh.createUniLockFsm(ctx, false, cmn.UniEnableStateDone) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 713 | } else { //UnlockStateFSM already init |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 714 | dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniEnableStateDone) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 715 | dh.runUniLockFsm(ctx, false) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 716 | } |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 717 | } |
| 718 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 719 | func (dh *deviceHandler) reconcileDeviceOnuInd(ctx context.Context) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 720 | 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] | 721 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 722 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 723 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 724 | 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] | 725 | return |
| 726 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 727 | if err := pDevEntry.RestoreDataFromOnuKvStore(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 728 | if err == fmt.Errorf("no-ONU-data-found") { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 729 | 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] | 730 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 731 | 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] | 732 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 733 | dh.StopReconciling(ctx, false) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 734 | return |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 735 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 736 | var onuIndication oop.OnuIndication |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 737 | pDevEntry.MutexPersOnuConfig.RLock() |
| 738 | onuIndication.IntfId = pDevEntry.SOnuPersistentData.PersIntfID |
| 739 | onuIndication.OnuId = pDevEntry.SOnuPersistentData.PersOnuID |
| 740 | onuIndication.OperState = pDevEntry.SOnuPersistentData.PersOperState |
| 741 | onuIndication.AdminState = pDevEntry.SOnuPersistentData.PersAdminState |
| 742 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 743 | _ = dh.createInterface(ctx, &onuIndication) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 746 | func (dh *deviceHandler) ReconcileDeviceTechProf(ctx context.Context) { |
| 747 | 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] | 748 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 749 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 750 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 751 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 752 | if !dh.IsSkipOnuConfigReconciling() { |
| 753 | dh.StopReconciling(ctx, false) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 754 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 755 | return |
| 756 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 757 | dh.pOnuTP.LockTpProcMutex() |
| 758 | defer dh.pOnuTP.UnlockTpProcMutex() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 759 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 760 | pDevEntry.MutexPersOnuConfig.RLock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 761 | persMutexLock := true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 762 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 763 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 764 | 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] | 765 | log.Fields{"device-id": dh.DeviceID}) |
| 766 | if !dh.IsSkipOnuConfigReconciling() { |
| 767 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 768 | } |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 769 | return |
| 770 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 771 | flowsFound := false |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 772 | techProfsFound := false |
| 773 | techProfInstLoadFailed := false |
| 774 | outerLoop: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 775 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 776 | //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support |
| 777 | if len(uniData.PersTpPathMap) == 0 { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 778 | logger.Debugw(ctx, "reconciling - no TPs stored for uniID", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 779 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 780 | continue |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 781 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 782 | //release MutexPersOnuConfig before TechProfile (ANIConfig) processing as otherwise the reception of |
| 783 | // 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] | 784 | // 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] | 785 | pDevEntry.MutexPersOnuConfig.RUnlock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 786 | persMutexLock = false |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 787 | 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] | 788 | for tpID := range uniData.PersTpPathMap { |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 789 | // Request the TpInstance again from the openolt adapter in case of reconcile |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 790 | iaTechTpInst, err := dh.getTechProfileInstanceFromParentAdapter(ctx, |
| 791 | dh.device.ProxyAddress.AdapterEndpoint, |
| 792 | &ic.TechProfileInstanceRequestMessage{ |
| 793 | DeviceId: dh.device.Id, |
| 794 | TpInstancePath: uniData.PersTpPathMap[tpID], |
| 795 | ParentDeviceId: dh.parentID, |
| 796 | ParentPonPort: dh.device.ParentPortNo, |
| 797 | OnuId: dh.device.ProxyAddress.OnuId, |
| 798 | UniId: uint32(uniData.PersUniID), |
| 799 | }) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 800 | if err != nil || iaTechTpInst == nil { |
| 801 | logger.Errorw(ctx, "error fetching tp instance", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 802 | 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] | 803 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 804 | break outerLoop |
| 805 | } |
| 806 | var tpInst tech_profile.TechProfileInstance |
| 807 | switch techTpInst := iaTechTpInst.TechTpInstance.(type) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 808 | case *ic.TechProfileDownloadMessage_TpInstance: // supports only GPON, XGPON, XGS-PON |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 809 | tpInst = *techTpInst.TpInstance |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 810 | logger.Debugw(ctx, "received-tp-instance-successfully-after-reconcile", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 811 | "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] | 812 | default: // do not support epon or other tech |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 813 | logger.Errorw(ctx, "unsupported-tech-profile", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 814 | "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] | 815 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 816 | break outerLoop |
| 817 | } |
| 818 | |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 819 | // deadline context to ensure completion of background routines waited for |
| 820 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 821 | 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] | 822 | dctx, cancel := context.WithDeadline(ctx, deadline) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 823 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 824 | dh.pOnuTP.ResetTpProcessingErrorIndication(uniData.PersUniID, tpID) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 825 | var wg sync.WaitGroup |
| 826 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 827 | 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] | 828 | dh.waitForCompletion(ctx, cancel, &wg, "TechProfReconcile") //wait for background process to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 829 | if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniData.PersUniID, tpID); err != nil { |
| 830 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 831 | techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure |
| 832 | break outerLoop |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 833 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 834 | } // for all TpPath entries for this UNI |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 835 | if len(uniData.PersFlowParams) != 0 { |
| 836 | flowsFound = true |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 837 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 838 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 839 | persMutexLock = true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 840 | } // for all UNI entries from SOnuPersistentData |
| 841 | if persMutexLock { // if loop was left with MutexPersOnuConfig still set |
| 842 | pDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 843 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 844 | |
| 845 | //had to move techProf/flow result evaluation into separate function due to SCA complexity limit |
| 846 | dh.updateReconcileStates(ctx, techProfsFound, techProfInstLoadFailed, flowsFound) |
| 847 | } |
| 848 | |
| 849 | func (dh *deviceHandler) updateReconcileStates(ctx context.Context, |
| 850 | abTechProfsFound bool, abTechProfInstLoadFailed bool, abFlowsFound bool) { |
| 851 | if !abTechProfsFound { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 852 | 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] | 853 | log.Fields{"device-id": dh.DeviceID}) |
| 854 | if !dh.IsSkipOnuConfigReconciling() { |
| 855 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 856 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 857 | return |
| 858 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 859 | if abTechProfInstLoadFailed { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 860 | dh.SetDeviceReason(cmn.DrTechProfileConfigDownloadFailed) |
| 861 | dh.StopReconciling(ctx, false) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 862 | return |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 863 | } else if dh.IsSkipOnuConfigReconciling() { |
| 864 | dh.SetDeviceReason(cmn.DrTechProfileConfigDownloadSuccess) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 865 | } |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 866 | if !abFlowsFound { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 867 | 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] | 868 | log.Fields{"device-id": dh.DeviceID}) |
| 869 | if !dh.IsSkipOnuConfigReconciling() { |
| 870 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 871 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 872 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 875 | func (dh *deviceHandler) ReconcileDeviceFlowConfig(ctx context.Context) { |
| 876 | 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] | 877 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 878 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 879 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 880 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 881 | if !dh.IsSkipOnuConfigReconciling() { |
| 882 | dh.StopReconciling(ctx, false) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 883 | } |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 884 | return |
| 885 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 886 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 887 | pDevEntry.MutexPersOnuConfig.RLock() |
| 888 | if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 { |
| 889 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 890 | 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] | 891 | log.Fields{"device-id": dh.DeviceID}) |
| 892 | if !dh.IsSkipOnuConfigReconciling() { |
| 893 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 894 | } |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 895 | return |
| 896 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 897 | flowsFound := false |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 898 | for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig { |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 899 | //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support |
| 900 | if len(uniData.PersFlowParams) == 0 { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 901 | logger.Debugw(ctx, "reconciling - no flows stored for uniID", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 902 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 903 | continue |
| 904 | } |
| 905 | if len(uniData.PersTpPathMap) == 0 { |
| 906 | logger.Warnw(ctx, "reconciling - flows but no TPs stored for uniID", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 907 | log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID}) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 908 | // It doesn't make sense to configure any flows if no TPs are available |
| 909 | continue |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 910 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 911 | //release MutexPersOnuConfig before VlanConfig processing as otherwise the reception of |
| 912 | // 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] | 913 | // 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] | 914 | pDevEntry.MutexPersOnuConfig.RUnlock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 915 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 916 | var uniPort *cmn.OnuUniPort |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 917 | var exist bool |
Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 918 | 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] | 919 | if uniPort, exist = dh.uniEntityMap[uniNo]; !exist { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 920 | logger.Errorw(ctx, "reconciling - OnuUniPort data not found - terminate reconcilement", |
| 921 | log.Fields{"uniNo": uniNo, "device-id": dh.DeviceID}) |
| 922 | if !dh.IsSkipOnuConfigReconciling() { |
| 923 | dh.StopReconciling(ctx, false) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 924 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 925 | return |
| 926 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 927 | flowsFound = true |
Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 928 | lastFlowToReconcile := false |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 929 | flowsProcessed := 0 |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 930 | pDevEntry.SetReconcilingFlows(true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 931 | for _, flowData := range uniData.PersFlowParams { |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 932 | logger.Debugw(ctx, "reconciling - add flow with cookie slice", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 933 | "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, "cookies": flowData.CookieSlice}) |
Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 934 | if flowsProcessed == len(uniData.PersFlowParams)-1 { |
| 935 | lastFlowToReconcile = true |
| 936 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 937 | //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] | 938 | dh.lockVlanConfig.Lock() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 939 | if _, exist = dh.UniVlanConfigFsmMap[uniData.PersUniID]; exist { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 940 | if err := dh.UniVlanConfigFsmMap[uniData.PersUniID].SetUniFlowParams(ctx, flowData.VlanRuleParams.TpID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 941 | flowData.CookieSlice, uint16(flowData.VlanRuleParams.MatchVid), uint16(flowData.VlanRuleParams.SetVid), |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 942 | uint8(flowData.VlanRuleParams.SetPcp), lastFlowToReconcile, flowData.Meter); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 943 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 944 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 945 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 946 | if err := dh.createVlanFilterFsm(ctx, uniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 947 | uint16(flowData.VlanRuleParams.MatchVid), uint16(flowData.VlanRuleParams.SetVid), |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 948 | uint8(flowData.VlanRuleParams.SetPcp), cmn.OmciVlanFilterAddDone, lastFlowToReconcile, flowData.Meter); err != nil { |
| 949 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 950 | } |
| 951 | } |
mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 952 | dh.lockVlanConfig.Unlock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 953 | flowsProcessed++ |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 954 | } //for all flows of this UNI |
| 955 | logger.Debugw(ctx, "reconciling - flows processed", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 956 | "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, "flowsProcessed": flowsProcessed, |
| 957 | "NumUniFlows": dh.UniVlanConfigFsmMap[uniData.PersUniID].NumUniFlows, |
| 958 | "ConfiguredUniFlow": dh.UniVlanConfigFsmMap[uniData.PersUniID].ConfiguredUniFlow}) |
Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 959 | // this can't be used as global finished reconciling flag because |
| 960 | // assumes is getting called before the state machines for the last flow is completed, |
| 961 | // while this is not guaranteed. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 962 | //dh.SetReconcilingFlows(false) |
| 963 | pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData |
| 964 | } // for all UNI entries from SOnuPersistentData |
| 965 | pDevEntry.MutexPersOnuConfig.RUnlock() |
mpagenko | 2dc896e | 2021-08-02 12:03:59 +0000 | [diff] [blame] | 966 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 967 | if !flowsFound { |
| 968 | 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] | 969 | log.Fields{"device-id": dh.DeviceID}) |
| 970 | if !dh.IsSkipOnuConfigReconciling() { |
| 971 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 7e9de86 | 2021-03-26 14:01:49 +0000 | [diff] [blame] | 972 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 973 | return |
| 974 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 975 | if dh.IsSkipOnuConfigReconciling() { |
| 976 | dh.SetDeviceReason(cmn.DrOmciFlowsPushed) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 977 | } |
| 978 | } |
| 979 | |
Holger Hildebrandt | 1b8f4ad | 2021-03-25 15:53:51 +0000 | [diff] [blame] | 980 | func (dh *deviceHandler) reconcileEnd(ctx context.Context) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 981 | logger.Debugw(ctx, "reconciling - completed!", log.Fields{"device-id": dh.DeviceID}) |
| 982 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 983 | } |
| 984 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 985 | func (dh *deviceHandler) deleteDevicePersistencyData(ctx context.Context) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 986 | 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] | 987 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 988 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 989 | if pDevEntry == nil { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 990 | //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] | 991 | 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] | 992 | return nil |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 993 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 994 | |
| 995 | // deadline context to ensure completion of background routines waited for |
| 996 | //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] | 997 | 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] | 998 | dctx, cancel := context.WithDeadline(ctx, deadline) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 999 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1000 | pDevEntry.ResetKvProcessingErrorIndication() |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1001 | |
| 1002 | var wg sync.WaitGroup |
| 1003 | wg.Add(1) // for the 1 go routine to finish |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1004 | go pDevEntry.DeleteDataFromOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1005 | dh.waitForCompletion(ctx, cancel, &wg, "DeleteDevice") //wait for background process to finish |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 1006 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1007 | // TODO: further actions - stop metrics and FSMs, remove device ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1008 | return pDevEntry.GetKvProcessingErrorIndication() |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1011 | //func (dh *deviceHandler) rebootDevice(ctx context.Context, device *voltha.Device) error { |
| 1012 | // before this change here return like this was used: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1013 | // return fmt.Errorf("device-unreachable: %s, %s", dh.DeviceID, device.SerialNumber) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1014 | //was and is called in background - error return does not make sense |
| 1015 | func (dh *deviceHandler) rebootDevice(ctx context.Context, aCheckDeviceState bool, device *voltha.Device) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1016 | 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] | 1017 | if aCheckDeviceState && device.ConnectStatus != voltha.ConnectStatus_REACHABLE { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1018 | 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] | 1019 | return |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1020 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1021 | if err := dh.pOnuOmciDevice.Reboot(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1022 | //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] | 1023 | 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] | 1024 | return |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1025 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1026 | |
| 1027 | //transfer the possibly modified logical uni port state |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1028 | dh.DisableUniPortStateUpdate(ctx) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1029 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1030 | 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] | 1031 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1032 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1033 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1034 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 1035 | OperStatus: voltha.OperStatus_DISCOVERED, |
| 1036 | }); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1037 | //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] | 1038 | 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] | 1039 | return |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1040 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1041 | if err := dh.deviceReasonUpdate(ctx, cmn.DrRebooting, true); err != nil { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1042 | return |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1043 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1044 | dh.SetReadyForOmciConfig(false) |
mpagenko | 8b07c1b | 2020-11-26 10:36:31 +0000 | [diff] [blame] | 1045 | //no specific activity to synchronize any internal FSM to the 'rebooted' state is explicitly done here |
| 1046 | // the expectation ids for a real device, that it will be synced with the expected following 'down' indication |
| 1047 | // as BBSIM does not support this testing requires explicite disable/enable device calls in which sequence also |
| 1048 | // all other FSM's should be synchronized again |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 1049 | } |
| 1050 | |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 1051 | //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] | 1052 | // used only for old - R2.7 style - upgrade API |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1053 | func (dh *deviceHandler) doOnuSwUpgrade(ctx context.Context, apImageDsc *voltha.ImageDownload, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1054 | apDownloadManager *swupg.AdapterDownloadManager) error { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1055 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1056 | "device-id": dh.DeviceID, "image-name": (*apImageDsc).Name}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1057 | |
| 1058 | var err error |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1059 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1060 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1061 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1062 | 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] | 1063 | } |
| 1064 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1065 | if dh.IsReadyForOmciConfig() { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1066 | var inactiveImageID uint16 |
| 1067 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1068 | dh.lockUpgradeFsm.Lock() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 1069 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
| 1070 | // but must be still locked at calling createOnuUpgradeFsm |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1071 | if dh.pOnuUpradeFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1072 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 1073 | dh.lockUpgradeFsm.Unlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1074 | if err == nil { |
| 1075 | if err = dh.pOnuUpradeFsm.SetDownloadParams(ctx, inactiveImageID, apImageDsc, apDownloadManager); err != nil { |
| 1076 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1077 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1078 | } |
| 1079 | } else { |
| 1080 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1081 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1082 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1083 | } else { //OnuSw upgrade already running - restart (with possible abort of running) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 1084 | dh.lockUpgradeFsm.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1085 | 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^] | 1086 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1087 | dh.upgradeCanceled = true |
| 1088 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1089 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1090 | //no effort spent anymore for the old API to automatically cancel and restart the download |
| 1091 | // like done for the new API |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1092 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1093 | } else { |
| 1094 | 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] | 1095 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 1096 | } |
| 1097 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1098 | logger.Errorw(ctx, "start Onu SW upgrade rejected: no active OMCI connection", log.Fields{"device-id": dh.DeviceID}) |
| 1099 | 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] | 1100 | } |
| 1101 | return err |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1104 | //onuSwUpgradeAfterDownload initiates the SW download transfer to the ONU with activate and commit options |
| 1105 | // after the OnuImage has been downloaded to the adapter, called in background |
| 1106 | func (dh *deviceHandler) onuSwUpgradeAfterDownload(ctx context.Context, apImageRequest *voltha.DeviceImageDownloadRequest, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1107 | apDownloadManager *swupg.FileDownloadManager, aImageIdentifier string) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1108 | |
| 1109 | var err error |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1110 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1111 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1112 | 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] | 1113 | return |
| 1114 | } |
| 1115 | |
| 1116 | var inactiveImageID uint16 |
| 1117 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil { |
| 1118 | logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1119 | "device-id": dh.DeviceID, "image-version": apImageRequest.Image.Version, "to onu-image": inactiveImageID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1120 | |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 1121 | dh.lockUpgradeFsm.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1122 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 1123 | // but must be still locked at calling createOnuUpgradeFsm |
| 1124 | // (and working with a local pointer copy does not work here if asynchronous request are done to fast |
| 1125 | // [e.g.leaving the local pointer on nil even though a creation is already on the way]) |
| 1126 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1127 | //OnuSw upgrade already running on this device (e.g. with activate/commit not yet set) |
| 1128 | // abort the current processing, running upgrades are always aborted by newer request |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1129 | 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] | 1130 | //flush the remove upgradeFsmChan channel |
| 1131 | select { |
| 1132 | case <-dh.upgradeFsmChan: |
| 1133 | logger.Debug(ctx, "flushed-upgrade-fsm-channel") |
| 1134 | default: |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1135 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 1136 | dh.lockUpgradeFsm.Unlock() |
| 1137 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1138 | dh.upgradeCanceled = true |
| 1139 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1140 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1141 | select { |
| 1142 | case <-time.After(cTimeOutRemoveUpgrade * time.Second): |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1143 | 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] | 1144 | //should not appear, can't proceed with new upgrade, perhaps operator can retry manually later |
| 1145 | return |
| 1146 | case <-dh.upgradeFsmChan: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1147 | 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] | 1148 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 1149 | dh.lockUpgradeFsm.Lock() //lock again for following creation |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1150 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1151 | |
| 1152 | //here it can be assumed that no running upgrade processing exists (anymore) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 1153 | //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] | 1154 | // but none yet defined |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1155 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 1156 | dh.lockUpgradeFsm.Unlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1157 | if err == nil { |
| 1158 | if err = dh.pOnuUpradeFsm.SetDownloadParamsAfterDownload(ctx, inactiveImageID, |
| 1159 | apImageRequest, apDownloadManager, aImageIdentifier); err != nil { |
| 1160 | logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1161 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1162 | return |
| 1163 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1164 | } else { |
| 1165 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1166 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1167 | } |
| 1168 | return |
| 1169 | } |
| 1170 | 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] | 1171 | "device-id": dh.DeviceID, "error": err}) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | //onuSwActivateRequest ensures activation of the requested image with commit options |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1175 | func (dh *deviceHandler) onuSwActivateRequest(ctx context.Context, |
| 1176 | aVersion string, aCommitRequest bool) (*voltha.ImageState, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1177 | var err error |
| 1178 | //SW activation for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1179 | // 1.) activation of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1180 | // 2.) activation of the inactive image |
| 1181 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1182 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1183 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1184 | logger.Errorw(ctx, "Onu image activation rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1185 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1186 | } |
| 1187 | dh.lockUpgradeFsm.RLock() |
| 1188 | if dh.pOnuUpradeFsm != nil { |
| 1189 | dh.lockUpgradeFsm.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1190 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1191 | if getErr != nil || onuVolthaDevice == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1192 | logger.Errorw(ctx, "Failed to fetch Onu device for image activation", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1193 | 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] | 1194 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 1195 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1196 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1197 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1198 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1199 | // use the OnuVendor identification from this device for the internal unique name |
| 1200 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1201 | // 1.) check a started upgrade process and relay the activation request to it |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1202 | if err = dh.pOnuUpradeFsm.SetActivationParamsRunning(ctx, imageIdentifier, aCommitRequest); err != nil { |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1203 | //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] | 1204 | 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] | 1205 | "device-id": dh.DeviceID, "error": err}) |
| 1206 | 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] | 1207 | } |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1208 | logger.Debugw(ctx, "image activation acknowledged by onu upgrade processing", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1209 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1210 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1211 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1212 | } //else |
| 1213 | dh.lockUpgradeFsm.RUnlock() |
| 1214 | |
| 1215 | // 2.) check if requested image-version equals the inactive one and start its activation |
| 1216 | // (image version is not [yet] checked - would be possible, but with increased effort ...) |
| 1217 | var inactiveImageID uint16 |
| 1218 | if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err != nil || inactiveImageID > 1 { |
| 1219 | logger.Errorw(ctx, "get inactive image failed", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1220 | "device-id": dh.DeviceID, "err": err, "image-id": inactiveImageID}) |
| 1221 | 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] | 1222 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1223 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1224 | if err == nil { |
| 1225 | if err = dh.pOnuUpradeFsm.SetActivationParamsStart(ctx, aVersion, |
| 1226 | inactiveImageID, aCommitRequest); err != nil { |
| 1227 | 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] | 1228 | "device-id": dh.DeviceID, "error": err}) |
| 1229 | 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] | 1230 | } |
| 1231 | logger.Debugw(ctx, "inactive image activation acknowledged by onu upgrade", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1232 | "device-id": dh.DeviceID, "image-version": aVersion}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1233 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1234 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1235 | } //else |
| 1236 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1237 | "device-id": dh.DeviceID, "error": err}) |
| 1238 | 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] | 1239 | } |
| 1240 | |
| 1241 | //onuSwCommitRequest ensures commitment of the requested image |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1242 | func (dh *deviceHandler) onuSwCommitRequest(ctx context.Context, |
| 1243 | aVersion string) (*voltha.ImageState, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1244 | var err error |
| 1245 | //SW commitment for the ONU image may have two use cases, one of them is selected here according to following prioritization: |
| 1246 | // 1.) commitment of the image for a started upgrade process (in case the running upgrade runs on the requested image) |
| 1247 | // 2.) commitment of the active image |
| 1248 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1249 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1250 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1251 | logger.Errorw(ctx, "Onu image commitment rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 1252 | return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1253 | } |
| 1254 | dh.lockUpgradeFsm.RLock() |
| 1255 | if dh.pOnuUpradeFsm != nil { |
| 1256 | dh.lockUpgradeFsm.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1257 | onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1258 | if getErr != nil || onuVolthaDevice == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1259 | logger.Errorw(ctx, "Failed to fetch Onu device for image commitment", log.Fields{"device-id": dh.DeviceID, "err": getErr}) |
| 1260 | 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] | 1261 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 1262 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 1263 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 1264 | return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID) |
| 1265 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1266 | // use the OnuVendor identification from this device for the internal unique name |
| 1267 | imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1268 | // 1.) check a started upgrade process and relay the commitment request to it |
| 1269 | // the running upgrade may be based either on the imageIdentifier (started from download) |
| 1270 | // or on the imageVersion (started from pure activation) |
| 1271 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsRunning(ctx, imageIdentifier, aVersion); err != nil { |
| 1272 | //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] | 1273 | 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] | 1274 | "device-id": dh.DeviceID, "error": err}) |
| 1275 | 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] | 1276 | } |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1277 | logger.Debugw(ctx, "image commitment acknowledged by onu upgrade processing", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1278 | "device-id": dh.DeviceID, "image-id": imageIdentifier}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1279 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1280 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1281 | } //else |
| 1282 | dh.lockUpgradeFsm.RUnlock() |
| 1283 | |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1284 | // 2.) use the active image to directly commit |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1285 | var activeImageID uint16 |
| 1286 | if activeImageID, err = pDevEntry.GetActiveImageMeID(ctx); err != nil || activeImageID > 1 { |
| 1287 | logger.Errorw(ctx, "get active image failed", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1288 | "device-id": dh.DeviceID, "err": err, "image-id": activeImageID}) |
| 1289 | 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] | 1290 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1291 | err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1292 | if err == nil { |
| 1293 | if err = dh.pOnuUpradeFsm.SetCommitmentParamsStart(ctx, aVersion, activeImageID); err != nil { |
| 1294 | 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] | 1295 | "device-id": dh.DeviceID, "error": err}) |
| 1296 | 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] | 1297 | } |
| 1298 | logger.Debugw(ctx, "active image commitment acknowledged by onu upgrade", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1299 | "device-id": dh.DeviceID, "image-version": aVersion}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1300 | pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 1301 | return pImageStates, nil |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 1302 | } //else |
| 1303 | logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1304 | "device-id": dh.DeviceID, "error": err}) |
| 1305 | 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] | 1306 | } |
| 1307 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1308 | func (dh *deviceHandler) requestOnuSwUpgradeState(ctx context.Context, aImageIdentifier string, |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1309 | aVersion string) *voltha.ImageState { |
| 1310 | var pImageState *voltha.ImageState |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1311 | dh.lockUpgradeFsm.RLock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1312 | defer dh.lockUpgradeFsm.RUnlock() |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1313 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1314 | pImageState = dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1315 | } else { //use the last stored ImageState (if the requested Imageversion coincides) |
| 1316 | if aVersion == dh.pLastUpgradeImageState.Version { |
| 1317 | pImageState = dh.pLastUpgradeImageState |
| 1318 | } else { //state request for an image version different from last processed image version |
| 1319 | pImageState = &voltha.ImageState{ |
| 1320 | Version: aVersion, |
| 1321 | //we cannot state something concerning this version |
| 1322 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, |
| 1323 | Reason: voltha.ImageState_NO_ERROR, |
| 1324 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 1325 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1326 | } |
| 1327 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1328 | return pImageState |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | func (dh *deviceHandler) cancelOnuSwUpgrade(ctx context.Context, aImageIdentifier string, |
| 1332 | aVersion string, pDeviceImageState *voltha.DeviceImageState) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1333 | pDeviceImageState.DeviceId = dh.DeviceID |
mpagenko | 7455fd4 | 2021-06-10 16:25:55 +0000 | [diff] [blame] | 1334 | pDeviceImageState.ImageState.Version = aVersion |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1335 | dh.lockUpgradeFsm.RLock() |
| 1336 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1337 | dh.lockUpgradeFsm.RUnlock() |
| 1338 | // so then we cancel the upgrade operation |
| 1339 | // but before we still request the actual upgrade states (which should not change with the cancellation) |
| 1340 | pImageState := dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion) |
| 1341 | pDeviceImageState.ImageState.DownloadState = pImageState.DownloadState |
| 1342 | pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST |
| 1343 | pDeviceImageState.ImageState.ImageState = pImageState.ImageState |
| 1344 | if pImageState.DownloadState != voltha.ImageState_DOWNLOAD_UNKNOWN { |
| 1345 | //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^] | 1346 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 1347 | dh.upgradeCanceled = true |
| 1348 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort |
| 1349 | } |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1350 | } //nothing to cancel (upgrade FSM for different image stays alive) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1351 | } else { |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 1352 | dh.lockUpgradeFsm.RUnlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1353 | // if no upgrade is ongoing, nothing is canceled and accordingly the states of the requested image are unknown |
| 1354 | // reset also the dh handler LastUpgradeImageState (not relevant anymore/cleared) |
| 1355 | (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1356 | (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR |
| 1357 | (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1358 | (*dh.pLastUpgradeImageState).Version = "" //reset to 'no (relevant) upgrade done' (like initial state) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1359 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 1360 | pDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 1361 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 1362 | //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] | 1363 | } |
| 1364 | } |
| 1365 | |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1366 | func (dh *deviceHandler) getOnuImages(ctx context.Context) (*voltha.OnuImages, error) { |
| 1367 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1368 | var onuImageStatus *swupg.OnuImageStatus |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1369 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1370 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1371 | if pDevEntry != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1372 | onuImageStatus = swupg.NewOnuImageStatus(dh, pDevEntry) |
| 1373 | pDevEntry.MutexOnuImageStatus.Lock() |
| 1374 | pDevEntry.POnuImageStatus = onuImageStatus |
| 1375 | pDevEntry.MutexOnuImageStatus.Unlock() |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1376 | |
| 1377 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1378 | 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] | 1379 | return nil, fmt.Errorf("no-valid-OnuDevice-aborting") |
| 1380 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1381 | images, err := onuImageStatus.GetOnuImageStatus(ctx) |
| 1382 | pDevEntry.MutexOnuImageStatus.Lock() |
| 1383 | pDevEntry.POnuImageStatus = nil |
| 1384 | pDevEntry.MutexOnuImageStatus.Unlock() |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1385 | return images, err |
| 1386 | } |
| 1387 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1388 | // deviceHandler methods that implement the adapters interface requests## end ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1389 | // ##################################################################################### |
| 1390 | |
| 1391 | // ################ to be updated acc. needs of ONU Device ######################## |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1392 | // deviceHandler StateMachine related state transition methods ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1393 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1394 | func (dh *deviceHandler) logStateChange(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1395 | 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] | 1396 | } |
| 1397 | |
| 1398 | // doStateInit provides the device update to the core |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1399 | func (dh *deviceHandler) doStateInit(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1400 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1401 | logger.Debug(ctx, "doStateInit-started") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1402 | var err error |
| 1403 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1404 | // populate what we know. rest comes later after mib sync |
| 1405 | dh.device.Root = false |
| 1406 | dh.device.Vendor = "OpenONU" |
| 1407 | dh.device.Model = "go" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1408 | dh.device.Reason = cmn.DeviceReasonMap[cmn.DrActivatingOnu] |
| 1409 | dh.SetDeviceReason(cmn.DrActivatingOnu) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1410 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1411 | dh.logicalDeviceID = dh.DeviceID // really needed - what for ??? //TODO!!! |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1412 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1413 | if !dh.IsReconciling() { |
| 1414 | 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] | 1415 | if err := dh.updateDeviceInCore(ctx, dh.device); err != nil { |
| 1416 | logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err}) |
| 1417 | } |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 1418 | //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] | 1419 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1420 | logger.Debugw(ctx, "reconciling - don't notify core about DeviceUpdate", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1421 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1422 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1423 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1424 | dh.parentID = dh.device.ParentId |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1425 | dh.ponPortNumber = dh.device.ParentPortNo |
| 1426 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1427 | // store proxy parameters for later communication - assumption: invariant, else they have to be requested dynamically!! |
| 1428 | dh.ProxyAddressID = dh.device.ProxyAddress.GetDeviceId() |
| 1429 | dh.ProxyAddressType = dh.device.ProxyAddress.GetDeviceType() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1430 | 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] | 1431 | "proxyAddressType": dh.ProxyAddressType, "SNR": dh.device.SerialNumber, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1432 | "ParentId": dh.parentID, "ParentPortNo": dh.ponPortNumber}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1433 | |
| 1434 | /* |
| 1435 | self._pon = PonPort.create(self, self._pon_port_number) |
| 1436 | self._pon.add_peer(self.parent_id, self._pon_port_number) |
| 1437 | self.logger.debug('adding-pon-port-to-agent', |
| 1438 | type=self._pon.get_port().type, |
| 1439 | admin_state=self._pon.get_port().admin_state, |
| 1440 | oper_status=self._pon.get_port().oper_status, |
| 1441 | ) |
| 1442 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1443 | if !dh.IsReconciling() { |
| 1444 | 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] | 1445 | var ponPortNo uint32 = 1 |
| 1446 | if dh.ponPortNumber != 0 { |
| 1447 | ponPortNo = dh.ponPortNumber |
| 1448 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1449 | |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1450 | pPonPort := &voltha.Port{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1451 | DeviceId: dh.DeviceID, |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1452 | PortNo: ponPortNo, |
| 1453 | Label: fmt.Sprintf("pon-%d", ponPortNo), |
| 1454 | Type: voltha.Port_PON_ONU, |
| 1455 | OperStatus: voltha.OperStatus_ACTIVE, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1456 | Peers: []*voltha.Port_PeerPort{{DeviceId: dh.parentID, // Peer device is OLT |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1457 | PortNo: ponPortNo}}, // Peer port is parent's port number |
| 1458 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1459 | if err = dh.CreatePortInCore(ctx, pPonPort); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1460 | logger.Fatalf(ctx, "Device FSM: PortCreated-failed-%s", err) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1461 | e.Cancel(err) |
| 1462 | return |
| 1463 | } |
| 1464 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1465 | 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] | 1466 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1467 | logger.Debug(ctx, "doStateInit-done") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | // postInit setups the DeviceEntry for the conerned device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1471 | func (dh *deviceHandler) postInit(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1472 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1473 | logger.Debug(ctx, "postInit-started") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1474 | var err error |
| 1475 | /* |
| 1476 | dh.Client = oop.NewOpenoltClient(dh.clientCon) |
| 1477 | dh.pTransitionMap.Handle(ctx, GrpcConnected) |
| 1478 | return nil |
| 1479 | */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1480 | if err = dh.addOnuDeviceEntry(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
| 1481 | logger.Fatalf(ctx, "Device FSM: addOnuDeviceEntry-failed-%s", err) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1482 | e.Cancel(err) |
| 1483 | return |
| 1484 | } |
| 1485 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1486 | if dh.IsReconciling() { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1487 | go dh.reconcileDeviceOnuInd(ctx) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1488 | // reconcilement will be continued after mib download is done |
| 1489 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1490 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1491 | /* |
| 1492 | ############################################################################ |
| 1493 | # Setup Alarm handler |
| 1494 | self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id, |
| 1495 | device.serial_number) |
| 1496 | ############################################################################ |
| 1497 | # Setup PM configuration for this device |
| 1498 | # Pass in ONU specific options |
| 1499 | kwargs = { |
| 1500 | OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY, |
| 1501 | 'heartbeat': self.heartbeat, |
| 1502 | OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device |
| 1503 | } |
| 1504 | self.logger.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number) |
| 1505 | self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id, |
| 1506 | self.logical_device_id, device.serial_number, |
| 1507 | grouped=True, freq_override=False, **kwargs) |
| 1508 | pm_config = self._pm_metrics.make_proto() |
| 1509 | self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm) |
| 1510 | self.logger.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number) |
| 1511 | yield self.core_proxy.device_pm_config_update(pm_config, init=True) |
| 1512 | |
| 1513 | # Note, ONU ID and UNI intf set in add_uni_port method |
| 1514 | self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events, |
| 1515 | ani_ports=[self._pon]) |
| 1516 | |
| 1517 | # Code to Run OMCI Test Action |
| 1518 | kwargs_omci_test_action = { |
| 1519 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 1520 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 1521 | } |
| 1522 | serial_number = device.serial_number |
| 1523 | self._test_request = OmciTestRequest(self.core_proxy, |
| 1524 | self.omci_agent, self.device_id, |
| 1525 | AniG, serial_number, |
| 1526 | self.logical_device_id, |
| 1527 | exclusive=False, |
| 1528 | **kwargs_omci_test_action) |
| 1529 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1530 | self.Enabled = True |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1531 | else: |
| 1532 | self.logger.info('onu-already-activated') |
| 1533 | */ |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1534 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1535 | logger.Debug(ctx, "postInit-done") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | // doStateConnected get the device info and update to voltha core |
| 1539 | // for comparison of the original method (not that easy to uncomment): compare here: |
| 1540 | // voltha-openolt-adapter/adaptercore/device_handler.go |
| 1541 | // -> this one obviously initiates all communication interfaces of the device ...? |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1542 | func (dh *deviceHandler) doStateConnected(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1543 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1544 | logger.Debug(ctx, "doStateConnected-started") |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1545 | err := errors.New("device FSM: function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1546 | e.Cancel(err) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1547 | logger.Debug(ctx, "doStateConnected-done") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | // doStateUp handle the onu up indication and update to voltha core |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1551 | func (dh *deviceHandler) doStateUp(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1552 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1553 | logger.Debug(ctx, "doStateUp-started") |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1554 | err := errors.New("device FSM: function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1555 | e.Cancel(err) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1556 | logger.Debug(ctx, "doStateUp-done") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1557 | |
| 1558 | /* |
| 1559 | // Synchronous call to update device state - this method is run in its own go routine |
| 1560 | if err := dh.coreProxy.DeviceStateUpdate(ctx, dh.device.Id, voltha.ConnectStatus_REACHABLE, |
| 1561 | voltha.OperStatus_ACTIVE); err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1562 | 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] | 1563 | return err |
| 1564 | } |
| 1565 | return nil |
| 1566 | */ |
| 1567 | } |
| 1568 | |
| 1569 | // doStateDown handle the onu down indication |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1570 | func (dh *deviceHandler) doStateDown(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1571 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1572 | logger.Debug(ctx, "doStateDown-started") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1573 | var err error |
| 1574 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1575 | device := dh.device |
| 1576 | if device == nil { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1577 | /*TODO: needs to handle error scenarios */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1578 | 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] | 1579 | e.Cancel(err) |
| 1580 | return |
| 1581 | } |
| 1582 | |
| 1583 | cloned := proto.Clone(device).(*voltha.Device) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1584 | logger.Debugw(ctx, "do-state-down", log.Fields{"ClonedDeviceID": cloned.Id}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1585 | /* |
| 1586 | // Update the all ports state on that device to disable |
| 1587 | if er := dh.coreProxy.PortsStateUpdate(ctx, cloned.Id, voltha.OperStatus_UNKNOWN); er != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1588 | 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] | 1589 | return er |
| 1590 | } |
| 1591 | |
| 1592 | //Update the device oper state and connection status |
| 1593 | cloned.OperStatus = voltha.OperStatus_UNKNOWN |
| 1594 | cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE |
| 1595 | dh.device = cloned |
| 1596 | |
| 1597 | 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] | 1598 | 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] | 1599 | return er |
| 1600 | } |
| 1601 | |
| 1602 | //get the child device for the parent device |
| 1603 | onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id) |
| 1604 | if err != nil { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1605 | 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] | 1606 | return err |
| 1607 | } |
| 1608 | for _, onuDevice := range onuDevices.Items { |
| 1609 | |
| 1610 | // Update onu state as down in onu adapter |
| 1611 | onuInd := oop.OnuIndication{} |
| 1612 | onuInd.OperState = "down" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1613 | er := dh.adapterProxy.SendInterAdapterMessage(ctx, &onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1614 | "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "") |
| 1615 | if er != nil { |
| 1616 | logger.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1617 | "From Adapter": "openolt", "DevieType": onuDevice.Type, "device-id": onuDevice.Id}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1618 | //Do not return here and continue to process other ONUs |
| 1619 | } |
| 1620 | } |
| 1621 | // * Discovered ONUs entries need to be cleared , since after OLT |
| 1622 | // is up, it starts sending discovery indications again* / |
| 1623 | dh.discOnus = sync.Map{} |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1624 | logger.Debugw("do-state-down-end", log.Fields{"device-id": device.Id}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1625 | return nil |
| 1626 | */ |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1627 | err = errors.New("device FSM: function not implemented yet") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1628 | e.Cancel(err) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1629 | logger.Debug(ctx, "doStateDown-done") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1630 | } |
| 1631 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1632 | // deviceHandler StateMachine related state transition methods ##### end ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1633 | // ################################################################################# |
| 1634 | |
| 1635 | // ################################################### |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1636 | // deviceHandler utility methods ##### begin ######### |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1637 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1638 | //GetOnuDeviceEntry gets the ONU device entry and may wait until its value is defined |
| 1639 | func (dh *deviceHandler) GetOnuDeviceEntry(ctx context.Context, aWait bool) *mib.OnuDeviceEntry { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1640 | dh.lockDevice.RLock() |
| 1641 | pOnuDeviceEntry := dh.pOnuOmciDevice |
| 1642 | if aWait && pOnuDeviceEntry == nil { |
| 1643 | //keep the read sema short to allow for subsequent write |
| 1644 | dh.lockDevice.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1645 | 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] | 1646 | // based on concurrent processing the deviceEntry setup may not yet be finished at his point |
| 1647 | // so it might be needed to wait here for that event with some timeout |
| 1648 | select { |
| 1649 | case <-time.After(60 * time.Second): //timer may be discussed ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1650 | 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] | 1651 | return nil |
| 1652 | case <-dh.deviceEntrySet: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1653 | logger.Debugw(ctx, "devicEntry ready now - continue", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1654 | // if written now, we can return the written value without sema |
| 1655 | return dh.pOnuOmciDevice |
| 1656 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1657 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1658 | dh.lockDevice.RUnlock() |
| 1659 | return pOnuDeviceEntry |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1662 | //setDeviceHandlerEntries sets the ONU device entry within the handler |
| 1663 | func (dh *deviceHandler) setDeviceHandlerEntries(apDeviceEntry *mib.OnuDeviceEntry, apOnuTp *avcfg.OnuUniTechProf, |
| 1664 | apOnuMetricsMgr *pmmgr.OnuMetricsManager, apOnuAlarmMgr *almgr.OnuAlarmManager, apSelfTestHdlr *otst.SelfTestControlBlock) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1665 | dh.lockDevice.Lock() |
| 1666 | defer dh.lockDevice.Unlock() |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 1667 | dh.pOnuOmciDevice = apDeviceEntry |
| 1668 | dh.pOnuTP = apOnuTp |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1669 | dh.pOnuMetricsMgr = apOnuMetricsMgr |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 1670 | dh.pAlarmMgr = apOnuAlarmMgr |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 1671 | dh.pSelfTestHdlr = apSelfTestHdlr |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 1674 | //addOnuDeviceEntry creates a new ONU device or returns the existing |
| 1675 | func (dh *deviceHandler) addOnuDeviceEntry(ctx context.Context) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1676 | logger.Debugw(ctx, "adding-deviceEntry", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1677 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1678 | deviceEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1679 | if deviceEntry == nil { |
| 1680 | /* costum_me_map in python code seems always to be None, |
| 1681 | we omit that here first (declaration unclear) -> todo at Adapter specialization ...*/ |
| 1682 | /* also no 'clock' argument - usage open ...*/ |
| 1683 | /* and no alarm_db yet (oo.alarm_db) */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1684 | deviceEntry = mib.NewOnuDeviceEntry(ctx, dh.coreClient, dh, dh.pOpenOnuAc) |
| 1685 | onuTechProfProc := avcfg.NewOnuUniTechProf(ctx, dh, deviceEntry) |
| 1686 | onuMetricsMgr := pmmgr.NewOnuMetricsManager(ctx, dh, deviceEntry) |
| 1687 | onuAlarmManager := almgr.NewAlarmManager(ctx, dh, deviceEntry) |
| 1688 | selfTestHdlr := otst.NewSelfTestMsgHandlerCb(ctx, dh, deviceEntry) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1689 | //error treatment possible //TODO!!! |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1690 | dh.setDeviceHandlerEntries(deviceEntry, onuTechProfProc, onuMetricsMgr, onuAlarmManager, selfTestHdlr) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1691 | // fire deviceEntry ready event to spread to possibly waiting processing |
| 1692 | dh.deviceEntrySet <- true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1693 | logger.Debugw(ctx, "onuDeviceEntry-added", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1694 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1695 | 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] | 1696 | } |
| 1697 | // might be updated with some error handling !!! |
| 1698 | return nil |
| 1699 | } |
| 1700 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1701 | func (dh *deviceHandler) createInterface(ctx context.Context, onuind *oop.OnuIndication) error { |
| 1702 | logger.Debugw(ctx, "create_interface-started", log.Fields{"OnuId": onuind.GetOnuId(), |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1703 | "OnuIntfId": onuind.GetIntfId(), "OnuSerialNumber": onuind.GetSerialNumber()}) |
| 1704 | |
| 1705 | dh.pOnuIndication = onuind // let's revise if storing the pointer is sufficient... |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1706 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1707 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1708 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1709 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 1710 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1711 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1712 | if !dh.IsReconciling() { |
| 1713 | if err := dh.StorePersistentData(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1714 | 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] | 1715 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1716 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1717 | 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] | 1718 | "OperStatus": voltha.OperStatus_ACTIVATING, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1719 | |
| 1720 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1721 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1722 | OperStatus: voltha.OperStatus_ACTIVATING, |
| 1723 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 1724 | }); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1725 | //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] | 1726 | 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] | 1727 | } |
| 1728 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1729 | logger.Debugw(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVATING", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1730 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1731 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1732 | pDevEntry.MutexPersOnuConfig.RLock() |
| 1733 | if !pDevEntry.SOnuPersistentData.PersUniUnlockDone { |
| 1734 | pDevEntry.MutexPersOnuConfig.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1735 | 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] | 1736 | log.Fields{"device-id": dh.DeviceID}) |
| 1737 | dh.StopReconciling(ctx, true) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1738 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1739 | pDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1740 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1741 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1742 | // It does not look to me as if makes sense to work with the real core device here, (not the stored clone)? |
| 1743 | // in this code the GetDevice would just make a check if the DeviceID's Device still exists in core |
| 1744 | // 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] | 1745 | // 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] | 1746 | // so let's just try to keep it simple ... |
| 1747 | /* |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1748 | 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] | 1749 | if err != nil || device == nil { |
| 1750 | //TODO: needs to handle error scenarios |
| 1751 | logger.Errorw("Failed to fetch device device at creating If", log.Fields{"err": err}) |
| 1752 | return errors.New("Voltha Device not found") |
| 1753 | } |
| 1754 | */ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1755 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1756 | if err := pDevEntry.Start(log.WithSpanFromContext(context.TODO(), ctx)); err != nil { |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1757 | return err |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1758 | } |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 1759 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1760 | _ = dh.deviceReasonUpdate(ctx, cmn.DrStartingOpenomci, !dh.IsReconciling()) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1761 | |
| 1762 | /* this might be a good time for Omci Verify message? */ |
| 1763 | verifyExec := make(chan bool) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1764 | omciVerify := otst.NewOmciTestRequest(log.WithSpanFromContext(context.TODO(), ctx), |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1765 | dh.device.Id, pDevEntry.PDevOmciCC, |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1766 | true, true) //exclusive and allowFailure (anyway not yet checked) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1767 | omciVerify.PerformOmciTest(log.WithSpanFromContext(context.TODO(), ctx), verifyExec) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1768 | |
| 1769 | /* give the handler some time here to wait for the OMCi verification result |
| 1770 | after Timeout start and try MibUpload FSM anyway |
| 1771 | (to prevent stopping on just not supported OMCI verification from ONU) */ |
| 1772 | select { |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 1773 | case <-time.After(pDevEntry.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1774 | logger.Warn(ctx, "omci start-verification timed out (continue normal)") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1775 | case testresult := <-verifyExec: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1776 | logger.Infow(ctx, "Omci start verification done", log.Fields{"result": testresult}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | /* In py code it looks earlier (on activate ..) |
| 1780 | # Code to Run OMCI Test Action |
| 1781 | kwargs_omci_test_action = { |
| 1782 | OmciTestRequest.DEFAULT_FREQUENCY_KEY: |
| 1783 | OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY |
| 1784 | } |
| 1785 | serial_number = device.serial_number |
| 1786 | self._test_request = OmciTestRequest(self.core_proxy, |
| 1787 | self.omci_agent, self.device_id, |
| 1788 | AniG, serial_number, |
| 1789 | self.logical_device_id, |
| 1790 | exclusive=False, |
| 1791 | **kwargs_omci_test_action) |
| 1792 | ... |
| 1793 | # Start test requests after a brief pause |
| 1794 | if not self._test_request_started: |
| 1795 | self._test_request_started = True |
| 1796 | tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5)) |
| 1797 | reactor.callLater(tststart, self._test_request.start_collector) |
| 1798 | |
| 1799 | */ |
| 1800 | /* which is then: in omci_test_request.py : */ |
| 1801 | /* |
| 1802 | def start_collector(self, callback=None): |
| 1803 | """ |
| 1804 | Start the collection loop for an adapter if the frequency > 0 |
| 1805 | |
| 1806 | :param callback: (callable) Function to call to collect PM data |
| 1807 | """ |
| 1808 | self.logger.info("starting-pm-collection", device_name=self.name, default_freq=self.default_freq) |
| 1809 | if callback is None: |
| 1810 | callback = self.perform_test_omci |
| 1811 | |
| 1812 | if self.lc is None: |
| 1813 | self.lc = LoopingCall(callback) |
| 1814 | |
| 1815 | if self.default_freq > 0: |
| 1816 | self.lc.start(interval=self.default_freq / 10) |
| 1817 | |
| 1818 | def perform_test_omci(self): |
| 1819 | """ |
| 1820 | Perform the initial test request |
| 1821 | """ |
| 1822 | ani_g_entities = self._device.configuration.ani_g_entities |
| 1823 | ani_g_entities_ids = list(ani_g_entities.keys()) if ani_g_entities \ |
| 1824 | is not None else None |
| 1825 | self._entity_id = ani_g_entities_ids[0] |
| 1826 | self.logger.info('perform-test', entity_class=self._entity_class, |
| 1827 | entity_id=self._entity_id) |
| 1828 | try: |
| 1829 | frame = MEFrame(self._entity_class, self._entity_id, []).test() |
| 1830 | result = yield self._device.omci_cc.send(frame) |
| 1831 | if not result.fields['omci_message'].fields['success_code']: |
| 1832 | self.logger.info('Self-Test Submitted Successfully', |
| 1833 | code=result.fields[ |
| 1834 | 'omci_message'].fields['success_code']) |
| 1835 | else: |
| 1836 | raise TestFailure('Test Failure: {}'.format( |
| 1837 | result.fields['omci_message'].fields['success_code'])) |
| 1838 | except TimeoutError as e: |
| 1839 | self.deferred.errback(failure.Failure(e)) |
| 1840 | |
| 1841 | except Exception as e: |
| 1842 | self.logger.exception('perform-test-Error', e=e, |
| 1843 | class_id=self._entity_class, |
| 1844 | entity_id=self._entity_id) |
| 1845 | self.deferred.errback(failure.Failure(e)) |
| 1846 | |
| 1847 | */ |
| 1848 | |
| 1849 | // PM related heartbeat??? !!!TODO.... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1850 | //self._heartbeat.Enabled = True |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1851 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1852 | /* Note: Even though FSM calls look 'synchronous' here, FSM is running in background with the effect that possible errors |
| 1853 | * within the MibUpload are not notified in the OnuIndication response, this might be acceptable here, |
| 1854 | * 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] | 1855 | * otherwise some processing synchronization would be required - cmp. e.g TechProfile processing |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 1856 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1857 | //call MibUploadFSM - transition up to state UlStInSync |
| 1858 | pMibUlFsm := pDevEntry.PMibUploadFsm.PFsm |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1859 | if pMibUlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1860 | if pMibUlFsm.Is(mib.UlStDisabled) { |
| 1861 | if err := pMibUlFsm.Event(mib.UlEvStart); err != nil { |
| 1862 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 1863 | return fmt.Errorf("can't go to state starting: %s", dh.DeviceID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1864 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1865 | logger.Debugw(ctx, "MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1866 | //Determine ONU status and start/re-start MIB Synchronization tasks |
| 1867 | //Determine if this ONU has ever synchronized |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1868 | if pDevEntry.IsNewOnu() { |
| 1869 | if err := pMibUlFsm.Event(mib.UlEvResetMib); err != nil { |
| 1870 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state resetting_mib", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 1871 | 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] | 1872 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1873 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1874 | if err := pMibUlFsm.Event(mib.UlEvExamineMds); err != nil { |
| 1875 | logger.Errorw(ctx, "MibSyncFsm: Can't go to state examine_mds", log.Fields{"device-id": dh.DeviceID, "err": err}) |
| 1876 | return fmt.Errorf("can't go to examine_mds: %s", dh.DeviceID) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1877 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1878 | logger.Debugw(ctx, "state of MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())}) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1879 | } |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1880 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1881 | 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] | 1882 | "device-id": dh.DeviceID}) |
| 1883 | return fmt.Errorf("wrong state of MibSyncFsm: %s", dh.DeviceID) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1884 | } |
| 1885 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1886 | logger.Errorw(ctx, "MibSyncFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID}) |
| 1887 | return fmt.Errorf("can't execute MibSync: %s", dh.DeviceID) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1888 | } |
| 1889 | return nil |
| 1890 | } |
| 1891 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1892 | func (dh *deviceHandler) updateInterface(ctx context.Context, onuind *oop.OnuIndication) error { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1893 | //state checking to prevent unneeded processing (eg. on ONU 'unreachable' and 'down') |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1894 | // (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] | 1895 | if dh.getDeviceReason() != cmn.DrStoppingOpenomci { |
| 1896 | logger.Debugw(ctx, "updateInterface-started - stopping-device", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1897 | |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1898 | //stop all running FSM processing - make use of the DH-state as mirrored in the deviceReason |
| 1899 | //here no conflict with aborted FSM's should arise as a complete OMCI initialization is assumed on ONU-Up |
| 1900 | //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] | 1901 | if err := dh.resetFsms(ctx, true); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1902 | logger.Errorw(ctx, "error-updateInterface at FSM stop", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1903 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1904 | // abort: system behavior is just unstable ... |
| 1905 | return err |
| 1906 | } |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 1907 | //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] | 1908 | _ = 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] | 1909 | |
| 1910 | //deviceEntry stop without omciCC reset here, regarding the OMCI_CC still valid for this ONU |
| 1911 | // - in contrary to disableDevice - compare with processUniDisableStateDoneEvent |
| 1912 | //stop the device entry which resets the attached omciCC |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1913 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1914 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1915 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 1916 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1917 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1918 | _ = pDevEntry.Stop(log.WithSpanFromContext(context.TODO(), ctx), false) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1919 | |
| 1920 | //TODO!!! remove existing traffic profiles |
| 1921 | /* from py code, if TP's exist, remove them - not yet implemented |
| 1922 | self._tp = dict() |
| 1923 | # Let TP download happen again |
| 1924 | for uni_id in self._tp_service_specific_task: |
| 1925 | self._tp_service_specific_task[uni_id].clear() |
| 1926 | for uni_id in self._tech_profile_download_done: |
| 1927 | self._tech_profile_download_done[uni_id].clear() |
| 1928 | */ |
| 1929 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1930 | dh.DisableUniPortStateUpdate(ctx) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1931 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1932 | dh.SetReadyForOmciConfig(false) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1933 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1934 | if err := dh.deviceReasonUpdate(ctx, cmn.DrStoppingOpenomci, true); err != nil { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1935 | // abort: system behavior is just unstable ... |
| 1936 | return err |
| 1937 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1938 | 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] | 1939 | "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1940 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1941 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1942 | ConnStatus: voltha.ConnectStatus_UNREACHABLE, |
| 1943 | OperStatus: voltha.OperStatus_DISCOVERED, |
| 1944 | }); err != nil { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 1945 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1946 | logger.Errorw(ctx, "error-updating-device-state unreachable-discovered", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1947 | log.Fields{"device-id": dh.DeviceID, "error": err}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1948 | // abort: system behavior is just unstable ... |
| 1949 | return err |
| 1950 | } |
| 1951 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1952 | logger.Debugw(ctx, "updateInterface - device already stopped", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 1953 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 1954 | return nil |
| 1955 | } |
| 1956 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1957 | func (dh *deviceHandler) resetFsms(ctx context.Context, includingMibSyncFsm bool) error { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1958 | //all possible FSM's are stopped or reset here to ensure their transition to 'disabled' |
| 1959 | //it is not sufficient to stop/reset the latest running FSM as done in previous versions |
| 1960 | // as after down/up procedures all FSM's might be active/ongoing (in theory) |
| 1961 | // and using the stop/reset event should never harm |
| 1962 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1963 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1964 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1965 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 1966 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1967 | } |
Holger Hildebrandt | c8ece36 | 2021-05-17 12:01:10 +0000 | [diff] [blame] | 1968 | if pDevEntry.PDevOmciCC != nil { |
mpagenko | 8cd1bf7 | 2021-06-22 10:11:19 +0000 | [diff] [blame] | 1969 | pDevEntry.PDevOmciCC.CancelRequestMonitoring(ctx) |
Holger Hildebrandt | c8ece36 | 2021-05-17 12:01:10 +0000 | [diff] [blame] | 1970 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1971 | pDevEntry.MutexOnuImageStatus.RLock() |
| 1972 | if pDevEntry.POnuImageStatus != nil { |
| 1973 | pDevEntry.POnuImageStatus.CancelProcessing(ctx) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 1974 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1975 | pDevEntry.MutexOnuImageStatus.RUnlock() |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 1976 | |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 1977 | if includingMibSyncFsm { |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 1978 | pDevEntry.CancelProcessing(ctx) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1979 | } |
| 1980 | //MibDownload may run |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1981 | pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1982 | if pMibDlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1983 | _ = pMibDlFsm.Event(mib.DlEvReset) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1984 | } |
| 1985 | //port lock/unlock FSM's may be active |
| 1986 | if dh.pUnlockStateFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1987 | _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1988 | } |
| 1989 | if dh.pLockStateFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1990 | _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 1991 | } |
| 1992 | //techProfile related PonAniConfigFsm FSM may be active |
| 1993 | if dh.pOnuTP != nil { |
| 1994 | // should always be the case here |
| 1995 | // 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] | 1996 | if dh.pOnuTP.PAniConfigFsm != nil { |
| 1997 | for uniTP := range dh.pOnuTP.PAniConfigFsm { |
| 1998 | dh.pOnuTP.PAniConfigFsm[uniTP].CancelProcessing(ctx) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 1999 | } |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2000 | } |
| 2001 | for _, uniPort := range dh.uniEntityMap { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2002 | // reset the possibly existing VlanConfigFsm |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2003 | dh.lockVlanConfig.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2004 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniPort.UniID]; exist { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2005 | //VlanFilterFsm exists and was already started |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2006 | dh.lockVlanConfig.RUnlock() |
| 2007 | //reset of all Fsm is always accompanied by global persistency data removal |
| 2008 | // no need to remove specific data |
| 2009 | pVlanFilterFsm.RequestClearPersistency(false) |
| 2010 | //ensure the FSM processing is stopped in case waiting for some response |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 2011 | pVlanFilterFsm.CancelProcessing(ctx) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2012 | } else { |
| 2013 | dh.lockVlanConfig.RUnlock() |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2014 | } |
| 2015 | } |
| 2016 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2017 | if dh.GetCollectorIsRunning() { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2018 | // Stop collector routine |
| 2019 | dh.stopCollector <- true |
| 2020 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2021 | if dh.GetAlarmManagerIsRunning(ctx) { |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2022 | dh.stopAlarmManager <- true |
| 2023 | } |
Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 2024 | if dh.pSelfTestHdlr.GetSelfTestHandlerIsRunning() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2025 | dh.pSelfTestHdlr.StopSelfTestModule <- true |
Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 2026 | } |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 2027 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2028 | //reset a possibly running upgrade FSM |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2029 | // (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] | 2030 | dh.lockUpgradeFsm.RLock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2031 | lopOnuUpradeFsm := dh.pOnuUpradeFsm |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2032 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2033 | dh.lockUpgradeFsm.RUnlock() |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2034 | if lopOnuUpradeFsm != nil { |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 2035 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 2036 | //here we do not expect intermediate cancelation, we still allow for other commands on this FSM |
| 2037 | // (even though it may also run into direct cancellation, a bit hard to verify here) |
| 2038 | // so don't set 'dh.upgradeCanceled = true' here! |
| 2039 | lopOnuUpradeFsm.CancelProcessing(ctx, false, voltha.ImageState_CANCELLED_ON_ONU_STATE) //conditional cancel |
| 2040 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2041 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2042 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2043 | logger.Infow(ctx, "resetFsms done", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2044 | return nil |
| 2045 | } |
| 2046 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2047 | func (dh *deviceHandler) processMibDatabaseSyncEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2048 | 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] | 2049 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2050 | // store persistent data collected during MIB upload processing |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2051 | if err := dh.StorePersistentData(ctx); err != nil { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2052 | 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] | 2053 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2054 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2055 | _ = dh.deviceReasonUpdate(ctx, cmn.DrDiscoveryMibsyncComplete, !dh.IsReconciling()) |
| 2056 | dh.AddAllUniPorts(ctx) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2057 | |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2058 | /* 200605: lock processing after initial MIBUpload removed now as the ONU should be in the lock state per default here */ |
| 2059 | /* 201117: build_dt-berlin-pod-openonugo_1T8GEM_voltha_DT_openonugo_master_test runs into error TC |
| 2060 | * 'Test Disable ONUs and OLT Then Delete ONUs and OLT for DT' with Sercom ONU, which obviously needs |
| 2061 | * disable/enable toggling here to allow traffic |
| 2062 | * but moreover it might be useful for tracking the interface operState changes if this will be implemented, |
| 2063 | * like the py comment says: |
| 2064 | * # start by locking all the unis till mib sync and initial mib is downloaded |
| 2065 | * # this way we can capture the port down/up events when we are ready |
| 2066 | */ |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2067 | |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2068 | // Init Uni Ports to Admin locked state |
| 2069 | // *** should generate UniLockStateDone event ***** |
| 2070 | if dh.pLockStateFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2071 | dh.createUniLockFsm(ctx, true, cmn.UniLockStateDone) |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2072 | } else { //LockStateFSM already init |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2073 | dh.pLockStateFsm.SetSuccessEvent(cmn.UniLockStateDone) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2074 | dh.runUniLockFsm(ctx, true) |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2075 | } |
| 2076 | } |
| 2077 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2078 | func (dh *deviceHandler) processUniLockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2079 | 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] | 2080 | /* Mib download procedure - |
| 2081 | ***** should run over 'downloaded' state and generate MibDownloadDone event ***** |
| 2082 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2083 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2084 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2085 | 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] | 2086 | return |
| 2087 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2088 | pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2089 | if pMibDlFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2090 | if pMibDlFsm.Is(mib.DlStDisabled) { |
| 2091 | if err := pMibDlFsm.Event(mib.DlEvStart); err != nil { |
| 2092 | 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] | 2093 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2094 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2095 | logger.Debugw(ctx, "MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2096 | // maybe use more specific states here for the specific download steps ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2097 | if err := pMibDlFsm.Event(mib.DlEvCreateGal); err != nil { |
| 2098 | 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] | 2099 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2100 | logger.Debugw(ctx, "state of MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2101 | //Begin MIB data download (running autonomously) |
| 2102 | } |
| 2103 | } |
| 2104 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2105 | 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] | 2106 | "device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2107 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2108 | } |
| 2109 | /***** Mib download started */ |
| 2110 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2111 | 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] | 2112 | } |
| 2113 | } |
| 2114 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2115 | func (dh *deviceHandler) processMibDownloadDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2116 | 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] | 2117 | //initiate DevStateUpdate |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2118 | if !dh.IsReconciling() { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2119 | 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] | 2120 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2121 | //we allow a possible OnuSw image commit only in the normal startup, not at reconciling |
| 2122 | // in case of adapter restart connected to an ONU upgrade I would not rely on the image quality |
| 2123 | // maybe some 'forced' commitment can be done in this situation from system management (or upgrade restarted) |
| 2124 | dh.checkOnOnuImageCommit(ctx) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2125 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2126 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2127 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2128 | OperStatus: voltha.OperStatus_ACTIVE, |
| 2129 | }); err != nil { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2130 | //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] | 2131 | 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] | 2132 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2133 | 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] | 2134 | } |
| 2135 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2136 | logger.Debugw(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVE", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2137 | log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2138 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2139 | _ = dh.deviceReasonUpdate(ctx, cmn.DrInitialMibDownloaded, !dh.IsReconciling()) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2140 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2141 | if !dh.GetCollectorIsRunning() { |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2142 | // Start PM collector routine |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2143 | go dh.StartCollector(ctx) |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2144 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2145 | if !dh.GetAlarmManagerIsRunning(ctx) { |
| 2146 | go dh.StartAlarmManager(ctx) |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2147 | } |
| 2148 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2149 | // Initialize classical L2 PM Interval Counters |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2150 | if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventInit); err != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2151 | // There is no way we should be landing here, but if we do then |
| 2152 | // there is nothing much we can do about this other than log error |
| 2153 | logger.Errorw(ctx, "error starting l2 pm fsm", log.Fields{"device-id": dh.device.Id, "err": err}) |
| 2154 | } |
| 2155 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2156 | dh.SetReadyForOmciConfig(true) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2157 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2158 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2159 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2160 | 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] | 2161 | return |
| 2162 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2163 | pDevEntry.MutexPersOnuConfig.RLock() |
| 2164 | if dh.IsReconciling() && pDevEntry.SOnuPersistentData.PersUniDisableDone { |
| 2165 | pDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2166 | 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] | 2167 | log.Fields{"device-id": dh.DeviceID}) |
| 2168 | go dh.ReconcileDeviceTechProf(ctx) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2169 | // reconcilement will be continued after ani config is done |
| 2170 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2171 | pDevEntry.MutexPersOnuConfig.RUnlock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2172 | // *** should generate UniUnlockStateDone event ***** |
| 2173 | if dh.pUnlockStateFsm == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2174 | dh.createUniLockFsm(ctx, false, cmn.UniUnlockStateDone) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2175 | } else { //UnlockStateFSM already init |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2176 | dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniUnlockStateDone) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2177 | dh.runUniLockFsm(ctx, false) |
| 2178 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2179 | } |
| 2180 | } |
| 2181 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2182 | func (dh *deviceHandler) processUniUnlockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2183 | dh.EnableUniPortStateUpdate(ctx) //cmp python yield self.enable_ports() |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2184 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2185 | if !dh.IsReconciling() { |
| 2186 | 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] | 2187 | raisedTs := time.Now().Unix() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2188 | go dh.sendOnuOperStateEvent(ctx, voltha.OperStatus_ACTIVE, dh.DeviceID, raisedTs) //cmp python onu_active_event |
| 2189 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2190 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2191 | 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] | 2192 | return |
| 2193 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2194 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2195 | pDevEntry.SOnuPersistentData.PersUniUnlockDone = true |
| 2196 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2197 | if err := dh.StorePersistentData(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2198 | 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] | 2199 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2200 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2201 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2202 | 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] | 2203 | log.Fields{"device-id": dh.DeviceID}) |
| 2204 | go dh.ReconcileDeviceTechProf(ctx) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2205 | // reconcilement will be continued after ani config is done |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2206 | } |
| 2207 | } |
| 2208 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2209 | func (dh *deviceHandler) processUniDisableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2210 | logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2211 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2212 | |
| 2213 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2214 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2215 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2216 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 2217 | }); err != nil { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2218 | //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] | 2219 | 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] | 2220 | } |
| 2221 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2222 | 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] | 2223 | // 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] | 2224 | _ = dh.deviceReasonUpdate(ctx, cmn.DrOmciAdminLock, true) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2225 | |
| 2226 | //transfer the modified logical uni port state |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2227 | dh.DisableUniPortStateUpdate(ctx) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2228 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2229 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2230 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2231 | 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] | 2232 | return |
| 2233 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2234 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2235 | pDevEntry.SOnuPersistentData.PersUniDisableDone = true |
| 2236 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2237 | if err := dh.StorePersistentData(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2238 | 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] | 2239 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2240 | } |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2241 | } |
| 2242 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2243 | func (dh *deviceHandler) processUniEnableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2244 | 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] | 2245 | "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2246 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2247 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2248 | ConnStatus: voltha.ConnectStatus_REACHABLE, |
| 2249 | OperStatus: voltha.OperStatus_ACTIVE, |
| 2250 | }); err != nil { |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2251 | //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] | 2252 | 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] | 2253 | } |
| 2254 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2255 | logger.Debugw(ctx, "DeviceReasonUpdate upon re-enable", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2256 | "reason": cmn.DeviceReasonMap[cmn.DrOnuReenabled], "device-id": dh.DeviceID}) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2257 | // 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] | 2258 | _ = dh.deviceReasonUpdate(ctx, cmn.DrOnuReenabled, true) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2259 | |
| 2260 | //transfer the modified logical uni port state |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2261 | dh.EnableUniPortStateUpdate(ctx) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2262 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2263 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2264 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2265 | 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] | 2266 | return |
| 2267 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2268 | pDevEntry.MutexPersOnuConfig.Lock() |
| 2269 | pDevEntry.SOnuPersistentData.PersUniDisableDone = false |
| 2270 | pDevEntry.MutexPersOnuConfig.Unlock() |
| 2271 | if err := dh.StorePersistentData(ctx); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2272 | 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] | 2273 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 2274 | } |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2275 | } |
| 2276 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2277 | func (dh *deviceHandler) processOmciAniConfigDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
| 2278 | if devEvent == cmn.OmciAniConfigDone { |
| 2279 | logger.Debugw(ctx, "OmciAniConfigDone event received", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2280 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 2281 | // - which may cause some inconsistency |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2282 | if dh.getDeviceReason() != cmn.DrTechProfileConfigDownloadSuccess { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2283 | // 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] | 2284 | _ = dh.deviceReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, !dh.IsReconciling()) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2285 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2286 | if dh.IsReconciling() { |
| 2287 | go dh.ReconcileDeviceFlowConfig(ctx) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2288 | } |
| 2289 | } else { // should be the OmciAniResourceRemoved block |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2290 | logger.Debugw(ctx, "OmciAniResourceRemoved event received", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2291 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 2292 | // - which may cause some inconsistency |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2293 | if dh.getDeviceReason() != cmn.DrTechProfileConfigDeleteSuccess { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2294 | // 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] | 2295 | _ = dh.deviceReasonUpdate(ctx, cmn.DrTechProfileConfigDeleteSuccess, true) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2296 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2297 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2298 | } |
| 2299 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2300 | func (dh *deviceHandler) processOmciVlanFilterDoneEvent(ctx context.Context, aDevEvent cmn.OnuDeviceEvent) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2301 | logger.Debugw(ctx, "OmciVlanFilterDone event received", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2302 | log.Fields{"device-id": dh.DeviceID, "event": aDevEvent}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2303 | // attention: the device reason update is done based on ONU-UNI-Port related activity |
| 2304 | // - which may cause some inconsistency |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2305 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2306 | if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterAddDoneNoKvStore { |
| 2307 | if dh.getDeviceReason() != cmn.DrOmciFlowsPushed { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2308 | // which may be the case from some previous actvity on another UNI Port of the ONU |
| 2309 | // or even some previous flow add activity on the same port |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2310 | _ = dh.deviceReasonUpdate(ctx, cmn.DrOmciFlowsPushed, !dh.IsReconciling()) |
| 2311 | if dh.IsReconciling() { |
Holger Hildebrandt | 1b8f4ad | 2021-03-25 15:53:51 +0000 | [diff] [blame] | 2312 | go dh.reconcileEnd(ctx) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2313 | } |
| 2314 | } |
| 2315 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2316 | if dh.getDeviceReason() != cmn.DrOmciFlowsDeleted { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2317 | //not relevant for reconcile |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2318 | _ = dh.deviceReasonUpdate(ctx, cmn.DrOmciFlowsDeleted, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 2319 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2320 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2321 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2322 | if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterRemDone { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2323 | //events that request KvStore write |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2324 | if err := dh.StorePersistentData(ctx); err != nil { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2325 | 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] | 2326 | log.Fields{"device-id": dh.DeviceID, "err": err}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 2327 | } |
| 2328 | } else { |
| 2329 | logger.Debugw(ctx, "OmciVlanFilter*Done* - write to KvStore not requested", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2330 | log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 2331 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2332 | } |
| 2333 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2334 | //DeviceProcStatusUpdate evaluates possible processing events and initiates according next activities |
| 2335 | func (dh *deviceHandler) DeviceProcStatusUpdate(ctx context.Context, devEvent cmn.OnuDeviceEvent) { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2336 | switch devEvent { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2337 | case cmn.MibDatabaseSync: |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2338 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2339 | dh.processMibDatabaseSyncEvent(ctx, devEvent) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2340 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2341 | case cmn.UniLockStateDone: |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2342 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2343 | dh.processUniLockStateDoneEvent(ctx, devEvent) |
mpagenko | a40e99a | 2020-11-17 13:50:39 +0000 | [diff] [blame] | 2344 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2345 | case cmn.MibDownloadDone: |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2346 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2347 | dh.processMibDownloadDoneEvent(ctx, devEvent) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2348 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2349 | case cmn.UniUnlockStateDone: |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2350 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2351 | dh.processUniUnlockStateDoneEvent(ctx, devEvent) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2352 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2353 | case cmn.UniEnableStateDone: |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2354 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2355 | dh.processUniEnableStateDoneEvent(ctx, devEvent) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2356 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2357 | case cmn.UniDisableStateDone: |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2358 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2359 | dh.processUniDisableStateDoneEvent(ctx, devEvent) |
mpagenko | 900ee4b | 2020-10-12 11:56:34 +0000 | [diff] [blame] | 2360 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2361 | case cmn.OmciAniConfigDone, cmn.OmciAniResourceRemoved: |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 2362 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2363 | dh.processOmciAniConfigDoneEvent(ctx, devEvent) |
mpagenko | 3dbcdd2 | 2020-07-22 07:38:45 +0000 | [diff] [blame] | 2364 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2365 | case cmn.OmciVlanFilterAddDone, cmn.OmciVlanFilterAddDoneNoKvStore, cmn.OmciVlanFilterRemDone, cmn.OmciVlanFilterRemDoneNoKvStore: |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2366 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2367 | dh.processOmciVlanFilterDoneEvent(ctx, devEvent) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2368 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2369 | default: |
| 2370 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2371 | 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] | 2372 | } |
| 2373 | } //switch |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2376 | 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] | 2377 | // parameters are IntfId, OnuId, uniId |
Mahir Gunyel | cb128ae | 2021-10-06 09:42:05 -0700 | [diff] [blame] | 2378 | uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2379 | uint32(aUniID)) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2380 | if _, present := dh.uniEntityMap[uniNo]; present { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2381 | 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] | 2382 | } else { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2383 | //with arguments aUniID, a_portNo, aPortType |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2384 | pUniPort := cmn.NewOnuUniPort(ctx, aUniID, uniNo, aUniInstNo, aPortType) |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2385 | if pUniPort == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2386 | 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] | 2387 | } else { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2388 | //store UniPort with the System-PortNumber key |
| 2389 | dh.uniEntityMap[uniNo] = pUniPort |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2390 | if !dh.IsReconciling() { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2391 | // create announce the UniPort to the core as VOLTHA Port object |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2392 | if err := pUniPort.CreateVolthaPort(ctx, dh); err == nil { |
| 2393 | logger.Infow(ctx, "OnuUniPort-added", log.Fields{"for PortNo": uniNo}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2394 | } //error logging already within UniPort method |
| 2395 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2396 | 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] | 2397 | } |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 2398 | } |
| 2399 | } |
| 2400 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2401 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2402 | func (dh *deviceHandler) AddAllUniPorts(ctx context.Context) { |
| 2403 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2404 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2405 | 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] | 2406 | return |
| 2407 | } |
| 2408 | i := 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] | 2409 | if pptpInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2410 | ctx, me.PhysicalPathTerminationPointEthernetUniClassID); len(pptpInstKeys) > 0 { |
| 2411 | for _, mgmtEntityID := range pptpInstKeys { |
| 2412 | logger.Debugw(ctx, "Add PPTPEthUni port for MIB-stored instance:", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2413 | "device-id": dh.DeviceID, "PPTPEthUni EntityID": mgmtEntityID}) |
| 2414 | dh.addUniPort(ctx, mgmtEntityID, i, cmn.UniPPTP) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2415 | i++ |
| 2416 | } |
| 2417 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2418 | 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] | 2419 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2420 | if veipInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2421 | ctx, me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 { |
| 2422 | for _, mgmtEntityID := range veipInstKeys { |
| 2423 | logger.Debugw(ctx, "Add VEIP for MIB-stored instance:", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2424 | "device-id": dh.DeviceID, "VEIP EntityID": mgmtEntityID}) |
| 2425 | dh.addUniPort(ctx, mgmtEntityID, i, cmn.UniVEIP) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2426 | i++ |
| 2427 | } |
| 2428 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2429 | 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] | 2430 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2431 | if potsInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys( |
ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 2432 | ctx, me.PhysicalPathTerminationPointPotsUniClassID); len(potsInstKeys) > 0 { |
| 2433 | for _, mgmtEntityID := range potsInstKeys { |
| 2434 | 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] | 2435 | "device-id": dh.DeviceID, "PPTP Pots UNI EntityID": mgmtEntityID}) |
| 2436 | dh.addUniPort(ctx, mgmtEntityID, i, cmn.UniPPTPPots) |
ozgecanetsia | 124d973 | 2021-09-16 14:31:57 +0300 | [diff] [blame] | 2437 | i++ |
| 2438 | } |
| 2439 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2440 | 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] | 2441 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2442 | if i == 0 { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2443 | logger.Warnw(ctx, "No UniG instances found", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2444 | } |
| 2445 | } |
| 2446 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2447 | // EnableUniPortStateUpdate enables UniPortState and update core port state accordingly |
| 2448 | func (dh *deviceHandler) EnableUniPortStateUpdate(ctx context.Context) { |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 2449 | // 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] | 2450 | // but towards core only the first port active state is signaled |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 2451 | // with following remark: |
| 2452 | // # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow |
| 2453 | // # load on the core |
| 2454 | |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2455 | // 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] | 2456 | |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2457 | for uniNo, uniPort := range dh.uniEntityMap { |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2458 | // only if this port is validated for operState transfer |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2459 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 2460 | logger.Infow(ctx, "OnuUniPort-forced-OperState-ACTIVE", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID}) |
| 2461 | uniPort.SetOperState(vc.OperStatus_ACTIVE) |
| 2462 | if !dh.IsReconciling() { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2463 | //maybe also use getter functions on uniPort - perhaps later ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2464 | go func(port *cmn.OnuUniPort) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2465 | if err := dh.updatePortStateInCore(ctx, &ic.PortState{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2466 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2467 | PortType: voltha.Port_ETHERNET_UNI, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2468 | PortNo: port.PortNo, |
| 2469 | OperStatus: port.OperState, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2470 | }); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2471 | 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] | 2472 | } |
| 2473 | }(uniPort) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 2474 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2475 | 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] | 2476 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2477 | } |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | // Disable UniPortState and update core port state accordingly |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2482 | func (dh *deviceHandler) DisableUniPortStateUpdate(ctx context.Context) { |
| 2483 | // compare EnableUniPortStateUpdate() above |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2484 | // -> use current restriction to operate only on first UNI port as inherited from actual Py code |
| 2485 | for uniNo, uniPort := range dh.uniEntityMap { |
| 2486 | // only if this port is validated for operState transfer |
Matteo Scandolo | 20d180c | 2021-06-10 17:20:21 +0200 | [diff] [blame] | 2487 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2488 | if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) { |
| 2489 | logger.Infow(ctx, "OnuUniPort-forced-OperState-UNKNOWN", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID}) |
| 2490 | uniPort.SetOperState(vc.OperStatus_UNKNOWN) |
| 2491 | if !dh.IsReconciling() { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2492 | //maybe also use getter functions on uniPort - perhaps later ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2493 | go func(port *cmn.OnuUniPort) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2494 | if err := dh.updatePortStateInCore(ctx, &ic.PortState{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2495 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2496 | PortType: voltha.Port_ETHERNET_UNI, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2497 | PortNo: port.PortNo, |
| 2498 | OperStatus: port.OperState, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2499 | }); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2500 | 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] | 2501 | } |
| 2502 | }(uniPort) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 2503 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2504 | 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] | 2505 | } |
| 2506 | |
Holger Hildebrandt | be67442 | 2020-05-05 13:05:30 +0000 | [diff] [blame] | 2507 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2508 | } |
| 2509 | } |
| 2510 | |
| 2511 | // ONU_Active/Inactive announcement on system KAFKA bus |
| 2512 | // 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] | 2513 | 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] | 2514 | var de voltha.DeviceEvent |
| 2515 | eventContext := make(map[string]string) |
| 2516 | //Populating event context |
| 2517 | // 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] | 2518 | parentDevice, err := dh.getDeviceFromCore(ctx, dh.parentID) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2519 | if err != nil || parentDevice == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2520 | logger.Errorw(ctx, "Failed to fetch parent device for OnuEvent", |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2521 | log.Fields{"parentID": dh.parentID, "err": err}) |
Holger Hildebrandt | 7ec14c4 | 2021-05-28 14:21:58 +0000 | [diff] [blame] | 2522 | 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] | 2523 | } |
| 2524 | oltSerialNumber := parentDevice.SerialNumber |
| 2525 | |
| 2526 | eventContext["pon-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.IntfId), 10) |
| 2527 | eventContext["onu-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.OnuId), 10) |
| 2528 | eventContext["serial-number"] = dh.device.SerialNumber |
ssiddiqui | 1221d1a | 2021-02-15 11:12:51 +0530 | [diff] [blame] | 2529 | eventContext["olt-serial-number"] = oltSerialNumber |
| 2530 | eventContext["device-id"] = aDeviceID |
| 2531 | eventContext["registration-id"] = aDeviceID //py: string(device_id)?? |
ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 2532 | eventContext["num-of-unis"] = strconv.Itoa(len(dh.uniEntityMap)) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2533 | if deviceEntry := dh.GetOnuDeviceEntry(ctx, false); deviceEntry != nil { |
| 2534 | deviceEntry.MutexPersOnuConfig.RLock() |
| 2535 | eventContext["equipment-id"] = deviceEntry.SOnuPersistentData.PersEquipmentID |
| 2536 | deviceEntry.MutexPersOnuConfig.RUnlock() |
| 2537 | eventContext["software-version"] = deviceEntry.GetActiveImageVersion(ctx) |
| 2538 | deviceEntry.MutexPersOnuConfig.RLock() |
| 2539 | eventContext["vendor"] = deviceEntry.SOnuPersistentData.PersVendorID |
| 2540 | deviceEntry.MutexPersOnuConfig.RUnlock() |
| 2541 | eventContext["inactive-software-version"] = deviceEntry.GetInactiveImageVersion(ctx) |
ozgecanetsia | f0a76b6 | 2021-05-31 17:42:09 +0300 | [diff] [blame] | 2542 | logger.Debugw(ctx, "prepare ONU_ACTIVATED event", |
| 2543 | log.Fields{"device-id": aDeviceID, "EventContext": eventContext}) |
| 2544 | } else { |
| 2545 | logger.Errorw(ctx, "Failed to fetch device-entry. ONU_ACTIVATED event is not sent", |
| 2546 | log.Fields{"device-id": aDeviceID}) |
| 2547 | return |
| 2548 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2549 | |
| 2550 | /* Populating device event body */ |
| 2551 | de.Context = eventContext |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2552 | de.ResourceId = aDeviceID |
| 2553 | if aOperState == voltha.OperStatus_ACTIVE { |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2554 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "RAISE_EVENT") |
| 2555 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 2556 | cEventObjectType, cOnuActivatedEvent, "Raised") |
| 2557 | } else { |
| 2558 | de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "CLEAR_EVENT") |
| 2559 | de.Description = fmt.Sprintf("%s Event - %s - %s", |
| 2560 | cEventObjectType, cOnuActivatedEvent, "Cleared") |
| 2561 | } |
| 2562 | /* Send event to KAFKA */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2563 | if err := dh.EventProxy.SendDeviceEvent(ctx, &de, equipment, pon, raisedTs); err != nil { |
| 2564 | logger.Warnw(ctx, "could not send ONU_ACTIVATED event", |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2565 | log.Fields{"device-id": aDeviceID, "error": err}) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2566 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2567 | logger.Debugw(ctx, "ctx, ONU_ACTIVATED event sent to KAFKA", |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2568 | log.Fields{"device-id": aDeviceID, "with-EventName": de.DeviceEventName}) |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2569 | } |
| 2570 | |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2571 | // 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] | 2572 | func (dh *deviceHandler) createUniLockFsm(ctx context.Context, aAdminState bool, devEvent cmn.OnuDeviceEvent) { |
| 2573 | chLSFsm := make(chan cmn.Message, 2048) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2574 | var sFsmName string |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2575 | if aAdminState { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2576 | logger.Debugw(ctx, "createLockStateFSM", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2577 | sFsmName = "LockStateFSM" |
| 2578 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2579 | logger.Debugw(ctx, "createUnlockStateFSM", log.Fields{"device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2580 | sFsmName = "UnLockStateFSM" |
| 2581 | } |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2582 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2583 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2584 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2585 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 2586 | return |
| 2587 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2588 | pLSFsm := uniprt.NewLockStateFsm(ctx, aAdminState, devEvent, sFsmName, dh, pDevEntry, chLSFsm) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2589 | if pLSFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2590 | if aAdminState { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2591 | dh.pLockStateFsm = pLSFsm |
| 2592 | } else { |
| 2593 | dh.pUnlockStateFsm = pLSFsm |
| 2594 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2595 | dh.runUniLockFsm(ctx, aAdminState) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2596 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2597 | 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] | 2598 | } |
| 2599 | } |
| 2600 | |
| 2601 | // 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] | 2602 | func (dh *deviceHandler) runUniLockFsm(ctx context.Context, aAdminState bool) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2603 | /* Uni Port lock/unlock procedure - |
| 2604 | ***** should run via 'adminDone' state and generate the argument requested event ***** |
| 2605 | */ |
| 2606 | var pLSStatemachine *fsm.FSM |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2607 | if aAdminState { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2608 | pLSStatemachine = dh.pLockStateFsm.PAdaptFsm.PFsm |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2609 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 2610 | if (dh.pUnlockStateFsm != nil) && |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2611 | (dh.pUnlockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) { |
| 2612 | _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2613 | } |
| 2614 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2615 | pLSStatemachine = dh.pUnlockStateFsm.PAdaptFsm.PFsm |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2616 | //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore |
| 2617 | if (dh.pLockStateFsm != nil) && |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2618 | (dh.pLockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) { |
| 2619 | _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2620 | } |
| 2621 | } |
| 2622 | if pLSStatemachine != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2623 | if pLSStatemachine.Is(uniprt.UniStDisabled) { |
| 2624 | if err := pLSStatemachine.Event(uniprt.UniEvStart); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2625 | logger.Warnw(ctx, "LockStateFSM: can't start", log.Fields{"err": err}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2626 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2627 | } else { |
| 2628 | /***** LockStateFSM started */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2629 | logger.Debugw(ctx, "LockStateFSM started", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2630 | "state": pLSStatemachine.Current(), "device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2631 | } |
| 2632 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2633 | logger.Warnw(ctx, "wrong state of LockStateFSM - want: disabled", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2634 | "have": pLSStatemachine.Current(), "device-id": dh.DeviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 2635 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2636 | } |
| 2637 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2638 | 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] | 2639 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2640 | } |
| 2641 | } |
| 2642 | |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2643 | // createOnuUpgradeFsm initializes and runs the Onu Software upgrade FSM |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 2644 | // precondition: lockUpgradeFsm is already locked from caller of this function |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2645 | 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] | 2646 | chUpgradeFsm := make(chan cmn.Message, 2048) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2647 | var sFsmName = "OnuSwUpgradeFSM" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2648 | logger.Debugw(ctx, "create OnuSwUpgradeFSM", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2649 | if apDevEntry.PDevOmciCC == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2650 | 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] | 2651 | 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] | 2652 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2653 | dh.pOnuUpradeFsm = swupg.NewOnuUpgradeFsm(ctx, dh, apDevEntry, apDevEntry.GetOnuDB(), aDevEvent, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2654 | sFsmName, chUpgradeFsm) |
| 2655 | if dh.pOnuUpradeFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2656 | pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2657 | if pUpgradeStatemachine != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2658 | if pUpgradeStatemachine.Is(swupg.UpgradeStDisabled) { |
| 2659 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvStart); err != nil { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2660 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't start", log.Fields{"err": err}) |
| 2661 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2662 | return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be started for device-id: %s", dh.device.Id)) |
| 2663 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 2664 | /***** Upgrade FSM started */ |
mpagenko | 4558676 | 2021-10-01 08:30:22 +0000 | [diff] [blame] | 2665 | //reset the last stored upgrade states (which anyway should be don't care as long as the newly created FSM exists) |
| 2666 | (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2667 | (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR |
| 2668 | (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2669 | logger.Debugw(ctx, "OnuSwUpgradeFSM started", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2670 | "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2671 | } else { |
| 2672 | 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] | 2673 | "have": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2674 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2675 | return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be started for device-id: %s, wrong internal state", dh.device.Id)) |
| 2676 | } |
| 2677 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2678 | 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] | 2679 | // maybe try a FSM reset and then again ... - TODO!!! |
| 2680 | return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM internal FSM could not be created for device-id: %s", dh.device.Id)) |
| 2681 | } |
| 2682 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2683 | 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] | 2684 | return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be created - abort for device-id: %s", dh.device.Id)) |
| 2685 | } |
| 2686 | return nil |
| 2687 | } |
| 2688 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2689 | // RemoveOnuUpgradeFsm clears the Onu Software upgrade FSM |
| 2690 | func (dh *deviceHandler) RemoveOnuUpgradeFsm(ctx context.Context, apImageState *voltha.ImageState) { |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2691 | logger.Debugw(ctx, "remove OnuSwUpgradeFSM StateMachine", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2692 | "device-id": dh.DeviceID}) |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2693 | dh.lockUpgradeFsm.Lock() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 2694 | dh.pOnuUpradeFsm = nil //resource clearing is left to garbage collector |
| 2695 | dh.upgradeCanceled = false //cancelation done |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2696 | dh.pLastUpgradeImageState = apImageState |
| 2697 | dh.lockUpgradeFsm.Unlock() |
| 2698 | //signal upgradeFsm removed using non-blocking channel send |
| 2699 | select { |
| 2700 | case dh.upgradeFsmChan <- struct{}{}: |
| 2701 | default: |
| 2702 | 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] | 2703 | "device-id": dh.DeviceID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2704 | } |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 2705 | } |
| 2706 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2707 | // checkOnOnuImageCommit verifies if the ONU is in some upgrade state that allows for image commit and if tries to commit |
| 2708 | func (dh *deviceHandler) checkOnOnuImageCommit(ctx context.Context) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2709 | pDevEntry := dh.GetOnuDeviceEntry(ctx, false) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2710 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2711 | 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] | 2712 | return |
| 2713 | } |
| 2714 | |
| 2715 | dh.lockUpgradeFsm.RLock() |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 2716 | //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2717 | if dh.pOnuUpradeFsm != nil { |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 2718 | if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation |
| 2719 | dh.lockUpgradeFsm.RUnlock() |
| 2720 | logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID}) |
| 2721 | return |
| 2722 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2723 | pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2724 | if pUpgradeStatemachine != nil { |
| 2725 | // commit is only processed in case out upgrade FSM indicates the according state (for automatic commit) |
| 2726 | // (some manual forced commit could do without) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2727 | UpgradeState := pUpgradeStatemachine.Current() |
| 2728 | if (UpgradeState == swupg.UpgradeStWaitForCommit) || |
| 2729 | (UpgradeState == swupg.UpgradeStRequestingActivate) { |
| 2730 | // 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] | 2731 | // 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] | 2732 | if pDevEntry.IsImageToBeCommitted(ctx, dh.pOnuUpradeFsm.InactiveImageMeID) { |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2733 | activeImageID, errImg := pDevEntry.GetActiveImageMeID(ctx) |
| 2734 | if errImg != nil { |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 2735 | dh.lockUpgradeFsm.RUnlock() |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2736 | logger.Errorw(ctx, "OnuSwUpgradeFSM abort - could not get active image after reboot", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2737 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 2738 | if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation |
| 2739 | dh.upgradeCanceled = true |
| 2740 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 2741 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2742 | return |
| 2743 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 2744 | dh.lockUpgradeFsm.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2745 | if activeImageID == dh.pOnuUpradeFsm.InactiveImageMeID { |
| 2746 | if (UpgradeState == swupg.UpgradeStRequestingActivate) && !dh.pOnuUpradeFsm.GetCommitFlag(ctx) { |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2747 | // 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] | 2748 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvActivationDone); err != nil { |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2749 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call activate-done event", log.Fields{"err": err}) |
| 2750 | return |
| 2751 | } |
| 2752 | logger.Debugw(ctx, "OnuSwUpgradeFSM activate-done after reboot", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2753 | "state": UpgradeState, "device-id": dh.DeviceID}) |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2754 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2755 | //FSM in waitForCommit or (UpgradeStRequestingActivate [lost ActivateResp] and commit allowed) |
| 2756 | if err := pUpgradeStatemachine.Event(swupg.UpgradeEvCommitSw); err != nil { |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2757 | logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call commit event", log.Fields{"err": err}) |
| 2758 | return |
| 2759 | } |
| 2760 | logger.Debugw(ctx, "OnuSwUpgradeFSM commit image requested", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2761 | "state": UpgradeState, "device-id": dh.DeviceID}) |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2762 | } |
| 2763 | } else { |
| 2764 | 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] | 2765 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 2766 | dh.upgradeCanceled = true |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 2767 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
mpagenko | 1f8e882 | 2021-06-25 14:10:21 +0000 | [diff] [blame] | 2768 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2769 | return |
| 2770 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 2771 | dh.lockUpgradeFsm.RUnlock() |
| 2772 | logger.Errorw(ctx, "OnuSwUpgradeFSM waiting to commit, but nothing to commit on ONU - abort upgrade", |
| 2773 | log.Fields{"device-id": dh.DeviceID}) |
| 2774 | dh.upgradeCanceled = true |
| 2775 | dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort |
| 2776 | return |
| 2777 | } |
| 2778 | //upgrade FSM is active but not waiting for commit: maybe because commit flag is not set |
| 2779 | // upgrade FSM is to be informed if the current active image is the one that was used in upgrade for the download |
| 2780 | if activeImageID, err := pDevEntry.GetActiveImageMeID(ctx); err == nil { |
| 2781 | if dh.pOnuUpradeFsm.InactiveImageMeID == activeImageID { |
| 2782 | logger.Debugw(ctx, "OnuSwUpgradeFSM image state set to activated", log.Fields{ |
| 2783 | "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID}) |
| 2784 | dh.pOnuUpradeFsm.SetImageStateActive(ctx) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 2785 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2786 | } |
| 2787 | } |
| 2788 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2789 | 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] | 2790 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame^] | 2791 | dh.lockUpgradeFsm.RUnlock() |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 2792 | } |
| 2793 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2794 | //SetBackend provides a DB backend for the specified path on the existing KV client |
| 2795 | func (dh *deviceHandler) SetBackend(ctx context.Context, aBasePathKvStore string) *db.Backend { |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 2796 | |
| 2797 | logger.Debugw(ctx, "SetKVStoreBackend", log.Fields{"IpTarget": dh.pOpenOnuAc.KVStoreAddress, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2798 | "BasePathKvStore": aBasePathKvStore, "device-id": dh.DeviceID}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 2799 | // 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] | 2800 | kvbackend := &db.Backend{ |
| 2801 | Client: dh.pOpenOnuAc.kvClient, |
| 2802 | StoreType: dh.pOpenOnuAc.KVStoreType, |
| 2803 | /* address config update acc. to [VOL-2736] */ |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 2804 | Address: dh.pOpenOnuAc.KVStoreAddress, |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 2805 | Timeout: dh.pOpenOnuAc.KVStoreTimeout, |
| 2806 | PathPrefix: aBasePathKvStore} |
Holger Hildebrandt | c54939a | 2020-06-17 08:14:27 +0000 | [diff] [blame] | 2807 | |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 2808 | return kvbackend |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 2809 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2810 | func (dh *deviceHandler) getFlowOfbFields(ctx context.Context, apFlowItem *of.OfpFlowStats, loMatchVlan *uint16, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2811 | loAddPcp *uint8, loIPProto *uint32) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2812 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2813 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 2814 | switch field.Type { |
| 2815 | case of.OxmOfbFieldTypes_OFPXMT_OFB_ETH_TYPE: |
| 2816 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2817 | logger.Debugw(ctx, "flow type EthType", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2818 | "EthType": strconv.FormatInt(int64(field.GetEthType()), 16)}) |
| 2819 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2820 | /* TT related temporary workaround - should not be needed anymore |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2821 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO: |
| 2822 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2823 | *loIPProto = field.GetIpProto() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2824 | logger.Debugw("flow type IpProto", log.Fields{"device-id": dh.DeviceID, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2825 | "IpProto": strconv.FormatInt(int64(*loIPProto), 16)}) |
| 2826 | if *loIPProto == 2 { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2827 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 2828 | // avoids installing invalid EVTOCD rule |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2829 | logger.Debugw("flow type IpProto 2: TT workaround: ignore flow", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2830 | log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2831 | return |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2832 | } |
| 2833 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2834 | */ |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2835 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID: |
| 2836 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2837 | *loMatchVlan = uint16(field.GetVlanVid()) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2838 | loMatchVlanMask := uint16(field.GetVlanVidMask()) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2839 | if !(*loMatchVlan == uint16(of.OfpVlanId_OFPVID_PRESENT) && |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2840 | loMatchVlanMask == uint16(of.OfpVlanId_OFPVID_PRESENT)) { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2841 | *loMatchVlan = *loMatchVlan & 0xFFF // not transparent: copy only ID bits |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2842 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2843 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2844 | "VID": strconv.FormatInt(int64(*loMatchVlan), 16)}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2845 | } |
| 2846 | case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP: |
| 2847 | { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2848 | *loAddPcp = uint8(field.GetVlanPcp()) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2849 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2850 | "PCP": loAddPcp}) |
| 2851 | } |
| 2852 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_DST: |
| 2853 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2854 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2855 | "UDP-DST": strconv.FormatInt(int64(field.GetUdpDst()), 16)}) |
| 2856 | } |
| 2857 | case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_SRC: |
| 2858 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2859 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2860 | "UDP-SRC": strconv.FormatInt(int64(field.GetUdpSrc()), 16)}) |
| 2861 | } |
| 2862 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_DST: |
| 2863 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2864 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2865 | "IPv4-DST": field.GetIpv4Dst()}) |
| 2866 | } |
| 2867 | case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_SRC: |
| 2868 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2869 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2870 | "IPv4-SRC": field.GetIpv4Src()}) |
| 2871 | } |
| 2872 | case of.OxmOfbFieldTypes_OFPXMT_OFB_METADATA: |
| 2873 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2874 | logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2875 | "Metadata": field.GetTableMetadata()}) |
| 2876 | } |
| 2877 | /* |
| 2878 | default: |
| 2879 | { |
| 2880 | //all other entires ignored |
| 2881 | } |
| 2882 | */ |
| 2883 | } |
| 2884 | } //for all OfbFields |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2885 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2886 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 2887 | 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] | 2888 | for _, action := range flow.GetActions(apFlowItem) { |
| 2889 | switch action.Type { |
| 2890 | /* not used: |
| 2891 | case of.OfpActionType_OFPAT_OUTPUT: |
| 2892 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2893 | logger.Debugw("flow action type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2894 | "Output": action.GetOutput()}) |
| 2895 | } |
| 2896 | */ |
| 2897 | case of.OfpActionType_OFPAT_PUSH_VLAN: |
| 2898 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2899 | logger.Debugw(ctx, "flow action type", log.Fields{"device-id": dh.DeviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2900 | "PushEthType": strconv.FormatInt(int64(action.GetPush().Ethertype), 16)}) |
| 2901 | } |
| 2902 | case of.OfpActionType_OFPAT_SET_FIELD: |
| 2903 | { |
| 2904 | pActionSetField := action.GetSetField() |
| 2905 | if pActionSetField.Field.OxmClass != of.OfpOxmClass_OFPXMC_OPENFLOW_BASIC { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2906 | 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] | 2907 | "OxcmClass": pActionSetField.Field.OxmClass}) |
| 2908 | } |
| 2909 | if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2910 | *loSetVlan = uint16(pActionSetField.Field.GetOfbField().GetVlanVid()) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2911 | 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] | 2912 | "SetVlan": strconv.FormatInt(int64(*loSetVlan), 16)}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2913 | } else if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2914 | *loSetPcp = uint8(pActionSetField.Field.GetOfbField().GetVlanPcp()) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2915 | 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] | 2916 | "SetPcp": *loSetPcp}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2917 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2918 | 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] | 2919 | "Type": pActionSetField.Field.GetOfbField().Type}) |
| 2920 | } |
| 2921 | } |
| 2922 | /* |
| 2923 | default: |
| 2924 | { |
| 2925 | //all other entires ignored |
| 2926 | } |
| 2927 | */ |
| 2928 | } |
| 2929 | } //for all Actions |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | //addFlowItemToUniPort parses the actual flow item to add it to the UniPort |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2933 | func (dh *deviceHandler) addFlowItemToUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort, |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 2934 | apFlowMetaData *voltha.FlowMetadata) error { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2935 | var loSetVlan uint16 = uint16(of.OfpVlanId_OFPVID_NONE) //noValidEntry |
| 2936 | var loMatchVlan uint16 = uint16(of.OfpVlanId_OFPVID_PRESENT) //reserved VLANID entry |
| 2937 | var loAddPcp, loSetPcp uint8 |
| 2938 | var loIPProto uint32 |
| 2939 | /* the TechProfileId is part of the flow Metadata - compare also comment within |
| 2940 | * OLT-Adapter:openolt_flowmgr.go |
| 2941 | * Metadata 8 bytes: |
| 2942 | * Most Significant 2 Bytes = Inner VLAN |
| 2943 | * Next 2 Bytes = Tech Profile ID(TPID) |
| 2944 | * Least Significant 4 Bytes = Port ID |
| 2945 | * Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all |
| 2946 | * subscriber related flows. |
| 2947 | */ |
| 2948 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2949 | metadata := flow.GetMetadataFromWriteMetadataAction(ctx, apFlowItem) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2950 | if metadata == 0 { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2951 | logger.Debugw(ctx, "flow-add invalid metadata - abort", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2952 | log.Fields{"device-id": dh.DeviceID}) |
| 2953 | return fmt.Errorf("flow-add invalid metadata: %s", dh.DeviceID) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2954 | } |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 2955 | loTpID := uint8(flow.GetTechProfileIDFromWriteMetaData(ctx, metadata)) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2956 | loCookie := apFlowItem.GetCookie() |
| 2957 | loCookieSlice := []uint64{loCookie} |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2958 | logger.Debugw(ctx, "flow-add base indications", log.Fields{"device-id": dh.DeviceID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2959 | "TechProf-Id": loTpID, "cookie": loCookie}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2960 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2961 | dh.getFlowOfbFields(ctx, apFlowItem, &loMatchVlan, &loAddPcp, &loIPProto) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2962 | /* TT related temporary workaround - should not be needed anymore |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2963 | if loIPProto == 2 { |
| 2964 | // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow |
| 2965 | // avoids installing invalid EVTOCD rule |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2966 | logger.Debugw("flow-add type IpProto 2: TT workaround: ignore flow", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2967 | log.Fields{"device-id": dh.DeviceID}) |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2968 | return nil |
| 2969 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2970 | */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2971 | dh.getFlowActions(ctx, apFlowItem, &loSetPcp, &loSetVlan) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2972 | |
| 2973 | if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2974 | 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] | 2975 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2976 | "set_vid": strconv.FormatInt(int64(loSetVlan), 16), |
| 2977 | "match_vid": strconv.FormatInt(int64(loMatchVlan), 16)}) |
| 2978 | //TODO!!: Use DeviceId within the error response to rwCore |
| 2979 | // likewise also in other error response cases to calling components as requested in [VOL-3458] |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2980 | return fmt.Errorf("flow-add Set/Match VlanId inconsistent: %s", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2981 | } |
| 2982 | 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] | 2983 | 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] | 2984 | loSetVlan = loMatchVlan //both 'transparent' (copy any) |
| 2985 | } else { |
| 2986 | //looks like OMCI value 4097 (copyFromOuter - for Uni double tagged) is not supported here |
| 2987 | if loSetVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) { |
| 2988 | // not set to transparent |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2989 | loSetVlan &= 0x0FFF //mask VID bits as prerequisite for vlanConfigFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2990 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2991 | logger.Debugw(ctx, "flow-add vlan-set", log.Fields{"device-id": dh.DeviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2992 | } |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 2993 | |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 2994 | var meter *voltha.OfpMeterConfig |
| 2995 | if apFlowMetaData != nil { |
| 2996 | meter = apFlowMetaData.Meters[0] |
| 2997 | } |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 2998 | //mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities |
| 2999 | // must be set including the execution of createVlanFilterFsm() to avoid unintended creation of FSM's |
| 3000 | // when different rules are requested concurrently for the same uni |
| 3001 | // (also vlan persistency data does not support multiple FSM's on the same UNI correctly!) |
| 3002 | dh.lockVlanAdd.Lock() //prevent multiple add activities to start in parallel |
| 3003 | dh.lockVlanConfig.RLock() //read protection on UniVlanConfigFsmMap (removeFlowItemFromUniPort) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3004 | logger.Debugw(ctx, "flow-add got lock", log.Fields{"device-id": dh.DeviceID, "tpID": loTpID, "uniID": apUniPort.UniID}) |
| 3005 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3006 | //SetUniFlowParams() may block on some rule that is suspended-to-add |
| 3007 | // in order to allow for according flow removal lockVlanConfig may only be used with RLock here |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3008 | err := dh.UniVlanConfigFsmMap[apUniPort.UniID].SetUniFlowParams(ctx, loTpID, loCookieSlice, |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3009 | loMatchVlan, loSetVlan, loSetPcp, false, meter) |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3010 | dh.lockVlanConfig.RUnlock() |
| 3011 | dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3012 | return err |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3013 | } |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3014 | dh.lockVlanConfig.RUnlock() |
| 3015 | 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] | 3016 | err := dh.createVlanFilterFsm(ctx, apUniPort, loTpID, loCookieSlice, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3017 | loMatchVlan, loSetVlan, loSetPcp, cmn.OmciVlanFilterAddDone, false, meter) |
mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3018 | dh.lockVlanConfig.Unlock() |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 3019 | dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing |
mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3020 | return err |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3021 | } |
| 3022 | |
| 3023 | //removeFlowItemFromUniPort parses the actual flow item to remove it from the UniPort |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3024 | func (dh *deviceHandler) removeFlowItemFromUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort) error { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3025 | //optimization and assumption: the flow cookie uniquely identifies the flow and with that the internal rule |
| 3026 | //hence only the cookie is used here to find the relevant flow and possibly remove the rule |
| 3027 | //no extra check is done on the rule parameters |
| 3028 | //accordingly the removal is done only once - for the first found flow with that cookie, even though |
| 3029 | // at flow creation is not assured, that the same cookie is not configured for different flows - just assumed |
| 3030 | //additionally it is assumed here, that removal can only be done for one cookie per flow in a sequence (different |
| 3031 | // 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] | 3032 | // - 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] | 3033 | loCookie := apFlowItem.GetCookie() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3034 | 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] | 3035 | |
| 3036 | /* TT related temporary workaround - should not be needed anymore |
| 3037 | for _, field := range flow.GetOfbFields(apFlowItem) { |
| 3038 | if field.Type == of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO { |
| 3039 | loIPProto := field.GetIpProto() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3040 | logger.Debugw(ctx, "flow type IpProto", log.Fields{"device-id": dh.DeviceID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3041 | "IpProto": strconv.FormatInt(int64(loIPProto), 16)}) |
| 3042 | if loIPProto == 2 { |
| 3043 | // 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] | 3044 | logger.Debugw(ctx, "flow-remove type IpProto 2: TT workaround: ignore flow", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3045 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3046 | return nil |
| 3047 | } |
| 3048 | } |
| 3049 | } //for all OfbFields |
| 3050 | */ |
| 3051 | |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3052 | //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] | 3053 | dh.lockVlanConfig.RLock() |
| 3054 | defer dh.lockVlanConfig.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3055 | logger.Debugw(ctx, "flow-remove got RLock", log.Fields{"device-id": dh.DeviceID, "uniID": apUniPort.UniID}) |
| 3056 | if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
| 3057 | return dh.UniVlanConfigFsmMap[apUniPort.UniID].RemoveUniFlowParams(ctx, loCookie) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3058 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3059 | 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] | 3060 | log.Fields{"device-id": dh.DeviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3061 | //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] | 3062 | // and treat the reason accordingly (which in the normal removal procedure is initiated by the FSM) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3063 | go dh.DeviceProcStatusUpdate(ctx, cmn.OmciVlanFilterRemDone) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3064 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 3065 | return nil |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3066 | } |
| 3067 | |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3068 | // createVlanFilterFsm initializes and runs the VlanFilter FSM to transfer OMCI related VLAN config |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 3069 | // 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] | 3070 | // precondition: dh.lockVlanConfig is locked by the caller! |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3071 | func (dh *deviceHandler) createVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8, aCookieSlice []uint64, |
| 3072 | aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8, aDevEvent cmn.OnuDeviceEvent, lastFlowToReconcile bool, aMeter *voltha.OfpMeterConfig) error { |
| 3073 | chVlanFilterFsm := make(chan cmn.Message, 2048) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3074 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3075 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3076 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3077 | logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID}) |
| 3078 | return fmt.Errorf("no valid OnuDevice for device-id %x - aborting", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3079 | } |
| 3080 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3081 | pVlanFilterFsm := avcfg.NewUniVlanConfigFsm(ctx, dh, pDevEntry, pDevEntry.PDevOmciCC, apUniPort, dh.pOnuTP, |
| 3082 | pDevEntry.GetOnuDB(), aTpID, aDevEvent, "UniVlanConfigFsm", chVlanFilterFsm, |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3083 | dh.pOpenOnuAc.AcceptIncrementalEvto, aCookieSlice, aMatchVlan, aSetVlan, aSetPcp, lastFlowToReconcile, aMeter) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3084 | if pVlanFilterFsm != nil { |
mpagenko | 7d14de1 | 2021-07-27 08:31:56 +0000 | [diff] [blame] | 3085 | //dh.lockVlanConfig is locked (by caller) throughout the state transition to 'starting' |
| 3086 | // to prevent unintended (ignored) events to be sent there (from parallel processing) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3087 | dh.UniVlanConfigFsmMap[apUniPort.UniID] = pVlanFilterFsm |
| 3088 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3089 | if pVlanFilterStatemachine != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3090 | if pVlanFilterStatemachine.Is(avcfg.VlanStDisabled) { |
| 3091 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvStart); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3092 | logger.Warnw(ctx, "UniVlanConfigFsm: can't start", log.Fields{"err": err}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3093 | return fmt.Errorf("can't start UniVlanConfigFsm for device-id %x", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3094 | } |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 3095 | /***** UniVlanConfigFsm started */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3096 | logger.Debugw(ctx, "UniVlanConfigFsm started", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3097 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3098 | "UniPort": apUniPort.PortNo}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3099 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3100 | logger.Warnw(ctx, "wrong state of UniVlanConfigFsm - want: disabled", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3101 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID}) |
| 3102 | 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] | 3103 | } |
| 3104 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3105 | logger.Errorw(ctx, "UniVlanConfigFsm StateMachine invalid - cannot be executed!!", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3106 | "device-id": dh.DeviceID}) |
| 3107 | return fmt.Errorf("uniVlanConfigFsm invalid for device-id %x", dh.DeviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3108 | } |
| 3109 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3110 | logger.Errorw(ctx, "UniVlanConfigFsm could not be created - abort!!", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3111 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
| 3112 | 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] | 3113 | } |
| 3114 | return nil |
| 3115 | } |
| 3116 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3117 | //VerifyVlanConfigRequest checks on existence of a given uniPort |
| 3118 | // and starts verification of flow config based on that |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3119 | func (dh *deviceHandler) VerifyVlanConfigRequest(ctx context.Context, aUniID uint8, aTpID uint8) { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3120 | //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] | 3121 | var pCurrentUniPort *cmn.OnuUniPort |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3122 | for _, uniPort := range dh.uniEntityMap { |
| 3123 | // only if this port is validated for operState transfer |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3124 | if uniPort.UniID == uint8(aUniID) { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3125 | pCurrentUniPort = uniPort |
| 3126 | break //found - end search loop |
| 3127 | } |
| 3128 | } |
| 3129 | if pCurrentUniPort == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3130 | logger.Debugw(ctx, "VerifyVlanConfig aborted: requested uniID not found in PortDB", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3131 | log.Fields{"device-id": dh.DeviceID, "uni-id": aUniID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3132 | return |
| 3133 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3134 | dh.VerifyUniVlanConfigRequest(ctx, pCurrentUniPort, aTpID) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 3135 | } |
| 3136 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3137 | //VerifyUniVlanConfigRequest checks on existence of flow configuration and starts it accordingly |
| 3138 | func (dh *deviceHandler) VerifyUniVlanConfigRequest(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3139 | //TODO!! verify and start pending flow configuration |
| 3140 | //some pending config request my exist in case the UniVlanConfig FSM was already started - with internal data - |
| 3141 | //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] | 3142 | |
| 3143 | dh.lockVlanConfig.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3144 | if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3145 | dh.lockVlanConfig.RUnlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3146 | //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] | 3147 | pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3148 | if pVlanFilterStatemachine != nil { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3149 | //if this was an event of the TP processing that was waited for in the VlanFilterFsm |
| 3150 | if pVlanFilterFsm.GetWaitingTpID() == aTpID { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3151 | if pVlanFilterStatemachine.Is(avcfg.VlanStWaitingTechProf) { |
| 3152 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvContinueConfig); err != nil { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3153 | logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3154 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3155 | } else { |
| 3156 | /***** UniVlanConfigFsm continued */ |
| 3157 | logger.Debugw(ctx, "UniVlanConfigFsm continued", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3158 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3159 | "UniPort": apUniPort.PortNo}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3160 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3161 | } else if pVlanFilterStatemachine.Is(avcfg.VlanStIncrFlowWaitTP) { |
| 3162 | if err := pVlanFilterStatemachine.Event(avcfg.VlanEvIncrFlowConfig); err != nil { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3163 | logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3164 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3165 | } else { |
| 3166 | /***** UniVlanConfigFsm continued */ |
| 3167 | logger.Debugw(ctx, "UniVlanConfigFsm continued with incremental flow", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3168 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3169 | "UniPort": apUniPort.PortNo}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3170 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3171 | } else { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3172 | logger.Debugw(ctx, "no state of UniVlanConfigFsm to be continued", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3173 | "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3174 | "UniPort": apUniPort.PortNo}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3175 | } |
| 3176 | } else { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 3177 | 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] | 3178 | "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID, |
| 3179 | "UniPort": apUniPort.PortNo, "techprofile-id (done)": aTpID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3180 | } |
| 3181 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3182 | 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] | 3183 | "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3184 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3185 | } else { |
| 3186 | dh.lockVlanConfig.RUnlock() |
| 3187 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3188 | } |
| 3189 | |
| 3190 | //RemoveVlanFilterFsm deletes the stored pointer to the VlanConfigFsm |
| 3191 | // 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] | 3192 | func (dh *deviceHandler) RemoveVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3193 | logger.Debugw(ctx, "remove UniVlanConfigFsm StateMachine", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3194 | "device-id": dh.DeviceID, "uniPort": apUniPort.PortNo}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3195 | //save to do, even if entry dows not exist |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3196 | dh.lockVlanConfig.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3197 | delete(dh.UniVlanConfigFsmMap, apUniPort.UniID) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3198 | dh.lockVlanConfig.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 3199 | } |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3200 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3201 | //startWritingOnuDataToKvStore initiates the KVStore write of ONU persistent data |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3202 | func (dh *deviceHandler) startWritingOnuDataToKvStore(ctx context.Context, aPDevEntry *mib.OnuDeviceEntry) error { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3203 | dh.mutexKvStoreContext.Lock() //this write routine may (could) be called with the same context, |
| 3204 | defer dh.mutexKvStoreContext.Unlock() //this write routine may (could) be called with the same context, |
| 3205 | // obviously then parallel processing on the cancel must be avoided |
| 3206 | // deadline context to ensure completion of background routines waited for |
| 3207 | //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted |
| 3208 | deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution |
| 3209 | dctx, cancel := context.WithDeadline(context.Background(), deadline) |
| 3210 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3211 | aPDevEntry.ResetKvProcessingErrorIndication() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3212 | var wg sync.WaitGroup |
| 3213 | wg.Add(1) // for the 1 go routine to finish |
| 3214 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3215 | go aPDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3216 | dh.waitForCompletion(ctx, cancel, &wg, "UpdateKvStore") //wait for background process to finish |
| 3217 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3218 | return aPDevEntry.GetKvProcessingErrorIndication() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3219 | } |
| 3220 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3221 | //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] | 3222 | //available for potential reconcilement |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3223 | func (dh *deviceHandler) StorePersUniFlowConfig(ctx context.Context, aUniID uint8, |
| 3224 | aUniVlanFlowParams *[]cmn.UniVlanFlowParams, aWriteToKvStore bool) error { |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3225 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3226 | if dh.IsReconciling() { |
| 3227 | 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] | 3228 | return nil |
| 3229 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3230 | 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] | 3231 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3232 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3233 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3234 | logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID}) |
| 3235 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3236 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3237 | pDevEntry.UpdateOnuUniFlowConfig(aUniID, aUniVlanFlowParams) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3238 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3239 | if aWriteToKvStore { |
| 3240 | return dh.startWritingOnuDataToKvStore(ctx, pDevEntry) |
| 3241 | } |
| 3242 | return nil |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3243 | } |
| 3244 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3245 | 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] | 3246 | defer cancel() //ensure termination of context (may be pro forma) |
| 3247 | wg.Wait() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3248 | logger.Debugw(ctx, "WaitGroup processing completed", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3249 | "device-id": dh.DeviceID, "called from": aCallerIdent}) |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 3250 | } |
| 3251 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3252 | func (dh *deviceHandler) deviceReasonUpdate(ctx context.Context, deviceReason uint8, notifyCore bool) error { |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 3253 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3254 | dh.SetDeviceReason(deviceReason) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3255 | if notifyCore { |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 3256 | //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] | 3257 | if err := dh.updateDeviceReasonInCore(ctx, &ic.DeviceReason{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3258 | DeviceId: dh.DeviceID, |
| 3259 | Reason: cmn.DeviceReasonMap[deviceReason], |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3260 | }); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3261 | logger.Errorf(ctx, "DeviceReasonUpdate error: %s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3262 | log.Fields{"device-id": dh.DeviceID, "error": err}, cmn.DeviceReasonMap[deviceReason]) |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 3263 | return err |
| 3264 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3265 | 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] | 3266 | return nil |
| 3267 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3268 | 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] | 3269 | return nil |
| 3270 | } |
| 3271 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3272 | func (dh *deviceHandler) StorePersistentData(ctx context.Context) error { |
| 3273 | pDevEntry := dh.GetOnuDeviceEntry(ctx, true) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3274 | if pDevEntry == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3275 | logger.Warnw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID}) |
| 3276 | return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID) |
Holger Hildebrandt | 3a64464 | 2020-12-02 09:46:18 +0000 | [diff] [blame] | 3277 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3278 | return dh.startWritingOnuDataToKvStore(ctx, pDevEntry) |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 3279 | } |
| 3280 | |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3281 | // 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] | 3282 | // nolint: unused |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3283 | func (dh *deviceHandler) getUniPortMEEntityID(uniPortNo uint32) (uint16, error) { |
| 3284 | dh.lockDevice.RLock() |
| 3285 | defer dh.lockDevice.RUnlock() |
| 3286 | if uniPort, ok := dh.uniEntityMap[uniPortNo]; ok { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3287 | return uniPort.EntityID, nil |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3288 | } |
| 3289 | return 0, errors.New("error-fetching-uni-port") |
| 3290 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3291 | |
| 3292 | // updatePmConfig updates the pm metrics config. |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3293 | func (dh *deviceHandler) updatePmConfig(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 3294 | var errorsList []error |
| 3295 | 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] | 3296 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3297 | errorsList = append(dh.handleGlobalPmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 3298 | errorsList = append(dh.handleGroupPmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 3299 | errorsList = append(dh.handleStandalonePmConfigUpdates(ctx, pmConfigs), errorsList...) |
| 3300 | |
| 3301 | // Note that if more than one pm config field is updated in a given call, it is possible that partial pm config is handled |
| 3302 | // successfully. |
| 3303 | // TODO: Although it is possible to revert to old config in case of partial failure, the code becomes quite complex. Needs more investigation |
| 3304 | // Is it possible the rw-core reverts to old config on partial failure but adapter retains a partial new config? |
| 3305 | if len(errorsList) > 0 { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3306 | 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] | 3307 | 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] | 3308 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3309 | 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] | 3310 | return nil |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3311 | } |
| 3312 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3313 | func (dh *deviceHandler) handleGlobalPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 3314 | var err error |
| 3315 | var errorsList []error |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3316 | 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] | 3317 | |
| 3318 | if pmConfigs.DefaultFreq != dh.pmConfigs.DefaultFreq { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3319 | if err = dh.pOnuMetricsMgr.UpdateDefaultFrequency(ctx, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3320 | errorsList = append(errorsList, err) |
| 3321 | } |
| 3322 | } |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3323 | 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] | 3324 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3325 | return errorsList |
| 3326 | } |
| 3327 | |
| 3328 | func (dh *deviceHandler) handleGroupPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 3329 | var err error |
| 3330 | var errorsList []error |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3331 | 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] | 3332 | // Check if group metric related config is updated |
| 3333 | for _, v := range pmConfigs.Groups { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3334 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() |
| 3335 | m, ok := dh.pOnuMetricsMgr.GroupMetricMap[v.GroupName] |
| 3336 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3337 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3338 | if ok && m.Frequency != v.GroupFreq { |
| 3339 | if err = dh.pOnuMetricsMgr.UpdateGroupFreq(ctx, v.GroupName, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3340 | errorsList = append(errorsList, err) |
| 3341 | } |
| 3342 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3343 | if ok && m.Enabled != v.Enabled { |
| 3344 | if err = dh.pOnuMetricsMgr.UpdateGroupSupport(ctx, v.GroupName, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3345 | errorsList = append(errorsList, err) |
| 3346 | } |
| 3347 | } |
| 3348 | } |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3349 | 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] | 3350 | return errorsList |
| 3351 | } |
| 3352 | |
| 3353 | func (dh *deviceHandler) handleStandalonePmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error { |
| 3354 | var err error |
| 3355 | var errorsList []error |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3356 | 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] | 3357 | // Check if standalone metric related config is updated |
| 3358 | for _, v := range pmConfigs.Metrics { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3359 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() |
| 3360 | m, ok := dh.pOnuMetricsMgr.StandaloneMetricMap[v.Name] |
| 3361 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3362 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3363 | if ok && m.Frequency != v.SampleFreq { |
| 3364 | if err = dh.pOnuMetricsMgr.UpdateMetricFreq(ctx, v.Name, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3365 | errorsList = append(errorsList, err) |
| 3366 | } |
| 3367 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3368 | if ok && m.Enabled != v.Enabled { |
| 3369 | if err = dh.pOnuMetricsMgr.UpdateMetricSupport(ctx, v.Name, pmConfigs); err != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3370 | errorsList = append(errorsList, err) |
| 3371 | } |
| 3372 | } |
| 3373 | } |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 3374 | 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] | 3375 | return errorsList |
| 3376 | } |
| 3377 | |
| 3378 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3379 | func (dh *deviceHandler) StartCollector(ctx context.Context) { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3380 | logger.Debugf(ctx, "startingCollector") |
| 3381 | |
| 3382 | // Start routine to process OMCI GET Responses |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3383 | go dh.pOnuMetricsMgr.ProcessOmciMessages(ctx) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3384 | // Create Extended Frame PM ME |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3385 | go dh.pOnuMetricsMgr.CreateEthernetFrameExtendedPMME(ctx) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3386 | // Initialize the next metric collection time. |
| 3387 | // Normally done when the onu_metrics_manager is initialized the first time, but needed again later when ONU is |
| 3388 | // reset like onu rebooted. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3389 | dh.pOnuMetricsMgr.InitializeMetricCollectionTime(ctx) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3390 | dh.setCollectorIsRunning(true) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3391 | for { |
| 3392 | select { |
| 3393 | case <-dh.stopCollector: |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3394 | dh.setCollectorIsRunning(false) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3395 | 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] | 3396 | // Stop the L2 PM FSM |
| 3397 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3398 | if dh.pOnuMetricsMgr.PAdaptFsm != nil && dh.pOnuMetricsMgr.PAdaptFsm.PFsm != nil { |
| 3399 | if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventStop); err != nil { |
| 3400 | 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] | 3401 | } |
| 3402 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3403 | 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] | 3404 | } |
| 3405 | }() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3406 | if dh.pOnuMetricsMgr.GetOmciProcessingStatus() { |
| 3407 | dh.pOnuMetricsMgr.StopProcessingOmciResponses <- true // Stop the OMCI GET response processing routine |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 3408 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3409 | if dh.pOnuMetricsMgr.GetTickGenerationStatus() { |
| 3410 | dh.pOnuMetricsMgr.StopTicks <- true |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 3411 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 3412 | |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3413 | return |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3414 | case <-time.After(time.Duration(pmmgr.FrequencyGranularity) * time.Second): // Check every FrequencyGranularity to see if it is time for collecting metrics |
| 3415 | if !dh.pmConfigs.FreqOverride { // If FreqOverride is false, then NextGlobalMetricCollectionTime applies |
| 3416 | // If the current time is eqaul to or greater than the NextGlobalMetricCollectionTime, collect the group and standalone metrics |
| 3417 | if time.Now().Equal(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) || time.Now().After(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) { |
| 3418 | go dh.pOnuMetricsMgr.CollectAllGroupAndStandaloneMetrics(ctx) |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 3419 | // Update the next metric collection time. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3420 | 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] | 3421 | } |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3422 | } else { |
| 3423 | if dh.pmConfigs.Grouped { // metrics are managed as a group |
| 3424 | // 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] | 3425 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() // Rlock as we are reading GroupMetricMap and StandaloneMetricMap |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3426 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3427 | for n, g := range dh.pOnuMetricsMgr.GroupMetricMap { |
| 3428 | // 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] | 3429 | // 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] | 3430 | if g.Enabled && !g.IsL2PMCounter && (time.Now().Equal(g.NextCollectionInterval) || time.Now().After(g.NextCollectionInterval)) { |
| 3431 | go dh.pOnuMetricsMgr.CollectGroupMetric(ctx, n) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3432 | } |
| 3433 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3434 | for n, m := range dh.pOnuMetricsMgr.StandaloneMetricMap { |
| 3435 | // If the standalone is enabled AND (current time is equal to OR after NextCollectionInterval, collect the metric) |
| 3436 | if m.Enabled && (time.Now().Equal(m.NextCollectionInterval) || time.Now().After(m.NextCollectionInterval)) { |
| 3437 | go dh.pOnuMetricsMgr.CollectStandaloneMetric(ctx, n) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3438 | } |
| 3439 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3440 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3441 | |
| 3442 | // parse through the group and update the next metric collection time |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3443 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.Lock() // Lock as we are writing the next metric collection time |
| 3444 | for _, g := range dh.pOnuMetricsMgr.GroupMetricMap { |
| 3445 | // 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] | 3446 | // 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] | 3447 | if g.Enabled && !g.IsL2PMCounter && (g.NextCollectionInterval.Before(time.Now()) || g.NextCollectionInterval.Equal(time.Now())) { |
| 3448 | g.NextCollectionInterval = time.Now().Add(time.Duration(g.Frequency) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3449 | } |
| 3450 | } |
| 3451 | // parse through the standalone metrics and update the next metric collection time |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3452 | for _, m := range dh.pOnuMetricsMgr.StandaloneMetricMap { |
| 3453 | // If standalone metrics enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp |
| 3454 | if m.Enabled && (m.NextCollectionInterval.Before(time.Now()) || m.NextCollectionInterval.Equal(time.Now())) { |
| 3455 | m.NextCollectionInterval = time.Now().Add(time.Duration(m.Frequency) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3456 | } |
| 3457 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3458 | dh.pOnuMetricsMgr.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 3459 | } /* else { // metrics are not managed as a group |
| 3460 | // TODO: We currently do not have standalone metrics. When available, add code here to fetch the metric. |
| 3461 | } */ |
| 3462 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3463 | } |
| 3464 | } |
| 3465 | } |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 3466 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3467 | func (dh *deviceHandler) GetUniPortStatus(ctx context.Context, uniInfo *extension.GetOnuUniInfoRequest) *extension.SingleGetValueResponse { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 3468 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3469 | portStatus := uniprt.NewUniPortStatus(dh, dh.pOnuOmciDevice.PDevOmciCC) |
| 3470 | return portStatus.GetUniPortStatus(ctx, uniInfo.UniIndex) |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 3471 | } |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3472 | |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3473 | func (dh *deviceHandler) getOnuOMCICounters(ctx context.Context, onuInfo *extension.GetOmciEthernetFrameExtendedPmRequest) *extension.SingleGetValueResponse { |
| 3474 | if dh.pOnuMetricsMgr == nil { |
| 3475 | return &extension.SingleGetValueResponse{ |
| 3476 | Response: &extension.GetValueResponse{ |
| 3477 | Status: extension.GetValueResponse_ERROR, |
| 3478 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 3479 | }, |
| 3480 | } |
| 3481 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3482 | resp := dh.pOnuMetricsMgr.CollectEthernetFrameExtendedPMCounters(ctx) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3483 | return resp |
| 3484 | } |
| 3485 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3486 | func (dh *deviceHandler) isFsmInOmciIdleState(ctx context.Context, PFsm *fsm.FSM, wantedState string) bool { |
| 3487 | if PFsm == nil { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3488 | return true //FSM not active - so there is no activity on omci |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3489 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3490 | return PFsm.Current() == wantedState |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3491 | } |
| 3492 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3493 | func (dh *deviceHandler) isFsmInOmciIdleStateDefault(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, wantedState string) bool { |
| 3494 | var PFsm *fsm.FSM |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3495 | //note/TODO!!: might be that access to all these specific FSM; pointers need a semaphore protection as well, cmp lockUpgradeFsm |
| 3496 | switch omciFsm { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3497 | case cmn.CUploadFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3498 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3499 | PFsm = dh.pOnuOmciDevice.PMibUploadFsm.PFsm |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3500 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3501 | case cmn.CDownloadFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3502 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3503 | PFsm = dh.pOnuOmciDevice.PMibDownloadFsm.PFsm |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3504 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3505 | case cmn.CUniLockFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3506 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3507 | PFsm = dh.pLockStateFsm.PAdaptFsm.PFsm |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3508 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3509 | case cmn.CUniUnLockFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3510 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3511 | PFsm = dh.pUnlockStateFsm.PAdaptFsm.PFsm |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3512 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3513 | case cmn.CL2PmFsm: |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3514 | { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3515 | if dh.pOnuMetricsMgr != nil && dh.pOnuMetricsMgr.PAdaptFsm != nil { |
| 3516 | PFsm = dh.pOnuMetricsMgr.PAdaptFsm.PFsm |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3517 | } else { |
| 3518 | return true //FSM not active - so there is no activity on omci |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3519 | } |
| 3520 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3521 | case cmn.COnuUpgradeFsm: |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3522 | { |
| 3523 | dh.lockUpgradeFsm.RLock() |
| 3524 | defer dh.lockUpgradeFsm.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3525 | PFsm = dh.pOnuUpradeFsm.PAdaptFsm.PFsm |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 3526 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3527 | default: |
| 3528 | { |
| 3529 | logger.Errorw(ctx, "invalid stateMachine selected for idle check", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3530 | "device-id": dh.DeviceID, "selectedFsm number": omciFsm}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3531 | 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] | 3532 | } |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3533 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3534 | return dh.isFsmInOmciIdleState(ctx, PFsm, wantedState) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3535 | } |
| 3536 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3537 | func (dh *deviceHandler) isAniConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool { |
| 3538 | for _, v := range dh.pOnuTP.PAniConfigFsm { |
| 3539 | if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3540 | return false |
| 3541 | } |
| 3542 | } |
| 3543 | return true |
| 3544 | } |
| 3545 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3546 | func (dh *deviceHandler) isUniVlanConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3547 | dh.lockVlanConfig.RLock() |
| 3548 | defer dh.lockVlanConfig.RUnlock() |
| 3549 | for _, v := range dh.UniVlanConfigFsmMap { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3550 | if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3551 | return false |
| 3552 | } |
| 3553 | } |
| 3554 | return true //FSM not active - so there is no activity on omci |
| 3555 | } |
| 3556 | |
| 3557 | func (dh *deviceHandler) checkUserServiceExists(ctx context.Context) bool { |
| 3558 | dh.lockVlanConfig.RLock() |
| 3559 | defer dh.lockVlanConfig.RUnlock() |
| 3560 | for _, v := range dh.UniVlanConfigFsmMap { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3561 | if v.PAdaptFsm.PFsm != nil { |
| 3562 | if v.PAdaptFsm.PFsm.Is(avcfg.CVlanFsmConfiguredState) { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3563 | return true //there is at least one VLAN FSM with some active configuration |
| 3564 | } |
| 3565 | } |
| 3566 | } |
| 3567 | return false //there is no VLAN FSM with some active configuration |
| 3568 | } |
| 3569 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3570 | func (dh *deviceHandler) CheckAuditStartCondition(ctx context.Context, callingFsm cmn.UsedOmciConfigFsms) bool { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 3571 | for fsmName, fsmStruct := range fsmOmciIdleStateFuncMap { |
| 3572 | if fsmName != callingFsm && !fsmStruct.omciIdleCheckFunc(dh, ctx, fsmName, fsmStruct.omciIdleState) { |
| 3573 | return false |
| 3574 | } |
| 3575 | } |
| 3576 | // a further check is done to identify, if at least some data traffic related configuration exists |
| 3577 | // 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]) |
| 3578 | return dh.checkUserServiceExists(ctx) |
| 3579 | } |
| 3580 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3581 | func (dh *deviceHandler) PrepareReconcilingWithActiveAdapter(ctx context.Context) { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3582 | logger.Debugw(ctx, "prepare to reconcile the ONU with adapter using persistency data", log.Fields{"device-id": dh.device.Id}) |
| 3583 | if err := dh.resetFsms(ctx, false); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3584 | 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] | 3585 | // TODO: fatal error reset ONU, delete deviceHandler! |
| 3586 | return |
| 3587 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3588 | dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort) |
| 3589 | dh.StartReconciling(ctx, false) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | func (dh *deviceHandler) setCollectorIsRunning(flagValue bool) { |
| 3593 | dh.mutexCollectorFlag.Lock() |
| 3594 | dh.collectorIsRunning = flagValue |
| 3595 | dh.mutexCollectorFlag.Unlock() |
| 3596 | } |
| 3597 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3598 | func (dh *deviceHandler) GetCollectorIsRunning() bool { |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 3599 | dh.mutexCollectorFlag.RLock() |
| 3600 | flagValue := dh.collectorIsRunning |
| 3601 | dh.mutexCollectorFlag.RUnlock() |
| 3602 | return flagValue |
| 3603 | } |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 3604 | |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 3605 | func (dh *deviceHandler) setAlarmManagerIsRunning(flagValue bool) { |
| 3606 | dh.mutextAlarmManagerFlag.Lock() |
| 3607 | dh.alarmManagerIsRunning = flagValue |
| 3608 | dh.mutextAlarmManagerFlag.Unlock() |
| 3609 | } |
| 3610 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3611 | func (dh *deviceHandler) GetAlarmManagerIsRunning(ctx context.Context) bool { |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 3612 | dh.mutextAlarmManagerFlag.RLock() |
| 3613 | flagValue := dh.alarmManagerIsRunning |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 3614 | logger.Debugw(ctx, "alarm-manager-is-running", log.Fields{"flag": dh.alarmManagerIsRunning}) |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 3615 | dh.mutextAlarmManagerFlag.RUnlock() |
| 3616 | return flagValue |
| 3617 | } |
| 3618 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3619 | func (dh *deviceHandler) StartAlarmManager(ctx context.Context) { |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 3620 | logger.Debugf(ctx, "startingAlarmManager") |
| 3621 | |
| 3622 | // Start routine to process OMCI GET Responses |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3623 | go dh.pAlarmMgr.StartOMCIAlarmMessageProcessing(ctx) |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 3624 | dh.setAlarmManagerIsRunning(true) |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 3625 | if stop := <-dh.stopAlarmManager; stop { |
| 3626 | 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] | 3627 | dh.setAlarmManagerIsRunning(false) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 3628 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3629 | if dh.pAlarmMgr.AlarmSyncFsm != nil && dh.pAlarmMgr.AlarmSyncFsm.PFsm != nil { |
| 3630 | _ = dh.pAlarmMgr.AlarmSyncFsm.PFsm.Event(almgr.AsEvStop) |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 3631 | } |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 3632 | }() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3633 | dh.pAlarmMgr.StopProcessingOmciMessages <- true // Stop the OMCI routines if any(This will stop the fsms also) |
| 3634 | dh.pAlarmMgr.StopAlarmAuditTimer <- struct{}{} |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 3635 | 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] | 3636 | } |
| 3637 | } |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 3638 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3639 | func (dh *deviceHandler) StartReconciling(ctx context.Context, skipOnuConfig bool) { |
| 3640 | 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] | 3641 | |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3642 | connectStatus := voltha.ConnectStatus_UNREACHABLE |
| 3643 | operState := voltha.OperStatus_UNKNOWN |
| 3644 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3645 | if !dh.IsReconciling() { |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3646 | go func() { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3647 | logger.Debugw(ctx, "wait for channel signal or timeout", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3648 | log.Fields{"timeout": dh.pOpenOnuAc.maxTimeoutReconciling, "device-id": dh.DeviceID}) |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3649 | select { |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 3650 | case success := <-dh.chReconcilingFinished: |
| 3651 | if success { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3652 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3653 | logger.Errorw(ctx, "No valid OnuDevice - aborting Core DeviceStateUpdate", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3654 | log.Fields{"device-id": dh.DeviceID}) |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3655 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3656 | if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3657 | connectStatus = voltha.ConnectStatus_REACHABLE |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3658 | if !onuDevEntry.SOnuPersistentData.PersUniDisableDone { |
| 3659 | if onuDevEntry.SOnuPersistentData.PersUniUnlockDone { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3660 | operState = voltha.OperStatus_ACTIVE |
| 3661 | } else { |
| 3662 | operState = voltha.OperStatus_ACTIVATING |
| 3663 | } |
| 3664 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3665 | } else if onuDevEntry.SOnuPersistentData.PersOperState == "down" || |
| 3666 | onuDevEntry.SOnuPersistentData.PersOperState == "unknown" || |
| 3667 | onuDevEntry.SOnuPersistentData.PersOperState == "" { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3668 | operState = voltha.OperStatus_DISCOVERED |
| 3669 | } |
| 3670 | |
| 3671 | logger.Debugw(ctx, "Core DeviceStateUpdate", log.Fields{"connectStatus": connectStatus, "operState": operState}) |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3672 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 3673 | logger.Debugw(ctx, "reconciling has been finished in time", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3674 | log.Fields{"device-id": dh.DeviceID}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3675 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3676 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3677 | ConnStatus: connectStatus, |
| 3678 | OperStatus: operState, |
| 3679 | }); err != nil { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3680 | logger.Errorw(ctx, "unable to update device state to core", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3681 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3682 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 3683 | } else { |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 3684 | logger.Errorw(ctx, "wait for reconciling aborted", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3685 | log.Fields{"device-id": dh.DeviceID}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3686 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3687 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3688 | logger.Errorw(ctx, "No valid OnuDevice", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3689 | log.Fields{"device-id": dh.DeviceID}) |
| 3690 | } else if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3691 | connectStatus = voltha.ConnectStatus_REACHABLE |
| 3692 | } |
| 3693 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3694 | dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileCanceled, connectStatus) |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 3695 | } |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 3696 | case <-time.After(dh.pOpenOnuAc.maxTimeoutReconciling): |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3697 | logger.Errorw(ctx, "timeout waiting for reconciling to be finished!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3698 | log.Fields{"device-id": dh.DeviceID}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3699 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3700 | if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3701 | logger.Errorw(ctx, "No valid OnuDevice", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3702 | log.Fields{"device-id": dh.DeviceID}) |
| 3703 | } else if onuDevEntry.SOnuPersistentData.PersOperState == "up" { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3704 | connectStatus = voltha.ConnectStatus_REACHABLE |
| 3705 | } |
| 3706 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3707 | dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileMaxTimeout, connectStatus) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3708 | |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3709 | } |
| 3710 | dh.mutexReconcilingFlag.Lock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3711 | dh.reconciling = cNoReconciling |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3712 | dh.mutexReconcilingFlag.Unlock() |
| 3713 | }() |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3714 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3715 | dh.mutexReconcilingFlag.Lock() |
| 3716 | if skipOnuConfig { |
| 3717 | dh.reconciling = cSkipOnuConfigReconciling |
| 3718 | } else { |
| 3719 | dh.reconciling = cOnuConfigReconciling |
| 3720 | } |
| 3721 | dh.mutexReconcilingFlag.Unlock() |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3722 | } |
| 3723 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3724 | func (dh *deviceHandler) StopReconciling(ctx context.Context, success bool) { |
| 3725 | logger.Debugw(ctx, "stop reconciling", log.Fields{"device-id": dh.DeviceID, "success": success}) |
| 3726 | if dh.IsReconciling() { |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 3727 | dh.chReconcilingFinished <- success |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3728 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3729 | 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] | 3730 | } |
| 3731 | } |
| 3732 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3733 | func (dh *deviceHandler) IsReconciling() bool { |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3734 | dh.mutexReconcilingFlag.RLock() |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3735 | defer dh.mutexReconcilingFlag.RUnlock() |
| 3736 | return dh.reconciling != cNoReconciling |
| 3737 | } |
| 3738 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3739 | func (dh *deviceHandler) IsSkipOnuConfigReconciling() bool { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3740 | dh.mutexReconcilingFlag.RLock() |
| 3741 | defer dh.mutexReconcilingFlag.RUnlock() |
| 3742 | return dh.reconciling == cSkipOnuConfigReconciling |
| 3743 | } |
| 3744 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3745 | func (dh *deviceHandler) SetDeviceReason(value uint8) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3746 | dh.mutexDeviceReason.Lock() |
| 3747 | dh.deviceReason = value |
| 3748 | dh.mutexDeviceReason.Unlock() |
| 3749 | } |
| 3750 | |
| 3751 | func (dh *deviceHandler) getDeviceReason() uint8 { |
| 3752 | dh.mutexDeviceReason.RLock() |
| 3753 | value := dh.deviceReason |
| 3754 | dh.mutexDeviceReason.RUnlock() |
Holger Hildebrandt | f37b3d7 | 2021-02-17 10:25:22 +0000 | [diff] [blame] | 3755 | return value |
| 3756 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3757 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3758 | func (dh *deviceHandler) GetDeviceReasonString() string { |
| 3759 | return cmn.DeviceReasonMap[dh.getDeviceReason()] |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 3760 | } |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 3761 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3762 | func (dh *deviceHandler) SetReadyForOmciConfig(flagValue bool) { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3763 | dh.mutexReadyForOmciConfig.Lock() |
| 3764 | dh.readyForOmciConfig = flagValue |
| 3765 | dh.mutexReadyForOmciConfig.Unlock() |
| 3766 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3767 | func (dh *deviceHandler) IsReadyForOmciConfig() bool { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3768 | dh.mutexReadyForOmciConfig.RLock() |
| 3769 | flagValue := dh.readyForOmciConfig |
| 3770 | dh.mutexReadyForOmciConfig.RUnlock() |
| 3771 | return flagValue |
| 3772 | } |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3773 | |
| 3774 | func (dh *deviceHandler) deviceReconcileFailedUpdate(ctx context.Context, deviceReason uint8, connectStatus voltha.ConnectStatus_Types) { |
| 3775 | if err := dh.deviceReasonUpdate(ctx, deviceReason, true); err != nil { |
| 3776 | logger.Errorw(ctx, "unable to update device reason to core", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3777 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3778 | } |
| 3779 | |
| 3780 | 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] | 3781 | if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3782 | DeviceId: dh.DeviceID, |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3783 | ConnStatus: connectStatus, |
| 3784 | OperStatus: voltha.OperStatus_RECONCILING_FAILED, |
| 3785 | }); err != nil { |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3786 | logger.Errorw(ctx, "unable to update device state to core", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3787 | log.Fields{"device-id": dh.DeviceID, "Err": err}) |
Maninder | 7961d72 | 2021-06-16 22:10:28 +0530 | [diff] [blame] | 3788 | } |
| 3789 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3790 | |
| 3791 | /* |
| 3792 | Helper functions to communicate with Core |
| 3793 | */ |
| 3794 | |
| 3795 | func (dh *deviceHandler) getDeviceFromCore(ctx context.Context, deviceID string) (*voltha.Device, error) { |
| 3796 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3797 | if err != nil || cClient == nil { |
| 3798 | return nil, err |
| 3799 | } |
| 3800 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 3801 | defer cancel() |
| 3802 | logger.Debugw(subCtx, "get-device-from-core", log.Fields{"device-id": deviceID}) |
| 3803 | return cClient.GetDevice(subCtx, &vc.ID{Id: deviceID}) |
| 3804 | } |
| 3805 | |
| 3806 | func (dh *deviceHandler) updateDeviceStateInCore(ctx context.Context, deviceStateFilter *ic.DeviceStateFilter) error { |
| 3807 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3808 | if err != nil || cClient == nil { |
| 3809 | return err |
| 3810 | } |
| 3811 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 3812 | defer cancel() |
| 3813 | _, err = cClient.DeviceStateUpdate(subCtx, deviceStateFilter) |
| 3814 | logger.Debugw(subCtx, "device-updated-in-core", log.Fields{"device-state": deviceStateFilter, "error": err}) |
| 3815 | return err |
| 3816 | } |
| 3817 | |
| 3818 | func (dh *deviceHandler) updatePMConfigInCore(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
| 3819 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3820 | if err != nil || cClient == nil { |
| 3821 | return err |
| 3822 | } |
| 3823 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 3824 | defer cancel() |
| 3825 | _, err = cClient.DevicePMConfigUpdate(subCtx, pmConfigs) |
| 3826 | logger.Debugw(subCtx, "pmconfig-updated-in-core", log.Fields{"pm-configs": pmConfigs, "error": err}) |
| 3827 | return err |
| 3828 | } |
| 3829 | |
| 3830 | func (dh *deviceHandler) updateDeviceInCore(ctx context.Context, device *voltha.Device) error { |
| 3831 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3832 | if err != nil || cClient == nil { |
| 3833 | return err |
| 3834 | } |
| 3835 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 3836 | defer cancel() |
| 3837 | _, err = cClient.DeviceUpdate(subCtx, device) |
| 3838 | logger.Debugw(subCtx, "device-updated-in-core", log.Fields{"device-id": device.Id, "error": err}) |
| 3839 | return err |
| 3840 | } |
| 3841 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3842 | func (dh *deviceHandler) CreatePortInCore(ctx context.Context, port *voltha.Port) error { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3843 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3844 | if err != nil || cClient == nil { |
| 3845 | return err |
| 3846 | } |
| 3847 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 3848 | defer cancel() |
| 3849 | _, err = cClient.PortCreated(subCtx, port) |
| 3850 | logger.Debugw(subCtx, "port-created-in-core", log.Fields{"port": port, "error": err}) |
| 3851 | return err |
| 3852 | } |
| 3853 | |
| 3854 | func (dh *deviceHandler) updatePortStateInCore(ctx context.Context, portState *ic.PortState) error { |
| 3855 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3856 | if err != nil || cClient == nil { |
| 3857 | return err |
| 3858 | } |
| 3859 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 3860 | defer cancel() |
| 3861 | _, err = cClient.PortStateUpdate(subCtx, portState) |
| 3862 | logger.Debugw(subCtx, "port-state-updated-in-core", log.Fields{"port-state": portState, "error": err}) |
| 3863 | return err |
| 3864 | } |
| 3865 | |
| 3866 | func (dh *deviceHandler) updateDeviceReasonInCore(ctx context.Context, reason *ic.DeviceReason) error { |
| 3867 | cClient, err := dh.coreClient.GetCoreServiceClient() |
| 3868 | if err != nil || cClient == nil { |
| 3869 | return err |
| 3870 | } |
| 3871 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout) |
| 3872 | defer cancel() |
| 3873 | _, err = cClient.DeviceReasonUpdate(subCtx, reason) |
| 3874 | logger.Debugw(subCtx, "device-reason-updated-in-core", log.Fields{"reason": reason, "error": err}) |
| 3875 | return err |
| 3876 | } |
| 3877 | |
| 3878 | /* |
| 3879 | Helper functions to communicate with parent adapter |
| 3880 | */ |
| 3881 | |
| 3882 | func (dh *deviceHandler) getTechProfileInstanceFromParentAdapter(ctx context.Context, parentEndpoint string, |
| 3883 | request *ic.TechProfileInstanceRequestMessage) (*ic.TechProfileDownloadMessage, error) { |
| 3884 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint) |
| 3885 | if err != nil || pgClient == nil { |
| 3886 | return nil, err |
| 3887 | } |
| 3888 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 3889 | defer cancel() |
| 3890 | logger.Debugw(subCtx, "get-tech-profile-instance", log.Fields{"request": request, "parent-endpoint": parentEndpoint}) |
| 3891 | return pgClient.GetTechProfileInstance(subCtx, request) |
| 3892 | } |
| 3893 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3894 | func (dh *deviceHandler) SendOMCIRequest(ctx context.Context, parentEndpoint string, request *ic.OmciMessage) error { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 3895 | pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint) |
| 3896 | if err != nil || pgClient == nil { |
| 3897 | return err |
| 3898 | } |
| 3899 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm) |
| 3900 | defer cancel() |
| 3901 | logger.Debugw(subCtx, "send-omci-request", log.Fields{"request": request, "parent-endpoint": parentEndpoint}) |
| 3902 | _, err = pgClient.ProxyOmciRequest(subCtx, request) |
| 3903 | if err != nil { |
| 3904 | logger.Errorw(ctx, "omci-failure", log.Fields{"request": request, "error": err, "request-parent": request.ParentDeviceId, "request-child": request.ChildDeviceId, "request-proxy": request.ProxyAddress}) |
| 3905 | } |
| 3906 | return err |
| 3907 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3908 | |
| 3909 | // GetDeviceID - TODO: add comment |
| 3910 | func (dh *deviceHandler) GetDeviceID() string { |
| 3911 | return dh.DeviceID |
| 3912 | } |
| 3913 | |
| 3914 | // GetProxyAddressID - TODO: add comment |
| 3915 | func (dh *deviceHandler) GetProxyAddressID() string { |
| 3916 | return dh.device.ProxyAddress.GetDeviceId() |
| 3917 | } |
| 3918 | |
| 3919 | // GetProxyAddressType - TODO: add comment |
| 3920 | func (dh *deviceHandler) GetProxyAddressType() string { |
| 3921 | return dh.device.ProxyAddress.GetDeviceType() |
| 3922 | } |
| 3923 | |
| 3924 | // GetProxyAddress - TODO: add comment |
| 3925 | func (dh *deviceHandler) GetProxyAddress() *voltha.Device_ProxyAddress { |
| 3926 | return dh.device.ProxyAddress |
| 3927 | } |
| 3928 | |
| 3929 | // GetEventProxy - TODO: add comment |
| 3930 | func (dh *deviceHandler) GetEventProxy() eventif.EventProxy { |
| 3931 | return dh.EventProxy |
| 3932 | } |
| 3933 | |
| 3934 | // GetOmciTimeout - TODO: add comment |
| 3935 | func (dh *deviceHandler) GetOmciTimeout() int { |
| 3936 | return dh.pOpenOnuAc.omciTimeout |
| 3937 | } |
| 3938 | |
| 3939 | // GetAlarmAuditInterval - TODO: add comment |
| 3940 | func (dh *deviceHandler) GetAlarmAuditInterval() time.Duration { |
| 3941 | return dh.pOpenOnuAc.alarmAuditInterval |
| 3942 | } |
| 3943 | |
| 3944 | // GetDlToOnuTimeout4M - TODO: add comment |
| 3945 | func (dh *deviceHandler) GetDlToOnuTimeout4M() time.Duration { |
| 3946 | return dh.pOpenOnuAc.dlToOnuTimeout4M |
| 3947 | } |
| 3948 | |
| 3949 | // GetUniEntityMap - TODO: add comment |
| 3950 | func (dh *deviceHandler) GetUniEntityMap() *cmn.OnuUniPortMap { |
| 3951 | return &dh.uniEntityMap |
| 3952 | } |
| 3953 | |
| 3954 | // GetPonPortNumber - TODO: add comment |
| 3955 | func (dh *deviceHandler) GetPonPortNumber() *uint32 { |
| 3956 | return &dh.ponPortNumber |
| 3957 | } |
| 3958 | |
| 3959 | // GetUniVlanConfigFsm - TODO: add comment |
| 3960 | func (dh *deviceHandler) GetUniVlanConfigFsm(uniID uint8) cmn.IuniVlanConfigFsm { |
| 3961 | return dh.UniVlanConfigFsmMap[uniID] |
| 3962 | } |
| 3963 | |
| 3964 | // GetOnuAlarmManager - TODO: add comment |
| 3965 | func (dh *deviceHandler) GetOnuAlarmManager() cmn.IonuAlarmManager { |
| 3966 | return dh.pAlarmMgr |
| 3967 | } |
| 3968 | |
| 3969 | // GetOnuMetricsManager - TODO: add comment |
| 3970 | func (dh *deviceHandler) GetOnuMetricsManager() cmn.IonuMetricsManager { |
| 3971 | return dh.pOnuMetricsMgr |
| 3972 | } |
| 3973 | |
| 3974 | // GetOnuTP - TODO: add comment |
| 3975 | func (dh *deviceHandler) GetOnuTP() cmn.IonuUniTechProf { |
| 3976 | return dh.pOnuTP |
| 3977 | } |
| 3978 | |
| 3979 | // GetBackendPathPrefix - TODO: add comment |
| 3980 | func (dh *deviceHandler) GetBackendPathPrefix() string { |
| 3981 | return dh.pOpenOnuAc.cm.Backend.PathPrefix |
| 3982 | } |
| 3983 | |
| 3984 | // GetOnuIndication - TODO: add comment |
| 3985 | func (dh *deviceHandler) GetOnuIndication() *openolt.OnuIndication { |
| 3986 | return dh.pOnuIndication |
| 3987 | } |
| 3988 | |
| 3989 | // RLockMutexDeletionInProgressFlag - TODO: add comment |
| 3990 | func (dh *deviceHandler) RLockMutexDeletionInProgressFlag() { |
| 3991 | dh.mutexDeletionInProgressFlag.RLock() |
| 3992 | } |
| 3993 | |
| 3994 | // RUnlockMutexDeletionInProgressFlag - TODO: add comment |
| 3995 | func (dh *deviceHandler) RUnlockMutexDeletionInProgressFlag() { |
| 3996 | dh.mutexDeletionInProgressFlag.RUnlock() |
| 3997 | } |
| 3998 | |
| 3999 | // GetDeletionInProgress - TODO: add comment |
| 4000 | func (dh *deviceHandler) GetDeletionInProgress() bool { |
| 4001 | return dh.deletionInProgress |
| 4002 | } |
| 4003 | |
| 4004 | // GetPmConfigs - TODO: add comment |
| 4005 | func (dh *deviceHandler) GetPmConfigs() *voltha.PmConfigs { |
| 4006 | return dh.pmConfigs |
| 4007 | } |
| 4008 | |
| 4009 | // GetDeviceType - TODO: add comment |
| 4010 | func (dh *deviceHandler) GetDeviceType() string { |
| 4011 | return dh.DeviceType |
| 4012 | } |
| 4013 | |
| 4014 | // GetLogicalDeviceID - TODO: add comment |
| 4015 | func (dh *deviceHandler) GetLogicalDeviceID() string { |
| 4016 | return dh.logicalDeviceID |
| 4017 | } |
| 4018 | |
| 4019 | // GetDevice - TODO: add comment |
| 4020 | func (dh *deviceHandler) GetDevice() *voltha.Device { |
| 4021 | return dh.device |
| 4022 | } |
| 4023 | |
| 4024 | // GetMetricsEnabled - TODO: add comment |
| 4025 | func (dh *deviceHandler) GetMetricsEnabled() bool { |
| 4026 | return dh.pOpenOnuAc.MetricsEnabled |
| 4027 | } |
| 4028 | |
| 4029 | // InitPmConfigs - TODO: add comment |
| 4030 | func (dh *deviceHandler) InitPmConfigs() { |
| 4031 | dh.pmConfigs = &voltha.PmConfigs{} |
| 4032 | } |
| 4033 | |
| 4034 | // GetUniPortMask - TODO: add comment |
| 4035 | func (dh *deviceHandler) GetUniPortMask() int { |
| 4036 | return dh.pOpenOnuAc.config.UniPortMask |
| 4037 | } |