Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1 | /* |
Joey Armstrong | e8c091f | 2023-01-17 16:56:26 -0500 | [diff] [blame] | 2 | * Copyright 2020-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 17 | //Package uniprt provides the utilities for uni port configuration |
| 18 | package uniprt |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 22 | "fmt" |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 23 | "sync" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 24 | "time" |
| 25 | |
| 26 | "github.com/looplab/fsm" |
| 27 | |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 28 | "github.com/opencord/omci-lib-go/v2" |
| 29 | me "github.com/opencord/omci-lib-go/v2/generated" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 30 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 31 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 32 | ) |
| 33 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 34 | //LockStateFsm defines the structure for the state machine to lock/unlock the ONU UNI ports via OMCI |
| 35 | type LockStateFsm struct { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 36 | deviceID string |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 37 | pDeviceHandler cmn.IdeviceHandler |
| 38 | pOnuDeviceEntry cmn.IonuDeviceEntry |
| 39 | pOmciCC *cmn.OmciCC |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 40 | mutexAdminState sync.RWMutex |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 41 | adminState bool |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 42 | requestEvent cmn.OnuDeviceEvent |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 43 | omciLockResponseReceived chan bool //seperate channel needed for checking UNI port OMCi message responses |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 44 | PAdaptFsm *cmn.AdapterFsm |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 45 | mutexPLastTxMeInstance sync.RWMutex |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 46 | pLastTxMeInstance *me.ManagedEntity |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 49 | // events of lock/unlock UNI port FSM |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 50 | const ( |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 51 | UniEvStart = "UniEvStart" |
| 52 | UniEvStartAdmin = "UniEvStartAdmin" |
| 53 | UniEvRxUnisResp = "UniEvRxUnisResp" |
| 54 | UniEvRxOnugResp = "UniEvRxOnugResp" |
| 55 | UniEvTimeoutSimple = "UniEvTimeoutSimple" |
| 56 | UniEvTimeoutUnis = "UniEvTimeoutUnis" |
| 57 | UniEvReset = "UniEvReset" |
| 58 | UniEvRestart = "UniEvRestart" |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 59 | ) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 60 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 61 | // states of lock/unlock UNI port FSM |
| 62 | const ( |
| 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 |
| 72 | const CUniFsmIdleState = UniStDisabled |
| 73 | |
| 74 | //NewLockStateFsm is the 'constructor' for the state machine to lock/unlock the ONU UNI ports via OMCI |
| 75 | func 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 Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 84 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 85 | 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{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 88 | "device-id": instFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 89 | return nil |
| 90 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 91 | if aAdminState { //port locking requested |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 92 | instFsm.PAdaptFsm.PFsm = fsm.NewFSM( |
| 93 | UniStDisabled, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 94 | fsm.Events{ |
| 95 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 96 | {Name: UniEvStart, Src: []string{UniStDisabled}, Dst: UniStStarting}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 97 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 98 | {Name: UniEvStartAdmin, Src: []string{UniStStarting}, Dst: UniStSettingUnis}, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 99 | // the settingUnis state is used for multi ME config for all UNI related ports |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 100 | // 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 Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 102 | {Name: UniEvRxUnisResp, Src: []string{UniStSettingUnis}, Dst: UniStSettingOnuG}, |
| 103 | {Name: UniEvRxOnugResp, Src: []string{UniStSettingOnuG}, Dst: UniStAdminDone}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 104 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 105 | {Name: UniEvTimeoutSimple, Src: []string{UniStSettingOnuG}, Dst: UniStStarting}, |
| 106 | {Name: UniEvTimeoutUnis, Src: []string{UniStSettingUnis}, Dst: UniStStarting}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 107 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 108 | {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 Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 113 | }, |
| 114 | |
| 115 | fsm.Callbacks{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 116 | "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 Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 122 | }, |
| 123 | ) |
| 124 | } else { //port unlocking requested |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 125 | instFsm.PAdaptFsm.PFsm = fsm.NewFSM( |
| 126 | UniStDisabled, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 127 | fsm.Events{ |
| 128 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 129 | {Name: UniEvStart, Src: []string{UniStDisabled}, Dst: UniStStarting}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 130 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 131 | {Name: UniEvStartAdmin, Src: []string{UniStStarting}, Dst: UniStSettingOnuG}, |
| 132 | {Name: UniEvRxOnugResp, Src: []string{UniStSettingOnuG}, Dst: UniStSettingUnis}, |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 133 | // the settingUnis state is used for multi ME config for all UNI related ports |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 134 | // 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 Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 136 | {Name: UniEvRxUnisResp, Src: []string{UniStSettingUnis}, Dst: UniStAdminDone}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 137 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 138 | {Name: UniEvTimeoutSimple, Src: []string{UniStSettingOnuG}, Dst: UniStStarting}, |
| 139 | {Name: UniEvTimeoutUnis, Src: []string{UniStSettingUnis}, Dst: UniStStarting}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 140 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 141 | {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 Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 146 | }, |
| 147 | |
| 148 | fsm.Callbacks{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 149 | "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 Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 155 | }, |
| 156 | ) |
| 157 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 158 | if instFsm.PAdaptFsm.PFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 159 | logger.Errorw(ctx, "LockStateFsm's Base FSM could not be instantiated!!", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 160 | "device-id": instFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 161 | return nil |
| 162 | } |
| 163 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 164 | logger.Debugw(ctx, "LockStateFsm created", log.Fields{"device-id": instFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 165 | return instFsm |
| 166 | } |
| 167 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 168 | //SetSuccessEvent modifies the requested event notified on success |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 169 | //assumption is that this is only called in the disabled (idle) state of the FSM, hence no sem protection required |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 170 | func (oFsm *LockStateFsm) SetSuccessEvent(aEvent cmn.OnuDeviceEvent) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 171 | oFsm.requestEvent = aEvent |
| 172 | } |
| 173 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 174 | func (oFsm *LockStateFsm) enterAdminStartingState(ctx context.Context, e *fsm.Event) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 175 | logger.Debugw(ctx, "LockStateFSM start", log.Fields{"in state": e.FSM.Current(), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 176 | "device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 177 | // 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) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 180 | logger.Debug(ctx, "LockStateFSM - OMCI UniLock RxChannel defined") |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 181 | } else { |
| 182 | // as we may 're-use' this instance of FSM and the connected channel |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 183 | // make sure there is no 'lingering' request in the already existing channels: |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 184 | // (simple loop sufficient as we are the only receiver) |
| 185 | for len(oFsm.omciLockResponseReceived) > 0 { |
| 186 | <-oFsm.omciLockResponseReceived |
| 187 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 188 | for len(oFsm.PAdaptFsm.CommChan) > 0 { |
| 189 | <-oFsm.PAdaptFsm.CommChan |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 190 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 191 | } |
| 192 | // start go routine for processing of LockState messages |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 193 | go oFsm.processOmciLockMessages(ctx) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 194 | |
| 195 | //let the state machine run forward from here directly |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 196 | pLockStateAFsm := oFsm.PAdaptFsm |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 197 | if pLockStateAFsm != nil { |
| 198 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 199 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 200 | if a_pAFsm != nil && a_pAFsm.PFsm != nil { |
| 201 | _ = a_pAFsm.PFsm.Event(UniEvStartAdmin) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 202 | } |
| 203 | }(pLockStateAFsm) |
| 204 | } |
| 205 | } |
| 206 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 207 | func (oFsm *LockStateFsm) enterSettingOnuGState(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 208 | var omciAdminState uint8 = 1 //default locked |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 209 | oFsm.mutexAdminState.RLock() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 210 | if !oFsm.adminState { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 211 | omciAdminState = 0 |
| 212 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 213 | oFsm.mutexAdminState.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 214 | logger.Debugw(ctx, "LockStateFSM Tx Set::ONU-G:admin", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 215 | "omciAdmin": omciAdminState, "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 216 | requestedAttributes := me.AttributeValueMap{me.OnuG_AdministrativeState: omciAdminState} |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 217 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 218 | meInstance, err := oFsm.pOmciCC.SendSetOnuGLS(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 219 | requestedAttributes, oFsm.PAdaptFsm.CommChan) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 220 | if err != nil { |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 221 | //Indicate the failure in UnLock case |
| 222 | if omciAdminState == 0 { |
| 223 | oFsm.SetSuccessEvent(cmn.UniEnableStateFailed) |
| 224 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 225 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 226 | logger.Errorw(ctx, "OnuGLS set failed, aborting LockStateFSM", log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 227 | pLockStateAFsm := oFsm.PAdaptFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 228 | if pLockStateAFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 229 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 230 | if a_pAFsm != nil && a_pAFsm.PFsm != nil { |
| 231 | _ = a_pAFsm.PFsm.Event(UniEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 232 | } |
| 233 | }(pLockStateAFsm) |
| 234 | } |
| 235 | return |
| 236 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 237 | //accept also nil as (error) return value for writing to LastTx |
| 238 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 239 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 240 | if oFsm.pLastTxMeInstance == nil { |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 241 | //Indicate the failure in UnLock case |
| 242 | if omciAdminState == 0 { |
| 243 | oFsm.SetSuccessEvent(cmn.UniEnableStateFailed) |
| 244 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 245 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 246 | 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 Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 249 | pLockStateAFsm := oFsm.PAdaptFsm |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 250 | if pLockStateAFsm != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 251 | |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 252 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 253 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 254 | if a_pAFsm != nil && a_pAFsm.PFsm != nil { |
| 255 | _ = a_pAFsm.PFsm.Event(UniEvReset) |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 256 | } |
| 257 | }(pLockStateAFsm) |
| 258 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 259 | return |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 260 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 261 | oFsm.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 264 | func (oFsm *LockStateFsm) enterSettingUnisState(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 265 | oFsm.mutexAdminState.RLock() |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 266 | logger.Debugw(ctx, "LockStateFSM - starting UniTP adminState loop", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 267 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID, "LockState": oFsm.adminState}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 268 | oFsm.mutexAdminState.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 269 | go oFsm.performUniPortAdminSet(ctx) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 272 | func (oFsm *LockStateFsm) enterAdminDoneState(ctx context.Context, e *fsm.Event) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 273 | logger.Debugw(ctx, "LockStateFSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 274 | //use DeviceHandler event notification directly, no need/support to update DeviceEntryState for lock/unlock |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 275 | oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, oFsm.requestEvent) |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 276 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 277 | //let's reset the state machine in order to release all resources now |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 278 | pLockStateAFsm := oFsm.PAdaptFsm |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 279 | if pLockStateAFsm != nil { |
| 280 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 281 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 282 | if a_pAFsm != nil && a_pAFsm.PFsm != nil { |
| 283 | _ = a_pAFsm.PFsm.Event(UniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 284 | } |
| 285 | }(pLockStateAFsm) |
| 286 | } |
| 287 | } |
| 288 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 289 | func (oFsm *LockStateFsm) enterResettingState(ctx context.Context, e *fsm.Event) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 290 | logger.Debugw(ctx, "LockStateFSM resetting", log.Fields{"device-id": oFsm.deviceID}) |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 291 | //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 Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 298 | pLockStateAFsm := oFsm.PAdaptFsm |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 299 | if pLockStateAFsm != nil { |
| 300 | // abort running message processing |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 301 | fsmAbortMsg := cmn.Message{ |
| 302 | Type: cmn.TestMsg, |
| 303 | Data: cmn.TestMessage{ |
| 304 | TestMessageVal: cmn.AbortMessageProcessing, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 305 | }, |
| 306 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 307 | pLockStateAFsm.CommChan <- fsmAbortMsg |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 308 | |
| 309 | //try to restart the FSM to 'disabled' |
| 310 | // see DownloadedState: decouple event transfer |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 311 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 312 | if a_pAFsm != nil && a_pAFsm.PFsm != nil { |
| 313 | _ = a_pAFsm.PFsm.Event(UniEvRestart) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 314 | } |
| 315 | }(pLockStateAFsm) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 316 | oFsm.mutexPLastTxMeInstance.Lock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 317 | oFsm.pLastTxMeInstance = nil |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 318 | oFsm.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 322 | func (oFsm *LockStateFsm) processOmciLockMessages(ctx context.Context) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 323 | logger.Debugw(ctx, "Start LockStateFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 324 | loop: |
| 325 | for { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 326 | // case <-ctx.Done(): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 327 | // logger.Info(ctx,"MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 328 | // break loop |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 329 | message, ok := <-oFsm.PAdaptFsm.CommChan |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 330 | if !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 331 | logger.Info(ctx, "LockStateFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 332 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 333 | _ = oFsm.PAdaptFsm.PFsm.Event(UniEvRestart) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 334 | break loop |
| 335 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 336 | logger.Debugw(ctx, "LockStateFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 337 | |
| 338 | switch message.Type { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 339 | case cmn.TestMsg: |
| 340 | msg, _ := message.Data.(cmn.TestMessage) |
| 341 | if msg.TestMessageVal == cmn.AbortMessageProcessing { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 342 | logger.Debugw(ctx, "LockStateFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 343 | break loop |
| 344 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 345 | logger.Warnw(ctx, "LockStateFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 346 | case cmn.OMCI: |
| 347 | msg, _ := message.Data.(cmn.OmciMessage) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 348 | oFsm.handleOmciLockStateMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 349 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 350 | logger.Warn(ctx, "LockStateFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 351 | "message.Type": message.Type}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 354 | logger.Debugw(ctx, "End LockStateFsm Msg processing", log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 357 | func (oFsm *LockStateFsm) handleOmciLockStateMessage(ctx context.Context, msg cmn.OmciMessage) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 358 | logger.Debugw(ctx, "Rx OMCI LockStateFsm Msg", log.Fields{"device-id": oFsm.deviceID, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 359 | "msgType": msg.OmciMsg.MessageType}) |
| 360 | |
| 361 | if msg.OmciMsg.MessageType == omci.SetResponseType { |
| 362 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 363 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 364 | logger.Errorw(ctx, "LockStateFsm - Omci Msg layer could not be detected for SetResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 365 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 366 | return |
| 367 | } |
| 368 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 369 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 370 | logger.Errorw(ctx, "LockStateFsm - Omci Msg layer could not be assigned for SetResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 371 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 372 | return |
| 373 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 374 | logger.Debugw(ctx, "LockStateFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 375 | if msgObj.Result != me.Success { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 376 | 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 Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 378 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 379 | return |
| 380 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 381 | |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 382 | //should never appear, left here for robustness |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 383 | oFsm.mutexPLastTxMeInstance.RLock() |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 384 | 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 Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 395 | oFsm.mutexPLastTxMeInstance.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 396 | _ = oFsm.PAdaptFsm.PFsm.Event(UniEvRxOnugResp) |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 397 | } |
| 398 | case "PhysicalPathTerminationPointEthernetUni", "VirtualEthernetInterfacePoint": |
| 399 | { // let the PPTP init proceed by stopping the wait function |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 400 | oFsm.mutexPLastTxMeInstance.RUnlock() |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 401 | oFsm.omciLockResponseReceived <- true |
| 402 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 403 | 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 Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 409 | } |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 410 | } else { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 411 | oFsm.mutexPLastTxMeInstance.RUnlock() |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 412 | 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 Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 414 | } |
Matteo Scandolo | b250bec | 2021-01-27 17:35:45 -0800 | [diff] [blame] | 415 | } else { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 416 | oFsm.mutexPLastTxMeInstance.RUnlock() |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 417 | logger.Errorw(ctx, "pLastTxMeInstance is nil", log.Fields{"device-id": oFsm.deviceID}) |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 418 | return |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 419 | } |
| 420 | } else { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 421 | logger.Errorw(ctx, "LockStateFsm - Rx OMCI unhandled MsgType", log.Fields{"device-id": oFsm.deviceID, "omciMsgType": msg.OmciMsg.MessageType}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 422 | return |
| 423 | } |
| 424 | } |
| 425 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 426 | func (oFsm *LockStateFsm) performUniPortAdminSet(ctx context.Context) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 427 | var omciAdminState uint8 = 1 //default locked |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 428 | oFsm.mutexAdminState.RLock() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 429 | if !oFsm.adminState { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 430 | omciAdminState = 0 |
| 431 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 432 | oFsm.mutexAdminState.RUnlock() |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 433 | //set PPTPEthUni or VEIP AdminState |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 434 | requestedAttributes := me.AttributeValueMap{me.PhysicalPathTerminationPointEthernetUni_AdministrativeState: omciAdminState} |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 435 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 436 | for uniNo, uniPort := range *oFsm.pDeviceHandler.GetUniEntityMap() { |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 437 | // only unlock the UniPort in case it is defined for usage (R2.6 limit only one port), |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 438 | // compare also limitation for logical voltha port in dh.EnableUniPortStateUpdate() |
Matteo Scandolo | 20d180c | 2021-06-10 17:20:21 +0200 | [diff] [blame] | 439 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 440 | if (omciAdminState == 1) || (1<<uniPort.UniID)&oFsm.pDeviceHandler.GetUniPortMask() == (1<<uniPort.UniID) { |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 441 | var meInstance *me.ManagedEntity |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 442 | if uniPort.PortType == cmn.UniPPTP { |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 443 | logger.Debugw(ctx, "Setting PPTP admin state", log.Fields{ |
| 444 | "device-id": oFsm.deviceID, "for PortNo": uniNo, "state (0-unlock)": omciAdminState}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 445 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 446 | meInstance, err := oFsm.pOmciCC.SendSetPptpEthUniLS(log.WithSpanFromContext(context.TODO(), ctx), |
| 447 | uniPort.EntityID, oFsm.pDeviceHandler.GetOmciTimeout(), |
| 448 | true, requestedAttributes, oFsm.PAdaptFsm.CommChan) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 449 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 450 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 451 | logger.Errorw(ctx, "SetPptpEthUniLS set failed, aborting LockStateFsm!", |
| 452 | log.Fields{"device-id": oFsm.deviceID}) |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 453 | //Indicate the failure in UnLock case |
| 454 | if omciAdminState == 0 { |
| 455 | oFsm.SetSuccessEvent(cmn.UniEnableStateFailed) |
| 456 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 457 | _ = oFsm.PAdaptFsm.PFsm.Event(UniEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 458 | return |
| 459 | } |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 460 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 461 | oFsm.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 462 | } else if uniPort.PortType == cmn.UniVEIP { |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 463 | logger.Debugw(ctx, "Setting VEIP admin state", log.Fields{ |
| 464 | "device-id": oFsm.deviceID, "for PortNo": uniNo, "state (0-unlock)": omciAdminState}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 465 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 466 | meInstance, err := oFsm.pOmciCC.SendSetVeipLS(log.WithSpanFromContext(context.TODO(), ctx), |
| 467 | uniPort.EntityID, oFsm.pDeviceHandler.GetOmciTimeout(), |
| 468 | true, requestedAttributes, oFsm.PAdaptFsm.CommChan) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 469 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 470 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 471 | logger.Errorw(ctx, "SetVeipLS set failed, aborting LockStateFsm!", |
| 472 | log.Fields{"device-id": oFsm.deviceID}) |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 473 | //Indicate the failure in UnLock case |
| 474 | if omciAdminState == 0 { |
| 475 | oFsm.SetSuccessEvent(cmn.UniEnableStateFailed) |
| 476 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 477 | _ = oFsm.PAdaptFsm.PFsm.Event(UniEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 478 | return |
| 479 | } |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 480 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 481 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 482 | } else { |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 483 | //TODO: Discuss on the uni port type POTS . |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 484 | logger.Warnw(ctx, "Unsupported UniTP type - skip", |
| 485 | log.Fields{"device-id": oFsm.deviceID, "Port": uniNo}) |
| 486 | continue |
| 487 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 488 | oFsm.mutexPLastTxMeInstance.RLock() |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 489 | if oFsm.pLastTxMeInstance == nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 490 | oFsm.mutexPLastTxMeInstance.RUnlock() |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 491 | logger.Errorw(ctx, "could not send PortAdmin OMCI message from LockStateFsm", log.Fields{ |
| 492 | "device-id": oFsm.deviceID, "Port": uniNo}) |
Mahir Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 493 | //Indicate the failure in UnLock case |
| 494 | if omciAdminState == 0 { |
| 495 | oFsm.SetSuccessEvent(cmn.UniEnableStateFailed) |
| 496 | } |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 497 | //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 Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 498 | _ = oFsm.PAdaptFsm.PFsm.Event(UniEvReset) |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 499 | return |
| 500 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 501 | oFsm.mutexPLastTxMeInstance.RUnlock() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 502 | |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 503 | //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 Gunyel | 50ddea6 | 2021-10-22 11:26:42 -0700 | [diff] [blame] | 508 | //Indicate the failure in UnLock case |
| 509 | if omciAdminState == 0 { |
| 510 | oFsm.SetSuccessEvent(cmn.UniEnableStateFailed) |
| 511 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 512 | _ = oFsm.PAdaptFsm.PFsm.Event(UniEvReset) |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 513 | return |
| 514 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 515 | } |
| 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 - !? |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 519 | logger.Infow(ctx, "UniTP adminState loop finished", log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 520 | _ = oFsm.PAdaptFsm.PFsm.Event(UniEvRxUnisResp) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 523 | func (oFsm *LockStateFsm) waitforOmciResponse(ctx context.Context, apMeInstance *me.ManagedEntity) error { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 524 | select { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 525 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 526 | // case <-ctx.Done(): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 527 | // logger.Infow(ctx,"LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID}) |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 528 | 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 Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 529 | logger.Warnw(ctx, "lockStateFSM uni-set timeout", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 530 | return fmt.Errorf("lockStateFsm uni-set timeout for device-id %s", oFsm.deviceID) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 531 | case success := <-oFsm.omciLockResponseReceived: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 532 | if success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 533 | logger.Debug(ctx, "LockStateFSM uni-set response received") |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 534 | return nil |
| 535 | } |
| 536 | // should not happen so far |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 537 | logger.Warnw(ctx, "lockStateFSM uni-set response error", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 538 | return fmt.Errorf("lockStateFsm uni-set responseError for device-id %s", oFsm.deviceID) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 539 | } |
| 540 | } |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 541 | |
| 542 | // PrepareForGarbageCollection - remove references to prepare for garbage collection |
| 543 | func (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 | } |