blob: 2a0a2c93a8a7189aae84a6423c9107e6437cbd87 [file] [log] [blame]
Holger Hildebrandtccd390c2020-05-29 13:49:04 +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 uniprt provides the utilities for uni port configuration
18package 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
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000034//LockStateFsm defines the structure for the state machine to lock/unlock the ONU UNI ports via OMCI
35type 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
74//NewLockStateFsm is the 'constructor' for the state machine to lock/unlock the ONU UNI ports via OMCI
75func 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
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000168//SetSuccessEvent modifies the requested event notified on success
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000169//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 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000376 logger.Errorw(ctx, "LockStateFsm - Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000377 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
378 return
379 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000380
mpagenkob06684f2021-03-23 14:39:04 +0000381 //should never appear, left here for robustness
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000382 oFsm.mutexPLastTxMeInstance.RLock()
Girish Gowdra3d5d6752021-03-22 19:21:24 -0700383 if oFsm.pLastTxMeInstance != nil {
384 // compare comments above for CreateResponse (apply also here ...)
385 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
386 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
387 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
388 // if, then something like:
389 //oFsm.pOnuDB.StoreMe(msgObj)
390
391 switch oFsm.pLastTxMeInstance.GetName() {
392 case "OnuG":
393 { // let the FSM proceed ...
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000394 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000395 _ = oFsm.PAdaptFsm.PFsm.Event(UniEvRxOnugResp)
Girish Gowdra3d5d6752021-03-22 19:21:24 -0700396 }
397 case "PhysicalPathTerminationPointEthernetUni", "VirtualEthernetInterfacePoint":
398 { // let the PPTP init proceed by stopping the wait function
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000399 oFsm.mutexPLastTxMeInstance.RUnlock()
Girish Gowdra3d5d6752021-03-22 19:21:24 -0700400 oFsm.omciLockResponseReceived <- true
401 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000402 default:
403 {
404 logger.Warnw(ctx, "Unsupported ME name received!",
405 log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID})
406 oFsm.mutexPLastTxMeInstance.RUnlock()
407 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000408 }
Girish Gowdra3d5d6752021-03-22 19:21:24 -0700409 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000410 oFsm.mutexPLastTxMeInstance.RUnlock()
Girish Gowdra3d5d6752021-03-22 19:21:24 -0700411 logger.Warnf(ctx, "LockStateFsm - Received SetResponse Data for %s with wrong classID or entityID ",
412 log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}, msgObj.EntityClass)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000413 }
Matteo Scandolob250bec2021-01-27 17:35:45 -0800414 } else {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000415 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenkob06684f2021-03-23 14:39:04 +0000416 logger.Errorw(ctx, "pLastTxMeInstance is nil", log.Fields{"device-id": oFsm.deviceID})
Girish Gowdra3d5d6752021-03-22 19:21:24 -0700417 return
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000418 }
419 } else {
mpagenkob06684f2021-03-23 14:39:04 +0000420 logger.Errorw(ctx, "LockStateFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000421 return
422 }
423}
424
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000425func (oFsm *LockStateFsm) performUniPortAdminSet(ctx context.Context) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000426 var omciAdminState uint8 = 1 //default locked
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000427 oFsm.mutexAdminState.RLock()
Himani Chawla4d908332020-08-31 12:30:20 +0530428 if !oFsm.adminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000429 omciAdminState = 0
430 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000431 oFsm.mutexAdminState.RUnlock()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +0000432 //set PPTPEthUni or VEIP AdminState
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +0000433 requestedAttributes := me.AttributeValueMap{me.PhysicalPathTerminationPointEthernetUni_AdministrativeState: omciAdminState}
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000434
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000435 for uniNo, uniPort := range *oFsm.pDeviceHandler.GetUniEntityMap() {
mpagenko8b5fdd22020-12-17 17:58:32 +0000436 // only unlock the UniPort in case it is defined for usage (R2.6 limit only one port),
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000437 // compare also limitation for logical voltha port in dh.EnableUniPortStateUpdate()
Matteo Scandolo20d180c2021-06-10 17:20:21 +0200438
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000439 if (omciAdminState == 1) || (1<<uniPort.UniID)&oFsm.pDeviceHandler.GetUniPortMask() == (1<<uniPort.UniID) {
mpagenko8b5fdd22020-12-17 17:58:32 +0000440 var meInstance *me.ManagedEntity
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000441 if uniPort.PortType == cmn.UniPPTP {
mpagenko8b5fdd22020-12-17 17:58:32 +0000442 logger.Debugw(ctx, "Setting PPTP admin state", log.Fields{
443 "device-id": oFsm.deviceID, "for PortNo": uniNo, "state (0-unlock)": omciAdminState})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000444 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000445 meInstance, err := oFsm.pOmciCC.SendSetPptpEthUniLS(log.WithSpanFromContext(context.TODO(), ctx),
446 uniPort.EntityID, oFsm.pDeviceHandler.GetOmciTimeout(),
447 true, requestedAttributes, oFsm.PAdaptFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300448 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000449 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300450 logger.Errorw(ctx, "SetPptpEthUniLS set failed, aborting LockStateFsm!",
451 log.Fields{"device-id": oFsm.deviceID})
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700452 //Indicate the failure in UnLock case
453 if omciAdminState == 0 {
454 oFsm.SetSuccessEvent(cmn.UniEnableStateFailed)
455 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000456 _ = oFsm.PAdaptFsm.PFsm.Event(UniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300457 return
458 }
mpagenko8b5fdd22020-12-17 17:58:32 +0000459 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000460 oFsm.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000461 } else if uniPort.PortType == cmn.UniVEIP {
mpagenko8b5fdd22020-12-17 17:58:32 +0000462 logger.Debugw(ctx, "Setting VEIP admin state", log.Fields{
463 "device-id": oFsm.deviceID, "for PortNo": uniNo, "state (0-unlock)": omciAdminState})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000464 oFsm.mutexPLastTxMeInstance.Lock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000465 meInstance, err := oFsm.pOmciCC.SendSetVeipLS(log.WithSpanFromContext(context.TODO(), ctx),
466 uniPort.EntityID, oFsm.pDeviceHandler.GetOmciTimeout(),
467 true, requestedAttributes, oFsm.PAdaptFsm.CommChan)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300468 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000469 oFsm.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300470 logger.Errorw(ctx, "SetVeipLS set failed, aborting LockStateFsm!",
471 log.Fields{"device-id": oFsm.deviceID})
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700472 //Indicate the failure in UnLock case
473 if omciAdminState == 0 {
474 oFsm.SetSuccessEvent(cmn.UniEnableStateFailed)
475 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000476 _ = oFsm.PAdaptFsm.PFsm.Event(UniEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300477 return
478 }
mpagenko8b5fdd22020-12-17 17:58:32 +0000479 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000480 oFsm.mutexPLastTxMeInstance.Unlock()
mpagenko8b5fdd22020-12-17 17:58:32 +0000481 } else {
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700482 //TODO: Discuss on the uni port type POTS .
mpagenko8b5fdd22020-12-17 17:58:32 +0000483 logger.Warnw(ctx, "Unsupported UniTP type - skip",
484 log.Fields{"device-id": oFsm.deviceID, "Port": uniNo})
485 continue
486 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000487 oFsm.mutexPLastTxMeInstance.RLock()
mpagenkob06684f2021-03-23 14:39:04 +0000488 if oFsm.pLastTxMeInstance == nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000489 oFsm.mutexPLastTxMeInstance.RUnlock()
mpagenkob06684f2021-03-23 14:39:04 +0000490 logger.Errorw(ctx, "could not send PortAdmin OMCI message from LockStateFsm", log.Fields{
491 "device-id": oFsm.deviceID, "Port": uniNo})
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700492 //Indicate the failure in UnLock case
493 if omciAdminState == 0 {
494 oFsm.SetSuccessEvent(cmn.UniEnableStateFailed)
495 }
mpagenkob06684f2021-03-23 14:39:04 +0000496 //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 +0000497 _ = oFsm.PAdaptFsm.PFsm.Event(UniEvReset)
mpagenkob06684f2021-03-23 14:39:04 +0000498 return
499 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000500 oFsm.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000501
mpagenko8b5fdd22020-12-17 17:58:32 +0000502 //verify response
503 err := oFsm.waitforOmciResponse(ctx, meInstance)
504 if err != nil {
505 logger.Errorw(ctx, "UniTP Admin State set failed, aborting LockState set!",
506 log.Fields{"device-id": oFsm.deviceID, "Port": uniNo})
Mahir Gunyel50ddea62021-10-22 11:26:42 -0700507 //Indicate the failure in UnLock case
508 if omciAdminState == 0 {
509 oFsm.SetSuccessEvent(cmn.UniEnableStateFailed)
510 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000511 _ = oFsm.PAdaptFsm.PFsm.Event(UniEvReset)
mpagenko8b5fdd22020-12-17 17:58:32 +0000512 return
513 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000514 }
515 } //for all UNI ports
516 // if Config has been done for all UNI related instances let the FSM proceed
517 // while we did not check here, if there is some port at all - !?
mpagenko8b5fdd22020-12-17 17:58:32 +0000518 logger.Infow(ctx, "UniTP adminState loop finished", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000519 _ = oFsm.PAdaptFsm.PFsm.Event(UniEvRxUnisResp)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000520}
521
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000522func (oFsm *LockStateFsm) waitforOmciResponse(ctx context.Context, apMeInstance *me.ManagedEntity) error {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000523 select {
Himani Chawla4d908332020-08-31 12:30:20 +0530524 // maybe be also some outside cancel (but no context modeled for the moment ...)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000525 // case <-ctx.Done():
dbainbri4d3a0dc2020-12-02 00:33:42 +0000526 // logger.Infow(ctx,"LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000527 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 +0000528 logger.Warnw(ctx, "lockStateFSM uni-set timeout", log.Fields{"for device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +0000529 return fmt.Errorf("lockStateFsm uni-set timeout for device-id %s", oFsm.deviceID)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000530 case success := <-oFsm.omciLockResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +0530531 if success {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000532 logger.Debug(ctx, "LockStateFSM uni-set response received")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000533 return nil
534 }
535 // should not happen so far
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000536 logger.Warnw(ctx, "lockStateFSM uni-set response error", log.Fields{"for device-id": oFsm.deviceID})
mpagenko01e726e2020-10-23 09:45:29 +0000537 return fmt.Errorf("lockStateFsm uni-set responseError for device-id %s", oFsm.deviceID)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000538 }
539}
Holger Hildebrandte7cc6092022-02-01 11:37:03 +0000540
541// PrepareForGarbageCollection - remove references to prepare for garbage collection
542func (oFsm *LockStateFsm) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
543 logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID})
544 oFsm.pDeviceHandler = nil
545 oFsm.pOnuDeviceEntry = nil
546 oFsm.pOmciCC = nil
547}