blob: 0461ac537d84a0f210ceb7d24f3b0b46fe94bc73 [file] [log] [blame]
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001/*
Joey Armstrong89c812c2024-01-12 19:00:20 -05002 * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00003 *
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
Joey Armstrong89c812c2024-01-12 19:00:20 -050017// Package uniprt provides the utilities for uni port configuration
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000018package uniprt
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000019
20import (
21 "context"
Andrea Campanella6515c582020-10-05 11:25:00 +020022 "fmt"
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000023 "sync"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000024 "time"
25
26 "github.com/looplab/fsm"
27
mpagenko836a1fd2021-11-01 16:12:42 +000028 "github.com/opencord/omci-lib-go/v2"
29 me "github.com/opencord/omci-lib-go/v2/generated"
khenaidoo7d3c5582021-08-11 18:09:44 -040030 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000031 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000032)
33
Joey Armstrong89c812c2024-01-12 19:00:20 -050034// LockStateFsm defines the structure for the state machine to lock/unlock the ONU UNI ports via OMCI
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000035type LockStateFsm struct {
mpagenko01e726e2020-10-23 09:45:29 +000036 deviceID string
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000037 pDeviceHandler cmn.IdeviceHandler
38 pOnuDeviceEntry cmn.IonuDeviceEntry
39 pOmciCC *cmn.OmciCC
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000040 mutexAdminState sync.RWMutex
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000041 adminState bool
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000042 requestEvent cmn.OnuDeviceEvent
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000043 omciLockResponseReceived chan bool //seperate channel needed for checking UNI port OMCi message responses
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000044 PAdaptFsm *cmn.AdapterFsm
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000045 mutexPLastTxMeInstance sync.RWMutex
mpagenko01e726e2020-10-23 09:45:29 +000046 pLastTxMeInstance *me.ManagedEntity
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000047}
48
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000049// events of lock/unlock UNI port FSM
mpagenko1cc3cb42020-07-27 15:24:38 +000050const (
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000051 UniEvStart = "UniEvStart"
52 UniEvStartAdmin = "UniEvStartAdmin"
53 UniEvRxUnisResp = "UniEvRxUnisResp"
54 UniEvRxOnugResp = "UniEvRxOnugResp"
55 UniEvTimeoutSimple = "UniEvTimeoutSimple"
56 UniEvTimeoutUnis = "UniEvTimeoutUnis"
57 UniEvReset = "UniEvReset"
58 UniEvRestart = "UniEvRestart"
mpagenko1cc3cb42020-07-27 15:24:38 +000059)
mpagenko1cc3cb42020-07-27 15:24:38 +000060
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000061// states of lock/unlock UNI port FSM
62const (
63 UniStDisabled = "UniStDisabled"
64 UniStStarting = "UniStStarting"
65 UniStSettingUnis = "UniStSettingUnis"
66 UniStSettingOnuG = "UniStSettingOnuG"
67 UniStAdminDone = "UniStAdminDone"
68 UniStResetting = "UniStResetting"
69)
70
71// CUniFsmIdleState - TODO: add comment
72const CUniFsmIdleState = UniStDisabled
73
Joey Armstrong89c812c2024-01-12 19:00:20 -050074// NewLockStateFsm is the 'constructor' for the state machine to lock/unlock the ONU UNI ports via OMCI
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000075func NewLockStateFsm(ctx context.Context, aAdminState bool, aRequestEvent cmn.OnuDeviceEvent,
76 aName string, apDeviceHandler cmn.IdeviceHandler, apOnuDeviceEntry cmn.IonuDeviceEntry, aCommChannel chan cmn.Message) *LockStateFsm {
77 instFsm := &LockStateFsm{
78 deviceID: apDeviceHandler.GetDeviceID(),
79 pDeviceHandler: apDeviceHandler,
80 pOnuDeviceEntry: apOnuDeviceEntry,
81 pOmciCC: apOnuDeviceEntry.GetDevOmciCC(),
82 adminState: aAdminState,
83 requestEvent: aRequestEvent,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000084 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000085 instFsm.PAdaptFsm = cmn.NewAdapterFsm(aName, instFsm.deviceID, aCommChannel)
86 if instFsm.PAdaptFsm == nil {
87 logger.Errorw(ctx, "LockStateFsm's cmn.AdapterFsm could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +000088 "device-id": instFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000089 return nil
90 }
Himani Chawla4d908332020-08-31 12:30:20 +053091 if aAdminState { //port locking requested
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000092 instFsm.PAdaptFsm.PFsm = fsm.NewFSM(
93 UniStDisabled,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000094 fsm.Events{
95
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000096 {Name: UniEvStart, Src: []string{UniStDisabled}, Dst: UniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000097
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000098 {Name: UniEvStartAdmin, Src: []string{UniStStarting}, Dst: UniStSettingUnis},
mpagenko1cc3cb42020-07-27 15:24:38 +000099 // the settingUnis state is used for multi ME config for all UNI related ports
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000100 // maybe such could be reflected in the state machine as well (port number parametrized)
101 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000102 {Name: UniEvRxUnisResp, Src: []string{UniStSettingUnis}, Dst: UniStSettingOnuG},
103 {Name: UniEvRxOnugResp, Src: []string{UniStSettingOnuG}, Dst: UniStAdminDone},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000104
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000105 {Name: UniEvTimeoutSimple, Src: []string{UniStSettingOnuG}, Dst: UniStStarting},
106 {Name: UniEvTimeoutUnis, Src: []string{UniStSettingUnis}, Dst: UniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000107
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000108 {Name: UniEvReset, Src: []string{UniStStarting, UniStSettingOnuG, UniStSettingUnis,
109 UniStAdminDone}, Dst: UniStResetting},
110 // exceptional treatment for all states except UniStResetting
111 {Name: UniEvRestart, Src: []string{UniStStarting, UniStSettingOnuG, UniStSettingUnis,
112 UniStAdminDone, UniStResetting}, Dst: UniStDisabled},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000113 },
114
115 fsm.Callbacks{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000116 "enter_state": func(e *fsm.Event) { instFsm.PAdaptFsm.LogFsmStateChange(ctx, e) },
117 ("enter_" + UniStStarting): func(e *fsm.Event) { instFsm.enterAdminStartingState(ctx, e) },
118 ("enter_" + UniStSettingOnuG): func(e *fsm.Event) { instFsm.enterSettingOnuGState(ctx, e) },
119 ("enter_" + UniStSettingUnis): func(e *fsm.Event) { instFsm.enterSettingUnisState(ctx, e) },
120 ("enter_" + UniStAdminDone): func(e *fsm.Event) { instFsm.enterAdminDoneState(ctx, e) },
121 ("enter_" + UniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(ctx, e) },
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000122 },
123 )
124 } else { //port unlocking requested
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000125 instFsm.PAdaptFsm.PFsm = fsm.NewFSM(
126 UniStDisabled,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000127 fsm.Events{
128
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000129 {Name: UniEvStart, Src: []string{UniStDisabled}, Dst: UniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000130
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000131 {Name: UniEvStartAdmin, Src: []string{UniStStarting}, Dst: UniStSettingOnuG},
132 {Name: UniEvRxOnugResp, Src: []string{UniStSettingOnuG}, Dst: UniStSettingUnis},
mpagenko1cc3cb42020-07-27 15:24:38 +0000133 // the settingUnis state is used for multi ME config for all UNI related ports
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000134 // maybe such could be reflected in the state machine as well (port number parametrized)
135 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000136 {Name: UniEvRxUnisResp, Src: []string{UniStSettingUnis}, Dst: UniStAdminDone},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000137
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000138 {Name: UniEvTimeoutSimple, Src: []string{UniStSettingOnuG}, Dst: UniStStarting},
139 {Name: UniEvTimeoutUnis, Src: []string{UniStSettingUnis}, Dst: UniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000140
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000141 {Name: UniEvReset, Src: []string{UniStStarting, UniStSettingOnuG, UniStSettingUnis,
142 UniStAdminDone}, Dst: UniStResetting},
143 // exceptional treatment for all states except UniStResetting
144 {Name: UniEvRestart, Src: []string{UniStStarting, UniStSettingOnuG, UniStSettingUnis,
145 UniStAdminDone, UniStResetting}, Dst: UniStDisabled},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000146 },
147
148 fsm.Callbacks{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000149 "enter_state": func(e *fsm.Event) { instFsm.PAdaptFsm.LogFsmStateChange(ctx, e) },
150 ("enter_" + UniStStarting): func(e *fsm.Event) { instFsm.enterAdminStartingState(ctx, e) },
151 ("enter_" + UniStSettingOnuG): func(e *fsm.Event) { instFsm.enterSettingOnuGState(ctx, e) },
152 ("enter_" + UniStSettingUnis): func(e *fsm.Event) { instFsm.enterSettingUnisState(ctx, e) },
153 ("enter_" + UniStAdminDone): func(e *fsm.Event) { instFsm.enterAdminDoneState(ctx, e) },
154 ("enter_" + UniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(ctx, e) },
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000155 },
156 )
157 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000158 if instFsm.PAdaptFsm.PFsm == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000159 logger.Errorw(ctx, "LockStateFsm's Base FSM could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000160 "device-id": instFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000161 return nil
162 }
163
dbainbri4d3a0dc2020-12-02 00:33:42 +0000164 logger.Debugw(ctx, "LockStateFsm created", log.Fields{"device-id": instFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000165 return instFsm
166}
167
Joey Armstrong89c812c2024-01-12 19:00:20 -0500168// SetSuccessEvent modifies the requested event notified on success
169// assumption is that this is only called in the disabled (idle) state of the FSM, hence no sem protection required
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000170func (oFsm *LockStateFsm) SetSuccessEvent(aEvent cmn.OnuDeviceEvent) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000171 oFsm.requestEvent = aEvent
172}
173
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000174func (oFsm *LockStateFsm) enterAdminStartingState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000175 logger.Debugw(ctx, "LockStateFSM start", log.Fields{"in state": e.FSM.Current(),
mpagenko01e726e2020-10-23 09:45:29 +0000176 "device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000177 // in case the used channel is not yet defined (can be re-used after restarts)
178 if oFsm.omciLockResponseReceived == nil {
179 oFsm.omciLockResponseReceived = make(chan bool)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000180 logger.Debug(ctx, "LockStateFSM - OMCI UniLock RxChannel defined")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000181 } else {
182 // as we may 're-use' this instance of FSM and the connected channel
mpagenkob06684f2021-03-23 14:39:04 +0000183 // make sure there is no 'lingering' request in the already existing channels:
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000184 // (simple loop sufficient as we are the only receiver)
185 for len(oFsm.omciLockResponseReceived) > 0 {
186 <-oFsm.omciLockResponseReceived
187 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000188 for len(oFsm.PAdaptFsm.CommChan) > 0 {
189 <-oFsm.PAdaptFsm.CommChan
mpagenkob06684f2021-03-23 14:39:04 +0000190 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000191 }
192 // start go routine for processing of LockState messages
dbainbri4d3a0dc2020-12-02 00:33:42 +0000193 go oFsm.processOmciLockMessages(ctx)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000194
195 //let the state machine run forward from here directly
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000196 pLockStateAFsm := oFsm.PAdaptFsm
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000197 if pLockStateAFsm != nil {
198 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000199 go func(a_pAFsm *cmn.AdapterFsm) {
200 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
201 _ = a_pAFsm.PFsm.Event(UniEvStartAdmin)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000202 }
203 }(pLockStateAFsm)
204 }
205}
206
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000207func (oFsm *LockStateFsm) enterSettingOnuGState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000208 var omciAdminState uint8 = 1 //default locked
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000209 oFsm.mutexAdminState.RLock()
Himani Chawla4d908332020-08-31 12:30:20 +0530210 if !oFsm.adminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000211 omciAdminState = 0
212 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000213 oFsm.mutexAdminState.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000214 logger.Debugw(ctx, "LockStateFSM Tx Set::ONU-G:admin", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000215 "omciAdmin": omciAdminState, "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000216 requestedAttributes := me.AttributeValueMap{me.OnuG_AdministrativeState: omciAdminState}
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000217 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000218 meInstance, err := oFsm.pOmciCC.SendSetOnuGLS(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true,
219 requestedAttributes, oFsm.PAdaptFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300220 if err != nil {
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700221 //Indicate the failure in UnLock case
222 if omciAdminState == 0 {
223 oFsm.SetSuccessEvent(cmn.UniEnableStateFailed)
224 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000225 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300226 logger.Errorw(ctx, "OnuGLS set failed, aborting LockStateFSM", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000227 pLockStateAFsm := oFsm.PAdaptFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +0300228 if pLockStateAFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000229 go func(a_pAFsm *cmn.AdapterFsm) {
230 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
231 _ = a_pAFsm.PFsm.Event(UniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300232 }
233 }(pLockStateAFsm)
234 }
235 return
236 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000237 //accept also nil as (error) return value for writing to LastTx
238 // - this avoids misinterpretation of new received OMCI messages
mpagenko01e726e2020-10-23 09:45:29 +0000239 oFsm.pLastTxMeInstance = meInstance
mpagenkob06684f2021-03-23 14:39:04 +0000240 if oFsm.pLastTxMeInstance == nil {
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700241 //Indicate the failure in UnLock case
242 if omciAdminState == 0 {
243 oFsm.SetSuccessEvent(cmn.UniEnableStateFailed)
244 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000245 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenkob06684f2021-03-23 14:39:04 +0000246 logger.Errorw(ctx, "could not send OMCI message from LockStateFsm", log.Fields{
247 "device-id": oFsm.deviceID})
248 //some more sophisticated approach is possible, e.g. repeating once, by now let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000249 pLockStateAFsm := oFsm.PAdaptFsm
mpagenkob06684f2021-03-23 14:39:04 +0000250 if pLockStateAFsm != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000251
mpagenkob06684f2021-03-23 14:39:04 +0000252 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000253 go func(a_pAFsm *cmn.AdapterFsm) {
254 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
255 _ = a_pAFsm.PFsm.Event(UniEvReset)
mpagenkob06684f2021-03-23 14:39:04 +0000256 }
257 }(pLockStateAFsm)
258 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000259 return
mpagenkob06684f2021-03-23 14:39:04 +0000260 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000261 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000262}
263
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000264func (oFsm *LockStateFsm) enterSettingUnisState(ctx context.Context, e *fsm.Event) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000265 oFsm.mutexAdminState.RLock()
mpagenko8b5fdd22020-12-17 17:58:32 +0000266 logger.Debugw(ctx, "LockStateFSM - starting UniTP adminState loop", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000267 "in state": e.FSM.Current(), "device-id": oFsm.deviceID, "LockState": oFsm.adminState})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000268 oFsm.mutexAdminState.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000269 go oFsm.performUniPortAdminSet(ctx)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000270}
271
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000272func (oFsm *LockStateFsm) enterAdminDoneState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000273 logger.Debugw(ctx, "LockStateFSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000274 //use DeviceHandler event notification directly, no need/support to update DeviceEntryState for lock/unlock
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000275 oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, oFsm.requestEvent)
Holger Hildebrandt8165eda2020-09-24 09:39:24 +0000276
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000277 //let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000278 pLockStateAFsm := oFsm.PAdaptFsm
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000279 if pLockStateAFsm != nil {
280 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000281 go func(a_pAFsm *cmn.AdapterFsm) {
282 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
283 _ = a_pAFsm.PFsm.Event(UniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000284 }
285 }(pLockStateAFsm)
286 }
287}
288
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000289func (oFsm *LockStateFsm) enterResettingState(ctx context.Context, e *fsm.Event) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000290 logger.Debugw(ctx, "LockStateFSM resetting", log.Fields{"device-id": oFsm.deviceID})
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700291 //If the fsm is reseted because of a failure during reenable, then issue the fail event.
292 if oFsm.requestEvent == cmn.UniEnableStateFailed {
293 logger.Debugw(ctx, "LockStateFSM send notification to core", log.Fields{"state": e.FSM.Current(), "device-id": oFsm.deviceID})
294 //use DeviceHandler event notification directly, no need/support to update DeviceEntryState for lock/unlock
295 oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, oFsm.requestEvent)
296 }
297
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000298 pLockStateAFsm := oFsm.PAdaptFsm
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000299 if pLockStateAFsm != nil {
300 // abort running message processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000301 fsmAbortMsg := cmn.Message{
302 Type: cmn.TestMsg,
303 Data: cmn.TestMessage{
304 TestMessageVal: cmn.AbortMessageProcessing,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000305 },
306 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000307 pLockStateAFsm.CommChan <- fsmAbortMsg
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000308
309 //try to restart the FSM to 'disabled'
310 // see DownloadedState: decouple event transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000311 go func(a_pAFsm *cmn.AdapterFsm) {
312 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
313 _ = a_pAFsm.PFsm.Event(UniEvRestart)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000314 }
315 }(pLockStateAFsm)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000316 oFsm.mutexPLastTxMeInstance.Lock()
mpagenko01e726e2020-10-23 09:45:29 +0000317 oFsm.pLastTxMeInstance = nil
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000318 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000319 }
320}
321
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000322func (oFsm *LockStateFsm) processOmciLockMessages(ctx context.Context) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000323 logger.Debugw(ctx, "Start LockStateFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000324loop:
325 for {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000326 // case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000327 // logger.Info(ctx,"MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000328 // break loop
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000329 message, ok := <-oFsm.PAdaptFsm.CommChan
Himani Chawla4d908332020-08-31 12:30:20 +0530330 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000331 logger.Info(ctx, "LockStateFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530332 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000333 _ = oFsm.PAdaptFsm.PFsm.Event(UniEvRestart)
Himani Chawla4d908332020-08-31 12:30:20 +0530334 break loop
335 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000336 logger.Debugw(ctx, "LockStateFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530337
338 switch message.Type {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000339 case cmn.TestMsg:
340 msg, _ := message.Data.(cmn.TestMessage)
341 if msg.TestMessageVal == cmn.AbortMessageProcessing {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000342 logger.Debugw(ctx, "LockStateFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000343 break loop
344 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000345 logger.Warnw(ctx, "LockStateFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000346 case cmn.OMCI:
347 msg, _ := message.Data.(cmn.OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000348 oFsm.handleOmciLockStateMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530349 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000350 logger.Warn(ctx, "LockStateFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID,
Himani Chawla4d908332020-08-31 12:30:20 +0530351 "message.Type": message.Type})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000352 }
353 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000354 logger.Debugw(ctx, "End LockStateFsm Msg processing", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000355}
356
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000357func (oFsm *LockStateFsm) handleOmciLockStateMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000358 logger.Debugw(ctx, "Rx OMCI LockStateFsm Msg", log.Fields{"device-id": oFsm.deviceID,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000359 "msgType": msg.OmciMsg.MessageType})
360
361 if msg.OmciMsg.MessageType == omci.SetResponseType {
362 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
363 if msgLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000364 logger.Errorw(ctx, "LockStateFsm - Omci Msg layer could not be detected for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +0000365 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000366 return
367 }
368 msgObj, msgOk := msgLayer.(*omci.SetResponse)
369 if !msgOk {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000370 logger.Errorw(ctx, "LockStateFsm - Omci Msg layer could not be assigned for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +0000371 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000372 return
373 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000374 logger.Debugw(ctx, "LockStateFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000375 if msgObj.Result != me.Success {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000376 logger.Errorw(ctx, "LockStateFsm - Omci SetResponse Error - later: drive FSM to abort state ?",
377 log.Fields{"Error": msgObj.Result, "EntityClass": msgObj.EntityClass, "EntityInstance": msgObj.EntityInstance, "device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000378 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
379 return
380 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000381
mpagenkob06684f2021-03-23 14:39:04 +0000382 //should never appear, left here for robustness
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000383 oFsm.mutexPLastTxMeInstance.RLock()
Girish Gowdra3d5d6752021-03-22 19:21:24 -0700384 if oFsm.pLastTxMeInstance != nil {
385 // compare comments above for CreateResponse (apply also here ...)
386 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
387 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
388 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
389 // if, then something like:
390 //oFsm.pOnuDB.StoreMe(msgObj)
391
392 switch oFsm.pLastTxMeInstance.GetName() {
393 case "OnuG":
394 { // let the FSM proceed ...
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000395 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000396 _ = oFsm.PAdaptFsm.PFsm.Event(UniEvRxOnugResp)
Girish Gowdra3d5d6752021-03-22 19:21:24 -0700397 }
398 case "PhysicalPathTerminationPointEthernetUni", "VirtualEthernetInterfacePoint":
399 { // let the PPTP init proceed by stopping the wait function
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000400 oFsm.mutexPLastTxMeInstance.RUnlock()
Girish Gowdra3d5d6752021-03-22 19:21:24 -0700401 oFsm.omciLockResponseReceived <- true
402 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000403 default:
404 {
405 logger.Warnw(ctx, "Unsupported ME name received!",
406 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
407 oFsm.mutexPLastTxMeInstance.RUnlock()
408 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000409 }
Girish Gowdra3d5d6752021-03-22 19:21:24 -0700410 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000411 oFsm.mutexPLastTxMeInstance.RUnlock()
Girish Gowdra3d5d6752021-03-22 19:21:24 -0700412 logger.Warnf(ctx, "LockStateFsm - Received SetResponse Data for %s with wrong classID or entityID ",
413 log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000414 }
Matteo Scandolob250bec2021-01-27 17:35:45 -0800415 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000416 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenkob06684f2021-03-23 14:39:04 +0000417 logger.Errorw(ctx, "pLastTxMeInstance is nil", log.Fields{"device-id": oFsm.deviceID})
Girish Gowdra3d5d6752021-03-22 19:21:24 -0700418 return
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000419 }
420 } else {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000421 logger.Errorw(ctx, "LockStateFsm - Rx OMCI unhandled MsgType", log.Fields{"device-id": oFsm.deviceID, "omciMsgType": msg.OmciMsg.MessageType})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000422 return
423 }
424}
425
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000426func (oFsm *LockStateFsm) performUniPortAdminSet(ctx context.Context) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000427 var omciAdminState uint8 = 1 //default locked
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000428 oFsm.mutexAdminState.RLock()
Himani Chawla4d908332020-08-31 12:30:20 +0530429 if !oFsm.adminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000430 omciAdminState = 0
431 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000432 oFsm.mutexAdminState.RUnlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000433 //set PPTPEthUni or VEIP AdminState
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000434 requestedAttributes := me.AttributeValueMap{me.PhysicalPathTerminationPointEthernetUni_AdministrativeState: omciAdminState}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000435
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000436 for uniNo, uniPort := range *oFsm.pDeviceHandler.GetUniEntityMap() {
mpagenko8b5fdd22020-12-17 17:58:32 +0000437 // only unlock the UniPort in case it is defined for usage (R2.6 limit only one port),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000438 // compare also limitation for logical voltha port in dh.EnableUniPortStateUpdate()
Matteo Scandolo20d180c2021-06-10 17:20:21 +0200439
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000440 if (omciAdminState == 1) || (1<<uniPort.UniID)&oFsm.pDeviceHandler.GetUniPortMask() == (1<<uniPort.UniID) {
mpagenko8b5fdd22020-12-17 17:58:32 +0000441 var meInstance *me.ManagedEntity
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000442 if uniPort.PortType == cmn.UniPPTP {
mpagenko8b5fdd22020-12-17 17:58:32 +0000443 logger.Debugw(ctx, "Setting PPTP admin state", log.Fields{
444 "device-id": oFsm.deviceID, "for PortNo": uniNo, "state (0-unlock)": omciAdminState})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000445 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000446 meInstance, err := oFsm.pOmciCC.SendSetPptpEthUniLS(log.WithSpanFromContext(context.TODO(), ctx),
447 uniPort.EntityID, oFsm.pDeviceHandler.GetOmciTimeout(),
448 true, requestedAttributes, oFsm.PAdaptFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300449 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000450 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300451 logger.Errorw(ctx, "SetPptpEthUniLS set failed, aborting LockStateFsm!",
452 log.Fields{"device-id": oFsm.deviceID})
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700453 //Indicate the failure in UnLock case
454 if omciAdminState == 0 {
455 oFsm.SetSuccessEvent(cmn.UniEnableStateFailed)
456 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000457 _ = oFsm.PAdaptFsm.PFsm.Event(UniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300458 return
459 }
mpagenko8b5fdd22020-12-17 17:58:32 +0000460 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000461 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000462 } else if uniPort.PortType == cmn.UniVEIP {
mpagenko8b5fdd22020-12-17 17:58:32 +0000463 logger.Debugw(ctx, "Setting VEIP admin state", log.Fields{
464 "device-id": oFsm.deviceID, "for PortNo": uniNo, "state (0-unlock)": omciAdminState})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000465 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000466 meInstance, err := oFsm.pOmciCC.SendSetVeipLS(log.WithSpanFromContext(context.TODO(), ctx),
467 uniPort.EntityID, oFsm.pDeviceHandler.GetOmciTimeout(),
468 true, requestedAttributes, oFsm.PAdaptFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300469 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000470 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300471 logger.Errorw(ctx, "SetVeipLS set failed, aborting LockStateFsm!",
472 log.Fields{"device-id": oFsm.deviceID})
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700473 //Indicate the failure in UnLock case
474 if omciAdminState == 0 {
475 oFsm.SetSuccessEvent(cmn.UniEnableStateFailed)
476 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000477 _ = oFsm.PAdaptFsm.PFsm.Event(UniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300478 return
479 }
mpagenko8b5fdd22020-12-17 17:58:32 +0000480 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000481 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko8b5fdd22020-12-17 17:58:32 +0000482 } else {
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700483 //TODO: Discuss on the uni port type POTS .
mpagenko8b5fdd22020-12-17 17:58:32 +0000484 logger.Warnw(ctx, "Unsupported UniTP type - skip",
485 log.Fields{"device-id": oFsm.deviceID, "Port": uniNo})
486 continue
487 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000488 oFsm.mutexPLastTxMeInstance.RLock()
mpagenkob06684f2021-03-23 14:39:04 +0000489 if oFsm.pLastTxMeInstance == nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000490 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenkob06684f2021-03-23 14:39:04 +0000491 logger.Errorw(ctx, "could not send PortAdmin OMCI message from LockStateFsm", log.Fields{
492 "device-id": oFsm.deviceID, "Port": uniNo})
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700493 //Indicate the failure in UnLock case
494 if omciAdminState == 0 {
495 oFsm.SetSuccessEvent(cmn.UniEnableStateFailed)
496 }
mpagenkob06684f2021-03-23 14:39:04 +0000497 //some more sophisticated approach is possible, e.g. repeating once, by now let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000498 _ = oFsm.PAdaptFsm.PFsm.Event(UniEvReset)
mpagenkob06684f2021-03-23 14:39:04 +0000499 return
500 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000501 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000502
mpagenko8b5fdd22020-12-17 17:58:32 +0000503 //verify response
504 err := oFsm.waitforOmciResponse(ctx, meInstance)
505 if err != nil {
506 logger.Errorw(ctx, "UniTP Admin State set failed, aborting LockState set!",
507 log.Fields{"device-id": oFsm.deviceID, "Port": uniNo})
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700508 //Indicate the failure in UnLock case
509 if omciAdminState == 0 {
510 oFsm.SetSuccessEvent(cmn.UniEnableStateFailed)
511 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000512 _ = oFsm.PAdaptFsm.PFsm.Event(UniEvReset)
mpagenko8b5fdd22020-12-17 17:58:32 +0000513 return
514 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000515 }
516 } //for all UNI ports
517 // if Config has been done for all UNI related instances let the FSM proceed
518 // while we did not check here, if there is some port at all - !?
mpagenko8b5fdd22020-12-17 17:58:32 +0000519 logger.Infow(ctx, "UniTP adminState loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000520 _ = oFsm.PAdaptFsm.PFsm.Event(UniEvRxUnisResp)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000521}
522
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000523func (oFsm *LockStateFsm) waitforOmciResponse(ctx context.Context, apMeInstance *me.ManagedEntity) error {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000524 select {
Himani Chawla4d908332020-08-31 12:30:20 +0530525 // maybe be also some outside cancel (but no context modeled for the moment ...)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000526 // case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000527 // logger.Infow(ctx,"LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000528 case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000529 logger.Warnw(ctx, "lockStateFSM uni-set timeout", log.Fields{"for device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +0000530 return fmt.Errorf("lockStateFsm uni-set timeout for device-id %s", oFsm.deviceID)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000531 case success := <-oFsm.omciLockResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +0530532 if success {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000533 logger.Debug(ctx, "LockStateFSM uni-set response received")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000534 return nil
535 }
536 // should not happen so far
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000537 logger.Warnw(ctx, "lockStateFSM uni-set response error", log.Fields{"for device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +0000538 return fmt.Errorf("lockStateFsm uni-set responseError for device-id %s", oFsm.deviceID)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000539 }
540}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000541
542// PrepareForGarbageCollection - remove references to prepare for garbage collection
543func (oFsm *LockStateFsm) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
544 logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID})
545 oFsm.pDeviceHandler = nil
546 oFsm.pOnuDeviceEntry = nil
547 oFsm.pOmciCC = nil
548}