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 | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 217 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 218 | logger.Errorw(ctx, "OnuGLS set failed, aborting LockStateFSM", log.Fields{"device-id": oFsm.deviceID}) |
| 219 | pLockStateAFsm := oFsm.pAdaptFsm |
| 220 | if pLockStateAFsm != nil { |
| 221 | go func(a_pAFsm *AdapterFsm) { |
| 222 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
| 223 | _ = a_pAFsm.pFsm.Event(uniEvReset) |
| 224 | } |
| 225 | }(pLockStateAFsm) |
| 226 | } |
| 227 | return |
| 228 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 229 | //accept also nil as (error) return value for writing to LastTx |
| 230 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 231 | oFsm.pLastTxMeInstance = meInstance |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 232 | if oFsm.pLastTxMeInstance == nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 233 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 234 | logger.Errorw(ctx, "could not send OMCI message from LockStateFsm", log.Fields{ |
| 235 | "device-id": oFsm.deviceID}) |
| 236 | //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 |
| 237 | pLockStateAFsm := oFsm.pAdaptFsm |
| 238 | if pLockStateAFsm != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 239 | |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 240 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 241 | go func(a_pAFsm *AdapterFsm) { |
| 242 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
| 243 | _ = a_pAFsm.pFsm.Event(uniEvReset) |
| 244 | } |
| 245 | }(pLockStateAFsm) |
| 246 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 247 | return |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 248 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 249 | oFsm.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 250 | } |
| 251 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 252 | func (oFsm *lockStateFsm) enterSettingUnisState(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 253 | oFsm.mutexAdminState.RLock() |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 254 | logger.Debugw(ctx, "LockStateFSM - starting UniTP adminState loop", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 255 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID, "LockState": oFsm.adminState}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 256 | oFsm.mutexAdminState.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 257 | go oFsm.performUniPortAdminSet(ctx) |
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) enterAdminDoneState(ctx context.Context, e *fsm.Event) { |
| 261 | 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] | 262 | //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] | 263 | oFsm.pDeviceHandler.deviceProcStatusUpdate(ctx, oFsm.requestEvent) |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 264 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 265 | //let's reset the state machine in order to release all resources now |
| 266 | pLockStateAFsm := oFsm.pAdaptFsm |
| 267 | if pLockStateAFsm != nil { |
| 268 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 269 | go func(a_pAFsm *AdapterFsm) { |
| 270 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 271 | _ = a_pAFsm.pFsm.Event(uniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 272 | } |
| 273 | }(pLockStateAFsm) |
| 274 | } |
| 275 | } |
| 276 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 277 | func (oFsm *lockStateFsm) enterResettingState(ctx context.Context, e *fsm.Event) { |
| 278 | logger.Debugw(ctx, "LockStateFSM resetting", log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 279 | pLockStateAFsm := oFsm.pAdaptFsm |
| 280 | if pLockStateAFsm != nil { |
| 281 | // abort running message processing |
| 282 | fsmAbortMsg := Message{ |
| 283 | Type: TestMsg, |
| 284 | Data: TestMessage{ |
| 285 | TestMessageVal: AbortMessageProcessing, |
| 286 | }, |
| 287 | } |
| 288 | pLockStateAFsm.commChan <- fsmAbortMsg |
| 289 | |
| 290 | //try to restart the FSM to 'disabled' |
| 291 | // see DownloadedState: decouple event transfer |
| 292 | go func(a_pAFsm *AdapterFsm) { |
| 293 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 294 | _ = a_pAFsm.pFsm.Event(uniEvRestart) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 295 | } |
| 296 | }(pLockStateAFsm) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 297 | oFsm.mutexPLastTxMeInstance.Lock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 298 | oFsm.pLastTxMeInstance = nil |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 299 | oFsm.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 303 | func (oFsm *lockStateFsm) processOmciLockMessages(ctx context.Context) { |
| 304 | 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] | 305 | loop: |
| 306 | for { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 307 | // case <-ctx.Done(): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 308 | // 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] | 309 | // break loop |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 310 | message, ok := <-oFsm.pAdaptFsm.commChan |
| 311 | if !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 312 | 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] | 313 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
| 314 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRestart) |
| 315 | break loop |
| 316 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 317 | logger.Debugw(ctx, "LockStateFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 318 | |
| 319 | switch message.Type { |
| 320 | case TestMsg: |
| 321 | msg, _ := message.Data.(TestMessage) |
| 322 | if msg.TestMessageVal == AbortMessageProcessing { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 323 | 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] | 324 | break loop |
| 325 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 326 | 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] | 327 | case OMCI: |
| 328 | msg, _ := message.Data.(OmciMessage) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 329 | oFsm.handleOmciLockStateMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 330 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 331 | 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] | 332 | "message.Type": message.Type}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 333 | } |
| 334 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 335 | 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] | 336 | } |
| 337 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 338 | func (oFsm *lockStateFsm) handleOmciLockStateMessage(ctx context.Context, msg OmciMessage) { |
| 339 | 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] | 340 | "msgType": msg.OmciMsg.MessageType}) |
| 341 | |
| 342 | if msg.OmciMsg.MessageType == omci.SetResponseType { |
| 343 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 344 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 345 | logger.Errorw(ctx, "LockStateFsm - Omci Msg layer could not be detected for SetResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 346 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 347 | return |
| 348 | } |
| 349 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 350 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 351 | logger.Errorw(ctx, "LockStateFsm - Omci Msg layer could not be assigned for SetResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 352 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 353 | return |
| 354 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 355 | 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] | 356 | if msgObj.Result != me.Success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 357 | 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] | 358 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 359 | return |
| 360 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 361 | |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 362 | //should never appear, left here for robustness |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 363 | oFsm.mutexPLastTxMeInstance.RLock() |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 364 | if oFsm.pLastTxMeInstance != nil { |
| 365 | // compare comments above for CreateResponse (apply also here ...) |
| 366 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 367 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 368 | //store the created ME into DB //TODO??? obviously the Python code does not store the config ... |
| 369 | // if, then something like: |
| 370 | //oFsm.pOnuDB.StoreMe(msgObj) |
| 371 | |
| 372 | switch oFsm.pLastTxMeInstance.GetName() { |
| 373 | case "OnuG": |
| 374 | { // let the FSM proceed ... |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 375 | oFsm.mutexPLastTxMeInstance.RUnlock() |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 376 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxOnugResp) |
| 377 | } |
| 378 | case "PhysicalPathTerminationPointEthernetUni", "VirtualEthernetInterfacePoint": |
| 379 | { // let the PPTP init proceed by stopping the wait function |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 380 | oFsm.mutexPLastTxMeInstance.RUnlock() |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 381 | oFsm.omciLockResponseReceived <- true |
| 382 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 383 | default: |
| 384 | { |
| 385 | logger.Warnw(ctx, "Unsupported ME name received!", |
| 386 | log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID}) |
| 387 | oFsm.mutexPLastTxMeInstance.RUnlock() |
| 388 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 389 | } |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 390 | } else { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 391 | oFsm.mutexPLastTxMeInstance.RUnlock() |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 392 | logger.Warnf(ctx, "LockStateFsm - Received SetResponse Data for %s with wrong classID or entityID ", |
| 393 | log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}, msgObj.EntityClass) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 394 | } |
Matteo Scandolo | b250bec | 2021-01-27 17:35:45 -0800 | [diff] [blame] | 395 | } else { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 396 | oFsm.mutexPLastTxMeInstance.RUnlock() |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 397 | logger.Errorw(ctx, "pLastTxMeInstance is nil", log.Fields{"device-id": oFsm.deviceID}) |
Girish Gowdra | 3d5d675 | 2021-03-22 19:21:24 -0700 | [diff] [blame] | 398 | return |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 399 | } |
| 400 | } else { |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 401 | 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] | 402 | return |
| 403 | } |
| 404 | } |
| 405 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 406 | func (oFsm *lockStateFsm) performUniPortAdminSet(ctx context.Context) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 407 | var omciAdminState uint8 = 1 //default locked |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 408 | oFsm.mutexAdminState.RLock() |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 409 | if !oFsm.adminState { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 410 | omciAdminState = 0 |
| 411 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 412 | oFsm.mutexAdminState.RUnlock() |
Holger Hildebrandt | 2fb7089 | 2020-10-28 11:53:18 +0000 | [diff] [blame] | 413 | //set PPTPEthUni or VEIP AdminState |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 414 | requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState} |
| 415 | |
| 416 | for uniNo, uniPort := range oFsm.pOmciCC.pBaseDeviceHandler.uniEntityMap { |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 417 | // only unlock the UniPort in case it is defined for usage (R2.6 limit only one port), |
| 418 | // compare also limitation for logical voltha port in dh.enableUniPortStateUpdate() |
Matteo Scandolo | 20d180c | 2021-06-10 17:20:21 +0200 | [diff] [blame] | 419 | |
| 420 | 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] | 421 | var meInstance *me.ManagedEntity |
| 422 | if uniPort.portType == uniPPTP { |
| 423 | logger.Debugw(ctx, "Setting PPTP admin state", log.Fields{ |
| 424 | "device-id": oFsm.deviceID, "for PortNo": uniNo, "state (0-unlock)": omciAdminState}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 425 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 426 | meInstance, err := oFsm.pOmciCC.sendSetPptpEthUniLS(log.WithSpanFromContext(context.TODO(), ctx), |
| 427 | uniPort.entityID, oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 428 | true, requestedAttributes, oFsm.pAdaptFsm.commChan) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 429 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 430 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 431 | logger.Errorw(ctx, "SetPptpEthUniLS set failed, aborting LockStateFsm!", |
| 432 | log.Fields{"device-id": oFsm.deviceID}) |
| 433 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
| 434 | return |
| 435 | } |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 436 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 437 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 438 | } else if uniPort.portType == uniVEIP { |
| 439 | logger.Debugw(ctx, "Setting VEIP admin state", log.Fields{ |
| 440 | "device-id": oFsm.deviceID, "for PortNo": uniNo, "state (0-unlock)": omciAdminState}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 441 | oFsm.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 442 | meInstance, err := oFsm.pOmciCC.sendSetVeipLS(log.WithSpanFromContext(context.TODO(), ctx), |
| 443 | uniPort.entityID, oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 444 | true, requestedAttributes, oFsm.pAdaptFsm.commChan) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 445 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 446 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 447 | logger.Errorw(ctx, "SetVeipLS set failed, aborting LockStateFsm!", |
| 448 | log.Fields{"device-id": oFsm.deviceID}) |
| 449 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
| 450 | return |
| 451 | } |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 452 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 453 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 454 | } else { |
| 455 | logger.Warnw(ctx, "Unsupported UniTP type - skip", |
| 456 | log.Fields{"device-id": oFsm.deviceID, "Port": uniNo}) |
| 457 | continue |
| 458 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 459 | oFsm.mutexPLastTxMeInstance.RLock() |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 460 | if oFsm.pLastTxMeInstance == nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 461 | oFsm.mutexPLastTxMeInstance.RUnlock() |
mpagenko | b06684f | 2021-03-23 14:39:04 +0000 | [diff] [blame] | 462 | logger.Errorw(ctx, "could not send PortAdmin OMCI message from LockStateFsm", log.Fields{ |
| 463 | "device-id": oFsm.deviceID, "Port": uniNo}) |
| 464 | //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 |
| 465 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
| 466 | return |
| 467 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 468 | oFsm.mutexPLastTxMeInstance.RUnlock() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 469 | |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 470 | //verify response |
| 471 | err := oFsm.waitforOmciResponse(ctx, meInstance) |
| 472 | if err != nil { |
| 473 | logger.Errorw(ctx, "UniTP Admin State set failed, aborting LockState set!", |
| 474 | log.Fields{"device-id": oFsm.deviceID, "Port": uniNo}) |
| 475 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
| 476 | return |
| 477 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 478 | } |
| 479 | } //for all UNI ports |
| 480 | // if Config has been done for all UNI related instances let the FSM proceed |
| 481 | // while we did not check here, if there is some port at all - !? |
mpagenko | 8b5fdd2 | 2020-12-17 17:58:32 +0000 | [diff] [blame] | 482 | 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] | 483 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxUnisResp) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 484 | } |
| 485 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 486 | func (oFsm *lockStateFsm) waitforOmciResponse(ctx context.Context, apMeInstance *me.ManagedEntity) error { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 487 | select { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 488 | // 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] | 489 | // case <-ctx.Done(): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 490 | // 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] | 491 | 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] | 492 | 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] | 493 | 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] | 494 | case success := <-oFsm.omciLockResponseReceived: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 495 | if success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 496 | logger.Debug(ctx, "LockStateFSM uni-set response received") |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 497 | return nil |
| 498 | } |
| 499 | // should not happen so far |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 500 | 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] | 501 | 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] | 502 | } |
| 503 | } |