Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | //Package adaptercoreonu provides the utility for onu devices, flows and statistics |
| 18 | package adaptercoreonu |
| 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 | |
| 28 | "github.com/opencord/omci-lib-go" |
| 29 | me "github.com/opencord/omci-lib-go/generated" |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 30 | "github.com/opencord/voltha-lib-go/v5/pkg/log" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 31 | //ic "github.com/opencord/voltha-protos/v4/go/inter_container" |
| 32 | //"github.com/opencord/voltha-protos/v4/go/openflow_13" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 33 | ) |
| 34 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 35 | //lockStateFsm defines the structure for the state machine to lock/unlock the ONU UNI ports via OMCI |
| 36 | type lockStateFsm struct { |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 37 | pDeviceHandler *deviceHandler |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 38 | deviceID string |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 39 | pOmciCC *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 |
| 42 | requestEvent OnuDeviceEvent |
| 43 | omciLockResponseReceived chan bool //seperate channel needed for checking UNI port OMCi message responses |
| 44 | pAdaptFsm *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 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 49 | const ( |
| 50 | // events of lock/unlock UNI port FSM |
| 51 | uniEvStart = "uniEvStart" |
| 52 | uniEvStartAdmin = "uniEvStartAdmin" |
| 53 | uniEvRxUnisResp = "uniEvRxUnisResp" |
| 54 | uniEvRxOnugResp = "uniEvRxOnugResp" |
| 55 | uniEvTimeoutSimple = "uniEvTimeoutSimple" |
| 56 | uniEvTimeoutUnis = "uniEvTimeoutUnis" |
| 57 | uniEvReset = "uniEvReset" |
| 58 | uniEvRestart = "uniEvRestart" |
| 59 | ) |
| 60 | const ( |
| 61 | // states of lock/unlock UNI port FSM |
| 62 | uniStDisabled = "uniStDisabled" |
| 63 | uniStStarting = "uniStStarting" |
| 64 | uniStSettingUnis = "uniStSettingUnis" |
| 65 | uniStSettingOnuG = "uniStSettingOnuG" |
| 66 | uniStAdminDone = "uniStAdminDone" |
| 67 | uniStResetting = "uniStResetting" |
| 68 | ) |
Holger Hildebrandt | 10d9819 | 2021-01-27 15:29:31 +0000 | [diff] [blame] | 69 | const cUniFsmIdleState = uniStDisabled |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 70 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 71 | //newLockStateFsm is the 'constructor' for the state machine to lock/unlock the ONU UNI ports via OMCI |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 72 | func newLockStateFsm(ctx context.Context, apDevOmciCC *omciCC, aAdminState bool, aRequestEvent OnuDeviceEvent, |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 73 | aName string, apDeviceHandler *deviceHandler, aCommChannel chan Message) *lockStateFsm { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 74 | instFsm := &lockStateFsm{ |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 75 | pDeviceHandler: apDeviceHandler, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 76 | deviceID: apDeviceHandler.deviceID, |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 77 | pOmciCC: apDevOmciCC, |
| 78 | adminState: aAdminState, |
| 79 | requestEvent: aRequestEvent, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 80 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 81 | instFsm.pAdaptFsm = NewAdapterFsm(aName, instFsm.deviceID, aCommChannel) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 82 | if instFsm.pAdaptFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 83 | logger.Errorw(ctx, "LockStateFsm's AdapterFsm could not be instantiated!!", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 84 | "device-id": instFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 85 | return nil |
| 86 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 87 | if aAdminState { //port locking requested |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 88 | instFsm.pAdaptFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 89 | uniStDisabled, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 90 | fsm.Events{ |
| 91 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 92 | {Name: uniEvStart, Src: []string{uniStDisabled}, Dst: uniStStarting}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 93 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 94 | {Name: uniEvStartAdmin, Src: []string{uniStStarting}, Dst: uniStSettingUnis}, |
| 95 | // 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] | 96 | // maybe such could be reflected in the state machine as well (port number parametrized) |
| 97 | // but that looks not straightforward here - so we keep it simple here for the beginning(?) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 98 | {Name: uniEvRxUnisResp, Src: []string{uniStSettingUnis}, Dst: uniStSettingOnuG}, |
| 99 | {Name: uniEvRxOnugResp, Src: []string{uniStSettingOnuG}, Dst: uniStAdminDone}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 100 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 101 | {Name: uniEvTimeoutSimple, Src: []string{uniStSettingOnuG}, Dst: uniStStarting}, |
| 102 | {Name: uniEvTimeoutUnis, Src: []string{uniStSettingUnis}, Dst: uniStStarting}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 103 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 104 | {Name: uniEvReset, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis, |
| 105 | uniStAdminDone}, Dst: uniStResetting}, |
| 106 | // exceptional treatment for all states except uniStResetting |
| 107 | {Name: uniEvRestart, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis, |
| 108 | uniStAdminDone, uniStResetting}, Dst: uniStDisabled}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 109 | }, |
| 110 | |
| 111 | fsm.Callbacks{ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 112 | "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(ctx, e) }, |
| 113 | ("enter_" + uniStStarting): func(e *fsm.Event) { instFsm.enterAdminStartingState(ctx, e) }, |
| 114 | ("enter_" + uniStSettingOnuG): func(e *fsm.Event) { instFsm.enterSettingOnuGState(ctx, e) }, |
| 115 | ("enter_" + uniStSettingUnis): func(e *fsm.Event) { instFsm.enterSettingUnisState(ctx, e) }, |
| 116 | ("enter_" + uniStAdminDone): func(e *fsm.Event) { instFsm.enterAdminDoneState(ctx, e) }, |
| 117 | ("enter_" + uniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(ctx, e) }, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 118 | }, |
| 119 | ) |
| 120 | } else { //port unlocking requested |
| 121 | instFsm.pAdaptFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 122 | uniStDisabled, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 123 | fsm.Events{ |
| 124 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 125 | {Name: uniEvStart, Src: []string{uniStDisabled}, Dst: uniStStarting}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 126 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 127 | {Name: uniEvStartAdmin, Src: []string{uniStStarting}, Dst: uniStSettingOnuG}, |
| 128 | {Name: uniEvRxOnugResp, Src: []string{uniStSettingOnuG}, Dst: uniStSettingUnis}, |
| 129 | // 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] | 130 | // maybe such could be reflected in the state machine as well (port number parametrized) |
| 131 | // but that looks not straightforward here - so we keep it simple here for the beginning(?) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 132 | {Name: uniEvRxUnisResp, Src: []string{uniStSettingUnis}, Dst: uniStAdminDone}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 133 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 134 | {Name: uniEvTimeoutSimple, Src: []string{uniStSettingOnuG}, Dst: uniStStarting}, |
| 135 | {Name: uniEvTimeoutUnis, Src: []string{uniStSettingUnis}, Dst: uniStStarting}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 136 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 137 | {Name: uniEvReset, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis, |
| 138 | uniStAdminDone}, Dst: uniStResetting}, |
| 139 | // exceptional treatment for all states except uniStResetting |
| 140 | {Name: uniEvRestart, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis, |
| 141 | uniStAdminDone, uniStResetting}, Dst: uniStDisabled}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 142 | }, |
| 143 | |
| 144 | fsm.Callbacks{ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 145 | "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(ctx, e) }, |
| 146 | ("enter_" + uniStStarting): func(e *fsm.Event) { instFsm.enterAdminStartingState(ctx, e) }, |
| 147 | ("enter_" + uniStSettingOnuG): func(e *fsm.Event) { instFsm.enterSettingOnuGState(ctx, e) }, |
| 148 | ("enter_" + uniStSettingUnis): func(e *fsm.Event) { instFsm.enterSettingUnisState(ctx, e) }, |
| 149 | ("enter_" + uniStAdminDone): func(e *fsm.Event) { instFsm.enterAdminDoneState(ctx, e) }, |
| 150 | ("enter_" + uniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(ctx, e) }, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 151 | }, |
| 152 | ) |
| 153 | } |
| 154 | if instFsm.pAdaptFsm.pFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 155 | logger.Errorw(ctx, "LockStateFsm's Base FSM could not be instantiated!!", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 156 | "device-id": instFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 157 | return nil |
| 158 | } |
| 159 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 160 | logger.Debugw(ctx, "LockStateFsm created", log.Fields{"device-id": instFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 161 | return instFsm |
| 162 | } |
| 163 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 164 | //setSuccessEvent modifies the requested event notified on success |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 165 | //assumption is that this is only called in the disabled (idle) state of the FSM, hence no sem protection required |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 166 | func (oFsm *lockStateFsm) setSuccessEvent(aEvent OnuDeviceEvent) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 167 | oFsm.requestEvent = aEvent |
| 168 | } |
| 169 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 170 | func (oFsm *lockStateFsm) enterAdminStartingState(ctx context.Context, e *fsm.Event) { |
| 171 | logger.Debugw(ctx, "LockStateFSM start", log.Fields{"in state": e.FSM.Current(), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 172 | "device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 173 | // in case the used channel is not yet defined (can be re-used after restarts) |
| 174 | if oFsm.omciLockResponseReceived == nil { |
| 175 | oFsm.omciLockResponseReceived = make(chan bool) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 176 | logger.Debug(ctx, "LockStateFSM - OMCI UniLock RxChannel defined") |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 177 | } else { |
| 178 | // as we may 're-use' this instance of FSM and the connected channel |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 179 | // make sure there is no 'lingering' request in the already existing channels: |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 180 | // (simple loop sufficient as we are the only receiver) |
| 181 | for len(oFsm.omciLockResponseReceived) > 0 { |
| 182 | <-oFsm.omciLockResponseReceived |
| 183 | } |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 184 | for len(oFsm.pAdaptFsm.commChan) > 0 { |
| 185 | <-oFsm.pAdaptFsm.commChan |
| 186 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 187 | } |
| 188 | // start go routine for processing of LockState messages |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 189 | go oFsm.processOmciLockMessages(ctx) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 190 | |
| 191 | //let the state machine run forward from here directly |
| 192 | pLockStateAFsm := oFsm.pAdaptFsm |
| 193 | if pLockStateAFsm != nil { |
| 194 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 195 | go func(a_pAFsm *AdapterFsm) { |
| 196 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 197 | _ = a_pAFsm.pFsm.Event(uniEvStartAdmin) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 198 | } |
| 199 | }(pLockStateAFsm) |
| 200 | } |
| 201 | } |
| 202 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 203 | func (oFsm *lockStateFsm) enterSettingOnuGState(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 204 | var omciAdminState uint8 = 1 //default locked |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 205 | oFsm.mutexAdminState.RLock() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 206 | if !oFsm.adminState { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 207 | omciAdminState = 0 |
| 208 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 209 | oFsm.mutexAdminState.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 210 | logger.Debugw(ctx, "LockStateFSM Tx Set::ONU-G:admin", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 211 | "omciAdmin": omciAdminState, "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 212 | requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState} |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 213 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 214 | meInstance, err := oFsm.pOmciCC.sendSetOnuGLS(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 215 | requestedAttributes, oFsm.pAdaptFsm.commChan) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 216 | if err != nil { |
Holger Hildebrandt | da15a09 | 2022-01-07 15:30:49 +0000 | [diff] [blame] | 217 | //Indicate the failure in UnLock case |
| 218 | if omciAdminState == 0 { |
| 219 | oFsm.setSuccessEvent(UniEnableStateFailed) |
| 220 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 221 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 222 | logger.Errorw(ctx, "OnuGLS set failed, aborting LockStateFSM", log.Fields{"device-id": oFsm.deviceID}) |
| 223 | pLockStateAFsm := oFsm.pAdaptFsm |
| 224 | if pLockStateAFsm != nil { |
| 225 | go func(a_pAFsm *AdapterFsm) { |
| 226 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
| 227 | _ = a_pAFsm.pFsm.Event(uniEvReset) |
| 228 | } |
| 229 | }(pLockStateAFsm) |
| 230 | } |
| 231 | return |
| 232 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 233 | //accept also nil as (error) return value for writing to LastTx |
| 234 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 235 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 236 | if oFsm.pLastTxMeInstance == nil { |
Holger Hildebrandt | da15a09 | 2022-01-07 15:30:49 +0000 | [diff] [blame] | 237 | //Indicate the failure in UnLock case |
| 238 | if omciAdminState == 0 { |
| 239 | oFsm.setSuccessEvent(UniEnableStateFailed) |
| 240 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 241 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 242 | logger.Errorw(ctx, "could not send OMCI message from LockStateFsm", log.Fields{ |
| 243 | "device-id": oFsm.deviceID}) |
| 244 | //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 |
| 245 | pLockStateAFsm := oFsm.pAdaptFsm |
| 246 | if pLockStateAFsm != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 247 | |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 248 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 249 | go func(a_pAFsm *AdapterFsm) { |
| 250 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
| 251 | _ = a_pAFsm.pFsm.Event(uniEvReset) |
| 252 | } |
| 253 | }(pLockStateAFsm) |
| 254 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 255 | return |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 256 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 257 | oFsm.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 258 | } |
| 259 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 260 | func (oFsm *lockStateFsm) enterSettingUnisState(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 261 | oFsm.mutexAdminState.RLock() |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 262 | logger.Debugw(ctx, "LockStateFSM - starting UniTP adminState loop", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 263 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID, "LockState": oFsm.adminState}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 264 | oFsm.mutexAdminState.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 265 | go oFsm.performUniPortAdminSet(ctx) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 266 | } |
| 267 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 268 | func (oFsm *lockStateFsm) enterAdminDoneState(ctx context.Context, e *fsm.Event) { |
| 269 | 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] | 270 | //use DeviceHandler event notification directly, no need/support to update DeviceEntryState for lock/unlock |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 271 | oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, oFsm.requestEvent) |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 272 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 273 | //let's reset the state machine in order to release all resources now |
| 274 | pLockStateAFsm := oFsm.pAdaptFsm |
| 275 | if pLockStateAFsm != nil { |
| 276 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 277 | go func(a_pAFsm *AdapterFsm) { |
| 278 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 279 | _ = a_pAFsm.pFsm.Event(uniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 280 | } |
| 281 | }(pLockStateAFsm) |
| 282 | } |
| 283 | } |
| 284 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 285 | func (oFsm *lockStateFsm) enterResettingState(ctx context.Context, e *fsm.Event) { |
| 286 | logger.Debugw(ctx, "LockStateFSM resetting", log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | da15a09 | 2022-01-07 15:30:49 +0000 | [diff] [blame] | 287 | //If the fsm is reseted because of a failure during reenable, then issue the fail event. |
| 288 | if oFsm.requestEvent == UniEnableStateFailed { |
| 289 | logger.Debugw(ctx, "LockStateFSM send notification to core", log.Fields{"state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 290 | //use DeviceHandler event notification directly, no need/support to update DeviceEntryState for lock/unlock |
| 291 | oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, oFsm.requestEvent) |
| 292 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 293 | pLockStateAFsm := oFsm.pAdaptFsm |
| 294 | if pLockStateAFsm != nil { |
| 295 | // abort running message processing |
| 296 | fsmAbortMsg := Message{ |
| 297 | Type: TestMsg, |
| 298 | Data: TestMessage{ |
| 299 | TestMessageVal: AbortMessageProcessing, |
| 300 | }, |
| 301 | } |
| 302 | pLockStateAFsm.commChan <- fsmAbortMsg |
| 303 | |
| 304 | //try to restart the FSM to 'disabled' |
| 305 | // see DownloadedState: decouple event transfer |
| 306 | go func(a_pAFsm *AdapterFsm) { |
| 307 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 308 | _ = a_pAFsm.pFsm.Event(uniEvRestart) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 309 | } |
| 310 | }(pLockStateAFsm) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 311 | oFsm.mutexPLastTxMeInstance.Lock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 312 | oFsm.pLastTxMeInstance = nil |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 313 | oFsm.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 317 | func (oFsm *lockStateFsm) processOmciLockMessages(ctx context.Context) { |
| 318 | 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] | 319 | loop: |
| 320 | for { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 321 | // case <-ctx.Done(): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 322 | // 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] | 323 | // break loop |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 324 | message, ok := <-oFsm.pAdaptFsm.commChan |
| 325 | if !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 326 | 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] | 327 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
| 328 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRestart) |
| 329 | break loop |
| 330 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 331 | logger.Debugw(ctx, "LockStateFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 332 | |
| 333 | switch message.Type { |
| 334 | case TestMsg: |
| 335 | msg, _ := message.Data.(TestMessage) |
| 336 | if msg.TestMessageVal == AbortMessageProcessing { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 337 | 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] | 338 | break loop |
| 339 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 340 | logger.Warnw(ctx, "LockStateFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 341 | case OMCI: |
| 342 | msg, _ := message.Data.(OmciMessage) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 343 | oFsm.handleOmciLockStateMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 344 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 345 | 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] | 346 | "message.Type": message.Type}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 347 | } |
| 348 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 349 | 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] | 350 | } |
| 351 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 352 | func (oFsm *lockStateFsm) handleOmciLockStateMessage(ctx context.Context, msg OmciMessage) { |
| 353 | 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] | 354 | "msgType": msg.OmciMsg.MessageType}) |
| 355 | |
| 356 | if msg.OmciMsg.MessageType == omci.SetResponseType { |
| 357 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 358 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 359 | logger.Errorw(ctx, "LockStateFsm - Omci Msg layer could not be detected for SetResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 360 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 361 | return |
| 362 | } |
| 363 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 364 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 365 | logger.Errorw(ctx, "LockStateFsm - Omci Msg layer could not be assigned for SetResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 366 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 367 | return |
| 368 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 369 | 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] | 370 | if msgObj.Result != me.Success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 371 | logger.Errorw(ctx, "LockStateFsm - Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 372 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 373 | return |
| 374 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 375 | |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 376 | //should never appear, left here for robustness |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 377 | oFsm.mutexPLastTxMeInstance.RLock() |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 378 | if oFsm.pLastTxMeInstance != nil { |
| 379 | // compare comments above for CreateResponse (apply also here ...) |
| 380 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 381 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 382 | //store the created ME into DB //TODO??? obviously the Python code does not store the config ... |
| 383 | // if, then something like: |
| 384 | //oFsm.pOnuDB.StoreMe(msgObj) |
| 385 | |
| 386 | switch oFsm.pLastTxMeInstance.GetName() { |
| 387 | case "OnuG": |
| 388 | { // let the FSM proceed ... |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 389 | oFsm.mutexPLastTxMeInstance.RUnlock() |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 390 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxOnugResp) |
| 391 | } |
| 392 | case "PhysicalPathTerminationPointEthernetUni", "VirtualEthernetInterfacePoint": |
| 393 | { // let the PPTP init proceed by stopping the wait function |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 394 | oFsm.mutexPLastTxMeInstance.RUnlock() |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 395 | oFsm.omciLockResponseReceived <- true |
| 396 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 397 | default: |
| 398 | { |
| 399 | logger.Warnw(ctx, "Unsupported ME name received!", |
| 400 | log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID}) |
| 401 | oFsm.mutexPLastTxMeInstance.RUnlock() |
| 402 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 403 | } |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 404 | } else { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 405 | oFsm.mutexPLastTxMeInstance.RUnlock() |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 406 | logger.Warnf(ctx, "LockStateFsm - Received SetResponse Data for %s with wrong classID or entityID ", |
| 407 | log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}, msgObj.EntityClass) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 408 | } |
Matteo Scandolo | b250bec | 2021-01-27 17:35:45 -0800 | [diff] [blame] | 409 | } else { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 410 | oFsm.mutexPLastTxMeInstance.RUnlock() |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 411 | logger.Errorw(ctx, "pLastTxMeInstance is nil", log.Fields{"device-id": oFsm.deviceID}) |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 412 | return |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 413 | } |
| 414 | } else { |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 415 | logger.Errorw(ctx, "LockStateFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 416 | return |
| 417 | } |
| 418 | } |
| 419 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 420 | func (oFsm *lockStateFsm) performUniPortAdminSet(ctx context.Context) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 421 | var omciAdminState uint8 = 1 //default locked |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 422 | oFsm.mutexAdminState.RLock() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 423 | if !oFsm.adminState { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 424 | omciAdminState = 0 |
| 425 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 426 | oFsm.mutexAdminState.RUnlock() |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 427 | //set PPTPEthUni or VEIP AdminState |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 428 | requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState} |
| 429 | |
| 430 | for uniNo, uniPort := range oFsm.pOmciCC.pBaseDeviceHandler.uniEntityMap { |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 431 | // only unlock the UniPort in case it is defined for usage (R2.6 limit only one port), |
| 432 | // compare also limitation for logical voltha port in dh.enableUniPortStateUpdate() |
Matteo Scandolo | 20d180c | 2021-06-10 17:20:21 +0200 | [diff] [blame] | 433 | |
| 434 | if (omciAdminState == 1) || (1<<uniPort.uniID)&oFsm.pDeviceHandler.pOpenOnuAc.config.UniPortMask == (1<<uniPort.uniID) { |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 435 | var meInstance *me.ManagedEntity |
| 436 | if uniPort.portType == uniPPTP { |
| 437 | logger.Debugw(ctx, "Setting PPTP admin state", log.Fields{ |
| 438 | "device-id": oFsm.deviceID, "for PortNo": uniNo, "state (0-unlock)": omciAdminState}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 439 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 440 | meInstance, err := oFsm.pOmciCC.sendSetPptpEthUniLS(log.WithSpanFromContext(context.TODO(), ctx), |
| 441 | uniPort.entityID, oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 442 | true, requestedAttributes, oFsm.pAdaptFsm.commChan) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 443 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 444 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 445 | logger.Errorw(ctx, "SetPptpEthUniLS set failed, aborting LockStateFsm!", |
| 446 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | da15a09 | 2022-01-07 15:30:49 +0000 | [diff] [blame] | 447 | //Indicate the failure in UnLock case |
| 448 | if omciAdminState == 0 { |
| 449 | oFsm.setSuccessEvent(UniEnableStateFailed) |
| 450 | } |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 451 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
| 452 | return |
| 453 | } |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 454 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 455 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 456 | } else if uniPort.portType == uniVEIP { |
| 457 | logger.Debugw(ctx, "Setting VEIP admin state", log.Fields{ |
| 458 | "device-id": oFsm.deviceID, "for PortNo": uniNo, "state (0-unlock)": omciAdminState}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 459 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 460 | meInstance, err := oFsm.pOmciCC.sendSetVeipLS(log.WithSpanFromContext(context.TODO(), ctx), |
| 461 | uniPort.entityID, oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 462 | true, requestedAttributes, oFsm.pAdaptFsm.commChan) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 463 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 464 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 465 | logger.Errorw(ctx, "SetVeipLS set failed, aborting LockStateFsm!", |
| 466 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | da15a09 | 2022-01-07 15:30:49 +0000 | [diff] [blame] | 467 | //Indicate the failure in UnLock case |
| 468 | if omciAdminState == 0 { |
| 469 | oFsm.setSuccessEvent(UniEnableStateFailed) |
| 470 | } |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 471 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
| 472 | return |
| 473 | } |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 474 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 475 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 476 | } else { |
| 477 | logger.Warnw(ctx, "Unsupported UniTP type - skip", |
| 478 | log.Fields{"device-id": oFsm.deviceID, "Port": uniNo}) |
| 479 | continue |
| 480 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 481 | oFsm.mutexPLastTxMeInstance.RLock() |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 482 | if oFsm.pLastTxMeInstance == nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 483 | oFsm.mutexPLastTxMeInstance.RUnlock() |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 484 | logger.Errorw(ctx, "could not send PortAdmin OMCI message from LockStateFsm", log.Fields{ |
| 485 | "device-id": oFsm.deviceID, "Port": uniNo}) |
Holger Hildebrandt | da15a09 | 2022-01-07 15:30:49 +0000 | [diff] [blame] | 486 | //Indicate the failure in UnLock case |
| 487 | if omciAdminState == 0 { |
| 488 | oFsm.setSuccessEvent(UniEnableStateFailed) |
| 489 | } |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 490 | //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 |
| 491 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
| 492 | return |
| 493 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 494 | oFsm.mutexPLastTxMeInstance.RUnlock() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 495 | |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 496 | //verify response |
| 497 | err := oFsm.waitforOmciResponse(ctx, meInstance) |
| 498 | if err != nil { |
| 499 | logger.Errorw(ctx, "UniTP Admin State set failed, aborting LockState set!", |
| 500 | log.Fields{"device-id": oFsm.deviceID, "Port": uniNo}) |
Holger Hildebrandt | da15a09 | 2022-01-07 15:30:49 +0000 | [diff] [blame] | 501 | //Indicate the failure in UnLock case |
| 502 | if omciAdminState == 0 { |
| 503 | oFsm.setSuccessEvent(UniEnableStateFailed) |
| 504 | } |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 505 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
| 506 | return |
| 507 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 508 | } |
| 509 | } //for all UNI ports |
| 510 | // if Config has been done for all UNI related instances let the FSM proceed |
| 511 | // while we did not check here, if there is some port at all - !? |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 512 | logger.Infow(ctx, "UniTP adminState loop finished", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 513 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxUnisResp) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 514 | } |
| 515 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 516 | func (oFsm *lockStateFsm) waitforOmciResponse(ctx context.Context, apMeInstance *me.ManagedEntity) error { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 517 | select { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 518 | // 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] | 519 | // case <-ctx.Done(): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 520 | // 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] | 521 | case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 522 | 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] | 523 | 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] | 524 | case success := <-oFsm.omciLockResponseReceived: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 525 | if success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 526 | logger.Debug(ctx, "LockStateFSM uni-set response received") |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 527 | return nil |
| 528 | } |
| 529 | // should not happen so far |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 530 | 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] | 531 | 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] | 532 | } |
| 533 | } |