blob: 449d96eba6e057f54a0f33b70eb23d381322523a [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"
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000032 me "github.com/opencord/omci-lib-go/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"
khenaidoo7d3c5582021-08-11 18:09:44 -040047 vc "github.com/opencord/voltha-protos/v5/go/common"
48 "github.com/opencord/voltha-protos/v5/go/extension"
49 ic "github.com/opencord/voltha-protos/v5/go/inter_container"
50 of "github.com/opencord/voltha-protos/v5/go/openflow_13"
mpagenko59862f02021-10-11 08:53:18 +000051 "github.com/opencord/voltha-protos/v5/go/openolt"
khenaidoo7d3c5582021-08-11 18:09:44 -040052 oop "github.com/opencord/voltha-protos/v5/go/openolt"
mpagenko59862f02021-10-11 08:53:18 +000053 "github.com/opencord/voltha-protos/v5/go/tech_profile"
khenaidoo7d3c5582021-08-11 18:09:44 -040054 "github.com/opencord/voltha-protos/v5/go/voltha"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000055)
56
mpagenko38662d02021-08-11 09:45:19 +000057// Constants for timeouts
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000058const (
mpagenko38662d02021-08-11 09:45:19 +000059 cTimeOutRemoveUpgrade = 1 //for usage in seconds
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000060)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000061
mpagenko1cc3cb42020-07-27 15:24:38 +000062const (
63 // events of Device FSM
64 devEvDeviceInit = "devEvDeviceInit"
65 devEvGrpcConnected = "devEvGrpcConnected"
66 devEvGrpcDisconnected = "devEvGrpcDisconnected"
67 devEvDeviceUpInd = "devEvDeviceUpInd"
68 devEvDeviceDownInd = "devEvDeviceDownInd"
69)
70const (
71 // states of Device FSM
72 devStNull = "devStNull"
73 devStDown = "devStDown"
74 devStInit = "devStInit"
75 devStConnected = "devStConnected"
76 devStUp = "devStUp"
77)
78
Holger Hildebrandt24d51952020-05-04 14:03:42 +000079//Event category and subcategory definitions - same as defiend for OLT in eventmgr.go - should be done more centrally
80const (
Himani Chawla4d908332020-08-31 12:30:20 +053081 pon = voltha.EventSubCategory_PON
82 //olt = voltha.EventSubCategory_OLT
83 //ont = voltha.EventSubCategory_ONT
84 //onu = voltha.EventSubCategory_ONU
85 //nni = voltha.EventSubCategory_NNI
86 //service = voltha.EventCategory_SERVICE
87 //security = voltha.EventCategory_SECURITY
88 equipment = voltha.EventCategory_EQUIPMENT
89 //processing = voltha.EventCategory_PROCESSING
90 //environment = voltha.EventCategory_ENVIRONMENT
91 //communication = voltha.EventCategory_COMMUNICATION
Holger Hildebrandt24d51952020-05-04 14:03:42 +000092)
93
94const (
95 cEventObjectType = "ONU"
96)
97const (
98 cOnuActivatedEvent = "ONU_ACTIVATED"
99)
100
mpagenkof1fc3862021-02-16 10:09:52 +0000101type omciIdleCheckStruct struct {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000102 omciIdleCheckFunc func(*deviceHandler, context.Context, cmn.UsedOmciConfigFsms, string) bool
mpagenkof1fc3862021-02-16 10:09:52 +0000103 omciIdleState string
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000104}
105
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000106var fsmOmciIdleStateFuncMap = map[cmn.UsedOmciConfigFsms]omciIdleCheckStruct{
107 cmn.CUploadFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibUlFsmIdleState},
108 cmn.CDownloadFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, mib.CMibDlFsmIdleState},
109 cmn.CUniLockFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState},
110 cmn.CUniUnLockFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, uniprt.CUniFsmIdleState},
111 cmn.CAniConfigFsm: {(*deviceHandler).isAniConfigFsmInOmciIdleState, avcfg.CAniFsmIdleState},
112 cmn.CUniVlanConfigFsm: {(*deviceHandler).isUniVlanConfigFsmInOmciIdleState, avcfg.CVlanFsmIdleState},
113 cmn.CL2PmFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, pmmgr.CL2PmFsmIdleState},
114 cmn.COnuUpgradeFsm: {(*deviceHandler).isFsmInOmciIdleStateDefault, swupg.COnuUpgradeFsmIdleState},
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000115}
116
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000117const (
118 cNoReconciling = iota
119 cOnuConfigReconciling
120 cSkipOnuConfigReconciling
121)
122
Himani Chawla6d2ae152020-09-02 13:11:20 +0530123//deviceHandler will interact with the ONU ? device.
124type deviceHandler struct {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000125 DeviceID string
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000126 DeviceType string
127 adminState string
128 device *voltha.Device
129 logicalDeviceID string
130 ProxyAddressID string
131 ProxyAddressType string
Himani Chawla4d908332020-08-31 12:30:20 +0530132 parentID string
Holger Hildebrandt24d51952020-05-04 14:03:42 +0000133 ponPortNumber uint32
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000134
khenaidoo7d3c5582021-08-11 18:09:44 -0400135 coreClient *vgrpc.Client
136 EventProxy eventif.EventProxy
Holger Hildebrandtc54939a2020-06-17 08:14:27 +0000137
Girish Gowdra5a7c4922021-01-22 18:33:41 -0800138 pmConfigs *voltha.PmConfigs
khenaidoo7d3c5582021-08-11 18:09:44 -0400139 config *config.AdapterFlags
Girish Gowdrae09a6202021-01-12 18:10:59 -0800140
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000141 pOpenOnuAc *OpenONUAC
142 pDeviceStateFsm *fsm.FSM
Himani Chawla4d908332020-08-31 12:30:20 +0530143 //pPonPort *voltha.Port
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000144 deviceEntrySet chan bool //channel for DeviceEntry set event
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000145 pOnuOmciDevice *mib.OnuDeviceEntry
146 pOnuTP *avcfg.OnuUniTechProf
147 pOnuMetricsMgr *pmmgr.OnuMetricsManager
148 pAlarmMgr *almgr.OnuAlarmManager
149 pSelfTestHdlr *otst.SelfTestControlBlock
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000150 exitChannel chan int
151 lockDevice sync.RWMutex
152 pOnuIndication *oop.OnuIndication
153 deviceReason uint8
154 mutexDeviceReason sync.RWMutex
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000155 pLockStateFsm *uniprt.LockStateFsm
156 pUnlockStateFsm *uniprt.LockStateFsm
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000157
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000158 //flowMgr *OpenOltFlowMgr
159 //eventMgr *OpenOltEventMgr
160 //resourceMgr *rsrcMgr.OpenOltResourceMgr
161
162 //discOnus sync.Map
163 //onus sync.Map
164 //portStats *OpenOltStatisticsMgr
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000165 collectorIsRunning bool
166 mutexCollectorFlag sync.RWMutex
167 stopCollector chan bool
168 alarmManagerIsRunning bool
169 mutextAlarmManagerFlag sync.RWMutex
170 stopAlarmManager chan bool
171 stopHeartbeatCheck chan bool
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000172 uniEntityMap cmn.OnuUniPortMap
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000173 mutexKvStoreContext sync.Mutex
174 lockVlanConfig sync.RWMutex
mpagenkobc4170a2021-08-17 16:42:10 +0000175 lockVlanAdd sync.RWMutex
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000176 UniVlanConfigFsmMap map[uint8]*avcfg.UniVlanConfigFsm
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000177 lockUpgradeFsm sync.RWMutex
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000178 pOnuUpradeFsm *swupg.OnuUpgradeFsm
mpagenko59862f02021-10-11 08:53:18 +0000179 upgradeCanceled bool
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000180 reconciling uint8
181 mutexReconcilingFlag sync.RWMutex
182 chReconcilingFinished chan bool //channel to indicate that reconciling has been finished
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000183 mutexReadyForOmciConfig sync.RWMutex
184 readyForOmciConfig bool
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000185 deletionInProgress bool
186 mutexDeletionInProgressFlag sync.RWMutex
mpagenko38662d02021-08-11 09:45:19 +0000187 pLastUpgradeImageState *voltha.ImageState
188 upgradeFsmChan chan struct{}
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000189}
190
Himani Chawla6d2ae152020-09-02 13:11:20 +0530191//newDeviceHandler creates a new device handler
khenaidoo7d3c5582021-08-11 18:09:44 -0400192func newDeviceHandler(ctx context.Context, cc *vgrpc.Client, ep eventif.EventProxy, device *voltha.Device, adapter *OpenONUAC) *deviceHandler {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530193 var dh deviceHandler
khenaidoo7d3c5582021-08-11 18:09:44 -0400194 dh.coreClient = cc
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000195 dh.EventProxy = ep
khenaidoo7d3c5582021-08-11 18:09:44 -0400196 dh.config = adapter.config
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000197 cloned := (proto.Clone(device)).(*voltha.Device)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000198 dh.DeviceID = cloned.Id
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000199 dh.DeviceType = cloned.Type
200 dh.adminState = "up"
201 dh.device = cloned
202 dh.pOpenOnuAc = adapter
203 dh.exitChannel = make(chan int, 1)
204 dh.lockDevice = sync.RWMutex{}
mpagenko3af1f032020-06-10 08:53:41 +0000205 dh.deviceEntrySet = make(chan bool, 1)
Holger Hildebrandt10d98192021-01-27 15:29:31 +0000206 dh.collectorIsRunning = false
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000207 dh.stopCollector = make(chan bool, 2)
Himani Chawla4c1d4c72021-02-18 12:14:31 +0530208 dh.alarmManagerIsRunning = false
Himani Chawlaac1f5ad2021-02-04 21:21:54 +0530209 dh.stopAlarmManager = make(chan bool, 2)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000210 dh.stopHeartbeatCheck = make(chan bool, 2)
211 //dh.metrics = pmmetrics.NewPmMetrics(cloned.Id, pmmetrics.Frequency(150), pmmetrics.FrequencyOverride(false), pmmetrics.Grouped(false), pmmetrics.Metrics(pmNames))
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000212 //TODO initialize the support classes.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000213 dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort)
mpagenkof1fc3862021-02-16 10:09:52 +0000214 dh.lockVlanConfig = sync.RWMutex{}
mpagenkobc4170a2021-08-17 16:42:10 +0000215 dh.lockVlanAdd = sync.RWMutex{}
mpagenko80622a52021-02-09 16:53:23 +0000216 dh.lockUpgradeFsm = sync.RWMutex{}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000217 dh.UniVlanConfigFsmMap = make(map[uint8]*avcfg.UniVlanConfigFsm)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000218 dh.reconciling = cNoReconciling
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +0000219 dh.chReconcilingFinished = make(chan bool)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000220 dh.readyForOmciConfig = false
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000221 dh.deletionInProgress = false
mpagenko38662d02021-08-11 09:45:19 +0000222 dh.pLastUpgradeImageState = &voltha.ImageState{
223 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN,
224 Reason: voltha.ImageState_UNKNOWN_ERROR,
225 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
226 }
227 dh.upgradeFsmChan = make(chan struct{})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000228
Girish Gowdra5a7c4922021-01-22 18:33:41 -0800229 if dh.device.PmConfigs != nil { // can happen after onu adapter restart
230 dh.pmConfigs = cloned.PmConfigs
231 } /* else {
232 // will be populated when onu_metrics_mananger is initialized.
233 }*/
Girish Gowdrae09a6202021-01-12 18:10:59 -0800234
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000235 // Device related state machine
236 dh.pDeviceStateFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000237 devStNull,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000238 fsm.Events{
mpagenko1cc3cb42020-07-27 15:24:38 +0000239 {Name: devEvDeviceInit, Src: []string{devStNull, devStDown}, Dst: devStInit},
240 {Name: devEvGrpcConnected, Src: []string{devStInit}, Dst: devStConnected},
241 {Name: devEvGrpcDisconnected, Src: []string{devStConnected, devStDown}, Dst: devStInit},
242 {Name: devEvDeviceUpInd, Src: []string{devStConnected, devStDown}, Dst: devStUp},
243 {Name: devEvDeviceDownInd, Src: []string{devStUp}, Dst: devStDown},
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000244 },
245 fsm.Callbacks{
dbainbri4d3a0dc2020-12-02 00:33:42 +0000246 "before_event": func(e *fsm.Event) { dh.logStateChange(ctx, e) },
247 ("before_" + devEvDeviceInit): func(e *fsm.Event) { dh.doStateInit(ctx, e) },
248 ("after_" + devEvDeviceInit): func(e *fsm.Event) { dh.postInit(ctx, e) },
249 ("before_" + devEvGrpcConnected): func(e *fsm.Event) { dh.doStateConnected(ctx, e) },
250 ("before_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.doStateInit(ctx, e) },
251 ("after_" + devEvGrpcDisconnected): func(e *fsm.Event) { dh.postInit(ctx, e) },
252 ("before_" + devEvDeviceUpInd): func(e *fsm.Event) { dh.doStateUp(ctx, e) },
253 ("before_" + devEvDeviceDownInd): func(e *fsm.Event) { dh.doStateDown(ctx, e) },
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000254 },
255 )
mpagenkoaf801632020-07-03 10:00:42 +0000256
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000257 return &dh
258}
259
Himani Chawla6d2ae152020-09-02 13:11:20 +0530260// start save the device to the data model
261func (dh *deviceHandler) start(ctx context.Context) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000262 logger.Debugw(ctx, "starting-device-handler", log.Fields{"device": dh.device, "device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000263 // Add the initial device to the local model
dbainbri4d3a0dc2020-12-02 00:33:42 +0000264 logger.Debug(ctx, "device-handler-started")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000265}
266
Himani Chawla4d908332020-08-31 12:30:20 +0530267/*
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000268// stop stops the device dh. Not much to do for now
Himani Chawla6d2ae152020-09-02 13:11:20 +0530269func (dh *deviceHandler) stop(ctx context.Context) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000270 logger.Debug("stopping-device-handler")
271 dh.exitChannel <- 1
272}
Himani Chawla4d908332020-08-31 12:30:20 +0530273*/
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000274
275// ##########################################################################################
Himani Chawla6d2ae152020-09-02 13:11:20 +0530276// deviceHandler methods that implement the adapters interface requests ##### begin #########
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000277
Girish Gowdrae0140f02021-02-02 16:55:09 -0800278//adoptOrReconcileDevice adopts the ONU device
Himani Chawla6d2ae152020-09-02 13:11:20 +0530279func (dh *deviceHandler) adoptOrReconcileDevice(ctx context.Context, device *voltha.Device) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400280 logger.Debugw(ctx, "adopt_or_reconcile_device", log.Fields{"device-id": device.Id, "Address": device.GetHostAndPort()})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000281
dbainbri4d3a0dc2020-12-02 00:33:42 +0000282 logger.Debugw(ctx, "Device FSM: ", log.Fields{"state": string(dh.pDeviceStateFsm.Current())})
mpagenko1cc3cb42020-07-27 15:24:38 +0000283 if dh.pDeviceStateFsm.Is(devStNull) {
284 if err := dh.pDeviceStateFsm.Event(devEvDeviceInit); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000285 logger.Errorw(ctx, "Device FSM: Can't go to state DeviceInit", log.Fields{"err": err})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000286 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000287 logger.Debugw(ctx, "Device FSM: ", log.Fields{"state": string(dh.pDeviceStateFsm.Current())})
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800288 // device.PmConfigs is not nil in cases when adapter restarts. We should not re-set the core again.
289 if device.PmConfigs == nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -0800290 // Now, set the initial PM configuration for that device
khenaidoo7d3c5582021-08-11 18:09:44 -0400291 if err := dh.updatePMConfigInCore(ctx, dh.pmConfigs); err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000292 logger.Errorw(ctx, "error updating pm config to core", log.Fields{"device-id": dh.DeviceID, "err": err})
Girish Gowdra5a7c4922021-01-22 18:33:41 -0800293 }
Girish Gowdrae09a6202021-01-12 18:10:59 -0800294 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000295 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000296 logger.Debugw(ctx, "AdoptOrReconcileDevice: Agent/device init already done", log.Fields{"device-id": device.Id})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000297 }
298
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000299}
300
khenaidoo7d3c5582021-08-11 18:09:44 -0400301func (dh *deviceHandler) handleOMCIIndication(ctx context.Context, msg *ic.OmciMessage) error {
mpagenko80622a52021-02-09 16:53:23 +0000302 /* 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 +0530303 //assuming omci message content is hex coded!
304 // with restricted output of 16(?) bytes would be ...omciMsg.Message[:16]
dbainbri4d3a0dc2020-12-02 00:33:42 +0000305 logger.Debugw(ctx, "inter-adapter-recv-omci", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000306 "device-id": dh.DeviceID, "RxOmciMessage": hex.EncodeToString(omciMsg.Message)})
mpagenko80622a52021-02-09 16:53:23 +0000307 */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000308 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Himani Chawla26e555c2020-08-31 12:30:20 +0530309 if pDevEntry != nil {
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000310 if pDevEntry.PDevOmciCC != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000311 return pDevEntry.PDevOmciCC.ReceiveMessage(log.WithSpanFromContext(context.TODO(), ctx), msg.Message)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000312 }
khenaidoo7d3c5582021-08-11 18:09:44 -0400313 logger.Debugw(ctx, "omciCC not ready to receive omci messages - incoming omci message ignored", log.Fields{"rxMsg": msg.Message})
Himani Chawla26e555c2020-08-31 12:30:20 +0530314 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000315 logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
316 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +0530317}
318
khenaidoo7d3c5582021-08-11 18:09:44 -0400319func (dh *deviceHandler) handleTechProfileDownloadRequest(ctx context.Context, techProfMsg *ic.TechProfileDownloadMessage) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000320 logger.Infow(ctx, "tech-profile-download-request", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000321
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000322 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000323 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000324 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
325 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000326 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530327 if dh.pOnuTP == nil {
328 //should normally not happen ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000329 logger.Errorw(ctx, "onuTechProf instance not set up for DLMsg request - ignoring request",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000330 log.Fields{"device-id": dh.DeviceID})
331 return fmt.Errorf("techProfile DLMsg request while onuTechProf instance not setup: %s", dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +0530332 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000333 if !dh.IsReadyForOmciConfig() {
334 logger.Errorw(ctx, "TechProf-set rejected: improper device state", log.Fields{"device-id": dh.DeviceID,
335 "device-state": dh.GetDeviceReasonString()})
336 return fmt.Errorf("improper device state %s on device %s", dh.GetDeviceReasonString(), dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +0530337 }
mpagenkofc4f56e2020-11-04 17:17:49 +0000338 //previous state test here was just this one, now extended for more states to reject the SetRequest:
339 // at least 'mib-downloaded' should be reached for processing of this specific ONU configuration
340 // if (dh.deviceReason == "stopping-openomci") || (dh.deviceReason == "omci-admin-lock")
Himani Chawla26e555c2020-08-31 12:30:20 +0530341
Himani Chawla26e555c2020-08-31 12:30:20 +0530342 // we have to lock access to TechProfile processing based on different messageType calls or
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000343 // even to fast subsequent calls of the same messageType as well as OnuKVStore processing due
344 // to possible concurrent access by flow processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000345 dh.pOnuTP.LockTpProcMutex()
346 defer dh.pOnuTP.UnlockTpProcMutex()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000347
348 if techProfMsg.UniId > 255 {
349 return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000350 techProfMsg.UniId, dh.DeviceID))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000351 }
352 uniID := uint8(techProfMsg.UniId)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000353 tpID, err := cmn.GetTpIDFromTpPath(techProfMsg.TpInstancePath)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800354 if err != nil {
Girish Gowdra50e56422021-06-01 16:46:04 -0700355 logger.Errorw(ctx, "error-parsing-tpid-from-tppath", log.Fields{"err": err, "tp-path": techProfMsg.TpInstancePath})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800356 return err
357 }
Girish Gowdra50e56422021-06-01 16:46:04 -0700358 logger.Debugw(ctx, "unmarshal-techprof-msg-body", log.Fields{"uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000359
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000360 if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, uint8(tpID), techProfMsg.TpInstancePath); bTpModify {
Himani Chawla26e555c2020-08-31 12:30:20 +0530361
Girish Gowdra50e56422021-06-01 16:46:04 -0700362 switch tpInst := techProfMsg.TechTpInstance.(type) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400363 case *ic.TechProfileDownloadMessage_TpInstance:
Girish Gowdra50e56422021-06-01 16:46:04 -0700364 logger.Debugw(ctx, "onu-uni-tp-path-modified", log.Fields{"uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID})
365 // if there has been some change for some uni TechProfilePath
366 //in order to allow concurrent calls to other dh instances we do not wait for execution here
367 //but doing so we can not indicate problems to the caller (who does what with that then?)
368 //by now we just assume straightforward successful execution
369 //TODO!!! Generally: In this scheme it would be good to have some means to indicate
370 // possible problems to the caller later autonomously
Himani Chawla26e555c2020-08-31 12:30:20 +0530371
Girish Gowdra50e56422021-06-01 16:46:04 -0700372 // deadline context to ensure completion of background routines waited for
373 //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
374 deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
375 dctx, cancel := context.WithDeadline(context.Background(), deadline)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000376
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000377 dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID)
Girish Gowdra50e56422021-06-01 16:46:04 -0700378
379 var wg sync.WaitGroup
380 wg.Add(1) // for the 1 go routine to finish
381 // attention: deadline completion check and wg.Done is to be done in both routines
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000382 go dh.pOnuTP.ConfigureUniTp(log.WithSpanFromContext(dctx, ctx), uniID, techProfMsg.TpInstancePath, *tpInst.TpInstance, &wg)
Girish Gowdra50e56422021-06-01 16:46:04 -0700383 dh.waitForCompletion(ctx, cancel, &wg, "TechProfDwld") //wait for background process to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000384 if tpErr := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); tpErr != nil {
385 logger.Errorw(ctx, "error-processing-tp", log.Fields{"device-id": dh.DeviceID, "err": tpErr, "tp-path": techProfMsg.TpInstancePath})
Girish Gowdra50e56422021-06-01 16:46:04 -0700386 return tpErr
387 }
388 deadline = time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
389 dctx2, cancel2 := context.WithDeadline(context.Background(), deadline)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000390 pDevEntry.ResetKvProcessingErrorIndication()
Girish Gowdra50e56422021-06-01 16:46:04 -0700391 wg.Add(1) // for the 1 go routine to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000392 go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg)
Girish Gowdra50e56422021-06-01 16:46:04 -0700393 dh.waitForCompletion(ctx, cancel2, &wg, "TechProfDwld") //wait for background process to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000394 if kvErr := pDevEntry.GetKvProcessingErrorIndication(); kvErr != nil {
395 logger.Errorw(ctx, "error-updating-KV", log.Fields{"device-id": dh.DeviceID, "err": kvErr, "tp-path": techProfMsg.TpInstancePath})
Girish Gowdra50e56422021-06-01 16:46:04 -0700396 return kvErr
397 }
398 return nil
399 default:
400 logger.Errorw(ctx, "unsupported-tp-instance-type", log.Fields{"tp-path": techProfMsg.TpInstancePath})
401 return fmt.Errorf("unsupported-tp-instance-type--tp-id-%v", techProfMsg.TpInstancePath)
Mahir Gunyel7f4483a2021-05-06 12:53:43 -0700402 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530403 }
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000404 // no change, nothing really to do - return success
Girish Gowdra50e56422021-06-01 16:46:04 -0700405 logger.Debugw(ctx, "onu-uni-tp-path-not-modified", log.Fields{"uniID": uniID, "tp-path": techProfMsg.TpInstancePath, "tpID": tpID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530406 return nil
407}
408
khenaidoo7d3c5582021-08-11 18:09:44 -0400409func (dh *deviceHandler) handleDeleteGemPortRequest(ctx context.Context, delGemPortMsg *ic.DeleteGemPortMessage) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000410 logger.Infow(ctx, "delete-gem-port-request", log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530411
412 if dh.pOnuTP == nil {
413 //should normally not happen ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000414 logger.Warnw(ctx, "onuTechProf instance not set up for DelGem request - ignoring request",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000415 log.Fields{"device-id": dh.DeviceID})
416 return fmt.Errorf("techProfile DelGem request while onuTechProf instance not setup: %s", dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +0530417 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530418 //compare TECH_PROFILE_DOWNLOAD_REQUEST
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000419 dh.pOnuTP.LockTpProcMutex()
420 defer dh.pOnuTP.UnlockTpProcMutex()
Himani Chawla26e555c2020-08-31 12:30:20 +0530421
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000422 if delGemPortMsg.UniId > 255 {
423 return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000424 delGemPortMsg.UniId, dh.DeviceID))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000425 }
426 uniID := uint8(delGemPortMsg.UniId)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000427 tpID, err := cmn.GetTpIDFromTpPath(delGemPortMsg.TpInstancePath)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800428 if err != nil {
Girish Gowdra50e56422021-06-01 16:46:04 -0700429 logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{"err": err, "tp-path": delGemPortMsg.TpInstancePath})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800430 return err
431 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000432 logger.Infow(ctx, "delete-gem-port-request", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "gem": delGemPortMsg.GemPortId})
mpagenkofc4f56e2020-11-04 17:17:49 +0000433 //a removal of some GemPort would never remove the complete TechProfile entry (done on T-Cont)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000434
Mahir Gunyel9545be22021-07-04 15:53:16 -0700435 return dh.deleteTechProfileResource(ctx, uniID, tpID, delGemPortMsg.TpInstancePath,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000436 avcfg.CResourceGemPort, delGemPortMsg.GemPortId)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000437
Himani Chawla26e555c2020-08-31 12:30:20 +0530438}
439
khenaidoo7d3c5582021-08-11 18:09:44 -0400440func (dh *deviceHandler) handleDeleteTcontRequest(ctx context.Context, delTcontMsg *ic.DeleteTcontMessage) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000441 logger.Infow(ctx, "delete-tcont-request", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000442
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000443 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000444 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000445 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
446 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000447 }
Himani Chawla26e555c2020-08-31 12:30:20 +0530448 if dh.pOnuTP == nil {
449 //should normally not happen ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000450 logger.Warnw(ctx, "onuTechProf instance not set up for DelTcont request - ignoring request",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000451 log.Fields{"device-id": dh.DeviceID})
452 return fmt.Errorf("techProfile DelTcont request while onuTechProf instance not setup: %s", dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +0530453 }
454
Himani Chawla26e555c2020-08-31 12:30:20 +0530455 //compare TECH_PROFILE_DOWNLOAD_REQUEST
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000456 dh.pOnuTP.LockTpProcMutex()
457 defer dh.pOnuTP.UnlockTpProcMutex()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000458
459 if delTcontMsg.UniId > 255 {
460 return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000461 delTcontMsg.UniId, dh.DeviceID))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000462 }
463 uniID := uint8(delTcontMsg.UniId)
Girish Gowdra50e56422021-06-01 16:46:04 -0700464 tpPath := delTcontMsg.TpInstancePath
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000465 tpID, err := cmn.GetTpIDFromTpPath(tpPath)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800466 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000467 logger.Errorw(ctx, "error-extracting-tp-id-from-tp-path", log.Fields{"err": err, "tp-path": tpPath})
Girish Gowdra041dcb32020-11-16 16:54:30 -0800468 return err
469 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000470 logger.Infow(ctx, "delete-tcont-request", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID, "tcont": delTcontMsg.AllocId})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000471
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000472 pDevEntry.FreeTcont(ctx, uint16(delTcontMsg.AllocId))
Himani Chawla26e555c2020-08-31 12:30:20 +0530473
Mahir Gunyel9545be22021-07-04 15:53:16 -0700474 return dh.deleteTechProfileResource(ctx, uniID, tpID, delTcontMsg.TpInstancePath,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000475 avcfg.CResourceTcont, delTcontMsg.AllocId)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000476
Mahir Gunyel9545be22021-07-04 15:53:16 -0700477}
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000478
Mahir Gunyel9545be22021-07-04 15:53:16 -0700479func (dh *deviceHandler) deleteTechProfileResource(ctx context.Context,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000480 uniID uint8, tpID uint8, pathString string, resource avcfg.ResourceEntry, entryID uint32) error {
481 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Mahir Gunyel9545be22021-07-04 15:53:16 -0700482 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000483 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
484 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +0530485 }
Mahir Gunyel9545be22021-07-04 15:53:16 -0700486 var resourceName string
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000487 if avcfg.CResourceGemPort == resource {
Mahir Gunyel9545be22021-07-04 15:53:16 -0700488 resourceName = "Gem"
489 } else {
490 resourceName = "Tcont"
491 }
492
493 // deadline context to ensure completion of background routines waited for
494 deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
495 dctx, cancel := context.WithDeadline(context.Background(), deadline)
496
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000497 dh.pOnuTP.ResetTpProcessingErrorIndication(uniID, tpID)
Mahir Gunyel9545be22021-07-04 15:53:16 -0700498
499 var wg sync.WaitGroup
500 wg.Add(1) // for the 1 go routine to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000501 go dh.pOnuTP.DeleteTpResource(log.WithSpanFromContext(dctx, ctx), uniID, tpID, pathString,
Mahir Gunyel9545be22021-07-04 15:53:16 -0700502 resource, entryID, &wg)
503 dh.waitForCompletion(ctx, cancel, &wg, resourceName+"Delete") //wait for background process to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000504 if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniID, tpID); err != nil {
505 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
Mahir Gunyel9545be22021-07-04 15:53:16 -0700506 return err
507 }
508
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000509 if dh.pOnuTP.IsTechProfileConfigCleared(ctx, uniID, tpID) {
510 logger.Debugw(ctx, "techProfile-config-cleared", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID})
511 if bTpModify := pDevEntry.UpdateOnuUniTpPath(ctx, uniID, tpID, ""); bTpModify {
512 pDevEntry.ResetKvProcessingErrorIndication()
Mahir Gunyel9545be22021-07-04 15:53:16 -0700513 var wg2 sync.WaitGroup
514 dctx2, cancel2 := context.WithDeadline(context.Background(), deadline)
515 wg2.Add(1)
516 // Removal of the gem id mapping represents the removal of the tech profile
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000517 logger.Infow(ctx, "remove-techProfile-indication-in-kv", log.Fields{"device-id": dh.DeviceID, "uni-id": uniID, "tpID": tpID})
518 go pDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx2, ctx), &wg2)
Mahir Gunyel9545be22021-07-04 15:53:16 -0700519 dh.waitForCompletion(ctx, cancel2, &wg2, "TechProfileDeleteOn"+resourceName) //wait for background process to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000520 if err := pDevEntry.GetKvProcessingErrorIndication(); err != nil {
521 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
Mahir Gunyel9545be22021-07-04 15:53:16 -0700522 return err
523 }
524 }
525 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000526 logger.Debugw(ctx, "delete-tech-profile-resource-completed", log.Fields{"device-id": dh.DeviceID,
Mahir Gunyel9545be22021-07-04 15:53:16 -0700527 "uni-id": uniID, "tpID": tpID, "resource-type": resourceName, "resource-id": entryID})
Himani Chawla26e555c2020-08-31 12:30:20 +0530528 return nil
529}
530
mpagenkodff5dda2020-08-28 11:52:01 +0000531//FlowUpdateIncremental removes and/or adds the flow changes on a given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000532func (dh *deviceHandler) FlowUpdateIncremental(ctx context.Context,
khenaidoo7d3c5582021-08-11 18:09:44 -0400533 apOfFlowChanges *of.FlowChanges,
534 apOfGroupChanges *of.FlowGroupChanges, apFlowMetaData *voltha.FlowMetadata) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000535 logger.Debugw(ctx, "FlowUpdateIncremental started", log.Fields{"device-id": dh.DeviceID, "metadata": apFlowMetaData})
mpagenko01e726e2020-10-23 09:45:29 +0000536 var retError error = nil
537 //Remove flows (always remove flows first - remove old and add new with same cookie may be part of the same request)
mpagenkodff5dda2020-08-28 11:52:01 +0000538 if apOfFlowChanges.ToRemove != nil {
539 for _, flowItem := range apOfFlowChanges.ToRemove.Items {
mpagenkodff5dda2020-08-28 11:52:01 +0000540 if flowItem.GetCookie() == 0 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000541 logger.Warnw(ctx, "flow-remove no cookie: ignore and continuing on checking further flows", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000542 "device-id": dh.DeviceID})
543 retError = fmt.Errorf("flow-remove no cookie, device-id %s", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +0000544 continue
545 }
546 flowInPort := flow.GetInPort(flowItem)
547 if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000548 logger.Warnw(ctx, "flow-remove inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID})
549 retError = fmt.Errorf("flow-remove inPort invalid, device-id %s", dh.DeviceID)
mpagenko01e726e2020-10-23 09:45:29 +0000550 continue
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000551 //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +0000552 } else if flowInPort == dh.ponPortNumber {
mpagenko01e726e2020-10-23 09:45:29 +0000553 //this is some downstream flow, not regarded as error, just ignored
dbainbri4d3a0dc2020-12-02 00:33:42 +0000554 logger.Debugw(ctx, "flow-remove for downstream: ignore and continuing on checking further flows", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000555 "device-id": dh.DeviceID, "inPort": flowInPort})
mpagenkodff5dda2020-08-28 11:52:01 +0000556 continue
557 } else {
558 // this is the relevant upstream flow
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000559 var loUniPort *cmn.OnuUniPort
mpagenkodff5dda2020-08-28 11:52:01 +0000560 if uniPort, exist := dh.uniEntityMap[flowInPort]; exist {
561 loUniPort = uniPort
562 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000563 logger.Warnw(ctx, "flow-remove inPort not found in UniPorts: ignore and continuing on checking further flows",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000564 log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort})
mpagenko01e726e2020-10-23 09:45:29 +0000565 retError = fmt.Errorf("flow-remove inPort not found in UniPorts, inPort %d, device-id %s",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000566 flowInPort, dh.DeviceID)
mpagenko01e726e2020-10-23 09:45:29 +0000567 continue
mpagenkodff5dda2020-08-28 11:52:01 +0000568 }
569 flowOutPort := flow.GetOutPort(flowItem)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000570 logger.Debugw(ctx, "flow-remove port indications", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000571 "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort,
572 "uniPortName": loUniPort.Name})
dbainbri4d3a0dc2020-12-02 00:33:42 +0000573 err := dh.removeFlowItemFromUniPort(ctx, flowItem, loUniPort)
mpagenko01e726e2020-10-23 09:45:29 +0000574 //try next flow after processing error
mpagenkodff5dda2020-08-28 11:52:01 +0000575 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000576 logger.Warnw(ctx, "flow-remove processing error: continuing on checking further flows",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000577 log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko01e726e2020-10-23 09:45:29 +0000578 retError = err
579 continue
580 //return err
581 } else { // if last setting succeeds, overwrite possibly previously set error
582 retError = nil
mpagenkodff5dda2020-08-28 11:52:01 +0000583 }
584 }
585 }
586 }
mpagenko01e726e2020-10-23 09:45:29 +0000587 if apOfFlowChanges.ToAdd != nil {
588 for _, flowItem := range apOfFlowChanges.ToAdd.Items {
589 if flowItem.GetCookie() == 0 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000590 logger.Debugw(ctx, "incremental flow-add no cookie: ignore and continuing on checking further flows", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000591 "device-id": dh.DeviceID})
592 retError = fmt.Errorf("flow-add no cookie, device-id %s", dh.DeviceID)
mpagenko01e726e2020-10-23 09:45:29 +0000593 continue
594 }
595 flowInPort := flow.GetInPort(flowItem)
596 if flowInPort == uint32(of.OfpPortNo_OFPP_INVALID) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000597 logger.Warnw(ctx, "flow-add inPort invalid: ignore and continuing on checking further flows", log.Fields{"device-id": dh.DeviceID})
598 retError = fmt.Errorf("flow-add inPort invalid, device-id %s", dh.DeviceID)
mpagenko01e726e2020-10-23 09:45:29 +0000599 continue
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000600 //return fmt.Errorf("flow inPort invalid: %s", dh.DeviceID)
mpagenko01e726e2020-10-23 09:45:29 +0000601 } else if flowInPort == dh.ponPortNumber {
602 //this is some downstream flow
dbainbri4d3a0dc2020-12-02 00:33:42 +0000603 logger.Debugw(ctx, "flow-add for downstream: ignore and continuing on checking further flows", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000604 "device-id": dh.DeviceID, "inPort": flowInPort})
mpagenko01e726e2020-10-23 09:45:29 +0000605 continue
606 } else {
607 // this is the relevant upstream flow
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000608 var loUniPort *cmn.OnuUniPort
mpagenko01e726e2020-10-23 09:45:29 +0000609 if uniPort, exist := dh.uniEntityMap[flowInPort]; exist {
610 loUniPort = uniPort
611 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000612 logger.Warnw(ctx, "flow-add inPort not found in UniPorts: ignore and continuing on checking further flows",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000613 log.Fields{"device-id": dh.DeviceID, "inPort": flowInPort})
mpagenko01e726e2020-10-23 09:45:29 +0000614 retError = fmt.Errorf("flow-add inPort not found in UniPorts, inPort %d, device-id %s",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000615 flowInPort, dh.DeviceID)
mpagenko01e726e2020-10-23 09:45:29 +0000616 continue
617 //return fmt.Errorf("flow-parameter inPort %d not found in internal UniPorts", flowInPort)
618 }
mpagenkofc4f56e2020-11-04 17:17:49 +0000619 // let's still assume that we receive the flow-add only in some 'active' device state (as so far observed)
620 // if not, we just throw some error here to have an indication about that, if we really need to support that
621 // then we would need to create some means to activate the internal stored flows
622 // after the device gets active automatically (and still with its dependency to the TechProfile)
623 // for state checking compare also code here: processInterAdapterTechProfileDownloadReqMessage
624 // also abort for the other still possible flows here
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000625 if !dh.IsReadyForOmciConfig() {
626 logger.Errorw(ctx, "flow-add rejected: improper device state", log.Fields{"device-id": dh.DeviceID,
627 "last device-reason": dh.GetDeviceReasonString()})
628 return fmt.Errorf("improper device state on device %s", dh.DeviceID)
mpagenkofc4f56e2020-11-04 17:17:49 +0000629 }
630
mpagenko01e726e2020-10-23 09:45:29 +0000631 flowOutPort := flow.GetOutPort(flowItem)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000632 logger.Debugw(ctx, "flow-add port indications", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000633 "device-id": dh.DeviceID, "inPort": flowInPort, "outPort": flowOutPort,
634 "uniPortName": loUniPort.Name})
ozgecanetsia82b91a62021-05-21 18:54:49 +0300635 err := dh.addFlowItemToUniPort(ctx, flowItem, loUniPort, apFlowMetaData)
mpagenko01e726e2020-10-23 09:45:29 +0000636 //try next flow after processing error
637 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000638 logger.Warnw(ctx, "flow-add processing error: continuing on checking further flows",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000639 log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko01e726e2020-10-23 09:45:29 +0000640 retError = err
641 continue
642 //return err
643 } else { // if last setting succeeds, overwrite possibly previously set error
644 retError = nil
645 }
646 }
647 }
648 }
649 return retError
mpagenkodff5dda2020-08-28 11:52:01 +0000650}
651
Himani Chawla6d2ae152020-09-02 13:11:20 +0530652//disableDevice locks the ONU and its UNI/VEIP ports (admin lock via OMCI)
mpagenkofc4f56e2020-11-04 17:17:49 +0000653//following are the expected device states after this activity:
654//Device Admin-State : down (on rwCore), Port-State: UNKNOWN, Conn-State: REACHABLE, Reason: omci-admin-lock
655// (Conn-State: REACHABLE might conflict with some previous ONU Down indication - maybe to be resolved later)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000656func (dh *deviceHandler) disableDevice(ctx context.Context, device *voltha.Device) {
657 logger.Debugw(ctx, "disable-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000658
mpagenko900ee4b2020-10-12 11:56:34 +0000659 //admin-lock reason can also be used uniquely for setting the DeviceState accordingly
mpagenkofc4f56e2020-11-04 17:17:49 +0000660 //note that disableDevice sequences in some 'ONU active' state may yield also
661 // "tech...delete-success" or "omci-flow-deleted" according to further received requests in the end
mpagenko900ee4b2020-10-12 11:56:34 +0000662 // - inblock state checking to prevent possibly unneeded processing (on command repitition)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000663 if dh.getDeviceReason() != cmn.DrOmciAdminLock {
mpagenkofc4f56e2020-11-04 17:17:49 +0000664 //disable-device shall be just a UNi/ONU-G related admin state setting
665 //all other configurations/FSM's shall not be impacted and shall execute as required by the system
mpagenko900ee4b2020-10-12 11:56:34 +0000666
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000667 if dh.IsReadyForOmciConfig() {
mpagenko01e726e2020-10-23 09:45:29 +0000668 // disable UNI ports/ONU
669 // *** should generate UniDisableStateDone event - used to disable the port(s) on success
670 if dh.pLockStateFsm == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000671 dh.createUniLockFsm(ctx, true, cmn.UniDisableStateDone)
mpagenko01e726e2020-10-23 09:45:29 +0000672 } else { //LockStateFSM already init
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000673 dh.pLockStateFsm.SetSuccessEvent(cmn.UniDisableStateDone)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000674 dh.runUniLockFsm(ctx, true)
mpagenko01e726e2020-10-23 09:45:29 +0000675 }
676 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000677 logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000678 "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID})
khenaidoo7d3c5582021-08-11 18:09:44 -0400679 if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000680 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -0400681 ConnStatus: voltha.ConnectStatus_REACHABLE,
682 OperStatus: voltha.OperStatus_UNKNOWN,
683 }); err != nil {
mpagenko01e726e2020-10-23 09:45:29 +0000684 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000685 logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko01e726e2020-10-23 09:45:29 +0000686 }
mpagenko01e726e2020-10-23 09:45:29 +0000687 // DeviceReason to update acc.to modified py code as per beginning of Sept 2020
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000688
689 //TODO with VOL-3045/VOL-3046: catch and return error, valid for all occurrences in the codebase
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000690 _ = dh.deviceReasonUpdate(ctx, cmn.DrOmciAdminLock, true)
mpagenko3af1f032020-06-10 08:53:41 +0000691 }
ozgecanetsiafce57b12020-05-25 14:39:35 +0300692 }
693}
694
Himani Chawla6d2ae152020-09-02 13:11:20 +0530695//reEnableDevice unlocks the ONU and its UNI/VEIP ports (admin unlock via OMCI)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000696func (dh *deviceHandler) reEnableDevice(ctx context.Context, device *voltha.Device) {
697 logger.Debugw(ctx, "reenable-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber})
mpagenko3af1f032020-06-10 08:53:41 +0000698
mpagenkoaa3afe92021-05-21 16:20:58 +0000699 //setting readyForOmciConfig here is just a workaround for BBSIM testing in the sequence
mpagenkofc4f56e2020-11-04 17:17:49 +0000700 // OnuSoftReboot-disable-enable, because BBSIM does not generate a new OnuIndication-Up event after SoftReboot
701 // which is the assumption for real ONU's, where the ready-state is then set according to the following MibUpload/Download
702 // for real ONU's that should have nearly no influence
703 // Note that for real ONU's there is anyway a problematic situation with following sequence:
704 // OnuIndication-Dw (or not active at all) (- disable) - enable: here already the LockFsm may run into timeout (no OmciResponse)
705 // but that anyway is hopefully resolved by some OnuIndication-Up event (maybe to be tested)
706 // one could also argue, that a device-enable should also enable attempts for specific omci configuration
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000707 dh.SetReadyForOmciConfig(true) //needed to allow subsequent flow/techProf config (on BBSIM)
mpagenkofc4f56e2020-11-04 17:17:49 +0000708
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000709 // enable ONU/UNI ports
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000710 // *** should generate cmn.UniEnableStateDone event - used to disable the port(s) on success
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000711 if dh.pUnlockStateFsm == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000712 dh.createUniLockFsm(ctx, false, cmn.UniEnableStateDone)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000713 } else { //UnlockStateFSM already init
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000714 dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniEnableStateDone)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000715 dh.runUniLockFsm(ctx, false)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000716 }
ozgecanetsiafce57b12020-05-25 14:39:35 +0300717}
718
dbainbri4d3a0dc2020-12-02 00:33:42 +0000719func (dh *deviceHandler) reconcileDeviceOnuInd(ctx context.Context) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000720 logger.Debugw(ctx, "reconciling - simulate onu indication", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000721
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000722 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000723 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000724 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000725 return
726 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000727 if err := pDevEntry.RestoreDataFromOnuKvStore(log.WithSpanFromContext(context.TODO(), ctx)); err != nil {
mpagenko2418ab02020-11-12 12:58:06 +0000728 if err == fmt.Errorf("no-ONU-data-found") {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000729 logger.Debugw(ctx, "no persistent data found - abort reconciling", log.Fields{"device-id": dh.DeviceID})
mpagenko2418ab02020-11-12 12:58:06 +0000730 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000731 logger.Errorw(ctx, "reconciling - restoring OnuTp-data failed - abort", log.Fields{"err": err, "device-id": dh.DeviceID})
mpagenko2418ab02020-11-12 12:58:06 +0000732 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000733 dh.StopReconciling(ctx, false)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000734 return
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000735 }
Himani Chawla4d908332020-08-31 12:30:20 +0530736 var onuIndication oop.OnuIndication
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000737 pDevEntry.MutexPersOnuConfig.RLock()
738 onuIndication.IntfId = pDevEntry.SOnuPersistentData.PersIntfID
739 onuIndication.OnuId = pDevEntry.SOnuPersistentData.PersOnuID
740 onuIndication.OperState = pDevEntry.SOnuPersistentData.PersOperState
741 onuIndication.AdminState = pDevEntry.SOnuPersistentData.PersAdminState
742 pDevEntry.MutexPersOnuConfig.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000743 _ = dh.createInterface(ctx, &onuIndication)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000744}
745
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000746func (dh *deviceHandler) ReconcileDeviceTechProf(ctx context.Context) {
747 logger.Debugw(ctx, "reconciling - trigger tech profile config", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000748
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000749 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000750 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000751 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
752 if !dh.IsSkipOnuConfigReconciling() {
753 dh.StopReconciling(ctx, false)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000754 }
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000755 return
756 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000757 dh.pOnuTP.LockTpProcMutex()
758 defer dh.pOnuTP.UnlockTpProcMutex()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000759
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000760 pDevEntry.MutexPersOnuConfig.RLock()
mpagenko2dc896e2021-08-02 12:03:59 +0000761 persMutexLock := true
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000762 if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 {
763 pDevEntry.MutexPersOnuConfig.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000764 logger.Debugw(ctx, "reconciling - no uni-configs have been stored before adapter restart - terminate reconcilement",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000765 log.Fields{"device-id": dh.DeviceID})
766 if !dh.IsSkipOnuConfigReconciling() {
767 dh.StopReconciling(ctx, true)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000768 }
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000769 return
770 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000771 flowsFound := false
Girish Gowdra50e56422021-06-01 16:46:04 -0700772 techProfsFound := false
773 techProfInstLoadFailed := false
774outerLoop:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000775 for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig {
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000776 //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support
777 if len(uniData.PersTpPathMap) == 0 {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000778 logger.Debugw(ctx, "reconciling - no TPs stored for uniID",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000779 log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000780 continue
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000781 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000782 //release MutexPersOnuConfig before TechProfile (ANIConfig) processing as otherwise the reception of
783 // OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI
mpagenko2dc896e2021-08-02 12:03:59 +0000784 // frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000785 pDevEntry.MutexPersOnuConfig.RUnlock()
mpagenko2dc896e2021-08-02 12:03:59 +0000786 persMutexLock = false
Girish Gowdra50e56422021-06-01 16:46:04 -0700787 techProfsFound = true // set to true if we found TP once for any UNI port
Girish Gowdra041dcb32020-11-16 16:54:30 -0800788 for tpID := range uniData.PersTpPathMap {
Girish Gowdra50e56422021-06-01 16:46:04 -0700789 // Request the TpInstance again from the openolt adapter in case of reconcile
khenaidoo7d3c5582021-08-11 18:09:44 -0400790 iaTechTpInst, err := dh.getTechProfileInstanceFromParentAdapter(ctx,
791 dh.device.ProxyAddress.AdapterEndpoint,
792 &ic.TechProfileInstanceRequestMessage{
793 DeviceId: dh.device.Id,
794 TpInstancePath: uniData.PersTpPathMap[tpID],
795 ParentDeviceId: dh.parentID,
796 ParentPonPort: dh.device.ParentPortNo,
797 OnuId: dh.device.ProxyAddress.OnuId,
798 UniId: uint32(uniData.PersUniID),
799 })
Girish Gowdra50e56422021-06-01 16:46:04 -0700800 if err != nil || iaTechTpInst == nil {
801 logger.Errorw(ctx, "error fetching tp instance",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000802 log.Fields{"tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID, "err": err})
Girish Gowdra50e56422021-06-01 16:46:04 -0700803 techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure
804 break outerLoop
805 }
806 var tpInst tech_profile.TechProfileInstance
807 switch techTpInst := iaTechTpInst.TechTpInstance.(type) {
khenaidoo7d3c5582021-08-11 18:09:44 -0400808 case *ic.TechProfileDownloadMessage_TpInstance: // supports only GPON, XGPON, XGS-PON
Girish Gowdra50e56422021-06-01 16:46:04 -0700809 tpInst = *techTpInst.TpInstance
mpagenko2dc896e2021-08-02 12:03:59 +0000810 logger.Debugw(ctx, "received-tp-instance-successfully-after-reconcile", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000811 "tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
Girish Gowdra50e56422021-06-01 16:46:04 -0700812 default: // do not support epon or other tech
mpagenko2dc896e2021-08-02 12:03:59 +0000813 logger.Errorw(ctx, "unsupported-tech-profile", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000814 "tp-id": tpID, "tpPath": uniData.PersTpPathMap[tpID], "uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
Girish Gowdra50e56422021-06-01 16:46:04 -0700815 techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure
816 break outerLoop
817 }
818
Girish Gowdra041dcb32020-11-16 16:54:30 -0800819 // deadline context to ensure completion of background routines waited for
820 //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
821 deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
dbainbri4d3a0dc2020-12-02 00:33:42 +0000822 dctx, cancel := context.WithDeadline(ctx, deadline)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000823
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000824 dh.pOnuTP.ResetTpProcessingErrorIndication(uniData.PersUniID, tpID)
Girish Gowdra041dcb32020-11-16 16:54:30 -0800825 var wg sync.WaitGroup
826 wg.Add(1) // for the 1 go routine to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000827 go dh.pOnuTP.ConfigureUniTp(log.WithSpanFromContext(dctx, ctx), uniData.PersUniID, uniData.PersTpPathMap[tpID], tpInst, &wg)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000828 dh.waitForCompletion(ctx, cancel, &wg, "TechProfReconcile") //wait for background process to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000829 if err := dh.pOnuTP.GetTpProcessingErrorIndication(uniData.PersUniID, tpID); err != nil {
830 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
Girish Gowdra50e56422021-06-01 16:46:04 -0700831 techProfInstLoadFailed = true // stop loading tp instance as soon as we hit failure
832 break outerLoop
Girish Gowdra041dcb32020-11-16 16:54:30 -0800833 }
mpagenko2dc896e2021-08-02 12:03:59 +0000834 } // for all TpPath entries for this UNI
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000835 if len(uniData.PersFlowParams) != 0 {
836 flowsFound = true
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000837 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000838 pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData
mpagenko2dc896e2021-08-02 12:03:59 +0000839 persMutexLock = true
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000840 } // for all UNI entries from SOnuPersistentData
841 if persMutexLock { // if loop was left with MutexPersOnuConfig still set
842 pDevEntry.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000843 }
mpagenko2dc896e2021-08-02 12:03:59 +0000844
845 //had to move techProf/flow result evaluation into separate function due to SCA complexity limit
846 dh.updateReconcileStates(ctx, techProfsFound, techProfInstLoadFailed, flowsFound)
847}
848
849func (dh *deviceHandler) updateReconcileStates(ctx context.Context,
850 abTechProfsFound bool, abTechProfInstLoadFailed bool, abFlowsFound bool) {
851 if !abTechProfsFound {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000852 logger.Debugw(ctx, "reconciling - no TPs have been stored before adapter restart - terminate reconcilement",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000853 log.Fields{"device-id": dh.DeviceID})
854 if !dh.IsSkipOnuConfigReconciling() {
855 dh.StopReconciling(ctx, true)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000856 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000857 return
858 }
mpagenko2dc896e2021-08-02 12:03:59 +0000859 if abTechProfInstLoadFailed {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000860 dh.SetDeviceReason(cmn.DrTechProfileConfigDownloadFailed)
861 dh.StopReconciling(ctx, false)
Girish Gowdra50e56422021-06-01 16:46:04 -0700862 return
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000863 } else if dh.IsSkipOnuConfigReconciling() {
864 dh.SetDeviceReason(cmn.DrTechProfileConfigDownloadSuccess)
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000865 }
mpagenko2dc896e2021-08-02 12:03:59 +0000866 if !abFlowsFound {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000867 logger.Debugw(ctx, "reconciling - no flows have been stored before adapter restart - terminate reconcilement",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000868 log.Fields{"device-id": dh.DeviceID})
869 if !dh.IsSkipOnuConfigReconciling() {
870 dh.StopReconciling(ctx, true)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000871 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000872 }
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000873}
874
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000875func (dh *deviceHandler) ReconcileDeviceFlowConfig(ctx context.Context) {
876 logger.Debugw(ctx, "reconciling - trigger flow config", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000877
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000878 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000879 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000880 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
881 if !dh.IsSkipOnuConfigReconciling() {
882 dh.StopReconciling(ctx, false)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000883 }
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000884 return
885 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000886
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000887 pDevEntry.MutexPersOnuConfig.RLock()
888 if len(pDevEntry.SOnuPersistentData.PersUniConfig) == 0 {
889 pDevEntry.MutexPersOnuConfig.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000890 logger.Debugw(ctx, "reconciling - no uni-configs have been stored before adapter restart - terminate reconcilement",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000891 log.Fields{"device-id": dh.DeviceID})
892 if !dh.IsSkipOnuConfigReconciling() {
893 dh.StopReconciling(ctx, true)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000894 }
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000895 return
896 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000897 flowsFound := false
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000898 for _, uniData := range pDevEntry.SOnuPersistentData.PersUniConfig {
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000899 //TODO: check for uni-port specific reconcilement in case of multi-uni-port-per-onu-support
900 if len(uniData.PersFlowParams) == 0 {
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000901 logger.Debugw(ctx, "reconciling - no flows stored for uniID",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000902 log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000903 continue
904 }
905 if len(uniData.PersTpPathMap) == 0 {
906 logger.Warnw(ctx, "reconciling - flows but no TPs stored for uniID",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000907 log.Fields{"uni-id": uniData.PersUniID, "device-id": dh.DeviceID})
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000908 // It doesn't make sense to configure any flows if no TPs are available
909 continue
Holger Hildebrandt3a644642020-12-02 09:46:18 +0000910 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000911 //release MutexPersOnuConfig before VlanConfig processing as otherwise the reception of
912 // OMCI frames may get completely stuck due to lock request within IncrementMibDataSync() at OMCI
mpagenko2dc896e2021-08-02 12:03:59 +0000913 // frame reception may also lock the complete OMCI reception processing based on mutexRxSchedMap
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000914 pDevEntry.MutexPersOnuConfig.RUnlock()
mpagenko2dc896e2021-08-02 12:03:59 +0000915
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000916 var uniPort *cmn.OnuUniPort
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000917 var exist bool
Mahir Gunyelcb128ae2021-10-06 09:42:05 -0700918 uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(), uint32(uniData.PersUniID))
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000919 if uniPort, exist = dh.uniEntityMap[uniNo]; !exist {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000920 logger.Errorw(ctx, "reconciling - OnuUniPort data not found - terminate reconcilement",
921 log.Fields{"uniNo": uniNo, "device-id": dh.DeviceID})
922 if !dh.IsSkipOnuConfigReconciling() {
923 dh.StopReconciling(ctx, false)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000924 }
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000925 return
926 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000927 flowsFound = true
Andrea Campanellaf66ac6e2021-05-24 17:09:20 +0200928 lastFlowToReconcile := false
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000929 flowsProcessed := 0
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000930 pDevEntry.SetReconcilingFlows(true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000931 for _, flowData := range uniData.PersFlowParams {
mpagenko2dc896e2021-08-02 12:03:59 +0000932 logger.Debugw(ctx, "reconciling - add flow with cookie slice", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000933 "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, "cookies": flowData.CookieSlice})
Andrea Campanellaf66ac6e2021-05-24 17:09:20 +0200934 if flowsProcessed == len(uniData.PersFlowParams)-1 {
935 lastFlowToReconcile = true
936 }
mpagenko01e726e2020-10-23 09:45:29 +0000937 //the slice can be passed 'by value' here, - which internally passes its reference copy
mpagenko7d14de12021-07-27 08:31:56 +0000938 dh.lockVlanConfig.Lock()
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000939 if _, exist = dh.UniVlanConfigFsmMap[uniData.PersUniID]; exist {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000940 if err := dh.UniVlanConfigFsmMap[uniData.PersUniID].SetUniFlowParams(ctx, flowData.VlanRuleParams.TpID,
mpagenko01e726e2020-10-23 09:45:29 +0000941 flowData.CookieSlice, uint16(flowData.VlanRuleParams.MatchVid), uint16(flowData.VlanRuleParams.SetVid),
ozgecanetsia82b91a62021-05-21 18:54:49 +0300942 uint8(flowData.VlanRuleParams.SetPcp), lastFlowToReconcile, flowData.Meter); err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000943 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000944 }
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000945 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000946 if err := dh.createVlanFilterFsm(ctx, uniPort, flowData.VlanRuleParams.TpID, flowData.CookieSlice,
mpagenko01e726e2020-10-23 09:45:29 +0000947 uint16(flowData.VlanRuleParams.MatchVid), uint16(flowData.VlanRuleParams.SetVid),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000948 uint8(flowData.VlanRuleParams.SetPcp), cmn.OmciVlanFilterAddDone, lastFlowToReconcile, flowData.Meter); err != nil {
949 logger.Errorw(ctx, err.Error(), log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000950 }
951 }
mpagenko7d14de12021-07-27 08:31:56 +0000952 dh.lockVlanConfig.Unlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000953 flowsProcessed++
mpagenko2dc896e2021-08-02 12:03:59 +0000954 } //for all flows of this UNI
955 logger.Debugw(ctx, "reconciling - flows processed", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000956 "device-id": dh.DeviceID, "uni-id": uniData.PersUniID, "flowsProcessed": flowsProcessed,
957 "NumUniFlows": dh.UniVlanConfigFsmMap[uniData.PersUniID].NumUniFlows,
958 "ConfiguredUniFlow": dh.UniVlanConfigFsmMap[uniData.PersUniID].ConfiguredUniFlow})
Andrea Campanellaf66ac6e2021-05-24 17:09:20 +0200959 // this can't be used as global finished reconciling flag because
960 // assumes is getting called before the state machines for the last flow is completed,
961 // while this is not guaranteed.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000962 //dh.SetReconcilingFlows(false)
963 pDevEntry.MutexPersOnuConfig.RLock() //set protection again for loop test on SOnuPersistentData
964 } // for all UNI entries from SOnuPersistentData
965 pDevEntry.MutexPersOnuConfig.RUnlock()
mpagenko2dc896e2021-08-02 12:03:59 +0000966
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000967 if !flowsFound {
968 logger.Debugw(ctx, "reconciling - no flows have been stored before adapter restart - terminate reconcilement",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000969 log.Fields{"device-id": dh.DeviceID})
970 if !dh.IsSkipOnuConfigReconciling() {
971 dh.StopReconciling(ctx, true)
Holger Hildebrandt7e9de862021-03-26 14:01:49 +0000972 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +0000973 return
974 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000975 if dh.IsSkipOnuConfigReconciling() {
976 dh.SetDeviceReason(cmn.DrOmciFlowsPushed)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000977 }
978}
979
Holger Hildebrandt1b8f4ad2021-03-25 15:53:51 +0000980func (dh *deviceHandler) reconcileEnd(ctx context.Context) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000981 logger.Debugw(ctx, "reconciling - completed!", log.Fields{"device-id": dh.DeviceID})
982 dh.StopReconciling(ctx, true)
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000983}
984
dbainbri4d3a0dc2020-12-02 00:33:42 +0000985func (dh *deviceHandler) deleteDevicePersistencyData(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000986 logger.Debugw(ctx, "delete device persistency data", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000987
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000988 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000989 if pDevEntry == nil {
mpagenko2418ab02020-11-12 12:58:06 +0000990 //IfDevEntry does not exist here, no problem - no persistent data should have been stored
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000991 logger.Debugw(ctx, "OnuDevice does not exist - nothing to delete", log.Fields{"device-id": dh.DeviceID})
mpagenko2418ab02020-11-12 12:58:06 +0000992 return nil
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000993 }
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000994
995 // deadline context to ensure completion of background routines waited for
996 //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
Himani Chawlad96df182020-09-28 11:12:02 +0530997 deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
dbainbri4d3a0dc2020-12-02 00:33:42 +0000998 dctx, cancel := context.WithDeadline(ctx, deadline)
Holger Hildebrandt47555e72020-09-21 11:07:24 +0000999
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001000 pDevEntry.ResetKvProcessingErrorIndication()
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001001
1002 var wg sync.WaitGroup
1003 wg.Add(1) // for the 1 go routine to finish
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001004 go pDevEntry.DeleteDataFromOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001005 dh.waitForCompletion(ctx, cancel, &wg, "DeleteDevice") //wait for background process to finish
Holger Hildebrandt47555e72020-09-21 11:07:24 +00001006
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001007 // TODO: further actions - stop metrics and FSMs, remove device ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001008 return pDevEntry.GetKvProcessingErrorIndication()
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +00001009}
1010
mpagenko15ff4a52021-03-02 10:09:20 +00001011//func (dh *deviceHandler) rebootDevice(ctx context.Context, device *voltha.Device) error {
1012// before this change here return like this was used:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001013// return fmt.Errorf("device-unreachable: %s, %s", dh.DeviceID, device.SerialNumber)
mpagenko15ff4a52021-03-02 10:09:20 +00001014//was and is called in background - error return does not make sense
1015func (dh *deviceHandler) rebootDevice(ctx context.Context, aCheckDeviceState bool, device *voltha.Device) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001016 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": dh.DeviceID, "SerialNumber": dh.device.SerialNumber})
mpagenko15ff4a52021-03-02 10:09:20 +00001017 if aCheckDeviceState && device.ConnectStatus != voltha.ConnectStatus_REACHABLE {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001018 logger.Errorw(ctx, "device-unreachable", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber})
mpagenko15ff4a52021-03-02 10:09:20 +00001019 return
ozgecanetsiae11479f2020-07-06 09:44:47 +03001020 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001021 if err := dh.pOnuOmciDevice.Reboot(log.WithSpanFromContext(context.TODO(), ctx)); err != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301022 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001023 logger.Errorw(ctx, "error-rebooting-device", log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko15ff4a52021-03-02 10:09:20 +00001024 return
Himani Chawla4d908332020-08-31 12:30:20 +05301025 }
mpagenko01e726e2020-10-23 09:45:29 +00001026
1027 //transfer the possibly modified logical uni port state
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001028 dh.DisableUniPortStateUpdate(ctx)
mpagenko01e726e2020-10-23 09:45:29 +00001029
dbainbri4d3a0dc2020-12-02 00:33:42 +00001030 logger.Debugw(ctx, "call DeviceStateUpdate upon reboot", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001031 "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID})
khenaidoo7d3c5582021-08-11 18:09:44 -04001032 if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001033 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04001034 ConnStatus: voltha.ConnectStatus_REACHABLE,
1035 OperStatus: voltha.OperStatus_DISCOVERED,
1036 }); err != nil {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001037 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001038 logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko15ff4a52021-03-02 10:09:20 +00001039 return
ozgecanetsiae11479f2020-07-06 09:44:47 +03001040 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001041 if err := dh.deviceReasonUpdate(ctx, cmn.DrRebooting, true); err != nil {
mpagenko15ff4a52021-03-02 10:09:20 +00001042 return
ozgecanetsiae11479f2020-07-06 09:44:47 +03001043 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001044 dh.SetReadyForOmciConfig(false)
mpagenko8b07c1b2020-11-26 10:36:31 +00001045 //no specific activity to synchronize any internal FSM to the 'rebooted' state is explicitly done here
1046 // the expectation ids for a real device, that it will be synced with the expected following 'down' indication
1047 // as BBSIM does not support this testing requires explicite disable/enable device calls in which sequence also
1048 // all other FSM's should be synchronized again
ozgecanetsiae11479f2020-07-06 09:44:47 +03001049}
1050
mpagenkoc8bba412021-01-15 15:38:44 +00001051//doOnuSwUpgrade initiates the SW download transfer to the ONU and on success activates the (inactive) image
mpagenko38662d02021-08-11 09:45:19 +00001052// used only for old - R2.7 style - upgrade API
mpagenko80622a52021-02-09 16:53:23 +00001053func (dh *deviceHandler) doOnuSwUpgrade(ctx context.Context, apImageDsc *voltha.ImageDownload,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001054 apDownloadManager *swupg.AdapterDownloadManager) error {
mpagenko80622a52021-02-09 16:53:23 +00001055 logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001056 "device-id": dh.DeviceID, "image-name": (*apImageDsc).Name})
mpagenko80622a52021-02-09 16:53:23 +00001057
1058 var err error
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001059 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
mpagenko15ff4a52021-03-02 10:09:20 +00001060 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001061 logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
1062 return fmt.Errorf("start Onu SW upgrade rejected: no valid OnuDevice for device-id: %s", dh.DeviceID)
mpagenko15ff4a52021-03-02 10:09:20 +00001063 }
1064
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001065 if dh.IsReadyForOmciConfig() {
mpagenko15ff4a52021-03-02 10:09:20 +00001066 var inactiveImageID uint16
1067 if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil {
1068 dh.lockUpgradeFsm.Lock()
mpagenko59862f02021-10-11 08:53:18 +00001069 //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm()
1070 // but must be still locked at calling createOnuUpgradeFsm
mpagenko15ff4a52021-03-02 10:09:20 +00001071 if dh.pOnuUpradeFsm == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001072 err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone)
mpagenko59862f02021-10-11 08:53:18 +00001073 dh.lockUpgradeFsm.Unlock()
mpagenko15ff4a52021-03-02 10:09:20 +00001074 if err == nil {
1075 if err = dh.pOnuUpradeFsm.SetDownloadParams(ctx, inactiveImageID, apImageDsc, apDownloadManager); err != nil {
1076 logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001077 "device-id": dh.DeviceID, "error": err})
mpagenko15ff4a52021-03-02 10:09:20 +00001078 }
1079 } else {
1080 logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001081 "device-id": dh.DeviceID, "error": err})
mpagenko80622a52021-02-09 16:53:23 +00001082 }
mpagenko15ff4a52021-03-02 10:09:20 +00001083 } else { //OnuSw upgrade already running - restart (with possible abort of running)
mpagenko59862f02021-10-11 08:53:18 +00001084 dh.lockUpgradeFsm.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001085 logger.Debugw(ctx, "Onu SW upgrade already running - abort", log.Fields{"device-id": dh.DeviceID})
mpagenko59862f02021-10-11 08:53:18 +00001086 if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation
1087 dh.upgradeCanceled = true
1088 dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort
1089 }
mpagenko38662d02021-08-11 09:45:19 +00001090 //no effort spent anymore for the old API to automatically cancel and restart the download
1091 // like done for the new API
mpagenko80622a52021-02-09 16:53:23 +00001092 }
mpagenko15ff4a52021-03-02 10:09:20 +00001093 } else {
1094 logger.Errorw(ctx, "start Onu SW upgrade rejected: no inactive image", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001095 "device-id": dh.DeviceID, "error": err})
mpagenko80622a52021-02-09 16:53:23 +00001096 }
1097 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001098 logger.Errorw(ctx, "start Onu SW upgrade rejected: no active OMCI connection", log.Fields{"device-id": dh.DeviceID})
1099 err = fmt.Errorf("start Onu SW upgrade rejected: no active OMCI connection for device-id: %s", dh.DeviceID)
mpagenko80622a52021-02-09 16:53:23 +00001100 }
1101 return err
mpagenkoc8bba412021-01-15 15:38:44 +00001102}
1103
mpagenkoc26d4c02021-05-06 14:27:57 +00001104//onuSwUpgradeAfterDownload initiates the SW download transfer to the ONU with activate and commit options
1105// after the OnuImage has been downloaded to the adapter, called in background
1106func (dh *deviceHandler) onuSwUpgradeAfterDownload(ctx context.Context, apImageRequest *voltha.DeviceImageDownloadRequest,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001107 apDownloadManager *swupg.FileDownloadManager, aImageIdentifier string) {
mpagenkoc26d4c02021-05-06 14:27:57 +00001108
1109 var err error
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001110 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
mpagenkoc26d4c02021-05-06 14:27:57 +00001111 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001112 logger.Errorw(ctx, "start Onu SW upgrade rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
mpagenkoc26d4c02021-05-06 14:27:57 +00001113 return
1114 }
1115
1116 var inactiveImageID uint16
1117 if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err == nil {
1118 logger.Debugw(ctx, "onuSwUpgrade requested", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001119 "device-id": dh.DeviceID, "image-version": apImageRequest.Image.Version, "to onu-image": inactiveImageID})
mpagenko38662d02021-08-11 09:45:19 +00001120
mpagenko59862f02021-10-11 08:53:18 +00001121 dh.lockUpgradeFsm.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001122 //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm()
mpagenko59862f02021-10-11 08:53:18 +00001123 // but must be still locked at calling createOnuUpgradeFsm
1124 // (and working with a local pointer copy does not work here if asynchronous request are done to fast
1125 // [e.g.leaving the local pointer on nil even though a creation is already on the way])
1126 if dh.pOnuUpradeFsm != nil {
mpagenko38662d02021-08-11 09:45:19 +00001127 //OnuSw upgrade already running on this device (e.g. with activate/commit not yet set)
1128 // abort the current processing, running upgrades are always aborted by newer request
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001129 logger.Debugw(ctx, "Onu SW upgrade already running - abort previous activity", log.Fields{"device-id": dh.DeviceID})
mpagenko38662d02021-08-11 09:45:19 +00001130 //flush the remove upgradeFsmChan channel
1131 select {
1132 case <-dh.upgradeFsmChan:
1133 logger.Debug(ctx, "flushed-upgrade-fsm-channel")
1134 default:
mpagenkoc26d4c02021-05-06 14:27:57 +00001135 }
mpagenko59862f02021-10-11 08:53:18 +00001136 dh.lockUpgradeFsm.Unlock()
1137 if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation
1138 dh.upgradeCanceled = true
1139 dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort
1140 }
mpagenko38662d02021-08-11 09:45:19 +00001141 select {
1142 case <-time.After(cTimeOutRemoveUpgrade * time.Second):
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001143 logger.Errorw(ctx, "could not remove Upgrade FSM in time, aborting", log.Fields{"device-id": dh.DeviceID})
mpagenko38662d02021-08-11 09:45:19 +00001144 //should not appear, can't proceed with new upgrade, perhaps operator can retry manually later
1145 return
1146 case <-dh.upgradeFsmChan:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001147 logger.Debugw(ctx, "recent Upgrade FSM removed, proceed with new request", log.Fields{"device-id": dh.DeviceID})
mpagenko38662d02021-08-11 09:45:19 +00001148 }
mpagenko59862f02021-10-11 08:53:18 +00001149 dh.lockUpgradeFsm.Lock() //lock again for following creation
mpagenkoc26d4c02021-05-06 14:27:57 +00001150 }
mpagenko38662d02021-08-11 09:45:19 +00001151
1152 //here it can be assumed that no running upgrade processing exists (anymore)
mpagenko59862f02021-10-11 08:53:18 +00001153 //OmciOnuSwUpgradeDone could be used to create some event notification with information on upgrade completion,
mpagenko38662d02021-08-11 09:45:19 +00001154 // but none yet defined
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001155 err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone)
mpagenko59862f02021-10-11 08:53:18 +00001156 dh.lockUpgradeFsm.Unlock()
mpagenko38662d02021-08-11 09:45:19 +00001157 if err == nil {
1158 if err = dh.pOnuUpradeFsm.SetDownloadParamsAfterDownload(ctx, inactiveImageID,
1159 apImageRequest, apDownloadManager, aImageIdentifier); err != nil {
1160 logger.Errorw(ctx, "onu upgrade fsm could not set parameters", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001161 "device-id": dh.DeviceID, "error": err})
mpagenkoc26d4c02021-05-06 14:27:57 +00001162 return
1163 }
mpagenko38662d02021-08-11 09:45:19 +00001164 } else {
1165 logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001166 "device-id": dh.DeviceID, "error": err})
mpagenkoc26d4c02021-05-06 14:27:57 +00001167 }
1168 return
1169 }
1170 logger.Errorw(ctx, "start Onu SW upgrade rejected: no inactive image", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001171 "device-id": dh.DeviceID, "error": err})
mpagenkoc26d4c02021-05-06 14:27:57 +00001172}
1173
1174//onuSwActivateRequest ensures activation of the requested image with commit options
mpagenko183647c2021-06-08 15:25:04 +00001175func (dh *deviceHandler) onuSwActivateRequest(ctx context.Context,
1176 aVersion string, aCommitRequest bool) (*voltha.ImageState, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +00001177 var err error
1178 //SW activation for the ONU image may have two use cases, one of them is selected here according to following prioritization:
1179 // 1.) activation of the image for a started upgrade process (in case the running upgrade runs on the requested image)
1180 // 2.) activation of the inactive image
1181
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001182 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
mpagenkoc26d4c02021-05-06 14:27:57 +00001183 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001184 logger.Errorw(ctx, "Onu image activation rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
1185 return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001186 }
1187 dh.lockUpgradeFsm.RLock()
1188 if dh.pOnuUpradeFsm != nil {
1189 dh.lockUpgradeFsm.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001190 onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001191 if getErr != nil || onuVolthaDevice == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001192 logger.Errorw(ctx, "Failed to fetch Onu device for image activation", log.Fields{"device-id": dh.DeviceID, "err": getErr})
1193 return nil, fmt.Errorf("could not fetch device for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001194 }
mpagenko59862f02021-10-11 08:53:18 +00001195 if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation
1196 logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID})
1197 return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID)
1198 }
mpagenkoc26d4c02021-05-06 14:27:57 +00001199 // use the OnuVendor identification from this device for the internal unique name
1200 imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU
mpagenko38662d02021-08-11 09:45:19 +00001201 // 1.) check a started upgrade process and relay the activation request to it
mpagenkoc26d4c02021-05-06 14:27:57 +00001202 if err = dh.pOnuUpradeFsm.SetActivationParamsRunning(ctx, imageIdentifier, aCommitRequest); err != nil {
mpagenko183647c2021-06-08 15:25:04 +00001203 //if some ONU upgrade is ongoing we do not accept some explicit ONU image-version related activation
mpagenkoc26d4c02021-05-06 14:27:57 +00001204 logger.Errorw(ctx, "onu upgrade fsm did not accept activation while running", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001205 "device-id": dh.DeviceID, "error": err})
1206 return nil, fmt.Errorf("activation not accepted for this version for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001207 }
mpagenko183647c2021-06-08 15:25:04 +00001208 logger.Debugw(ctx, "image activation acknowledged by onu upgrade processing", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001209 "device-id": dh.DeviceID, "image-id": imageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +00001210 pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion)
mpagenko183647c2021-06-08 15:25:04 +00001211 return pImageStates, nil
mpagenkoc26d4c02021-05-06 14:27:57 +00001212 } //else
1213 dh.lockUpgradeFsm.RUnlock()
1214
1215 // 2.) check if requested image-version equals the inactive one and start its activation
1216 // (image version is not [yet] checked - would be possible, but with increased effort ...)
1217 var inactiveImageID uint16
1218 if inactiveImageID, err = pDevEntry.GetInactiveImageMeID(ctx); err != nil || inactiveImageID > 1 {
1219 logger.Errorw(ctx, "get inactive image failed", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001220 "device-id": dh.DeviceID, "err": err, "image-id": inactiveImageID})
1221 return nil, fmt.Errorf("no valid inactive image found for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001222 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001223 err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone)
mpagenkoc26d4c02021-05-06 14:27:57 +00001224 if err == nil {
1225 if err = dh.pOnuUpradeFsm.SetActivationParamsStart(ctx, aVersion,
1226 inactiveImageID, aCommitRequest); err != nil {
1227 logger.Errorw(ctx, "onu upgrade fsm did not accept activation to start", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001228 "device-id": dh.DeviceID, "error": err})
1229 return nil, fmt.Errorf("activation to start from scratch not accepted for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001230 }
1231 logger.Debugw(ctx, "inactive image activation acknowledged by onu upgrade", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001232 "device-id": dh.DeviceID, "image-version": aVersion})
mpagenko38662d02021-08-11 09:45:19 +00001233 pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion)
mpagenko183647c2021-06-08 15:25:04 +00001234 return pImageStates, nil
mpagenkoc26d4c02021-05-06 14:27:57 +00001235 } //else
1236 logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001237 "device-id": dh.DeviceID, "error": err})
1238 return nil, fmt.Errorf("could not start upgradeFsm for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001239}
1240
1241//onuSwCommitRequest ensures commitment of the requested image
mpagenko183647c2021-06-08 15:25:04 +00001242func (dh *deviceHandler) onuSwCommitRequest(ctx context.Context,
1243 aVersion string) (*voltha.ImageState, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +00001244 var err error
1245 //SW commitment for the ONU image may have two use cases, one of them is selected here according to following prioritization:
1246 // 1.) commitment of the image for a started upgrade process (in case the running upgrade runs on the requested image)
1247 // 2.) commitment of the active image
1248
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001249 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
mpagenkoc26d4c02021-05-06 14:27:57 +00001250 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001251 logger.Errorw(ctx, "Onu image commitment rejected: no valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
1252 return nil, fmt.Errorf("no valid OnuDevice for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001253 }
1254 dh.lockUpgradeFsm.RLock()
1255 if dh.pOnuUpradeFsm != nil {
1256 dh.lockUpgradeFsm.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001257 onuVolthaDevice, getErr := dh.getDeviceFromCore(ctx, dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001258 if getErr != nil || onuVolthaDevice == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001259 logger.Errorw(ctx, "Failed to fetch Onu device for image commitment", log.Fields{"device-id": dh.DeviceID, "err": getErr})
1260 return nil, fmt.Errorf("could not fetch device for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001261 }
mpagenko59862f02021-10-11 08:53:18 +00001262 if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation
1263 logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID})
1264 return nil, fmt.Errorf("request collides with some ongoing cancelation for device-id: %s", dh.DeviceID)
1265 }
mpagenkoc26d4c02021-05-06 14:27:57 +00001266 // use the OnuVendor identification from this device for the internal unique name
1267 imageIdentifier := onuVolthaDevice.VendorId + aVersion //head on vendor ID of the ONU
mpagenko38662d02021-08-11 09:45:19 +00001268 // 1.) check a started upgrade process and relay the commitment request to it
1269 // the running upgrade may be based either on the imageIdentifier (started from download)
1270 // or on the imageVersion (started from pure activation)
1271 if err = dh.pOnuUpradeFsm.SetCommitmentParamsRunning(ctx, imageIdentifier, aVersion); err != nil {
1272 //if some ONU upgrade is ongoing we do not accept some explicit different ONU image-version related commitment
mpagenkoc26d4c02021-05-06 14:27:57 +00001273 logger.Errorw(ctx, "onu upgrade fsm did not accept commitment while running", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001274 "device-id": dh.DeviceID, "error": err})
1275 return nil, fmt.Errorf("commitment not accepted for this version for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001276 }
mpagenko183647c2021-06-08 15:25:04 +00001277 logger.Debugw(ctx, "image commitment acknowledged by onu upgrade processing", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001278 "device-id": dh.DeviceID, "image-id": imageIdentifier})
mpagenko38662d02021-08-11 09:45:19 +00001279 pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion)
mpagenko183647c2021-06-08 15:25:04 +00001280 return pImageStates, nil
mpagenkoc26d4c02021-05-06 14:27:57 +00001281 } //else
1282 dh.lockUpgradeFsm.RUnlock()
1283
mpagenko183647c2021-06-08 15:25:04 +00001284 // 2.) use the active image to directly commit
mpagenkoc26d4c02021-05-06 14:27:57 +00001285 var activeImageID uint16
1286 if activeImageID, err = pDevEntry.GetActiveImageMeID(ctx); err != nil || activeImageID > 1 {
1287 logger.Errorw(ctx, "get active image failed", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001288 "device-id": dh.DeviceID, "err": err, "image-id": activeImageID})
1289 return nil, fmt.Errorf("no valid active image found for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001290 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001291 err = dh.createOnuUpgradeFsm(ctx, pDevEntry, cmn.OmciOnuSwUpgradeDone)
mpagenkoc26d4c02021-05-06 14:27:57 +00001292 if err == nil {
1293 if err = dh.pOnuUpradeFsm.SetCommitmentParamsStart(ctx, aVersion, activeImageID); err != nil {
1294 logger.Errorw(ctx, "onu upgrade fsm did not accept commitment to start", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001295 "device-id": dh.DeviceID, "error": err})
1296 return nil, fmt.Errorf("commitment to start from scratch not accepted for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001297 }
1298 logger.Debugw(ctx, "active image commitment acknowledged by onu upgrade", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001299 "device-id": dh.DeviceID, "image-version": aVersion})
mpagenko38662d02021-08-11 09:45:19 +00001300 pImageStates := dh.pOnuUpradeFsm.GetImageStates(ctx, "", aVersion)
mpagenko183647c2021-06-08 15:25:04 +00001301 return pImageStates, nil
mpagenkoc26d4c02021-05-06 14:27:57 +00001302 } //else
1303 logger.Errorw(ctx, "onu upgrade fsm could not be created", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001304 "device-id": dh.DeviceID, "error": err})
1305 return nil, fmt.Errorf("could not start upgradeFsm for device-id: %s", dh.DeviceID)
mpagenkoc26d4c02021-05-06 14:27:57 +00001306}
1307
mpagenkoaa3afe92021-05-21 16:20:58 +00001308func (dh *deviceHandler) requestOnuSwUpgradeState(ctx context.Context, aImageIdentifier string,
mpagenko38662d02021-08-11 09:45:19 +00001309 aVersion string) *voltha.ImageState {
1310 var pImageState *voltha.ImageState
mpagenkoaa3afe92021-05-21 16:20:58 +00001311 dh.lockUpgradeFsm.RLock()
mpagenko38662d02021-08-11 09:45:19 +00001312 defer dh.lockUpgradeFsm.RUnlock()
mpagenkoaa3afe92021-05-21 16:20:58 +00001313 if dh.pOnuUpradeFsm != nil {
mpagenko38662d02021-08-11 09:45:19 +00001314 pImageState = dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion)
1315 } else { //use the last stored ImageState (if the requested Imageversion coincides)
1316 if aVersion == dh.pLastUpgradeImageState.Version {
1317 pImageState = dh.pLastUpgradeImageState
1318 } else { //state request for an image version different from last processed image version
1319 pImageState = &voltha.ImageState{
1320 Version: aVersion,
1321 //we cannot state something concerning this version
1322 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN,
1323 Reason: voltha.ImageState_NO_ERROR,
1324 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
1325 }
mpagenkoaa3afe92021-05-21 16:20:58 +00001326 }
1327 }
mpagenko38662d02021-08-11 09:45:19 +00001328 return pImageState
mpagenkoaa3afe92021-05-21 16:20:58 +00001329}
1330
1331func (dh *deviceHandler) cancelOnuSwUpgrade(ctx context.Context, aImageIdentifier string,
1332 aVersion string, pDeviceImageState *voltha.DeviceImageState) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001333 pDeviceImageState.DeviceId = dh.DeviceID
mpagenko7455fd42021-06-10 16:25:55 +00001334 pDeviceImageState.ImageState.Version = aVersion
mpagenkoaa3afe92021-05-21 16:20:58 +00001335 dh.lockUpgradeFsm.RLock()
1336 if dh.pOnuUpradeFsm != nil {
mpagenko45586762021-10-01 08:30:22 +00001337 dh.lockUpgradeFsm.RUnlock()
1338 // so then we cancel the upgrade operation
1339 // but before we still request the actual upgrade states (which should not change with the cancellation)
1340 pImageState := dh.pOnuUpradeFsm.GetImageStates(ctx, aImageIdentifier, aVersion)
1341 pDeviceImageState.ImageState.DownloadState = pImageState.DownloadState
1342 pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST
1343 pDeviceImageState.ImageState.ImageState = pImageState.ImageState
1344 if pImageState.DownloadState != voltha.ImageState_DOWNLOAD_UNKNOWN {
1345 //so here the imageIdentifier or version equals to what is used in the upgrade FSM
mpagenko59862f02021-10-11 08:53:18 +00001346 if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation
1347 dh.upgradeCanceled = true
1348 dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_REQUEST) //complete abort
1349 }
mpagenko45586762021-10-01 08:30:22 +00001350 } //nothing to cancel (upgrade FSM for different image stays alive)
mpagenkoaa3afe92021-05-21 16:20:58 +00001351 } else {
mpagenko45586762021-10-01 08:30:22 +00001352 dh.lockUpgradeFsm.RUnlock()
mpagenko38662d02021-08-11 09:45:19 +00001353 // if no upgrade is ongoing, nothing is canceled and accordingly the states of the requested image are unknown
1354 // reset also the dh handler LastUpgradeImageState (not relevant anymore/cleared)
1355 (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
1356 (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR
1357 (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN
1358 (*dh.pLastUpgradeImageState).Version = "" //reset to 'no (relevant) upgrade done' (like initial state)
mpagenkoaa3afe92021-05-21 16:20:58 +00001359 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
1360 pDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR
mpagenko38662d02021-08-11 09:45:19 +00001361 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
1362 //an abort request to a not active upgrade processing can be used to reset the device upgrade states completely
mpagenkoaa3afe92021-05-21 16:20:58 +00001363 }
1364}
1365
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00001366func (dh *deviceHandler) getOnuImages(ctx context.Context) (*voltha.OnuImages, error) {
1367
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001368 var onuImageStatus *swupg.OnuImageStatus
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00001369
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001370 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00001371 if pDevEntry != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001372 onuImageStatus = swupg.NewOnuImageStatus(dh, pDevEntry)
1373 pDevEntry.MutexOnuImageStatus.Lock()
1374 pDevEntry.POnuImageStatus = onuImageStatus
1375 pDevEntry.MutexOnuImageStatus.Unlock()
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00001376
1377 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001378 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00001379 return nil, fmt.Errorf("no-valid-OnuDevice-aborting")
1380 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001381 images, err := onuImageStatus.GetOnuImageStatus(ctx)
1382 pDevEntry.MutexOnuImageStatus.Lock()
1383 pDevEntry.POnuImageStatus = nil
1384 pDevEntry.MutexOnuImageStatus.Unlock()
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00001385 return images, err
1386}
1387
Himani Chawla6d2ae152020-09-02 13:11:20 +05301388// deviceHandler methods that implement the adapters interface requests## end #########
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001389// #####################################################################################
1390
1391// ################ to be updated acc. needs of ONU Device ########################
Himani Chawla6d2ae152020-09-02 13:11:20 +05301392// deviceHandler StateMachine related state transition methods ##### begin #########
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001393
dbainbri4d3a0dc2020-12-02 00:33:42 +00001394func (dh *deviceHandler) logStateChange(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001395 logger.Debugw(ctx, "Device FSM: ", log.Fields{"event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst), "device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001396}
1397
1398// doStateInit provides the device update to the core
dbainbri4d3a0dc2020-12-02 00:33:42 +00001399func (dh *deviceHandler) doStateInit(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001400
dbainbri4d3a0dc2020-12-02 00:33:42 +00001401 logger.Debug(ctx, "doStateInit-started")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001402 var err error
1403
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001404 // populate what we know. rest comes later after mib sync
1405 dh.device.Root = false
1406 dh.device.Vendor = "OpenONU"
1407 dh.device.Model = "go"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001408 dh.device.Reason = cmn.DeviceReasonMap[cmn.DrActivatingOnu]
1409 dh.SetDeviceReason(cmn.DrActivatingOnu)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001410
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001411 dh.logicalDeviceID = dh.DeviceID // really needed - what for ??? //TODO!!!
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001412
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001413 if !dh.IsReconciling() {
1414 logger.Infow(ctx, "DeviceUpdate", log.Fields{"deviceReason": dh.device.Reason, "device-id": dh.DeviceID})
khenaidoo7d3c5582021-08-11 18:09:44 -04001415 if err := dh.updateDeviceInCore(ctx, dh.device); err != nil {
1416 logger.Errorw(ctx, "device-update-failed", log.Fields{"device-id": dh.device.Id, "error": err})
1417 }
Himani Chawlac07fda02020-12-09 16:21:21 +05301418 //TODO Need to Update Device Reason To CORE as part of device update userstory
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001419 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001420 logger.Debugw(ctx, "reconciling - don't notify core about DeviceUpdate",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001421 log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001422 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001423
Himani Chawla4d908332020-08-31 12:30:20 +05301424 dh.parentID = dh.device.ParentId
Holger Hildebrandt24d51952020-05-04 14:03:42 +00001425 dh.ponPortNumber = dh.device.ParentPortNo
1426
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001427 // store proxy parameters for later communication - assumption: invariant, else they have to be requested dynamically!!
1428 dh.ProxyAddressID = dh.device.ProxyAddress.GetDeviceId()
1429 dh.ProxyAddressType = dh.device.ProxyAddress.GetDeviceType()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001430 logger.Debugw(ctx, "device-updated", log.Fields{"device-id": dh.DeviceID, "proxyAddressID": dh.ProxyAddressID,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001431 "proxyAddressType": dh.ProxyAddressType, "SNR": dh.device.SerialNumber,
Himani Chawla4d908332020-08-31 12:30:20 +05301432 "ParentId": dh.parentID, "ParentPortNo": dh.ponPortNumber})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001433
1434 /*
1435 self._pon = PonPort.create(self, self._pon_port_number)
1436 self._pon.add_peer(self.parent_id, self._pon_port_number)
1437 self.logger.debug('adding-pon-port-to-agent',
1438 type=self._pon.get_port().type,
1439 admin_state=self._pon.get_port().admin_state,
1440 oper_status=self._pon.get_port().oper_status,
1441 )
1442 */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001443 if !dh.IsReconciling() {
1444 logger.Debugw(ctx, "adding-pon-port", log.Fields{"device-id": dh.DeviceID, "ponPortNo": dh.ponPortNumber})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001445 var ponPortNo uint32 = 1
1446 if dh.ponPortNumber != 0 {
1447 ponPortNo = dh.ponPortNumber
1448 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001449
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001450 pPonPort := &voltha.Port{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001451 DeviceId: dh.DeviceID,
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001452 PortNo: ponPortNo,
1453 Label: fmt.Sprintf("pon-%d", ponPortNo),
1454 Type: voltha.Port_PON_ONU,
1455 OperStatus: voltha.OperStatus_ACTIVE,
Himani Chawla4d908332020-08-31 12:30:20 +05301456 Peers: []*voltha.Port_PeerPort{{DeviceId: dh.parentID, // Peer device is OLT
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001457 PortNo: ponPortNo}}, // Peer port is parent's port number
1458 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001459 if err = dh.CreatePortInCore(ctx, pPonPort); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001460 logger.Fatalf(ctx, "Device FSM: PortCreated-failed-%s", err)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001461 e.Cancel(err)
1462 return
1463 }
1464 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001465 logger.Debugw(ctx, "reconciling - pon-port already added", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001466 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001467 logger.Debug(ctx, "doStateInit-done")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001468}
1469
1470// postInit setups the DeviceEntry for the conerned device
dbainbri4d3a0dc2020-12-02 00:33:42 +00001471func (dh *deviceHandler) postInit(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001472
dbainbri4d3a0dc2020-12-02 00:33:42 +00001473 logger.Debug(ctx, "postInit-started")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001474 var err error
1475 /*
1476 dh.Client = oop.NewOpenoltClient(dh.clientCon)
1477 dh.pTransitionMap.Handle(ctx, GrpcConnected)
1478 return nil
1479 */
dbainbri4d3a0dc2020-12-02 00:33:42 +00001480 if err = dh.addOnuDeviceEntry(log.WithSpanFromContext(context.TODO(), ctx)); err != nil {
1481 logger.Fatalf(ctx, "Device FSM: addOnuDeviceEntry-failed-%s", err)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001482 e.Cancel(err)
1483 return
1484 }
1485
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001486 if dh.IsReconciling() {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001487 go dh.reconcileDeviceOnuInd(ctx)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001488 // reconcilement will be continued after mib download is done
1489 }
Girish Gowdrae09a6202021-01-12 18:10:59 -08001490
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001491 /*
1492 ############################################################################
1493 # Setup Alarm handler
1494 self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id,
1495 device.serial_number)
1496 ############################################################################
1497 # Setup PM configuration for this device
1498 # Pass in ONU specific options
1499 kwargs = {
1500 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
1501 'heartbeat': self.heartbeat,
1502 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
1503 }
1504 self.logger.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number)
1505 self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
1506 self.logical_device_id, device.serial_number,
1507 grouped=True, freq_override=False, **kwargs)
1508 pm_config = self._pm_metrics.make_proto()
1509 self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm)
1510 self.logger.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number)
1511 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
1512
1513 # Note, ONU ID and UNI intf set in add_uni_port method
1514 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
1515 ani_ports=[self._pon])
1516
1517 # Code to Run OMCI Test Action
1518 kwargs_omci_test_action = {
1519 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
1520 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
1521 }
1522 serial_number = device.serial_number
1523 self._test_request = OmciTestRequest(self.core_proxy,
1524 self.omci_agent, self.device_id,
1525 AniG, serial_number,
1526 self.logical_device_id,
1527 exclusive=False,
1528 **kwargs_omci_test_action)
1529
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001530 self.Enabled = True
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001531 else:
1532 self.logger.info('onu-already-activated')
1533 */
Girish Gowdrae09a6202021-01-12 18:10:59 -08001534
dbainbri4d3a0dc2020-12-02 00:33:42 +00001535 logger.Debug(ctx, "postInit-done")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001536}
1537
1538// doStateConnected get the device info and update to voltha core
1539// for comparison of the original method (not that easy to uncomment): compare here:
1540// voltha-openolt-adapter/adaptercore/device_handler.go
1541// -> this one obviously initiates all communication interfaces of the device ...?
dbainbri4d3a0dc2020-12-02 00:33:42 +00001542func (dh *deviceHandler) doStateConnected(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001543
dbainbri4d3a0dc2020-12-02 00:33:42 +00001544 logger.Debug(ctx, "doStateConnected-started")
Himani Chawla4d908332020-08-31 12:30:20 +05301545 err := errors.New("device FSM: function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001546 e.Cancel(err)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001547 logger.Debug(ctx, "doStateConnected-done")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001548}
1549
1550// doStateUp handle the onu up indication and update to voltha core
dbainbri4d3a0dc2020-12-02 00:33:42 +00001551func (dh *deviceHandler) doStateUp(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001552
dbainbri4d3a0dc2020-12-02 00:33:42 +00001553 logger.Debug(ctx, "doStateUp-started")
Himani Chawla4d908332020-08-31 12:30:20 +05301554 err := errors.New("device FSM: function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001555 e.Cancel(err)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001556 logger.Debug(ctx, "doStateUp-done")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001557
1558 /*
1559 // Synchronous call to update device state - this method is run in its own go routine
1560 if err := dh.coreProxy.DeviceStateUpdate(ctx, dh.device.Id, voltha.ConnectStatus_REACHABLE,
1561 voltha.OperStatus_ACTIVE); err != nil {
mpagenko01e726e2020-10-23 09:45:29 +00001562 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 +00001563 return err
1564 }
1565 return nil
1566 */
1567}
1568
1569// doStateDown handle the onu down indication
dbainbri4d3a0dc2020-12-02 00:33:42 +00001570func (dh *deviceHandler) doStateDown(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001571
dbainbri4d3a0dc2020-12-02 00:33:42 +00001572 logger.Debug(ctx, "doStateDown-started")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001573 var err error
1574
Holger Hildebrandt24d51952020-05-04 14:03:42 +00001575 device := dh.device
1576 if device == nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001577 /*TODO: needs to handle error scenarios */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001578 logger.Errorw(ctx, "Failed to fetch handler device", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001579 e.Cancel(err)
1580 return
1581 }
1582
1583 cloned := proto.Clone(device).(*voltha.Device)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001584 logger.Debugw(ctx, "do-state-down", log.Fields{"ClonedDeviceID": cloned.Id})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001585 /*
1586 // Update the all ports state on that device to disable
1587 if er := dh.coreProxy.PortsStateUpdate(ctx, cloned.Id, voltha.OperStatus_UNKNOWN); er != nil {
mpagenko01e726e2020-10-23 09:45:29 +00001588 logger.Errorw("updating-ports-failed", log.Fields{"device-id": device.Id, "error": er})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001589 return er
1590 }
1591
1592 //Update the device oper state and connection status
1593 cloned.OperStatus = voltha.OperStatus_UNKNOWN
1594 cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE
1595 dh.device = cloned
1596
1597 if er := dh.coreProxy.DeviceStateUpdate(ctx, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); er != nil {
mpagenko01e726e2020-10-23 09:45:29 +00001598 logger.Errorw("error-updating-device-state", log.Fields{"device-id": device.Id, "error": er})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001599 return er
1600 }
1601
1602 //get the child device for the parent device
1603 onuDevices, err := dh.coreProxy.GetChildDevices(ctx, dh.device.Id)
1604 if err != nil {
mpagenko01e726e2020-10-23 09:45:29 +00001605 logger.Errorw("failed to get child devices information", log.Fields{"device-id": dh.device.Id, "error": err})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001606 return err
1607 }
1608 for _, onuDevice := range onuDevices.Items {
1609
1610 // Update onu state as down in onu adapter
1611 onuInd := oop.OnuIndication{}
1612 onuInd.OperState = "down"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001613 er := dh.adapterProxy.SendInterAdapterMessage(ctx, &onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001614 "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "")
1615 if er != nil {
1616 logger.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd,
mpagenko01e726e2020-10-23 09:45:29 +00001617 "From Adapter": "openolt", "DevieType": onuDevice.Type, "device-id": onuDevice.Id})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001618 //Do not return here and continue to process other ONUs
1619 }
1620 }
1621 // * Discovered ONUs entries need to be cleared , since after OLT
1622 // is up, it starts sending discovery indications again* /
1623 dh.discOnus = sync.Map{}
mpagenko01e726e2020-10-23 09:45:29 +00001624 logger.Debugw("do-state-down-end", log.Fields{"device-id": device.Id})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001625 return nil
1626 */
Himani Chawla4d908332020-08-31 12:30:20 +05301627 err = errors.New("device FSM: function not implemented yet")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001628 e.Cancel(err)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001629 logger.Debug(ctx, "doStateDown-done")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001630}
1631
Himani Chawla6d2ae152020-09-02 13:11:20 +05301632// deviceHandler StateMachine related state transition methods ##### end #########
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001633// #################################################################################
1634
1635// ###################################################
Himani Chawla6d2ae152020-09-02 13:11:20 +05301636// deviceHandler utility methods ##### begin #########
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001637
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001638//GetOnuDeviceEntry gets the ONU device entry and may wait until its value is defined
1639func (dh *deviceHandler) GetOnuDeviceEntry(ctx context.Context, aWait bool) *mib.OnuDeviceEntry {
mpagenko3af1f032020-06-10 08:53:41 +00001640 dh.lockDevice.RLock()
1641 pOnuDeviceEntry := dh.pOnuOmciDevice
1642 if aWait && pOnuDeviceEntry == nil {
1643 //keep the read sema short to allow for subsequent write
1644 dh.lockDevice.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001645 logger.Debugw(ctx, "Waiting for DeviceEntry to be set ...", log.Fields{"device-id": dh.DeviceID})
mpagenko3af1f032020-06-10 08:53:41 +00001646 // based on concurrent processing the deviceEntry setup may not yet be finished at his point
1647 // so it might be needed to wait here for that event with some timeout
1648 select {
1649 case <-time.After(60 * time.Second): //timer may be discussed ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001650 logger.Errorw(ctx, "No valid DeviceEntry set after maxTime", log.Fields{"device-id": dh.DeviceID})
mpagenko3af1f032020-06-10 08:53:41 +00001651 return nil
1652 case <-dh.deviceEntrySet:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001653 logger.Debugw(ctx, "devicEntry ready now - continue", log.Fields{"device-id": dh.DeviceID})
mpagenko3af1f032020-06-10 08:53:41 +00001654 // if written now, we can return the written value without sema
1655 return dh.pOnuOmciDevice
1656 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001657 }
mpagenko3af1f032020-06-10 08:53:41 +00001658 dh.lockDevice.RUnlock()
1659 return pOnuDeviceEntry
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001660}
1661
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001662//setDeviceHandlerEntries sets the ONU device entry within the handler
1663func (dh *deviceHandler) setDeviceHandlerEntries(apDeviceEntry *mib.OnuDeviceEntry, apOnuTp *avcfg.OnuUniTechProf,
1664 apOnuMetricsMgr *pmmgr.OnuMetricsManager, apOnuAlarmMgr *almgr.OnuAlarmManager, apSelfTestHdlr *otst.SelfTestControlBlock) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001665 dh.lockDevice.Lock()
1666 defer dh.lockDevice.Unlock()
mpagenkoaf801632020-07-03 10:00:42 +00001667 dh.pOnuOmciDevice = apDeviceEntry
1668 dh.pOnuTP = apOnuTp
Girish Gowdrae09a6202021-01-12 18:10:59 -08001669 dh.pOnuMetricsMgr = apOnuMetricsMgr
Himani Chawlaac1f5ad2021-02-04 21:21:54 +05301670 dh.pAlarmMgr = apOnuAlarmMgr
Girish Gowdra6afb56a2021-04-27 17:47:57 -07001671 dh.pSelfTestHdlr = apSelfTestHdlr
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001672}
1673
Himani Chawla6d2ae152020-09-02 13:11:20 +05301674//addOnuDeviceEntry creates a new ONU device or returns the existing
1675func (dh *deviceHandler) addOnuDeviceEntry(ctx context.Context) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001676 logger.Debugw(ctx, "adding-deviceEntry", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001677
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001678 deviceEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001679 if deviceEntry == nil {
1680 /* costum_me_map in python code seems always to be None,
1681 we omit that here first (declaration unclear) -> todo at Adapter specialization ...*/
1682 /* also no 'clock' argument - usage open ...*/
1683 /* and no alarm_db yet (oo.alarm_db) */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001684 deviceEntry = mib.NewOnuDeviceEntry(ctx, dh.coreClient, dh, dh.pOpenOnuAc)
1685 onuTechProfProc := avcfg.NewOnuUniTechProf(ctx, dh, deviceEntry)
1686 onuMetricsMgr := pmmgr.NewOnuMetricsManager(ctx, dh, deviceEntry)
1687 onuAlarmManager := almgr.NewAlarmManager(ctx, dh, deviceEntry)
1688 selfTestHdlr := otst.NewSelfTestMsgHandlerCb(ctx, dh, deviceEntry)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001689 //error treatment possible //TODO!!!
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001690 dh.setDeviceHandlerEntries(deviceEntry, onuTechProfProc, onuMetricsMgr, onuAlarmManager, selfTestHdlr)
mpagenko3af1f032020-06-10 08:53:41 +00001691 // fire deviceEntry ready event to spread to possibly waiting processing
1692 dh.deviceEntrySet <- true
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001693 logger.Debugw(ctx, "onuDeviceEntry-added", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001694 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001695 logger.Debugw(ctx, "onuDeviceEntry-add: Device already exists", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001696 }
1697 // might be updated with some error handling !!!
1698 return nil
1699}
1700
dbainbri4d3a0dc2020-12-02 00:33:42 +00001701func (dh *deviceHandler) createInterface(ctx context.Context, onuind *oop.OnuIndication) error {
1702 logger.Debugw(ctx, "create_interface-started", log.Fields{"OnuId": onuind.GetOnuId(),
Holger Hildebrandt24d51952020-05-04 14:03:42 +00001703 "OnuIntfId": onuind.GetIntfId(), "OnuSerialNumber": onuind.GetSerialNumber()})
1704
1705 dh.pOnuIndication = onuind // let's revise if storing the pointer is sufficient...
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001706
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001707 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001708 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001709 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
1710 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001711 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001712 if !dh.IsReconciling() {
1713 if err := dh.StorePersistentData(ctx); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001714 logger.Warnw(ctx, "store persistent data error - continue as there will be additional write attempts",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001715 log.Fields{"device-id": dh.DeviceID, "err": err})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001716 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001717 logger.Debugw(ctx, "call DeviceStateUpdate upon create interface", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001718 "OperStatus": voltha.OperStatus_ACTIVATING, "device-id": dh.DeviceID})
khenaidoo7d3c5582021-08-11 18:09:44 -04001719
1720 if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001721 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04001722 OperStatus: voltha.OperStatus_ACTIVATING,
1723 ConnStatus: voltha.ConnectStatus_REACHABLE,
1724 }); err != nil {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001725 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001726 logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001727 }
1728 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001729 logger.Debugw(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVATING",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001730 log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001731
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001732 pDevEntry.MutexPersOnuConfig.RLock()
1733 if !pDevEntry.SOnuPersistentData.PersUniUnlockDone {
1734 pDevEntry.MutexPersOnuConfig.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +00001735 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 +00001736 log.Fields{"device-id": dh.DeviceID})
1737 dh.StopReconciling(ctx, true)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00001738 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001739 pDevEntry.MutexPersOnuConfig.RUnlock()
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001740 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001741 }
Holger Hildebrandt24d51952020-05-04 14:03:42 +00001742 // It does not look to me as if makes sense to work with the real core device here, (not the stored clone)?
1743 // in this code the GetDevice would just make a check if the DeviceID's Device still exists in core
1744 // in python code it looks as the started onu_omci_device might have been updated with some new instance state of the core device
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001745 // 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 +00001746 // so let's just try to keep it simple ...
1747 /*
dbainbri4d3a0dc2020-12-02 00:33:42 +00001748 device, err := dh.coreProxy.GetDevice(log.WithSpanFromContext(context.TODO(), ctx), dh.device.Id, dh.device.Id)
Holger Hildebrandt24d51952020-05-04 14:03:42 +00001749 if err != nil || device == nil {
1750 //TODO: needs to handle error scenarios
1751 logger.Errorw("Failed to fetch device device at creating If", log.Fields{"err": err})
1752 return errors.New("Voltha Device not found")
1753 }
1754 */
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001755
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001756 if err := pDevEntry.Start(log.WithSpanFromContext(context.TODO(), ctx)); err != nil {
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001757 return err
mpagenko3af1f032020-06-10 08:53:41 +00001758 }
Holger Hildebrandt3a644642020-12-02 09:46:18 +00001759
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001760 _ = dh.deviceReasonUpdate(ctx, cmn.DrStartingOpenomci, !dh.IsReconciling())
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001761
1762 /* this might be a good time for Omci Verify message? */
1763 verifyExec := make(chan bool)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001764 omciVerify := otst.NewOmciTestRequest(log.WithSpanFromContext(context.TODO(), ctx),
mpagenko3af1f032020-06-10 08:53:41 +00001765 dh.device.Id, pDevEntry.PDevOmciCC,
mpagenko900ee4b2020-10-12 11:56:34 +00001766 true, true) //exclusive and allowFailure (anyway not yet checked)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001767 omciVerify.PerformOmciTest(log.WithSpanFromContext(context.TODO(), ctx), verifyExec)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001768
1769 /* give the handler some time here to wait for the OMCi verification result
1770 after Timeout start and try MibUpload FSM anyway
1771 (to prevent stopping on just not supported OMCI verification from ONU) */
1772 select {
Holger Hildebrandt366ef192021-05-05 11:07:44 +00001773 case <-time.After(pDevEntry.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second):
dbainbri4d3a0dc2020-12-02 00:33:42 +00001774 logger.Warn(ctx, "omci start-verification timed out (continue normal)")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001775 case testresult := <-verifyExec:
dbainbri4d3a0dc2020-12-02 00:33:42 +00001776 logger.Infow(ctx, "Omci start verification done", log.Fields{"result": testresult})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001777 }
1778
1779 /* In py code it looks earlier (on activate ..)
1780 # Code to Run OMCI Test Action
1781 kwargs_omci_test_action = {
1782 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
1783 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
1784 }
1785 serial_number = device.serial_number
1786 self._test_request = OmciTestRequest(self.core_proxy,
1787 self.omci_agent, self.device_id,
1788 AniG, serial_number,
1789 self.logical_device_id,
1790 exclusive=False,
1791 **kwargs_omci_test_action)
1792 ...
1793 # Start test requests after a brief pause
1794 if not self._test_request_started:
1795 self._test_request_started = True
1796 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1797 reactor.callLater(tststart, self._test_request.start_collector)
1798
1799 */
1800 /* which is then: in omci_test_request.py : */
1801 /*
1802 def start_collector(self, callback=None):
1803 """
1804 Start the collection loop for an adapter if the frequency > 0
1805
1806 :param callback: (callable) Function to call to collect PM data
1807 """
1808 self.logger.info("starting-pm-collection", device_name=self.name, default_freq=self.default_freq)
1809 if callback is None:
1810 callback = self.perform_test_omci
1811
1812 if self.lc is None:
1813 self.lc = LoopingCall(callback)
1814
1815 if self.default_freq > 0:
1816 self.lc.start(interval=self.default_freq / 10)
1817
1818 def perform_test_omci(self):
1819 """
1820 Perform the initial test request
1821 """
1822 ani_g_entities = self._device.configuration.ani_g_entities
1823 ani_g_entities_ids = list(ani_g_entities.keys()) if ani_g_entities \
1824 is not None else None
1825 self._entity_id = ani_g_entities_ids[0]
1826 self.logger.info('perform-test', entity_class=self._entity_class,
1827 entity_id=self._entity_id)
1828 try:
1829 frame = MEFrame(self._entity_class, self._entity_id, []).test()
1830 result = yield self._device.omci_cc.send(frame)
1831 if not result.fields['omci_message'].fields['success_code']:
1832 self.logger.info('Self-Test Submitted Successfully',
1833 code=result.fields[
1834 'omci_message'].fields['success_code'])
1835 else:
1836 raise TestFailure('Test Failure: {}'.format(
1837 result.fields['omci_message'].fields['success_code']))
1838 except TimeoutError as e:
1839 self.deferred.errback(failure.Failure(e))
1840
1841 except Exception as e:
1842 self.logger.exception('perform-test-Error', e=e,
1843 class_id=self._entity_class,
1844 entity_id=self._entity_id)
1845 self.deferred.errback(failure.Failure(e))
1846
1847 */
1848
1849 // PM related heartbeat??? !!!TODO....
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001850 //self._heartbeat.Enabled = True
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001851
mpagenko1cc3cb42020-07-27 15:24:38 +00001852 /* Note: Even though FSM calls look 'synchronous' here, FSM is running in background with the effect that possible errors
1853 * within the MibUpload are not notified in the OnuIndication response, this might be acceptable here,
1854 * as further OltAdapter processing may rely on the deviceReason event 'MibUploadDone' as a result of the FSM processing
Himani Chawla4d908332020-08-31 12:30:20 +05301855 * otherwise some processing synchronization would be required - cmp. e.g TechProfile processing
mpagenko1cc3cb42020-07-27 15:24:38 +00001856 */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001857 //call MibUploadFSM - transition up to state UlStInSync
1858 pMibUlFsm := pDevEntry.PMibUploadFsm.PFsm
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +00001859 if pMibUlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001860 if pMibUlFsm.Is(mib.UlStDisabled) {
1861 if err := pMibUlFsm.Event(mib.UlEvStart); err != nil {
1862 logger.Errorw(ctx, "MibSyncFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err})
1863 return fmt.Errorf("can't go to state starting: %s", dh.DeviceID)
Himani Chawla4d908332020-08-31 12:30:20 +05301864 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001865 logger.Debugw(ctx, "MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())})
Himani Chawla4d908332020-08-31 12:30:20 +05301866 //Determine ONU status and start/re-start MIB Synchronization tasks
1867 //Determine if this ONU has ever synchronized
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001868 if pDevEntry.IsNewOnu() {
1869 if err := pMibUlFsm.Event(mib.UlEvResetMib); err != nil {
1870 logger.Errorw(ctx, "MibSyncFsm: Can't go to state resetting_mib", log.Fields{"device-id": dh.DeviceID, "err": err})
1871 return fmt.Errorf("can't go to state resetting_mib: %s", dh.DeviceID)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001872 }
Himani Chawla4d908332020-08-31 12:30:20 +05301873 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001874 if err := pMibUlFsm.Event(mib.UlEvExamineMds); err != nil {
1875 logger.Errorw(ctx, "MibSyncFsm: Can't go to state examine_mds", log.Fields{"device-id": dh.DeviceID, "err": err})
1876 return fmt.Errorf("can't go to examine_mds: %s", dh.DeviceID)
Himani Chawla4d908332020-08-31 12:30:20 +05301877 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001878 logger.Debugw(ctx, "state of MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001879 }
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +00001880 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001881 logger.Errorw(ctx, "wrong state of MibSyncFsm - want: disabled", log.Fields{"have": string(pMibUlFsm.Current()),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001882 "device-id": dh.DeviceID})
1883 return fmt.Errorf("wrong state of MibSyncFsm: %s", dh.DeviceID)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001884 }
1885 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001886 logger.Errorw(ctx, "MibSyncFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID})
1887 return fmt.Errorf("can't execute MibSync: %s", dh.DeviceID)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001888 }
1889 return nil
1890}
1891
dbainbri4d3a0dc2020-12-02 00:33:42 +00001892func (dh *deviceHandler) updateInterface(ctx context.Context, onuind *oop.OnuIndication) error {
mpagenko3af1f032020-06-10 08:53:41 +00001893 //state checking to prevent unneeded processing (eg. on ONU 'unreachable' and 'down')
mpagenkofc4f56e2020-11-04 17:17:49 +00001894 // (but note that the deviceReason may also have changed to e.g. TechProf*Delete_Success in between)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001895 if dh.getDeviceReason() != cmn.DrStoppingOpenomci {
1896 logger.Debugw(ctx, "updateInterface-started - stopping-device", log.Fields{"device-id": dh.DeviceID})
mpagenko2418ab02020-11-12 12:58:06 +00001897
mpagenko900ee4b2020-10-12 11:56:34 +00001898 //stop all running FSM processing - make use of the DH-state as mirrored in the deviceReason
1899 //here no conflict with aborted FSM's should arise as a complete OMCI initialization is assumed on ONU-Up
1900 //but that might change with some simple MDS check on ONU-Up treatment -> attention!!!
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001901 if err := dh.resetFsms(ctx, true); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001902 logger.Errorw(ctx, "error-updateInterface at FSM stop",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001903 log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko900ee4b2020-10-12 11:56:34 +00001904 // abort: system behavior is just unstable ...
1905 return err
1906 }
mpagenkoa40e99a2020-11-17 13:50:39 +00001907 //all stored persistent data are not valid anymore (loosing knowledge about the connected ONU)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001908 _ = 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 +00001909
1910 //deviceEntry stop without omciCC reset here, regarding the OMCI_CC still valid for this ONU
1911 // - in contrary to disableDevice - compare with processUniDisableStateDoneEvent
1912 //stop the device entry which resets the attached omciCC
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001913 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
mpagenko3af1f032020-06-10 08:53:41 +00001914 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001915 logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
1916 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
mpagenko3af1f032020-06-10 08:53:41 +00001917 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001918 _ = pDevEntry.Stop(log.WithSpanFromContext(context.TODO(), ctx), false)
mpagenko3af1f032020-06-10 08:53:41 +00001919
1920 //TODO!!! remove existing traffic profiles
1921 /* from py code, if TP's exist, remove them - not yet implemented
1922 self._tp = dict()
1923 # Let TP download happen again
1924 for uni_id in self._tp_service_specific_task:
1925 self._tp_service_specific_task[uni_id].clear()
1926 for uni_id in self._tech_profile_download_done:
1927 self._tech_profile_download_done[uni_id].clear()
1928 */
1929
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001930 dh.DisableUniPortStateUpdate(ctx)
mpagenko3af1f032020-06-10 08:53:41 +00001931
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001932 dh.SetReadyForOmciConfig(false)
mpagenkofc4f56e2020-11-04 17:17:49 +00001933
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001934 if err := dh.deviceReasonUpdate(ctx, cmn.DrStoppingOpenomci, true); err != nil {
mpagenko3af1f032020-06-10 08:53:41 +00001935 // abort: system behavior is just unstable ...
1936 return err
1937 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001938 logger.Debugw(ctx, "call DeviceStateUpdate upon update interface", log.Fields{"ConnectStatus": voltha.ConnectStatus_UNREACHABLE,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001939 "OperStatus": voltha.OperStatus_DISCOVERED, "device-id": dh.DeviceID})
khenaidoo7d3c5582021-08-11 18:09:44 -04001940 if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001941 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04001942 ConnStatus: voltha.ConnectStatus_UNREACHABLE,
1943 OperStatus: voltha.OperStatus_DISCOVERED,
1944 }); err != nil {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00001945 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
dbainbri4d3a0dc2020-12-02 00:33:42 +00001946 logger.Errorw(ctx, "error-updating-device-state unreachable-discovered",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001947 log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko3af1f032020-06-10 08:53:41 +00001948 // abort: system behavior is just unstable ...
1949 return err
1950 }
1951 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001952 logger.Debugw(ctx, "updateInterface - device already stopped", log.Fields{"device-id": dh.DeviceID})
mpagenko3af1f032020-06-10 08:53:41 +00001953 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00001954 return nil
1955}
1956
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001957func (dh *deviceHandler) resetFsms(ctx context.Context, includingMibSyncFsm bool) error {
mpagenko900ee4b2020-10-12 11:56:34 +00001958 //all possible FSM's are stopped or reset here to ensure their transition to 'disabled'
1959 //it is not sufficient to stop/reset the latest running FSM as done in previous versions
1960 // as after down/up procedures all FSM's might be active/ongoing (in theory)
1961 // and using the stop/reset event should never harm
1962
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001963 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
mpagenko900ee4b2020-10-12 11:56:34 +00001964 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001965 logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
1966 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
mpagenko900ee4b2020-10-12 11:56:34 +00001967 }
Holger Hildebrandtc8ece362021-05-17 12:01:10 +00001968 if pDevEntry.PDevOmciCC != nil {
mpagenko8cd1bf72021-06-22 10:11:19 +00001969 pDevEntry.PDevOmciCC.CancelRequestMonitoring(ctx)
Holger Hildebrandtc8ece362021-05-17 12:01:10 +00001970 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001971 pDevEntry.MutexOnuImageStatus.RLock()
1972 if pDevEntry.POnuImageStatus != nil {
1973 pDevEntry.POnuImageStatus.CancelProcessing(ctx)
Holger Hildebrandtfb402a62021-05-26 14:40:49 +00001974 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001975 pDevEntry.MutexOnuImageStatus.RUnlock()
mpagenkoaa3afe92021-05-21 16:20:58 +00001976
Holger Hildebrandt10d98192021-01-27 15:29:31 +00001977 if includingMibSyncFsm {
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00001978 pDevEntry.CancelProcessing(ctx)
mpagenko900ee4b2020-10-12 11:56:34 +00001979 }
1980 //MibDownload may run
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001981 pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm
mpagenko900ee4b2020-10-12 11:56:34 +00001982 if pMibDlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001983 _ = pMibDlFsm.Event(mib.DlEvReset)
mpagenko900ee4b2020-10-12 11:56:34 +00001984 }
1985 //port lock/unlock FSM's may be active
1986 if dh.pUnlockStateFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001987 _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset)
mpagenko900ee4b2020-10-12 11:56:34 +00001988 }
1989 if dh.pLockStateFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001990 _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset)
mpagenko900ee4b2020-10-12 11:56:34 +00001991 }
1992 //techProfile related PonAniConfigFsm FSM may be active
1993 if dh.pOnuTP != nil {
1994 // should always be the case here
1995 // FSM stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001996 if dh.pOnuTP.PAniConfigFsm != nil {
1997 for uniTP := range dh.pOnuTP.PAniConfigFsm {
1998 dh.pOnuTP.PAniConfigFsm[uniTP].CancelProcessing(ctx)
Girish Gowdra041dcb32020-11-16 16:54:30 -08001999 }
mpagenko900ee4b2020-10-12 11:56:34 +00002000 }
2001 for _, uniPort := range dh.uniEntityMap {
mpagenko900ee4b2020-10-12 11:56:34 +00002002 // reset the possibly existing VlanConfigFsm
mpagenkof1fc3862021-02-16 10:09:52 +00002003 dh.lockVlanConfig.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002004 if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniPort.UniID]; exist {
mpagenko900ee4b2020-10-12 11:56:34 +00002005 //VlanFilterFsm exists and was already started
mpagenko7d6bb022021-03-11 15:07:55 +00002006 dh.lockVlanConfig.RUnlock()
2007 //reset of all Fsm is always accompanied by global persistency data removal
2008 // no need to remove specific data
2009 pVlanFilterFsm.RequestClearPersistency(false)
2010 //ensure the FSM processing is stopped in case waiting for some response
mpagenko73143992021-04-09 15:17:10 +00002011 pVlanFilterFsm.CancelProcessing(ctx)
mpagenkof1fc3862021-02-16 10:09:52 +00002012 } else {
2013 dh.lockVlanConfig.RUnlock()
mpagenko900ee4b2020-10-12 11:56:34 +00002014 }
2015 }
2016 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002017 if dh.GetCollectorIsRunning() {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00002018 // Stop collector routine
2019 dh.stopCollector <- true
2020 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002021 if dh.GetAlarmManagerIsRunning(ctx) {
Himani Chawla4c1d4c72021-02-18 12:14:31 +05302022 dh.stopAlarmManager <- true
2023 }
Girish Gowdra10123c02021-08-30 11:52:06 -07002024 if dh.pSelfTestHdlr.GetSelfTestHandlerIsRunning() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002025 dh.pSelfTestHdlr.StopSelfTestModule <- true
Girish Gowdra10123c02021-08-30 11:52:06 -07002026 }
Himani Chawla4c1d4c72021-02-18 12:14:31 +05302027
mpagenko80622a52021-02-09 16:53:23 +00002028 //reset a possibly running upgrade FSM
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002029 // (note the Upgrade FSM may stay alive e.g. in state UpgradeStWaitForCommit to endure the ONU reboot)
mpagenko80622a52021-02-09 16:53:23 +00002030 dh.lockUpgradeFsm.RLock()
mpagenko38662d02021-08-11 09:45:19 +00002031 lopOnuUpradeFsm := dh.pOnuUpradeFsm
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002032 //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm()
mpagenko80622a52021-02-09 16:53:23 +00002033 dh.lockUpgradeFsm.RUnlock()
mpagenko38662d02021-08-11 09:45:19 +00002034 if lopOnuUpradeFsm != nil {
mpagenko59862f02021-10-11 08:53:18 +00002035 if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation
2036 //here we do not expect intermediate cancelation, we still allow for other commands on this FSM
2037 // (even though it may also run into direct cancellation, a bit hard to verify here)
2038 // so don't set 'dh.upgradeCanceled = true' here!
2039 lopOnuUpradeFsm.CancelProcessing(ctx, false, voltha.ImageState_CANCELLED_ON_ONU_STATE) //conditional cancel
2040 }
mpagenko38662d02021-08-11 09:45:19 +00002041 }
mpagenko80622a52021-02-09 16:53:23 +00002042
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002043 logger.Infow(ctx, "resetFsms done", log.Fields{"device-id": dh.DeviceID})
mpagenko900ee4b2020-10-12 11:56:34 +00002044 return nil
2045}
2046
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002047func (dh *deviceHandler) processMibDatabaseSyncEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
2048 logger.Debugw(ctx, "MibInSync event received, adding uni ports and locking the ONU interfaces", log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302049
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002050 // store persistent data collected during MIB upload processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002051 if err := dh.StorePersistentData(ctx); err != nil {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002052 logger.Warnw(ctx, "store persistent data error - continue as there will be additional write attempts",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002053 log.Fields{"device-id": dh.DeviceID, "err": err})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002054 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002055 _ = dh.deviceReasonUpdate(ctx, cmn.DrDiscoveryMibsyncComplete, !dh.IsReconciling())
2056 dh.AddAllUniPorts(ctx)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002057
mpagenkoa40e99a2020-11-17 13:50:39 +00002058 /* 200605: lock processing after initial MIBUpload removed now as the ONU should be in the lock state per default here */
2059 /* 201117: build_dt-berlin-pod-openonugo_1T8GEM_voltha_DT_openonugo_master_test runs into error TC
2060 * 'Test Disable ONUs and OLT Then Delete ONUs and OLT for DT' with Sercom ONU, which obviously needs
2061 * disable/enable toggling here to allow traffic
2062 * but moreover it might be useful for tracking the interface operState changes if this will be implemented,
2063 * like the py comment says:
2064 * # start by locking all the unis till mib sync and initial mib is downloaded
2065 * # this way we can capture the port down/up events when we are ready
2066 */
Himani Chawla26e555c2020-08-31 12:30:20 +05302067
mpagenkoa40e99a2020-11-17 13:50:39 +00002068 // Init Uni Ports to Admin locked state
2069 // *** should generate UniLockStateDone event *****
2070 if dh.pLockStateFsm == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002071 dh.createUniLockFsm(ctx, true, cmn.UniLockStateDone)
mpagenkoa40e99a2020-11-17 13:50:39 +00002072 } else { //LockStateFSM already init
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002073 dh.pLockStateFsm.SetSuccessEvent(cmn.UniLockStateDone)
dbainbri4d3a0dc2020-12-02 00:33:42 +00002074 dh.runUniLockFsm(ctx, true)
mpagenkoa40e99a2020-11-17 13:50:39 +00002075 }
2076}
2077
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002078func (dh *deviceHandler) processUniLockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
2079 logger.Infow(ctx, "UniLockStateDone event: Starting MIB download", log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302080 /* Mib download procedure -
2081 ***** should run over 'downloaded' state and generate MibDownloadDone event *****
2082 */
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002083 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002084 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002085 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002086 return
2087 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002088 pMibDlFsm := pDevEntry.PMibDownloadFsm.PFsm
Himani Chawla26e555c2020-08-31 12:30:20 +05302089 if pMibDlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002090 if pMibDlFsm.Is(mib.DlStDisabled) {
2091 if err := pMibDlFsm.Event(mib.DlEvStart); err != nil {
2092 logger.Errorw(ctx, "MibDownloadFsm: Can't go to state starting", log.Fields{"device-id": dh.DeviceID, "err": err})
Himani Chawla26e555c2020-08-31 12:30:20 +05302093 // maybe try a FSM reset and then again ... - TODO!!!
2094 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002095 logger.Debugw(ctx, "MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())})
Himani Chawla26e555c2020-08-31 12:30:20 +05302096 // maybe use more specific states here for the specific download steps ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002097 if err := pMibDlFsm.Event(mib.DlEvCreateGal); err != nil {
2098 logger.Errorw(ctx, "MibDownloadFsm: Can't start CreateGal", log.Fields{"device-id": dh.DeviceID, "err": err})
Himani Chawla26e555c2020-08-31 12:30:20 +05302099 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002100 logger.Debugw(ctx, "state of MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())})
Himani Chawla26e555c2020-08-31 12:30:20 +05302101 //Begin MIB data download (running autonomously)
2102 }
2103 }
2104 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002105 logger.Errorw(ctx, "wrong state of MibDownloadFsm - want: disabled", log.Fields{"have": string(pMibDlFsm.Current()),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002106 "device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302107 // maybe try a FSM reset and then again ... - TODO!!!
2108 }
2109 /***** Mib download started */
2110 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002111 logger.Errorw(ctx, "MibDownloadFsm invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302112 }
2113}
2114
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002115func (dh *deviceHandler) processMibDownloadDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
2116 logger.Debugw(ctx, "MibDownloadDone event received, unlocking the ONU interfaces", log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302117 //initiate DevStateUpdate
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002118 if !dh.IsReconciling() {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002119 logger.Debugw(ctx, "call DeviceStateUpdate upon mib-download done", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002120 "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID})
mpagenko15ff4a52021-03-02 10:09:20 +00002121 //we allow a possible OnuSw image commit only in the normal startup, not at reconciling
2122 // in case of adapter restart connected to an ONU upgrade I would not rely on the image quality
2123 // maybe some 'forced' commitment can be done in this situation from system management (or upgrade restarted)
2124 dh.checkOnOnuImageCommit(ctx)
khenaidoo7d3c5582021-08-11 18:09:44 -04002125 if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002126 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04002127 ConnStatus: voltha.ConnectStatus_REACHABLE,
2128 OperStatus: voltha.OperStatus_ACTIVE,
2129 }); err != nil {
Himani Chawla26e555c2020-08-31 12:30:20 +05302130 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002131 logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
Himani Chawla26e555c2020-08-31 12:30:20 +05302132 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002133 logger.Debugw(ctx, "dev state updated to 'Oper.Active'", log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302134 }
2135 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002136 logger.Debugw(ctx, "reconciling - don't notify core about DeviceStateUpdate to ACTIVE",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002137 log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302138 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002139 _ = dh.deviceReasonUpdate(ctx, cmn.DrInitialMibDownloaded, !dh.IsReconciling())
Girish Gowdrae0140f02021-02-02 16:55:09 -08002140
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002141 if !dh.GetCollectorIsRunning() {
Girish Gowdra7b0ee5c2021-03-19 21:48:15 -07002142 // Start PM collector routine
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002143 go dh.StartCollector(ctx)
Girish Gowdra7b0ee5c2021-03-19 21:48:15 -07002144 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002145 if !dh.GetAlarmManagerIsRunning(ctx) {
2146 go dh.StartAlarmManager(ctx)
Girish Gowdra7b0ee5c2021-03-19 21:48:15 -07002147 }
2148
Girish Gowdrae0140f02021-02-02 16:55:09 -08002149 // Initialize classical L2 PM Interval Counters
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002150 if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventInit); err != nil {
Girish Gowdrae0140f02021-02-02 16:55:09 -08002151 // There is no way we should be landing here, but if we do then
2152 // there is nothing much we can do about this other than log error
2153 logger.Errorw(ctx, "error starting l2 pm fsm", log.Fields{"device-id": dh.device.Id, "err": err})
2154 }
2155
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002156 dh.SetReadyForOmciConfig(true)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002157
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002158 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002159 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002160 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002161 return
2162 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002163 pDevEntry.MutexPersOnuConfig.RLock()
2164 if dh.IsReconciling() && pDevEntry.SOnuPersistentData.PersUniDisableDone {
2165 pDevEntry.MutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002166 logger.Debugw(ctx, "reconciling - uni-ports were disabled by admin before adapter restart - keep the ports locked",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002167 log.Fields{"device-id": dh.DeviceID})
2168 go dh.ReconcileDeviceTechProf(ctx)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002169 // reconcilement will be continued after ani config is done
2170 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002171 pDevEntry.MutexPersOnuConfig.RUnlock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002172 // *** should generate UniUnlockStateDone event *****
2173 if dh.pUnlockStateFsm == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002174 dh.createUniLockFsm(ctx, false, cmn.UniUnlockStateDone)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002175 } else { //UnlockStateFSM already init
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002176 dh.pUnlockStateFsm.SetSuccessEvent(cmn.UniUnlockStateDone)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002177 dh.runUniLockFsm(ctx, false)
2178 }
Himani Chawla26e555c2020-08-31 12:30:20 +05302179 }
2180}
2181
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002182func (dh *deviceHandler) processUniUnlockStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
2183 dh.EnableUniPortStateUpdate(ctx) //cmp python yield self.enable_ports()
Himani Chawla26e555c2020-08-31 12:30:20 +05302184
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002185 if !dh.IsReconciling() {
2186 logger.Infow(ctx, "UniUnlockStateDone event: Sending OnuUp event", log.Fields{"device-id": dh.DeviceID})
ozgecanetsia2f05ed32021-05-31 17:13:48 +03002187 raisedTs := time.Now().Unix()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002188 go dh.sendOnuOperStateEvent(ctx, voltha.OperStatus_ACTIVE, dh.DeviceID, raisedTs) //cmp python onu_active_event
2189 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002190 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002191 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002192 return
2193 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002194 pDevEntry.MutexPersOnuConfig.Lock()
2195 pDevEntry.SOnuPersistentData.PersUniUnlockDone = true
2196 pDevEntry.MutexPersOnuConfig.Unlock()
2197 if err := dh.StorePersistentData(ctx); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002198 logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002199 log.Fields{"device-id": dh.DeviceID, "err": err})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002200 }
Himani Chawla26e555c2020-08-31 12:30:20 +05302201 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002202 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 +00002203 log.Fields{"device-id": dh.DeviceID})
2204 go dh.ReconcileDeviceTechProf(ctx)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00002205 // reconcilement will be continued after ani config is done
Himani Chawla26e555c2020-08-31 12:30:20 +05302206 }
2207}
2208
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002209func (dh *deviceHandler) processUniDisableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002210 logger.Debugw(ctx, "DeviceStateUpdate upon disable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002211 "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": dh.DeviceID})
khenaidoo7d3c5582021-08-11 18:09:44 -04002212
2213 if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002214 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04002215 ConnStatus: voltha.ConnectStatus_REACHABLE,
2216 OperStatus: voltha.OperStatus_UNKNOWN,
2217 }); err != nil {
mpagenko900ee4b2020-10-12 11:56:34 +00002218 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002219 logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko900ee4b2020-10-12 11:56:34 +00002220 }
2221
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002222 logger.Debugw(ctx, "DeviceReasonUpdate upon disable", log.Fields{"reason": cmn.DeviceReasonMap[cmn.DrOmciAdminLock], "device-id": dh.DeviceID})
mpagenko900ee4b2020-10-12 11:56:34 +00002223 // DeviceReason to update acc.to modified py code as per beginning of Sept 2020
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002224 _ = dh.deviceReasonUpdate(ctx, cmn.DrOmciAdminLock, true)
mpagenko900ee4b2020-10-12 11:56:34 +00002225
2226 //transfer the modified logical uni port state
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002227 dh.DisableUniPortStateUpdate(ctx)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002228
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002229 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002230 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002231 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002232 return
2233 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002234 pDevEntry.MutexPersOnuConfig.Lock()
2235 pDevEntry.SOnuPersistentData.PersUniDisableDone = true
2236 pDevEntry.MutexPersOnuConfig.Unlock()
2237 if err := dh.StorePersistentData(ctx); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002238 logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002239 log.Fields{"device-id": dh.DeviceID, "err": err})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002240 }
mpagenko900ee4b2020-10-12 11:56:34 +00002241}
2242
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002243func (dh *deviceHandler) processUniEnableStateDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002244 logger.Debugw(ctx, "DeviceStateUpdate upon re-enable", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002245 "OperStatus": voltha.OperStatus_ACTIVE, "device-id": dh.DeviceID})
khenaidoo7d3c5582021-08-11 18:09:44 -04002246 if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002247 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04002248 ConnStatus: voltha.ConnectStatus_REACHABLE,
2249 OperStatus: voltha.OperStatus_ACTIVE,
2250 }); err != nil {
mpagenko900ee4b2020-10-12 11:56:34 +00002251 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002252 logger.Errorw(ctx, "error-updating-device-state", log.Fields{"device-id": dh.DeviceID, "error": err})
mpagenko900ee4b2020-10-12 11:56:34 +00002253 }
2254
dbainbri4d3a0dc2020-12-02 00:33:42 +00002255 logger.Debugw(ctx, "DeviceReasonUpdate upon re-enable", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002256 "reason": cmn.DeviceReasonMap[cmn.DrOnuReenabled], "device-id": dh.DeviceID})
mpagenko900ee4b2020-10-12 11:56:34 +00002257 // DeviceReason to update acc.to modified py code as per beginning of Sept 2020
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002258 _ = dh.deviceReasonUpdate(ctx, cmn.DrOnuReenabled, true)
mpagenko900ee4b2020-10-12 11:56:34 +00002259
2260 //transfer the modified logical uni port state
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002261 dh.EnableUniPortStateUpdate(ctx)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002262
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002263 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002264 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002265 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002266 return
2267 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002268 pDevEntry.MutexPersOnuConfig.Lock()
2269 pDevEntry.SOnuPersistentData.PersUniDisableDone = false
2270 pDevEntry.MutexPersOnuConfig.Unlock()
2271 if err := dh.StorePersistentData(ctx); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002272 logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002273 log.Fields{"device-id": dh.DeviceID, "err": err})
Holger Hildebrandt3a644642020-12-02 09:46:18 +00002274 }
mpagenko900ee4b2020-10-12 11:56:34 +00002275}
2276
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002277func (dh *deviceHandler) processOmciAniConfigDoneEvent(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
2278 if devEvent == cmn.OmciAniConfigDone {
2279 logger.Debugw(ctx, "OmciAniConfigDone event received", log.Fields{"device-id": dh.DeviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +00002280 // attention: the device reason update is done based on ONU-UNI-Port related activity
2281 // - which may cause some inconsistency
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002282 if dh.getDeviceReason() != cmn.DrTechProfileConfigDownloadSuccess {
mpagenkofc4f56e2020-11-04 17:17:49 +00002283 // which may be the case from some previous actvity even on this UNI Port (but also other UNI ports)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002284 _ = dh.deviceReasonUpdate(ctx, cmn.DrTechProfileConfigDownloadSuccess, !dh.IsReconciling())
Himani Chawla26e555c2020-08-31 12:30:20 +05302285 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002286 if dh.IsReconciling() {
2287 go dh.ReconcileDeviceFlowConfig(ctx)
mpagenkofc4f56e2020-11-04 17:17:49 +00002288 }
2289 } else { // should be the OmciAniResourceRemoved block
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002290 logger.Debugw(ctx, "OmciAniResourceRemoved event received", log.Fields{"device-id": dh.DeviceID})
mpagenkofc4f56e2020-11-04 17:17:49 +00002291 // attention: the device reason update is done based on ONU-UNI-Port related activity
2292 // - which may cause some inconsistency
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002293 if dh.getDeviceReason() != cmn.DrTechProfileConfigDeleteSuccess {
mpagenkofc4f56e2020-11-04 17:17:49 +00002294 // which may be the case from some previous actvity even on this ONU port (but also other UNI ports)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002295 _ = dh.deviceReasonUpdate(ctx, cmn.DrTechProfileConfigDeleteSuccess, true)
mpagenkofc4f56e2020-11-04 17:17:49 +00002296 }
Holger Hildebrandt47555e72020-09-21 11:07:24 +00002297 }
Himani Chawla26e555c2020-08-31 12:30:20 +05302298}
2299
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002300func (dh *deviceHandler) processOmciVlanFilterDoneEvent(ctx context.Context, aDevEvent cmn.OnuDeviceEvent) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002301 logger.Debugw(ctx, "OmciVlanFilterDone event received",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002302 log.Fields{"device-id": dh.DeviceID, "event": aDevEvent})
Himani Chawla26e555c2020-08-31 12:30:20 +05302303 // attention: the device reason update is done based on ONU-UNI-Port related activity
2304 // - which may cause some inconsistency
Himani Chawla26e555c2020-08-31 12:30:20 +05302305
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002306 if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterAddDoneNoKvStore {
2307 if dh.getDeviceReason() != cmn.DrOmciFlowsPushed {
mpagenkofc4f56e2020-11-04 17:17:49 +00002308 // which may be the case from some previous actvity on another UNI Port of the ONU
2309 // or even some previous flow add activity on the same port
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002310 _ = dh.deviceReasonUpdate(ctx, cmn.DrOmciFlowsPushed, !dh.IsReconciling())
2311 if dh.IsReconciling() {
Holger Hildebrandt1b8f4ad2021-03-25 15:53:51 +00002312 go dh.reconcileEnd(ctx)
mpagenkofc4f56e2020-11-04 17:17:49 +00002313 }
2314 }
2315 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002316 if dh.getDeviceReason() != cmn.DrOmciFlowsDeleted {
mpagenkofc4f56e2020-11-04 17:17:49 +00002317 //not relevant for reconcile
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002318 _ = dh.deviceReasonUpdate(ctx, cmn.DrOmciFlowsDeleted, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00002319 }
Himani Chawla26e555c2020-08-31 12:30:20 +05302320 }
mpagenkof1fc3862021-02-16 10:09:52 +00002321
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002322 if aDevEvent == cmn.OmciVlanFilterAddDone || aDevEvent == cmn.OmciVlanFilterRemDone {
mpagenkof1fc3862021-02-16 10:09:52 +00002323 //events that request KvStore write
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002324 if err := dh.StorePersistentData(ctx); err != nil {
mpagenkof1fc3862021-02-16 10:09:52 +00002325 logger.Warnw(ctx, "store persistent data error - continue for now as there will be additional write attempts",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002326 log.Fields{"device-id": dh.DeviceID, "err": err})
mpagenkof1fc3862021-02-16 10:09:52 +00002327 }
2328 } else {
2329 logger.Debugw(ctx, "OmciVlanFilter*Done* - write to KvStore not requested",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002330 log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt10d98192021-01-27 15:29:31 +00002331 }
Himani Chawla26e555c2020-08-31 12:30:20 +05302332}
2333
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002334//DeviceProcStatusUpdate evaluates possible processing events and initiates according next activities
2335func (dh *deviceHandler) DeviceProcStatusUpdate(ctx context.Context, devEvent cmn.OnuDeviceEvent) {
Himani Chawla4d908332020-08-31 12:30:20 +05302336 switch devEvent {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002337 case cmn.MibDatabaseSync:
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002338 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002339 dh.processMibDatabaseSyncEvent(ctx, devEvent)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002340 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002341 case cmn.UniLockStateDone:
mpagenkoa40e99a2020-11-17 13:50:39 +00002342 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002343 dh.processUniLockStateDoneEvent(ctx, devEvent)
mpagenkoa40e99a2020-11-17 13:50:39 +00002344 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002345 case cmn.MibDownloadDone:
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002346 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002347 dh.processMibDownloadDoneEvent(ctx, devEvent)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002348 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002349 case cmn.UniUnlockStateDone:
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002350 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002351 dh.processUniUnlockStateDoneEvent(ctx, devEvent)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002352 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002353 case cmn.UniEnableStateDone:
mpagenko900ee4b2020-10-12 11:56:34 +00002354 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002355 dh.processUniEnableStateDoneEvent(ctx, devEvent)
mpagenko900ee4b2020-10-12 11:56:34 +00002356 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002357 case cmn.UniDisableStateDone:
mpagenko900ee4b2020-10-12 11:56:34 +00002358 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002359 dh.processUniDisableStateDoneEvent(ctx, devEvent)
mpagenko900ee4b2020-10-12 11:56:34 +00002360 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002361 case cmn.OmciAniConfigDone, cmn.OmciAniResourceRemoved:
mpagenko3dbcdd22020-07-22 07:38:45 +00002362 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002363 dh.processOmciAniConfigDoneEvent(ctx, devEvent)
mpagenko3dbcdd22020-07-22 07:38:45 +00002364 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002365 case cmn.OmciVlanFilterAddDone, cmn.OmciVlanFilterAddDoneNoKvStore, cmn.OmciVlanFilterRemDone, cmn.OmciVlanFilterRemDoneNoKvStore:
mpagenkodff5dda2020-08-28 11:52:01 +00002366 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002367 dh.processOmciVlanFilterDoneEvent(ctx, devEvent)
mpagenkodff5dda2020-08-28 11:52:01 +00002368 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002369 default:
2370 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002371 logger.Debugw(ctx, "unhandled-device-event", log.Fields{"device-id": dh.DeviceID, "event": devEvent})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002372 }
2373 } //switch
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002374}
2375
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002376func (dh *deviceHandler) addUniPort(ctx context.Context, aUniInstNo uint16, aUniID uint8, aPortType cmn.UniPortType) {
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002377 // parameters are IntfId, OnuId, uniId
Mahir Gunyelcb128ae2021-10-06 09:42:05 -07002378 uniNo := platform.MkUniPortNum(ctx, dh.pOnuIndication.GetIntfId(), dh.pOnuIndication.GetOnuId(),
Himani Chawla4d908332020-08-31 12:30:20 +05302379 uint32(aUniID))
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002380 if _, present := dh.uniEntityMap[uniNo]; present {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002381 logger.Warnw(ctx, "OnuUniPort-add: Port already exists", log.Fields{"for InstanceId": aUniInstNo})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002382 } else {
Himani Chawla4d908332020-08-31 12:30:20 +05302383 //with arguments aUniID, a_portNo, aPortType
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002384 pUniPort := cmn.NewOnuUniPort(ctx, aUniID, uniNo, aUniInstNo, aPortType)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002385 if pUniPort == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002386 logger.Warnw(ctx, "OnuUniPort-add: Could not create Port", log.Fields{"for InstanceId": aUniInstNo})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002387 } else {
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002388 //store UniPort with the System-PortNumber key
2389 dh.uniEntityMap[uniNo] = pUniPort
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002390 if !dh.IsReconciling() {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00002391 // create announce the UniPort to the core as VOLTHA Port object
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002392 if err := pUniPort.CreateVolthaPort(ctx, dh); err == nil {
2393 logger.Infow(ctx, "OnuUniPort-added", log.Fields{"for PortNo": uniNo})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00002394 } //error logging already within UniPort method
2395 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002396 logger.Debugw(ctx, "reconciling - OnuUniPort already added", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00002397 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +00002398 }
2399 }
2400}
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002401
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002402func (dh *deviceHandler) AddAllUniPorts(ctx context.Context) {
2403 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002404 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002405 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002406 return
2407 }
2408 i := uint8(0) //UNI Port limit: see MaxUnisPerOnu (by now 16) (OMCI supports max 255 p.b.)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002409 if pptpInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys(
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002410 ctx, me.PhysicalPathTerminationPointEthernetUniClassID); len(pptpInstKeys) > 0 {
2411 for _, mgmtEntityID := range pptpInstKeys {
2412 logger.Debugw(ctx, "Add PPTPEthUni port for MIB-stored instance:", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002413 "device-id": dh.DeviceID, "PPTPEthUni EntityID": mgmtEntityID})
2414 dh.addUniPort(ctx, mgmtEntityID, i, cmn.UniPPTP)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002415 i++
2416 }
2417 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002418 logger.Debugw(ctx, "No PPTP instances found", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002419 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002420 if veipInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys(
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002421 ctx, me.VirtualEthernetInterfacePointClassID); len(veipInstKeys) > 0 {
2422 for _, mgmtEntityID := range veipInstKeys {
2423 logger.Debugw(ctx, "Add VEIP for MIB-stored instance:", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002424 "device-id": dh.DeviceID, "VEIP EntityID": mgmtEntityID})
2425 dh.addUniPort(ctx, mgmtEntityID, i, cmn.UniVEIP)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002426 i++
2427 }
2428 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002429 logger.Debugw(ctx, "No VEIP instances found", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002430 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002431 if potsInstKeys := pDevEntry.GetOnuDB().GetSortedInstKeys(
ozgecanetsia124d9732021-09-16 14:31:57 +03002432 ctx, me.PhysicalPathTerminationPointPotsUniClassID); len(potsInstKeys) > 0 {
2433 for _, mgmtEntityID := range potsInstKeys {
2434 logger.Debugw(ctx, "Add PPTP Pots UNI for MIB-stored instance:", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002435 "device-id": dh.DeviceID, "PPTP Pots UNI EntityID": mgmtEntityID})
2436 dh.addUniPort(ctx, mgmtEntityID, i, cmn.UniPPTPPots)
ozgecanetsia124d9732021-09-16 14:31:57 +03002437 i++
2438 }
2439 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002440 logger.Debugw(ctx, "No PPTP Pots UNI instances found", log.Fields{"device-id": dh.DeviceID})
ozgecanetsia124d9732021-09-16 14:31:57 +03002441 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002442 if i == 0 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002443 logger.Warnw(ctx, "No UniG instances found", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002444 }
2445}
2446
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002447// EnableUniPortStateUpdate enables UniPortState and update core port state accordingly
2448func (dh *deviceHandler) EnableUniPortStateUpdate(ctx context.Context) {
Holger Hildebrandtbe674422020-05-05 13:05:30 +00002449 // py code was updated 2003xx to activate the real ONU UNI ports per OMCI (VEIP or PPTP)
Himani Chawla4d908332020-08-31 12:30:20 +05302450 // but towards core only the first port active state is signaled
Holger Hildebrandtbe674422020-05-05 13:05:30 +00002451 // with following remark:
2452 // # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
2453 // # load on the core
2454
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002455 // 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 +00002456
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002457 for uniNo, uniPort := range dh.uniEntityMap {
mpagenko3af1f032020-06-10 08:53:41 +00002458 // only if this port is validated for operState transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002459 if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) {
2460 logger.Infow(ctx, "OnuUniPort-forced-OperState-ACTIVE", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID})
2461 uniPort.SetOperState(vc.OperStatus_ACTIVE)
2462 if !dh.IsReconciling() {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00002463 //maybe also use getter functions on uniPort - perhaps later ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002464 go func(port *cmn.OnuUniPort) {
khenaidoo7d3c5582021-08-11 18:09:44 -04002465 if err := dh.updatePortStateInCore(ctx, &ic.PortState{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002466 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04002467 PortType: voltha.Port_ETHERNET_UNI,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002468 PortNo: port.PortNo,
2469 OperStatus: port.OperState,
khenaidoo7d3c5582021-08-11 18:09:44 -04002470 }); err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002471 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 -04002472 }
2473 }(uniPort)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00002474 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002475 logger.Debugw(ctx, "reconciling - don't notify core about PortStateUpdate", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtf41a1602020-08-19 09:52:50 +00002476 }
mpagenko3af1f032020-06-10 08:53:41 +00002477 }
2478 }
2479}
2480
2481// Disable UniPortState and update core port state accordingly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002482func (dh *deviceHandler) DisableUniPortStateUpdate(ctx context.Context) {
2483 // compare EnableUniPortStateUpdate() above
mpagenko3af1f032020-06-10 08:53:41 +00002484 // -> use current restriction to operate only on first UNI port as inherited from actual Py code
2485 for uniNo, uniPort := range dh.uniEntityMap {
2486 // only if this port is validated for operState transfer
Matteo Scandolo20d180c2021-06-10 17:20:21 +02002487
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002488 if (1<<uniPort.UniID)&dh.pOpenOnuAc.config.UniPortMask == (1 << uniPort.UniID) {
2489 logger.Infow(ctx, "OnuUniPort-forced-OperState-UNKNOWN", log.Fields{"for PortNo": uniNo, "device-id": dh.DeviceID})
2490 uniPort.SetOperState(vc.OperStatus_UNKNOWN)
2491 if !dh.IsReconciling() {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002492 //maybe also use getter functions on uniPort - perhaps later ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002493 go func(port *cmn.OnuUniPort) {
khenaidoo7d3c5582021-08-11 18:09:44 -04002494 if err := dh.updatePortStateInCore(ctx, &ic.PortState{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002495 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04002496 PortType: voltha.Port_ETHERNET_UNI,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002497 PortNo: port.PortNo,
2498 OperStatus: port.OperState,
khenaidoo7d3c5582021-08-11 18:09:44 -04002499 }); err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002500 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 -04002501 }
2502 }(uniPort)
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002503 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002504 logger.Debugw(ctx, "reconciling - don't notify core about PortStateUpdate", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00002505 }
2506
Holger Hildebrandtbe674422020-05-05 13:05:30 +00002507 }
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002508 }
2509}
2510
2511// ONU_Active/Inactive announcement on system KAFKA bus
2512// tried to re-use procedure of oltUpDownIndication from openolt_eventmgr.go with used values from Py code
dbainbri4d3a0dc2020-12-02 00:33:42 +00002513func (dh *deviceHandler) sendOnuOperStateEvent(ctx context.Context, aOperState vc.OperStatus_Types, aDeviceID string, raisedTs int64) {
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002514 var de voltha.DeviceEvent
2515 eventContext := make(map[string]string)
2516 //Populating event context
2517 // assume giving ParentId in GetDevice twice really gives the ParentDevice (there is no GetParentDevice()...)
khenaidoo7d3c5582021-08-11 18:09:44 -04002518 parentDevice, err := dh.getDeviceFromCore(ctx, dh.parentID)
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002519 if err != nil || parentDevice == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002520 logger.Errorw(ctx, "Failed to fetch parent device for OnuEvent",
Himani Chawla4d908332020-08-31 12:30:20 +05302521 log.Fields{"parentID": dh.parentID, "err": err})
Holger Hildebrandt7ec14c42021-05-28 14:21:58 +00002522 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 +00002523 }
2524 oltSerialNumber := parentDevice.SerialNumber
2525
2526 eventContext["pon-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.IntfId), 10)
2527 eventContext["onu-id"] = strconv.FormatUint(uint64(dh.pOnuIndication.OnuId), 10)
2528 eventContext["serial-number"] = dh.device.SerialNumber
ssiddiqui1221d1a2021-02-15 11:12:51 +05302529 eventContext["olt-serial-number"] = oltSerialNumber
2530 eventContext["device-id"] = aDeviceID
2531 eventContext["registration-id"] = aDeviceID //py: string(device_id)??
ozgecanetsiaf0a76b62021-05-31 17:42:09 +03002532 eventContext["num-of-unis"] = strconv.Itoa(len(dh.uniEntityMap))
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002533 if deviceEntry := dh.GetOnuDeviceEntry(ctx, false); deviceEntry != nil {
2534 deviceEntry.MutexPersOnuConfig.RLock()
2535 eventContext["equipment-id"] = deviceEntry.SOnuPersistentData.PersEquipmentID
2536 deviceEntry.MutexPersOnuConfig.RUnlock()
2537 eventContext["software-version"] = deviceEntry.GetActiveImageVersion(ctx)
2538 deviceEntry.MutexPersOnuConfig.RLock()
2539 eventContext["vendor"] = deviceEntry.SOnuPersistentData.PersVendorID
2540 deviceEntry.MutexPersOnuConfig.RUnlock()
2541 eventContext["inactive-software-version"] = deviceEntry.GetInactiveImageVersion(ctx)
ozgecanetsiaf0a76b62021-05-31 17:42:09 +03002542 logger.Debugw(ctx, "prepare ONU_ACTIVATED event",
2543 log.Fields{"device-id": aDeviceID, "EventContext": eventContext})
2544 } else {
2545 logger.Errorw(ctx, "Failed to fetch device-entry. ONU_ACTIVATED event is not sent",
2546 log.Fields{"device-id": aDeviceID})
2547 return
2548 }
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002549
2550 /* Populating device event body */
2551 de.Context = eventContext
Himani Chawla4d908332020-08-31 12:30:20 +05302552 de.ResourceId = aDeviceID
2553 if aOperState == voltha.OperStatus_ACTIVE {
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002554 de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "RAISE_EVENT")
2555 de.Description = fmt.Sprintf("%s Event - %s - %s",
2556 cEventObjectType, cOnuActivatedEvent, "Raised")
2557 } else {
2558 de.DeviceEventName = fmt.Sprintf("%s_%s", cOnuActivatedEvent, "CLEAR_EVENT")
2559 de.Description = fmt.Sprintf("%s Event - %s - %s",
2560 cEventObjectType, cOnuActivatedEvent, "Cleared")
2561 }
2562 /* Send event to KAFKA */
dbainbri4d3a0dc2020-12-02 00:33:42 +00002563 if err := dh.EventProxy.SendDeviceEvent(ctx, &de, equipment, pon, raisedTs); err != nil {
2564 logger.Warnw(ctx, "could not send ONU_ACTIVATED event",
Himani Chawla4d908332020-08-31 12:30:20 +05302565 log.Fields{"device-id": aDeviceID, "error": err})
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002566 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00002567 logger.Debugw(ctx, "ctx, ONU_ACTIVATED event sent to KAFKA",
Himani Chawla4d908332020-08-31 12:30:20 +05302568 log.Fields{"device-id": aDeviceID, "with-EventName": de.DeviceEventName})
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002569}
2570
Himani Chawla4d908332020-08-31 12:30:20 +05302571// createUniLockFsm initializes and runs the UniLock FSM to transfer the OMCI related commands for port lock/unlock
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002572func (dh *deviceHandler) createUniLockFsm(ctx context.Context, aAdminState bool, devEvent cmn.OnuDeviceEvent) {
2573 chLSFsm := make(chan cmn.Message, 2048)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002574 var sFsmName string
Himani Chawla4d908332020-08-31 12:30:20 +05302575 if aAdminState {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002576 logger.Debugw(ctx, "createLockStateFSM", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002577 sFsmName = "LockStateFSM"
2578 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002579 logger.Debugw(ctx, "createUnlockStateFSM", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002580 sFsmName = "UnLockStateFSM"
2581 }
mpagenko3af1f032020-06-10 08:53:41 +00002582
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002583 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
mpagenko3af1f032020-06-10 08:53:41 +00002584 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002585 logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
mpagenko3af1f032020-06-10 08:53:41 +00002586 return
2587 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002588 pLSFsm := uniprt.NewLockStateFsm(ctx, aAdminState, devEvent, sFsmName, dh, pDevEntry, chLSFsm)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002589 if pLSFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05302590 if aAdminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002591 dh.pLockStateFsm = pLSFsm
2592 } else {
2593 dh.pUnlockStateFsm = pLSFsm
2594 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00002595 dh.runUniLockFsm(ctx, aAdminState)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002596 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002597 logger.Errorw(ctx, "LockStateFSM could not be created - abort!!", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002598 }
2599}
2600
2601// runUniLockFsm starts the UniLock FSM to transfer the OMCI related commands for port lock/unlock
dbainbri4d3a0dc2020-12-02 00:33:42 +00002602func (dh *deviceHandler) runUniLockFsm(ctx context.Context, aAdminState bool) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002603 /* Uni Port lock/unlock procedure -
2604 ***** should run via 'adminDone' state and generate the argument requested event *****
2605 */
2606 var pLSStatemachine *fsm.FSM
Himani Chawla4d908332020-08-31 12:30:20 +05302607 if aAdminState {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002608 pLSStatemachine = dh.pLockStateFsm.PAdaptFsm.PFsm
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002609 //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore
2610 if (dh.pUnlockStateFsm != nil) &&
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002611 (dh.pUnlockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) {
2612 _ = dh.pUnlockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002613 }
2614 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002615 pLSStatemachine = dh.pUnlockStateFsm.PAdaptFsm.PFsm
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002616 //make sure the opposite FSM is not running and if so, terminate it as not relevant anymore
2617 if (dh.pLockStateFsm != nil) &&
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002618 (dh.pLockStateFsm.PAdaptFsm.PFsm.Current() != uniprt.UniStDisabled) {
2619 _ = dh.pLockStateFsm.PAdaptFsm.PFsm.Event(uniprt.UniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002620 }
2621 }
2622 if pLSStatemachine != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002623 if pLSStatemachine.Is(uniprt.UniStDisabled) {
2624 if err := pLSStatemachine.Event(uniprt.UniEvStart); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002625 logger.Warnw(ctx, "LockStateFSM: can't start", log.Fields{"err": err})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002626 // maybe try a FSM reset and then again ... - TODO!!!
2627 } else {
2628 /***** LockStateFSM started */
dbainbri4d3a0dc2020-12-02 00:33:42 +00002629 logger.Debugw(ctx, "LockStateFSM started", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002630 "state": pLSStatemachine.Current(), "device-id": dh.DeviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002631 }
2632 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002633 logger.Warnw(ctx, "wrong state of LockStateFSM - want: disabled", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002634 "have": pLSStatemachine.Current(), "device-id": dh.DeviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002635 // maybe try a FSM reset and then again ... - TODO!!!
2636 }
2637 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002638 logger.Errorw(ctx, "LockStateFSM StateMachine invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00002639 // maybe try a FSM reset and then again ... - TODO!!!
2640 }
2641}
2642
mpagenko80622a52021-02-09 16:53:23 +00002643// createOnuUpgradeFsm initializes and runs the Onu Software upgrade FSM
mpagenko59862f02021-10-11 08:53:18 +00002644// precondition: lockUpgradeFsm is already locked from caller of this function
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002645func (dh *deviceHandler) createOnuUpgradeFsm(ctx context.Context, apDevEntry *mib.OnuDeviceEntry, aDevEvent cmn.OnuDeviceEvent) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002646 chUpgradeFsm := make(chan cmn.Message, 2048)
mpagenko80622a52021-02-09 16:53:23 +00002647 var sFsmName = "OnuSwUpgradeFSM"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002648 logger.Debugw(ctx, "create OnuSwUpgradeFSM", log.Fields{"device-id": dh.DeviceID})
mpagenko15ff4a52021-03-02 10:09:20 +00002649 if apDevEntry.PDevOmciCC == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002650 logger.Errorw(ctx, "no valid OnuDevice or omciCC - abort", log.Fields{"device-id": dh.DeviceID})
mpagenko15ff4a52021-03-02 10:09:20 +00002651 return fmt.Errorf(fmt.Sprintf("no valid omciCC - abort for device-id: %s", dh.device.Id))
mpagenko80622a52021-02-09 16:53:23 +00002652 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002653 dh.pOnuUpradeFsm = swupg.NewOnuUpgradeFsm(ctx, dh, apDevEntry, apDevEntry.GetOnuDB(), aDevEvent,
mpagenko80622a52021-02-09 16:53:23 +00002654 sFsmName, chUpgradeFsm)
2655 if dh.pOnuUpradeFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002656 pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm
mpagenko80622a52021-02-09 16:53:23 +00002657 if pUpgradeStatemachine != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002658 if pUpgradeStatemachine.Is(swupg.UpgradeStDisabled) {
2659 if err := pUpgradeStatemachine.Event(swupg.UpgradeEvStart); err != nil {
mpagenko80622a52021-02-09 16:53:23 +00002660 logger.Errorw(ctx, "OnuSwUpgradeFSM: can't start", log.Fields{"err": err})
2661 // maybe try a FSM reset and then again ... - TODO!!!
2662 return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be started for device-id: %s", dh.device.Id))
2663 }
mpagenko59862f02021-10-11 08:53:18 +00002664 /***** Upgrade FSM started */
mpagenko45586762021-10-01 08:30:22 +00002665 //reset the last stored upgrade states (which anyway should be don't care as long as the newly created FSM exists)
2666 (*dh.pLastUpgradeImageState).DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenko38662d02021-08-11 09:45:19 +00002667 (*dh.pLastUpgradeImageState).Reason = voltha.ImageState_NO_ERROR
2668 (*dh.pLastUpgradeImageState).ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenko80622a52021-02-09 16:53:23 +00002669 logger.Debugw(ctx, "OnuSwUpgradeFSM started", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002670 "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID})
mpagenko80622a52021-02-09 16:53:23 +00002671 } else {
2672 logger.Errorw(ctx, "wrong state of OnuSwUpgradeFSM to start - want: disabled", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002673 "have": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID})
mpagenko80622a52021-02-09 16:53:23 +00002674 // maybe try a FSM reset and then again ... - TODO!!!
2675 return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be started for device-id: %s, wrong internal state", dh.device.Id))
2676 }
2677 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002678 logger.Errorw(ctx, "OnuSwUpgradeFSM internal FSM invalid - cannot be executed!!", log.Fields{"device-id": dh.DeviceID})
mpagenko80622a52021-02-09 16:53:23 +00002679 // maybe try a FSM reset and then again ... - TODO!!!
2680 return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM internal FSM could not be created for device-id: %s", dh.device.Id))
2681 }
2682 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002683 logger.Errorw(ctx, "OnuSwUpgradeFSM could not be created - abort", log.Fields{"device-id": dh.DeviceID})
mpagenko80622a52021-02-09 16:53:23 +00002684 return fmt.Errorf(fmt.Sprintf("OnuSwUpgradeFSM could not be created - abort for device-id: %s", dh.device.Id))
2685 }
2686 return nil
2687}
2688
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002689// RemoveOnuUpgradeFsm clears the Onu Software upgrade FSM
2690func (dh *deviceHandler) RemoveOnuUpgradeFsm(ctx context.Context, apImageState *voltha.ImageState) {
mpagenko80622a52021-02-09 16:53:23 +00002691 logger.Debugw(ctx, "remove OnuSwUpgradeFSM StateMachine", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002692 "device-id": dh.DeviceID})
mpagenko80622a52021-02-09 16:53:23 +00002693 dh.lockUpgradeFsm.Lock()
mpagenko59862f02021-10-11 08:53:18 +00002694 dh.pOnuUpradeFsm = nil //resource clearing is left to garbage collector
2695 dh.upgradeCanceled = false //cancelation done
mpagenko38662d02021-08-11 09:45:19 +00002696 dh.pLastUpgradeImageState = apImageState
2697 dh.lockUpgradeFsm.Unlock()
2698 //signal upgradeFsm removed using non-blocking channel send
2699 select {
2700 case dh.upgradeFsmChan <- struct{}{}:
2701 default:
2702 logger.Debugw(ctx, "removed-UpgradeFsm signal not send on upgradeFsmChan (no receiver)", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002703 "device-id": dh.DeviceID})
mpagenko38662d02021-08-11 09:45:19 +00002704 }
mpagenko80622a52021-02-09 16:53:23 +00002705}
2706
mpagenko15ff4a52021-03-02 10:09:20 +00002707// checkOnOnuImageCommit verifies if the ONU is in some upgrade state that allows for image commit and if tries to commit
2708func (dh *deviceHandler) checkOnOnuImageCommit(ctx context.Context) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002709 pDevEntry := dh.GetOnuDeviceEntry(ctx, false)
mpagenko15ff4a52021-03-02 10:09:20 +00002710 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002711 logger.Errorw(ctx, "No valid OnuDevice -aborting checkOnOnuImageCommit", log.Fields{"device-id": dh.DeviceID})
mpagenko15ff4a52021-03-02 10:09:20 +00002712 return
2713 }
2714
2715 dh.lockUpgradeFsm.RLock()
mpagenko59862f02021-10-11 08:53:18 +00002716 //lockUpgradeFsm must be release before cancellation as this may implicitly request RemoveOnuUpgradeFsm()
mpagenko15ff4a52021-03-02 10:09:20 +00002717 if dh.pOnuUpradeFsm != nil {
mpagenko59862f02021-10-11 08:53:18 +00002718 if dh.upgradeCanceled { //avoid starting some new action in case it is already doing the cancelation
2719 dh.lockUpgradeFsm.RUnlock()
2720 logger.Errorw(ctx, "Some upgrade procedure still runs cancelation - abort", log.Fields{"device-id": dh.DeviceID})
2721 return
2722 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002723 pUpgradeStatemachine := dh.pOnuUpradeFsm.PAdaptFsm.PFsm
mpagenko15ff4a52021-03-02 10:09:20 +00002724 if pUpgradeStatemachine != nil {
2725 // commit is only processed in case out upgrade FSM indicates the according state (for automatic commit)
2726 // (some manual forced commit could do without)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002727 UpgradeState := pUpgradeStatemachine.Current()
2728 if (UpgradeState == swupg.UpgradeStWaitForCommit) ||
2729 (UpgradeState == swupg.UpgradeStRequestingActivate) {
2730 // also include UpgradeStRequestingActivate as it may be left in case the ActivateResponse just got lost
mpagenko183647c2021-06-08 15:25:04 +00002731 // 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 +00002732 if pDevEntry.IsImageToBeCommitted(ctx, dh.pOnuUpradeFsm.InactiveImageMeID) {
mpagenko1f8e8822021-06-25 14:10:21 +00002733 activeImageID, errImg := pDevEntry.GetActiveImageMeID(ctx)
2734 if errImg != nil {
mpagenko59862f02021-10-11 08:53:18 +00002735 dh.lockUpgradeFsm.RUnlock()
mpagenko1f8e8822021-06-25 14:10:21 +00002736 logger.Errorw(ctx, "OnuSwUpgradeFSM abort - could not get active image after reboot",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002737 log.Fields{"device-id": dh.DeviceID})
mpagenko59862f02021-10-11 08:53:18 +00002738 if !dh.upgradeCanceled { //avoid double cancelation in case it is already doing the cancelation
2739 dh.upgradeCanceled = true
2740 dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort
2741 }
mpagenko15ff4a52021-03-02 10:09:20 +00002742 return
2743 }
mpagenko59862f02021-10-11 08:53:18 +00002744 dh.lockUpgradeFsm.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002745 if activeImageID == dh.pOnuUpradeFsm.InactiveImageMeID {
2746 if (UpgradeState == swupg.UpgradeStRequestingActivate) && !dh.pOnuUpradeFsm.GetCommitFlag(ctx) {
mpagenko1f8e8822021-06-25 14:10:21 +00002747 // if FSM was waiting on activateResponse, new image is active, but FSM shall not commit, then:
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002748 if err := pUpgradeStatemachine.Event(swupg.UpgradeEvActivationDone); err != nil {
mpagenko1f8e8822021-06-25 14:10:21 +00002749 logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call activate-done event", log.Fields{"err": err})
2750 return
2751 }
2752 logger.Debugw(ctx, "OnuSwUpgradeFSM activate-done after reboot", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002753 "state": UpgradeState, "device-id": dh.DeviceID})
mpagenko1f8e8822021-06-25 14:10:21 +00002754 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002755 //FSM in waitForCommit or (UpgradeStRequestingActivate [lost ActivateResp] and commit allowed)
2756 if err := pUpgradeStatemachine.Event(swupg.UpgradeEvCommitSw); err != nil {
mpagenko1f8e8822021-06-25 14:10:21 +00002757 logger.Errorw(ctx, "OnuSwUpgradeFSM: can't call commit event", log.Fields{"err": err})
2758 return
2759 }
2760 logger.Debugw(ctx, "OnuSwUpgradeFSM commit image requested", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002761 "state": UpgradeState, "device-id": dh.DeviceID})
mpagenko1f8e8822021-06-25 14:10:21 +00002762 }
2763 } else {
2764 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 +00002765 log.Fields{"device-id": dh.DeviceID})
mpagenko59862f02021-10-11 08:53:18 +00002766 dh.upgradeCanceled = true
mpagenko38662d02021-08-11 09:45:19 +00002767 dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort
mpagenko1f8e8822021-06-25 14:10:21 +00002768 }
mpagenko15ff4a52021-03-02 10:09:20 +00002769 return
2770 }
mpagenko59862f02021-10-11 08:53:18 +00002771 dh.lockUpgradeFsm.RUnlock()
2772 logger.Errorw(ctx, "OnuSwUpgradeFSM waiting to commit, but nothing to commit on ONU - abort upgrade",
2773 log.Fields{"device-id": dh.DeviceID})
2774 dh.upgradeCanceled = true
2775 dh.pOnuUpradeFsm.CancelProcessing(ctx, true, voltha.ImageState_CANCELLED_ON_ONU_STATE) //complete abort
2776 return
2777 }
2778 //upgrade FSM is active but not waiting for commit: maybe because commit flag is not set
2779 // upgrade FSM is to be informed if the current active image is the one that was used in upgrade for the download
2780 if activeImageID, err := pDevEntry.GetActiveImageMeID(ctx); err == nil {
2781 if dh.pOnuUpradeFsm.InactiveImageMeID == activeImageID {
2782 logger.Debugw(ctx, "OnuSwUpgradeFSM image state set to activated", log.Fields{
2783 "state": pUpgradeStatemachine.Current(), "device-id": dh.DeviceID})
2784 dh.pOnuUpradeFsm.SetImageStateActive(ctx)
mpagenko183647c2021-06-08 15:25:04 +00002785 }
mpagenko15ff4a52021-03-02 10:09:20 +00002786 }
2787 }
2788 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002789 logger.Debugw(ctx, "no ONU image to be committed", log.Fields{"device-id": dh.DeviceID})
mpagenko15ff4a52021-03-02 10:09:20 +00002790 }
mpagenko59862f02021-10-11 08:53:18 +00002791 dh.lockUpgradeFsm.RUnlock()
mpagenko15ff4a52021-03-02 10:09:20 +00002792}
2793
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002794//SetBackend provides a DB backend for the specified path on the existing KV client
2795func (dh *deviceHandler) SetBackend(ctx context.Context, aBasePathKvStore string) *db.Backend {
Matteo Scandolo127c59d2021-01-28 11:31:18 -08002796
2797 logger.Debugw(ctx, "SetKVStoreBackend", log.Fields{"IpTarget": dh.pOpenOnuAc.KVStoreAddress,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002798 "BasePathKvStore": aBasePathKvStore, "device-id": dh.DeviceID})
Girish Gowdra50e56422021-06-01 16:46:04 -07002799 // kvbackend := db.NewBackend(ctx, dh.pOpenOnuAc.KVStoreType, dh.pOpenOnuAc.KVStoreAddress, dh.pOpenOnuAc.KVStoreTimeout, aBasePathKvStore)
mpagenkoaf801632020-07-03 10:00:42 +00002800 kvbackend := &db.Backend{
2801 Client: dh.pOpenOnuAc.kvClient,
2802 StoreType: dh.pOpenOnuAc.KVStoreType,
2803 /* address config update acc. to [VOL-2736] */
Matteo Scandolo127c59d2021-01-28 11:31:18 -08002804 Address: dh.pOpenOnuAc.KVStoreAddress,
mpagenkoaf801632020-07-03 10:00:42 +00002805 Timeout: dh.pOpenOnuAc.KVStoreTimeout,
2806 PathPrefix: aBasePathKvStore}
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00002807
mpagenkoaf801632020-07-03 10:00:42 +00002808 return kvbackend
Holger Hildebrandt24d51952020-05-04 14:03:42 +00002809}
khenaidoo7d3c5582021-08-11 18:09:44 -04002810func (dh *deviceHandler) getFlowOfbFields(ctx context.Context, apFlowItem *of.OfpFlowStats, loMatchVlan *uint16,
Himani Chawla26e555c2020-08-31 12:30:20 +05302811 loAddPcp *uint8, loIPProto *uint32) {
mpagenkodff5dda2020-08-28 11:52:01 +00002812
mpagenkodff5dda2020-08-28 11:52:01 +00002813 for _, field := range flow.GetOfbFields(apFlowItem) {
2814 switch field.Type {
2815 case of.OxmOfbFieldTypes_OFPXMT_OFB_ETH_TYPE:
2816 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002817 logger.Debugw(ctx, "flow type EthType", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00002818 "EthType": strconv.FormatInt(int64(field.GetEthType()), 16)})
2819 }
mpagenko01e726e2020-10-23 09:45:29 +00002820 /* TT related temporary workaround - should not be needed anymore
mpagenkodff5dda2020-08-28 11:52:01 +00002821 case of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO:
2822 {
Himani Chawla26e555c2020-08-31 12:30:20 +05302823 *loIPProto = field.GetIpProto()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002824 logger.Debugw("flow type IpProto", log.Fields{"device-id": dh.DeviceID,
Himani Chawla26e555c2020-08-31 12:30:20 +05302825 "IpProto": strconv.FormatInt(int64(*loIPProto), 16)})
2826 if *loIPProto == 2 {
mpagenkodff5dda2020-08-28 11:52:01 +00002827 // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow
2828 // avoids installing invalid EVTOCD rule
mpagenko01e726e2020-10-23 09:45:29 +00002829 logger.Debugw("flow type IpProto 2: TT workaround: ignore flow",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002830 log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302831 return
mpagenkodff5dda2020-08-28 11:52:01 +00002832 }
2833 }
mpagenko01e726e2020-10-23 09:45:29 +00002834 */
mpagenkodff5dda2020-08-28 11:52:01 +00002835 case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID:
2836 {
Himani Chawla26e555c2020-08-31 12:30:20 +05302837 *loMatchVlan = uint16(field.GetVlanVid())
mpagenkodff5dda2020-08-28 11:52:01 +00002838 loMatchVlanMask := uint16(field.GetVlanVidMask())
Himani Chawla26e555c2020-08-31 12:30:20 +05302839 if !(*loMatchVlan == uint16(of.OfpVlanId_OFPVID_PRESENT) &&
mpagenkodff5dda2020-08-28 11:52:01 +00002840 loMatchVlanMask == uint16(of.OfpVlanId_OFPVID_PRESENT)) {
Himani Chawla26e555c2020-08-31 12:30:20 +05302841 *loMatchVlan = *loMatchVlan & 0xFFF // not transparent: copy only ID bits
mpagenkodff5dda2020-08-28 11:52:01 +00002842 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002843 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
Himani Chawla26e555c2020-08-31 12:30:20 +05302844 "VID": strconv.FormatInt(int64(*loMatchVlan), 16)})
mpagenkodff5dda2020-08-28 11:52:01 +00002845 }
2846 case of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP:
2847 {
Himani Chawla26e555c2020-08-31 12:30:20 +05302848 *loAddPcp = uint8(field.GetVlanPcp())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002849 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00002850 "PCP": loAddPcp})
2851 }
2852 case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_DST:
2853 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002854 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00002855 "UDP-DST": strconv.FormatInt(int64(field.GetUdpDst()), 16)})
2856 }
2857 case of.OxmOfbFieldTypes_OFPXMT_OFB_UDP_SRC:
2858 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002859 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00002860 "UDP-SRC": strconv.FormatInt(int64(field.GetUdpSrc()), 16)})
2861 }
2862 case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_DST:
2863 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002864 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00002865 "IPv4-DST": field.GetIpv4Dst()})
2866 }
2867 case of.OxmOfbFieldTypes_OFPXMT_OFB_IPV4_SRC:
2868 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002869 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00002870 "IPv4-SRC": field.GetIpv4Src()})
2871 }
2872 case of.OxmOfbFieldTypes_OFPXMT_OFB_METADATA:
2873 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002874 logger.Debugw(ctx, "flow field type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00002875 "Metadata": field.GetTableMetadata()})
2876 }
2877 /*
2878 default:
2879 {
2880 //all other entires ignored
2881 }
2882 */
2883 }
2884 } //for all OfbFields
Himani Chawla26e555c2020-08-31 12:30:20 +05302885}
mpagenkodff5dda2020-08-28 11:52:01 +00002886
khenaidoo7d3c5582021-08-11 18:09:44 -04002887func (dh *deviceHandler) getFlowActions(ctx context.Context, apFlowItem *of.OfpFlowStats, loSetPcp *uint8, loSetVlan *uint16) {
mpagenkodff5dda2020-08-28 11:52:01 +00002888 for _, action := range flow.GetActions(apFlowItem) {
2889 switch action.Type {
2890 /* not used:
2891 case of.OfpActionType_OFPAT_OUTPUT:
2892 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002893 logger.Debugw("flow action type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00002894 "Output": action.GetOutput()})
2895 }
2896 */
2897 case of.OfpActionType_OFPAT_PUSH_VLAN:
2898 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002899 logger.Debugw(ctx, "flow action type", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00002900 "PushEthType": strconv.FormatInt(int64(action.GetPush().Ethertype), 16)})
2901 }
2902 case of.OfpActionType_OFPAT_SET_FIELD:
2903 {
2904 pActionSetField := action.GetSetField()
2905 if pActionSetField.Field.OxmClass != of.OfpOxmClass_OFPXMC_OPENFLOW_BASIC {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002906 logger.Warnw(ctx, "flow action SetField invalid OxmClass (ignored)", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00002907 "OxcmClass": pActionSetField.Field.OxmClass})
2908 }
2909 if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID {
Himani Chawla26e555c2020-08-31 12:30:20 +05302910 *loSetVlan = uint16(pActionSetField.Field.GetOfbField().GetVlanVid())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002911 logger.Debugw(ctx, "flow Set VLAN from SetField action", log.Fields{"device-id": dh.DeviceID,
Himani Chawla26e555c2020-08-31 12:30:20 +05302912 "SetVlan": strconv.FormatInt(int64(*loSetVlan), 16)})
mpagenkodff5dda2020-08-28 11:52:01 +00002913 } else if pActionSetField.Field.GetOfbField().Type == of.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP {
Himani Chawla26e555c2020-08-31 12:30:20 +05302914 *loSetPcp = uint8(pActionSetField.Field.GetOfbField().GetVlanPcp())
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002915 logger.Debugw(ctx, "flow Set PCP from SetField action", log.Fields{"device-id": dh.DeviceID,
Himani Chawla26e555c2020-08-31 12:30:20 +05302916 "SetPcp": *loSetPcp})
mpagenkodff5dda2020-08-28 11:52:01 +00002917 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002918 logger.Warnw(ctx, "flow action SetField invalid FieldType", log.Fields{"device-id": dh.DeviceID,
mpagenkodff5dda2020-08-28 11:52:01 +00002919 "Type": pActionSetField.Field.GetOfbField().Type})
2920 }
2921 }
2922 /*
2923 default:
2924 {
2925 //all other entires ignored
2926 }
2927 */
2928 }
2929 } //for all Actions
Himani Chawla26e555c2020-08-31 12:30:20 +05302930}
2931
2932//addFlowItemToUniPort parses the actual flow item to add it to the UniPort
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002933func (dh *deviceHandler) addFlowItemToUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort,
ozgecanetsia82b91a62021-05-21 18:54:49 +03002934 apFlowMetaData *voltha.FlowMetadata) error {
Himani Chawla26e555c2020-08-31 12:30:20 +05302935 var loSetVlan uint16 = uint16(of.OfpVlanId_OFPVID_NONE) //noValidEntry
2936 var loMatchVlan uint16 = uint16(of.OfpVlanId_OFPVID_PRESENT) //reserved VLANID entry
2937 var loAddPcp, loSetPcp uint8
2938 var loIPProto uint32
2939 /* the TechProfileId is part of the flow Metadata - compare also comment within
2940 * OLT-Adapter:openolt_flowmgr.go
2941 * Metadata 8 bytes:
2942 * Most Significant 2 Bytes = Inner VLAN
2943 * Next 2 Bytes = Tech Profile ID(TPID)
2944 * Least Significant 4 Bytes = Port ID
2945 * Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all
2946 * subscriber related flows.
2947 */
2948
dbainbri4d3a0dc2020-12-02 00:33:42 +00002949 metadata := flow.GetMetadataFromWriteMetadataAction(ctx, apFlowItem)
Himani Chawla26e555c2020-08-31 12:30:20 +05302950 if metadata == 0 {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002951 logger.Debugw(ctx, "flow-add invalid metadata - abort",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002952 log.Fields{"device-id": dh.DeviceID})
2953 return fmt.Errorf("flow-add invalid metadata: %s", dh.DeviceID)
Himani Chawla26e555c2020-08-31 12:30:20 +05302954 }
mpagenko551a4d42020-12-08 18:09:20 +00002955 loTpID := uint8(flow.GetTechProfileIDFromWriteMetaData(ctx, metadata))
mpagenko01e726e2020-10-23 09:45:29 +00002956 loCookie := apFlowItem.GetCookie()
2957 loCookieSlice := []uint64{loCookie}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002958 logger.Debugw(ctx, "flow-add base indications", log.Fields{"device-id": dh.DeviceID,
mpagenko01e726e2020-10-23 09:45:29 +00002959 "TechProf-Id": loTpID, "cookie": loCookie})
Himani Chawla26e555c2020-08-31 12:30:20 +05302960
dbainbri4d3a0dc2020-12-02 00:33:42 +00002961 dh.getFlowOfbFields(ctx, apFlowItem, &loMatchVlan, &loAddPcp, &loIPProto)
mpagenko01e726e2020-10-23 09:45:29 +00002962 /* TT related temporary workaround - should not be needed anymore
Himani Chawla26e555c2020-08-31 12:30:20 +05302963 if loIPProto == 2 {
2964 // some workaround for TT workflow at proto == 2 (IGMP trap) -> ignore the flow
2965 // avoids installing invalid EVTOCD rule
mpagenko01e726e2020-10-23 09:45:29 +00002966 logger.Debugw("flow-add type IpProto 2: TT workaround: ignore flow",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002967 log.Fields{"device-id": dh.DeviceID})
Himani Chawla26e555c2020-08-31 12:30:20 +05302968 return nil
2969 }
mpagenko01e726e2020-10-23 09:45:29 +00002970 */
dbainbri4d3a0dc2020-12-02 00:33:42 +00002971 dh.getFlowActions(ctx, apFlowItem, &loSetPcp, &loSetVlan)
mpagenkodff5dda2020-08-28 11:52:01 +00002972
2973 if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00002974 logger.Errorw(ctx, "flow-add aborted - SetVlanId undefined, but MatchVid set", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002975 "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo,
mpagenkodff5dda2020-08-28 11:52:01 +00002976 "set_vid": strconv.FormatInt(int64(loSetVlan), 16),
2977 "match_vid": strconv.FormatInt(int64(loMatchVlan), 16)})
2978 //TODO!!: Use DeviceId within the error response to rwCore
2979 // likewise also in other error response cases to calling components as requested in [VOL-3458]
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002980 return fmt.Errorf("flow-add Set/Match VlanId inconsistent: %s", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00002981 }
2982 if loSetVlan == uint16(of.OfpVlanId_OFPVID_NONE) && loMatchVlan == uint16(of.OfpVlanId_OFPVID_PRESENT) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002983 logger.Debugw(ctx, "flow-add vlan-any/copy", log.Fields{"device-id": dh.DeviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00002984 loSetVlan = loMatchVlan //both 'transparent' (copy any)
2985 } else {
2986 //looks like OMCI value 4097 (copyFromOuter - for Uni double tagged) is not supported here
2987 if loSetVlan != uint16(of.OfpVlanId_OFPVID_PRESENT) {
2988 // not set to transparent
Himani Chawla26e555c2020-08-31 12:30:20 +05302989 loSetVlan &= 0x0FFF //mask VID bits as prerequisite for vlanConfigFsm
mpagenkodff5dda2020-08-28 11:52:01 +00002990 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00002991 logger.Debugw(ctx, "flow-add vlan-set", log.Fields{"device-id": dh.DeviceID})
mpagenkodff5dda2020-08-28 11:52:01 +00002992 }
mpagenko9a304ea2020-12-16 15:54:01 +00002993
ozgecanetsia82b91a62021-05-21 18:54:49 +03002994 var meter *voltha.OfpMeterConfig
2995 if apFlowMetaData != nil {
2996 meter = apFlowMetaData.Meters[0]
2997 }
mpagenkobc4170a2021-08-17 16:42:10 +00002998 //mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities
2999 // must be set including the execution of createVlanFilterFsm() to avoid unintended creation of FSM's
3000 // when different rules are requested concurrently for the same uni
3001 // (also vlan persistency data does not support multiple FSM's on the same UNI correctly!)
3002 dh.lockVlanAdd.Lock() //prevent multiple add activities to start in parallel
3003 dh.lockVlanConfig.RLock() //read protection on UniVlanConfigFsmMap (removeFlowItemFromUniPort)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003004 logger.Debugw(ctx, "flow-add got lock", log.Fields{"device-id": dh.DeviceID, "tpID": loTpID, "uniID": apUniPort.UniID})
3005 if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist {
mpagenkobc4170a2021-08-17 16:42:10 +00003006 //SetUniFlowParams() may block on some rule that is suspended-to-add
3007 // in order to allow for according flow removal lockVlanConfig may only be used with RLock here
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003008 err := dh.UniVlanConfigFsmMap[apUniPort.UniID].SetUniFlowParams(ctx, loTpID, loCookieSlice,
ozgecanetsia82b91a62021-05-21 18:54:49 +03003009 loMatchVlan, loSetVlan, loSetPcp, false, meter)
mpagenkobc4170a2021-08-17 16:42:10 +00003010 dh.lockVlanConfig.RUnlock()
3011 dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing
mpagenkof1fc3862021-02-16 10:09:52 +00003012 return err
mpagenkodff5dda2020-08-28 11:52:01 +00003013 }
mpagenkobc4170a2021-08-17 16:42:10 +00003014 dh.lockVlanConfig.RUnlock()
3015 dh.lockVlanConfig.Lock() //createVlanFilterFsm should always be a non-blocking operation and requires r+w lock
mpagenko7d14de12021-07-27 08:31:56 +00003016 err := dh.createVlanFilterFsm(ctx, apUniPort, loTpID, loCookieSlice,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003017 loMatchVlan, loSetVlan, loSetPcp, cmn.OmciVlanFilterAddDone, false, meter)
mpagenko7d14de12021-07-27 08:31:56 +00003018 dh.lockVlanConfig.Unlock()
mpagenkobc4170a2021-08-17 16:42:10 +00003019 dh.lockVlanAdd.Unlock() //re-admit new Add-flow-processing
mpagenko7d14de12021-07-27 08:31:56 +00003020 return err
mpagenko01e726e2020-10-23 09:45:29 +00003021}
3022
3023//removeFlowItemFromUniPort parses the actual flow item to remove it from the UniPort
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003024func (dh *deviceHandler) removeFlowItemFromUniPort(ctx context.Context, apFlowItem *of.OfpFlowStats, apUniPort *cmn.OnuUniPort) error {
mpagenko01e726e2020-10-23 09:45:29 +00003025 //optimization and assumption: the flow cookie uniquely identifies the flow and with that the internal rule
3026 //hence only the cookie is used here to find the relevant flow and possibly remove the rule
3027 //no extra check is done on the rule parameters
3028 //accordingly the removal is done only once - for the first found flow with that cookie, even though
3029 // at flow creation is not assured, that the same cookie is not configured for different flows - just assumed
3030 //additionally it is assumed here, that removal can only be done for one cookie per flow in a sequence (different
3031 // from addFlow - where at reconcilement multiple cookies per flow ) can be configured in one sequence)
mpagenkofc4f56e2020-11-04 17:17:49 +00003032 // - 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 +00003033 loCookie := apFlowItem.GetCookie()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003034 logger.Debugw(ctx, "flow-remove base indications", log.Fields{"device-id": dh.DeviceID, "cookie": loCookie})
mpagenko01e726e2020-10-23 09:45:29 +00003035
3036 /* TT related temporary workaround - should not be needed anymore
3037 for _, field := range flow.GetOfbFields(apFlowItem) {
3038 if field.Type == of.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO {
3039 loIPProto := field.GetIpProto()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003040 logger.Debugw(ctx, "flow type IpProto", log.Fields{"device-id": dh.DeviceID,
mpagenko01e726e2020-10-23 09:45:29 +00003041 "IpProto": strconv.FormatInt(int64(loIPProto), 16)})
3042 if loIPProto == 2 {
3043 // some workaround for TT workflow on proto == 2 (IGMP trap) -> the flow was not added, no need to remove
mpagenko551a4d42020-12-08 18:09:20 +00003044 logger.Debugw(ctx, "flow-remove type IpProto 2: TT workaround: ignore flow",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003045 log.Fields{"device-id": dh.DeviceID})
mpagenko01e726e2020-10-23 09:45:29 +00003046 return nil
3047 }
3048 }
3049 } //for all OfbFields
3050 */
3051
mpagenko9a304ea2020-12-16 15:54:01 +00003052 //mutex protection as the update_flow rpc maybe running concurrently for different flows, perhaps also activities
mpagenkof1fc3862021-02-16 10:09:52 +00003053 dh.lockVlanConfig.RLock()
3054 defer dh.lockVlanConfig.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003055 logger.Debugw(ctx, "flow-remove got RLock", log.Fields{"device-id": dh.DeviceID, "uniID": apUniPort.UniID})
3056 if _, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist {
3057 return dh.UniVlanConfigFsmMap[apUniPort.UniID].RemoveUniFlowParams(ctx, loCookie)
mpagenko01e726e2020-10-23 09:45:29 +00003058 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00003059 logger.Debugw(ctx, "flow-remove called, but no flow is configured (no VlanConfigFsm, flow already removed) ",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003060 log.Fields{"device-id": dh.DeviceID})
mpagenko01e726e2020-10-23 09:45:29 +00003061 //but as we regard the flow as not existing = removed we respond just ok
mpagenkofc4f56e2020-11-04 17:17:49 +00003062 // and treat the reason accordingly (which in the normal removal procedure is initiated by the FSM)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003063 go dh.DeviceProcStatusUpdate(ctx, cmn.OmciVlanFilterRemDone)
mpagenkofc4f56e2020-11-04 17:17:49 +00003064
mpagenko01e726e2020-10-23 09:45:29 +00003065 return nil
mpagenkodff5dda2020-08-28 11:52:01 +00003066}
3067
Himani Chawla26e555c2020-08-31 12:30:20 +05303068// createVlanFilterFsm initializes and runs the VlanFilter FSM to transfer OMCI related VLAN config
mpagenko9a304ea2020-12-16 15:54:01 +00003069// if this function is called from possibly concurrent processes it must be mutex-protected from the caller!
mpagenko7d14de12021-07-27 08:31:56 +00003070// precondition: dh.lockVlanConfig is locked by the caller!
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003071func (dh *deviceHandler) createVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8, aCookieSlice []uint64,
3072 aMatchVlan uint16, aSetVlan uint16, aSetPcp uint8, aDevEvent cmn.OnuDeviceEvent, lastFlowToReconcile bool, aMeter *voltha.OfpMeterConfig) error {
3073 chVlanFilterFsm := make(chan cmn.Message, 2048)
mpagenkodff5dda2020-08-28 11:52:01 +00003074
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003075 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
mpagenkodff5dda2020-08-28 11:52:01 +00003076 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003077 logger.Errorw(ctx, "No valid OnuDevice -aborting", log.Fields{"device-id": dh.DeviceID})
3078 return fmt.Errorf("no valid OnuDevice for device-id %x - aborting", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00003079 }
3080
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003081 pVlanFilterFsm := avcfg.NewUniVlanConfigFsm(ctx, dh, pDevEntry, pDevEntry.PDevOmciCC, apUniPort, dh.pOnuTP,
3082 pDevEntry.GetOnuDB(), aTpID, aDevEvent, "UniVlanConfigFsm", chVlanFilterFsm,
ozgecanetsia82b91a62021-05-21 18:54:49 +03003083 dh.pOpenOnuAc.AcceptIncrementalEvto, aCookieSlice, aMatchVlan, aSetVlan, aSetPcp, lastFlowToReconcile, aMeter)
mpagenkodff5dda2020-08-28 11:52:01 +00003084 if pVlanFilterFsm != nil {
mpagenko7d14de12021-07-27 08:31:56 +00003085 //dh.lockVlanConfig is locked (by caller) throughout the state transition to 'starting'
3086 // to prevent unintended (ignored) events to be sent there (from parallel processing)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003087 dh.UniVlanConfigFsmMap[apUniPort.UniID] = pVlanFilterFsm
3088 pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm
mpagenkodff5dda2020-08-28 11:52:01 +00003089 if pVlanFilterStatemachine != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003090 if pVlanFilterStatemachine.Is(avcfg.VlanStDisabled) {
3091 if err := pVlanFilterStatemachine.Event(avcfg.VlanEvStart); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003092 logger.Warnw(ctx, "UniVlanConfigFsm: can't start", log.Fields{"err": err})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003093 return fmt.Errorf("can't start UniVlanConfigFsm for device-id %x", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00003094 }
Himani Chawla26e555c2020-08-31 12:30:20 +05303095 /***** UniVlanConfigFsm started */
dbainbri4d3a0dc2020-12-02 00:33:42 +00003096 logger.Debugw(ctx, "UniVlanConfigFsm started", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003097 "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
3098 "UniPort": apUniPort.PortNo})
mpagenkodff5dda2020-08-28 11:52:01 +00003099 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003100 logger.Warnw(ctx, "wrong state of UniVlanConfigFsm - want: disabled", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003101 "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID})
3102 return fmt.Errorf("uniVlanConfigFsm not in expected disabled state for device-id %x", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00003103 }
3104 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003105 logger.Errorw(ctx, "UniVlanConfigFsm StateMachine invalid - cannot be executed!!", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003106 "device-id": dh.DeviceID})
3107 return fmt.Errorf("uniVlanConfigFsm invalid for device-id %x", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00003108 }
3109 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003110 logger.Errorw(ctx, "UniVlanConfigFsm could not be created - abort!!", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003111 "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo})
3112 return fmt.Errorf("uniVlanConfigFsm could not be created for device-id %x", dh.DeviceID)
mpagenkodff5dda2020-08-28 11:52:01 +00003113 }
3114 return nil
3115}
3116
mpagenkofc4f56e2020-11-04 17:17:49 +00003117//VerifyVlanConfigRequest checks on existence of a given uniPort
3118// and starts verification of flow config based on that
mpagenko551a4d42020-12-08 18:09:20 +00003119func (dh *deviceHandler) VerifyVlanConfigRequest(ctx context.Context, aUniID uint8, aTpID uint8) {
mpagenkofc4f56e2020-11-04 17:17:49 +00003120 //ensure that the given uniID is available (configured) in the UniPort class (used for OMCI entities)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003121 var pCurrentUniPort *cmn.OnuUniPort
mpagenkofc4f56e2020-11-04 17:17:49 +00003122 for _, uniPort := range dh.uniEntityMap {
3123 // only if this port is validated for operState transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003124 if uniPort.UniID == uint8(aUniID) {
mpagenkofc4f56e2020-11-04 17:17:49 +00003125 pCurrentUniPort = uniPort
3126 break //found - end search loop
3127 }
3128 }
3129 if pCurrentUniPort == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003130 logger.Debugw(ctx, "VerifyVlanConfig aborted: requested uniID not found in PortDB",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003131 log.Fields{"device-id": dh.DeviceID, "uni-id": aUniID})
mpagenkofc4f56e2020-11-04 17:17:49 +00003132 return
3133 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003134 dh.VerifyUniVlanConfigRequest(ctx, pCurrentUniPort, aTpID)
mpagenkofc4f56e2020-11-04 17:17:49 +00003135}
3136
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003137//VerifyUniVlanConfigRequest checks on existence of flow configuration and starts it accordingly
3138func (dh *deviceHandler) VerifyUniVlanConfigRequest(ctx context.Context, apUniPort *cmn.OnuUniPort, aTpID uint8) {
mpagenkodff5dda2020-08-28 11:52:01 +00003139 //TODO!! verify and start pending flow configuration
3140 //some pending config request my exist in case the UniVlanConfig FSM was already started - with internal data -
3141 //but execution was set to 'on hold' as first the TechProfile config had to be applied
mpagenkof1fc3862021-02-16 10:09:52 +00003142
3143 dh.lockVlanConfig.RLock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003144 if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[apUniPort.UniID]; exist {
mpagenkof1fc3862021-02-16 10:09:52 +00003145 dh.lockVlanConfig.RUnlock()
mpagenkodff5dda2020-08-28 11:52:01 +00003146 //VlanFilterFsm exists and was already started (assumed to wait for TechProfile execution here)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003147 pVlanFilterStatemachine := pVlanFilterFsm.PAdaptFsm.PFsm
mpagenkodff5dda2020-08-28 11:52:01 +00003148 if pVlanFilterStatemachine != nil {
mpagenko551a4d42020-12-08 18:09:20 +00003149 //if this was an event of the TP processing that was waited for in the VlanFilterFsm
3150 if pVlanFilterFsm.GetWaitingTpID() == aTpID {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003151 if pVlanFilterStatemachine.Is(avcfg.VlanStWaitingTechProf) {
3152 if err := pVlanFilterStatemachine.Event(avcfg.VlanEvContinueConfig); err != nil {
mpagenko551a4d42020-12-08 18:09:20 +00003153 logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003154 "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo})
mpagenko551a4d42020-12-08 18:09:20 +00003155 } else {
3156 /***** UniVlanConfigFsm continued */
3157 logger.Debugw(ctx, "UniVlanConfigFsm continued", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003158 "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
3159 "UniPort": apUniPort.PortNo})
mpagenko551a4d42020-12-08 18:09:20 +00003160 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003161 } else if pVlanFilterStatemachine.Is(avcfg.VlanStIncrFlowWaitTP) {
3162 if err := pVlanFilterStatemachine.Event(avcfg.VlanEvIncrFlowConfig); err != nil {
mpagenko551a4d42020-12-08 18:09:20 +00003163 logger.Warnw(ctx, "UniVlanConfigFsm: can't continue processing", log.Fields{"err": err,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003164 "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo})
mpagenko551a4d42020-12-08 18:09:20 +00003165 } else {
3166 /***** UniVlanConfigFsm continued */
3167 logger.Debugw(ctx, "UniVlanConfigFsm continued with incremental flow", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003168 "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
3169 "UniPort": apUniPort.PortNo})
mpagenko551a4d42020-12-08 18:09:20 +00003170 }
mpagenkodff5dda2020-08-28 11:52:01 +00003171 } else {
mpagenko551a4d42020-12-08 18:09:20 +00003172 logger.Debugw(ctx, "no state of UniVlanConfigFsm to be continued", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003173 "have": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
3174 "UniPort": apUniPort.PortNo})
mpagenkodff5dda2020-08-28 11:52:01 +00003175 }
3176 } else {
mpagenko551a4d42020-12-08 18:09:20 +00003177 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 +00003178 "state": pVlanFilterStatemachine.Current(), "device-id": dh.DeviceID,
3179 "UniPort": apUniPort.PortNo, "techprofile-id (done)": aTpID})
mpagenkodff5dda2020-08-28 11:52:01 +00003180 }
3181 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003182 logger.Debugw(ctx, "UniVlanConfigFsm StateMachine does not exist, no flow processing", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003183 "device-id": dh.DeviceID, "UniPort": apUniPort.PortNo})
mpagenkodff5dda2020-08-28 11:52:01 +00003184 }
mpagenkof1fc3862021-02-16 10:09:52 +00003185 } else {
3186 dh.lockVlanConfig.RUnlock()
3187 }
mpagenkodff5dda2020-08-28 11:52:01 +00003188}
3189
3190//RemoveVlanFilterFsm deletes the stored pointer to the VlanConfigFsm
3191// intention is to provide this method to be called from VlanConfigFsm itself, when resources (and methods!) are cleaned up
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003192func (dh *deviceHandler) RemoveVlanFilterFsm(ctx context.Context, apUniPort *cmn.OnuUniPort) {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003193 logger.Debugw(ctx, "remove UniVlanConfigFsm StateMachine", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003194 "device-id": dh.DeviceID, "uniPort": apUniPort.PortNo})
mpagenkodff5dda2020-08-28 11:52:01 +00003195 //save to do, even if entry dows not exist
mpagenkof1fc3862021-02-16 10:09:52 +00003196 dh.lockVlanConfig.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003197 delete(dh.UniVlanConfigFsmMap, apUniPort.UniID)
mpagenkof1fc3862021-02-16 10:09:52 +00003198 dh.lockVlanConfig.Unlock()
mpagenkodff5dda2020-08-28 11:52:01 +00003199}
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003200
mpagenkof1fc3862021-02-16 10:09:52 +00003201//startWritingOnuDataToKvStore initiates the KVStore write of ONU persistent data
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003202func (dh *deviceHandler) startWritingOnuDataToKvStore(ctx context.Context, aPDevEntry *mib.OnuDeviceEntry) error {
mpagenkof1fc3862021-02-16 10:09:52 +00003203 dh.mutexKvStoreContext.Lock() //this write routine may (could) be called with the same context,
3204 defer dh.mutexKvStoreContext.Unlock() //this write routine may (could) be called with the same context,
3205 // obviously then parallel processing on the cancel must be avoided
3206 // deadline context to ensure completion of background routines waited for
3207 //20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
3208 deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
3209 dctx, cancel := context.WithDeadline(context.Background(), deadline)
3210
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003211 aPDevEntry.ResetKvProcessingErrorIndication()
mpagenkof1fc3862021-02-16 10:09:52 +00003212 var wg sync.WaitGroup
3213 wg.Add(1) // for the 1 go routine to finish
3214
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003215 go aPDevEntry.UpdateOnuKvStore(log.WithSpanFromContext(dctx, ctx), &wg)
mpagenkof1fc3862021-02-16 10:09:52 +00003216 dh.waitForCompletion(ctx, cancel, &wg, "UpdateKvStore") //wait for background process to finish
3217
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003218 return aPDevEntry.GetKvProcessingErrorIndication()
mpagenkof1fc3862021-02-16 10:09:52 +00003219}
3220
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003221//StorePersUniFlowConfig updates local storage of OnuUniFlowConfig and writes it into kv-store afterwards to have it
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003222//available for potential reconcilement
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003223func (dh *deviceHandler) StorePersUniFlowConfig(ctx context.Context, aUniID uint8,
3224 aUniVlanFlowParams *[]cmn.UniVlanFlowParams, aWriteToKvStore bool) error {
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003225
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003226 if dh.IsReconciling() {
3227 logger.Debugw(ctx, "reconciling - don't store persistent UniFlowConfig", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003228 return nil
3229 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003230 logger.Debugw(ctx, "Store or clear persistent UniFlowConfig", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003231
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003232 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003233 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003234 logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.DeviceID})
3235 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003236 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003237 pDevEntry.UpdateOnuUniFlowConfig(aUniID, aUniVlanFlowParams)
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003238
mpagenkof1fc3862021-02-16 10:09:52 +00003239 if aWriteToKvStore {
3240 return dh.startWritingOnuDataToKvStore(ctx, pDevEntry)
3241 }
3242 return nil
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003243}
3244
dbainbri4d3a0dc2020-12-02 00:33:42 +00003245func (dh *deviceHandler) waitForCompletion(ctx context.Context, cancel context.CancelFunc, wg *sync.WaitGroup, aCallerIdent string) {
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003246 defer cancel() //ensure termination of context (may be pro forma)
3247 wg.Wait()
dbainbri4d3a0dc2020-12-02 00:33:42 +00003248 logger.Debugw(ctx, "WaitGroup processing completed", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003249 "device-id": dh.DeviceID, "called from": aCallerIdent})
Holger Hildebrandt47555e72020-09-21 11:07:24 +00003250}
3251
dbainbri4d3a0dc2020-12-02 00:33:42 +00003252func (dh *deviceHandler) deviceReasonUpdate(ctx context.Context, deviceReason uint8, notifyCore bool) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +00003253
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003254 dh.SetDeviceReason(deviceReason)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00003255 if notifyCore {
Holger Hildebrandt80129db2020-11-23 10:49:32 +00003256 //TODO with VOL-3045/VOL-3046: return the error and stop further processing at calling position
khenaidoo7d3c5582021-08-11 18:09:44 -04003257 if err := dh.updateDeviceReasonInCore(ctx, &ic.DeviceReason{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003258 DeviceId: dh.DeviceID,
3259 Reason: cmn.DeviceReasonMap[deviceReason],
khenaidoo7d3c5582021-08-11 18:09:44 -04003260 }); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00003261 logger.Errorf(ctx, "DeviceReasonUpdate error: %s",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003262 log.Fields{"device-id": dh.DeviceID, "error": err}, cmn.DeviceReasonMap[deviceReason])
Holger Hildebrandt80129db2020-11-23 10:49:32 +00003263 return err
3264 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003265 logger.Infof(ctx, "DeviceReasonUpdate success: %s - device-id: %s", cmn.DeviceReasonMap[deviceReason], dh.DeviceID)
Holger Hildebrandt80129db2020-11-23 10:49:32 +00003266 return nil
3267 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003268 logger.Infof(ctx, "Don't notify core about DeviceReasonUpdate: %s - device-id: %s", cmn.DeviceReasonMap[deviceReason], dh.DeviceID)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00003269 return nil
3270}
3271
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003272func (dh *deviceHandler) StorePersistentData(ctx context.Context) error {
3273 pDevEntry := dh.GetOnuDeviceEntry(ctx, true)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00003274 if pDevEntry == nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003275 logger.Warnw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.DeviceID})
3276 return fmt.Errorf("no valid OnuDevice: %s", dh.DeviceID)
Holger Hildebrandt3a644642020-12-02 09:46:18 +00003277 }
mpagenkof1fc3862021-02-16 10:09:52 +00003278 return dh.startWritingOnuDataToKvStore(ctx, pDevEntry)
Holger Hildebrandt80129db2020-11-23 10:49:32 +00003279}
3280
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003281// getUniPortMEEntityID takes uniPortNo as the input and returns the Entity ID corresponding to this UNI-G ME Instance
ozgecanetsia72e1c9f2021-05-26 17:26:29 +03003282// nolint: unused
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003283func (dh *deviceHandler) getUniPortMEEntityID(uniPortNo uint32) (uint16, error) {
3284 dh.lockDevice.RLock()
3285 defer dh.lockDevice.RUnlock()
3286 if uniPort, ok := dh.uniEntityMap[uniPortNo]; ok {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003287 return uniPort.EntityID, nil
ozgecanetsiab5000ef2020-11-27 14:38:20 +03003288 }
3289 return 0, errors.New("error-fetching-uni-port")
3290}
Girish Gowdrae09a6202021-01-12 18:10:59 -08003291
3292// updatePmConfig updates the pm metrics config.
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003293func (dh *deviceHandler) updatePmConfig(ctx context.Context, pmConfigs *voltha.PmConfigs) error {
3294 var errorsList []error
3295 logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": dh.device.Id, "new-pm-configs": pmConfigs, "old-pm-config": dh.pmConfigs})
Girish Gowdrae09a6202021-01-12 18:10:59 -08003296
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003297 errorsList = append(dh.handleGlobalPmConfigUpdates(ctx, pmConfigs), errorsList...)
3298 errorsList = append(dh.handleGroupPmConfigUpdates(ctx, pmConfigs), errorsList...)
3299 errorsList = append(dh.handleStandalonePmConfigUpdates(ctx, pmConfigs), errorsList...)
3300
3301 // Note that if more than one pm config field is updated in a given call, it is possible that partial pm config is handled
3302 // successfully.
3303 // TODO: Although it is possible to revert to old config in case of partial failure, the code becomes quite complex. Needs more investigation
3304 // Is it possible the rw-core reverts to old config on partial failure but adapter retains a partial new config?
3305 if len(errorsList) > 0 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003306 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 -08003307 return fmt.Errorf("errors-handling-one-or-more-pm-config, errors:%v", errorsList)
Girish Gowdrae09a6202021-01-12 18:10:59 -08003308 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003309 logger.Infow(ctx, "pm-config-updated", log.Fields{"device-id": dh.DeviceID, "pmConfig": dh.pmConfigs})
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003310 return nil
Girish Gowdrae09a6202021-01-12 18:10:59 -08003311}
3312
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003313func (dh *deviceHandler) handleGlobalPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error {
3314 var err error
3315 var errorsList []error
Girish Gowdra36ccf7d2021-02-25 20:42:51 -08003316 logger.Infow(ctx, "handling-global-pm-config-params - start", log.Fields{"device-id": dh.device.Id})
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003317
3318 if pmConfigs.DefaultFreq != dh.pmConfigs.DefaultFreq {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003319 if err = dh.pOnuMetricsMgr.UpdateDefaultFrequency(ctx, pmConfigs); err != nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003320 errorsList = append(errorsList, err)
3321 }
3322 }
Girish Gowdra36ccf7d2021-02-25 20:42:51 -08003323 logger.Infow(ctx, "handling-global-pm-config-params - done", log.Fields{"device-id": dh.device.Id})
mpagenko15ff4a52021-03-02 10:09:20 +00003324
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003325 return errorsList
3326}
3327
3328func (dh *deviceHandler) handleGroupPmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error {
3329 var err error
3330 var errorsList []error
Girish Gowdra36ccf7d2021-02-25 20:42:51 -08003331 logger.Debugw(ctx, "handling-group-pm-config-params - start", log.Fields{"device-id": dh.device.Id})
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003332 // Check if group metric related config is updated
3333 for _, v := range pmConfigs.Groups {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003334 dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock()
3335 m, ok := dh.pOnuMetricsMgr.GroupMetricMap[v.GroupName]
3336 dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock()
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003337
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003338 if ok && m.Frequency != v.GroupFreq {
3339 if err = dh.pOnuMetricsMgr.UpdateGroupFreq(ctx, v.GroupName, pmConfigs); err != nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003340 errorsList = append(errorsList, err)
3341 }
3342 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003343 if ok && m.Enabled != v.Enabled {
3344 if err = dh.pOnuMetricsMgr.UpdateGroupSupport(ctx, v.GroupName, pmConfigs); err != nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003345 errorsList = append(errorsList, err)
3346 }
3347 }
3348 }
Girish Gowdra36ccf7d2021-02-25 20:42:51 -08003349 logger.Debugw(ctx, "handling-group-pm-config-params - done", log.Fields{"device-id": dh.device.Id})
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003350 return errorsList
3351}
3352
3353func (dh *deviceHandler) handleStandalonePmConfigUpdates(ctx context.Context, pmConfigs *voltha.PmConfigs) []error {
3354 var err error
3355 var errorsList []error
Girish Gowdra36ccf7d2021-02-25 20:42:51 -08003356 logger.Debugw(ctx, "handling-individual-pm-config-params - start", log.Fields{"device-id": dh.device.Id})
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003357 // Check if standalone metric related config is updated
3358 for _, v := range pmConfigs.Metrics {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003359 dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock()
3360 m, ok := dh.pOnuMetricsMgr.StandaloneMetricMap[v.Name]
3361 dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock()
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003362
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003363 if ok && m.Frequency != v.SampleFreq {
3364 if err = dh.pOnuMetricsMgr.UpdateMetricFreq(ctx, v.Name, pmConfigs); err != nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003365 errorsList = append(errorsList, err)
3366 }
3367 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003368 if ok && m.Enabled != v.Enabled {
3369 if err = dh.pOnuMetricsMgr.UpdateMetricSupport(ctx, v.Name, pmConfigs); err != nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003370 errorsList = append(errorsList, err)
3371 }
3372 }
3373 }
Girish Gowdra36ccf7d2021-02-25 20:42:51 -08003374 logger.Debugw(ctx, "handling-individual-pm-config-params - done", log.Fields{"device-id": dh.device.Id})
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003375 return errorsList
3376}
3377
3378// nolint: gocyclo
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003379func (dh *deviceHandler) StartCollector(ctx context.Context) {
Girish Gowdrae09a6202021-01-12 18:10:59 -08003380 logger.Debugf(ctx, "startingCollector")
3381
3382 // Start routine to process OMCI GET Responses
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003383 go dh.pOnuMetricsMgr.ProcessOmciMessages(ctx)
Himani Chawla43f95ff2021-06-03 00:24:12 +05303384 // Create Extended Frame PM ME
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003385 go dh.pOnuMetricsMgr.CreateEthernetFrameExtendedPMME(ctx)
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003386 // Initialize the next metric collection time.
3387 // Normally done when the onu_metrics_manager is initialized the first time, but needed again later when ONU is
3388 // reset like onu rebooted.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003389 dh.pOnuMetricsMgr.InitializeMetricCollectionTime(ctx)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003390 dh.setCollectorIsRunning(true)
Girish Gowdrae09a6202021-01-12 18:10:59 -08003391 for {
3392 select {
3393 case <-dh.stopCollector:
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003394 dh.setCollectorIsRunning(false)
Girish Gowdrae09a6202021-01-12 18:10:59 -08003395 logger.Debugw(ctx, "stopping-collector-for-onu", log.Fields{"device-id": dh.device.Id})
Girish Gowdrae0140f02021-02-02 16:55:09 -08003396 // Stop the L2 PM FSM
3397 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003398 if dh.pOnuMetricsMgr.PAdaptFsm != nil && dh.pOnuMetricsMgr.PAdaptFsm.PFsm != nil {
3399 if err := dh.pOnuMetricsMgr.PAdaptFsm.PFsm.Event(pmmgr.L2PmEventStop); err != nil {
3400 logger.Errorw(ctx, "error calling event", log.Fields{"device-id": dh.DeviceID, "err": err})
Girish Gowdrae0140f02021-02-02 16:55:09 -08003401 }
3402 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003403 logger.Errorw(ctx, "metrics manager fsm not initialized", log.Fields{"device-id": dh.DeviceID})
Girish Gowdrae0140f02021-02-02 16:55:09 -08003404 }
3405 }()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003406 if dh.pOnuMetricsMgr.GetOmciProcessingStatus() {
3407 dh.pOnuMetricsMgr.StopProcessingOmciResponses <- true // Stop the OMCI GET response processing routine
Girish Gowdra7b0ee5c2021-03-19 21:48:15 -07003408 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003409 if dh.pOnuMetricsMgr.GetTickGenerationStatus() {
3410 dh.pOnuMetricsMgr.StopTicks <- true
Girish Gowdra7b0ee5c2021-03-19 21:48:15 -07003411 }
Girish Gowdrae0140f02021-02-02 16:55:09 -08003412
Girish Gowdrae09a6202021-01-12 18:10:59 -08003413 return
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003414 case <-time.After(time.Duration(pmmgr.FrequencyGranularity) * time.Second): // Check every FrequencyGranularity to see if it is time for collecting metrics
3415 if !dh.pmConfigs.FreqOverride { // If FreqOverride is false, then NextGlobalMetricCollectionTime applies
3416 // If the current time is eqaul to or greater than the NextGlobalMetricCollectionTime, collect the group and standalone metrics
3417 if time.Now().Equal(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) || time.Now().After(dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime) {
3418 go dh.pOnuMetricsMgr.CollectAllGroupAndStandaloneMetrics(ctx)
Girish Gowdraaf0ad632021-01-27 13:00:01 -08003419 // Update the next metric collection time.
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003420 dh.pOnuMetricsMgr.NextGlobalMetricCollectionTime = time.Now().Add(time.Duration(dh.pmConfigs.DefaultFreq) * time.Second)
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003421 }
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003422 } else {
3423 if dh.pmConfigs.Grouped { // metrics are managed as a group
3424 // parse through the group and standalone metrics to see it is time to collect their metrics
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003425 dh.pOnuMetricsMgr.OnuMetricsManagerLock.RLock() // Rlock as we are reading GroupMetricMap and StandaloneMetricMap
Girish Gowdrae09a6202021-01-12 18:10:59 -08003426
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003427 for n, g := range dh.pOnuMetricsMgr.GroupMetricMap {
3428 // If the group is enabled AND (current time is equal to OR after NextCollectionInterval, collect the group metric)
Girish Gowdrae0140f02021-02-02 16:55:09 -08003429 // 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 +00003430 if g.Enabled && !g.IsL2PMCounter && (time.Now().Equal(g.NextCollectionInterval) || time.Now().After(g.NextCollectionInterval)) {
3431 go dh.pOnuMetricsMgr.CollectGroupMetric(ctx, n)
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003432 }
3433 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003434 for n, m := range dh.pOnuMetricsMgr.StandaloneMetricMap {
3435 // If the standalone is enabled AND (current time is equal to OR after NextCollectionInterval, collect the metric)
3436 if m.Enabled && (time.Now().Equal(m.NextCollectionInterval) || time.Now().After(m.NextCollectionInterval)) {
3437 go dh.pOnuMetricsMgr.CollectStandaloneMetric(ctx, n)
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003438 }
3439 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003440 dh.pOnuMetricsMgr.OnuMetricsManagerLock.RUnlock()
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003441
3442 // parse through the group and update the next metric collection time
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003443 dh.pOnuMetricsMgr.OnuMetricsManagerLock.Lock() // Lock as we are writing the next metric collection time
3444 for _, g := range dh.pOnuMetricsMgr.GroupMetricMap {
3445 // If group enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp
Girish Gowdrae0140f02021-02-02 16:55:09 -08003446 // 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 +00003447 if g.Enabled && !g.IsL2PMCounter && (g.NextCollectionInterval.Before(time.Now()) || g.NextCollectionInterval.Equal(time.Now())) {
3448 g.NextCollectionInterval = time.Now().Add(time.Duration(g.Frequency) * time.Second)
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003449 }
3450 }
3451 // parse through the standalone metrics and update the next metric collection time
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003452 for _, m := range dh.pOnuMetricsMgr.StandaloneMetricMap {
3453 // If standalone metrics enabled, and the NextCollectionInterval is old (before or equal to current time), update the next collection time stamp
3454 if m.Enabled && (m.NextCollectionInterval.Before(time.Now()) || m.NextCollectionInterval.Equal(time.Now())) {
3455 m.NextCollectionInterval = time.Now().Add(time.Duration(m.Frequency) * time.Second)
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003456 }
3457 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003458 dh.pOnuMetricsMgr.OnuMetricsManagerLock.Unlock()
Girish Gowdra5a7c4922021-01-22 18:33:41 -08003459 } /* else { // metrics are not managed as a group
3460 // TODO: We currently do not have standalone metrics. When available, add code here to fetch the metric.
3461 } */
3462 }
Girish Gowdrae09a6202021-01-12 18:10:59 -08003463 }
3464 }
3465}
kesavandfdf77632021-01-26 23:40:33 -05003466
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003467func (dh *deviceHandler) GetUniPortStatus(ctx context.Context, uniInfo *extension.GetOnuUniInfoRequest) *extension.SingleGetValueResponse {
kesavandfdf77632021-01-26 23:40:33 -05003468
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003469 portStatus := uniprt.NewUniPortStatus(dh, dh.pOnuOmciDevice.PDevOmciCC)
3470 return portStatus.GetUniPortStatus(ctx, uniInfo.UniIndex)
kesavandfdf77632021-01-26 23:40:33 -05003471}
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003472
Himani Chawla43f95ff2021-06-03 00:24:12 +05303473func (dh *deviceHandler) getOnuOMCICounters(ctx context.Context, onuInfo *extension.GetOmciEthernetFrameExtendedPmRequest) *extension.SingleGetValueResponse {
3474 if dh.pOnuMetricsMgr == nil {
3475 return &extension.SingleGetValueResponse{
3476 Response: &extension.GetValueResponse{
3477 Status: extension.GetValueResponse_ERROR,
3478 ErrReason: extension.GetValueResponse_INTERNAL_ERROR,
3479 },
3480 }
3481 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003482 resp := dh.pOnuMetricsMgr.CollectEthernetFrameExtendedPMCounters(ctx)
Himani Chawla43f95ff2021-06-03 00:24:12 +05303483 return resp
3484}
3485
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003486func (dh *deviceHandler) isFsmInOmciIdleState(ctx context.Context, PFsm *fsm.FSM, wantedState string) bool {
3487 if PFsm == nil {
mpagenkof1fc3862021-02-16 10:09:52 +00003488 return true //FSM not active - so there is no activity on omci
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003489 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003490 return PFsm.Current() == wantedState
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003491}
3492
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003493func (dh *deviceHandler) isFsmInOmciIdleStateDefault(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, wantedState string) bool {
3494 var PFsm *fsm.FSM
mpagenkof1fc3862021-02-16 10:09:52 +00003495 //note/TODO!!: might be that access to all these specific FSM; pointers need a semaphore protection as well, cmp lockUpgradeFsm
3496 switch omciFsm {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003497 case cmn.CUploadFsm:
mpagenkof1fc3862021-02-16 10:09:52 +00003498 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003499 PFsm = dh.pOnuOmciDevice.PMibUploadFsm.PFsm
mpagenkof1fc3862021-02-16 10:09:52 +00003500 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003501 case cmn.CDownloadFsm:
mpagenkof1fc3862021-02-16 10:09:52 +00003502 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003503 PFsm = dh.pOnuOmciDevice.PMibDownloadFsm.PFsm
mpagenkof1fc3862021-02-16 10:09:52 +00003504 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003505 case cmn.CUniLockFsm:
mpagenkof1fc3862021-02-16 10:09:52 +00003506 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003507 PFsm = dh.pLockStateFsm.PAdaptFsm.PFsm
mpagenkof1fc3862021-02-16 10:09:52 +00003508 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003509 case cmn.CUniUnLockFsm:
mpagenkof1fc3862021-02-16 10:09:52 +00003510 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003511 PFsm = dh.pUnlockStateFsm.PAdaptFsm.PFsm
mpagenkof1fc3862021-02-16 10:09:52 +00003512 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003513 case cmn.CL2PmFsm:
mpagenkof1fc3862021-02-16 10:09:52 +00003514 {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003515 if dh.pOnuMetricsMgr != nil && dh.pOnuMetricsMgr.PAdaptFsm != nil {
3516 PFsm = dh.pOnuMetricsMgr.PAdaptFsm.PFsm
mpagenkof1fc3862021-02-16 10:09:52 +00003517 } else {
3518 return true //FSM not active - so there is no activity on omci
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003519 }
3520 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003521 case cmn.COnuUpgradeFsm:
mpagenko80622a52021-02-09 16:53:23 +00003522 {
3523 dh.lockUpgradeFsm.RLock()
3524 defer dh.lockUpgradeFsm.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003525 PFsm = dh.pOnuUpradeFsm.PAdaptFsm.PFsm
mpagenko80622a52021-02-09 16:53:23 +00003526 }
mpagenkof1fc3862021-02-16 10:09:52 +00003527 default:
3528 {
3529 logger.Errorw(ctx, "invalid stateMachine selected for idle check", log.Fields{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003530 "device-id": dh.DeviceID, "selectedFsm number": omciFsm})
mpagenkof1fc3862021-02-16 10:09:52 +00003531 return false //logical error in FSM check, do not not indicate 'idle' - we can't be sure
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003532 }
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003533 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003534 return dh.isFsmInOmciIdleState(ctx, PFsm, wantedState)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003535}
3536
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003537func (dh *deviceHandler) isAniConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool {
3538 for _, v := range dh.pOnuTP.PAniConfigFsm {
3539 if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003540 return false
3541 }
3542 }
3543 return true
3544}
3545
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003546func (dh *deviceHandler) isUniVlanConfigFsmInOmciIdleState(ctx context.Context, omciFsm cmn.UsedOmciConfigFsms, idleState string) bool {
mpagenkof1fc3862021-02-16 10:09:52 +00003547 dh.lockVlanConfig.RLock()
3548 defer dh.lockVlanConfig.RUnlock()
3549 for _, v := range dh.UniVlanConfigFsmMap {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003550 if !dh.isFsmInOmciIdleState(ctx, v.PAdaptFsm.PFsm, idleState) {
mpagenkof1fc3862021-02-16 10:09:52 +00003551 return false
3552 }
3553 }
3554 return true //FSM not active - so there is no activity on omci
3555}
3556
3557func (dh *deviceHandler) checkUserServiceExists(ctx context.Context) bool {
3558 dh.lockVlanConfig.RLock()
3559 defer dh.lockVlanConfig.RUnlock()
3560 for _, v := range dh.UniVlanConfigFsmMap {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003561 if v.PAdaptFsm.PFsm != nil {
3562 if v.PAdaptFsm.PFsm.Is(avcfg.CVlanFsmConfiguredState) {
mpagenkof1fc3862021-02-16 10:09:52 +00003563 return true //there is at least one VLAN FSM with some active configuration
3564 }
3565 }
3566 }
3567 return false //there is no VLAN FSM with some active configuration
3568}
3569
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003570func (dh *deviceHandler) CheckAuditStartCondition(ctx context.Context, callingFsm cmn.UsedOmciConfigFsms) bool {
mpagenkof1fc3862021-02-16 10:09:52 +00003571 for fsmName, fsmStruct := range fsmOmciIdleStateFuncMap {
3572 if fsmName != callingFsm && !fsmStruct.omciIdleCheckFunc(dh, ctx, fsmName, fsmStruct.omciIdleState) {
3573 return false
3574 }
3575 }
3576 // a further check is done to identify, if at least some data traffic related configuration exists
3577 // so that a user of this ONU could be 'online' (otherwise it makes no sense to check the MDS [with the intention to keep the user service up])
3578 return dh.checkUserServiceExists(ctx)
3579}
3580
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003581func (dh *deviceHandler) PrepareReconcilingWithActiveAdapter(ctx context.Context) {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003582 logger.Debugw(ctx, "prepare to reconcile the ONU with adapter using persistency data", log.Fields{"device-id": dh.device.Id})
3583 if err := dh.resetFsms(ctx, false); err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003584 logger.Errorw(ctx, "reset of FSMs failed!", log.Fields{"device-id": dh.DeviceID, "error": err})
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003585 // TODO: fatal error reset ONU, delete deviceHandler!
3586 return
3587 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003588 dh.uniEntityMap = make(map[uint32]*cmn.OnuUniPort)
3589 dh.StartReconciling(ctx, false)
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003590}
3591
3592func (dh *deviceHandler) setCollectorIsRunning(flagValue bool) {
3593 dh.mutexCollectorFlag.Lock()
3594 dh.collectorIsRunning = flagValue
3595 dh.mutexCollectorFlag.Unlock()
3596}
3597
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003598func (dh *deviceHandler) GetCollectorIsRunning() bool {
Holger Hildebrandt10d98192021-01-27 15:29:31 +00003599 dh.mutexCollectorFlag.RLock()
3600 flagValue := dh.collectorIsRunning
3601 dh.mutexCollectorFlag.RUnlock()
3602 return flagValue
3603}
Himani Chawlaac1f5ad2021-02-04 21:21:54 +05303604
Himani Chawla4c1d4c72021-02-18 12:14:31 +05303605func (dh *deviceHandler) setAlarmManagerIsRunning(flagValue bool) {
3606 dh.mutextAlarmManagerFlag.Lock()
3607 dh.alarmManagerIsRunning = flagValue
3608 dh.mutextAlarmManagerFlag.Unlock()
3609}
3610
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003611func (dh *deviceHandler) GetAlarmManagerIsRunning(ctx context.Context) bool {
Himani Chawla4c1d4c72021-02-18 12:14:31 +05303612 dh.mutextAlarmManagerFlag.RLock()
3613 flagValue := dh.alarmManagerIsRunning
Himani Chawla1472c682021-03-17 17:11:14 +05303614 logger.Debugw(ctx, "alarm-manager-is-running", log.Fields{"flag": dh.alarmManagerIsRunning})
Himani Chawla4c1d4c72021-02-18 12:14:31 +05303615 dh.mutextAlarmManagerFlag.RUnlock()
3616 return flagValue
3617}
3618
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003619func (dh *deviceHandler) StartAlarmManager(ctx context.Context) {
Himani Chawlaac1f5ad2021-02-04 21:21:54 +05303620 logger.Debugf(ctx, "startingAlarmManager")
3621
3622 // Start routine to process OMCI GET Responses
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003623 go dh.pAlarmMgr.StartOMCIAlarmMessageProcessing(ctx)
Himani Chawla4c1d4c72021-02-18 12:14:31 +05303624 dh.setAlarmManagerIsRunning(true)
Himani Chawlaac1f5ad2021-02-04 21:21:54 +05303625 if stop := <-dh.stopAlarmManager; stop {
3626 logger.Debugw(ctx, "stopping-collector-for-onu", log.Fields{"device-id": dh.device.Id})
Himani Chawla4c1d4c72021-02-18 12:14:31 +05303627 dh.setAlarmManagerIsRunning(false)
Himani Chawlad3dac422021-03-13 02:31:31 +05303628 go func() {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003629 if dh.pAlarmMgr.AlarmSyncFsm != nil && dh.pAlarmMgr.AlarmSyncFsm.PFsm != nil {
3630 _ = dh.pAlarmMgr.AlarmSyncFsm.PFsm.Event(almgr.AsEvStop)
Himani Chawla1472c682021-03-17 17:11:14 +05303631 }
Himani Chawlad3dac422021-03-13 02:31:31 +05303632 }()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003633 dh.pAlarmMgr.StopProcessingOmciMessages <- true // Stop the OMCI routines if any(This will stop the fsms also)
3634 dh.pAlarmMgr.StopAlarmAuditTimer <- struct{}{}
Himani Chawla1472c682021-03-17 17:11:14 +05303635 logger.Debugw(ctx, "sent-all-stop-signals-to-alarm-manager", log.Fields{"device-id": dh.device.Id})
Himani Chawlaac1f5ad2021-02-04 21:21:54 +05303636 }
3637}
Holger Hildebrandt38985dc2021-02-18 16:25:20 +00003638
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003639func (dh *deviceHandler) StartReconciling(ctx context.Context, skipOnuConfig bool) {
3640 logger.Debugw(ctx, "start reconciling", log.Fields{"skipOnuConfig": skipOnuConfig, "device-id": dh.DeviceID})
Holger Hildebrandtbe523842021-03-10 10:47:18 +00003641
Maninder7961d722021-06-16 22:10:28 +05303642 connectStatus := voltha.ConnectStatus_UNREACHABLE
3643 operState := voltha.OperStatus_UNKNOWN
3644
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003645 if !dh.IsReconciling() {
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00003646 go func() {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00003647 logger.Debugw(ctx, "wait for channel signal or timeout",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003648 log.Fields{"timeout": dh.pOpenOnuAc.maxTimeoutReconciling, "device-id": dh.DeviceID})
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00003649 select {
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00003650 case success := <-dh.chReconcilingFinished:
3651 if success {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003652 if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil {
Maninderb5187552021-03-23 22:23:42 +05303653 logger.Errorw(ctx, "No valid OnuDevice - aborting Core DeviceStateUpdate",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003654 log.Fields{"device-id": dh.DeviceID})
Maninderb5187552021-03-23 22:23:42 +05303655 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003656 if onuDevEntry.SOnuPersistentData.PersOperState == "up" {
Maninderb5187552021-03-23 22:23:42 +05303657 connectStatus = voltha.ConnectStatus_REACHABLE
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003658 if !onuDevEntry.SOnuPersistentData.PersUniDisableDone {
3659 if onuDevEntry.SOnuPersistentData.PersUniUnlockDone {
Maninderb5187552021-03-23 22:23:42 +05303660 operState = voltha.OperStatus_ACTIVE
3661 } else {
3662 operState = voltha.OperStatus_ACTIVATING
3663 }
3664 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003665 } else if onuDevEntry.SOnuPersistentData.PersOperState == "down" ||
3666 onuDevEntry.SOnuPersistentData.PersOperState == "unknown" ||
3667 onuDevEntry.SOnuPersistentData.PersOperState == "" {
Maninderb5187552021-03-23 22:23:42 +05303668 operState = voltha.OperStatus_DISCOVERED
3669 }
3670
3671 logger.Debugw(ctx, "Core DeviceStateUpdate", log.Fields{"connectStatus": connectStatus, "operState": operState})
Maninderb5187552021-03-23 22:23:42 +05303672 }
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00003673 logger.Debugw(ctx, "reconciling has been finished in time",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003674 log.Fields{"device-id": dh.DeviceID})
khenaidoo7d3c5582021-08-11 18:09:44 -04003675 if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003676 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04003677 ConnStatus: connectStatus,
3678 OperStatus: operState,
3679 }); err != nil {
Maninder7961d722021-06-16 22:10:28 +05303680 logger.Errorw(ctx, "unable to update device state to core",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003681 log.Fields{"device-id": dh.DeviceID, "Err": err})
Maninder7961d722021-06-16 22:10:28 +05303682 }
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00003683 } else {
Maninderb5187552021-03-23 22:23:42 +05303684 logger.Errorw(ctx, "wait for reconciling aborted",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003685 log.Fields{"device-id": dh.DeviceID})
Maninder7961d722021-06-16 22:10:28 +05303686
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003687 if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil {
Maninder7961d722021-06-16 22:10:28 +05303688 logger.Errorw(ctx, "No valid OnuDevice",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003689 log.Fields{"device-id": dh.DeviceID})
3690 } else if onuDevEntry.SOnuPersistentData.PersOperState == "up" {
Maninder7961d722021-06-16 22:10:28 +05303691 connectStatus = voltha.ConnectStatus_REACHABLE
3692 }
3693
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003694 dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileCanceled, connectStatus)
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00003695 }
Holger Hildebrandt38985dc2021-02-18 16:25:20 +00003696 case <-time.After(dh.pOpenOnuAc.maxTimeoutReconciling):
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00003697 logger.Errorw(ctx, "timeout waiting for reconciling to be finished!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003698 log.Fields{"device-id": dh.DeviceID})
Maninder7961d722021-06-16 22:10:28 +05303699
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003700 if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil {
Maninder7961d722021-06-16 22:10:28 +05303701 logger.Errorw(ctx, "No valid OnuDevice",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003702 log.Fields{"device-id": dh.DeviceID})
3703 } else if onuDevEntry.SOnuPersistentData.PersOperState == "up" {
Maninder7961d722021-06-16 22:10:28 +05303704 connectStatus = voltha.ConnectStatus_REACHABLE
3705 }
3706
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003707 dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileMaxTimeout, connectStatus)
Maninder7961d722021-06-16 22:10:28 +05303708
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00003709 }
3710 dh.mutexReconcilingFlag.Lock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00003711 dh.reconciling = cNoReconciling
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00003712 dh.mutexReconcilingFlag.Unlock()
3713 }()
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00003714 }
Holger Hildebrandtbe523842021-03-10 10:47:18 +00003715 dh.mutexReconcilingFlag.Lock()
3716 if skipOnuConfig {
3717 dh.reconciling = cSkipOnuConfigReconciling
3718 } else {
3719 dh.reconciling = cOnuConfigReconciling
3720 }
3721 dh.mutexReconcilingFlag.Unlock()
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00003722}
3723
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003724func (dh *deviceHandler) StopReconciling(ctx context.Context, success bool) {
3725 logger.Debugw(ctx, "stop reconciling", log.Fields{"device-id": dh.DeviceID, "success": success})
3726 if dh.IsReconciling() {
Girish Gowdra50e56422021-06-01 16:46:04 -07003727 dh.chReconcilingFinished <- success
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00003728 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003729 logger.Infow(ctx, "reconciling is not running", log.Fields{"device-id": dh.DeviceID})
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00003730 }
3731}
3732
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003733func (dh *deviceHandler) IsReconciling() bool {
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00003734 dh.mutexReconcilingFlag.RLock()
Holger Hildebrandtbe523842021-03-10 10:47:18 +00003735 defer dh.mutexReconcilingFlag.RUnlock()
3736 return dh.reconciling != cNoReconciling
3737}
3738
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003739func (dh *deviceHandler) IsSkipOnuConfigReconciling() bool {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00003740 dh.mutexReconcilingFlag.RLock()
3741 defer dh.mutexReconcilingFlag.RUnlock()
3742 return dh.reconciling == cSkipOnuConfigReconciling
3743}
3744
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003745func (dh *deviceHandler) SetDeviceReason(value uint8) {
Holger Hildebrandtbe523842021-03-10 10:47:18 +00003746 dh.mutexDeviceReason.Lock()
3747 dh.deviceReason = value
3748 dh.mutexDeviceReason.Unlock()
3749}
3750
3751func (dh *deviceHandler) getDeviceReason() uint8 {
3752 dh.mutexDeviceReason.RLock()
3753 value := dh.deviceReason
3754 dh.mutexDeviceReason.RUnlock()
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +00003755 return value
3756}
Holger Hildebrandtbe523842021-03-10 10:47:18 +00003757
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003758func (dh *deviceHandler) GetDeviceReasonString() string {
3759 return cmn.DeviceReasonMap[dh.getDeviceReason()]
Holger Hildebrandtbe523842021-03-10 10:47:18 +00003760}
Holger Hildebrandtb4563ab2021-04-14 10:27:20 +00003761
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003762func (dh *deviceHandler) SetReadyForOmciConfig(flagValue bool) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003763 dh.mutexReadyForOmciConfig.Lock()
3764 dh.readyForOmciConfig = flagValue
3765 dh.mutexReadyForOmciConfig.Unlock()
3766}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003767func (dh *deviceHandler) IsReadyForOmciConfig() bool {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +00003768 dh.mutexReadyForOmciConfig.RLock()
3769 flagValue := dh.readyForOmciConfig
3770 dh.mutexReadyForOmciConfig.RUnlock()
3771 return flagValue
3772}
Maninder7961d722021-06-16 22:10:28 +05303773
3774func (dh *deviceHandler) deviceReconcileFailedUpdate(ctx context.Context, deviceReason uint8, connectStatus voltha.ConnectStatus_Types) {
3775 if err := dh.deviceReasonUpdate(ctx, deviceReason, true); err != nil {
3776 logger.Errorw(ctx, "unable to update device reason to core",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003777 log.Fields{"device-id": dh.DeviceID, "Err": err})
Maninder7961d722021-06-16 22:10:28 +05303778 }
3779
3780 logger.Debugw(ctx, "Core DeviceStateUpdate", log.Fields{"connectStatus": connectStatus, "operState": voltha.OperStatus_RECONCILING_FAILED})
khenaidoo7d3c5582021-08-11 18:09:44 -04003781 if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003782 DeviceId: dh.DeviceID,
khenaidoo7d3c5582021-08-11 18:09:44 -04003783 ConnStatus: connectStatus,
3784 OperStatus: voltha.OperStatus_RECONCILING_FAILED,
3785 }); err != nil {
Maninder7961d722021-06-16 22:10:28 +05303786 logger.Errorw(ctx, "unable to update device state to core",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003787 log.Fields{"device-id": dh.DeviceID, "Err": err})
Maninder7961d722021-06-16 22:10:28 +05303788 }
3789}
khenaidoo7d3c5582021-08-11 18:09:44 -04003790
3791/*
3792Helper functions to communicate with Core
3793*/
3794
3795func (dh *deviceHandler) getDeviceFromCore(ctx context.Context, deviceID string) (*voltha.Device, error) {
3796 cClient, err := dh.coreClient.GetCoreServiceClient()
3797 if err != nil || cClient == nil {
3798 return nil, err
3799 }
3800 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
3801 defer cancel()
3802 logger.Debugw(subCtx, "get-device-from-core", log.Fields{"device-id": deviceID})
3803 return cClient.GetDevice(subCtx, &vc.ID{Id: deviceID})
3804}
3805
3806func (dh *deviceHandler) updateDeviceStateInCore(ctx context.Context, deviceStateFilter *ic.DeviceStateFilter) error {
3807 cClient, err := dh.coreClient.GetCoreServiceClient()
3808 if err != nil || cClient == nil {
3809 return err
3810 }
3811 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
3812 defer cancel()
3813 _, err = cClient.DeviceStateUpdate(subCtx, deviceStateFilter)
3814 logger.Debugw(subCtx, "device-updated-in-core", log.Fields{"device-state": deviceStateFilter, "error": err})
3815 return err
3816}
3817
3818func (dh *deviceHandler) updatePMConfigInCore(ctx context.Context, pmConfigs *voltha.PmConfigs) error {
3819 cClient, err := dh.coreClient.GetCoreServiceClient()
3820 if err != nil || cClient == nil {
3821 return err
3822 }
3823 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
3824 defer cancel()
3825 _, err = cClient.DevicePMConfigUpdate(subCtx, pmConfigs)
3826 logger.Debugw(subCtx, "pmconfig-updated-in-core", log.Fields{"pm-configs": pmConfigs, "error": err})
3827 return err
3828}
3829
3830func (dh *deviceHandler) updateDeviceInCore(ctx context.Context, device *voltha.Device) error {
3831 cClient, err := dh.coreClient.GetCoreServiceClient()
3832 if err != nil || cClient == nil {
3833 return err
3834 }
3835 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
3836 defer cancel()
3837 _, err = cClient.DeviceUpdate(subCtx, device)
3838 logger.Debugw(subCtx, "device-updated-in-core", log.Fields{"device-id": device.Id, "error": err})
3839 return err
3840}
3841
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003842func (dh *deviceHandler) CreatePortInCore(ctx context.Context, port *voltha.Port) error {
khenaidoo7d3c5582021-08-11 18:09:44 -04003843 cClient, err := dh.coreClient.GetCoreServiceClient()
3844 if err != nil || cClient == nil {
3845 return err
3846 }
3847 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
3848 defer cancel()
3849 _, err = cClient.PortCreated(subCtx, port)
3850 logger.Debugw(subCtx, "port-created-in-core", log.Fields{"port": port, "error": err})
3851 return err
3852}
3853
3854func (dh *deviceHandler) updatePortStateInCore(ctx context.Context, portState *ic.PortState) error {
3855 cClient, err := dh.coreClient.GetCoreServiceClient()
3856 if err != nil || cClient == nil {
3857 return err
3858 }
3859 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
3860 defer cancel()
3861 _, err = cClient.PortStateUpdate(subCtx, portState)
3862 logger.Debugw(subCtx, "port-state-updated-in-core", log.Fields{"port-state": portState, "error": err})
3863 return err
3864}
3865
3866func (dh *deviceHandler) updateDeviceReasonInCore(ctx context.Context, reason *ic.DeviceReason) error {
3867 cClient, err := dh.coreClient.GetCoreServiceClient()
3868 if err != nil || cClient == nil {
3869 return err
3870 }
3871 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.RPCTimeout)
3872 defer cancel()
3873 _, err = cClient.DeviceReasonUpdate(subCtx, reason)
3874 logger.Debugw(subCtx, "device-reason-updated-in-core", log.Fields{"reason": reason, "error": err})
3875 return err
3876}
3877
3878/*
3879Helper functions to communicate with parent adapter
3880*/
3881
3882func (dh *deviceHandler) getTechProfileInstanceFromParentAdapter(ctx context.Context, parentEndpoint string,
3883 request *ic.TechProfileInstanceRequestMessage) (*ic.TechProfileDownloadMessage, error) {
3884 pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint)
3885 if err != nil || pgClient == nil {
3886 return nil, err
3887 }
3888 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm)
3889 defer cancel()
3890 logger.Debugw(subCtx, "get-tech-profile-instance", log.Fields{"request": request, "parent-endpoint": parentEndpoint})
3891 return pgClient.GetTechProfileInstance(subCtx, request)
3892}
3893
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003894func (dh *deviceHandler) SendOMCIRequest(ctx context.Context, parentEndpoint string, request *ic.OmciMessage) error {
khenaidoo7d3c5582021-08-11 18:09:44 -04003895 pgClient, err := dh.pOpenOnuAc.getParentAdapterServiceClient(parentEndpoint)
3896 if err != nil || pgClient == nil {
3897 return err
3898 }
3899 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), dh.config.MaxTimeoutInterAdapterComm)
3900 defer cancel()
3901 logger.Debugw(subCtx, "send-omci-request", log.Fields{"request": request, "parent-endpoint": parentEndpoint})
3902 _, err = pgClient.ProxyOmciRequest(subCtx, request)
3903 if err != nil {
3904 logger.Errorw(ctx, "omci-failure", log.Fields{"request": request, "error": err, "request-parent": request.ParentDeviceId, "request-child": request.ChildDeviceId, "request-proxy": request.ProxyAddress})
3905 }
3906 return err
3907}
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00003908
3909// GetDeviceID - TODO: add comment
3910func (dh *deviceHandler) GetDeviceID() string {
3911 return dh.DeviceID
3912}
3913
3914// GetProxyAddressID - TODO: add comment
3915func (dh *deviceHandler) GetProxyAddressID() string {
3916 return dh.device.ProxyAddress.GetDeviceId()
3917}
3918
3919// GetProxyAddressType - TODO: add comment
3920func (dh *deviceHandler) GetProxyAddressType() string {
3921 return dh.device.ProxyAddress.GetDeviceType()
3922}
3923
3924// GetProxyAddress - TODO: add comment
3925func (dh *deviceHandler) GetProxyAddress() *voltha.Device_ProxyAddress {
3926 return dh.device.ProxyAddress
3927}
3928
3929// GetEventProxy - TODO: add comment
3930func (dh *deviceHandler) GetEventProxy() eventif.EventProxy {
3931 return dh.EventProxy
3932}
3933
3934// GetOmciTimeout - TODO: add comment
3935func (dh *deviceHandler) GetOmciTimeout() int {
3936 return dh.pOpenOnuAc.omciTimeout
3937}
3938
3939// GetAlarmAuditInterval - TODO: add comment
3940func (dh *deviceHandler) GetAlarmAuditInterval() time.Duration {
3941 return dh.pOpenOnuAc.alarmAuditInterval
3942}
3943
3944// GetDlToOnuTimeout4M - TODO: add comment
3945func (dh *deviceHandler) GetDlToOnuTimeout4M() time.Duration {
3946 return dh.pOpenOnuAc.dlToOnuTimeout4M
3947}
3948
3949// GetUniEntityMap - TODO: add comment
3950func (dh *deviceHandler) GetUniEntityMap() *cmn.OnuUniPortMap {
3951 return &dh.uniEntityMap
3952}
3953
3954// GetPonPortNumber - TODO: add comment
3955func (dh *deviceHandler) GetPonPortNumber() *uint32 {
3956 return &dh.ponPortNumber
3957}
3958
3959// GetUniVlanConfigFsm - TODO: add comment
3960func (dh *deviceHandler) GetUniVlanConfigFsm(uniID uint8) cmn.IuniVlanConfigFsm {
3961 return dh.UniVlanConfigFsmMap[uniID]
3962}
3963
3964// GetOnuAlarmManager - TODO: add comment
3965func (dh *deviceHandler) GetOnuAlarmManager() cmn.IonuAlarmManager {
3966 return dh.pAlarmMgr
3967}
3968
3969// GetOnuMetricsManager - TODO: add comment
3970func (dh *deviceHandler) GetOnuMetricsManager() cmn.IonuMetricsManager {
3971 return dh.pOnuMetricsMgr
3972}
3973
3974// GetOnuTP - TODO: add comment
3975func (dh *deviceHandler) GetOnuTP() cmn.IonuUniTechProf {
3976 return dh.pOnuTP
3977}
3978
3979// GetBackendPathPrefix - TODO: add comment
3980func (dh *deviceHandler) GetBackendPathPrefix() string {
3981 return dh.pOpenOnuAc.cm.Backend.PathPrefix
3982}
3983
3984// GetOnuIndication - TODO: add comment
3985func (dh *deviceHandler) GetOnuIndication() *openolt.OnuIndication {
3986 return dh.pOnuIndication
3987}
3988
3989// RLockMutexDeletionInProgressFlag - TODO: add comment
3990func (dh *deviceHandler) RLockMutexDeletionInProgressFlag() {
3991 dh.mutexDeletionInProgressFlag.RLock()
3992}
3993
3994// RUnlockMutexDeletionInProgressFlag - TODO: add comment
3995func (dh *deviceHandler) RUnlockMutexDeletionInProgressFlag() {
3996 dh.mutexDeletionInProgressFlag.RUnlock()
3997}
3998
3999// GetDeletionInProgress - TODO: add comment
4000func (dh *deviceHandler) GetDeletionInProgress() bool {
4001 return dh.deletionInProgress
4002}
4003
4004// GetPmConfigs - TODO: add comment
4005func (dh *deviceHandler) GetPmConfigs() *voltha.PmConfigs {
4006 return dh.pmConfigs
4007}
4008
4009// GetDeviceType - TODO: add comment
4010func (dh *deviceHandler) GetDeviceType() string {
4011 return dh.DeviceType
4012}
4013
4014// GetLogicalDeviceID - TODO: add comment
4015func (dh *deviceHandler) GetLogicalDeviceID() string {
4016 return dh.logicalDeviceID
4017}
4018
4019// GetDevice - TODO: add comment
4020func (dh *deviceHandler) GetDevice() *voltha.Device {
4021 return dh.device
4022}
4023
4024// GetMetricsEnabled - TODO: add comment
4025func (dh *deviceHandler) GetMetricsEnabled() bool {
4026 return dh.pOpenOnuAc.MetricsEnabled
4027}
4028
4029// InitPmConfigs - TODO: add comment
4030func (dh *deviceHandler) InitPmConfigs() {
4031 dh.pmConfigs = &voltha.PmConfigs{}
4032}
4033
4034// GetUniPortMask - TODO: add comment
4035func (dh *deviceHandler) GetUniPortMask() int {
4036 return dh.pOpenOnuAc.config.UniPortMask
4037}