blob: af7fef372b23289bb48d0a30897c5837172ef471 [file] [log] [blame]
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001/*
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 Hildebrandt4b5e73f2021-08-19 06:51:21 +000017//Package core provides the utility for onu devices, flows and statistics
18package core
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000019
20import (
21 "context"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000022 "errors"
23 "fmt"
Holger Hildebrandt24d51952020-05-04 14:03:42 +000024 "strconv"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000025 "sync"
26 "time"
27
khenaidoo7d3c5582021-08-11 18:09:44 -040028 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config"
mpagenko1f8e8822021-06-25 14:10:21 +000029
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000030 "github.com/gogo/protobuf/proto"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000031 "github.com/looplab/fsm"
mpagenko836a1fd2021-11-01 16:12:42 +000032 me "github.com/opencord/omci-lib-go/v2/generated"
khenaidoo7d3c5582021-08-11 18:09:44 -040033 "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 Gunyelcb128ae2021-10-06 09:42:05 -070038 platform "github.com/opencord/voltha-lib-go/v7/pkg/platform"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000039 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"
kesavand011d5162021-11-25 19:21:06 +053047 "github.com/opencord/voltha-protos/v5/go/common"
khenaidoo7d3c5582021-08-11 18:09:44 -040048 vc "github.com/opencord/voltha-protos/v5/go/common"
khenaidoo42dcdfd2021-10-19 17:34:12 -040049 ca "github.com/opencord/voltha-protos/v5/go/core_adapter"
khenaidoo7d3c5582021-08-11 18:09:44 -040050 "github.com/opencord/voltha-protos/v5/go/extension"
Holger Hildebrandt9afc1582021-11-30 16:10:19 +000051 "github.com/opencord/voltha-protos/v5/go/inter_adapter"
khenaidoo42dcdfd2021-10-19 17:34:12 -040052 ia "github.com/opencord/voltha-protos/v5/go/inter_adapter"
khenaidoo7d3c5582021-08-11 18:09:44 -040053 of "github.com/opencord/voltha-protos/v5/go/openflow_13"
mpagenko59862f02021-10-11 08:53:18 +000054 "github.com/opencord/voltha-protos/v5/go/openolt"
khenaidoo7d3c5582021-08-11 18:09:44 -040055 oop "github.com/opencord/voltha-protos/v5/go/openolt"
mpagenko59862f02021-10-11 08:53:18 +000056 "github.com/opencord/voltha-protos/v5/go/tech_profile"
khenaidoo7d3c5582021-08-11 18:09:44 -040057 "github.com/opencord/voltha-protos/v5/go/voltha"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000058)
59
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000060const (
mpagenko101ac942021-11-16 15:01:29 +000061 //constants for reconcile flow check channel
62 cWaitReconcileFlowAbortOnSuccess = 0xFFFD
63 cWaitReconcileFlowAbortOnError = 0xFFFE
64 cWaitReconcileFlowNoActivity = 0xFFFF
65)
66
67const (
68 // constants for timeouts
mpagenko38662d02021-08-11 09:45:19 +000069 cTimeOutRemoveUpgrade = 1 //for usage in seconds
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000070)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000071
mpagenko1cc3cb42020-07-27 15:24:38 +000072const (
mpagenko44bd8362021-11-15 11:40:05 +000073 // dummy constant - irregular value for ConnState - used to avoiding setting this state in the updateDeviceState()
74 // should better be defined in voltha protobuf or best solution would be to define an interface to just set the OperState
75 // as long as such is not available by the libraries - use this workaround
76 connectStatusINVALID = 255 // as long as not used as key in voltha.ConnectStatus_Types_name
77)
78
79const (
mpagenko1cc3cb42020-07-27 15:24:38 +000080 // events of Device FSM
81 devEvDeviceInit = "devEvDeviceInit"
82 devEvGrpcConnected = "devEvGrpcConnected"
83 devEvGrpcDisconnected = "devEvGrpcDisconnected"
84 devEvDeviceUpInd = "devEvDeviceUpInd"
85 devEvDeviceDownInd = "devEvDeviceDownInd"
86)
87const (
88 // states of Device FSM
89 devStNull = "devStNull"
90 devStDown = "devStDown"
91 devStInit = "devStInit"
92 devStConnected = "devStConnected"
93 devStUp = "devStUp"
94)
95
Holger Hildebrandt24d51952020-05-04 14:03:42 +000096//Event category and subcategory definitions - same as defiend for OLT in eventmgr.go - should be done more centrally
97const (
Himani Chawla4d908332020-08-31 12:30:20 +053098 pon = voltha.EventSubCategory_PON
99 //olt = voltha.EventSubCategory_OLT
100 //ont = voltha.EventSubCategory_ONT
101 //onu = voltha.EventSubCategory_ONU
102 //nni = voltha.EventSubCategory_NNI
103 //service = voltha.EventCategory_SERVICE
104 //security = voltha.EventCategory_SECURITY
105 equipment = voltha.EventCategory_EQUIPMENT
106 //processing = voltha.EventCategory_PROCESSING
107 //environment = voltha.EventCategory_ENVIRONMENT
108 //communication = voltha.EventCategory_COMMUNICATION
Holger Hildebrandt24d51952020-05-04 14:03:42 +0000109)
110
111const (
112 cEventObjectType = "ONU"
113)
114const (
115 cOnuActivatedEvent = "ONU_ACTIVATED"
116)
117
mpagenkof1fc3862021-02-16 10:09:52 +0000118type omciIdleCheckStruct struct {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000119 omciIdleCheckFunc func(*deviceHandler, context.Context, cmn.UsedOmciConfigFsms, string) bool
mpagenkof1fc3862021-02-16 10:09:52 +0000120 omciIdleState string
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000121}
122
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000123var fsmOmciIdleStateFuncMap = map[cmn.UsedOmciConfigFsms]omciIdleCheckStruct{
124 cmn.CUploadFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibUlFsmIdleState},
125 cmn.CDownloadFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibDlFsmIdleState},
126 cmn.CUniLockFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState},
127 cmn.CUniUnLockFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState},
128 cmn.CAniConfigFsm: {(*deviceHandler).isAniConfigFsmInOmciIdleState, avcfg.CAniFsmIdleState},
129 cmn.CUniVlanConfigFsm: {(*deviceHandler).isUniVlanConfigFsmInOmciIdleState, avcfg.CVlanFsmIdleState},
130 cmn.CL2PmFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, pmmgr.CL2PmFsmIdleState},
131 cmn.COnuUpgradeFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, swupg.COnuUpgradeFsmIdleState},
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000132}
133
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000134const (
135 cNoReconciling = iota
136 cOnuConfigReconciling
137 cSkipOnuConfigReconciling
138)
139
Girish Gowdrae95687a2021-09-08 16:30:58 -0700140// FlowCb is the flow control block containing flow add/delete information along with a response channel
141type FlowCb struct {
142 ctx context.Context // Flow handler context
143 addFlow bool // if true flow to be added, else removed
144 flowItem *of.OfpFlowStats
145 uniPort *cmn.OnuUniPort
khenaidoo42dcdfd2021-10-19 17:34:12 -0400146 flowMetaData *of.FlowMetadata
Girish Gowdrae95687a2021-09-08 16:30:58 -0700147 respChan *chan error // channel to report the Flow handling error
148}
149
Himani Chawla6d2ae152020-09-02 13:11:20 +0530150//deviceHandler will interact with the ONU ? device.
151type deviceHandler struct {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000152 DeviceID string
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000153 DeviceType string
154 adminState string
155 device *voltha.Device
156 logicalDeviceID string
157 ProxyAddressID string
158 ProxyAddressType string
Himani Chawla4d908332020-08-31 12:30:20 +0530159 parentID string
Holger Hildebrandt24d51952020-05-04 14:03:42 +0000160 ponPortNumber uint32
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000161
khenaidoo7d3c5582021-08-11 18:09:44 -0400162 coreClient *vgrpc.Client
163 EventProxy eventif.EventProxy
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000164
Girish Gowdra5a7c4922021-01-22 18:33:41 -0800165 pmConfigs *voltha.PmConfigs
khenaidoo7d3c5582021-08-11 18:09:44 -0400166 config *config.AdapterFlags
Girish Gowdrae09a6202021-01-12 18:10:59 -0800167
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000168 pOpenOnuAc *OpenONUAC
169 pDeviceStateFsm *fsm.FSM
Himani Chawla4d908332020-08-31 12:30:20 +0530170 //pPonPort *voltha.Port
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000171 deviceEntrySet chan bool //channel for DeviceEntry set event
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000172 pOnuOmciDevice *mib.OnuDeviceEntry
173 pOnuTP *avcfg.OnuUniTechProf
174 pOnuMetricsMgr *pmmgr.OnuMetricsManager
175 pAlarmMgr *almgr.OnuAlarmManager
176 pSelfTestHdlr *otst.SelfTestControlBlock
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000177 exitChannel chan int
178 lockDevice sync.RWMutex
179 pOnuIndication *oop.OnuIndication
180 deviceReason uint8
181 mutexDeviceReason sync.RWMutex
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000182 pLockStateFsm *uniprt.LockStateFsm
183 pUnlockStateFsm *uniprt.LockStateFsm
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000184
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000185 //flowMgr *OpenOltFlowMgr
186 //eventMgr *OpenOltEventMgr
187 //resourceMgr *rsrcMgr.OpenOltResourceMgr
188
189 //discOnus sync.Map
190 //onus sync.Map
191 //portStats *OpenOltStatisticsMgr
mpagenko101ac942021-11-16 15:01:29 +0000192 collectorIsRunning bool
193 mutexCollectorFlag sync.RWMutex
194 stopCollector chan bool
195 alarmManagerIsRunning bool
196 mutextAlarmManagerFlag sync.RWMutex
197 stopAlarmManager chan bool
198 stopHeartbeatCheck chan bool
199 uniEntityMap cmn.OnuUniPortMap
200 mutexKvStoreContext sync.Mutex
201 lockVlanConfig sync.RWMutex
202 lockVlanAdd sync.RWMutex
203 UniVlanConfigFsmMap map[uint8]*avcfg.UniVlanConfigFsm
204 lockUpgradeFsm sync.RWMutex
205 pOnuUpradeFsm *swupg.OnuUpgradeFsm
206 upgradeCanceled bool
207 reconciling uint8
208 mutexReconcilingFlag sync.RWMutex
Holger Hildebrandt7741f272022-01-18 08:17:39 +0000209 reconcilingFirstPass bool
210 mutexReconcilingFirstPassFlag sync.RWMutex
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000211 reconcilingReasonUpdate bool
212 mutexReconcilingReasonUpdate sync.RWMutex
mpagenko101ac942021-11-16 15:01:29 +0000213 chUniVlanConfigReconcilingDone chan uint16 //channel to indicate that VlanConfig reconciling for a specific UNI has been finished
214 chReconcilingFinished chan bool //channel to indicate that reconciling has been finished
215 reconcileExpiryComplete time.Duration
216 reconcileExpiryVlanConfig time.Duration
217 mutexReadyForOmciConfig sync.RWMutex
218 readyForOmciConfig bool
219 deletionInProgress bool
220 mutexDeletionInProgressFlag sync.RWMutex
221 pLastUpgradeImageState *voltha.ImageState
222 upgradeFsmChan chan struct{}
Girish Gowdrae95687a2021-09-08 16:30:58 -0700223
224 flowCbChan []chan FlowCb
225 mutexFlowMonitoringRoutineFlag sync.RWMutex
ozgecanetsia5cbcfbe2022-01-14 10:32:34 +0300226 mutexForDisableDeviceRequested sync.RWMutex
Girish Gowdrae95687a2021-09-08 16:30:58 -0700227 stopFlowMonitoringRoutine []chan bool // length of slice equal to number of uni ports
228 isFlowMonitoringRoutineActive []bool // length of slice equal to number of uni ports
ozgecanetsia5cbcfbe2022-01-14 10:32:34 +0300229 disableDeviceRequested bool // this flag identify ONU received disable request or not
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000230}
231
Himani Chawla6d2ae152020-09-02 13:11:20 +0530232//newDeviceHandler creates a new device handler
khenaidoo7d3c5582021-08-11 18:09:44 -0400233func newDeviceHandler(ctx context.Context, cc *vgrpc.Client, ep eventif.EventProxy, device *voltha.Device, adapter *OpenONUAC) *deviceHandler {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530234 var dh deviceHandler
khenaidoo7d3c5582021-08-11 18:09:44 -0400235 dh.coreClient = cc
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000236 dh.EventProxy = ep
khenaidoo7d3c5582021-08-11 18:09:44 -0400237 dh.config = adapter.config
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000238 cloned := (proto.Clone(device)).(*voltha.Device)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000239 dh.DeviceID = cloned.Id
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000240 dh.DeviceType = cloned.Type
241 dh.adminState = "up"
242 dh.device = cloned
243 dh.pOpenOnuAc = adapter
244 dh.exitChannel = make(chan int, 1)
245 dh.lockDevice = sync.RWMutex{}
mpagenko3af1f032020-06-10 08:53:41 +0000246 dh.deviceEntrySet = make(chan bool, 1)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000247 dh.collectorIsRunning = false
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000248 dh.stopCollector = make(chan bool, 2)
Himani Chawla4c1d4c72021-02-18 12:14:31 +0530249 dh.alarmManagerIsRunning = false
Himani Chawlaac1f5ad2021-02-04 21:21:54 +0530250 dh.stopAlarmManager = make(chan bool, 2)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000251 dh.stopHeartbeatCheck = make(chan bool, 2)
252 //dh.metrics = pmmetrics.NewPmMetrics(cloned.Id, pmmetrics.Frequency(150), pmmetrics.FrequencyOverride(false), pmmetrics.Grouped(false), pmmetrics.Metrics(pmNames))
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000253 //TODO initialize the support classes.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000254 dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort)
mpagenkof1fc3862021-02-16 10:09:52 +0000255 dh.lockVlanConfig = sync.RWMutex{}
mpagenkobc4170a2021-08-17 16:42:10 +0000256 dh.lockVlanAdd = sync.RWMutex{}
mpagenko80622a52021-02-09 16:53:23 +0000257 dh.lockUpgradeFsm = sync.RWMutex{}
ozgecanetsia5cbcfbe2022-01-14 10:32:34 +0300258 dh.mutexForDisableDeviceRequested = sync.RWMutex{}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000259 dh.UniVlanConfigFsmMap = make(map[uint8]*avcfg.UniVlanConfigFsm)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000260 dh.reconciling = cNoReconciling
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000261 dh.reconcilingReasonUpdate = false
Holger Hildebrandt7741f272022-01-18 08:17:39 +0000262 dh.reconcilingFirstPass = true
ozgecanetsia5cbcfbe2022-01-14 10:32:34 +0300263 dh.disableDeviceRequested = false
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +0000264 dh.chReconcilingFinished = make(chan bool)
mpagenko101ac942021-11-16 15:01:29 +0000265 dh.reconcileExpiryComplete = adapter.maxTimeoutReconciling //assumption is to have it as duration in s!
266 rECSeconds := int(dh.reconcileExpiryComplete / time.Second)
267 if rECSeconds < 2 {
268 dh.reconcileExpiryComplete = time.Duration(2) * time.Second //ensure a minimum expiry time of 2s for complete reconciling
269 rECSeconds = 2
270 }
271 rEVCSeconds := rECSeconds / 2
272 dh.reconcileExpiryVlanConfig = time.Duration(rEVCSeconds) * time.Second //set this duration to some according lower value
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000273 dh.readyForOmciConfig = false
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000274 dh.deletionInProgress = false
mpagenko38662d02021-08-11 09:45:19 +0000275 dh.pLastUpgradeImageState = &voltha.ImageState{
276 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN,
277 Reason: voltha.ImageState_UNKNOWN_ERROR,
278 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
279 }
280 dh.upgradeFsmChan = make(chan struct{})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000281
Girish Gowdra5a7c4922021-01-22 18:33:41 -0800282 if dh.device.PmConfigs != nil { // can happen after onu adapter restart
283 dh.pmConfigs = cloned.PmConfigs
284 } /* else {
285 // will be populated when onu_metrics_mananger is initialized.
286 }*/
Girish Gowdrae09a6202021-01-12 18:10:59 -0800287
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000288 // Device related state machine
289 dh.pDeviceStateFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000290 devStNull,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000291 fsm.Events{
mpagenko1cc3cb42020-07-27 15:24:38 +0000292 {Name: devEvDeviceInit, Src: []string{devStNull, devStDown}, Dst: devStInit},
293 {Name: devEvGrpcConnected, Src: []string{devStInit}, Dst: devStConnected},
294 {Name: devEvGrpcDisconnected, Src: []string{devStConnected, devStDown}, Dst: devStInit},
295 {Name: devEvDeviceUpInd, Src: []string{devStConnected, devStDown}, Dst: devStUp},
296 {Name: devEvDeviceDownInd, Src: []string{devStUp}, Dst: devStDown},
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000297 },
298 fsm.Callbacks{
dbainbri4d3a0dc2020-12-02 00:33:42 +0000299 "before_event": func(e *fsm.Event) { dh.logStateChange(ctx, e) },
300 ("before_" + devEvDeviceInit): func(e *fsm.Event) { dh.doStateInit(ctx, e) },
301 ("after_" + devEvDeviceInit): func(e *fsm.Event) { dh.postInit(ctx, e) },
302 ("before_" + devEvGrpcConnected): func(e *fsm.Event) { dh.doStateConnected(ctx, e) },
303 ("before_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.doStateInit(ctx, e) },
304 ("after_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.postInit(ctx, e) },
305 ("before_" + devEvDeviceUpInd): func(e *fsm.Event) { dh.doStateUp(ctx, e) },
306 ("before_" + devEvDeviceDownInd): func(e *fsm.Event) { dh.doStateDown(ctx, e) },
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000307 },
308 )
mpagenkoaf801632020-07-03 10:00:42 +0000309
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000310 return &dh
311}
312
Himani Chawla6d2ae152020-09-02 13:11:20 +0530313// start save the device to the data model
314func (dh *deviceHandler) start(ctx context.Context) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000315 logger.Debugw(ctx, "starting-device-handler", log.Fields{"device": dh.device, "device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000316 // Add the initial device to the local model
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000317 logger.Debugw(ctx, "device-handler-started", log.Fields{"device": dh.device})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000318}
319
Himani Chawla4d908332020-08-31 12:30:20 +0530320/*
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000321// stop stops the device dh. Not much to do for now
Himani Chawla6d2ae152020-09-02 13:11:20 +0530322func (dh *deviceHandler) stop(ctx context.Context) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000323 logger.Debug("stopping-device-handler")
324 dh.exitChannel <- 1
325}
Himani Chawla4d908332020-08-31 12:30:20 +0530326*/
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000327
328// ##########################################################################################
Himani Chawla6d2ae152020-09-02 13:11:20 +0530329// deviceHandler methods that implement the adapters interface requests ##### begin #########
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000330
Girish Gowdrae0140f02021-02-02 16:55:09 -0800331//adoptOrReconcileDevice adopts the ONU device
Himani Chawla6d2ae152020-09-02 13:11:20 +0530332func (dh *deviceHandler) adoptOrReconcileDevice(ctx context.Context, device *voltha.Device) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400333 logger.Debugw(ctx, "adopt_or_reconcile_device", log.Fields{"device-id": device.Id, "Address": device.GetHostAndPort()})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000334
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000335 logger.Debugw(ctx, "Device FSM: ", log.Fields{"device-id": device.Id, "state": string(dh.pDeviceStateFsm.Current())})
mpagenko1cc3cb42020-07-27 15:24:38 +0000336 if dh.pDeviceStateFsm.Is(devStNull) {
337 if err := dh.pDeviceStateFsm.Event(devEvDeviceInit); err != nil {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000338 logger.Errorw(ctx, "Device FSM: Can't go to state DeviceInit", log.Fields{"device-id": device.Id, "err": err})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000339 }
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000340 logger.Debugw(ctx, "Device FSM: ", log.Fields{"device-id": device.Id, "state": string(dh.pDeviceStateFsm.Current())})
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800341 // device.PmConfigs is not nil in cases when adapter restarts. We should not re-set the core again.
342 if device.PmConfigs == nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -0800343 // Now, set the initial PM configuration for that device
khenaidoo7d3c5582021-08-11 18:09:44 -0400344 if err := dh.updatePMConfigInCore(ctx, dh.pmConfigs); err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000345 logger.Errorw(ctx, "error updating pm config to core", log.Fields{"device-id": dh.DeviceID, "err": err})
Girish Gowdra5a7c4922021-01-22 18:33:41 -0800346 }
Girish Gowdrae09a6202021-01-12 18:10:59 -0800347 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000348 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000349 logger.Debugw(ctx, "AdoptOrReconcileDevice: Agent/device init already done", log.Fields{"device-id": device.Id})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000350 }
351
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000352}
353
khenaidoo42dcdfd2021-10-19 17:34:12 -0400354func (dh *deviceHandler) handleOMCIIndication(ctx context.Context, msg *ia.OmciMessage) error {
mpagenko80622a52021-02-09 16:53:23 +0000355 /* msg print moved symmetrically to omci_cc, if wanted here as additional debug, than perhaps only based on additional debug setting!
Himani Chawla26e555c2020-08-31 12:30:20 +0530356 //assuming omci message content is hex coded!
357 // with restricted output of 16(?) bytes would be ...omciMsg.Message[:16]
dbainbri4d3a0dc2020-12-02 00:33:42 +0000358 logger.Debugw(ctx, "inter-adapter-recv-omci", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000359 "device-id": dh.DeviceID, "RxOmciMessage": hex.EncodeToString(omciMsg.Message)})
mpagenko80622a52021-02-09 16:53:23 +0000360 */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000361 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Himani Chawla26e555c2020-08-31 12:30:20 +0530362 if pDevEntry != nil {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000363 if pDevEntry.PDevOmciCC != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000364 return pDevEntry.PDevOmciCC.ReceiveMessage(log.WithSpanFromContext(context.TODO(), ctx), msg.Message)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000365 }
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000366 logger.Debugw(ctx, "omciCC not ready to receive omci messages - incoming omci message ignored", log.Fields{"device-id": dh.DeviceID,
367 "rxMsg": msg.Message})
Himani Chawla26e555c2020-08-31 12:30:20 +0530368 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000369 logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
370 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +0530371}
372
khenaidoo42dcdfd2021-10-19 17:34:12 -0400373func (dh *deviceHandler) handleTechProfileDownloadRequest(ctx context.Context, techProfMsg *ia.TechProfileDownloadMessage) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000374 logger.Infow(ctx, "tech-profile-download-request", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000375
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000376 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000377 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000378 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
379 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000380 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530381 if dh.pOnuTP == nil {
382 //should normally not happen ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000383 logger.Errorw(ctx, "onuTechProf instance not set up for DLMsg request - ignoring request",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000384 log.Fields{"device-id": dh.DeviceID})
385 return fmt.Errorf("techProfile DLMsg request while onuTechProf instance not setup: %s", dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +0530386 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000387 if !dh.IsReadyForOmciConfig() {
388 logger.Errorw(ctx, "TechProf-set rejected: improper device state", log.Fields{"device-id": dh.DeviceID,
389 "device-state": dh.GetDeviceReasonString()})
390 return fmt.Errorf("improper device state %s on device %s", dh.GetDeviceReasonString(), dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +0530391 }
mpagenkofc4f56e2020-11-04 17:17:49 +0000392 //previous state test here was just this one, now extended for more states to reject the SetRequest:
393 // at least 'mib-downloaded' should be reached for processing of this specific ONU configuration
394 // if (dh.deviceReason == "stopping-openomci") || (dh.deviceReason == "omci-admin-lock")
Himani Chawla26e555c2020-08-31 12:30:20 +0530395
Himani Chawla26e555c2020-08-31 12:30:20 +0530396 // we have to lock access to TechProfile processing based on different messageType calls or
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000397 // even to fast subsequent calls of the same messageType as well as OnuKVStore processing due
398 // to possible concurrent access by flow processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000399 dh.pOnuTP.LockTpProcMutex()
400 defer dh.pOnuTP.UnlockTpProcMutex()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000401
mpagenko44bd8362021-11-15 11:40:05 +0000402 if techProfMsg.UniId >= platform.MaxUnisPerOnu {
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000403 return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000404 techProfMsg.UniId, dh.DeviceID))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000405 }
406 uniID := uint8(techProfMsg.UniId)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000407 tpID, err := cmn.GetTpIDFromTpPath(techProfMsg.TpInstancePath)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800408 if err != nil {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000409 logger.Errorw(ctx, "error-parsing-tpid-from-tppath",
410 log.Fields{"device-id": dh.DeviceID, "err": err, "tp-path": techProfMsg.TpInstancePath})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800411 return err
412 }
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000413 logger.Debugw(ctx, "unmarshal-techprof-msg-body", log.Fields{"device-id": dh.DeviceID,
414 "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000415
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000416 if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, uint8(tpID), techProfMsg.TpInstancePath); bTpModify {
Himani Chawla26e555c2020-08-31 12:30:20 +0530417
Girish Gowdra50e56422021-06-01 16:46:04 -0700418 switch tpInst := techProfMsg.TechTpInstance.(type) {
khenaidoo42dcdfd2021-10-19 17:34:12 -0400419 case *ia.TechProfileDownloadMessage_TpInstance:
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000420 logger.Debugw(ctx, "onu-uni-tp-path-modified", log.Fields{"device-id": dh.DeviceID,
421 "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID})
Girish Gowdra50e56422021-06-01 16:46:04 -0700422 // if there has been some change for some uni TechProfilePath
423 //in order to allow concurrent calls to other dh instances we do not wait for execution here
424 //but doing so we can not indicate problems to the caller (who does what with that then?)
425 //by now we just assume straightforward successful execution
426 //TODO!!! Generally: In this scheme it would be good to have some means to indicate
427 // possible problems to the caller later autonomously
Himani Chawla26e555c2020-08-31 12:30:20 +0530428
Girish Gowdra50e56422021-06-01 16:46:04 -0700429 // deadline context to ensure completion of background routines waited for
430 //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
431 deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
432 dctx, cancel := context.WithDeadline(context.Background(), deadline)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000433
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000434 dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID)
Girish Gowdra50e56422021-06-01 16:46:04 -0700435
436 var wg sync.WaitGroup
437 wg.Add(1) // for the 1 go routine to finish
438 // attention: deadline completion check and wg.Done is to be done in both routines
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000439 go dh.pOnuTP.ConfigureUniTp(log.WithSpanFromContext(dctx, ctx), uniID, techProfMsg.TpInstancePath, *tpInst.TpInstance, &wg)
Girish Gowdra50e56422021-06-01 16:46:04 -0700440 dh.waitForCompletion(ctx, cancel, &wg, "TechProfDwld") //wait for background process to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000441 if tpErr := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); tpErr != nil {
442 logger.Errorw(ctx, "error-processing-tp", log.Fields{"device-id": dh.DeviceID, "err": tpErr, "tp-path": techProfMsg.TpInstancePath})
Girish Gowdra50e56422021-06-01 16:46:04 -0700443 return tpErr
444 }
445 deadline = time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
446 dctx2, cancel2 := context.WithDeadline(context.Background(), deadline)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000447 pDevEntry.ResetKvProcessingErrorIndication()
Girish Gowdra50e56422021-06-01 16:46:04 -0700448 wg.Add(1) // for the 1 go routine to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000449 go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg)
Girish Gowdra50e56422021-06-01 16:46:04 -0700450 dh.waitForCompletion(ctx, cancel2, &wg, "TechProfDwld") //wait for background process to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000451 if kvErr := pDevEntry.GetKvProcessingErrorIndication(); kvErr != nil {
452 logger.Errorw(ctx, "error-updating-KV", log.Fields{"device-id": dh.DeviceID, "err": kvErr, "tp-path": techProfMsg.TpInstancePath})
Girish Gowdra50e56422021-06-01 16:46:04 -0700453 return kvErr
454 }
455 return nil
456 default:
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000457 logger.Errorw(ctx, "unsupported-tp-instance-type", log.Fields{"device-id": dh.DeviceID, "tp-path": techProfMsg.TpInstancePath})
Girish Gowdra50e56422021-06-01 16:46:04 -0700458 return fmt.Errorf("unsupported-tp-instance-type--tp-id-%v", techProfMsg.TpInstancePath)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700459 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530460 }
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000461 // no change, nothing really to do - return success
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +0000462 logger.Debugw(ctx, "onu-uni-tp-path-not-modified", log.Fields{"device-id": dh.DeviceID,
463 "uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530464 return nil
465}
466
khenaidoo42dcdfd2021-10-19 17:34:12 -0400467func (dh *deviceHandler) handleDeleteGemPortRequest(ctx context.Context, delGemPortMsg *ia.DeleteGemPortMessage) error {
mpagenko0f543222021-11-03 16:24:14 +0000468 logger.Infow(ctx, "delete-gem-port-request start", log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530469
470 if dh.pOnuTP == nil {
471 //should normally not happen ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000472 logger.Warnw(ctx, "onuTechProf instance not set up for DelGem request - ignoring request",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000473 log.Fields{"device-id": dh.DeviceID})
474 return fmt.Errorf("techProfile DelGem request while onuTechProf instance not setup: %s", dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +0530475 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530476 //compare TECH_PROFILE_DOWNLOAD_REQUEST
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000477 dh.pOnuTP.LockTpProcMutex()
478 defer dh.pOnuTP.UnlockTpProcMutex()
Himani Chawla26e555c2020-08-31 12:30:20 +0530479
mpagenko0f543222021-11-03 16:24:14 +0000480 if delGemPortMsg.UniId >= platform.MaxUnisPerOnu {
481 logger.Errorw(ctx, "delete-gem-port UniId exceeds range", log.Fields{
482 "device-id": dh.DeviceID, "uni-id": delGemPortMsg.UniId})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000483 return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000484 delGemPortMsg.UniId, dh.DeviceID))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000485 }
486 uniID := uint8(delGemPortMsg.UniId)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000487 tpID, err := cmn.GetTpIDFromTpPath(delGemPortMsg.TpInstancePath)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800488 if err != nil {
mpagenko0f543222021-11-03 16:24:14 +0000489 logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{
490 "device-id": dh.DeviceID, "err": err, "tp-path": delGemPortMsg.TpInstancePath})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800491 return err
492 }
mpagenko0f543222021-11-03 16:24:14 +0000493 logger.Infow(ctx, "delete-gem-port-request", log.Fields{
494 "device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "gem": delGemPortMsg.GemPortId})
mpagenkofc4f56e2020-11-04 17:17:49 +0000495 //a removal of some GemPort would never remove the complete TechProfile entry (done on T-Cont)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000496
Mahir Gunyel9545be22021-07-04 15:53:16 -0700497 return dh.deleteTechProfileResource(ctx, uniID, tpID, delGemPortMsg.TpInstancePath,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000498 avcfg.CResourceGemPort, delGemPortMsg.GemPortId)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000499
Himani Chawla26e555c2020-08-31 12:30:20 +0530500}
501
khenaidoo42dcdfd2021-10-19 17:34:12 -0400502func (dh *deviceHandler) handleDeleteTcontRequest(ctx context.Context, delTcontMsg *ia.DeleteTcontMessage) error {
Holger Hildebrandt6ec9cc12022-01-24 15:47:52 +0000503 logger.Infow(ctx, "delete-tcont-request start", log.Fields{"device-id": dh.DeviceID, "uni-id": delTcontMsg.UniId, "tcont": delTcontMsg.AllocId})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000504
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000505 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000506 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000507 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
508 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000509 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530510 if dh.pOnuTP == nil {
511 //should normally not happen ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000512 logger.Warnw(ctx, "onuTechProf instance not set up for DelTcont request - ignoring request",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000513 log.Fields{"device-id": dh.DeviceID})
514 return fmt.Errorf("techProfile DelTcont request while onuTechProf instance not setup: %s", dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +0530515 }
516
Himani Chawla26e555c2020-08-31 12:30:20 +0530517 //compare TECH_PROFILE_DOWNLOAD_REQUEST
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000518 dh.pOnuTP.LockTpProcMutex()
519 defer dh.pOnuTP.UnlockTpProcMutex()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000520
mpagenko0f543222021-11-03 16:24:14 +0000521 if delTcontMsg.UniId >= platform.MaxUnisPerOnu {
522 logger.Errorw(ctx, "delete-tcont UniId exceeds range", log.Fields{
523 "device-id": dh.DeviceID, "uni-id": delTcontMsg.UniId})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000524 return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000525 delTcontMsg.UniId, dh.DeviceID))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000526 }
527 uniID := uint8(delTcontMsg.UniId)
Girish Gowdra50e56422021-06-01 16:46:04 -0700528 tpPath := delTcontMsg.TpInstancePath
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000529 tpID, err := cmn.GetTpIDFromTpPath(tpPath)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800530 if err != nil {
mpagenko0f543222021-11-03 16:24:14 +0000531 logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{
532 "device-id": dh.DeviceID, "err": err, "tp-path": tpPath})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800533 return err
534 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000535 pDevEntry.FreeTcont(ctx, uint16(delTcontMsg.AllocId))
Himani Chawla26e555c2020-08-31 12:30:20 +0530536
Holger Hildebrandt6ec9cc12022-01-24 15:47:52 +0000537 var wg sync.WaitGroup
538 deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
539 dctx, cancel := context.WithDeadline(context.Background(), deadline)
540 wg.Add(1)
541 logger.Debugw(ctx, "remove-tcont-in-kv", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "tcont": delTcontMsg.AllocId})
542 go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg)
543 dh.waitForCompletion(ctx, cancel, &wg, "DeleteTcont") //wait for background process to finish
544 if err := pDevEntry.GetKvProcessingErrorIndication(); err != nil {
545 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
546 return err
547 }
548
Mahir Gunyel9545be22021-07-04 15:53:16 -0700549 return dh.deleteTechProfileResource(ctx, uniID, tpID, delTcontMsg.TpInstancePath,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000550 avcfg.CResourceTcont, delTcontMsg.AllocId)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000551
Mahir Gunyel9545be22021-07-04 15:53:16 -0700552}
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000553
Mahir Gunyel9545be22021-07-04 15:53:16 -0700554func (dh *deviceHandler) deleteTechProfileResource(ctx context.Context,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000555 uniID uint8, tpID uint8, pathString string, resource avcfg.ResourceEntry, entryID uint32) error {
556 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Mahir Gunyel9545be22021-07-04 15:53:16 -0700557 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000558 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
559 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +0530560 }
Mahir Gunyel9545be22021-07-04 15:53:16 -0700561 var resourceName string
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000562 if avcfg.CResourceGemPort == resource {
Mahir Gunyel9545be22021-07-04 15:53:16 -0700563 resourceName = "Gem"
564 } else {
565 resourceName = "Tcont"
566 }
567
568 // deadline context to ensure completion of background routines waited for
569 deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
570 dctx, cancel := context.WithDeadline(context.Background(), deadline)
571
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000572 dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID)
Mahir Gunyel9545be22021-07-04 15:53:16 -0700573
574 var wg sync.WaitGroup
575 wg.Add(1) // for the 1 go routine to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000576 go dh.pOnuTP.DeleteTpResource(log.WithSpanFromContext(dctx, ctx), uniID, tpID, pathString,
Mahir Gunyel9545be22021-07-04 15:53:16 -0700577 resource, entryID, &wg)
578 dh.waitForCompletion(ctx, cancel, &wg, resourceName+"Delete") //wait for background process to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000579 if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); err != nil {
580 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
Mahir Gunyel9545be22021-07-04 15:53:16 -0700581 return err
582 }
583
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000584 if dh.pOnuTP.IsTechProfileConfigCleared(ctx, uniID, tpID) {
585 logger.Debugw(ctx, "techProfile-config-cleared", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID})
586 if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, tpID, ""); bTpModify {
587 pDevEntry.ResetKvProcessingErrorIndication()
Mahir Gunyel9545be22021-07-04 15:53:16 -0700588 var wg2 sync.WaitGroup
589 dctx2, cancel2 := context.WithDeadline(context.Background(), deadline)
590 wg2.Add(1)
591 // Removal of the gem id mapping represents the removal of the tech profile
Holger Hildebrandt6ec9cc12022-01-24 15:47:52 +0000592 logger.Debugw(ctx, "remove-techProfile-indication-in-kv", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000593 go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg2)
Mahir Gunyel9545be22021-07-04 15:53:16 -0700594 dh.waitForCompletion(ctx, cancel2, &wg2, "TechProfileDeleteOn"+resourceName) //wait for background process to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000595 if err := pDevEntry.GetKvProcessingErrorIndication(); err != nil {
596 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
Mahir Gunyel9545be22021-07-04 15:53:16 -0700597 return err
598 }
599 }
600 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000601 logger.Debugw(ctx, "delete-tech-profile-resource-completed", log.Fields{"device-id": dh.DeviceID,
Mahir Gunyel9545be22021-07-04 15:53:16 -0700602 "uni-id": uniID, "tpID": tpID, "resource-type": resourceName, "resource-id": entryID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530603 return nil
604}
605
mpagenkodff5dda2020-08-28 11:52:01 +0000606//FlowUpdateIncremental removes and/or adds the flow changes on a given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000607func (dh *deviceHandler) FlowUpdateIncremental(ctx context.Context,
khenaidoo7d3c5582021-08-11 18:09:44 -0400608 apOfFlowChanges *of.FlowChanges,
khenaidoo42dcdfd2021-10-19 17:34:12 -0400609 apOfGroupChanges *of.FlowGroupChanges, apFlowMetaData *of.FlowMetadata) error {
Girish Gowdrae95687a2021-09-08 16:30:58 -0700610 logger.Debugw(ctx, "FlowUpdateIncremental started", log.Fields{"device-id": dh.DeviceID, "flow": apOfFlowChanges, "metadata": apFlowMetaData})
611 var errorsList []error
612 var retError error
mpagenko01e726e2020-10-23 09:45:29 +0000613 //Remove flows (always remove flows first - remove old and add new with same cookie may be part of the same request)
mpagenkodff5dda2020-08-28 11:52:01 +0000614 if apOfFlowChanges.ToRemove != nil {
615 for _, flowItem := range apOfFlowChanges.ToRemove.Items {
mpagenkodff5dda2020-08-28 11:52:01 +0000616 if flowItem.GetCookie() == 0 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000617 logger.Warnw(ctx, "flow-remove no cookie: ignore and continuing on checking further flows", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000618 "device-id": dh.DeviceID})
619 retError = fmt.Errorf("flow-remove no cookie, device-id %s", dh.DeviceID)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700620 errorsList = append(errorsList, retError)
mpagenkodff5dda2020-08-28 11:52:01 +0000621 continue
622 }
623 flowInPort := flow.GetInPort(flowItem)
624 if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000625 logger.Warnw(ctx, "flow-remove inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID})
626 retError = fmt.Errorf("flow-remove inPort invalid, device-id %s", dh.DeviceID)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700627 errorsList = append(errorsList, retError)
mpagenko01e726e2020-10-23 09:45:29 +0000628 continue
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000629 //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +0000630 } else if flowInPort == dh.ponPortNumber {
mpagenko01e726e2020-10-23 09:45:29 +0000631 //this is some downstream flow, not regarded as error, just ignored
dbainbri4d3a0dc2020-12-02 00:33:42 +0000632 logger.Debugw(ctx, "flow-remove for downstream: ignore and continuing on checking further flows", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000633 "device-id": dh.DeviceID, "inPort": flowInPort})
mpagenkodff5dda2020-08-28 11:52:01 +0000634 continue
635 } else {
636 // this is the relevant upstream flow
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000637 var loUniPort *cmn.OnuUniPort
mpagenkodff5dda2020-08-28 11:52:01 +0000638 if uniPort, exist := dh.uniEntityMap[flowInPort]; exist {
639 loUniPort = uniPort
640 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000641 logger.Warnw(ctx, "flow-remove inPort not found in UniPorts: ignore and continuing on checking further flows",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000642 log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort})
mpagenko01e726e2020-10-23 09:45:29 +0000643 retError = fmt.Errorf("flow-remove inPort not found in UniPorts, inPort %d, device-id %s",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000644 flowInPort, dh.DeviceID)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700645 errorsList = append(errorsList, retError)
mpagenko01e726e2020-10-23 09:45:29 +0000646 continue
mpagenkodff5dda2020-08-28 11:52:01 +0000647 }
648 flowOutPort := flow.GetOutPort(flowItem)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000649 logger.Debugw(ctx, "flow-remove port indications", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000650 "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort,
651 "uniPortName": loUniPort.Name})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700652
653 if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) {
654 // Step1 : Fill flowControlBlock
655 // Step2 : Push the flowControlBlock to ONU channel
656 // Step3 : Wait on response channel for response
657 // Step4 : Return error value
658 startTime := time.Now()
659 respChan := make(chan error)
660 flowCb := FlowCb{
661 ctx: ctx,
662 addFlow: false,
663 flowItem: flowItem,
664 flowMetaData: nil,
665 uniPort: loUniPort,
666 respChan: &respChan,
667 }
668 dh.flowCbChan[loUniPort.UniID] <- flowCb
669 logger.Infow(ctx, "process-flow-remove-start", log.Fields{"device-id": dh.DeviceID})
670 // Wait on the channel for flow handlers return value
671 retError = <-respChan
672 logger.Infow(ctx, "process-flow-remove-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()})
673 if retError != nil {
674 logger.Warnw(ctx, "flow-delete processing error: continuing on checking further flows",
675 log.Fields{"device-id": dh.DeviceID, "error": retError})
676 errorsList = append(errorsList, retError)
677 continue
678 }
679 } else {
680 retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID)
681 errorsList = append(errorsList, retError)
mpagenkodff5dda2020-08-28 11:52:01 +0000682 }
683 }
684 }
685 }
mpagenko01e726e2020-10-23 09:45:29 +0000686 if apOfFlowChanges.ToAdd != nil {
687 for _, flowItem := range apOfFlowChanges.ToAdd.Items {
688 if flowItem.GetCookie() == 0 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000689 logger.Debugw(ctx, "incremental flow-add no cookie: ignore and continuing on checking further flows", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000690 "device-id": dh.DeviceID})
691 retError = fmt.Errorf("flow-add no cookie, device-id %s", dh.DeviceID)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700692 errorsList = append(errorsList, retError)
mpagenko01e726e2020-10-23 09:45:29 +0000693 continue
694 }
695 flowInPort := flow.GetInPort(flowItem)
696 if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000697 logger.Warnw(ctx, "flow-add inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID})
698 retError = fmt.Errorf("flow-add inPort invalid, device-id %s", dh.DeviceID)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700699 errorsList = append(errorsList, retError)
mpagenko01e726e2020-10-23 09:45:29 +0000700 continue
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000701 //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID)
mpagenko01e726e2020-10-23 09:45:29 +0000702 } else if flowInPort == dh.ponPortNumber {
703 //this is some downstream flow
dbainbri4d3a0dc2020-12-02 00:33:42 +0000704 logger.Debugw(ctx, "flow-add for downstream: ignore and continuing on checking further flows", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000705 "device-id": dh.DeviceID, "inPort": flowInPort})
mpagenko01e726e2020-10-23 09:45:29 +0000706 continue
707 } else {
708 // this is the relevant upstream flow
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000709 var loUniPort *cmn.OnuUniPort
mpagenko01e726e2020-10-23 09:45:29 +0000710 if uniPort, exist := dh.uniEntityMap[flowInPort]; exist {
711 loUniPort = uniPort
712 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000713 logger.Warnw(ctx, "flow-add inPort not found in UniPorts: ignore and continuing on checking further flows",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000714 log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort})
mpagenko01e726e2020-10-23 09:45:29 +0000715 retError = fmt.Errorf("flow-add inPort not found in UniPorts, inPort %d, device-id %s",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000716 flowInPort, dh.DeviceID)
Girish Gowdrae95687a2021-09-08 16:30:58 -0700717 errorsList = append(errorsList, retError)
mpagenko01e726e2020-10-23 09:45:29 +0000718 continue
mpagenko01e726e2020-10-23 09:45:29 +0000719 }
mpagenkofc4f56e2020-11-04 17:17:49 +0000720 // let's still assume that we receive the flow-add only in some 'active' device state (as so far observed)
721 // if not, we just throw some error here to have an indication about that, if we really need to support that
722 // then we would need to create some means to activate the internal stored flows
723 // after the device gets active automatically (and still with its dependency to the TechProfile)
724 // for state checking compare also code here: processInterAdapterTechProfileDownloadReqMessage
725 // also abort for the other still possible flows here
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000726 if !dh.IsReadyForOmciConfig() {
727 logger.Errorw(ctx, "flow-add rejected: improper device state", log.Fields{"device-id": dh.DeviceID,
728 "last device-reason": dh.GetDeviceReasonString()})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700729 retError = fmt.Errorf("improper device state on device %s", dh.DeviceID)
730 errorsList = append(errorsList, retError)
731 continue
mpagenkofc4f56e2020-11-04 17:17:49 +0000732 }
733
mpagenko01e726e2020-10-23 09:45:29 +0000734 flowOutPort := flow.GetOutPort(flowItem)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000735 logger.Debugw(ctx, "flow-add port indications", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000736 "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort,
737 "uniPortName": loUniPort.Name})
Girish Gowdrae95687a2021-09-08 16:30:58 -0700738 if dh.GetFlowMonitoringIsRunning(loUniPort.UniID) {
739 // Step1 : Fill flowControlBlock
740 // Step2 : Push the flowControlBlock to ONU channel
741 // Step3 : Wait on response channel for response
742 // Step4 : Return error value
743 startTime := time.Now()
744 respChan := make(chan error)
745 flowCb := FlowCb{
746 ctx: ctx,
747 addFlow: true,
748 flowItem: flowItem,
749 flowMetaData: apFlowMetaData,
750 uniPort: loUniPort,
751 respChan: &respChan,
752 }
753 dh.flowCbChan[loUniPort.UniID] <- flowCb
754 logger.Infow(ctx, "process-flow-add-start", log.Fields{"device-id": dh.DeviceID})
755 // Wait on the channel for flow handlers return value
756 retError = <-respChan
757 logger.Infow(ctx, "process-flow-add-end", log.Fields{"device-id": dh.DeviceID, "err": retError, "totalTimeSeconds": time.Since(startTime).Seconds()})
758 if retError != nil {
759 logger.Warnw(ctx, "flow-add processing error: continuing on checking further flows",
760 log.Fields{"device-id": dh.DeviceID, "error": retError})
761 errorsList = append(errorsList, retError)
762 continue
763 }
764 } else {
765 retError = fmt.Errorf("flow-handler-routine-not-active-for-onu--device-id-%v", dh.DeviceID)
766 errorsList = append(errorsList, retError)
mpagenko01e726e2020-10-23 09:45:29 +0000767 }
768 }
769 }
770 }
Girish Gowdrae95687a2021-09-08 16:30:58 -0700771 if len(errorsList) > 0 {
772 logger.Errorw(ctx, "error-processing-flow", log.Fields{"device-id": dh.DeviceID, "errList": errorsList})
773 return fmt.Errorf("errors-installing-one-or-more-flows-groups, errors:%v", errorsList)
774 }
775 return nil
mpagenkodff5dda2020-08-28 11:52:01 +0000776}
777
Himani Chawla6d2ae152020-09-02 13:11:20 +0530778//disableDevice locks the ONU and its UNI/VEIP ports (admin lock via OMCI)
mpagenkofc4f56e2020-11-04 17:17:49 +0000779//following are the expected device states after this activity:
780//Device Admin-State : down (on rwCore), Port-State: UNKNOWN, Conn-State: REACHABLE, Reason: omci-admin-lock
781// (Conn-State: REACHABLE might conflict with some previous ONU Down indication - maybe to be resolved later)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000782func (dh *deviceHandler) disableDevice(ctx context.Context, device *voltha.Device) {
783 logger.Debugw(ctx, "disable-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber})
ozgecanetsia5cbcfbe2022-01-14 10:32:34 +0300784 dh.mutexForDisableDeviceRequested.Lock()
785 dh.disableDeviceRequested = true
786 dh.mutexForDisableDeviceRequested.Unlock()
mpagenko900ee4b2020-10-12 11:56:34 +0000787 //admin-lock reason can also be used uniquely for setting the DeviceState accordingly
mpagenkofc4f56e2020-11-04 17:17:49 +0000788 //note that disableDevice sequences in some 'ONU active' state may yield also
789 // "tech...delete-success" or "omci-flow-deleted" according to further received requests in the end
mpagenko900ee4b2020-10-12 11:56:34 +0000790 // - inblock state checking to prevent possibly unneeded processing (on command repitition)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000791 if dh.getDeviceReason() != cmn.DrOmciAdminLock {
mpagenkofc4f56e2020-11-04 17:17:49 +0000792 //disable-device shall be just a UNi/ONU-G related admin state setting
793 //all other configurations/FSM's shall not be impacted and shall execute as required by the system
mpagenko900ee4b2020-10-12 11:56:34 +0000794
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000795 if dh.IsReadyForOmciConfig() {
mpagenko01e726e2020-10-23 09:45:29 +0000796 // disable UNI ports/ONU
797 // *** should generate UniDisableStateDone event - used to disable the port(s) on success
798 if dh.pLockStateFsm == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000799 dh.createUniLockFsm(ctx, true, cmn.UniDisableStateDone)
mpagenko01e726e2020-10-23 09:45:29 +0000800 } else { //LockStateFSM already init
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000801 dh.pLockStateFsm.SetSuccessEvent(cmn.UniDisableStateDone)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000802 dh.runUniLockFsm(ctx, true)
mpagenko01e726e2020-10-23 09:45:29 +0000803 }
804 } else {
mpagenko44bd8362021-11-15 11:40:05 +0000805 logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000806 "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID})
mpagenko44bd8362021-11-15 11:40:05 +0000807 // disable device should have no impact on ConnStatus
khenaidoo42dcdfd2021-10-19 17:34:12 -0400808 if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000809 DeviceId: dh.DeviceID,
mpagenko44bd8362021-11-15 11:40:05 +0000810 ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus
khenaidoo7d3c5582021-08-11 18:09:44 -0400811 OperStatus: voltha.OperStatus_UNKNOWN,
812 }); err != nil {
mpagenko01e726e2020-10-23 09:45:29 +0000813 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000814 logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko01e726e2020-10-23 09:45:29 +0000815 }
mpagenko01e726e2020-10-23 09:45:29 +0000816 // DeviceReason to update acc.to modified py code as per beginning of Sept 2020
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000817
818 //TODO with VOL-3045/VOL-3046: catch and return error, valid for all occurrences in the codebase
mpagenkoe4782082021-11-25 12:04:26 +0000819 _ = dh.ReasonUpdate(ctx, cmn.DrOmciAdminLock, true)
mpagenko3af1f032020-06-10 08:53:41 +0000820 }
ozgecanetsiafce57b12020-05-25 14:39:35 +0300821 }
822}
823
Himani Chawla6d2ae152020-09-02 13:11:20 +0530824//reEnableDevice unlocks the ONU and its UNI/VEIP ports (admin unlock via OMCI)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000825func (dh *deviceHandler) reEnableDevice(ctx context.Context, device *voltha.Device) {
826 logger.Debugw(ctx, "reenable-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber})
mpagenko3af1f032020-06-10 08:53:41 +0000827
mpagenkoaa3afe92021-05-21 16:20:58 +0000828 //setting readyForOmciConfig here is just a workaround for BBSIM testing in the sequence
mpagenkofc4f56e2020-11-04 17:17:49 +0000829 // OnuSoftReboot-disable-enable, because BBSIM does not generate a new OnuIndication-Up event after SoftReboot
830 // which is the assumption for real ONU's, where the ready-state is then set according to the following MibUpload/Download
831 // for real ONU's that should have nearly no influence
832 // Note that for real ONU's there is anyway a problematic situation with following sequence:
833 // OnuIndication-Dw (or not active at all) (- disable) - enable: here already the LockFsm may run into timeout (no OmciResponse)
834 // but that anyway is hopefully resolved by some OnuIndication-Up event (maybe to be tested)
835 // one could also argue, that a device-enable should also enable attempts for specific omci configuration
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000836 dh.SetReadyForOmciConfig(true) //needed to allow subsequent flow/techProf config (on BBSIM)
mpagenkofc4f56e2020-11-04 17:17:49 +0000837
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000838 // enable ONU/UNI ports
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000839 // *** should generate cmn.UniEnableStateDone event - used to disable the port(s) on success
ozgecanetsia5cbcfbe2022-01-14 10:32:34 +0300840 dh.mutexForDisableDeviceRequested.Lock()
841 dh.disableDeviceRequested = false
842 dh.mutexForDisableDeviceRequested.Unlock()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000843 if dh.pUnlockStateFsm == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000844 dh.createUniLockFsm(ctx, false, cmn.UniEnableStateDone)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000845 } else { //UnlockStateFSM already init
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000846 dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniEnableStateDone)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000847 dh.runUniLockFsm(ctx, false)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000848 }
ozgecanetsiafce57b12020-05-25 14:39:35 +0300849}
850
dbainbri4d3a0dc2020-12-02 00:33:42 +0000851func (dh *deviceHandler) reconcileDeviceOnuInd(ctx context.Context) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000852 logger.Debugw(ctx, "reconciling - simulate onu indication", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000853
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000854 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000855 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000856 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000857 return
858 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000859 if err := pDevEntry.RestoreDataFromOnuKvStore(log.WithSpanFromContext(context.TODO(), ctx)); err != nil {
mpagenko2418ab02020-11-12 12:58:06 +0000860 if err == fmt.Errorf("no-ONU-data-found") {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000861 logger.Debugw(ctx, "no persistent data found - abort reconciling", log.Fields{"device-id": dh.DeviceID})
mpagenko2418ab02020-11-12 12:58:06 +0000862 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000863 logger.Errorw(ctx, "reconciling - restoring OnuTp-data failed - abort", log.Fields{"err": err, "device-id": dh.DeviceID})
mpagenko2418ab02020-11-12 12:58:06 +0000864 }
mpagenko101ac942021-11-16 15:01:29 +0000865 dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000866 return
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000867 }
Himani Chawla4d908332020-08-31 12:30:20 +0530868 var onuIndication oop.OnuIndication
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000869 pDevEntry.MutexPersOnuConfig.RLock()
870 onuIndication.IntfId = pDevEntry.SOnuPersistentData.PersIntfID
871 onuIndication.OnuId = pDevEntry.SOnuPersistentData.PersOnuID
872 onuIndication.OperState = pDevEntry.SOnuPersistentData.PersOperState
873 onuIndication.AdminState = pDevEntry.SOnuPersistentData.PersAdminState
874 pDevEntry.MutexPersOnuConfig.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000875 _ = dh.createInterface(ctx, &onuIndication)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000876}
877
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000878func (dh *deviceHandler) ReconcileDeviceTechProf(ctx context.Context) bool {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000879 logger.Debugw(ctx, "reconciling - trigger tech profile config", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000880
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000881 continueWithFlowConfig := false
882
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000883 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000884 if pDevEntry == nil {
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000885 logger.Errorw(ctx, "reconciling - no valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000886 dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity)
887 return continueWithFlowConfig
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000888 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000889 dh.pOnuTP.LockTpProcMutex()
890 defer dh.pOnuTP.UnlockTpProcMutex()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000891
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000892 pDevEntry.MutexPersOnuConfig.RLock()
mpagenko2dc896e2021-08-02 12:03:59 +0000893 persMutexLock := true
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000894 if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 {
895 pDevEntry.MutexPersOnuConfig.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000896 logger.Debugw(ctx, "reconciling - no uni-configs have been stored before adapter restart - terminate reconcilement",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000897 log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000898 dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity)
899 return continueWithFlowConfig
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000900 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000901 flowsFound := false
Girish Gowdra50e56422021-06-01 16:46:04 -0700902 techProfsFound := false
903 techProfInstLoadFailed := false
904outerLoop:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000905 for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig {
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000906 uniID := uniData.PersUniID
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000907 //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000908 if !dh.anyTpPathExists(uniData.PersTpPathMap) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000909 logger.Debugw(ctx, "reconciling - no TPs stored for uniID",
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000910 log.Fields{"uni-id": uniID, "device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000911 continue
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000912 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000913 //release MutexPersOnuConfig before TechProfile (ANIConfig) processing as otherwise the reception of
914 // OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI
mpagenko2dc896e2021-08-02 12:03:59 +0000915 // frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000916 pDevEntry.MutexPersOnuConfig.RUnlock()
mpagenko2dc896e2021-08-02 12:03:59 +0000917 persMutexLock = false
Girish Gowdra50e56422021-06-01 16:46:04 -0700918 techProfsFound = true // set to true if we found TP once for any UNI port
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000919 var iaTechTpInst ia.TechProfileDownloadMessage
920 var ok bool
Girish Gowdra041dcb32020-11-16 16:54:30 -0800921 for tpID := range uniData.PersTpPathMap {
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000922 pDevEntry.MutexReconciledTpInstances.RLock()
923 if iaTechTpInst, ok = pDevEntry.ReconciledTpInstances[uniID][tpID]; !ok {
924 logger.Errorw(ctx, "reconciling - no reconciled tp instance available",
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000925 log.Fields{"tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID,
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000926 "device-id": dh.DeviceID})
Girish Gowdra50e56422021-06-01 16:46:04 -0700927 techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000928 pDevEntry.MutexReconciledTpInstances.RUnlock()
Girish Gowdra50e56422021-06-01 16:46:04 -0700929 break outerLoop
930 }
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000931 pDevEntry.MutexReconciledTpInstances.RUnlock()
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000932 continueWithFlowConfig = true // valid TP found - try flow configuration later
Girish Gowdra50e56422021-06-01 16:46:04 -0700933 var tpInst tech_profile.TechProfileInstance
934 switch techTpInst := iaTechTpInst.TechTpInstance.(type) {
khenaidoo42dcdfd2021-10-19 17:34:12 -0400935 case *ia.TechProfileDownloadMessage_TpInstance: // supports only GPON, XGPON, XGS-PON
Girish Gowdra50e56422021-06-01 16:46:04 -0700936 tpInst = *techTpInst.TpInstance
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000937 logger.Debugw(ctx, "reconciling - received-tp-instance-successfully-after-reconcile", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000938 "tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
Girish Gowdra50e56422021-06-01 16:46:04 -0700939 default: // do not support epon or other tech
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000940 logger.Errorw(ctx, "reconciling - unsupported-tech-profile", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000941 "tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
Girish Gowdra50e56422021-06-01 16:46:04 -0700942 techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure
943 break outerLoop
944 }
945
Girish Gowdra041dcb32020-11-16 16:54:30 -0800946 // deadline context to ensure completion of background routines waited for
947 //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
948 deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
dbainbri4d3a0dc2020-12-02 00:33:42 +0000949 dctx, cancel := context.WithDeadline(ctx, deadline)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000950
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000951 dh.pOnuTP.ResetTpProcessingErrorIndication(uniData.PersUniID, tpID)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800952 var wg sync.WaitGroup
953 wg.Add(1) // for the 1 go routine to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000954 go dh.pOnuTP.ConfigureUniTp(log.WithSpanFromContext(dctx, ctx), uniData.PersUniID, uniData.PersTpPathMap[tpID], tpInst, &wg)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000955 dh.waitForCompletion(ctx, cancel, &wg, "TechProfReconcile") //wait for background process to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000956 if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniData.PersUniID, tpID); err != nil {
957 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
Girish Gowdra50e56422021-06-01 16:46:04 -0700958 techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure
959 break outerLoop
Girish Gowdra041dcb32020-11-16 16:54:30 -0800960 }
mpagenko2dc896e2021-08-02 12:03:59 +0000961 } // for all TpPath entries for this UNI
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000962 if len(uniData.PersFlowParams) != 0 {
963 flowsFound = true
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000964 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000965 pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData
mpagenko2dc896e2021-08-02 12:03:59 +0000966 persMutexLock = true
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000967 } // for all UNI entries from SOnuPersistentData
968 if persMutexLock { // if loop was left with MutexPersOnuConfig still set
969 pDevEntry.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000970 }
mpagenko2dc896e2021-08-02 12:03:59 +0000971
972 //had to move techProf/flow result evaluation into separate function due to SCA complexity limit
973 dh.updateReconcileStates(ctx, techProfsFound, techProfInstLoadFailed, flowsFound)
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000974
975 return continueWithFlowConfig
mpagenko2dc896e2021-08-02 12:03:59 +0000976}
977
978func (dh *deviceHandler) updateReconcileStates(ctx context.Context,
979 abTechProfsFound bool, abTechProfInstLoadFailed bool, abFlowsFound bool) {
980 if !abTechProfsFound {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000981 logger.Debugw(ctx, "reconciling - no TPs have been stored before adapter restart - terminate reconcilement",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000982 log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000983 dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000984 return
985 }
mpagenko2dc896e2021-08-02 12:03:59 +0000986 if abTechProfInstLoadFailed {
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000987 _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadFailed, dh.IsReconcilingReasonUpdate())
mpagenko101ac942021-11-16 15:01:29 +0000988 dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity)
Girish Gowdra50e56422021-06-01 16:46:04 -0700989 return
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000990 } else if dh.IsSkipOnuConfigReconciling() {
Holger Hildebrandt9afc1582021-11-30 16:10:19 +0000991 _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, dh.IsReconcilingReasonUpdate())
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000992 }
mpagenko2dc896e2021-08-02 12:03:59 +0000993 if !abFlowsFound {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000994 logger.Debugw(ctx, "reconciling - no flows have been stored before adapter restart - terminate reconcilement",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000995 log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtb314f442021-11-24 12:03:10 +0000996 dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000997 }
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000998}
999
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001000func (dh *deviceHandler) ReconcileDeviceFlowConfig(ctx context.Context) {
1001 logger.Debugw(ctx, "reconciling - trigger flow config", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001002
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001003 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001004 if pDevEntry == nil {
Holger Hildebrandt9afc1582021-11-30 16:10:19 +00001005 logger.Errorw(ctx, "reconciling - no valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtb314f442021-11-24 12:03:10 +00001006 dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001007 return
1008 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001009
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001010 pDevEntry.MutexPersOnuConfig.RLock()
1011 if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 {
1012 pDevEntry.MutexPersOnuConfig.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001013 logger.Debugw(ctx, "reconciling - no uni-configs have been stored before adapter restart - terminate reconcilement",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001014 log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtb314f442021-11-24 12:03:10 +00001015 dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001016 return
1017 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001018 flowsFound := false
mpagenko101ac942021-11-16 15:01:29 +00001019 var uniVlanConfigEntries []uint8
1020 var loWaitGroupWTO cmn.WaitGroupWithTimeOut
1021
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001022 for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig {
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001023 //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support
1024 if len(uniData.PersFlowParams) == 0 {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001025 logger.Debugw(ctx, "reconciling - no flows stored for uniID",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001026 log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001027 continue
1028 }
Holger Hildebrandtb314f442021-11-24 12:03:10 +00001029 if !dh.anyTpPathExists(uniData.PersTpPathMap) {
mpagenko101ac942021-11-16 15:01:29 +00001030 logger.Warnw(ctx, "reconciling flows - but no TPs stored for uniID, abort",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001031 log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
Holger Hildebrandt7e9de862021-03-26 14:01:49 +00001032 // It doesn't make sense to configure any flows if no TPs are available
1033 continue
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001034 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001035 //release MutexPersOnuConfig before VlanConfig processing as otherwise the reception of
1036 // OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI
mpagenko2dc896e2021-08-02 12:03:59 +00001037 // frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001038 pDevEntry.MutexPersOnuConfig.RUnlock()
mpagenko2dc896e2021-08-02 12:03:59 +00001039
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001040 var uniPort *cmn.OnuUniPort
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001041 var exist bool
Mahir Gunyelcb128ae2021-10-06 09:42:05 -07001042 uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), uint32(uniData.PersUniID))
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001043 if uniPort, exist = dh.uniEntityMap[uniNo]; !exist {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001044 logger.Errorw(ctx, "reconciling - OnuUniPort data not found - terminate reconcilement",
1045 log.Fields{"uniNo": uniNo, "device-id": dh.DeviceID})
Holger Hildebrandtb314f442021-11-24 12:03:10 +00001046 dh.stopReconciling(ctx, false, cWaitReconcileFlowNoActivity)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001047 return
1048 }
mpagenko101ac942021-11-16 15:01:29 +00001049 //needed to split up function due to sca complexity
1050 dh.updateReconcileFlowConfig(ctx, uniPort, uniData.PersFlowParams, uniVlanConfigEntries, &loWaitGroupWTO, &flowsFound)
1051
mpagenko2dc896e2021-08-02 12:03:59 +00001052 logger.Debugw(ctx, "reconciling - flows processed", log.Fields{
mpagenko101ac942021-11-16 15:01:29 +00001053 "device-id": dh.DeviceID, "uni-id": uniData.PersUniID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001054 "NumUniFlows": dh.UniVlanConfigFsmMap[uniData.PersUniID].NumUniFlows,
1055 "ConfiguredUniFlow": dh.UniVlanConfigFsmMap[uniData.PersUniID].ConfiguredUniFlow})
Andrea Campanellaf66ac6e2021-05-24 17:09:20 +02001056 // this can't be used as global finished reconciling flag because
1057 // assumes is getting called before the state machines for the last flow is completed,
1058 // while this is not guaranteed.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001059 pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData
1060 } // for all UNI entries from SOnuPersistentData
1061 pDevEntry.MutexPersOnuConfig.RUnlock()
mpagenko2dc896e2021-08-02 12:03:59 +00001062
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001063 if !flowsFound {
1064 logger.Debugw(ctx, "reconciling - no flows have been stored before adapter restart - terminate reconcilement",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001065 log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtb314f442021-11-24 12:03:10 +00001066 dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00001067 return
1068 }
Holger Hildebrandt7741f272022-01-18 08:17:39 +00001069 logger.Debugw(ctx, "reconciling flows - waiting on ready indication of requested UNIs", log.Fields{
1070 "device-id": dh.DeviceID, "expiry": dh.reconcileExpiryVlanConfig})
1071 if executed := loWaitGroupWTO.WaitTimeout(dh.reconcileExpiryVlanConfig); executed {
1072 logger.Debugw(ctx, "reconciling flows for all UNI's has been finished in time",
1073 log.Fields{"device-id": dh.DeviceID})
1074 dh.stopReconciling(ctx, true, cWaitReconcileFlowAbortOnSuccess)
1075 if pDevEntry != nil {
1076 pDevEntry.SendChReconcilingFlowsFinished(ctx, true)
mpagenko101ac942021-11-16 15:01:29 +00001077 }
Holger Hildebrandt7741f272022-01-18 08:17:39 +00001078 } else {
1079 logger.Errorw(ctx, "reconciling - timeout waiting for reconciling flows for all UNI's to be finished!",
1080 log.Fields{"device-id": dh.DeviceID})
1081 dh.stopReconciling(ctx, false, cWaitReconcileFlowAbortOnError)
1082 if pDevEntry != nil {
1083 pDevEntry.SendChReconcilingFlowsFinished(ctx, false)
1084 }
1085 return
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001086 }
Holger Hildebrandt7741f272022-01-18 08:17:39 +00001087 _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsPushed, dh.IsReconcilingReasonUpdate())
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001088}
1089
mpagenko101ac942021-11-16 15:01:29 +00001090func (dh *deviceHandler) updateReconcileFlowConfig(ctx context.Context, apUniPort *cmn.OnuUniPort,
1091 aPersFlowParam []cmn.UniVlanFlowParams, aUniVlanConfigEntries []uint8,
1092 apWaitGroup *cmn.WaitGroupWithTimeOut, apFlowsFound *bool) {
1093 flowsProcessed := 0
1094 lastFlowToReconcile := false
1095 loUniID := apUniPort.UniID
1096 for _, flowData := range aPersFlowParam {
Holger Hildebrandt7741f272022-01-18 08:17:39 +00001097 if !(*apFlowsFound) {
1098 *apFlowsFound = true
1099 syncChannel := make(chan struct{})
1100 // start go routine with select() on reconciling vlan config channel before
1101 // starting vlan config reconciling process to prevent loss of any signal
1102 // this routine just collects all the received 'flow-reconciled' signals - possibly from different UNI's
1103 go dh.waitOnUniVlanConfigReconcilingReady(ctx, syncChannel, apWaitGroup)
1104 //block until the wait routine is really blocked on channel input
1105 // in order to prevent to early ready signal from VlanConfig processing
1106 <-syncChannel
1107 }
1108 if flowsProcessed == len(aPersFlowParam)-1 {
1109 var uniAdded bool
1110 lastFlowToReconcile = true
1111 if aUniVlanConfigEntries, uniAdded = dh.appendIfMissing(aUniVlanConfigEntries, loUniID); uniAdded {
1112 apWaitGroup.Add(1) //increment the waiting group
mpagenko101ac942021-11-16 15:01:29 +00001113 }
1114 }
mpagenko101ac942021-11-16 15:01:29 +00001115 logger.Debugw(ctx, "reconciling - add flow with cookie slice", log.Fields{
1116 "device-id": dh.DeviceID, "uni-id": loUniID,
1117 "flowsProcessed": flowsProcessed, "cookies": flowData.CookieSlice})
1118 dh.lockVlanConfig.Lock()
1119 //the CookieSlice can be passed 'by value' here, - which internally passes its reference
1120 if _, exist := dh.UniVlanConfigFsmMap[loUniID]; exist {
1121 if err := dh.UniVlanConfigFsmMap[loUniID].SetUniFlowParams(ctx, flowData.VlanRuleParams.TpID,
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05301122 flowData.CookieSlice, uint16(flowData.VlanRuleParams.MatchVid), uint8(flowData.VlanRuleParams.MatchPcp), uint16(flowData.VlanRuleParams.SetVid), uint8(flowData.VlanRuleParams.SetPcp), flowData.VlanRuleParams.InnerCvlan, lastFlowToReconcile, flowData.Meter, nil); err != nil {
mpagenko101ac942021-11-16 15:01:29 +00001123 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
1124 }
1125 } else {
1126 if err := dh.createVlanFilterFsm(ctx, apUniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice,
Abhilash Laxmeshwarc7c29d82022-03-03 18:38:45 +05301127 uint16(flowData.VlanRuleParams.MatchVid), uint8(flowData.VlanRuleParams.MatchPcp), uint16(flowData.VlanRuleParams.SetVid),
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05301128 uint8(flowData.VlanRuleParams.SetPcp), flowData.VlanRuleParams.InnerCvlan, cmn.OmciVlanFilterAddDone, lastFlowToReconcile, flowData.Meter, nil); err != nil {
mpagenko101ac942021-11-16 15:01:29 +00001129 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
1130 }
1131 }
1132 dh.lockVlanConfig.Unlock()
1133 flowsProcessed++
1134 } //for all flows of this UNI
1135}
1136
1137//waitOnUniVlanConfigReconcilingReady collects all VlanConfigReady signals from VlanConfig FSM processing in reconciling
1138// and decrements the according handler wait group waiting for these indications
1139func (dh *deviceHandler) waitOnUniVlanConfigReconcilingReady(ctx context.Context, aSyncChannel chan<- struct{},
1140 waitGroup *cmn.WaitGroupWithTimeOut) {
1141 var reconciledUniVlanConfigEntries []uint8
1142 var appended bool
1143 expiry := dh.GetReconcileExpiryVlanConfigAbort()
1144 logger.Debugw(ctx, "start waiting on reconcile vlanConfig ready indications", log.Fields{
1145 "device-id": dh.DeviceID, "expiry": expiry})
1146 // indicate blocking on channel now to the caller
1147 aSyncChannel <- struct{}{}
1148 for {
1149 select {
1150 case uniIndication := <-dh.chUniVlanConfigReconcilingDone:
1151 switch uniIndication {
1152 // no activity requested (should normally not be received) - just continue waiting
1153 case cWaitReconcileFlowNoActivity:
1154 // waiting on channel inputs from VlanConfig for all UNI's to be aborted on error condition
1155 case cWaitReconcileFlowAbortOnError:
1156 logger.Debugw(ctx, "waitReconcileFlow aborted on error",
1157 log.Fields{"device-id": dh.DeviceID, "rxEntries": reconciledUniVlanConfigEntries})
1158 return
1159 // waiting on channel inputs from VlanConfig for all UNI's to be aborted on success condition
1160 case cWaitReconcileFlowAbortOnSuccess:
1161 logger.Debugw(ctx, "waitReconcileFlow aborted on success",
1162 log.Fields{"device-id": dh.DeviceID, "rxEntries": reconciledUniVlanConfigEntries})
1163 return
1164 // this should be a valid UNI vlan config done indication
1165 default:
1166 if uniIndication < platform.MaxUnisPerOnu {
1167 logger.Debugw(ctx, "reconciling flows has been finished in time for this UNI",
1168 log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication})
1169 if reconciledUniVlanConfigEntries, appended =
1170 dh.appendIfMissing(reconciledUniVlanConfigEntries, uint8(uniIndication)); appended {
1171 waitGroup.Done()
1172 }
1173 } else {
1174 logger.Errorw(ctx, "received unexpected UNI flowConfig done indication - is ignored",
1175 log.Fields{"device-id": dh.DeviceID, "uni-id": uniIndication})
1176 }
1177 } //switch uniIndication
1178
1179 case <-time.After(expiry): //a bit longer than reconcileExpiryVlanConfig
1180 logger.Errorw(ctx, "timeout waiting for reconciling all UNI flows to be finished!",
1181 log.Fields{"device-id": dh.DeviceID})
1182 return
1183 }
1184 }
1185}
1186
1187func (dh *deviceHandler) GetReconcileExpiryVlanConfigAbort() time.Duration {
1188 return dh.reconcileExpiryVlanConfig + (500 * time.Millisecond)
1189}
1190
1191func (dh *deviceHandler) appendIfMissing(slice []uint8, val uint8) ([]uint8, bool) {
1192 for _, ele := range slice {
1193 if ele == val {
1194 return slice, false
1195 }
1196 }
1197 return append(slice, val), true
1198}
1199
1200// sendChReconcileFinished - sends true or false on reconcileFinish channel
1201func (dh *deviceHandler) sendChReconcileFinished(success bool) {
1202 if dh != nil { //if the object still exists (might have been already deleted in background)
1203 //use asynchronous channel sending to avoid stucking on non-waiting receiver
1204 select {
1205 case dh.chReconcilingFinished <- success:
1206 default:
1207 }
1208 }
1209}
1210
1211// SendChUniVlanConfigFinished - sends the Uni number on channel if the flow reconcilement for this UNI is finished
1212func (dh *deviceHandler) SendChUniVlanConfigFinished(value uint16) {
1213 if dh != nil { //if the object still exists (might have been already deleted in background)
1214 //use asynchronous channel sending to avoid stucking on non-waiting receiver
1215 select {
1216 case dh.chUniVlanConfigReconcilingDone <- value:
1217 default:
1218 }
1219 }
1220}
1221
dbainbri4d3a0dc2020-12-02 00:33:42 +00001222func (dh *deviceHandler) deleteDevicePersistencyData(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001223 logger.Debugw(ctx, "delete device persistency data", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001224
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001225 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001226 if pDevEntry == nil {
mpagenko2418ab02020-11-12 12:58:06 +00001227 //IfDevEntry does not exist here, no problem - no persistent data should have been stored
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001228 logger.Debugw(ctx, "OnuDevice does not exist - nothing to delete", log.Fields{"device-id": dh.DeviceID})
mpagenko2418ab02020-11-12 12:58:06 +00001229 return nil
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001230 }
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001231
1232 // deadline context to ensure completion of background routines waited for
1233 //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
Himani Chawlad96df182020-09-28 11:12:02 +05301234 deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
dbainbri4d3a0dc2020-12-02 00:33:42 +00001235 dctx, cancel := context.WithDeadline(ctx, deadline)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001236
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001237 pDevEntry.ResetKvProcessingErrorIndication()
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001238
1239 var wg sync.WaitGroup
1240 wg.Add(1) // for the 1 go routine to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001241 go pDevEntry.DeleteDataFromOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001242 dh.waitForCompletion(ctx, cancel, &wg, "DeleteDevice") //wait for background process to finish
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001243
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001244 // TODO: further actions - stop metrics and FSMs, remove device ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001245 return pDevEntry.GetKvProcessingErrorIndication()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001246}
1247
mpagenko15ff4a52021-03-02 10:09:20 +00001248//func (dh *deviceHandler) rebootDevice(ctx context.Context, device *voltha.Device) error {
1249// before this change here return like this was used:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001250// return fmt.Errorf("device-unreachable: %s, %s", dh.DeviceID, device.SerialNumber)
mpagenko15ff4a52021-03-02 10:09:20 +00001251//was and is called in background - error return does not make sense
1252func (dh *deviceHandler) rebootDevice(ctx context.Context, aCheckDeviceState bool, device *voltha.Device) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001253 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": dh.DeviceID, "SerialNumber": dh.device.SerialNumber})
mpagenko15ff4a52021-03-02 10:09:20 +00001254 if aCheckDeviceState && device.ConnectStatus != voltha.ConnectStatus_REACHABLE {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001255 logger.Errorw(ctx, "device-unreachable", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber})
mpagenko15ff4a52021-03-02 10:09:20 +00001256 return
ozgecanetsiae11479f2020-07-06 09:44:47 +03001257 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001258 if err := dh.pOnuOmciDevice.Reboot(log.WithSpanFromContext(context.TODO(), ctx)); err != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301259 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001260 logger.Errorw(ctx, "error-rebooting-device", log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko15ff4a52021-03-02 10:09:20 +00001261 return
Himani Chawla4d908332020-08-31 12:30:20 +05301262 }
mpagenko01e726e2020-10-23 09:45:29 +00001263
1264 //transfer the possibly modified logical uni port state
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001265 dh.DisableUniPortStateUpdate(ctx)
mpagenko01e726e2020-10-23 09:45:29 +00001266
mpagenko44bd8362021-11-15 11:40:05 +00001267 logger.Debugw(ctx, "call DeviceStateUpdate upon reboot", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001268 "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID})
mpagenko44bd8362021-11-15 11:40:05 +00001269 // do not set the ConnStatus here as it may conflict with the parallel setting from ONU down indication (updateInterface())
khenaidoo42dcdfd2021-10-19 17:34:12 -04001270 if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001271 DeviceId: dh.DeviceID,
mpagenko44bd8362021-11-15 11:40:05 +00001272 ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus
khenaidoo7d3c5582021-08-11 18:09:44 -04001273 OperStatus: voltha.OperStatus_DISCOVERED,
1274 }); err != nil {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001275 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001276 logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko15ff4a52021-03-02 10:09:20 +00001277 return
ozgecanetsiae11479f2020-07-06 09:44:47 +03001278 }
mpagenkoe4782082021-11-25 12:04:26 +00001279 if err := dh.ReasonUpdate(ctx, cmn.DrRebooting, true); err != nil {
mpagenko15ff4a52021-03-02 10:09:20 +00001280 return
ozgecanetsiae11479f2020-07-06 09:44:47 +03001281 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001282 dh.SetReadyForOmciConfig(false)
mpagenko8b07c1b2020-11-26 10:36:31 +00001283 //no specific activity to synchronize any internal FSM to the 'rebooted' state is explicitly done here
1284 // the expectation ids for a real device, that it will be synced with the expected following 'down' indication
1285 // as BBSIM does not support this testing requires explicite disable/enable device calls in which sequence also
1286 // all other FSM's should be synchronized again
ozgecanetsiae11479f2020-07-06 09:44:47 +03001287}
1288
mpagenkoc8bba412021-01-15 15:38:44 +00001289//doOnuSwUpgrade initiates the SW download transfer to the ONU and on success activates the (inactive) image
mpagenko38662d02021-08-11 09:45:19 +00001290// used only for old - R2.7 style - upgrade API
mpagenko80622a52021-02-09 16:53:23 +00001291func (dh *deviceHandler) doOnuSwUpgrade(ctx context.Context, apImageDsc *voltha.ImageDownload,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001292 apDownloadManager *swupg.AdapterDownloadManager) error {
mpagenko80622a52021-02-09 16:53:23 +00001293 logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001294 "device-id": dh.DeviceID, "image-name": (*apImageDsc).Name})
mpagenko80622a52021-02-09 16:53:23 +00001295
1296 var err error
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001297 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
mpagenko15ff4a52021-03-02 10:09:20 +00001298 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001299 logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
1300 return fmt.Errorf("start Onu SW upgrade rejected: no valid OnuDevice for device-id: %s", dh.DeviceID)
mpagenko15ff4a52021-03-02 10:09:20 +00001301 }
1302
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001303 if dh.IsReadyForOmciConfig() {
mpagenko15ff4a52021-03-02 10:09:20 +00001304 var inactiveImageID uint16
1305 if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil {
1306 dh.lockUpgradeFsm.Lock()
mpagenko59862f02021-10-11 08:53:18 +00001307 //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm()
1308 // but must be still locked at calling createOnuUpgradeFsm
mpagenko15ff4a52021-03-02 10:09:20 +00001309 if dh.pOnuUpradeFsm == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001310 err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone)
mpagenko59862f02021-10-11 08:53:18 +00001311 dh.lockUpgradeFsm.Unlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001312 if err == nil {
1313 if err = dh.pOnuUpradeFsm.SetDownloadParams(ctx, inactiveImageID, apImageDsc, apDownloadManager); err != nil {
1314 logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001315 "device-id": dh.DeviceID, "error": err})
mpagenko15ff4a52021-03-02 10:09:20 +00001316 }
1317 } else {
1318 logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001319 "device-id": dh.DeviceID, "error": err})
mpagenko80622a52021-02-09 16:53:23 +00001320 }
mpagenko15ff4a52021-03-02 10:09:20 +00001321 } else { //OnuSw upgrade already running - restart (with possible abort of running)
mpagenko59862f02021-10-11 08:53:18 +00001322 dh.lockUpgradeFsm.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001323 logger.Debugw(ctx, "Onu SW upgrade already running - abort", log.Fields{"device-id": dh.DeviceID})
mpagenko59862f02021-10-11 08:53:18 +00001324 if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation
1325 dh.upgradeCanceled = true
1326 dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort
1327 }
mpagenko38662d02021-08-11 09:45:19 +00001328 //no effort spent anymore for the old API to automatically cancel and restart the download
1329 // like done for the new API
mpagenko80622a52021-02-09 16:53:23 +00001330 }
mpagenko15ff4a52021-03-02 10:09:20 +00001331 } else {
1332 logger.Errorw(ctx, "start Onu SW upgrade rejected: no inactive image", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001333 "device-id": dh.DeviceID, "error": err})
mpagenko80622a52021-02-09 16:53:23 +00001334 }
1335 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001336 logger.Errorw(ctx, "start Onu SW upgrade rejected: no active OMCI connection", log.Fields{"device-id": dh.DeviceID})
1337 err = fmt.Errorf("start Onu SW upgrade rejected: no active OMCI connection for device-id: %s", dh.DeviceID)
mpagenko80622a52021-02-09 16:53:23 +00001338 }
1339 return err
mpagenkoc8bba412021-01-15 15:38:44 +00001340}
1341
mpagenkoc26d4c02021-05-06 14:27:57 +00001342//onuSwUpgradeAfterDownload initiates the SW download transfer to the ONU with activate and commit options
1343// after the OnuImage has been downloaded to the adapter, called in background
1344func (dh *deviceHandler) onuSwUpgradeAfterDownload(ctx context.Context, apImageRequest *voltha.DeviceImageDownloadRequest,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001345 apDownloadManager *swupg.FileDownloadManager, aImageIdentifier string) {
mpagenkoc26d4c02021-05-06 14:27:57 +00001346
1347 var err error
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001348 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
mpagenkoc26d4c02021-05-06 14:27:57 +00001349 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001350 logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
mpagenkoc26d4c02021-05-06 14:27:57 +00001351 return
1352 }
1353
1354 var inactiveImageID uint16
1355 if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil {
1356 logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001357 "device-id": dh.DeviceID, "image-version": apImageRequest.Image.Version, "to onu-image": inactiveImageID})
mpagenko38662d02021-08-11 09:45:19 +00001358
mpagenko59862f02021-10-11 08:53:18 +00001359 dh.lockUpgradeFsm.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001360 //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm()
mpagenko59862f02021-10-11 08:53:18 +00001361 // but must be still locked at calling createOnuUpgradeFsm
1362 // (and working with a local pointer copy does not work here if asynchronous request are done to fast
1363 // [e.g.leaving the local pointer on nil even though a creation is already on the way])
1364 if dh.pOnuUpradeFsm != nil {
mpagenko38662d02021-08-11 09:45:19 +00001365 //OnuSw upgrade already running on this device (e.g. with activate/commit not yet set)
1366 // abort the current processing, running upgrades are always aborted by newer request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001367 logger.Debugw(ctx, "Onu SW upgrade already running - abort previous activity", log.Fields{"device-id": dh.DeviceID})
mpagenko38662d02021-08-11 09:45:19 +00001368 //flush the remove upgradeFsmChan channel
1369 select {
1370 case <-dh.upgradeFsmChan:
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001371 logger.Debugw(ctx, "flushed-upgrade-fsm-channel", log.Fields{"device-id": dh.DeviceID})
mpagenko38662d02021-08-11 09:45:19 +00001372 default:
mpagenkoc26d4c02021-05-06 14:27:57 +00001373 }
mpagenko59862f02021-10-11 08:53:18 +00001374 dh.lockUpgradeFsm.Unlock()
1375 if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation
1376 dh.upgradeCanceled = true
1377 dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort
1378 }
mpagenko38662d02021-08-11 09:45:19 +00001379 select {
1380 case <-time.After(cTimeOutRemoveUpgrade * time.Second):
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001381 logger.Errorw(ctx, "could not remove Upgrade FSM in time, aborting", log.Fields{"device-id": dh.DeviceID})
mpagenko38662d02021-08-11 09:45:19 +00001382 //should not appear, can't proceed with new upgrade, perhaps operator can retry manually later
1383 return
1384 case <-dh.upgradeFsmChan:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001385 logger.Debugw(ctx, "recent Upgrade FSM removed, proceed with new request", log.Fields{"device-id": dh.DeviceID})
mpagenko38662d02021-08-11 09:45:19 +00001386 }
mpagenko59862f02021-10-11 08:53:18 +00001387 dh.lockUpgradeFsm.Lock() //lock again for following creation
mpagenkoc26d4c02021-05-06 14:27:57 +00001388 }
mpagenko38662d02021-08-11 09:45:19 +00001389
1390 //here it can be assumed that no running upgrade processing exists (anymore)
mpagenko59862f02021-10-11 08:53:18 +00001391 //OmciOnuSwUpgradeDone could be used to create some event notification with information on upgrade completion,
mpagenko38662d02021-08-11 09:45:19 +00001392 // but none yet defined
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001393 err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone)
mpagenko59862f02021-10-11 08:53:18 +00001394 dh.lockUpgradeFsm.Unlock()
mpagenko38662d02021-08-11 09:45:19 +00001395 if err == nil {
1396 if err = dh.pOnuUpradeFsm.SetDownloadParamsAfterDownload(ctx, inactiveImageID,
1397 apImageRequest, apDownloadManager, aImageIdentifier); err != nil {
1398 logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001399 "device-id": dh.DeviceID, "error": err})
mpagenkoc26d4c02021-05-06 14:27:57 +00001400 return
1401 }
mpagenko38662d02021-08-11 09:45:19 +00001402 } else {
1403 logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001404 "device-id": dh.DeviceID, "error": err})
mpagenkoc26d4c02021-05-06 14:27:57 +00001405 }
1406 return
1407 }
1408 logger.Errorw(ctx, "start Onu SW upgrade rejected: no inactive image", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001409 "device-id": dh.DeviceID, "error": err})
mpagenkoc26d4c02021-05-06 14:27:57 +00001410}
1411
1412//onuSwActivateRequest ensures activation of the requested image with commit options
mpagenko183647c2021-06-08 15:25:04 +00001413func (dh *deviceHandler) onuSwActivateRequest(ctx context.Context,
1414 aVersion string, aCommitRequest bool) (*voltha.ImageState, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +00001415 var err error
1416 //SW activation for the ONU image may have two use cases, one of them is selected here according to following prioritization:
1417 // 1.) activation of the image for a started upgrade process (in case the running upgrade runs on the requested image)
1418 // 2.) activation of the inactive image
1419
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001420 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
mpagenkoc26d4c02021-05-06 14:27:57 +00001421 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001422 logger.Errorw(ctx, "Onu image activation rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
1423 return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001424 }
1425 dh.lockUpgradeFsm.RLock()
1426 if dh.pOnuUpradeFsm != nil {
1427 dh.lockUpgradeFsm.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001428 onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001429 if getErr != nil || onuVolthaDevice == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001430 logger.Errorw(ctx, "Failed to fetch Onu device for image activation", log.Fields{"device-id": dh.DeviceID, "err": getErr})
1431 return nil, fmt.Errorf("could not fetch device for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001432 }
mpagenko59862f02021-10-11 08:53:18 +00001433 if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation
1434 logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID})
1435 return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID)
1436 }
mpagenkoc26d4c02021-05-06 14:27:57 +00001437 // use the OnuVendor identification from this device for the internal unique name
1438 imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU
mpagenko38662d02021-08-11 09:45:19 +00001439 // 1.) check a started upgrade process and relay the activation request to it
mpagenkoc26d4c02021-05-06 14:27:57 +00001440 if err = dh.pOnuUpradeFsm.SetActivationParamsRunning(ctx, imageIdentifier, aCommitRequest); err != nil {
mpagenko183647c2021-06-08 15:25:04 +00001441 //if some ONU upgrade is ongoing we do not accept some explicit ONU image-version related activation
mpagenkoc26d4c02021-05-06 14:27:57 +00001442 logger.Errorw(ctx, "onu upgrade fsm did not accept activation while running", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001443 "device-id": dh.DeviceID, "error": err})
1444 return nil, fmt.Errorf("activation not accepted for this version for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001445 }
mpagenko183647c2021-06-08 15:25:04 +00001446 logger.Debugw(ctx, "image activation acknowledged by onu upgrade processing", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001447 "device-id": dh.DeviceID, "image-id": imageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +00001448 pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion)
mpagenko183647c2021-06-08 15:25:04 +00001449 return pImageStates, nil
mpagenkoc26d4c02021-05-06 14:27:57 +00001450 } //else
1451 dh.lockUpgradeFsm.RUnlock()
1452
1453 // 2.) check if requested image-version equals the inactive one and start its activation
1454 // (image version is not [yet] checked - would be possible, but with increased effort ...)
1455 var inactiveImageID uint16
1456 if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err != nil || inactiveImageID > 1 {
1457 logger.Errorw(ctx, "get inactive image failed", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001458 "device-id": dh.DeviceID, "err": err, "image-id": inactiveImageID})
1459 return nil, fmt.Errorf("no valid inactive image found for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001460 }
mpagenkoa2b288f2021-10-21 11:25:27 +00001461 dh.lockUpgradeFsm.Lock() //lock again for following creation
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001462 err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone)
mpagenkoa2b288f2021-10-21 11:25:27 +00001463 dh.lockUpgradeFsm.Unlock()
mpagenkoc26d4c02021-05-06 14:27:57 +00001464 if err == nil {
1465 if err = dh.pOnuUpradeFsm.SetActivationParamsStart(ctx, aVersion,
1466 inactiveImageID, aCommitRequest); err != nil {
1467 logger.Errorw(ctx, "onu upgrade fsm did not accept activation to start", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001468 "device-id": dh.DeviceID, "error": err})
1469 return nil, fmt.Errorf("activation to start from scratch not accepted for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001470 }
1471 logger.Debugw(ctx, "inactive image activation acknowledged by onu upgrade", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001472 "device-id": dh.DeviceID, "image-version": aVersion})
mpagenko38662d02021-08-11 09:45:19 +00001473 pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion)
mpagenko183647c2021-06-08 15:25:04 +00001474 return pImageStates, nil
mpagenkoc26d4c02021-05-06 14:27:57 +00001475 } //else
1476 logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001477 "device-id": dh.DeviceID, "error": err})
1478 return nil, fmt.Errorf("could not start upgradeFsm for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001479}
1480
1481//onuSwCommitRequest ensures commitment of the requested image
mpagenko183647c2021-06-08 15:25:04 +00001482func (dh *deviceHandler) onuSwCommitRequest(ctx context.Context,
1483 aVersion string) (*voltha.ImageState, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +00001484 var err error
1485 //SW commitment for the ONU image may have two use cases, one of them is selected here according to following prioritization:
1486 // 1.) commitment of the image for a started upgrade process (in case the running upgrade runs on the requested image)
1487 // 2.) commitment of the active image
1488
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001489 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
mpagenkoc26d4c02021-05-06 14:27:57 +00001490 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001491 logger.Errorw(ctx, "Onu image commitment rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
1492 return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001493 }
1494 dh.lockUpgradeFsm.RLock()
1495 if dh.pOnuUpradeFsm != nil {
1496 dh.lockUpgradeFsm.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001497 onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001498 if getErr != nil || onuVolthaDevice == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001499 logger.Errorw(ctx, "Failed to fetch Onu device for image commitment", log.Fields{"device-id": dh.DeviceID, "err": getErr})
1500 return nil, fmt.Errorf("could not fetch device for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001501 }
mpagenko59862f02021-10-11 08:53:18 +00001502 if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation
1503 logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID})
1504 return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID)
1505 }
mpagenkoc26d4c02021-05-06 14:27:57 +00001506 // use the OnuVendor identification from this device for the internal unique name
1507 imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU
mpagenko38662d02021-08-11 09:45:19 +00001508 // 1.) check a started upgrade process and relay the commitment request to it
1509 // the running upgrade may be based either on the imageIdentifier (started from download)
1510 // or on the imageVersion (started from pure activation)
1511 if err = dh.pOnuUpradeFsm.SetCommitmentParamsRunning(ctx, imageIdentifier, aVersion); err != nil {
1512 //if some ONU upgrade is ongoing we do not accept some explicit different ONU image-version related commitment
mpagenkoc26d4c02021-05-06 14:27:57 +00001513 logger.Errorw(ctx, "onu upgrade fsm did not accept commitment while running", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001514 "device-id": dh.DeviceID, "error": err})
1515 return nil, fmt.Errorf("commitment not accepted for this version for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001516 }
mpagenko183647c2021-06-08 15:25:04 +00001517 logger.Debugw(ctx, "image commitment acknowledged by onu upgrade processing", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001518 "device-id": dh.DeviceID, "image-id": imageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +00001519 pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion)
mpagenko183647c2021-06-08 15:25:04 +00001520 return pImageStates, nil
mpagenkoc26d4c02021-05-06 14:27:57 +00001521 } //else
1522 dh.lockUpgradeFsm.RUnlock()
1523
mpagenko183647c2021-06-08 15:25:04 +00001524 // 2.) use the active image to directly commit
mpagenkoc26d4c02021-05-06 14:27:57 +00001525 var activeImageID uint16
1526 if activeImageID, err = pDevEntry.GetActiveImageMeID(ctx); err != nil || activeImageID > 1 {
1527 logger.Errorw(ctx, "get active image failed", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001528 "device-id": dh.DeviceID, "err": err, "image-id": activeImageID})
1529 return nil, fmt.Errorf("no valid active image found for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001530 }
mpagenkoa2b288f2021-10-21 11:25:27 +00001531 dh.lockUpgradeFsm.Lock() //lock again for following creation
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001532 err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone)
mpagenkoa2b288f2021-10-21 11:25:27 +00001533 dh.lockUpgradeFsm.Unlock()
mpagenkoc26d4c02021-05-06 14:27:57 +00001534 if err == nil {
1535 if err = dh.pOnuUpradeFsm.SetCommitmentParamsStart(ctx, aVersion, activeImageID); err != nil {
1536 logger.Errorw(ctx, "onu upgrade fsm did not accept commitment to start", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001537 "device-id": dh.DeviceID, "error": err})
1538 return nil, fmt.Errorf("commitment to start from scratch not accepted for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001539 }
1540 logger.Debugw(ctx, "active image commitment acknowledged by onu upgrade", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001541 "device-id": dh.DeviceID, "image-version": aVersion})
mpagenko38662d02021-08-11 09:45:19 +00001542 pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion)
mpagenko183647c2021-06-08 15:25:04 +00001543 return pImageStates, nil
mpagenkoc26d4c02021-05-06 14:27:57 +00001544 } //else
1545 logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001546 "device-id": dh.DeviceID, "error": err})
1547 return nil, fmt.Errorf("could not start upgradeFsm for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001548}
1549
mpagenkoaa3afe92021-05-21 16:20:58 +00001550func (dh *deviceHandler) requestOnuSwUpgradeState(ctx context.Context, aImageIdentifier string,
mpagenko38662d02021-08-11 09:45:19 +00001551 aVersion string) *voltha.ImageState {
1552 var pImageState *voltha.ImageState
mpagenkoaa3afe92021-05-21 16:20:58 +00001553 dh.lockUpgradeFsm.RLock()
mpagenko38662d02021-08-11 09:45:19 +00001554 defer dh.lockUpgradeFsm.RUnlock()
mpagenkoaa3afe92021-05-21 16:20:58 +00001555 if dh.pOnuUpradeFsm != nil {
mpagenko38662d02021-08-11 09:45:19 +00001556 pImageState = dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion)
1557 } else { //use the last stored ImageState (if the requested Imageversion coincides)
1558 if aVersion == dh.pLastUpgradeImageState.Version {
1559 pImageState = dh.pLastUpgradeImageState
1560 } else { //state request for an image version different from last processed image version
1561 pImageState = &voltha.ImageState{
1562 Version: aVersion,
1563 //we cannot state something concerning this version
1564 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN,
1565 Reason: voltha.ImageState_NO_ERROR,
1566 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
1567 }
mpagenkoaa3afe92021-05-21 16:20:58 +00001568 }
1569 }
mpagenko38662d02021-08-11 09:45:19 +00001570 return pImageState
mpagenkoaa3afe92021-05-21 16:20:58 +00001571}
1572
1573func (dh *deviceHandler) cancelOnuSwUpgrade(ctx context.Context, aImageIdentifier string,
1574 aVersion string, pDeviceImageState *voltha.DeviceImageState) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001575 pDeviceImageState.DeviceId = dh.DeviceID
mpagenko7455fd42021-06-10 16:25:55 +00001576 pDeviceImageState.ImageState.Version = aVersion
mpagenkoaa3afe92021-05-21 16:20:58 +00001577 dh.lockUpgradeFsm.RLock()
1578 if dh.pOnuUpradeFsm != nil {
mpagenko45586762021-10-01 08:30:22 +00001579 dh.lockUpgradeFsm.RUnlock()
1580 // so then we cancel the upgrade operation
mpagenkoa2b288f2021-10-21 11:25:27 +00001581 // but before we still request the actual upgrade states for the direct response
mpagenko45586762021-10-01 08:30:22 +00001582 pImageState := dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion)
1583 pDeviceImageState.ImageState.DownloadState = pImageState.DownloadState
1584 pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST
1585 pDeviceImageState.ImageState.ImageState = pImageState.ImageState
1586 if pImageState.DownloadState != voltha.ImageState_DOWNLOAD_UNKNOWN {
1587 //so here the imageIdentifier or version equals to what is used in the upgrade FSM
mpagenko59862f02021-10-11 08:53:18 +00001588 if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation
1589 dh.upgradeCanceled = true
1590 dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort
1591 }
mpagenko45586762021-10-01 08:30:22 +00001592 } //nothing to cancel (upgrade FSM for different image stays alive)
mpagenkoaa3afe92021-05-21 16:20:58 +00001593 } else {
mpagenko45586762021-10-01 08:30:22 +00001594 dh.lockUpgradeFsm.RUnlock()
mpagenko38662d02021-08-11 09:45:19 +00001595 // if no upgrade is ongoing, nothing is canceled and accordingly the states of the requested image are unknown
1596 // reset also the dh handler LastUpgradeImageState (not relevant anymore/cleared)
1597 (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
1598 (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR
1599 (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN
1600 (*dh.pLastUpgradeImageState).Version = "" //reset to 'no (relevant) upgrade done' (like initial state)
mpagenkoaa3afe92021-05-21 16:20:58 +00001601 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
1602 pDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR
mpagenko38662d02021-08-11 09:45:19 +00001603 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
1604 //an abort request to a not active upgrade processing can be used to reset the device upgrade states completely
mpagenkoaa3afe92021-05-21 16:20:58 +00001605 }
1606}
1607
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00001608func (dh *deviceHandler) getOnuImages(ctx context.Context) (*voltha.OnuImages, error) {
1609
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001610 var onuImageStatus *swupg.OnuImageStatus
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00001611
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001612 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00001613 if pDevEntry != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001614 onuImageStatus = swupg.NewOnuImageStatus(dh, pDevEntry)
1615 pDevEntry.MutexOnuImageStatus.Lock()
1616 pDevEntry.POnuImageStatus = onuImageStatus
1617 pDevEntry.MutexOnuImageStatus.Unlock()
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00001618
1619 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001620 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00001621 return nil, fmt.Errorf("no-valid-OnuDevice-aborting")
1622 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001623 images, err := onuImageStatus.GetOnuImageStatus(ctx)
1624 pDevEntry.MutexOnuImageStatus.Lock()
1625 pDevEntry.POnuImageStatus = nil
1626 pDevEntry.MutexOnuImageStatus.Unlock()
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00001627 return images, err
1628}
1629
Himani Chawla6d2ae152020-09-02 13:11:20 +05301630// deviceHandler methods that implement the adapters interface requests## end #########
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001631// #####################################################################################
1632
1633// ################ to be updated acc. needs of ONU Device ########################
Himani Chawla6d2ae152020-09-02 13:11:20 +05301634// deviceHandler StateMachine related state transition methods ##### begin #########
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001635
dbainbri4d3a0dc2020-12-02 00:33:42 +00001636func (dh *deviceHandler) logStateChange(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001637 logger.Debugw(ctx, "Device FSM: ", log.Fields{"event name": string(e.Event),
1638 "src state": string(e.Src), "dst state": string(e.Dst), "device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001639}
1640
1641// doStateInit provides the device update to the core
dbainbri4d3a0dc2020-12-02 00:33:42 +00001642func (dh *deviceHandler) doStateInit(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001643
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001644 logger.Debugw(ctx, "doStateInit-started", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001645 var err error
1646
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001647 // populate what we know. rest comes later after mib sync
1648 dh.device.Root = false
1649 dh.device.Vendor = "OpenONU"
1650 dh.device.Model = "go"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001651 dh.device.Reason = cmn.DeviceReasonMap[cmn.DrActivatingOnu]
mpagenkoe4782082021-11-25 12:04:26 +00001652 _ = dh.ReasonUpdate(ctx, cmn.DrActivatingOnu, false)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001653
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001654 dh.logicalDeviceID = dh.DeviceID // really needed - what for ??? //TODO!!!
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001655
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001656 if !dh.IsReconciling() {
1657 logger.Infow(ctx, "DeviceUpdate", log.Fields{"deviceReason": dh.device.Reason, "device-id": dh.DeviceID})
khenaidoo7d3c5582021-08-11 18:09:44 -04001658 if err := dh.updateDeviceInCore(ctx, dh.device); err != nil {
1659 logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err})
1660 }
Himani Chawlac07fda02020-12-09 16:21:21 +05301661 //TODO Need to Update Device Reason To CORE as part of device update userstory
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001662 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001663 logger.Debugw(ctx, "reconciling - don't notify core about DeviceUpdate",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001664 log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001665 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001666
Himani Chawla4d908332020-08-31 12:30:20 +05301667 dh.parentID = dh.device.ParentId
Holger Hildebrandt24d51952020-05-04 14:03:42 +00001668 dh.ponPortNumber = dh.device.ParentPortNo
1669
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001670 // store proxy parameters for later communication - assumption: invariant, else they have to be requested dynamically!!
1671 dh.ProxyAddressID = dh.device.ProxyAddress.GetDeviceId()
1672 dh.ProxyAddressType = dh.device.ProxyAddress.GetDeviceType()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001673 logger.Debugw(ctx, "device-updated", log.Fields{"device-id": dh.DeviceID, "proxyAddressID": dh.ProxyAddressID,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001674 "proxyAddressType": dh.ProxyAddressType, "SNR": dh.device.SerialNumber,
Himani Chawla4d908332020-08-31 12:30:20 +05301675 "ParentId": dh.parentID, "ParentPortNo": dh.ponPortNumber})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001676
1677 /*
1678 self._pon = PonPort.create(self, self._pon_port_number)
1679 self._pon.add_peer(self.parent_id, self._pon_port_number)
1680 self.logger.debug('adding-pon-port-to-agent',
1681 type=self._pon.get_port().type,
1682 admin_state=self._pon.get_port().admin_state,
1683 oper_status=self._pon.get_port().oper_status,
1684 )
1685 */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001686 if !dh.IsReconciling() {
1687 logger.Debugw(ctx, "adding-pon-port", log.Fields{"device-id": dh.DeviceID, "ponPortNo": dh.ponPortNumber})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001688 var ponPortNo uint32 = 1
1689 if dh.ponPortNumber != 0 {
1690 ponPortNo = dh.ponPortNumber
1691 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001692
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001693 pPonPort := &voltha.Port{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001694 DeviceId: dh.DeviceID,
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001695 PortNo: ponPortNo,
1696 Label: fmt.Sprintf("pon-%d", ponPortNo),
1697 Type: voltha.Port_PON_ONU,
1698 OperStatus: voltha.OperStatus_ACTIVE,
Himani Chawla4d908332020-08-31 12:30:20 +05301699 Peers: []*voltha.Port_PeerPort{{DeviceId: dh.parentID, // Peer device is OLT
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001700 PortNo: ponPortNo}}, // Peer port is parent's port number
1701 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001702 if err = dh.CreatePortInCore(ctx, pPonPort); err != nil {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001703 logger.Fatalf(ctx, "Device FSM: PortCreated-failed-%s:%s", err, dh.DeviceID)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001704 e.Cancel(err)
1705 return
1706 }
1707 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001708 logger.Debugw(ctx, "reconciling - pon-port already added", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001709 }
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001710 logger.Debugw(ctx, "doStateInit-done", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001711}
1712
1713// postInit setups the DeviceEntry for the conerned device
dbainbri4d3a0dc2020-12-02 00:33:42 +00001714func (dh *deviceHandler) postInit(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001715
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001716 logger.Debugw(ctx, "postInit-started", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001717 var err error
1718 /*
1719 dh.Client = oop.NewOpenoltClient(dh.clientCon)
1720 dh.pTransitionMap.Handle(ctx, GrpcConnected)
1721 return nil
1722 */
dbainbri4d3a0dc2020-12-02 00:33:42 +00001723 if err = dh.addOnuDeviceEntry(log.WithSpanFromContext(context.TODO(), ctx)); err != nil {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001724 logger.Fatalf(ctx, "Device FSM: addOnuDeviceEntry-failed-%s:%s", err, dh.DeviceID)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001725 e.Cancel(err)
1726 return
1727 }
1728
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001729 if dh.IsReconciling() {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001730 go dh.reconcileDeviceOnuInd(ctx)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001731 // reconcilement will be continued after mib download is done
1732 }
Girish Gowdrae09a6202021-01-12 18:10:59 -08001733
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001734 /*
1735 ############################################################################
1736 # Setup Alarm handler
1737 self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id,
1738 device.serial_number)
1739 ############################################################################
1740 # Setup PM configuration for this device
1741 # Pass in ONU specific options
1742 kwargs = {
1743 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
1744 'heartbeat': self.heartbeat,
1745 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
1746 }
1747 self.logger.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number)
1748 self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
1749 self.logical_device_id, device.serial_number,
1750 grouped=True, freq_override=False, **kwargs)
1751 pm_config = self._pm_metrics.make_proto()
1752 self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm)
1753 self.logger.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number)
1754 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
1755
1756 # Note, ONU ID and UNI intf set in add_uni_port method
1757 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
1758 ani_ports=[self._pon])
1759
1760 # Code to Run OMCI Test Action
1761 kwargs_omci_test_action = {
1762 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
1763 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
1764 }
1765 serial_number = device.serial_number
1766 self._test_request = OmciTestRequest(self.core_proxy,
1767 self.omci_agent, self.device_id,
1768 AniG, serial_number,
1769 self.logical_device_id,
1770 exclusive=False,
1771 **kwargs_omci_test_action)
1772
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001773 self.Enabled = True
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001774 else:
1775 self.logger.info('onu-already-activated')
1776 */
Girish Gowdrae09a6202021-01-12 18:10:59 -08001777
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001778 logger.Debugw(ctx, "postInit-done", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001779}
1780
1781// doStateConnected get the device info and update to voltha core
1782// for comparison of the original method (not that easy to uncomment): compare here:
1783// voltha-openolt-adapter/adaptercore/device_handler.go
1784// -> this one obviously initiates all communication interfaces of the device ...?
dbainbri4d3a0dc2020-12-02 00:33:42 +00001785func (dh *deviceHandler) doStateConnected(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001786
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001787 logger.Debugw(ctx, "doStateConnected-started", log.Fields{"device-id": dh.DeviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301788 err := errors.New("device FSM: function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001789 e.Cancel(err)
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001790 logger.Debugw(ctx, "doStateConnected-done", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001791}
1792
1793// doStateUp handle the onu up indication and update to voltha core
dbainbri4d3a0dc2020-12-02 00:33:42 +00001794func (dh *deviceHandler) doStateUp(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001795
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001796 logger.Debugw(ctx, "doStateUp-started", log.Fields{"device-id": dh.DeviceID})
Himani Chawla4d908332020-08-31 12:30:20 +05301797 err := errors.New("device FSM: function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001798 e.Cancel(err)
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001799 logger.Debugw(ctx, "doStateUp-done", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001800
1801 /*
1802 // Synchronous call to update device state - this method is run in its own go routine
1803 if err := dh.coreProxy.DeviceStateUpdate(ctx, dh.device.Id, voltha.ConnectStatus_REACHABLE,
1804 voltha.OperStatus_ACTIVE); err != nil {
mpagenko01e726e2020-10-23 09:45:29 +00001805 logger.Errorw("Failed to update device with OLT UP indication", log.Fields{"device-id": dh.device.Id, "error": err})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001806 return err
1807 }
1808 return nil
1809 */
1810}
1811
1812// doStateDown handle the onu down indication
dbainbri4d3a0dc2020-12-02 00:33:42 +00001813func (dh *deviceHandler) doStateDown(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001814
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001815 logger.Debugw(ctx, "doStateDown-started", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001816 var err error
1817
Holger Hildebrandt24d51952020-05-04 14:03:42 +00001818 device := dh.device
1819 if device == nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001820 /*TODO: needs to handle error scenarios */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001821 logger.Errorw(ctx, "Failed to fetch handler device", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001822 e.Cancel(err)
1823 return
1824 }
1825
1826 cloned := proto.Clone(device).(*voltha.Device)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001827 logger.Debugw(ctx, "do-state-down", log.Fields{"ClonedDeviceID": cloned.Id})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001828 /*
1829 // Update the all ports state on that device to disable
1830 if er := dh.coreProxy.PortsStateUpdate(ctx, cloned.Id, voltha.OperStatus_UNKNOWN); er != nil {
mpagenko01e726e2020-10-23 09:45:29 +00001831 logger.Errorw("updating-ports-failed", log.Fields{"device-id": device.Id, "error": er})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001832 return er
1833 }
1834
1835 //Update the device oper state and connection status
1836 cloned.OperStatus = voltha.OperStatus_UNKNOWN
1837 cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE
1838 dh.device = cloned
1839
1840 if er := dh.coreProxy.DeviceStateUpdate(ctx, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); er != nil {
mpagenko01e726e2020-10-23 09:45:29 +00001841 logger.Errorw("error-updating-device-state", log.Fields{"device-id": device.Id, "error": er})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001842 return er
1843 }
1844
1845 //get the child device for the parent device
1846 onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id)
1847 if err != nil {
mpagenko01e726e2020-10-23 09:45:29 +00001848 logger.Errorw("failed to get child devices information", log.Fields{"device-id": dh.device.Id, "error": err})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001849 return err
1850 }
1851 for _, onuDevice := range onuDevices.Items {
1852
1853 // Update onu state as down in onu adapter
1854 onuInd := oop.OnuIndication{}
1855 onuInd.OperState = "down"
khenaidoo42dcdfd2021-10-19 17:34:12 -04001856 er := dh.adapterProxy.SendInterAdapterMessage(ctx, &onuInd, ca.InterAdapterMessageType_ONU_IND_REQUEST,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001857 "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "")
1858 if er != nil {
1859 logger.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd,
mpagenko01e726e2020-10-23 09:45:29 +00001860 "From Adapter": "openolt", "DevieType": onuDevice.Type, "device-id": onuDevice.Id})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001861 //Do not return here and continue to process other ONUs
1862 }
1863 }
1864 // * Discovered ONUs entries need to be cleared , since after OLT
1865 // is up, it starts sending discovery indications again* /
1866 dh.discOnus = sync.Map{}
mpagenko01e726e2020-10-23 09:45:29 +00001867 logger.Debugw("do-state-down-end", log.Fields{"device-id": device.Id})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001868 return nil
1869 */
Himani Chawla4d908332020-08-31 12:30:20 +05301870 err = errors.New("device FSM: function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001871 e.Cancel(err)
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001872 logger.Debugw(ctx, "doStateDown-done", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001873}
1874
Himani Chawla6d2ae152020-09-02 13:11:20 +05301875// deviceHandler StateMachine related state transition methods ##### end #########
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001876// #################################################################################
1877
1878// ###################################################
Himani Chawla6d2ae152020-09-02 13:11:20 +05301879// deviceHandler utility methods ##### begin #########
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001880
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001881//GetOnuDeviceEntry gets the ONU device entry and may wait until its value is defined
1882func (dh *deviceHandler) GetOnuDeviceEntry(ctx context.Context, aWait bool) *mib.OnuDeviceEntry {
mpagenko3af1f032020-06-10 08:53:41 +00001883 dh.lockDevice.RLock()
1884 pOnuDeviceEntry := dh.pOnuOmciDevice
1885 if aWait && pOnuDeviceEntry == nil {
1886 //keep the read sema short to allow for subsequent write
1887 dh.lockDevice.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001888 logger.Debugw(ctx, "Waiting for DeviceEntry to be set ...", log.Fields{"device-id": dh.DeviceID})
mpagenko3af1f032020-06-10 08:53:41 +00001889 // based on concurrent processing the deviceEntry setup may not yet be finished at his point
1890 // so it might be needed to wait here for that event with some timeout
1891 select {
1892 case <-time.After(60 * time.Second): //timer may be discussed ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001893 logger.Errorw(ctx, "No valid DeviceEntry set after maxTime", log.Fields{"device-id": dh.DeviceID})
mpagenko3af1f032020-06-10 08:53:41 +00001894 return nil
1895 case <-dh.deviceEntrySet:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001896 logger.Debugw(ctx, "devicEntry ready now - continue", log.Fields{"device-id": dh.DeviceID})
mpagenko3af1f032020-06-10 08:53:41 +00001897 // if written now, we can return the written value without sema
1898 return dh.pOnuOmciDevice
1899 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001900 }
mpagenko3af1f032020-06-10 08:53:41 +00001901 dh.lockDevice.RUnlock()
1902 return pOnuDeviceEntry
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001903}
1904
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001905//setDeviceHandlerEntries sets the ONU device entry within the handler
1906func (dh *deviceHandler) setDeviceHandlerEntries(apDeviceEntry *mib.OnuDeviceEntry, apOnuTp *avcfg.OnuUniTechProf,
1907 apOnuMetricsMgr *pmmgr.OnuMetricsManager, apOnuAlarmMgr *almgr.OnuAlarmManager, apSelfTestHdlr *otst.SelfTestControlBlock) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001908 dh.lockDevice.Lock()
1909 defer dh.lockDevice.Unlock()
mpagenkoaf801632020-07-03 10:00:42 +00001910 dh.pOnuOmciDevice = apDeviceEntry
1911 dh.pOnuTP = apOnuTp
Girish Gowdrae09a6202021-01-12 18:10:59 -08001912 dh.pOnuMetricsMgr = apOnuMetricsMgr
Himani Chawlaac1f5ad2021-02-04 21:21:54 +05301913 dh.pAlarmMgr = apOnuAlarmMgr
Girish Gowdra6afb56a2021-04-27 17:47:57 -07001914 dh.pSelfTestHdlr = apSelfTestHdlr
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001915}
1916
Himani Chawla6d2ae152020-09-02 13:11:20 +05301917//addOnuDeviceEntry creates a new ONU device or returns the existing
1918func (dh *deviceHandler) addOnuDeviceEntry(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001919 logger.Debugw(ctx, "adding-deviceEntry", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001920
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001921 deviceEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001922 if deviceEntry == nil {
1923 /* costum_me_map in python code seems always to be None,
1924 we omit that here first (declaration unclear) -> todo at Adapter specialization ...*/
1925 /* also no 'clock' argument - usage open ...*/
1926 /* and no alarm_db yet (oo.alarm_db) */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001927 deviceEntry = mib.NewOnuDeviceEntry(ctx, dh.coreClient, dh, dh.pOpenOnuAc)
1928 onuTechProfProc := avcfg.NewOnuUniTechProf(ctx, dh, deviceEntry)
1929 onuMetricsMgr := pmmgr.NewOnuMetricsManager(ctx, dh, deviceEntry)
1930 onuAlarmManager := almgr.NewAlarmManager(ctx, dh, deviceEntry)
1931 selfTestHdlr := otst.NewSelfTestMsgHandlerCb(ctx, dh, deviceEntry)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001932 //error treatment possible //TODO!!!
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001933 dh.setDeviceHandlerEntries(deviceEntry, onuTechProfProc, onuMetricsMgr, onuAlarmManager, selfTestHdlr)
mpagenko3af1f032020-06-10 08:53:41 +00001934 // fire deviceEntry ready event to spread to possibly waiting processing
1935 dh.deviceEntrySet <- true
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001936 logger.Debugw(ctx, "onuDeviceEntry-added", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001937 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001938 logger.Debugw(ctx, "onuDeviceEntry-add: Device already exists", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001939 }
1940 // might be updated with some error handling !!!
1941 return nil
1942}
1943
dbainbri4d3a0dc2020-12-02 00:33:42 +00001944func (dh *deviceHandler) createInterface(ctx context.Context, onuind *oop.OnuIndication) error {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00001945 logger.Debugw(ctx, "create_interface-started", log.Fields{"device-id": dh.DeviceID, "OnuId": onuind.GetOnuId(),
Holger Hildebrandt24d51952020-05-04 14:03:42 +00001946 "OnuIntfId": onuind.GetIntfId(), "OnuSerialNumber": onuind.GetSerialNumber()})
1947
1948 dh.pOnuIndication = onuind // let's revise if storing the pointer is sufficient...
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001949
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001950 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001951 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001952 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
1953 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001954 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001955 if !dh.IsReconciling() {
1956 if err := dh.StorePersistentData(ctx); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001957 logger.Warnw(ctx, "store persistent data error - continue as there will be additional write attempts",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001958 log.Fields{"device-id": dh.DeviceID, "err": err})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001959 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001960 logger.Debugw(ctx, "call DeviceStateUpdate upon create interface", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001961 "OperStatus": voltha.OperStatus_ACTIVATING, "device-id": dh.DeviceID})
khenaidoo7d3c5582021-08-11 18:09:44 -04001962
khenaidoo42dcdfd2021-10-19 17:34:12 -04001963 if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001964 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04001965 OperStatus: voltha.OperStatus_ACTIVATING,
1966 ConnStatus: voltha.ConnectStatus_REACHABLE,
1967 }); err != nil {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001968 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001969 logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001970 }
1971 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001972 logger.Debugw(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVATING",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001973 log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001974
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001975 pDevEntry.MutexPersOnuConfig.RLock()
1976 if !pDevEntry.SOnuPersistentData.PersUniUnlockDone {
1977 pDevEntry.MutexPersOnuConfig.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001978 logger.Debugw(ctx, "reconciling - uni-ports were not unlocked before adapter restart - resume with a normal start-up",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001979 log.Fields{"device-id": dh.DeviceID})
mpagenko101ac942021-11-16 15:01:29 +00001980 dh.stopReconciling(ctx, true, cWaitReconcileFlowNoActivity)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001981 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001982 pDevEntry.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001983 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001984 }
Holger Hildebrandt24d51952020-05-04 14:03:42 +00001985 // It does not look to me as if makes sense to work with the real core device here, (not the stored clone)?
1986 // in this code the GetDevice would just make a check if the DeviceID's Device still exists in core
1987 // 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 Hildebrandt4b5e73f2021-08-19 06:51:21 +00001988 // but I would not know why, and the go code anyway does not work with the device directly anymore in the mib.OnuDeviceEntry
Holger Hildebrandt24d51952020-05-04 14:03:42 +00001989 // so let's just try to keep it simple ...
1990 /*
dbainbri4d3a0dc2020-12-02 00:33:42 +00001991 device, err := dh.coreProxy.GetDevice(log.WithSpanFromContext(context.TODO(), ctx), dh.device.Id, dh.device.Id)
Holger Hildebrandt24d51952020-05-04 14:03:42 +00001992 if err != nil || device == nil {
1993 //TODO: needs to handle error scenarios
1994 logger.Errorw("Failed to fetch device device at creating If", log.Fields{"err": err})
1995 return errors.New("Voltha Device not found")
1996 }
1997 */
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001998
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001999 if err := pDevEntry.Start(log.WithSpanFromContext(context.TODO(), ctx)); err != nil {
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002000 return err
mpagenko3af1f032020-06-10 08:53:41 +00002001 }
Holger Hildebrandt9afc1582021-11-30 16:10:19 +00002002 _ = dh.ReasonUpdate(ctx, cmn.DrStartingOpenomci, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate())
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002003
2004 /* this might be a good time for Omci Verify message? */
2005 verifyExec := make(chan bool)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002006 omciVerify := otst.NewOmciTestRequest(log.WithSpanFromContext(context.TODO(), ctx),
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00002007 dh.device.Id, pDevEntry.PDevOmciCC, false,
mpagenko900ee4b2020-10-12 11:56:34 +00002008 true, true) //exclusive and allowFailure (anyway not yet checked)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002009 omciVerify.PerformOmciTest(log.WithSpanFromContext(context.TODO(), ctx), verifyExec)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002010
2011 /* give the handler some time here to wait for the OMCi verification result
2012 after Timeout start and try MibUpload FSM anyway
2013 (to prevent stopping on just not supported OMCI verification from ONU) */
2014 select {
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00002015 case <-time.After(((cmn.CDefaultRetries+1)*otst.CTestRequestOmciTimeout + 1) * time.Second):
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00002016 logger.Warnw(ctx, "omci start-verification timed out (continue normal)", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002017 case testresult := <-verifyExec:
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00002018 logger.Infow(ctx, "Omci start verification done", log.Fields{"device-id": dh.DeviceID, "result": testresult})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002019 }
2020
2021 /* In py code it looks earlier (on activate ..)
2022 # Code to Run OMCI Test Action
2023 kwargs_omci_test_action = {
2024 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
2025 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
2026 }
2027 serial_number = device.serial_number
2028 self._test_request = OmciTestRequest(self.core_proxy,
2029 self.omci_agent, self.device_id,
2030 AniG, serial_number,
2031 self.logical_device_id,
2032 exclusive=False,
2033 **kwargs_omci_test_action)
2034 ...
2035 # Start test requests after a brief pause
2036 if not self._test_request_started:
2037 self._test_request_started = True
2038 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
2039 reactor.callLater(tststart, self._test_request.start_collector)
2040
2041 */
2042 /* which is then: in omci_test_request.py : */
2043 /*
2044 def start_collector(self, callback=None):
2045 """
2046 Start the collection loop for an adapter if the frequency > 0
2047
2048 :param callback: (callable) Function to call to collect PM data
2049 """
2050 self.logger.info("starting-pm-collection", device_name=self.name, default_freq=self.default_freq)
2051 if callback is None:
2052 callback = self.perform_test_omci
2053
2054 if self.lc is None:
2055 self.lc = LoopingCall(callback)
2056
2057 if self.default_freq > 0:
2058 self.lc.start(interval=self.default_freq / 10)
2059
2060 def perform_test_omci(self):
2061 """
2062 Perform the initial test request
2063 """
2064 ani_g_entities = self._device.configuration.ani_g_entities
2065 ani_g_entities_ids = list(ani_g_entities.keys()) if ani_g_entities \
2066 is not None else None
2067 self._entity_id = ani_g_entities_ids[0]
2068 self.logger.info('perform-test', entity_class=self._entity_class,
2069 entity_id=self._entity_id)
2070 try:
2071 frame = MEFrame(self._entity_class, self._entity_id, []).test()
2072 result = yield self._device.omci_cc.send(frame)
2073 if not result.fields['omci_message'].fields['success_code']:
2074 self.logger.info('Self-Test Submitted Successfully',
2075 code=result.fields[
2076 'omci_message'].fields['success_code'])
2077 else:
2078 raise TestFailure('Test Failure: {}'.format(
2079 result.fields['omci_message'].fields['success_code']))
2080 except TimeoutError as e:
2081 self.deferred.errback(failure.Failure(e))
2082
2083 except Exception as e:
2084 self.logger.exception('perform-test-Error', e=e,
2085 class_id=self._entity_class,
2086 entity_id=self._entity_id)
2087 self.deferred.errback(failure.Failure(e))
2088
2089 */
2090
2091 // PM related heartbeat??? !!!TODO....
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002092 //self._heartbeat.Enabled = True
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002093
mpagenko1cc3cb42020-07-27 15:24:38 +00002094 /* Note: Even though FSM calls look 'synchronous' here, FSM is running in background with the effect that possible errors
2095 * within the MibUpload are not notified in the OnuIndication response, this might be acceptable here,
2096 * as further OltAdapter processing may rely on the deviceReason event 'MibUploadDone' as a result of the FSM processing
Himani Chawla4d908332020-08-31 12:30:20 +05302097 * otherwise some processing synchronization would be required - cmp. e.g TechProfile processing
mpagenko1cc3cb42020-07-27 15:24:38 +00002098 */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002099 //call MibUploadFSM - transition up to state UlStInSync
2100 pMibUlFsm := pDevEntry.PMibUploadFsm.PFsm
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +00002101 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002102 if pMibUlFsm.Is(mib.UlStDisabled) {
2103 if err := pMibUlFsm.Event(mib.UlEvStart); err != nil {
2104 logger.Errorw(ctx, "MibSyncFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err})
2105 return fmt.Errorf("can't go to state starting: %s", dh.DeviceID)
Himani Chawla4d908332020-08-31 12:30:20 +05302106 }
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00002107 logger.Debugw(ctx, "MibSyncFsm", log.Fields{"device-id": dh.DeviceID, "state": string(pMibUlFsm.Current())})
Himani Chawla4d908332020-08-31 12:30:20 +05302108 //Determine ONU status and start/re-start MIB Synchronization tasks
2109 //Determine if this ONU has ever synchronized
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002110 if pDevEntry.IsNewOnu() {
2111 if err := pMibUlFsm.Event(mib.UlEvResetMib); err != nil {
2112 logger.Errorw(ctx, "MibSyncFsm: Can't go to state resetting_mib", log.Fields{"device-id": dh.DeviceID, "err": err})
2113 return fmt.Errorf("can't go to state resetting_mib: %s", dh.DeviceID)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002114 }
Himani Chawla4d908332020-08-31 12:30:20 +05302115 } else {
Holger Hildebrandt9afc1582021-11-30 16:10:19 +00002116 if err := pMibUlFsm.Event(mib.UlEvVerifyAndStoreTPs); err != nil {
2117 logger.Errorw(ctx, "MibSyncFsm: Can't go to state verify and store TPs", log.Fields{"device-id": dh.DeviceID, "err": err})
2118 return fmt.Errorf("can't go to state verify and store TPs: %s", dh.DeviceID)
Himani Chawla4d908332020-08-31 12:30:20 +05302119 }
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00002120 logger.Debugw(ctx, "state of MibSyncFsm", log.Fields{"device-id": dh.DeviceID, "state": string(pMibUlFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002121 }
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +00002122 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002123 logger.Errorw(ctx, "wrong state of MibSyncFsm - want: disabled", log.Fields{"have": string(pMibUlFsm.Current()),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002124 "device-id": dh.DeviceID})
2125 return fmt.Errorf("wrong state of MibSyncFsm: %s", dh.DeviceID)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002126 }
2127 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002128 logger.Errorw(ctx, "MibSyncFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID})
2129 return fmt.Errorf("can't execute MibSync: %s", dh.DeviceID)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002130 }
2131 return nil
2132}
2133
dbainbri4d3a0dc2020-12-02 00:33:42 +00002134func (dh *deviceHandler) updateInterface(ctx context.Context, onuind *oop.OnuIndication) error {
mpagenko3af1f032020-06-10 08:53:41 +00002135 //state checking to prevent unneeded processing (eg. on ONU 'unreachable' and 'down')
mpagenkofc4f56e2020-11-04 17:17:49 +00002136 // (but note that the deviceReason may also have changed to e.g. TechProf*Delete_Success in between)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002137 if dh.getDeviceReason() != cmn.DrStoppingOpenomci {
2138 logger.Debugw(ctx, "updateInterface-started - stopping-device", log.Fields{"device-id": dh.DeviceID})
mpagenko2418ab02020-11-12 12:58:06 +00002139
mpagenko900ee4b2020-10-12 11:56:34 +00002140 //stop all running FSM processing - make use of the DH-state as mirrored in the deviceReason
2141 //here no conflict with aborted FSM's should arise as a complete OMCI initialization is assumed on ONU-Up
2142 //but that might change with some simple MDS check on ONU-Up treatment -> attention!!!
Holger Hildebrandt10d98192021-01-27 15:29:31 +00002143 if err := dh.resetFsms(ctx, true); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002144 logger.Errorw(ctx, "error-updateInterface at FSM stop",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002145 log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko900ee4b2020-10-12 11:56:34 +00002146 // abort: system behavior is just unstable ...
2147 return err
2148 }
mpagenkoa40e99a2020-11-17 13:50:39 +00002149 //all stored persistent data are not valid anymore (loosing knowledge about the connected ONU)
dbainbri4d3a0dc2020-12-02 00:33:42 +00002150 _ = dh.deleteDevicePersistencyData(ctx) //ignore possible errors here and continue, hope is that data is synchronized with new ONU-Up
mpagenko900ee4b2020-10-12 11:56:34 +00002151
2152 //deviceEntry stop without omciCC reset here, regarding the OMCI_CC still valid for this ONU
mpagenko44bd8362021-11-15 11:40:05 +00002153 //stop the device entry to allow for all system event transfers again
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002154 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
mpagenko3af1f032020-06-10 08:53:41 +00002155 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002156 logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
2157 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
mpagenko3af1f032020-06-10 08:53:41 +00002158 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002159 _ = pDevEntry.Stop(log.WithSpanFromContext(context.TODO(), ctx), false)
mpagenko3af1f032020-06-10 08:53:41 +00002160
2161 //TODO!!! remove existing traffic profiles
2162 /* from py code, if TP's exist, remove them - not yet implemented
2163 self._tp = dict()
2164 # Let TP download happen again
2165 for uni_id in self._tp_service_specific_task:
2166 self._tp_service_specific_task[uni_id].clear()
2167 for uni_id in self._tech_profile_download_done:
2168 self._tech_profile_download_done[uni_id].clear()
2169 */
2170
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002171 dh.DisableUniPortStateUpdate(ctx)
mpagenko3af1f032020-06-10 08:53:41 +00002172
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002173 dh.SetReadyForOmciConfig(false)
mpagenkofc4f56e2020-11-04 17:17:49 +00002174
mpagenkoe4782082021-11-25 12:04:26 +00002175 if err := dh.ReasonUpdate(ctx, cmn.DrStoppingOpenomci, true); err != nil {
mpagenko3af1f032020-06-10 08:53:41 +00002176 // abort: system behavior is just unstable ...
2177 return err
2178 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00002179 logger.Debugw(ctx, "call DeviceStateUpdate upon update interface", log.Fields{"ConnectStatus": voltha.ConnectStatus_UNREACHABLE,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002180 "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID})
khenaidoo42dcdfd2021-10-19 17:34:12 -04002181 if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002182 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04002183 ConnStatus: voltha.ConnectStatus_UNREACHABLE,
2184 OperStatus: voltha.OperStatus_DISCOVERED,
2185 }); err != nil {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00002186 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
dbainbri4d3a0dc2020-12-02 00:33:42 +00002187 logger.Errorw(ctx, "error-updating-device-state unreachable-discovered",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002188 log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko3af1f032020-06-10 08:53:41 +00002189 // abort: system behavior is just unstable ...
2190 return err
2191 }
2192 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002193 logger.Debugw(ctx, "updateInterface - device already stopped", log.Fields{"device-id": dh.DeviceID})
mpagenko3af1f032020-06-10 08:53:41 +00002194 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002195 return nil
2196}
2197
Holger Hildebrandt10d98192021-01-27 15:29:31 +00002198func (dh *deviceHandler) resetFsms(ctx context.Context, includingMibSyncFsm bool) error {
mpagenko900ee4b2020-10-12 11:56:34 +00002199 //all possible FSM's are stopped or reset here to ensure their transition to 'disabled'
2200 //it is not sufficient to stop/reset the latest running FSM as done in previous versions
2201 // as after down/up procedures all FSM's might be active/ongoing (in theory)
2202 // and using the stop/reset event should never harm
Holger Hildebrandt12609a12022-03-25 13:23:25 +00002203 logger.Debugw(ctx, "resetFsms entered", log.Fields{"device-id": dh.DeviceID})
mpagenko900ee4b2020-10-12 11:56:34 +00002204
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002205 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
mpagenko900ee4b2020-10-12 11:56:34 +00002206 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002207 logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
2208 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
mpagenko900ee4b2020-10-12 11:56:34 +00002209 }
Holger Hildebrandtc8ece362021-05-17 12:01:10 +00002210 if pDevEntry.PDevOmciCC != nil {
mpagenko8cd1bf72021-06-22 10:11:19 +00002211 pDevEntry.PDevOmciCC.CancelRequestMonitoring(ctx)
Holger Hildebrandtc8ece362021-05-17 12:01:10 +00002212 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002213 pDevEntry.MutexOnuImageStatus.RLock()
2214 if pDevEntry.POnuImageStatus != nil {
2215 pDevEntry.POnuImageStatus.CancelProcessing(ctx)
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00002216 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002217 pDevEntry.MutexOnuImageStatus.RUnlock()
mpagenkoaa3afe92021-05-21 16:20:58 +00002218
Holger Hildebrandt10d98192021-01-27 15:29:31 +00002219 if includingMibSyncFsm {
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00002220 pDevEntry.CancelProcessing(ctx)
mpagenko900ee4b2020-10-12 11:56:34 +00002221 }
2222 //MibDownload may run
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002223 pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm
mpagenko900ee4b2020-10-12 11:56:34 +00002224 if pMibDlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002225 _ = pMibDlFsm.Event(mib.DlEvReset)
mpagenko900ee4b2020-10-12 11:56:34 +00002226 }
mpagenko101ac942021-11-16 15:01:29 +00002227 //stop any deviceHandler reconcile processing (if running)
2228 dh.stopReconciling(ctx, false, cWaitReconcileFlowAbortOnError)
mpagenko900ee4b2020-10-12 11:56:34 +00002229 //port lock/unlock FSM's may be active
2230 if dh.pUnlockStateFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002231 _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset)
mpagenko900ee4b2020-10-12 11:56:34 +00002232 }
2233 if dh.pLockStateFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002234 _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset)
mpagenko900ee4b2020-10-12 11:56:34 +00002235 }
2236 //techProfile related PonAniConfigFsm FSM may be active
2237 if dh.pOnuTP != nil {
2238 // should always be the case here
2239 // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002240 if dh.pOnuTP.PAniConfigFsm != nil {
2241 for uniTP := range dh.pOnuTP.PAniConfigFsm {
2242 dh.pOnuTP.PAniConfigFsm[uniTP].CancelProcessing(ctx)
Girish Gowdra041dcb32020-11-16 16:54:30 -08002243 }
mpagenko900ee4b2020-10-12 11:56:34 +00002244 }
2245 for _, uniPort := range dh.uniEntityMap {
mpagenko900ee4b2020-10-12 11:56:34 +00002246 // reset the possibly existing VlanConfigFsm
mpagenkof1fc3862021-02-16 10:09:52 +00002247 dh.lockVlanConfig.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002248 if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniPort.UniID]; exist {
mpagenko900ee4b2020-10-12 11:56:34 +00002249 //VlanFilterFsm exists and was already started
mpagenko7d6bb022021-03-11 15:07:55 +00002250 dh.lockVlanConfig.RUnlock()
mpagenko7d6bb022021-03-11 15:07:55 +00002251 //ensure the FSM processing is stopped in case waiting for some response
mpagenko73143992021-04-09 15:17:10 +00002252 pVlanFilterFsm.CancelProcessing(ctx)
mpagenkof1fc3862021-02-16 10:09:52 +00002253 } else {
2254 dh.lockVlanConfig.RUnlock()
mpagenko900ee4b2020-10-12 11:56:34 +00002255 }
2256 }
2257 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002258 if dh.GetCollectorIsRunning() {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00002259 // Stop collector routine
2260 dh.stopCollector <- true
2261 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002262 if dh.GetAlarmManagerIsRunning(ctx) {
Himani Chawla4c1d4c72021-02-18 12:14:31 +05302263 dh.stopAlarmManager <- true
2264 }
Girish Gowdra10123c02021-08-30 11:52:06 -07002265 if dh.pSelfTestHdlr.GetSelfTestHandlerIsRunning() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002266 dh.pSelfTestHdlr.StopSelfTestModule <- true
Girish Gowdra10123c02021-08-30 11:52:06 -07002267 }
Himani Chawla4c1d4c72021-02-18 12:14:31 +05302268
Girish Gowdrae95687a2021-09-08 16:30:58 -07002269 // Note: We want flow deletes to be processed on onu down, so do not stop flow monitoring routines
2270
mpagenko80622a52021-02-09 16:53:23 +00002271 //reset a possibly running upgrade FSM
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002272 // (note the Upgrade FSM may stay alive e.g. in state UpgradeStWaitForCommit to endure the ONU reboot)
mpagenko80622a52021-02-09 16:53:23 +00002273 dh.lockUpgradeFsm.RLock()
mpagenko38662d02021-08-11 09:45:19 +00002274 lopOnuUpradeFsm := dh.pOnuUpradeFsm
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002275 //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm()
mpagenko80622a52021-02-09 16:53:23 +00002276 dh.lockUpgradeFsm.RUnlock()
mpagenko38662d02021-08-11 09:45:19 +00002277 if lopOnuUpradeFsm != nil {
mpagenko59862f02021-10-11 08:53:18 +00002278 if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation
2279 //here we do not expect intermediate cancelation, we still allow for other commands on this FSM
2280 // (even though it may also run into direct cancellation, a bit hard to verify here)
2281 // so don't set 'dh.upgradeCanceled = true' here!
2282 lopOnuUpradeFsm.CancelProcessing(ctx, false, voltha.ImageState_CANCELLED_ON_ONU_STATE) //conditional cancel
2283 }
mpagenko38662d02021-08-11 09:45:19 +00002284 }
mpagenko80622a52021-02-09 16:53:23 +00002285
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002286 logger.Infow(ctx, "resetFsms done", log.Fields{"device-id": dh.DeviceID})
mpagenko900ee4b2020-10-12 11:56:34 +00002287 return nil
2288}
2289
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002290func (dh *deviceHandler) processMibDatabaseSyncEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
2291 logger.Debugw(ctx, "MibInSync event received, adding uni ports and locking the ONU interfaces", log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302292
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002293 // store persistent data collected during MIB upload processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002294 if err := dh.StorePersistentData(ctx); err != nil {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002295 logger.Warnw(ctx, "store persistent data error - continue as there will be additional write attempts",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002296 log.Fields{"device-id": dh.DeviceID, "err": err})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002297 }
Holger Hildebrandt9afc1582021-11-30 16:10:19 +00002298 _ = dh.ReasonUpdate(ctx, cmn.DrDiscoveryMibsyncComplete, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002299 dh.AddAllUniPorts(ctx)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002300
mpagenkoa40e99a2020-11-17 13:50:39 +00002301 /* 200605: lock processing after initial MIBUpload removed now as the ONU should be in the lock state per default here */
2302 /* 201117: build_dt-berlin-pod-openonugo_1T8GEM_voltha_DT_openonugo_master_test runs into error TC
2303 * 'Test Disable ONUs and OLT Then Delete ONUs and OLT for DT' with Sercom ONU, which obviously needs
2304 * disable/enable toggling here to allow traffic
2305 * but moreover it might be useful for tracking the interface operState changes if this will be implemented,
2306 * like the py comment says:
2307 * # start by locking all the unis till mib sync and initial mib is downloaded
2308 * # this way we can capture the port down/up events when we are ready
2309 */
Himani Chawla26e555c2020-08-31 12:30:20 +05302310
mpagenkoa40e99a2020-11-17 13:50:39 +00002311 // Init Uni Ports to Admin locked state
2312 // *** should generate UniLockStateDone event *****
2313 if dh.pLockStateFsm == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002314 dh.createUniLockFsm(ctx, true, cmn.UniLockStateDone)
mpagenkoa40e99a2020-11-17 13:50:39 +00002315 } else { //LockStateFSM already init
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002316 dh.pLockStateFsm.SetSuccessEvent(cmn.UniLockStateDone)
dbainbri4d3a0dc2020-12-02 00:33:42 +00002317 dh.runUniLockFsm(ctx, true)
mpagenkoa40e99a2020-11-17 13:50:39 +00002318 }
2319}
2320
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002321func (dh *deviceHandler) processUniLockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
2322 logger.Infow(ctx, "UniLockStateDone event: Starting MIB download", log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302323 /* Mib download procedure -
2324 ***** should run over 'downloaded' state and generate MibDownloadDone event *****
2325 */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002326 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002327 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002328 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002329 return
2330 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002331 pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm
Himani Chawla26e555c2020-08-31 12:30:20 +05302332 if pMibDlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002333 if pMibDlFsm.Is(mib.DlStDisabled) {
2334 if err := pMibDlFsm.Event(mib.DlEvStart); err != nil {
2335 logger.Errorw(ctx, "MibDownloadFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err})
Himani Chawla26e555c2020-08-31 12:30:20 +05302336 // maybe try a FSM reset and then again ... - TODO!!!
2337 } else {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00002338 logger.Debugw(ctx, "MibDownloadFsm", log.Fields{"device-id": dh.DeviceID, "state": string(pMibDlFsm.Current())})
Himani Chawla26e555c2020-08-31 12:30:20 +05302339 // maybe use more specific states here for the specific download steps ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002340 if err := pMibDlFsm.Event(mib.DlEvCreateGal); err != nil {
2341 logger.Errorw(ctx, "MibDownloadFsm: Can't start CreateGal", log.Fields{"device-id": dh.DeviceID, "err": err})
Himani Chawla26e555c2020-08-31 12:30:20 +05302342 } else {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00002343 logger.Debugw(ctx, "state of MibDownloadFsm", log.Fields{"device-id": dh.DeviceID, "state": string(pMibDlFsm.Current())})
Himani Chawla26e555c2020-08-31 12:30:20 +05302344 //Begin MIB data download (running autonomously)
2345 }
2346 }
2347 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002348 logger.Errorw(ctx, "wrong state of MibDownloadFsm - want: disabled", log.Fields{"have": string(pMibDlFsm.Current()),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002349 "device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302350 // maybe try a FSM reset and then again ... - TODO!!!
2351 }
2352 /***** Mib download started */
2353 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002354 logger.Errorw(ctx, "MibDownloadFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302355 }
2356}
2357
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002358func (dh *deviceHandler) processMibDownloadDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
2359 logger.Debugw(ctx, "MibDownloadDone event received, unlocking the ONU interfaces", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +00002360 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
2361 if pDevEntry == nil {
2362 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
2363 return
2364 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002365 if !dh.IsReconciling() {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +00002366 logger.Debugw(ctx, "call DeviceUpdate and DeviceStateUpdate upon mib-download done", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002367 "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID})
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +00002368 // update device info in core
2369 pDevEntry.MutexPersOnuConfig.RLock()
2370 dh.device.Vendor = pDevEntry.SOnuPersistentData.PersVendorID
2371 dh.device.VendorId = pDevEntry.SOnuPersistentData.PersVendorID
2372 dh.device.Model = pDevEntry.SOnuPersistentData.PersVersion
2373 pDevEntry.MutexPersOnuConfig.RUnlock()
2374 dh.logicalDeviceID = dh.DeviceID
2375 if err := dh.updateDeviceInCore(ctx, dh.device); err != nil {
2376 logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err})
2377 }
2378 // update device state in core
mpagenko15ff4a52021-03-02 10:09:20 +00002379 //we allow a possible OnuSw image commit only in the normal startup, not at reconciling
2380 // in case of adapter restart connected to an ONU upgrade I would not rely on the image quality
2381 // maybe some 'forced' commitment can be done in this situation from system management (or upgrade restarted)
2382 dh.checkOnOnuImageCommit(ctx)
khenaidoo42dcdfd2021-10-19 17:34:12 -04002383 if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002384 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04002385 ConnStatus: voltha.ConnectStatus_REACHABLE,
2386 OperStatus: voltha.OperStatus_ACTIVE,
2387 }); err != nil {
Himani Chawla26e555c2020-08-31 12:30:20 +05302388 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002389 logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
Himani Chawla26e555c2020-08-31 12:30:20 +05302390 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002391 logger.Debugw(ctx, "dev state updated to 'Oper.Active'", log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302392 }
2393 } else {
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +00002394 logger.Debugw(ctx, "reconciling - don't notify core about updated device info and DeviceStateUpdate to ACTIVE",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002395 log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302396 }
Holger Hildebrandt9afc1582021-11-30 16:10:19 +00002397 _ = dh.ReasonUpdate(ctx, cmn.DrInitialMibDownloaded, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate())
Girish Gowdrae0140f02021-02-02 16:55:09 -08002398
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002399 if !dh.GetCollectorIsRunning() {
Girish Gowdraf7d82d02022-04-26 16:18:35 -07002400 var waitForOmciProcessor sync.WaitGroup
2401 waitForOmciProcessor.Add(1)
Girish Gowdra7b0ee5c2021-03-19 21:48:15 -07002402 // Start PM collector routine
Girish Gowdraf7d82d02022-04-26 16:18:35 -07002403 go dh.StartCollector(ctx, &waitForOmciProcessor)
2404 waitForOmciProcessor.Wait()
Girish Gowdra7b0ee5c2021-03-19 21:48:15 -07002405 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002406 if !dh.GetAlarmManagerIsRunning(ctx) {
2407 go dh.StartAlarmManager(ctx)
Girish Gowdra7b0ee5c2021-03-19 21:48:15 -07002408 }
2409
Girish Gowdrae95687a2021-09-08 16:30:58 -07002410 // Start flow handler routines per UNI
2411 for _, uniPort := range dh.uniEntityMap {
2412 // only if this port was enabled for use by the operator at startup
2413 if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) {
2414 if !dh.GetFlowMonitoringIsRunning(uniPort.UniID) {
2415 go dh.PerOnuFlowHandlerRoutine(uniPort.UniID)
2416 }
2417 }
2418 }
2419
Girish Gowdrae0140f02021-02-02 16:55:09 -08002420 // Initialize classical L2 PM Interval Counters
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002421 if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventInit); err != nil {
Girish Gowdrae0140f02021-02-02 16:55:09 -08002422 // There is no way we should be landing here, but if we do then
2423 // there is nothing much we can do about this other than log error
2424 logger.Errorw(ctx, "error starting l2 pm fsm", log.Fields{"device-id": dh.device.Id, "err": err})
2425 }
2426
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002427 dh.SetReadyForOmciConfig(true)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002428
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002429 pDevEntry.MutexPersOnuConfig.RLock()
2430 if dh.IsReconciling() && pDevEntry.SOnuPersistentData.PersUniDisableDone {
2431 pDevEntry.MutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002432 logger.Debugw(ctx, "reconciling - uni-ports were disabled by admin before adapter restart - keep the ports locked",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002433 log.Fields{"device-id": dh.DeviceID})
ozgecanetsia5cbcfbe2022-01-14 10:32:34 +03002434 dh.mutexForDisableDeviceRequested.Lock()
2435 dh.disableDeviceRequested = true
2436 dh.mutexForDisableDeviceRequested.Unlock()
Holger Hildebrandt7741f272022-01-18 08:17:39 +00002437 dh.ReconcileDeviceTechProf(ctx)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002438 // reconcilement will be continued after ani config is done
2439 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002440 pDevEntry.MutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002441 // *** should generate UniUnlockStateDone event *****
ozgecanetsia5cbcfbe2022-01-14 10:32:34 +03002442 dh.mutexForDisableDeviceRequested.RLock()
2443 if !dh.disableDeviceRequested {
2444 if dh.pUnlockStateFsm == nil {
2445 dh.createUniLockFsm(ctx, false, cmn.UniUnlockStateDone)
2446 } else { //UnlockStateFSM already init
2447 dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniUnlockStateDone)
2448 dh.runUniLockFsm(ctx, false)
2449 }
2450 dh.mutexForDisableDeviceRequested.RUnlock()
2451 } else {
2452 dh.mutexForDisableDeviceRequested.RUnlock()
2453 logger.Debugw(ctx, "Uni already lock", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002454 }
Himani Chawla26e555c2020-08-31 12:30:20 +05302455 }
2456}
2457
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002458func (dh *deviceHandler) processUniUnlockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
2459 dh.EnableUniPortStateUpdate(ctx) //cmp python yield self.enable_ports()
Himani Chawla26e555c2020-08-31 12:30:20 +05302460
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002461 if !dh.IsReconciling() {
2462 logger.Infow(ctx, "UniUnlockStateDone event: Sending OnuUp event", log.Fields{"device-id": dh.DeviceID})
ozgecanetsia2f05ed32021-05-31 17:13:48 +03002463 raisedTs := time.Now().Unix()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002464 go dh.sendOnuOperStateEvent(ctx, voltha.OperStatus_ACTIVE, dh.DeviceID, raisedTs) //cmp python onu_active_event
2465 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002466 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002467 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002468 return
2469 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002470 pDevEntry.MutexPersOnuConfig.Lock()
2471 pDevEntry.SOnuPersistentData.PersUniUnlockDone = true
2472 pDevEntry.MutexPersOnuConfig.Unlock()
2473 if err := dh.StorePersistentData(ctx); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002474 logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002475 log.Fields{"device-id": dh.DeviceID, "err": err})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002476 }
Himani Chawla26e555c2020-08-31 12:30:20 +05302477 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002478 logger.Debugw(ctx, "reconciling - don't notify core that onu went to active but trigger tech profile config",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002479 log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt7741f272022-01-18 08:17:39 +00002480 dh.ReconcileDeviceTechProf(ctx)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00002481 // reconcilement will be continued after ani config is done
Himani Chawla26e555c2020-08-31 12:30:20 +05302482 }
2483}
2484
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002485func (dh *deviceHandler) processUniDisableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
mpagenko44bd8362021-11-15 11:40:05 +00002486 logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002487 "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID})
khenaidoo7d3c5582021-08-11 18:09:44 -04002488
mpagenko44bd8362021-11-15 11:40:05 +00002489 // disable device should have no impact on ConnStatus
khenaidoo42dcdfd2021-10-19 17:34:12 -04002490 if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002491 DeviceId: dh.DeviceID,
mpagenko44bd8362021-11-15 11:40:05 +00002492 ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus
khenaidoo7d3c5582021-08-11 18:09:44 -04002493 OperStatus: voltha.OperStatus_UNKNOWN,
2494 }); err != nil {
mpagenko900ee4b2020-10-12 11:56:34 +00002495 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002496 logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko900ee4b2020-10-12 11:56:34 +00002497 }
2498
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002499 logger.Debugw(ctx, "DeviceReasonUpdate upon disable", log.Fields{"reason": cmn.DeviceReasonMap[cmn.DrOmciAdminLock], "device-id": dh.DeviceID})
mpagenko900ee4b2020-10-12 11:56:34 +00002500 // DeviceReason to update acc.to modified py code as per beginning of Sept 2020
mpagenkoe4782082021-11-25 12:04:26 +00002501 _ = dh.ReasonUpdate(ctx, cmn.DrOmciAdminLock, true)
mpagenko900ee4b2020-10-12 11:56:34 +00002502
2503 //transfer the modified logical uni port state
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002504 dh.DisableUniPortStateUpdate(ctx)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002505
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002506 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002507 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002508 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002509 return
2510 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002511 pDevEntry.MutexPersOnuConfig.Lock()
2512 pDevEntry.SOnuPersistentData.PersUniDisableDone = true
2513 pDevEntry.MutexPersOnuConfig.Unlock()
2514 if err := dh.StorePersistentData(ctx); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002515 logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002516 log.Fields{"device-id": dh.DeviceID, "err": err})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002517 }
mpagenko900ee4b2020-10-12 11:56:34 +00002518}
2519
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002520func (dh *deviceHandler) processUniEnableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002521 logger.Debugw(ctx, "DeviceStateUpdate upon re-enable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002522 "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID})
khenaidoo42dcdfd2021-10-19 17:34:12 -04002523 if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002524 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04002525 ConnStatus: voltha.ConnectStatus_REACHABLE,
2526 OperStatus: voltha.OperStatus_ACTIVE,
2527 }); err != nil {
mpagenko900ee4b2020-10-12 11:56:34 +00002528 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002529 logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko900ee4b2020-10-12 11:56:34 +00002530 }
2531
dbainbri4d3a0dc2020-12-02 00:33:42 +00002532 logger.Debugw(ctx, "DeviceReasonUpdate upon re-enable", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002533 "reason": cmn.DeviceReasonMap[cmn.DrOnuReenabled], "device-id": dh.DeviceID})
mpagenko900ee4b2020-10-12 11:56:34 +00002534 // DeviceReason to update acc.to modified py code as per beginning of Sept 2020
mpagenkoe4782082021-11-25 12:04:26 +00002535 _ = dh.ReasonUpdate(ctx, cmn.DrOnuReenabled, true)
mpagenko900ee4b2020-10-12 11:56:34 +00002536
2537 //transfer the modified logical uni port state
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002538 dh.EnableUniPortStateUpdate(ctx)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002539
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002540 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002541 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002542 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002543 return
2544 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002545 pDevEntry.MutexPersOnuConfig.Lock()
2546 pDevEntry.SOnuPersistentData.PersUniDisableDone = false
2547 pDevEntry.MutexPersOnuConfig.Unlock()
2548 if err := dh.StorePersistentData(ctx); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002549 logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002550 log.Fields{"device-id": dh.DeviceID, "err": err})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002551 }
mpagenko900ee4b2020-10-12 11:56:34 +00002552}
2553
Mahir Gunyel50ddea62021-10-22 11:26:42 -07002554func (dh *deviceHandler) processUniEnableStateFailedEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
2555 logger.Debugw(ctx, "DeviceStateUpdate upon re-enable failure. ", log.Fields{
2556 "OperStatus": voltha.OperStatus_FAILED, "device-id": dh.DeviceID})
khenaidoo42dcdfd2021-10-19 17:34:12 -04002557 if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{
Mahir Gunyel50ddea62021-10-22 11:26:42 -07002558 DeviceId: dh.DeviceID,
mpagenko44bd8362021-11-15 11:40:05 +00002559 ConnStatus: connectStatusINVALID, //use some dummy value to prevent modification of the ConnStatus
Mahir Gunyel50ddea62021-10-22 11:26:42 -07002560 OperStatus: voltha.OperStatus_FAILED,
2561 }); err != nil {
2562 logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
2563 }
2564}
2565
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002566func (dh *deviceHandler) processOmciAniConfigDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
2567 if devEvent == cmn.OmciAniConfigDone {
2568 logger.Debugw(ctx, "OmciAniConfigDone event received", log.Fields{"device-id": dh.DeviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +00002569 // attention: the device reason update is done based on ONU-UNI-Port related activity
2570 // - which may cause some inconsistency
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002571 if dh.getDeviceReason() != cmn.DrTechProfileConfigDownloadSuccess {
mpagenkoe4782082021-11-25 12:04:26 +00002572 // which may be the case from some previous activity even on this UNI Port (but also other UNI ports)
Holger Hildebrandt9afc1582021-11-30 16:10:19 +00002573 _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate())
Himani Chawla26e555c2020-08-31 12:30:20 +05302574 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002575 if dh.IsReconciling() {
Holger Hildebrandt7741f272022-01-18 08:17:39 +00002576 // during reconciling with OMCI configuration in TT multi-UNI scenario, OmciAniConfigDone is reached several times
2577 // therefore it must be ensured that reconciling of flow config is only started on the first pass of this code position
2578 dh.mutexReconcilingFirstPassFlag.Lock()
2579 if dh.reconcilingFirstPass {
2580 logger.Debugw(ctx, "reconciling - OmciAniConfigDone first pass, start flow processing", log.Fields{"device-id": dh.DeviceID})
2581 dh.reconcilingFirstPass = false
2582 go dh.ReconcileDeviceFlowConfig(ctx)
2583 }
2584 dh.mutexReconcilingFirstPassFlag.Unlock()
mpagenkofc4f56e2020-11-04 17:17:49 +00002585 }
2586 } else { // should be the OmciAniResourceRemoved block
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002587 logger.Debugw(ctx, "OmciAniResourceRemoved event received", log.Fields{"device-id": dh.DeviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +00002588 // attention: the device reason update is done based on ONU-UNI-Port related activity
2589 // - which may cause some inconsistency
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002590 if dh.getDeviceReason() != cmn.DrTechProfileConfigDeleteSuccess {
mpagenkoe4782082021-11-25 12:04:26 +00002591 // which may be the case from some previous activity even on this ONU port (but also other UNI ports)
2592 _ = dh.ReasonUpdate(ctx, cmn.DrTechProfileConfigDeleteSuccess, true)
mpagenkofc4f56e2020-11-04 17:17:49 +00002593 }
Holger Hildebrandt47555e72020-09-21 11:07:24 +00002594 }
Himani Chawla26e555c2020-08-31 12:30:20 +05302595}
2596
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002597func (dh *deviceHandler) processOmciVlanFilterDoneEvent(ctx context.Context, aDevEvent cmn.OnuDeviceEvent) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002598 logger.Debugw(ctx, "OmciVlanFilterDone event received",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002599 log.Fields{"device-id": dh.DeviceID, "event": aDevEvent})
Himani Chawla26e555c2020-08-31 12:30:20 +05302600 // attention: the device reason update is done based on ONU-UNI-Port related activity
2601 // - which may cause some inconsistency
Himani Chawla26e555c2020-08-31 12:30:20 +05302602
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002603 if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterAddDoneNoKvStore {
2604 if dh.getDeviceReason() != cmn.DrOmciFlowsPushed {
mpagenkoe4782082021-11-25 12:04:26 +00002605 // which may be the case from some previous activity on another UNI Port of the ONU
mpagenkofc4f56e2020-11-04 17:17:49 +00002606 // or even some previous flow add activity on the same port
Holger Hildebrandt9afc1582021-11-30 16:10:19 +00002607 _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsPushed, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate())
mpagenkofc4f56e2020-11-04 17:17:49 +00002608 }
2609 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002610 if dh.getDeviceReason() != cmn.DrOmciFlowsDeleted {
mpagenkofc4f56e2020-11-04 17:17:49 +00002611 //not relevant for reconcile
mpagenkoe4782082021-11-25 12:04:26 +00002612 _ = dh.ReasonUpdate(ctx, cmn.DrOmciFlowsDeleted, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00002613 }
Himani Chawla26e555c2020-08-31 12:30:20 +05302614 }
mpagenkof1fc3862021-02-16 10:09:52 +00002615
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002616 if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterRemDone {
mpagenkof1fc3862021-02-16 10:09:52 +00002617 //events that request KvStore write
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002618 if err := dh.StorePersistentData(ctx); err != nil {
mpagenkof1fc3862021-02-16 10:09:52 +00002619 logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002620 log.Fields{"device-id": dh.DeviceID, "err": err})
mpagenkof1fc3862021-02-16 10:09:52 +00002621 }
2622 } else {
2623 logger.Debugw(ctx, "OmciVlanFilter*Done* - write to KvStore not requested",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002624 log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt10d98192021-01-27 15:29:31 +00002625 }
Himani Chawla26e555c2020-08-31 12:30:20 +05302626}
2627
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002628//DeviceProcStatusUpdate evaluates possible processing events and initiates according next activities
2629func (dh *deviceHandler) DeviceProcStatusUpdate(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
Himani Chawla4d908332020-08-31 12:30:20 +05302630 switch devEvent {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002631 case cmn.MibDatabaseSync:
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002632 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002633 dh.processMibDatabaseSyncEvent(ctx, devEvent)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002634 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002635 case cmn.UniLockStateDone:
mpagenkoa40e99a2020-11-17 13:50:39 +00002636 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002637 dh.processUniLockStateDoneEvent(ctx, devEvent)
mpagenkoa40e99a2020-11-17 13:50:39 +00002638 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002639 case cmn.MibDownloadDone:
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002640 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002641 dh.processMibDownloadDoneEvent(ctx, devEvent)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002642 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002643 case cmn.UniUnlockStateDone:
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002644 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002645 dh.processUniUnlockStateDoneEvent(ctx, devEvent)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002646 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002647 case cmn.UniEnableStateDone:
mpagenko900ee4b2020-10-12 11:56:34 +00002648 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002649 dh.processUniEnableStateDoneEvent(ctx, devEvent)
mpagenko900ee4b2020-10-12 11:56:34 +00002650 }
Mahir Gunyel50ddea62021-10-22 11:26:42 -07002651 case cmn.UniEnableStateFailed:
2652 {
2653 dh.processUniEnableStateFailedEvent(ctx, devEvent)
2654 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002655 case cmn.UniDisableStateDone:
mpagenko900ee4b2020-10-12 11:56:34 +00002656 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002657 dh.processUniDisableStateDoneEvent(ctx, devEvent)
mpagenko900ee4b2020-10-12 11:56:34 +00002658 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002659 case cmn.OmciAniConfigDone, cmn.OmciAniResourceRemoved:
mpagenko3dbcdd22020-07-22 07:38:45 +00002660 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002661 dh.processOmciAniConfigDoneEvent(ctx, devEvent)
mpagenko3dbcdd22020-07-22 07:38:45 +00002662 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002663 case cmn.OmciVlanFilterAddDone, cmn.OmciVlanFilterAddDoneNoKvStore, cmn.OmciVlanFilterRemDone, cmn.OmciVlanFilterRemDoneNoKvStore:
mpagenkodff5dda2020-08-28 11:52:01 +00002664 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002665 dh.processOmciVlanFilterDoneEvent(ctx, devEvent)
mpagenkodff5dda2020-08-28 11:52:01 +00002666 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002667 default:
2668 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002669 logger.Debugw(ctx, "unhandled-device-event", log.Fields{"device-id": dh.DeviceID, "event": devEvent})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002670 }
2671 } //switch
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002672}
2673
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002674func (dh *deviceHandler) addUniPort(ctx context.Context, aUniInstNo uint16, aUniID uint8, aPortType cmn.UniPortType) {
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002675 // parameters are IntfId, OnuId, uniId
Mahir Gunyelcb128ae2021-10-06 09:42:05 -07002676 uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(),
Himani Chawla4d908332020-08-31 12:30:20 +05302677 uint32(aUniID))
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002678 if _, present := dh.uniEntityMap[uniNo]; present {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00002679 logger.Warnw(ctx, "OnuUniPort-add: Port already exists", log.Fields{"device-id": dh.DeviceID, "for InstanceId": aUniInstNo})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002680 } else {
Himani Chawla4d908332020-08-31 12:30:20 +05302681 //with arguments aUniID, a_portNo, aPortType
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002682 pUniPort := cmn.NewOnuUniPort(ctx, aUniID, uniNo, aUniInstNo, aPortType)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002683 if pUniPort == nil {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00002684 logger.Warnw(ctx, "OnuUniPort-add: Could not create Port", log.Fields{"device-id": dh.DeviceID, "for InstanceId": aUniInstNo})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002685 } else {
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002686 //store UniPort with the System-PortNumber key
2687 dh.uniEntityMap[uniNo] = pUniPort
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002688 if !dh.IsReconciling() {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00002689 // create announce the UniPort to the core as VOLTHA Port object
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002690 if err := pUniPort.CreateVolthaPort(ctx, dh); err == nil {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00002691 logger.Infow(ctx, "OnuUniPort-added", log.Fields{"device-id": dh.DeviceID, "for PortNo": uniNo})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00002692 } //error logging already within UniPort method
2693 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002694 logger.Debugw(ctx, "reconciling - OnuUniPort already added", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00002695 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002696 }
2697 }
2698}
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002699
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002700func (dh *deviceHandler) AddAllUniPorts(ctx context.Context) {
2701 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002702 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002703 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002704 return
2705 }
Girish Gowdrae95687a2021-09-08 16:30:58 -07002706 uniCnt := uint8(0) //UNI Port limit: see MaxUnisPerOnu (by now 16) (OMCI supports max 255 p.b.)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002707 if pptpInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys(
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002708 ctx, me.PhysicalPathTerminationPointEthernetUniClassID); len(pptpInstKeys) > 0 {
2709 for _, mgmtEntityID := range pptpInstKeys {
2710 logger.Debugw(ctx, "Add PPTPEthUni port for MIB-stored instance:", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002711 "device-id": dh.DeviceID, "PPTPEthUni EntityID": mgmtEntityID})
Girish Gowdrae95687a2021-09-08 16:30:58 -07002712 dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniPPTP)
2713 uniCnt++
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002714 }
2715 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002716 logger.Debugw(ctx, "No PPTP instances found", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002717 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002718 if veipInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys(
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002719 ctx, me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 {
2720 for _, mgmtEntityID := range veipInstKeys {
2721 logger.Debugw(ctx, "Add VEIP for MIB-stored instance:", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002722 "device-id": dh.DeviceID, "VEIP EntityID": mgmtEntityID})
Girish Gowdrae95687a2021-09-08 16:30:58 -07002723 dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniVEIP)
2724 uniCnt++
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002725 }
2726 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002727 logger.Debugw(ctx, "No VEIP instances found", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002728 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002729 if potsInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys(
ozgecanetsia124d9732021-09-16 14:31:57 +03002730 ctx, me.PhysicalPathTerminationPointPotsUniClassID); len(potsInstKeys) > 0 {
2731 for _, mgmtEntityID := range potsInstKeys {
2732 logger.Debugw(ctx, "Add PPTP Pots UNI for MIB-stored instance:", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002733 "device-id": dh.DeviceID, "PPTP Pots UNI EntityID": mgmtEntityID})
Girish Gowdrae95687a2021-09-08 16:30:58 -07002734 dh.addUniPort(ctx, mgmtEntityID, uniCnt, cmn.UniPPTPPots)
2735 uniCnt++
ozgecanetsia124d9732021-09-16 14:31:57 +03002736 }
2737 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002738 logger.Debugw(ctx, "No PPTP Pots UNI instances found", log.Fields{"device-id": dh.DeviceID})
ozgecanetsia124d9732021-09-16 14:31:57 +03002739 }
Girish Gowdrae95687a2021-09-08 16:30:58 -07002740 if uniCnt == 0 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002741 logger.Warnw(ctx, "No UniG instances found", log.Fields{"device-id": dh.DeviceID})
Girish Gowdrae95687a2021-09-08 16:30:58 -07002742 return
2743 }
2744
mpagenko2c3f6c52021-11-23 11:22:10 +00002745 //Note: For the moment is is not required to include the (newly added) POTS ports into the range
2746 // of flowCall or reconcile channels. But some sort of flow and reconcile processing might get necessary
2747 // also for the POTS ports, so we include them already for future usage - should anyway do no great harm
Girish Gowdrae95687a2021-09-08 16:30:58 -07002748 dh.flowCbChan = make([]chan FlowCb, uniCnt)
2749 dh.stopFlowMonitoringRoutine = make([]chan bool, uniCnt)
2750 dh.isFlowMonitoringRoutineActive = make([]bool, uniCnt)
mpagenko2c3f6c52021-11-23 11:22:10 +00002751 //chUniVlanConfigReconcilingDone needs to have the capacity of all UniPorts as flow reconcile may run parallel for all of them
2752 dh.chUniVlanConfigReconcilingDone = make(chan uint16, uniCnt)
Girish Gowdrae95687a2021-09-08 16:30:58 -07002753 for i := 0; i < int(uniCnt); i++ {
2754 dh.flowCbChan[i] = make(chan FlowCb, dh.pOpenOnuAc.config.MaxConcurrentFlowsPerUni)
2755 dh.stopFlowMonitoringRoutine[i] = make(chan bool)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002756 }
2757}
2758
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002759// EnableUniPortStateUpdate enables UniPortState and update core port state accordingly
2760func (dh *deviceHandler) EnableUniPortStateUpdate(ctx context.Context) {
Holger Hildebrandtbe674422020-05-05 13:05:30 +00002761 // py code was updated 2003xx to activate the real ONU UNI ports per OMCI (VEIP or PPTP)
Himani Chawla4d908332020-08-31 12:30:20 +05302762 // but towards core only the first port active state is signaled
Holger Hildebrandtbe674422020-05-05 13:05:30 +00002763 // with following remark:
2764 // # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
2765 // # load on the core
2766
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002767 // lock_ports(false) as done in py code here is shifted to separate call from device event processing
Holger Hildebrandtbe674422020-05-05 13:05:30 +00002768
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002769 for uniNo, uniPort := range dh.uniEntityMap {
mpagenko3af1f032020-06-10 08:53:41 +00002770 // only if this port is validated for operState transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002771 if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) {
2772 logger.Infow(ctx, "OnuUniPort-forced-OperState-ACTIVE", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID})
2773 uniPort.SetOperState(vc.OperStatus_ACTIVE)
2774 if !dh.IsReconciling() {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00002775 //maybe also use getter functions on uniPort - perhaps later ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002776 go func(port *cmn.OnuUniPort) {
khenaidoo42dcdfd2021-10-19 17:34:12 -04002777 if err := dh.updatePortStateInCore(ctx, &ca.PortState{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002778 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04002779 PortType: voltha.Port_ETHERNET_UNI,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002780 PortNo: port.PortNo,
2781 OperStatus: port.OperState,
khenaidoo7d3c5582021-08-11 18:09:44 -04002782 }); err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002783 logger.Errorw(ctx, "port-state-update-failed", log.Fields{"error": err, "port-no": uniPort.PortNo, "device-id": dh.DeviceID})
khenaidoo7d3c5582021-08-11 18:09:44 -04002784 }
2785 }(uniPort)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00002786 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002787 logger.Debugw(ctx, "reconciling - don't notify core about PortStateUpdate", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00002788 }
mpagenko3af1f032020-06-10 08:53:41 +00002789 }
2790 }
2791}
2792
2793// Disable UniPortState and update core port state accordingly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002794func (dh *deviceHandler) DisableUniPortStateUpdate(ctx context.Context) {
2795 // compare EnableUniPortStateUpdate() above
mpagenko3af1f032020-06-10 08:53:41 +00002796 // -> use current restriction to operate only on first UNI port as inherited from actual Py code
2797 for uniNo, uniPort := range dh.uniEntityMap {
2798 // only if this port is validated for operState transfer
Matteo Scandolo20d180c2021-06-10 17:20:21 +02002799
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002800 if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) {
2801 logger.Infow(ctx, "OnuUniPort-forced-OperState-UNKNOWN", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID})
2802 uniPort.SetOperState(vc.OperStatus_UNKNOWN)
2803 if !dh.IsReconciling() {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002804 //maybe also use getter functions on uniPort - perhaps later ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002805 go func(port *cmn.OnuUniPort) {
khenaidoo42dcdfd2021-10-19 17:34:12 -04002806 if err := dh.updatePortStateInCore(ctx, &ca.PortState{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002807 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04002808 PortType: voltha.Port_ETHERNET_UNI,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002809 PortNo: port.PortNo,
2810 OperStatus: port.OperState,
khenaidoo7d3c5582021-08-11 18:09:44 -04002811 }); err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002812 logger.Errorw(ctx, "port-state-update-failed", log.Fields{"error": err, "port-no": uniPort.PortNo, "device-id": dh.DeviceID})
khenaidoo7d3c5582021-08-11 18:09:44 -04002813 }
2814 }(uniPort)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002815 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002816 logger.Debugw(ctx, "reconciling - don't notify core about PortStateUpdate", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002817 }
2818
Holger Hildebrandtbe674422020-05-05 13:05:30 +00002819 }
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002820 }
2821}
2822
2823// ONU_Active/Inactive announcement on system KAFKA bus
2824// tried to re-use procedure of oltUpDownIndication from openolt_eventmgr.go with used values from Py code
dbainbri4d3a0dc2020-12-02 00:33:42 +00002825func (dh *deviceHandler) sendOnuOperStateEvent(ctx context.Context, aOperState vc.OperStatus_Types, aDeviceID string, raisedTs int64) {
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002826 var de voltha.DeviceEvent
2827 eventContext := make(map[string]string)
2828 //Populating event context
2829 // assume giving ParentId in GetDevice twice really gives the ParentDevice (there is no GetParentDevice()...)
khenaidoo7d3c5582021-08-11 18:09:44 -04002830 parentDevice, err := dh.getDeviceFromCore(ctx, dh.parentID)
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002831 if err != nil || parentDevice == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002832 logger.Errorw(ctx, "Failed to fetch parent device for OnuEvent",
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00002833 log.Fields{"device-id": dh.DeviceID, "parentID": dh.parentID, "err": err})
Holger Hildebrandt7ec14c42021-05-28 14:21:58 +00002834 return //TODO with VOL-3045: rw-core is unresponsive: report error and/or perform self-initiated onu-reset?
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002835 }
2836 oltSerialNumber := parentDevice.SerialNumber
2837
2838 eventContext["pon-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.IntfId), 10)
2839 eventContext["onu-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.OnuId), 10)
2840 eventContext["serial-number"] = dh.device.SerialNumber
ssiddiqui1221d1a2021-02-15 11:12:51 +05302841 eventContext["olt-serial-number"] = oltSerialNumber
2842 eventContext["device-id"] = aDeviceID
2843 eventContext["registration-id"] = aDeviceID //py: string(device_id)??
ozgecanetsiaf0a76b62021-05-31 17:42:09 +03002844 eventContext["num-of-unis"] = strconv.Itoa(len(dh.uniEntityMap))
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002845 if deviceEntry := dh.GetOnuDeviceEntry(ctx, false); deviceEntry != nil {
2846 deviceEntry.MutexPersOnuConfig.RLock()
Holger Hildebrandt3d3c2c52022-06-08 13:25:43 +00002847 eventContext["vendor-id"] = deviceEntry.SOnuPersistentData.PersVendorID
2848 eventContext["model"] = deviceEntry.SOnuPersistentData.PersVersion
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002849 eventContext["equipment-id"] = deviceEntry.SOnuPersistentData.PersEquipmentID
2850 deviceEntry.MutexPersOnuConfig.RUnlock()
2851 eventContext["software-version"] = deviceEntry.GetActiveImageVersion(ctx)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002852 eventContext["inactive-software-version"] = deviceEntry.GetInactiveImageVersion(ctx)
ozgecanetsiaf0a76b62021-05-31 17:42:09 +03002853 logger.Debugw(ctx, "prepare ONU_ACTIVATED event",
2854 log.Fields{"device-id": aDeviceID, "EventContext": eventContext})
2855 } else {
2856 logger.Errorw(ctx, "Failed to fetch device-entry. ONU_ACTIVATED event is not sent",
2857 log.Fields{"device-id": aDeviceID})
2858 return
2859 }
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002860
2861 /* Populating device event body */
2862 de.Context = eventContext
Himani Chawla4d908332020-08-31 12:30:20 +05302863 de.ResourceId = aDeviceID
2864 if aOperState == voltha.OperStatus_ACTIVE {
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002865 de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "RAISE_EVENT")
2866 de.Description = fmt.Sprintf("%s Event - %s - %s",
2867 cEventObjectType, cOnuActivatedEvent, "Raised")
2868 } else {
2869 de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "CLEAR_EVENT")
2870 de.Description = fmt.Sprintf("%s Event - %s - %s",
2871 cEventObjectType, cOnuActivatedEvent, "Cleared")
2872 }
2873 /* Send event to KAFKA */
kesavand510a31c2022-03-16 17:12:12 +05302874 if err := dh.EventProxy.SendDeviceEventWithKey(ctx, &de, equipment, pon, raisedTs, aDeviceID); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002875 logger.Warnw(ctx, "could not send ONU_ACTIVATED event",
Himani Chawla4d908332020-08-31 12:30:20 +05302876 log.Fields{"device-id": aDeviceID, "error": err})
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002877 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00002878 logger.Debugw(ctx, "ctx, ONU_ACTIVATED event sent to KAFKA",
Himani Chawla4d908332020-08-31 12:30:20 +05302879 log.Fields{"device-id": aDeviceID, "with-EventName": de.DeviceEventName})
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002880}
2881
Himani Chawla4d908332020-08-31 12:30:20 +05302882// createUniLockFsm initializes and runs the UniLock FSM to transfer the OMCI related commands for port lock/unlock
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002883func (dh *deviceHandler) createUniLockFsm(ctx context.Context, aAdminState bool, devEvent cmn.OnuDeviceEvent) {
2884 chLSFsm := make(chan cmn.Message, 2048)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002885 var sFsmName string
Himani Chawla4d908332020-08-31 12:30:20 +05302886 if aAdminState {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002887 logger.Debugw(ctx, "createLockStateFSM", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002888 sFsmName = "LockStateFSM"
2889 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002890 logger.Debugw(ctx, "createUnlockStateFSM", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002891 sFsmName = "UnLockStateFSM"
2892 }
mpagenko3af1f032020-06-10 08:53:41 +00002893
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002894 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
mpagenko3af1f032020-06-10 08:53:41 +00002895 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002896 logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
mpagenko3af1f032020-06-10 08:53:41 +00002897 return
2898 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002899 pLSFsm := uniprt.NewLockStateFsm(ctx, aAdminState, devEvent, sFsmName, dh, pDevEntry, chLSFsm)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002900 if pLSFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05302901 if aAdminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002902 dh.pLockStateFsm = pLSFsm
2903 } else {
2904 dh.pUnlockStateFsm = pLSFsm
2905 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00002906 dh.runUniLockFsm(ctx, aAdminState)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002907 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002908 logger.Errorw(ctx, "LockStateFSM could not be created - abort!!", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002909 }
2910}
2911
2912// runUniLockFsm starts the UniLock FSM to transfer the OMCI related commands for port lock/unlock
dbainbri4d3a0dc2020-12-02 00:33:42 +00002913func (dh *deviceHandler) runUniLockFsm(ctx context.Context, aAdminState bool) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002914 /* Uni Port lock/unlock procedure -
2915 ***** should run via 'adminDone' state and generate the argument requested event *****
2916 */
2917 var pLSStatemachine *fsm.FSM
Himani Chawla4d908332020-08-31 12:30:20 +05302918 if aAdminState {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002919 pLSStatemachine = dh.pLockStateFsm.PAdaptFsm.PFsm
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002920 //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore
2921 if (dh.pUnlockStateFsm != nil) &&
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002922 (dh.pUnlockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) {
2923 _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002924 }
2925 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002926 pLSStatemachine = dh.pUnlockStateFsm.PAdaptFsm.PFsm
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002927 //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore
2928 if (dh.pLockStateFsm != nil) &&
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002929 (dh.pLockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) {
2930 _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002931 }
2932 }
2933 if pLSStatemachine != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002934 if pLSStatemachine.Is(uniprt.UniStDisabled) {
2935 if err := pLSStatemachine.Event(uniprt.UniEvStart); err != nil {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00002936 logger.Warnw(ctx, "LockStateFSM: can't start", log.Fields{"device-id": dh.DeviceID, "err": err})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002937 // maybe try a FSM reset and then again ... - TODO!!!
2938 } else {
2939 /***** LockStateFSM started */
dbainbri4d3a0dc2020-12-02 00:33:42 +00002940 logger.Debugw(ctx, "LockStateFSM started", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002941 "state": pLSStatemachine.Current(), "device-id": dh.DeviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002942 }
2943 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002944 logger.Warnw(ctx, "wrong state of LockStateFSM - want: disabled", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002945 "have": pLSStatemachine.Current(), "device-id": dh.DeviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002946 // maybe try a FSM reset and then again ... - TODO!!!
2947 }
2948 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002949 logger.Errorw(ctx, "LockStateFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002950 // maybe try a FSM reset and then again ... - TODO!!!
2951 }
2952}
2953
mpagenko80622a52021-02-09 16:53:23 +00002954// createOnuUpgradeFsm initializes and runs the Onu Software upgrade FSM
mpagenko59862f02021-10-11 08:53:18 +00002955// precondition: lockUpgradeFsm is already locked from caller of this function
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002956func (dh *deviceHandler) createOnuUpgradeFsm(ctx context.Context, apDevEntry *mib.OnuDeviceEntry, aDevEvent cmn.OnuDeviceEvent) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002957 chUpgradeFsm := make(chan cmn.Message, 2048)
mpagenko80622a52021-02-09 16:53:23 +00002958 var sFsmName = "OnuSwUpgradeFSM"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002959 logger.Debugw(ctx, "create OnuSwUpgradeFSM", log.Fields{"device-id": dh.DeviceID})
mpagenko15ff4a52021-03-02 10:09:20 +00002960 if apDevEntry.PDevOmciCC == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002961 logger.Errorw(ctx, "no valid OnuDevice or omciCC - abort", log.Fields{"device-id": dh.DeviceID})
mpagenko15ff4a52021-03-02 10:09:20 +00002962 return fmt.Errorf(fmt.Sprintf("no valid omciCC - abort for device-id: %s", dh.device.Id))
mpagenko80622a52021-02-09 16:53:23 +00002963 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002964 dh.pOnuUpradeFsm = swupg.NewOnuUpgradeFsm(ctx, dh, apDevEntry, apDevEntry.GetOnuDB(), aDevEvent,
mpagenko80622a52021-02-09 16:53:23 +00002965 sFsmName, chUpgradeFsm)
2966 if dh.pOnuUpradeFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002967 pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm
mpagenko80622a52021-02-09 16:53:23 +00002968 if pUpgradeStatemachine != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002969 if pUpgradeStatemachine.Is(swupg.UpgradeStDisabled) {
2970 if err := pUpgradeStatemachine.Event(swupg.UpgradeEvStart); err != nil {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00002971 logger.Errorw(ctx, "OnuSwUpgradeFSM: can't start", log.Fields{"device-id": dh.DeviceID, "err": err})
mpagenko80622a52021-02-09 16:53:23 +00002972 // maybe try a FSM reset and then again ... - TODO!!!
2973 return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be started for device-id: %s", dh.device.Id))
2974 }
mpagenko59862f02021-10-11 08:53:18 +00002975 /***** Upgrade FSM started */
mpagenko45586762021-10-01 08:30:22 +00002976 //reset the last stored upgrade states (which anyway should be don't care as long as the newly created FSM exists)
2977 (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenko38662d02021-08-11 09:45:19 +00002978 (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR
2979 (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenko80622a52021-02-09 16:53:23 +00002980 logger.Debugw(ctx, "OnuSwUpgradeFSM started", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002981 "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID})
mpagenko80622a52021-02-09 16:53:23 +00002982 } else {
2983 logger.Errorw(ctx, "wrong state of OnuSwUpgradeFSM to start - want: disabled", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002984 "have": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID})
mpagenko80622a52021-02-09 16:53:23 +00002985 // maybe try a FSM reset and then again ... - TODO!!!
2986 return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be started for device-id: %s, wrong internal state", dh.device.Id))
2987 }
2988 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002989 logger.Errorw(ctx, "OnuSwUpgradeFSM internal FSM invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID})
mpagenko80622a52021-02-09 16:53:23 +00002990 // maybe try a FSM reset and then again ... - TODO!!!
2991 return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM internal FSM could not be created for device-id: %s", dh.device.Id))
2992 }
2993 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002994 logger.Errorw(ctx, "OnuSwUpgradeFSM could not be created - abort", log.Fields{"device-id": dh.DeviceID})
mpagenko80622a52021-02-09 16:53:23 +00002995 return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be created - abort for device-id: %s", dh.device.Id))
2996 }
2997 return nil
2998}
2999
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003000// RemoveOnuUpgradeFsm clears the Onu Software upgrade FSM
3001func (dh *deviceHandler) RemoveOnuUpgradeFsm(ctx context.Context, apImageState *voltha.ImageState) {
mpagenko80622a52021-02-09 16:53:23 +00003002 logger.Debugw(ctx, "remove OnuSwUpgradeFSM StateMachine", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003003 "device-id": dh.DeviceID})
mpagenko80622a52021-02-09 16:53:23 +00003004 dh.lockUpgradeFsm.Lock()
mpagenko59862f02021-10-11 08:53:18 +00003005 dh.pOnuUpradeFsm = nil //resource clearing is left to garbage collector
3006 dh.upgradeCanceled = false //cancelation done
mpagenko38662d02021-08-11 09:45:19 +00003007 dh.pLastUpgradeImageState = apImageState
3008 dh.lockUpgradeFsm.Unlock()
3009 //signal upgradeFsm removed using non-blocking channel send
3010 select {
3011 case dh.upgradeFsmChan <- struct{}{}:
3012 default:
3013 logger.Debugw(ctx, "removed-UpgradeFsm signal not send on upgradeFsmChan (no receiver)", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003014 "device-id": dh.DeviceID})
mpagenko38662d02021-08-11 09:45:19 +00003015 }
mpagenko80622a52021-02-09 16:53:23 +00003016}
3017
mpagenko15ff4a52021-03-02 10:09:20 +00003018// checkOnOnuImageCommit verifies if the ONU is in some upgrade state that allows for image commit and if tries to commit
3019func (dh *deviceHandler) checkOnOnuImageCommit(ctx context.Context) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003020 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
mpagenko15ff4a52021-03-02 10:09:20 +00003021 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003022 logger.Errorw(ctx, "No valid OnuDevice -aborting checkOnOnuImageCommit", log.Fields{"device-id": dh.DeviceID})
mpagenko15ff4a52021-03-02 10:09:20 +00003023 return
3024 }
3025
3026 dh.lockUpgradeFsm.RLock()
mpagenko59862f02021-10-11 08:53:18 +00003027 //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm()
mpagenko15ff4a52021-03-02 10:09:20 +00003028 if dh.pOnuUpradeFsm != nil {
mpagenko59862f02021-10-11 08:53:18 +00003029 if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation
3030 dh.lockUpgradeFsm.RUnlock()
3031 logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID})
3032 return
3033 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003034 pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm
mpagenko15ff4a52021-03-02 10:09:20 +00003035 if pUpgradeStatemachine != nil {
3036 // commit is only processed in case out upgrade FSM indicates the according state (for automatic commit)
3037 // (some manual forced commit could do without)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003038 UpgradeState := pUpgradeStatemachine.Current()
3039 if (UpgradeState == swupg.UpgradeStWaitForCommit) ||
3040 (UpgradeState == swupg.UpgradeStRequestingActivate) {
3041 // also include UpgradeStRequestingActivate as it may be left in case the ActivateResponse just got lost
mpagenko183647c2021-06-08 15:25:04 +00003042 // here no need to update the upgrade image state to activated as the state will be immediately be set to committing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003043 if pDevEntry.IsImageToBeCommitted(ctx, dh.pOnuUpradeFsm.InactiveImageMeID) {
mpagenko1f8e8822021-06-25 14:10:21 +00003044 activeImageID, errImg := pDevEntry.GetActiveImageMeID(ctx)
3045 if errImg != nil {
mpagenko59862f02021-10-11 08:53:18 +00003046 dh.lockUpgradeFsm.RUnlock()
mpagenko1f8e8822021-06-25 14:10:21 +00003047 logger.Errorw(ctx, "OnuSwUpgradeFSM abort - could not get active image after reboot",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003048 log.Fields{"device-id": dh.DeviceID})
mpagenko59862f02021-10-11 08:53:18 +00003049 if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation
3050 dh.upgradeCanceled = true
3051 dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort
3052 }
mpagenko15ff4a52021-03-02 10:09:20 +00003053 return
3054 }
mpagenko59862f02021-10-11 08:53:18 +00003055 dh.lockUpgradeFsm.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003056 if activeImageID == dh.pOnuUpradeFsm.InactiveImageMeID {
3057 if (UpgradeState == swupg.UpgradeStRequestingActivate) && !dh.pOnuUpradeFsm.GetCommitFlag(ctx) {
mpagenko1f8e8822021-06-25 14:10:21 +00003058 // if FSM was waiting on activateResponse, new image is active, but FSM shall not commit, then:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003059 if err := pUpgradeStatemachine.Event(swupg.UpgradeEvActivationDone); err != nil {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00003060 logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call activate-done event",
3061 log.Fields{"device-id": dh.DeviceID, "err": err})
mpagenko1f8e8822021-06-25 14:10:21 +00003062 return
3063 }
3064 logger.Debugw(ctx, "OnuSwUpgradeFSM activate-done after reboot", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003065 "state": UpgradeState, "device-id": dh.DeviceID})
mpagenko1f8e8822021-06-25 14:10:21 +00003066 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003067 //FSM in waitForCommit or (UpgradeStRequestingActivate [lost ActivateResp] and commit allowed)
3068 if err := pUpgradeStatemachine.Event(swupg.UpgradeEvCommitSw); err != nil {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00003069 logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call commit event",
3070 log.Fields{"device-id": dh.DeviceID, "err": err})
mpagenko1f8e8822021-06-25 14:10:21 +00003071 return
3072 }
3073 logger.Debugw(ctx, "OnuSwUpgradeFSM commit image requested", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003074 "state": UpgradeState, "device-id": dh.DeviceID})
mpagenko1f8e8822021-06-25 14:10:21 +00003075 }
3076 } else {
3077 logger.Errorw(ctx, "OnuSwUpgradeFSM waiting to commit/on ActivateResponse, but load did not start with expected image Id",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003078 log.Fields{"device-id": dh.DeviceID})
mpagenkoa2b288f2021-10-21 11:25:27 +00003079 if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation
3080 dh.upgradeCanceled = true
3081 dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort
3082 }
mpagenko1f8e8822021-06-25 14:10:21 +00003083 }
mpagenko15ff4a52021-03-02 10:09:20 +00003084 return
3085 }
mpagenko59862f02021-10-11 08:53:18 +00003086 dh.lockUpgradeFsm.RUnlock()
3087 logger.Errorw(ctx, "OnuSwUpgradeFSM waiting to commit, but nothing to commit on ONU - abort upgrade",
3088 log.Fields{"device-id": dh.DeviceID})
mpagenkoa2b288f2021-10-21 11:25:27 +00003089 if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation
3090 dh.upgradeCanceled = true
3091 dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort
3092 }
mpagenko59862f02021-10-11 08:53:18 +00003093 return
3094 }
3095 //upgrade FSM is active but not waiting for commit: maybe because commit flag is not set
3096 // upgrade FSM is to be informed if the current active image is the one that was used in upgrade for the download
3097 if activeImageID, err := pDevEntry.GetActiveImageMeID(ctx); err == nil {
3098 if dh.pOnuUpradeFsm.InactiveImageMeID == activeImageID {
3099 logger.Debugw(ctx, "OnuSwUpgradeFSM image state set to activated", log.Fields{
3100 "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID})
3101 dh.pOnuUpradeFsm.SetImageStateActive(ctx)
mpagenko183647c2021-06-08 15:25:04 +00003102 }
mpagenko15ff4a52021-03-02 10:09:20 +00003103 }
3104 }
3105 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003106 logger.Debugw(ctx, "no ONU image to be committed", log.Fields{"device-id": dh.DeviceID})
mpagenko15ff4a52021-03-02 10:09:20 +00003107 }
mpagenko59862f02021-10-11 08:53:18 +00003108 dh.lockUpgradeFsm.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00003109}
3110
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003111//SetBackend provides a DB backend for the specified path on the existing KV client
3112func (dh *deviceHandler) SetBackend(ctx context.Context, aBasePathKvStore string) *db.Backend {
Matteo Scandolo127c59d2021-01-28 11:31:18 -08003113
3114 logger.Debugw(ctx, "SetKVStoreBackend", log.Fields{"IpTarget": dh.pOpenOnuAc.KVStoreAddress,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003115 "BasePathKvStore": aBasePathKvStore, "device-id": dh.DeviceID})
Girish Gowdra50e56422021-06-01 16:46:04 -07003116 // kvbackend := db.NewBackend(ctx, dh.pOpenOnuAc.KVStoreType, dh.pOpenOnuAc.KVStoreAddress, dh.pOpenOnuAc.KVStoreTimeout, aBasePathKvStore)
mpagenkoaf801632020-07-03 10:00:42 +00003117 kvbackend := &db.Backend{
3118 Client: dh.pOpenOnuAc.kvClient,
3119 StoreType: dh.pOpenOnuAc.KVStoreType,
3120 /* address config update acc. to [VOL-2736] */
Matteo Scandolo127c59d2021-01-28 11:31:18 -08003121 Address: dh.pOpenOnuAc.KVStoreAddress,
mpagenkoaf801632020-07-03 10:00:42 +00003122 Timeout: dh.pOpenOnuAc.KVStoreTimeout,
3123 PathPrefix: aBasePathKvStore}
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00003124
mpagenkoaf801632020-07-03 10:00:42 +00003125 return kvbackend
Holger Hildebrandt24d51952020-05-04 14:03:42 +00003126}
khenaidoo7d3c5582021-08-11 18:09:44 -04003127func (dh *deviceHandler) getFlowOfbFields(ctx context.Context, apFlowItem *of.OfpFlowStats, loMatchVlan *uint16,
Abhilash Laxmeshwarc7c29d82022-03-03 18:38:45 +05303128 loMatchPcp *uint8, loIPProto *uint32) {
mpagenkodff5dda2020-08-28 11:52:01 +00003129
mpagenkodff5dda2020-08-28 11:52:01 +00003130 for _, field := range flow.GetOfbFields(apFlowItem) {
3131 switch field.Type {
3132 case of.OxmOfbFieldTypes_OFPXMT_OFB_ETH_TYPE:
3133 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003134 logger.Debugw(ctx, "flow type EthType", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00003135 "EthType": strconv.FormatInt(int64(field.GetEthType()), 16)})
3136 }
mpagenko01e726e2020-10-23 09:45:29 +00003137 /* TT related temporary workaround - should not be needed anymore
mpagenkodff5dda2020-08-28 11:52:01 +00003138 case of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO:
3139 {
Himani Chawla26e555c2020-08-31 12:30:20 +05303140 *loIPProto = field.GetIpProto()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003141 logger.Debugw("flow type IpProto", log.Fields{"device-id": dh.DeviceID,
Himani Chawla26e555c2020-08-31 12:30:20 +05303142 "IpProto": strconv.FormatInt(int64(*loIPProto), 16)})
3143 if *loIPProto == 2 {
mpagenkodff5dda2020-08-28 11:52:01 +00003144 // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow
3145 // avoids installing invalid EVTOCD rule
mpagenko01e726e2020-10-23 09:45:29 +00003146 logger.Debugw("flow type IpProto 2: TT workaround: ignore flow",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003147 log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05303148 return
mpagenkodff5dda2020-08-28 11:52:01 +00003149 }
3150 }
mpagenko01e726e2020-10-23 09:45:29 +00003151 */
mpagenkodff5dda2020-08-28 11:52:01 +00003152 case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID:
3153 {
Himani Chawla26e555c2020-08-31 12:30:20 +05303154 *loMatchVlan = uint16(field.GetVlanVid())
mpagenkodff5dda2020-08-28 11:52:01 +00003155 loMatchVlanMask := uint16(field.GetVlanVidMask())
Himani Chawla26e555c2020-08-31 12:30:20 +05303156 if !(*loMatchVlan == uint16(of.OfpVlanId_OFPVID_PRESENT) &&
mpagenkodff5dda2020-08-28 11:52:01 +00003157 loMatchVlanMask == uint16(of.OfpVlanId_OFPVID_PRESENT)) {
Himani Chawla26e555c2020-08-31 12:30:20 +05303158 *loMatchVlan = *loMatchVlan & 0xFFF // not transparent: copy only ID bits
mpagenkodff5dda2020-08-28 11:52:01 +00003159 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003160 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
Himani Chawla26e555c2020-08-31 12:30:20 +05303161 "VID": strconv.FormatInt(int64(*loMatchVlan), 16)})
mpagenkodff5dda2020-08-28 11:52:01 +00003162 }
3163 case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP:
3164 {
Abhilash Laxmeshwarc7c29d82022-03-03 18:38:45 +05303165 *loMatchPcp = uint8(field.GetVlanPcp())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003166 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
Abhilash Laxmeshwarc7c29d82022-03-03 18:38:45 +05303167 "PCP": loMatchPcp})
mpagenkodff5dda2020-08-28 11:52:01 +00003168 }
3169 case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_DST:
3170 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003171 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00003172 "UDP-DST": strconv.FormatInt(int64(field.GetUdpDst()), 16)})
3173 }
3174 case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_SRC:
3175 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003176 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00003177 "UDP-SRC": strconv.FormatInt(int64(field.GetUdpSrc()), 16)})
3178 }
3179 case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_DST:
3180 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003181 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00003182 "IPv4-DST": field.GetIpv4Dst()})
3183 }
3184 case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_SRC:
3185 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003186 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00003187 "IPv4-SRC": field.GetIpv4Src()})
3188 }
3189 case of.OxmOfbFieldTypes_OFPXMT_OFB_METADATA:
3190 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003191 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00003192 "Metadata": field.GetTableMetadata()})
3193 }
3194 /*
3195 default:
3196 {
3197 //all other entires ignored
3198 }
3199 */
3200 }
3201 } //for all OfbFields
Himani Chawla26e555c2020-08-31 12:30:20 +05303202}
mpagenkodff5dda2020-08-28 11:52:01 +00003203
khenaidoo7d3c5582021-08-11 18:09:44 -04003204func (dh *deviceHandler) getFlowActions(ctx context.Context, apFlowItem *of.OfpFlowStats, loSetPcp *uint8, loSetVlan *uint16) {
mpagenkodff5dda2020-08-28 11:52:01 +00003205 for _, action := range flow.GetActions(apFlowItem) {
3206 switch action.Type {
3207 /* not used:
3208 case of.OfpActionType_OFPAT_OUTPUT:
3209 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003210 logger.Debugw("flow action type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00003211 "Output": action.GetOutput()})
3212 }
3213 */
3214 case of.OfpActionType_OFPAT_PUSH_VLAN:
3215 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003216 logger.Debugw(ctx, "flow action type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00003217 "PushEthType": strconv.FormatInt(int64(action.GetPush().Ethertype), 16)})
3218 }
3219 case of.OfpActionType_OFPAT_SET_FIELD:
3220 {
3221 pActionSetField := action.GetSetField()
3222 if pActionSetField.Field.OxmClass != of.OfpOxmClass_OFPXMC_OPENFLOW_BASIC {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003223 logger.Warnw(ctx, "flow action SetField invalid OxmClass (ignored)", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00003224 "OxcmClass": pActionSetField.Field.OxmClass})
3225 }
3226 if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID {
Himani Chawla26e555c2020-08-31 12:30:20 +05303227 *loSetVlan = uint16(pActionSetField.Field.GetOfbField().GetVlanVid())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003228 logger.Debugw(ctx, "flow Set VLAN from SetField action", log.Fields{"device-id": dh.DeviceID,
Himani Chawla26e555c2020-08-31 12:30:20 +05303229 "SetVlan": strconv.FormatInt(int64(*loSetVlan), 16)})
mpagenkodff5dda2020-08-28 11:52:01 +00003230 } else if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP {
Himani Chawla26e555c2020-08-31 12:30:20 +05303231 *loSetPcp = uint8(pActionSetField.Field.GetOfbField().GetVlanPcp())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003232 logger.Debugw(ctx, "flow Set PCP from SetField action", log.Fields{"device-id": dh.DeviceID,
Himani Chawla26e555c2020-08-31 12:30:20 +05303233 "SetPcp": *loSetPcp})
mpagenkodff5dda2020-08-28 11:52:01 +00003234 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003235 logger.Warnw(ctx, "flow action SetField invalid FieldType", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00003236 "Type": pActionSetField.Field.GetOfbField().Type})
3237 }
3238 }
3239 /*
3240 default:
3241 {
3242 //all other entires ignored
3243 }
3244 */
3245 }
3246 } //for all Actions
Himani Chawla26e555c2020-08-31 12:30:20 +05303247}
3248
3249//addFlowItemToUniPort parses the actual flow item to add it to the UniPort
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003250func (dh *deviceHandler) addFlowItemToUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort,
khenaidoo42dcdfd2021-10-19 17:34:12 -04003251 apFlowMetaData *of.FlowMetadata, respChan *chan error) {
Himani Chawla26e555c2020-08-31 12:30:20 +05303252 var loSetVlan uint16 = uint16(of.OfpVlanId_OFPVID_NONE) //noValidEntry
3253 var loMatchVlan uint16 = uint16(of.OfpVlanId_OFPVID_PRESENT) //reserved VLANID entry
Abhilash Laxmeshwarc7c29d82022-03-03 18:38:45 +05303254 var loSetPcp uint8
3255 var loMatchPcp uint8 = 8 // could the const 'cPrioDoNotFilter' be used from omci_vlan_config.go ?
Himani Chawla26e555c2020-08-31 12:30:20 +05303256 var loIPProto uint32
3257 /* the TechProfileId is part of the flow Metadata - compare also comment within
3258 * OLT-Adapter:openolt_flowmgr.go
3259 * Metadata 8 bytes:
3260 * Most Significant 2 Bytes = Inner VLAN
3261 * Next 2 Bytes = Tech Profile ID(TPID)
3262 * Least Significant 4 Bytes = Port ID
3263 * Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all
3264 * subscriber related flows.
3265 */
3266
dbainbri4d3a0dc2020-12-02 00:33:42 +00003267 metadata := flow.GetMetadataFromWriteMetadataAction(ctx, apFlowItem)
Himani Chawla26e555c2020-08-31 12:30:20 +05303268 if metadata == 0 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003269 logger.Debugw(ctx, "flow-add invalid metadata - abort",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003270 log.Fields{"device-id": dh.DeviceID})
Girish Gowdrae95687a2021-09-08 16:30:58 -07003271 *respChan <- fmt.Errorf("flow-add invalid metadata: %s", dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +05303272 }
mpagenko551a4d42020-12-08 18:09:20 +00003273 loTpID := uint8(flow.GetTechProfileIDFromWriteMetaData(ctx, metadata))
mpagenko01e726e2020-10-23 09:45:29 +00003274 loCookie := apFlowItem.GetCookie()
3275 loCookieSlice := []uint64{loCookie}
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05303276 loInnerCvlan := flow.GetInnerTagFromWriteMetaData(ctx, metadata)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003277 logger.Debugw(ctx, "flow-add base indications", log.Fields{"device-id": dh.DeviceID,
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05303278 "TechProf-Id": loTpID, "cookie": loCookie, "innerCvlan": loInnerCvlan})
Himani Chawla26e555c2020-08-31 12:30:20 +05303279
Abhilash Laxmeshwarc7c29d82022-03-03 18:38:45 +05303280 dh.getFlowOfbFields(ctx, apFlowItem, &loMatchVlan, &loMatchPcp, &loIPProto)
mpagenko01e726e2020-10-23 09:45:29 +00003281 /* TT related temporary workaround - should not be needed anymore
Himani Chawla26e555c2020-08-31 12:30:20 +05303282 if loIPProto == 2 {
3283 // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow
3284 // avoids installing invalid EVTOCD rule
mpagenko01e726e2020-10-23 09:45:29 +00003285 logger.Debugw("flow-add type IpProto 2: TT workaround: ignore flow",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003286 log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05303287 return nil
3288 }
mpagenko01e726e2020-10-23 09:45:29 +00003289 */
dbainbri4d3a0dc2020-12-02 00:33:42 +00003290 dh.getFlowActions(ctx, apFlowItem, &loSetPcp, &loSetVlan)
mpagenkodff5dda2020-08-28 11:52:01 +00003291
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05303292 if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) && (loMatchPcp == 8) &&
3293 loInnerCvlan == uint16(of.OfpVlanId_OFPVID_NONE) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003294 logger.Errorw(ctx, "flow-add aborted - SetVlanId undefined, but MatchVid set", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003295 "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo,
mpagenkodff5dda2020-08-28 11:52:01 +00003296 "set_vid": strconv.FormatInt(int64(loSetVlan), 16),
3297 "match_vid": strconv.FormatInt(int64(loMatchVlan), 16)})
3298 //TODO!!: Use DeviceId within the error response to rwCore
3299 // likewise also in other error response cases to calling components as requested in [VOL-3458]
Girish Gowdrae95687a2021-09-08 16:30:58 -07003300 *respChan <- fmt.Errorf("flow-add Set/Match VlanId inconsistent: %s", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00003301 }
3302 if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan == uint16(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003303 logger.Debugw(ctx, "flow-add vlan-any/copy", log.Fields{"device-id": dh.DeviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00003304 loSetVlan = loMatchVlan //both 'transparent' (copy any)
3305 } else {
3306 //looks like OMCI value 4097 (copyFromOuter - for Uni double tagged) is not supported here
3307 if loSetVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) {
3308 // not set to transparent
Himani Chawla26e555c2020-08-31 12:30:20 +05303309 loSetVlan &= 0x0FFF //mask VID bits as prerequisite for vlanConfigFsm
mpagenkodff5dda2020-08-28 11:52:01 +00003310 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003311 logger.Debugw(ctx, "flow-add vlan-set", log.Fields{"device-id": dh.DeviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00003312 }
mpagenko9a304ea2020-12-16 15:54:01 +00003313
khenaidoo42dcdfd2021-10-19 17:34:12 -04003314 var meter *of.OfpMeterConfig
ozgecanetsia82b91a62021-05-21 18:54:49 +03003315 if apFlowMetaData != nil {
3316 meter = apFlowMetaData.Meters[0]
3317 }
mpagenkobc4170a2021-08-17 16:42:10 +00003318 //mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities
3319 // must be set including the execution of createVlanFilterFsm() to avoid unintended creation of FSM's
3320 // when different rules are requested concurrently for the same uni
3321 // (also vlan persistency data does not support multiple FSM's on the same UNI correctly!)
3322 dh.lockVlanAdd.Lock() //prevent multiple add activities to start in parallel
3323 dh.lockVlanConfig.RLock() //read protection on UniVlanConfigFsmMap (removeFlowItemFromUniPort)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003324 logger.Debugw(ctx, "flow-add got lock", log.Fields{"device-id": dh.DeviceID, "tpID": loTpID, "uniID": apUniPort.UniID})
3325 if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist {
mpagenkobc4170a2021-08-17 16:42:10 +00003326 //SetUniFlowParams() may block on some rule that is suspended-to-add
3327 // in order to allow for according flow removal lockVlanConfig may only be used with RLock here
Girish Gowdrae95687a2021-09-08 16:30:58 -07003328 // Also the error is returned to caller via response channel
3329 _ = dh.UniVlanConfigFsmMap[apUniPort.UniID].SetUniFlowParams(ctx, loTpID, loCookieSlice,
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05303330 loMatchVlan, loMatchPcp, loSetVlan, loSetPcp, loInnerCvlan, false, meter, respChan)
mpagenkobc4170a2021-08-17 16:42:10 +00003331 dh.lockVlanConfig.RUnlock()
3332 dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing
Girish Gowdrae95687a2021-09-08 16:30:58 -07003333 return
mpagenkodff5dda2020-08-28 11:52:01 +00003334 }
mpagenkobc4170a2021-08-17 16:42:10 +00003335 dh.lockVlanConfig.RUnlock()
3336 dh.lockVlanConfig.Lock() //createVlanFilterFsm should always be a non-blocking operation and requires r+w lock
mpagenko7d14de12021-07-27 08:31:56 +00003337 err := dh.createVlanFilterFsm(ctx, apUniPort, loTpID, loCookieSlice,
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05303338 loMatchVlan, loMatchPcp, loSetVlan, loSetPcp, loInnerCvlan, cmn.OmciVlanFilterAddDone, false, meter, respChan)
mpagenko7d14de12021-07-27 08:31:56 +00003339 dh.lockVlanConfig.Unlock()
mpagenkobc4170a2021-08-17 16:42:10 +00003340 dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing
Girish Gowdrae95687a2021-09-08 16:30:58 -07003341 if err != nil {
3342 *respChan <- err
3343 }
mpagenko01e726e2020-10-23 09:45:29 +00003344}
3345
3346//removeFlowItemFromUniPort parses the actual flow item to remove it from the UniPort
Girish Gowdrae95687a2021-09-08 16:30:58 -07003347func (dh *deviceHandler) removeFlowItemFromUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort, respChan *chan error) {
mpagenko01e726e2020-10-23 09:45:29 +00003348 //optimization and assumption: the flow cookie uniquely identifies the flow and with that the internal rule
3349 //hence only the cookie is used here to find the relevant flow and possibly remove the rule
3350 //no extra check is done on the rule parameters
3351 //accordingly the removal is done only once - for the first found flow with that cookie, even though
3352 // at flow creation is not assured, that the same cookie is not configured for different flows - just assumed
3353 //additionally it is assumed here, that removal can only be done for one cookie per flow in a sequence (different
3354 // from addFlow - where at reconcilement multiple cookies per flow ) can be configured in one sequence)
mpagenkofc4f56e2020-11-04 17:17:49 +00003355 // - some possible 'delete-all' sequence would have to be implemented separately (where the cookies are don't care anyway)
mpagenko01e726e2020-10-23 09:45:29 +00003356 loCookie := apFlowItem.GetCookie()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003357 logger.Debugw(ctx, "flow-remove base indications", log.Fields{"device-id": dh.DeviceID, "cookie": loCookie})
mpagenko01e726e2020-10-23 09:45:29 +00003358
3359 /* TT related temporary workaround - should not be needed anymore
3360 for _, field := range flow.GetOfbFields(apFlowItem) {
3361 if field.Type == of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO {
3362 loIPProto := field.GetIpProto()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003363 logger.Debugw(ctx, "flow type IpProto", log.Fields{"device-id": dh.DeviceID,
mpagenko01e726e2020-10-23 09:45:29 +00003364 "IpProto": strconv.FormatInt(int64(loIPProto), 16)})
3365 if loIPProto == 2 {
3366 // some workaround for TT workflow on proto == 2 (IGMP trap) -> the flow was not added, no need to remove
mpagenko551a4d42020-12-08 18:09:20 +00003367 logger.Debugw(ctx, "flow-remove type IpProto 2: TT workaround: ignore flow",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003368 log.Fields{"device-id": dh.DeviceID})
mpagenko01e726e2020-10-23 09:45:29 +00003369 return nil
3370 }
3371 }
3372 } //for all OfbFields
3373 */
3374
mpagenko9a304ea2020-12-16 15:54:01 +00003375 //mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities
mpagenkof1fc3862021-02-16 10:09:52 +00003376 dh.lockVlanConfig.RLock()
3377 defer dh.lockVlanConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003378 logger.Debugw(ctx, "flow-remove got RLock", log.Fields{"device-id": dh.DeviceID, "uniID": apUniPort.UniID})
3379 if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist {
Girish Gowdrae95687a2021-09-08 16:30:58 -07003380 _ = dh.UniVlanConfigFsmMap[apUniPort.UniID].RemoveUniFlowParams(ctx, loCookie, respChan)
3381 return
mpagenko01e726e2020-10-23 09:45:29 +00003382 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00003383 logger.Debugw(ctx, "flow-remove called, but no flow is configured (no VlanConfigFsm, flow already removed) ",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003384 log.Fields{"device-id": dh.DeviceID})
mpagenko01e726e2020-10-23 09:45:29 +00003385 //but as we regard the flow as not existing = removed we respond just ok
mpagenkofc4f56e2020-11-04 17:17:49 +00003386 // and treat the reason accordingly (which in the normal removal procedure is initiated by the FSM)
Girish Gowdrae95687a2021-09-08 16:30:58 -07003387 // Push response on the response channel
3388 if respChan != nil {
3389 // Do it in a non blocking fashion, so that in case the flow handler routine has shutdown for any reason, we do not block here
3390 select {
3391 case *respChan <- nil:
3392 logger.Debugw(ctx, "submitted-response-for-flow", log.Fields{"device-id": dh.DeviceID, "err": nil})
3393 default:
3394 }
3395 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003396 go dh.DeviceProcStatusUpdate(ctx, cmn.OmciVlanFilterRemDone)
mpagenkodff5dda2020-08-28 11:52:01 +00003397}
3398
Himani Chawla26e555c2020-08-31 12:30:20 +05303399// createVlanFilterFsm initializes and runs the VlanFilter FSM to transfer OMCI related VLAN config
mpagenko9a304ea2020-12-16 15:54:01 +00003400// if this function is called from possibly concurrent processes it must be mutex-protected from the caller!
mpagenko7d14de12021-07-27 08:31:56 +00003401// precondition: dh.lockVlanConfig is locked by the caller!
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003402func (dh *deviceHandler) createVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8, aCookieSlice []uint64,
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05303403 aMatchVlan uint16, aMatchPcp uint8, aSetVlan uint16, aSetPcp uint8, innerCvlan uint16, aDevEvent cmn.OnuDeviceEvent, lastFlowToReconcile bool, aMeter *of.OfpMeterConfig, respChan *chan error) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003404 chVlanFilterFsm := make(chan cmn.Message, 2048)
mpagenkodff5dda2020-08-28 11:52:01 +00003405
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003406 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
mpagenkodff5dda2020-08-28 11:52:01 +00003407 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003408 logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
3409 return fmt.Errorf("no valid OnuDevice for device-id %x - aborting", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00003410 }
3411
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003412 pVlanFilterFsm := avcfg.NewUniVlanConfigFsm(ctx, dh, pDevEntry, pDevEntry.PDevOmciCC, apUniPort, dh.pOnuTP,
3413 pDevEntry.GetOnuDB(), aTpID, aDevEvent, "UniVlanConfigFsm", chVlanFilterFsm,
Abhilash Laxmeshwar81b5ccf2022-03-17 15:04:18 +05303414 dh.pOpenOnuAc.AcceptIncrementalEvto, aCookieSlice, aMatchVlan, aMatchPcp, aSetVlan, aSetPcp, innerCvlan, lastFlowToReconcile, aMeter, respChan)
mpagenkodff5dda2020-08-28 11:52:01 +00003415 if pVlanFilterFsm != nil {
mpagenko7d14de12021-07-27 08:31:56 +00003416 //dh.lockVlanConfig is locked (by caller) throughout the state transition to 'starting'
3417 // to prevent unintended (ignored) events to be sent there (from parallel processing)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003418 dh.UniVlanConfigFsmMap[apUniPort.UniID] = pVlanFilterFsm
3419 pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm
mpagenkodff5dda2020-08-28 11:52:01 +00003420 if pVlanFilterStatemachine != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003421 if pVlanFilterStatemachine.Is(avcfg.VlanStDisabled) {
3422 if err := pVlanFilterStatemachine.Event(avcfg.VlanEvStart); err != nil {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00003423 logger.Warnw(ctx, "UniVlanConfigFsm: can't start",
3424 log.Fields{"device-id": dh.DeviceID, "err": err})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003425 return fmt.Errorf("can't start UniVlanConfigFsm for device-id %x", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00003426 }
Himani Chawla26e555c2020-08-31 12:30:20 +05303427 /***** UniVlanConfigFsm started */
dbainbri4d3a0dc2020-12-02 00:33:42 +00003428 logger.Debugw(ctx, "UniVlanConfigFsm started", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003429 "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
3430 "UniPort": apUniPort.PortNo})
mpagenkodff5dda2020-08-28 11:52:01 +00003431 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003432 logger.Warnw(ctx, "wrong state of UniVlanConfigFsm - want: disabled", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003433 "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID})
3434 return fmt.Errorf("uniVlanConfigFsm not in expected disabled state for device-id %x", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00003435 }
3436 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003437 logger.Errorw(ctx, "UniVlanConfigFsm StateMachine invalid - cannot be executed!!", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003438 "device-id": dh.DeviceID})
3439 return fmt.Errorf("uniVlanConfigFsm invalid for device-id %x", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00003440 }
3441 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003442 logger.Errorw(ctx, "UniVlanConfigFsm could not be created - abort!!", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003443 "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo})
3444 return fmt.Errorf("uniVlanConfigFsm could not be created for device-id %x", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00003445 }
3446 return nil
3447}
3448
mpagenkofc4f56e2020-11-04 17:17:49 +00003449//VerifyVlanConfigRequest checks on existence of a given uniPort
3450// and starts verification of flow config based on that
mpagenko551a4d42020-12-08 18:09:20 +00003451func (dh *deviceHandler) VerifyVlanConfigRequest(ctx context.Context, aUniID uint8, aTpID uint8) {
mpagenkofc4f56e2020-11-04 17:17:49 +00003452 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003453 var pCurrentUniPort *cmn.OnuUniPort
mpagenkofc4f56e2020-11-04 17:17:49 +00003454 for _, uniPort := range dh.uniEntityMap {
3455 // only if this port is validated for operState transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003456 if uniPort.UniID == uint8(aUniID) {
mpagenkofc4f56e2020-11-04 17:17:49 +00003457 pCurrentUniPort = uniPort
3458 break //found - end search loop
3459 }
3460 }
3461 if pCurrentUniPort == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003462 logger.Debugw(ctx, "VerifyVlanConfig aborted: requested uniID not found in PortDB",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003463 log.Fields{"device-id": dh.DeviceID, "uni-id": aUniID})
mpagenkofc4f56e2020-11-04 17:17:49 +00003464 return
3465 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003466 dh.VerifyUniVlanConfigRequest(ctx, pCurrentUniPort, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +00003467}
3468
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003469//VerifyUniVlanConfigRequest checks on existence of flow configuration and starts it accordingly
3470func (dh *deviceHandler) VerifyUniVlanConfigRequest(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8) {
mpagenkodff5dda2020-08-28 11:52:01 +00003471 //TODO!! verify and start pending flow configuration
3472 //some pending config request my exist in case the UniVlanConfig FSM was already started - with internal data -
3473 //but execution was set to 'on hold' as first the TechProfile config had to be applied
mpagenkof1fc3862021-02-16 10:09:52 +00003474
3475 dh.lockVlanConfig.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003476 if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist {
mpagenkof1fc3862021-02-16 10:09:52 +00003477 dh.lockVlanConfig.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00003478 //VlanFilterFsm exists and was already started (assumed to wait for TechProfile execution here)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003479 pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm
mpagenkodff5dda2020-08-28 11:52:01 +00003480 if pVlanFilterStatemachine != nil {
mpagenko551a4d42020-12-08 18:09:20 +00003481 //if this was an event of the TP processing that was waited for in the VlanFilterFsm
Holger Hildebrandtc192bc42021-10-28 14:38:31 +00003482 if pVlanFilterFsm.GetWaitingTpID(ctx) == aTpID {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003483 if pVlanFilterStatemachine.Is(avcfg.VlanStWaitingTechProf) {
3484 if err := pVlanFilterStatemachine.Event(avcfg.VlanEvContinueConfig); err != nil {
mpagenko551a4d42020-12-08 18:09:20 +00003485 logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003486 "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo})
mpagenko551a4d42020-12-08 18:09:20 +00003487 } else {
3488 /***** UniVlanConfigFsm continued */
3489 logger.Debugw(ctx, "UniVlanConfigFsm continued", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003490 "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
3491 "UniPort": apUniPort.PortNo})
mpagenko551a4d42020-12-08 18:09:20 +00003492 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003493 } else if pVlanFilterStatemachine.Is(avcfg.VlanStIncrFlowWaitTP) {
3494 if err := pVlanFilterStatemachine.Event(avcfg.VlanEvIncrFlowConfig); err != nil {
mpagenko551a4d42020-12-08 18:09:20 +00003495 logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003496 "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo})
mpagenko551a4d42020-12-08 18:09:20 +00003497 } else {
3498 /***** UniVlanConfigFsm continued */
3499 logger.Debugw(ctx, "UniVlanConfigFsm continued with incremental flow", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003500 "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
3501 "UniPort": apUniPort.PortNo})
mpagenko551a4d42020-12-08 18:09:20 +00003502 }
mpagenkodff5dda2020-08-28 11:52:01 +00003503 } else {
mpagenko551a4d42020-12-08 18:09:20 +00003504 logger.Debugw(ctx, "no state of UniVlanConfigFsm to be continued", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003505 "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
3506 "UniPort": apUniPort.PortNo})
mpagenkodff5dda2020-08-28 11:52:01 +00003507 }
3508 } else {
mpagenko551a4d42020-12-08 18:09:20 +00003509 logger.Debugw(ctx, "TechProfile Ready event for TpId that was not waited for in the VlanConfigFsm - continue waiting", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003510 "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
3511 "UniPort": apUniPort.PortNo, "techprofile-id (done)": aTpID})
mpagenkodff5dda2020-08-28 11:52:01 +00003512 }
3513 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003514 logger.Debugw(ctx, "UniVlanConfigFsm StateMachine does not exist, no flow processing", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003515 "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo})
mpagenkodff5dda2020-08-28 11:52:01 +00003516 }
mpagenkof1fc3862021-02-16 10:09:52 +00003517 } else {
3518 dh.lockVlanConfig.RUnlock()
3519 }
mpagenkodff5dda2020-08-28 11:52:01 +00003520}
3521
3522//RemoveVlanFilterFsm deletes the stored pointer to the VlanConfigFsm
3523// intention is to provide this method to be called from VlanConfigFsm itself, when resources (and methods!) are cleaned up
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003524func (dh *deviceHandler) RemoveVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003525 logger.Debugw(ctx, "remove UniVlanConfigFsm StateMachine", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003526 "device-id": dh.DeviceID, "uniPort": apUniPort.PortNo})
mpagenkodff5dda2020-08-28 11:52:01 +00003527 //save to do, even if entry dows not exist
mpagenkof1fc3862021-02-16 10:09:52 +00003528 dh.lockVlanConfig.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003529 delete(dh.UniVlanConfigFsmMap, apUniPort.UniID)
mpagenkof1fc3862021-02-16 10:09:52 +00003530 dh.lockVlanConfig.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00003531}
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003532
mpagenkof1fc3862021-02-16 10:09:52 +00003533//startWritingOnuDataToKvStore initiates the KVStore write of ONU persistent data
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003534func (dh *deviceHandler) startWritingOnuDataToKvStore(ctx context.Context, aPDevEntry *mib.OnuDeviceEntry) error {
mpagenkof1fc3862021-02-16 10:09:52 +00003535 dh.mutexKvStoreContext.Lock() //this write routine may (could) be called with the same context,
3536 defer dh.mutexKvStoreContext.Unlock() //this write routine may (could) be called with the same context,
3537 // obviously then parallel processing on the cancel must be avoided
3538 // deadline context to ensure completion of background routines waited for
3539 //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
3540 deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
3541 dctx, cancel := context.WithDeadline(context.Background(), deadline)
3542
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003543 aPDevEntry.ResetKvProcessingErrorIndication()
mpagenkof1fc3862021-02-16 10:09:52 +00003544 var wg sync.WaitGroup
3545 wg.Add(1) // for the 1 go routine to finish
3546
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003547 go aPDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg)
mpagenkof1fc3862021-02-16 10:09:52 +00003548 dh.waitForCompletion(ctx, cancel, &wg, "UpdateKvStore") //wait for background process to finish
3549
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003550 return aPDevEntry.GetKvProcessingErrorIndication()
mpagenkof1fc3862021-02-16 10:09:52 +00003551}
3552
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003553//StorePersUniFlowConfig updates local storage of OnuUniFlowConfig and writes it into kv-store afterwards to have it
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003554//available for potential reconcilement
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003555func (dh *deviceHandler) StorePersUniFlowConfig(ctx context.Context, aUniID uint8,
3556 aUniVlanFlowParams *[]cmn.UniVlanFlowParams, aWriteToKvStore bool) error {
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003557
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003558 if dh.IsReconciling() {
3559 logger.Debugw(ctx, "reconciling - don't store persistent UniFlowConfig", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003560 return nil
3561 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003562 logger.Debugw(ctx, "Store or clear persistent UniFlowConfig", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003563
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003564 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003565 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003566 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
3567 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003568 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003569 pDevEntry.UpdateOnuUniFlowConfig(aUniID, aUniVlanFlowParams)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003570
mpagenkof1fc3862021-02-16 10:09:52 +00003571 if aWriteToKvStore {
3572 return dh.startWritingOnuDataToKvStore(ctx, pDevEntry)
3573 }
3574 return nil
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003575}
3576
dbainbri4d3a0dc2020-12-02 00:33:42 +00003577func (dh *deviceHandler) waitForCompletion(ctx context.Context, cancel context.CancelFunc, wg *sync.WaitGroup, aCallerIdent string) {
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003578 defer cancel() //ensure termination of context (may be pro forma)
3579 wg.Wait()
dbainbri4d3a0dc2020-12-02 00:33:42 +00003580 logger.Debugw(ctx, "WaitGroup processing completed", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003581 "device-id": dh.DeviceID, "called from": aCallerIdent})
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003582}
3583
mpagenkoe4782082021-11-25 12:04:26 +00003584//ReasonUpdate set the internally store device reason and if requested in notifyCore updates this state in the core
3585// (renamed from previous deviceReasonUpdate to avoid confusing with the core function DeviceReasonUpdate)
3586func (dh *deviceHandler) ReasonUpdate(ctx context.Context, deviceReason uint8, notifyCore bool) error {
3587 // acquire the deviceReason semaphore throughout this function including the possible update processing in core
3588 // in order to avoid reversion of the state sequence within core in case of quasi-parallel calls (eg. in multi UNI processing)
3589 dh.mutexDeviceReason.Lock()
3590 defer dh.mutexDeviceReason.Unlock()
Holger Hildebrandt3a644642020-12-02 09:46:18 +00003591 if notifyCore {
Holger Hildebrandt80129db2020-11-23 10:49:32 +00003592 //TODO with VOL-3045/VOL-3046: return the error and stop further processing at calling position
khenaidoo42dcdfd2021-10-19 17:34:12 -04003593 if err := dh.updateDeviceReasonInCore(ctx, &ca.DeviceReason{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003594 DeviceId: dh.DeviceID,
3595 Reason: cmn.DeviceReasonMap[deviceReason],
khenaidoo7d3c5582021-08-11 18:09:44 -04003596 }); err != nil {
mpagenkoe4782082021-11-25 12:04:26 +00003597 logger.Errorf(ctx, "updating reason in core failed for: %s",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003598 log.Fields{"device-id": dh.DeviceID, "error": err}, cmn.DeviceReasonMap[deviceReason])
Holger Hildebrandt80129db2020-11-23 10:49:32 +00003599 return err
3600 }
mpagenkoe4782082021-11-25 12:04:26 +00003601 } else {
3602 logger.Debugf(ctx, "update reason in core not requested: %s - device-id: %s", cmn.DeviceReasonMap[deviceReason], dh.DeviceID)
Holger Hildebrandt80129db2020-11-23 10:49:32 +00003603 }
mpagenkoe4782082021-11-25 12:04:26 +00003604 dh.deviceReason = deviceReason
3605 logger.Infof(ctx, "reason update done for: %s - device-id: %s - with core update: %v",
3606 cmn.DeviceReasonMap[deviceReason], dh.DeviceID, notifyCore)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00003607 return nil
3608}
3609
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003610func (dh *deviceHandler) StorePersistentData(ctx context.Context) error {
3611 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00003612 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003613 logger.Warnw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
3614 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00003615 }
mpagenkof1fc3862021-02-16 10:09:52 +00003616 return dh.startWritingOnuDataToKvStore(ctx, pDevEntry)
Holger Hildebrandt80129db2020-11-23 10:49:32 +00003617}
3618
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003619// getUniPortMEEntityID takes uniPortNo as the input and returns the Entity ID corresponding to this UNI-G ME Instance
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03003620// nolint: unused
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003621func (dh *deviceHandler) getUniPortMEEntityID(uniPortNo uint32) (uint16, error) {
3622 dh.lockDevice.RLock()
3623 defer dh.lockDevice.RUnlock()
3624 if uniPort, ok := dh.uniEntityMap[uniPortNo]; ok {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003625 return uniPort.EntityID, nil
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003626 }
3627 return 0, errors.New("error-fetching-uni-port")
3628}
Girish Gowdrae09a6202021-01-12 18:10:59 -08003629
3630// updatePmConfig updates the pm metrics config.
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003631func (dh *deviceHandler) updatePmConfig(ctx context.Context, pmConfigs *voltha.PmConfigs) error {
3632 var errorsList []error
3633 logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": dh.device.Id, "new-pm-configs": pmConfigs, "old-pm-config": dh.pmConfigs})
Girish Gowdrae09a6202021-01-12 18:10:59 -08003634
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003635 errorsList = append(dh.handleGlobalPmConfigUpdates(ctx, pmConfigs), errorsList...)
3636 errorsList = append(dh.handleGroupPmConfigUpdates(ctx, pmConfigs), errorsList...)
3637 errorsList = append(dh.handleStandalonePmConfigUpdates(ctx, pmConfigs), errorsList...)
3638
3639 // Note that if more than one pm config field is updated in a given call, it is possible that partial pm config is handled
3640 // successfully.
3641 // TODO: Although it is possible to revert to old config in case of partial failure, the code becomes quite complex. Needs more investigation
3642 // Is it possible the rw-core reverts to old config on partial failure but adapter retains a partial new config?
3643 if len(errorsList) > 0 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003644 logger.Errorw(ctx, "one-or-more-pm-config-failed", log.Fields{"device-id": dh.DeviceID, "pmConfig": dh.pmConfigs})
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003645 return fmt.Errorf("errors-handling-one-or-more-pm-config, errors:%v", errorsList)
Girish Gowdrae09a6202021-01-12 18:10:59 -08003646 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003647 logger.Infow(ctx, "pm-config-updated", log.Fields{"device-id": dh.DeviceID, "pmConfig": dh.pmConfigs})
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003648 return nil
Girish Gowdrae09a6202021-01-12 18:10:59 -08003649}
3650
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003651func (dh *deviceHandler) handleGlobalPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error {
3652 var err error
3653 var errorsList []error
Girish Gowdra36ccf7d2021-02-25 20:42:51 -08003654 logger.Infow(ctx, "handling-global-pm-config-params - start", log.Fields{"device-id": dh.device.Id})
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003655
3656 if pmConfigs.DefaultFreq != dh.pmConfigs.DefaultFreq {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003657 if err = dh.pOnuMetricsMgr.UpdateDefaultFrequency(ctx, pmConfigs); err != nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003658 errorsList = append(errorsList, err)
3659 }
3660 }
Girish Gowdra36ccf7d2021-02-25 20:42:51 -08003661 logger.Infow(ctx, "handling-global-pm-config-params - done", log.Fields{"device-id": dh.device.Id})
mpagenko15ff4a52021-03-02 10:09:20 +00003662
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003663 return errorsList
3664}
3665
3666func (dh *deviceHandler) handleGroupPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error {
3667 var err error
3668 var errorsList []error
Girish Gowdra36ccf7d2021-02-25 20:42:51 -08003669 logger.Debugw(ctx, "handling-group-pm-config-params - start", log.Fields{"device-id": dh.device.Id})
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003670 // Check if group metric related config is updated
3671 for _, v := range pmConfigs.Groups {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003672 dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock()
3673 m, ok := dh.pOnuMetricsMgr.GroupMetricMap[v.GroupName]
3674 dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock()
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003675
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003676 if ok && m.Frequency != v.GroupFreq {
3677 if err = dh.pOnuMetricsMgr.UpdateGroupFreq(ctx, v.GroupName, pmConfigs); err != nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003678 errorsList = append(errorsList, err)
3679 }
3680 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003681 if ok && m.Enabled != v.Enabled {
3682 if err = dh.pOnuMetricsMgr.UpdateGroupSupport(ctx, v.GroupName, pmConfigs); err != nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003683 errorsList = append(errorsList, err)
3684 }
3685 }
3686 }
Girish Gowdra36ccf7d2021-02-25 20:42:51 -08003687 logger.Debugw(ctx, "handling-group-pm-config-params - done", log.Fields{"device-id": dh.device.Id})
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003688 return errorsList
3689}
3690
3691func (dh *deviceHandler) handleStandalonePmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error {
3692 var err error
3693 var errorsList []error
Girish Gowdra36ccf7d2021-02-25 20:42:51 -08003694 logger.Debugw(ctx, "handling-individual-pm-config-params - start", log.Fields{"device-id": dh.device.Id})
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003695 // Check if standalone metric related config is updated
3696 for _, v := range pmConfigs.Metrics {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003697 dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock()
3698 m, ok := dh.pOnuMetricsMgr.StandaloneMetricMap[v.Name]
3699 dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock()
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003700
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003701 if ok && m.Frequency != v.SampleFreq {
3702 if err = dh.pOnuMetricsMgr.UpdateMetricFreq(ctx, v.Name, pmConfigs); err != nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003703 errorsList = append(errorsList, err)
3704 }
3705 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003706 if ok && m.Enabled != v.Enabled {
3707 if err = dh.pOnuMetricsMgr.UpdateMetricSupport(ctx, v.Name, pmConfigs); err != nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003708 errorsList = append(errorsList, err)
3709 }
3710 }
3711 }
Girish Gowdra36ccf7d2021-02-25 20:42:51 -08003712 logger.Debugw(ctx, "handling-individual-pm-config-params - done", log.Fields{"device-id": dh.device.Id})
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003713 return errorsList
3714}
3715
3716// nolint: gocyclo
Girish Gowdraf7d82d02022-04-26 16:18:35 -07003717func (dh *deviceHandler) StartCollector(ctx context.Context, waitForOmciProcessor *sync.WaitGroup) {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00003718 logger.Debugw(ctx, "startingCollector", log.Fields{"device-id": dh.device.Id})
Girish Gowdrae09a6202021-01-12 18:10:59 -08003719
3720 // Start routine to process OMCI GET Responses
Girish Gowdraf7d82d02022-04-26 16:18:35 -07003721 go dh.pOnuMetricsMgr.ProcessOmciMessages(ctx, waitForOmciProcessor)
Himani Chawla43f95ff2021-06-03 00:24:12 +05303722 // Create Extended Frame PM ME
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003723 go dh.pOnuMetricsMgr.CreateEthernetFrameExtendedPMME(ctx)
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003724 // Initialize the next metric collection time.
3725 // Normally done when the onu_metrics_manager is initialized the first time, but needed again later when ONU is
3726 // reset like onu rebooted.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003727 dh.pOnuMetricsMgr.InitializeMetricCollectionTime(ctx)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003728 dh.setCollectorIsRunning(true)
Girish Gowdrae09a6202021-01-12 18:10:59 -08003729 for {
3730 select {
3731 case <-dh.stopCollector:
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003732 dh.setCollectorIsRunning(false)
Girish Gowdrae09a6202021-01-12 18:10:59 -08003733 logger.Debugw(ctx, "stopping-collector-for-onu", log.Fields{"device-id": dh.device.Id})
Girish Gowdrae0140f02021-02-02 16:55:09 -08003734 // Stop the L2 PM FSM
3735 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003736 if dh.pOnuMetricsMgr.PAdaptFsm != nil && dh.pOnuMetricsMgr.PAdaptFsm.PFsm != nil {
3737 if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventStop); err != nil {
3738 logger.Errorw(ctx, "error calling event", log.Fields{"device-id": dh.DeviceID, "err": err})
Girish Gowdrae0140f02021-02-02 16:55:09 -08003739 }
3740 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003741 logger.Errorw(ctx, "metrics manager fsm not initialized", log.Fields{"device-id": dh.DeviceID})
Girish Gowdrae0140f02021-02-02 16:55:09 -08003742 }
3743 }()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003744 if dh.pOnuMetricsMgr.GetOmciProcessingStatus() {
3745 dh.pOnuMetricsMgr.StopProcessingOmciResponses <- true // Stop the OMCI GET response processing routine
Girish Gowdra7b0ee5c2021-03-19 21:48:15 -07003746 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003747 if dh.pOnuMetricsMgr.GetTickGenerationStatus() {
3748 dh.pOnuMetricsMgr.StopTicks <- true
Girish Gowdra7b0ee5c2021-03-19 21:48:15 -07003749 }
Girish Gowdrae0140f02021-02-02 16:55:09 -08003750
Girish Gowdrae09a6202021-01-12 18:10:59 -08003751 return
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003752 case <-time.After(time.Duration(pmmgr.FrequencyGranularity) * time.Second): // Check every FrequencyGranularity to see if it is time for collecting metrics
3753 if !dh.pmConfigs.FreqOverride { // If FreqOverride is false, then NextGlobalMetricCollectionTime applies
3754 // If the current time is eqaul to or greater than the NextGlobalMetricCollectionTime, collect the group and standalone metrics
3755 if time.Now().Equal(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) || time.Now().After(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) {
3756 go dh.pOnuMetricsMgr.CollectAllGroupAndStandaloneMetrics(ctx)
Girish Gowdraaf0ad632021-01-27 13:00:01 -08003757 // Update the next metric collection time.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003758 dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime = time.Now().Add(time.Duration(dh.pmConfigs.DefaultFreq) * time.Second)
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003759 }
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003760 } else {
3761 if dh.pmConfigs.Grouped { // metrics are managed as a group
3762 // parse through the group and standalone metrics to see it is time to collect their metrics
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003763 dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() // Rlock as we are reading GroupMetricMap and StandaloneMetricMap
Girish Gowdrae09a6202021-01-12 18:10:59 -08003764
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003765 for n, g := range dh.pOnuMetricsMgr.GroupMetricMap {
3766 // If the group is enabled AND (current time is equal to OR after NextCollectionInterval, collect the group metric)
Girish Gowdrae0140f02021-02-02 16:55:09 -08003767 // Since the L2 PM counters are collected in a separate FSM, we should avoid those counters in the check.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003768 if g.Enabled && !g.IsL2PMCounter && (time.Now().Equal(g.NextCollectionInterval) || time.Now().After(g.NextCollectionInterval)) {
3769 go dh.pOnuMetricsMgr.CollectGroupMetric(ctx, n)
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003770 }
3771 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003772 for n, m := range dh.pOnuMetricsMgr.StandaloneMetricMap {
3773 // If the standalone is enabled AND (current time is equal to OR after NextCollectionInterval, collect the metric)
3774 if m.Enabled && (time.Now().Equal(m.NextCollectionInterval) || time.Now().After(m.NextCollectionInterval)) {
3775 go dh.pOnuMetricsMgr.CollectStandaloneMetric(ctx, n)
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003776 }
3777 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003778 dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock()
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003779
3780 // parse through the group and update the next metric collection time
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003781 dh.pOnuMetricsMgr.OnuMetricsManagerLock.Lock() // Lock as we are writing the next metric collection time
3782 for _, g := range dh.pOnuMetricsMgr.GroupMetricMap {
3783 // If group enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp
Girish Gowdrae0140f02021-02-02 16:55:09 -08003784 // Since the L2 PM counters are collected and managed in a separate FSM, we should avoid those counters in the check.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003785 if g.Enabled && !g.IsL2PMCounter && (g.NextCollectionInterval.Before(time.Now()) || g.NextCollectionInterval.Equal(time.Now())) {
3786 g.NextCollectionInterval = time.Now().Add(time.Duration(g.Frequency) * time.Second)
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003787 }
3788 }
3789 // parse through the standalone metrics and update the next metric collection time
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003790 for _, m := range dh.pOnuMetricsMgr.StandaloneMetricMap {
3791 // If standalone metrics enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp
3792 if m.Enabled && (m.NextCollectionInterval.Before(time.Now()) || m.NextCollectionInterval.Equal(time.Now())) {
3793 m.NextCollectionInterval = time.Now().Add(time.Duration(m.Frequency) * time.Second)
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003794 }
3795 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003796 dh.pOnuMetricsMgr.OnuMetricsManagerLock.Unlock()
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003797 } /* else { // metrics are not managed as a group
khenaidoo42dcdfd2021-10-19 17:34:12 -04003798 // TODO: We currently do not have standalone metrics. When available, add code here to fetch the metrca.
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003799 } */
3800 }
Girish Gowdrae09a6202021-01-12 18:10:59 -08003801 }
3802 }
3803}
kesavandfdf77632021-01-26 23:40:33 -05003804
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003805func (dh *deviceHandler) GetUniPortStatus(ctx context.Context, uniInfo *extension.GetOnuUniInfoRequest) *extension.SingleGetValueResponse {
kesavandfdf77632021-01-26 23:40:33 -05003806
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003807 portStatus := uniprt.NewUniPortStatus(dh, dh.pOnuOmciDevice.PDevOmciCC)
3808 return portStatus.GetUniPortStatus(ctx, uniInfo.UniIndex)
kesavandfdf77632021-01-26 23:40:33 -05003809}
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003810
Himani Chawla43f95ff2021-06-03 00:24:12 +05303811func (dh *deviceHandler) getOnuOMCICounters(ctx context.Context, onuInfo *extension.GetOmciEthernetFrameExtendedPmRequest) *extension.SingleGetValueResponse {
3812 if dh.pOnuMetricsMgr == nil {
3813 return &extension.SingleGetValueResponse{
3814 Response: &extension.GetValueResponse{
3815 Status: extension.GetValueResponse_ERROR,
3816 ErrReason: extension.GetValueResponse_INTERNAL_ERROR,
3817 },
3818 }
3819 }
Himani Chawlaee10b542021-09-20 16:46:40 +05303820 resp := dh.pOnuMetricsMgr.CollectEthernetFrameExtendedPMCounters(ctx, onuInfo)
Himani Chawla43f95ff2021-06-03 00:24:12 +05303821 return resp
3822}
3823
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003824func (dh *deviceHandler) isFsmInOmciIdleState(ctx context.Context, PFsm *fsm.FSM, wantedState string) bool {
3825 if PFsm == nil {
mpagenkof1fc3862021-02-16 10:09:52 +00003826 return true //FSM not active - so there is no activity on omci
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003827 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003828 return PFsm.Current() == wantedState
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003829}
3830
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003831func (dh *deviceHandler) isFsmInOmciIdleStateDefault(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, wantedState string) bool {
mpagenkofbf577d2021-10-12 11:44:33 +00003832 var pAdapterFsm *cmn.AdapterFsm
3833 //note/TODO!!: might be that access to all these specific FSM pointers need a semaphore protection as well, cmp lockUpgradeFsm
mpagenkof1fc3862021-02-16 10:09:52 +00003834 switch omciFsm {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003835 case cmn.CUploadFsm:
mpagenkof1fc3862021-02-16 10:09:52 +00003836 {
mpagenkofbf577d2021-10-12 11:44:33 +00003837 if dh.pOnuOmciDevice != nil {
3838 pAdapterFsm = dh.pOnuOmciDevice.PMibUploadFsm
3839 } else {
3840 return true //FSM not active - so there is no activity on omci
3841 }
mpagenkof1fc3862021-02-16 10:09:52 +00003842 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003843 case cmn.CDownloadFsm:
mpagenkof1fc3862021-02-16 10:09:52 +00003844 {
mpagenkofbf577d2021-10-12 11:44:33 +00003845 if dh.pOnuOmciDevice != nil {
3846 pAdapterFsm = dh.pOnuOmciDevice.PMibDownloadFsm
3847 } else {
3848 return true //FSM not active - so there is no activity on omci
3849 }
mpagenkof1fc3862021-02-16 10:09:52 +00003850 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003851 case cmn.CUniLockFsm:
mpagenkof1fc3862021-02-16 10:09:52 +00003852 {
mpagenkofbf577d2021-10-12 11:44:33 +00003853 if dh.pLockStateFsm != nil {
3854 pAdapterFsm = dh.pLockStateFsm.PAdaptFsm
3855 } else {
3856 return true //FSM not active - so there is no activity on omci
3857 }
mpagenkof1fc3862021-02-16 10:09:52 +00003858 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003859 case cmn.CUniUnLockFsm:
mpagenkof1fc3862021-02-16 10:09:52 +00003860 {
mpagenkofbf577d2021-10-12 11:44:33 +00003861 if dh.pUnlockStateFsm != nil {
3862 pAdapterFsm = dh.pUnlockStateFsm.PAdaptFsm
3863 } else {
3864 return true //FSM not active - so there is no activity on omci
3865 }
mpagenkof1fc3862021-02-16 10:09:52 +00003866 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003867 case cmn.CL2PmFsm:
mpagenkof1fc3862021-02-16 10:09:52 +00003868 {
mpagenkofbf577d2021-10-12 11:44:33 +00003869 if dh.pOnuMetricsMgr != nil {
3870 pAdapterFsm = dh.pOnuMetricsMgr.PAdaptFsm
mpagenkof1fc3862021-02-16 10:09:52 +00003871 } else {
3872 return true //FSM not active - so there is no activity on omci
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003873 }
3874 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003875 case cmn.COnuUpgradeFsm:
mpagenko80622a52021-02-09 16:53:23 +00003876 {
3877 dh.lockUpgradeFsm.RLock()
3878 defer dh.lockUpgradeFsm.RUnlock()
mpagenkofbf577d2021-10-12 11:44:33 +00003879 if dh.pOnuUpradeFsm != nil {
3880 pAdapterFsm = dh.pOnuUpradeFsm.PAdaptFsm
3881 } else {
3882 return true //FSM not active - so there is no activity on omci
3883 }
mpagenko80622a52021-02-09 16:53:23 +00003884 }
mpagenkof1fc3862021-02-16 10:09:52 +00003885 default:
3886 {
3887 logger.Errorw(ctx, "invalid stateMachine selected for idle check", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003888 "device-id": dh.DeviceID, "selectedFsm number": omciFsm})
mpagenkof1fc3862021-02-16 10:09:52 +00003889 return false //logical error in FSM check, do not not indicate 'idle' - we can't be sure
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003890 }
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003891 }
mpagenkofbf577d2021-10-12 11:44:33 +00003892 if pAdapterFsm != nil && pAdapterFsm.PFsm != nil {
3893 return dh.isFsmInOmciIdleState(ctx, pAdapterFsm.PFsm, wantedState)
3894 }
3895 return true //FSM not active - so there is no activity on omci
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003896}
3897
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003898func (dh *deviceHandler) isAniConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool {
3899 for _, v := range dh.pOnuTP.PAniConfigFsm {
3900 if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003901 return false
3902 }
3903 }
3904 return true
3905}
3906
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003907func (dh *deviceHandler) isUniVlanConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool {
mpagenkof1fc3862021-02-16 10:09:52 +00003908 dh.lockVlanConfig.RLock()
3909 defer dh.lockVlanConfig.RUnlock()
3910 for _, v := range dh.UniVlanConfigFsmMap {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003911 if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) {
mpagenkof1fc3862021-02-16 10:09:52 +00003912 return false
3913 }
3914 }
3915 return true //FSM not active - so there is no activity on omci
3916}
3917
3918func (dh *deviceHandler) checkUserServiceExists(ctx context.Context) bool {
3919 dh.lockVlanConfig.RLock()
3920 defer dh.lockVlanConfig.RUnlock()
3921 for _, v := range dh.UniVlanConfigFsmMap {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003922 if v.PAdaptFsm.PFsm != nil {
3923 if v.PAdaptFsm.PFsm.Is(avcfg.CVlanFsmConfiguredState) {
mpagenkof1fc3862021-02-16 10:09:52 +00003924 return true //there is at least one VLAN FSM with some active configuration
3925 }
3926 }
3927 }
3928 return false //there is no VLAN FSM with some active configuration
3929}
3930
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003931func (dh *deviceHandler) CheckAuditStartCondition(ctx context.Context, callingFsm cmn.UsedOmciConfigFsms) bool {
mpagenkof1fc3862021-02-16 10:09:52 +00003932 for fsmName, fsmStruct := range fsmOmciIdleStateFuncMap {
3933 if fsmName != callingFsm && !fsmStruct.omciIdleCheckFunc(dh, ctx, fsmName, fsmStruct.omciIdleState) {
3934 return false
3935 }
3936 }
3937 // a further check is done to identify, if at least some data traffic related configuration exists
3938 // 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])
3939 return dh.checkUserServiceExists(ctx)
3940}
3941
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003942func (dh *deviceHandler) PrepareReconcilingWithActiveAdapter(ctx context.Context) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003943 logger.Debugw(ctx, "prepare to reconcile the ONU with adapter using persistency data", log.Fields{"device-id": dh.device.Id})
3944 if err := dh.resetFsms(ctx, false); err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003945 logger.Errorw(ctx, "reset of FSMs failed!", log.Fields{"device-id": dh.DeviceID, "error": err})
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003946 // TODO: fatal error reset ONU, delete deviceHandler!
3947 return
3948 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003949 dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort)
3950 dh.StartReconciling(ctx, false)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003951}
3952
3953func (dh *deviceHandler) setCollectorIsRunning(flagValue bool) {
3954 dh.mutexCollectorFlag.Lock()
3955 dh.collectorIsRunning = flagValue
3956 dh.mutexCollectorFlag.Unlock()
3957}
3958
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003959func (dh *deviceHandler) GetCollectorIsRunning() bool {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003960 dh.mutexCollectorFlag.RLock()
3961 flagValue := dh.collectorIsRunning
3962 dh.mutexCollectorFlag.RUnlock()
3963 return flagValue
3964}
Himani Chawlaac1f5ad2021-02-04 21:21:54 +05303965
Himani Chawla4c1d4c72021-02-18 12:14:31 +05303966func (dh *deviceHandler) setAlarmManagerIsRunning(flagValue bool) {
3967 dh.mutextAlarmManagerFlag.Lock()
3968 dh.alarmManagerIsRunning = flagValue
3969 dh.mutextAlarmManagerFlag.Unlock()
3970}
3971
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003972func (dh *deviceHandler) GetAlarmManagerIsRunning(ctx context.Context) bool {
Himani Chawla4c1d4c72021-02-18 12:14:31 +05303973 dh.mutextAlarmManagerFlag.RLock()
3974 flagValue := dh.alarmManagerIsRunning
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00003975 logger.Debugw(ctx, "alarm-manager-is-running", log.Fields{"device-id": dh.device.Id, "flag": dh.alarmManagerIsRunning})
Himani Chawla4c1d4c72021-02-18 12:14:31 +05303976 dh.mutextAlarmManagerFlag.RUnlock()
3977 return flagValue
3978}
3979
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003980func (dh *deviceHandler) StartAlarmManager(ctx context.Context) {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00003981 logger.Debugw(ctx, "startingAlarmManager", log.Fields{"device-id": dh.device.Id})
Himani Chawlaac1f5ad2021-02-04 21:21:54 +05303982
3983 // Start routine to process OMCI GET Responses
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003984 go dh.pAlarmMgr.StartOMCIAlarmMessageProcessing(ctx)
Himani Chawla4c1d4c72021-02-18 12:14:31 +05303985 dh.setAlarmManagerIsRunning(true)
Himani Chawlaac1f5ad2021-02-04 21:21:54 +05303986 if stop := <-dh.stopAlarmManager; stop {
3987 logger.Debugw(ctx, "stopping-collector-for-onu", log.Fields{"device-id": dh.device.Id})
Himani Chawla4c1d4c72021-02-18 12:14:31 +05303988 dh.setAlarmManagerIsRunning(false)
Himani Chawlad3dac422021-03-13 02:31:31 +05303989 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003990 if dh.pAlarmMgr.AlarmSyncFsm != nil && dh.pAlarmMgr.AlarmSyncFsm.PFsm != nil {
3991 _ = dh.pAlarmMgr.AlarmSyncFsm.PFsm.Event(almgr.AsEvStop)
Himani Chawla1472c682021-03-17 17:11:14 +05303992 }
Himani Chawlad3dac422021-03-13 02:31:31 +05303993 }()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003994 dh.pAlarmMgr.StopProcessingOmciMessages <- true // Stop the OMCI routines if any(This will stop the fsms also)
3995 dh.pAlarmMgr.StopAlarmAuditTimer <- struct{}{}
Himani Chawla1472c682021-03-17 17:11:14 +05303996 logger.Debugw(ctx, "sent-all-stop-signals-to-alarm-manager", log.Fields{"device-id": dh.device.Id})
Himani Chawlaac1f5ad2021-02-04 21:21:54 +05303997 }
3998}
Holger Hildebrandt38985dc2021-02-18 16:25:20 +00003999
Girish Gowdrae95687a2021-09-08 16:30:58 -07004000func (dh *deviceHandler) setFlowMonitoringIsRunning(uniID uint8, flag bool) {
4001 dh.mutexFlowMonitoringRoutineFlag.Lock()
4002 defer dh.mutexFlowMonitoringRoutineFlag.Unlock()
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00004003 logger.Debugw(context.Background(), "set-flow-monitoring-routine", log.Fields{"device-id": dh.device.Id, "flag": flag})
Girish Gowdrae95687a2021-09-08 16:30:58 -07004004 dh.isFlowMonitoringRoutineActive[uniID] = flag
4005}
4006
4007func (dh *deviceHandler) GetFlowMonitoringIsRunning(uniID uint8) bool {
4008 dh.mutexFlowMonitoringRoutineFlag.RLock()
4009 defer dh.mutexFlowMonitoringRoutineFlag.RUnlock()
4010 logger.Debugw(context.Background(), "get-flow-monitoring-routine",
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00004011 log.Fields{"device-id": dh.device.Id, "isFlowMonitoringRoutineActive": dh.isFlowMonitoringRoutineActive})
Girish Gowdrae95687a2021-09-08 16:30:58 -07004012 return dh.isFlowMonitoringRoutineActive[uniID]
4013}
4014
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004015func (dh *deviceHandler) StartReconciling(ctx context.Context, skipOnuConfig bool) {
4016 logger.Debugw(ctx, "start reconciling", log.Fields{"skipOnuConfig": skipOnuConfig, "device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00004017
Maninder7961d722021-06-16 22:10:28 +05304018 connectStatus := voltha.ConnectStatus_UNREACHABLE
4019 operState := voltha.OperStatus_UNKNOWN
4020
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004021 if !dh.IsReconciling() {
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00004022 go func() {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00004023 logger.Debugw(ctx, "wait for channel signal or timeout",
mpagenko101ac942021-11-16 15:01:29 +00004024 log.Fields{"timeout": dh.reconcileExpiryComplete, "device-id": dh.DeviceID})
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00004025 select {
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00004026 case success := <-dh.chReconcilingFinished:
Holger Hildebrandtf7459252022-01-03 16:10:37 +00004027 logger.Debugw(ctx, "reconciling finished signal received",
4028 log.Fields{"device-id": dh.DeviceID, "dh.chReconcilingFinished": dh.chReconcilingFinished})
4029 // To guarantee that the case-branch below is completely processed before reconciling processing is continued,
4030 // dh.mutexReconcilingFlag is locked already here. Thereby it is ensured, that further reconciling processing is stopped
4031 // at next call of dh.IsReconciling() until dh.reconciling is set after informing core about finished reconciling below.
4032 // This change addresses a problem described in VOL-4533 where the flag dh.reconciling not yet reset causes the uni ports
4033 // not to be created in ONOS in function dh.addUniPort(), when reconciling was started in reason "starting-openomci".
4034 // TODO: Keeping the mutex beyond an RPC towards core seems justifiable, as the effects here are easily overseeable.
4035 // However, a later refactoring of the functionality remains unaffected.
4036 dh.mutexReconcilingFlag.Lock()
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00004037 if success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004038 if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil {
Maninderb5187552021-03-23 22:23:42 +05304039 logger.Errorw(ctx, "No valid OnuDevice - aborting Core DeviceStateUpdate",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004040 log.Fields{"device-id": dh.DeviceID})
Maninderb5187552021-03-23 22:23:42 +05304041 } else {
mpagenko2c3f6c52021-11-23 11:22:10 +00004042 onuDevEntry.MutexPersOnuConfig.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004043 if onuDevEntry.SOnuPersistentData.PersOperState == "up" {
Maninderb5187552021-03-23 22:23:42 +05304044 connectStatus = voltha.ConnectStatus_REACHABLE
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004045 if !onuDevEntry.SOnuPersistentData.PersUniDisableDone {
4046 if onuDevEntry.SOnuPersistentData.PersUniUnlockDone {
Maninderb5187552021-03-23 22:23:42 +05304047 operState = voltha.OperStatus_ACTIVE
4048 } else {
4049 operState = voltha.OperStatus_ACTIVATING
4050 }
4051 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004052 } else if onuDevEntry.SOnuPersistentData.PersOperState == "down" ||
4053 onuDevEntry.SOnuPersistentData.PersOperState == "unknown" ||
4054 onuDevEntry.SOnuPersistentData.PersOperState == "" {
Maninderb5187552021-03-23 22:23:42 +05304055 operState = voltha.OperStatus_DISCOVERED
4056 }
mpagenko2c3f6c52021-11-23 11:22:10 +00004057 onuDevEntry.MutexPersOnuConfig.RUnlock()
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00004058 logger.Debugw(ctx, "Core DeviceStateUpdate",
4059 log.Fields{"device-id": dh.device.Id, "connectStatus": connectStatus, "operState": operState})
Maninderb5187552021-03-23 22:23:42 +05304060 }
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00004061 logger.Debugw(ctx, "reconciling has been finished in time",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004062 log.Fields{"device-id": dh.DeviceID})
khenaidoo42dcdfd2021-10-19 17:34:12 -04004063 if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004064 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04004065 ConnStatus: connectStatus,
4066 OperStatus: operState,
4067 }); err != nil {
Maninder7961d722021-06-16 22:10:28 +05304068 logger.Errorw(ctx, "unable to update device state to core",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004069 log.Fields{"device-id": dh.DeviceID, "Err": err})
Maninder7961d722021-06-16 22:10:28 +05304070 }
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00004071 } else {
Maninderb5187552021-03-23 22:23:42 +05304072 logger.Errorw(ctx, "wait for reconciling aborted",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004073 log.Fields{"device-id": dh.DeviceID})
Maninder7961d722021-06-16 22:10:28 +05304074
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004075 if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil {
Maninder7961d722021-06-16 22:10:28 +05304076 logger.Errorw(ctx, "No valid OnuDevice",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004077 log.Fields{"device-id": dh.DeviceID})
mpagenko2c3f6c52021-11-23 11:22:10 +00004078 } else {
4079 onuDevEntry.MutexPersOnuConfig.RLock()
4080 if onuDevEntry.SOnuPersistentData.PersOperState == "up" {
4081 connectStatus = voltha.ConnectStatus_REACHABLE
4082 }
4083 onuDevEntry.MutexPersOnuConfig.RUnlock()
Maninder7961d722021-06-16 22:10:28 +05304084 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004085 dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileCanceled, connectStatus)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00004086 }
mpagenko101ac942021-11-16 15:01:29 +00004087 case <-time.After(dh.reconcileExpiryComplete):
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00004088 logger.Errorw(ctx, "timeout waiting for reconciling to be finished!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004089 log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtf7459252022-01-03 16:10:37 +00004090 dh.mutexReconcilingFlag.Lock()
Maninder7961d722021-06-16 22:10:28 +05304091
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004092 if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil {
Maninder7961d722021-06-16 22:10:28 +05304093 logger.Errorw(ctx, "No valid OnuDevice",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004094 log.Fields{"device-id": dh.DeviceID})
mpagenko2c3f6c52021-11-23 11:22:10 +00004095 } else {
4096 onuDevEntry.MutexPersOnuConfig.RLock()
4097 if onuDevEntry.SOnuPersistentData.PersOperState == "up" {
4098 connectStatus = voltha.ConnectStatus_REACHABLE
4099 }
4100 onuDevEntry.MutexPersOnuConfig.RUnlock()
Maninder7961d722021-06-16 22:10:28 +05304101 }
4102
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004103 dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileMaxTimeout, connectStatus)
Maninder7961d722021-06-16 22:10:28 +05304104
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00004105 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +00004106 dh.reconciling = cNoReconciling
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00004107 dh.mutexReconcilingFlag.Unlock()
Holger Hildebrandt9afc1582021-11-30 16:10:19 +00004108 dh.SetReconcilingReasonUpdate(false)
Holger Hildebrandt7741f272022-01-18 08:17:39 +00004109 dh.SetReconcilingFirstPass(true)
Holger Hildebrandt9afc1582021-11-30 16:10:19 +00004110
4111 if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil {
4112 logger.Errorw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
4113 } else {
4114 onuDevEntry.MutexReconciledTpInstances.Lock()
4115 onuDevEntry.ReconciledTpInstances = make(map[uint8]map[uint8]inter_adapter.TechProfileDownloadMessage)
4116 onuDevEntry.MutexReconciledTpInstances.Unlock()
4117 }
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00004118 }()
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00004119 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +00004120 dh.mutexReconcilingFlag.Lock()
4121 if skipOnuConfig {
4122 dh.reconciling = cSkipOnuConfigReconciling
4123 } else {
4124 dh.reconciling = cOnuConfigReconciling
4125 }
4126 dh.mutexReconcilingFlag.Unlock()
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00004127}
4128
mpagenko101ac942021-11-16 15:01:29 +00004129func (dh *deviceHandler) stopReconciling(ctx context.Context, success bool, reconcileFlowResult uint16) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004130 logger.Debugw(ctx, "stop reconciling", log.Fields{"device-id": dh.DeviceID, "success": success})
4131 if dh.IsReconciling() {
mpagenko101ac942021-11-16 15:01:29 +00004132 dh.sendChReconcileFinished(success)
4133 if reconcileFlowResult != cWaitReconcileFlowNoActivity {
4134 dh.SendChUniVlanConfigFinished(reconcileFlowResult)
4135 }
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00004136 } else {
mpagenko101ac942021-11-16 15:01:29 +00004137 logger.Debugw(ctx, "nothing to stop - reconciling is not running", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00004138 }
4139}
4140
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004141func (dh *deviceHandler) IsReconciling() bool {
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00004142 dh.mutexReconcilingFlag.RLock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00004143 defer dh.mutexReconcilingFlag.RUnlock()
4144 return dh.reconciling != cNoReconciling
4145}
4146
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004147func (dh *deviceHandler) IsSkipOnuConfigReconciling() bool {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00004148 dh.mutexReconcilingFlag.RLock()
4149 defer dh.mutexReconcilingFlag.RUnlock()
4150 return dh.reconciling == cSkipOnuConfigReconciling
4151}
4152
Holger Hildebrandt7741f272022-01-18 08:17:39 +00004153func (dh *deviceHandler) SetReconcilingFirstPass(value bool) {
4154 dh.mutexReconcilingFirstPassFlag.Lock()
4155 dh.reconcilingFirstPass = value
4156 dh.mutexReconcilingFirstPassFlag.Unlock()
4157}
4158
Holger Hildebrandt9afc1582021-11-30 16:10:19 +00004159func (dh *deviceHandler) SetReconcilingReasonUpdate(value bool) {
4160 dh.mutexReconcilingReasonUpdate.Lock()
4161 dh.reconcilingReasonUpdate = value
4162 dh.mutexReconcilingReasonUpdate.Unlock()
4163}
4164
4165func (dh *deviceHandler) IsReconcilingReasonUpdate() bool {
4166 dh.mutexReconcilingReasonUpdate.RLock()
4167 defer dh.mutexReconcilingReasonUpdate.RUnlock()
4168 return dh.reconcilingReasonUpdate
4169}
4170
Holger Hildebrandtbe523842021-03-10 10:47:18 +00004171func (dh *deviceHandler) getDeviceReason() uint8 {
4172 dh.mutexDeviceReason.RLock()
4173 value := dh.deviceReason
4174 dh.mutexDeviceReason.RUnlock()
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00004175 return value
4176}
Holger Hildebrandtbe523842021-03-10 10:47:18 +00004177
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004178func (dh *deviceHandler) GetDeviceReasonString() string {
4179 return cmn.DeviceReasonMap[dh.getDeviceReason()]
Holger Hildebrandtbe523842021-03-10 10:47:18 +00004180}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00004181
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004182func (dh *deviceHandler) SetReadyForOmciConfig(flagValue bool) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00004183 dh.mutexReadyForOmciConfig.Lock()
4184 dh.readyForOmciConfig = flagValue
4185 dh.mutexReadyForOmciConfig.Unlock()
4186}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004187func (dh *deviceHandler) IsReadyForOmciConfig() bool {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00004188 dh.mutexReadyForOmciConfig.RLock()
4189 flagValue := dh.readyForOmciConfig
4190 dh.mutexReadyForOmciConfig.RUnlock()
4191 return flagValue
4192}
Maninder7961d722021-06-16 22:10:28 +05304193
4194func (dh *deviceHandler) deviceReconcileFailedUpdate(ctx context.Context, deviceReason uint8, connectStatus voltha.ConnectStatus_Types) {
mpagenkoe4782082021-11-25 12:04:26 +00004195 if err := dh.ReasonUpdate(ctx, deviceReason, true); err != nil {
Maninder7961d722021-06-16 22:10:28 +05304196 logger.Errorw(ctx, "unable to update device reason to core",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004197 log.Fields{"device-id": dh.DeviceID, "Err": err})
Maninder7961d722021-06-16 22:10:28 +05304198 }
4199
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00004200 logger.Debugw(ctx, "Core DeviceStateUpdate",
4201 log.Fields{"device-id": dh.device.Id, "connectStatus": connectStatus, "operState": voltha.OperStatus_RECONCILING_FAILED})
khenaidoo42dcdfd2021-10-19 17:34:12 -04004202 if err := dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004203 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04004204 ConnStatus: connectStatus,
4205 OperStatus: voltha.OperStatus_RECONCILING_FAILED,
4206 }); err != nil {
Maninder7961d722021-06-16 22:10:28 +05304207 logger.Errorw(ctx, "unable to update device state to core",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004208 log.Fields{"device-id": dh.DeviceID, "Err": err})
Maninder7961d722021-06-16 22:10:28 +05304209 }
4210}
khenaidoo7d3c5582021-08-11 18:09:44 -04004211
4212/*
4213Helper functions to communicate with Core
4214*/
4215
4216func (dh *deviceHandler) getDeviceFromCore(ctx context.Context, deviceID string) (*voltha.Device, error) {
4217 cClient, err := dh.coreClient.GetCoreServiceClient()
4218 if err != nil || cClient == nil {
4219 return nil, err
4220 }
4221 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
4222 defer cancel()
4223 logger.Debugw(subCtx, "get-device-from-core", log.Fields{"device-id": deviceID})
4224 return cClient.GetDevice(subCtx, &vc.ID{Id: deviceID})
4225}
4226
khenaidoo42dcdfd2021-10-19 17:34:12 -04004227func (dh *deviceHandler) updateDeviceStateInCore(ctx context.Context, deviceStateFilter *ca.DeviceStateFilter) error {
khenaidoo7d3c5582021-08-11 18:09:44 -04004228 cClient, err := dh.coreClient.GetCoreServiceClient()
4229 if err != nil || cClient == nil {
4230 return err
4231 }
4232 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
4233 defer cancel()
4234 _, err = cClient.DeviceStateUpdate(subCtx, deviceStateFilter)
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00004235 logger.Debugw(subCtx, "device-updated-in-core",
4236 log.Fields{"device-id": dh.device.Id, "device-state": deviceStateFilter, "error": err})
khenaidoo7d3c5582021-08-11 18:09:44 -04004237 return err
4238}
4239
4240func (dh *deviceHandler) updatePMConfigInCore(ctx context.Context, pmConfigs *voltha.PmConfigs) error {
4241 cClient, err := dh.coreClient.GetCoreServiceClient()
4242 if err != nil || cClient == nil {
4243 return err
4244 }
4245 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
4246 defer cancel()
4247 _, err = cClient.DevicePMConfigUpdate(subCtx, pmConfigs)
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00004248 logger.Debugw(subCtx, "pmconfig-updated-in-core",
4249 log.Fields{"device-id": dh.device.Id, "pm-configs": pmConfigs, "error": err})
khenaidoo7d3c5582021-08-11 18:09:44 -04004250 return err
4251}
4252
4253func (dh *deviceHandler) updateDeviceInCore(ctx context.Context, device *voltha.Device) error {
4254 cClient, err := dh.coreClient.GetCoreServiceClient()
4255 if err != nil || cClient == nil {
4256 return err
4257 }
4258 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
4259 defer cancel()
4260 _, err = cClient.DeviceUpdate(subCtx, device)
4261 logger.Debugw(subCtx, "device-updated-in-core", log.Fields{"device-id": device.Id, "error": err})
4262 return err
4263}
4264
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004265func (dh *deviceHandler) CreatePortInCore(ctx context.Context, port *voltha.Port) error {
khenaidoo7d3c5582021-08-11 18:09:44 -04004266 cClient, err := dh.coreClient.GetCoreServiceClient()
4267 if err != nil || cClient == nil {
4268 return err
4269 }
4270 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
4271 defer cancel()
4272 _, err = cClient.PortCreated(subCtx, port)
4273 logger.Debugw(subCtx, "port-created-in-core", log.Fields{"port": port, "error": err})
4274 return err
4275}
4276
khenaidoo42dcdfd2021-10-19 17:34:12 -04004277func (dh *deviceHandler) updatePortStateInCore(ctx context.Context, portState *ca.PortState) error {
khenaidoo7d3c5582021-08-11 18:09:44 -04004278 cClient, err := dh.coreClient.GetCoreServiceClient()
4279 if err != nil || cClient == nil {
4280 return err
4281 }
4282 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
4283 defer cancel()
4284 _, err = cClient.PortStateUpdate(subCtx, portState)
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00004285 logger.Debugw(subCtx, "port-state-updated-in-core", log.Fields{"device-id": dh.device.Id, "port-state": portState, "error": err})
khenaidoo7d3c5582021-08-11 18:09:44 -04004286 return err
4287}
4288
khenaidoo42dcdfd2021-10-19 17:34:12 -04004289func (dh *deviceHandler) updateDeviceReasonInCore(ctx context.Context, reason *ca.DeviceReason) error {
khenaidoo7d3c5582021-08-11 18:09:44 -04004290 cClient, err := dh.coreClient.GetCoreServiceClient()
4291 if err != nil || cClient == nil {
4292 return err
4293 }
4294 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
4295 defer cancel()
4296 _, err = cClient.DeviceReasonUpdate(subCtx, reason)
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00004297 logger.Debugw(subCtx, "device-reason-updated-in-core", log.Fields{"device-id": dh.device.Id, "reason": reason, "error": err})
khenaidoo7d3c5582021-08-11 18:09:44 -04004298 return err
4299}
4300
4301/*
4302Helper functions to communicate with parent adapter
4303*/
4304
Holger Hildebrandt9afc1582021-11-30 16:10:19 +00004305func (dh *deviceHandler) GetTechProfileInstanceFromParentAdapter(ctx context.Context, aUniID uint8,
4306 aTpPath string) (*ia.TechProfileDownloadMessage, error) {
4307
4308 var request = ia.TechProfileInstanceRequestMessage{
4309 DeviceId: dh.DeviceID,
4310 TpInstancePath: aTpPath,
4311 ParentDeviceId: dh.parentID,
4312 ParentPonPort: dh.device.ParentPortNo,
4313 OnuId: dh.device.ProxyAddress.OnuId,
4314 UniId: uint32(aUniID),
4315 }
4316
4317 pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(dh.device.ProxyAddress.AdapterEndpoint)
khenaidoo7d3c5582021-08-11 18:09:44 -04004318 if err != nil || pgClient == nil {
4319 return nil, err
4320 }
4321 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm)
4322 defer cancel()
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00004323 logger.Debugw(subCtx, "get-tech-profile-instance",
4324 log.Fields{"device-id": dh.device.Id, "request": request, "parent-endpoint": dh.device.ProxyAddress.AdapterEndpoint})
Holger Hildebrandt9afc1582021-11-30 16:10:19 +00004325 return pgClient.GetTechProfileInstance(subCtx, &request)
khenaidoo7d3c5582021-08-11 18:09:44 -04004326}
4327
Girish Gowdrae95687a2021-09-08 16:30:58 -07004328// This routine is unique per ONU ID and blocks on flowControlBlock channel for incoming flows
4329// Each incoming flow is processed in a synchronous manner, i.e., the flow is processed to completion before picking another
4330func (dh *deviceHandler) PerOnuFlowHandlerRoutine(uniID uint8) {
4331 logger.Infow(context.Background(), "starting-flow-handler-routine", log.Fields{"device-id": dh.DeviceID})
4332 dh.setFlowMonitoringIsRunning(uniID, true)
4333 for {
4334 select {
4335 // block on the channel to receive an incoming flow
4336 // process the flow completely before proceeding to handle the next flow
4337 case flowCb := <-dh.flowCbChan[uniID]:
4338 startTime := time.Now()
4339 logger.Debugw(flowCb.ctx, "serial-flow-processor--start", log.Fields{"device-id": dh.DeviceID})
4340 respChan := make(chan error)
4341 if flowCb.addFlow {
4342 go dh.addFlowItemToUniPort(flowCb.ctx, flowCb.flowItem, flowCb.uniPort, flowCb.flowMetaData, &respChan)
4343 } else {
4344 go dh.removeFlowItemFromUniPort(flowCb.ctx, flowCb.flowItem, flowCb.uniPort, &respChan)
4345 }
4346 // Block on response and tunnel it back to the caller
4347 *flowCb.respChan <- <-respChan
4348 logger.Debugw(flowCb.ctx, "serial-flow-processor--end",
4349 log.Fields{"device-id": dh.DeviceID, "absoluteTimeForFlowProcessingInSecs": time.Since(startTime).Seconds()})
4350 case <-dh.stopFlowMonitoringRoutine[uniID]:
4351 logger.Infow(context.Background(), "stopping-flow-handler-routine", log.Fields{"device-id": dh.DeviceID})
4352 dh.setFlowMonitoringIsRunning(uniID, false)
4353 return
4354 }
4355 }
4356}
4357
kesavand011d5162021-11-25 19:21:06 +05304358func (dh *deviceHandler) SendOnuSwSectionsOfWindow(ctx context.Context, parentEndpoint string, request *ia.OmciMessages) error {
4359 request.ParentDeviceId = dh.GetProxyAddressID()
4360 request.ChildDeviceId = dh.DeviceID
4361 request.ProxyAddress = dh.GetProxyAddress()
4362 request.ConnectStatus = common.ConnectStatus_REACHABLE
4363
4364 pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint)
4365 if err != nil || pgClient == nil {
4366 return err
4367 }
4368 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm)
4369 defer cancel()
4370 logger.Debugw(subCtx, "send-omci-request", log.Fields{"request": request, "parent-endpoint": parentEndpoint})
4371 _, err = pgClient.ProxyOmciRequests(subCtx, request)
4372 if err != nil {
Holger Hildebrandtabfef032022-02-25 12:40:20 +00004373 logger.Errorw(ctx, "omci-failure", log.Fields{"device-id": dh.device.Id, "request": request, "error": err,
4374 "request-parent": request.ParentDeviceId, "request-child": request.ChildDeviceId, "request-proxy": request.ProxyAddress})
kesavand011d5162021-11-25 19:21:06 +05304375 }
4376 return err
4377}
4378
khenaidoo42dcdfd2021-10-19 17:34:12 -04004379func (dh *deviceHandler) SendOMCIRequest(ctx context.Context, parentEndpoint string, request *ia.OmciMessage) error {
khenaidoo7d3c5582021-08-11 18:09:44 -04004380 pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint)
4381 if err != nil || pgClient == nil {
4382 return err
4383 }
4384 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm)
4385 defer cancel()
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00004386 logger.Debugw(subCtx, "send-omci-request", log.Fields{"device-id": dh.device.Id, "request": request, "parent-endpoint": parentEndpoint})
khenaidoo7d3c5582021-08-11 18:09:44 -04004387 _, err = pgClient.ProxyOmciRequest(subCtx, request)
4388 if err != nil {
Holger Hildebrandtba6fbe82021-12-03 14:29:42 +00004389 logger.Errorw(ctx, "omci-failure",
4390 log.Fields{"device-id": dh.device.Id, "request": request, "error": err, "request-parent": request.ParentDeviceId,
4391 "request-child": request.ChildDeviceId, "request-proxy": request.ProxyAddress})
khenaidoo7d3c5582021-08-11 18:09:44 -04004392 }
4393 return err
4394}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004395
4396// GetDeviceID - TODO: add comment
4397func (dh *deviceHandler) GetDeviceID() string {
4398 return dh.DeviceID
4399}
4400
4401// GetProxyAddressID - TODO: add comment
4402func (dh *deviceHandler) GetProxyAddressID() string {
4403 return dh.device.ProxyAddress.GetDeviceId()
4404}
4405
4406// GetProxyAddressType - TODO: add comment
4407func (dh *deviceHandler) GetProxyAddressType() string {
4408 return dh.device.ProxyAddress.GetDeviceType()
4409}
4410
4411// GetProxyAddress - TODO: add comment
4412func (dh *deviceHandler) GetProxyAddress() *voltha.Device_ProxyAddress {
4413 return dh.device.ProxyAddress
4414}
4415
4416// GetEventProxy - TODO: add comment
4417func (dh *deviceHandler) GetEventProxy() eventif.EventProxy {
4418 return dh.EventProxy
4419}
4420
4421// GetOmciTimeout - TODO: add comment
4422func (dh *deviceHandler) GetOmciTimeout() int {
4423 return dh.pOpenOnuAc.omciTimeout
4424}
4425
4426// GetAlarmAuditInterval - TODO: add comment
4427func (dh *deviceHandler) GetAlarmAuditInterval() time.Duration {
4428 return dh.pOpenOnuAc.alarmAuditInterval
4429}
4430
4431// GetDlToOnuTimeout4M - TODO: add comment
4432func (dh *deviceHandler) GetDlToOnuTimeout4M() time.Duration {
4433 return dh.pOpenOnuAc.dlToOnuTimeout4M
4434}
4435
4436// GetUniEntityMap - TODO: add comment
4437func (dh *deviceHandler) GetUniEntityMap() *cmn.OnuUniPortMap {
4438 return &dh.uniEntityMap
4439}
4440
4441// GetPonPortNumber - TODO: add comment
4442func (dh *deviceHandler) GetPonPortNumber() *uint32 {
4443 return &dh.ponPortNumber
4444}
4445
4446// GetUniVlanConfigFsm - TODO: add comment
4447func (dh *deviceHandler) GetUniVlanConfigFsm(uniID uint8) cmn.IuniVlanConfigFsm {
Holger Hildebrandtc192bc42021-10-28 14:38:31 +00004448 dh.lockVlanConfig.RLock()
4449 value := dh.UniVlanConfigFsmMap[uniID]
4450 dh.lockVlanConfig.RUnlock()
4451 return value
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004452}
4453
4454// GetOnuAlarmManager - TODO: add comment
4455func (dh *deviceHandler) GetOnuAlarmManager() cmn.IonuAlarmManager {
4456 return dh.pAlarmMgr
4457}
4458
4459// GetOnuMetricsManager - TODO: add comment
4460func (dh *deviceHandler) GetOnuMetricsManager() cmn.IonuMetricsManager {
4461 return dh.pOnuMetricsMgr
4462}
4463
4464// GetOnuTP - TODO: add comment
4465func (dh *deviceHandler) GetOnuTP() cmn.IonuUniTechProf {
4466 return dh.pOnuTP
4467}
4468
4469// GetBackendPathPrefix - TODO: add comment
4470func (dh *deviceHandler) GetBackendPathPrefix() string {
4471 return dh.pOpenOnuAc.cm.Backend.PathPrefix
4472}
4473
4474// GetOnuIndication - TODO: add comment
4475func (dh *deviceHandler) GetOnuIndication() *openolt.OnuIndication {
4476 return dh.pOnuIndication
4477}
4478
4479// RLockMutexDeletionInProgressFlag - TODO: add comment
4480func (dh *deviceHandler) RLockMutexDeletionInProgressFlag() {
4481 dh.mutexDeletionInProgressFlag.RLock()
4482}
4483
4484// RUnlockMutexDeletionInProgressFlag - TODO: add comment
4485func (dh *deviceHandler) RUnlockMutexDeletionInProgressFlag() {
4486 dh.mutexDeletionInProgressFlag.RUnlock()
4487}
4488
4489// GetDeletionInProgress - TODO: add comment
4490func (dh *deviceHandler) GetDeletionInProgress() bool {
4491 return dh.deletionInProgress
4492}
4493
4494// GetPmConfigs - TODO: add comment
4495func (dh *deviceHandler) GetPmConfigs() *voltha.PmConfigs {
4496 return dh.pmConfigs
4497}
4498
4499// GetDeviceType - TODO: add comment
4500func (dh *deviceHandler) GetDeviceType() string {
4501 return dh.DeviceType
4502}
4503
4504// GetLogicalDeviceID - TODO: add comment
4505func (dh *deviceHandler) GetLogicalDeviceID() string {
4506 return dh.logicalDeviceID
4507}
4508
4509// GetDevice - TODO: add comment
4510func (dh *deviceHandler) GetDevice() *voltha.Device {
4511 return dh.device
4512}
4513
4514// GetMetricsEnabled - TODO: add comment
4515func (dh *deviceHandler) GetMetricsEnabled() bool {
4516 return dh.pOpenOnuAc.MetricsEnabled
4517}
4518
Holger Hildebrandtc572e622022-06-22 09:19:17 +00004519// GetExtendedOmciSupportEnabled - TODO: add comment
4520func (dh *deviceHandler) GetExtendedOmciSupportEnabled() bool {
4521 return dh.pOpenOnuAc.ExtendedOmciSupportEnabled
4522}
4523
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00004524// InitPmConfigs - TODO: add comment
4525func (dh *deviceHandler) InitPmConfigs() {
4526 dh.pmConfigs = &voltha.PmConfigs{}
4527}
4528
4529// GetUniPortMask - TODO: add comment
4530func (dh *deviceHandler) GetUniPortMask() int {
4531 return dh.pOpenOnuAc.config.UniPortMask
4532}
Holger Hildebrandtb314f442021-11-24 12:03:10 +00004533
4534func (dh *deviceHandler) anyTpPathExists(aTpPathMap map[uint8]string) bool {
4535 tpPathFound := false
4536 for _, tpPath := range aTpPathMap {
4537 if tpPath != "" {
4538 tpPathFound = true
4539 }
4540 }
4541 return tpPathFound
4542}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00004543
4544// PrepareForGarbageCollection - remove references to prepare for garbage collection
4545func (dh *deviceHandler) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
4546 logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID})
4547
4548 // Note: This function must be called as a goroutine to prevent blocking of further processing!
4549 // first let the objects rest for some time to give all asynchronously started
4550 // cleanup routines a chance to come to an end
Holger Hildebrandt12609a12022-03-25 13:23:25 +00004551 time.Sleep(2 * time.Second)
4552
4553 if dh.pOnuOmciDevice != nil {
4554 if dh.pOnuOmciDevice.PDevOmciCC != nil {
4555 // Since we cannot rule out that one of the handlers had initiated any OMCI configurations during its
4556 // reset handling (even in future coding), request monitoring is canceled here one last time to
4557 // be sure that all corresponding go routines are terminated
4558 dh.pOnuOmciDevice.PDevOmciCC.CancelRequestMonitoring(ctx)
4559 }
4560 }
4561 time.Sleep(3 * time.Second)
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00004562
4563 if dh.pOnuTP != nil {
4564 dh.pOnuTP.PrepareForGarbageCollection(ctx, aDeviceID)
4565 }
4566 if dh.pOnuMetricsMgr != nil {
4567 dh.pOnuMetricsMgr.PrepareForGarbageCollection(ctx, aDeviceID)
Girish Gowdraabcceb12022-04-13 23:35:22 -07004568 select {
4569 case <-dh.pOnuMetricsMgr.GarbageCollectionComplete:
4570 logger.Debugw(ctx, "pm fsm shut down and garbage collection complete", log.Fields{"deviceID": aDeviceID})
4571 case <-time.After(pmmgr.MaxTimeForPmFsmShutDown * time.Second):
4572 logger.Errorw(ctx, "fsm did not shut down in time", log.Fields{"deviceID": aDeviceID})
4573 }
Holger Hildebrandte7cc6092022-02-01 11:37:03 +00004574 }
4575 if dh.pAlarmMgr != nil {
4576 dh.pAlarmMgr.PrepareForGarbageCollection(ctx, aDeviceID)
4577 }
4578 if dh.pSelfTestHdlr != nil {
4579 dh.pSelfTestHdlr.PrepareForGarbageCollection(ctx, aDeviceID)
4580 }
4581 if dh.pLockStateFsm != nil {
4582 dh.pLockStateFsm.PrepareForGarbageCollection(ctx, aDeviceID)
4583 }
4584 if dh.pUnlockStateFsm != nil {
4585 dh.pUnlockStateFsm.PrepareForGarbageCollection(ctx, aDeviceID)
4586 }
4587 if dh.pOnuUpradeFsm != nil {
4588 dh.pOnuUpradeFsm.PrepareForGarbageCollection(ctx, aDeviceID)
4589 }
4590 if dh.pOnuOmciDevice != nil {
4591 dh.pOnuOmciDevice.PrepareForGarbageCollection(ctx, aDeviceID)
4592 }
4593 for k, v := range dh.UniVlanConfigFsmMap {
4594 v.PrepareForGarbageCollection(ctx, aDeviceID)
4595 delete(dh.UniVlanConfigFsmMap, k)
4596 }
4597 dh.pOnuOmciDevice = nil
4598 dh.pOnuTP = nil
4599 dh.pOnuMetricsMgr = nil
4600 dh.pAlarmMgr = nil
4601 dh.pSelfTestHdlr = nil
4602 dh.pLockStateFsm = nil
4603 dh.pUnlockStateFsm = nil
4604 dh.pOnuUpradeFsm = nil
4605}