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 | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 23 | "time" |
| 24 | |
| 25 | "github.com/looplab/fsm" |
| 26 | |
| 27 | "github.com/opencord/omci-lib-go" |
| 28 | me "github.com/opencord/omci-lib-go/generated" |
| 29 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 30 | //ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 31 | //"github.com/opencord/voltha-protos/v3/go/openflow_13" |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 32 | ) |
| 33 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 34 | //lockStateFsm defines the structure for the state machine to lock/unlock the ONU UNI ports via OMCI |
| 35 | type lockStateFsm struct { |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 36 | pDeviceHandler *deviceHandler |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 37 | pOmciCC *omciCC |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 38 | adminState bool |
| 39 | requestEvent OnuDeviceEvent |
| 40 | omciLockResponseReceived chan bool //seperate channel needed for checking UNI port OMCi message responses |
| 41 | pAdaptFsm *AdapterFsm |
| 42 | } |
| 43 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 44 | const ( |
| 45 | // events of lock/unlock UNI port FSM |
| 46 | uniEvStart = "uniEvStart" |
| 47 | uniEvStartAdmin = "uniEvStartAdmin" |
| 48 | uniEvRxUnisResp = "uniEvRxUnisResp" |
| 49 | uniEvRxOnugResp = "uniEvRxOnugResp" |
| 50 | uniEvTimeoutSimple = "uniEvTimeoutSimple" |
| 51 | uniEvTimeoutUnis = "uniEvTimeoutUnis" |
| 52 | uniEvReset = "uniEvReset" |
| 53 | uniEvRestart = "uniEvRestart" |
| 54 | ) |
| 55 | const ( |
| 56 | // states of lock/unlock UNI port FSM |
| 57 | uniStDisabled = "uniStDisabled" |
| 58 | uniStStarting = "uniStStarting" |
| 59 | uniStSettingUnis = "uniStSettingUnis" |
| 60 | uniStSettingOnuG = "uniStSettingOnuG" |
| 61 | uniStAdminDone = "uniStAdminDone" |
| 62 | uniStResetting = "uniStResetting" |
| 63 | ) |
| 64 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 65 | //newLockStateFsm is the 'constructor' for the state machine to lock/unlock the ONU UNI ports via OMCI |
| 66 | func newLockStateFsm(apDevOmciCC *omciCC, aAdminState bool, aRequestEvent OnuDeviceEvent, |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 67 | aName string, apDeviceHandler *deviceHandler, aCommChannel chan Message) *lockStateFsm { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 68 | instFsm := &lockStateFsm{ |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 69 | pDeviceHandler: apDeviceHandler, |
| 70 | pOmciCC: apDevOmciCC, |
| 71 | adminState: aAdminState, |
| 72 | requestEvent: aRequestEvent, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 73 | } |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 74 | instFsm.pAdaptFsm = NewAdapterFsm(aName, apDeviceHandler.deviceID, aCommChannel) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 75 | if instFsm.pAdaptFsm == nil { |
| 76 | logger.Errorw("LockStateFsm's AdapterFsm could not be instantiated!!", log.Fields{ |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 77 | "device-id": apDeviceHandler.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 78 | return nil |
| 79 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 80 | if aAdminState { //port locking requested |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 81 | instFsm.pAdaptFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 82 | uniStDisabled, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 83 | fsm.Events{ |
| 84 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 85 | {Name: uniEvStart, Src: []string{uniStDisabled}, Dst: uniStStarting}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 86 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 87 | {Name: uniEvStartAdmin, Src: []string{uniStStarting}, Dst: uniStSettingUnis}, |
| 88 | // 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] | 89 | // maybe such could be reflected in the state machine as well (port number parametrized) |
| 90 | // 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] | 91 | {Name: uniEvRxUnisResp, Src: []string{uniStSettingUnis}, Dst: uniStSettingOnuG}, |
| 92 | {Name: uniEvRxOnugResp, Src: []string{uniStSettingOnuG}, Dst: uniStAdminDone}, |
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: uniEvTimeoutSimple, Src: []string{uniStSettingOnuG}, Dst: uniStStarting}, |
| 95 | {Name: uniEvTimeoutUnis, Src: []string{uniStSettingUnis}, Dst: uniStStarting}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 96 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 97 | {Name: uniEvReset, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis, |
| 98 | uniStAdminDone}, Dst: uniStResetting}, |
| 99 | // exceptional treatment for all states except uniStResetting |
| 100 | {Name: uniEvRestart, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis, |
| 101 | uniStAdminDone, uniStResetting}, Dst: uniStDisabled}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 102 | }, |
| 103 | |
| 104 | fsm.Callbacks{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 105 | "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(e) }, |
| 106 | ("enter_" + uniStStarting): func(e *fsm.Event) { instFsm.enterAdminStartingState(e) }, |
| 107 | ("enter_" + uniStSettingOnuG): func(e *fsm.Event) { instFsm.enterSettingOnuGState(e) }, |
| 108 | ("enter_" + uniStSettingUnis): func(e *fsm.Event) { instFsm.enterSettingUnisState(e) }, |
| 109 | ("enter_" + uniStAdminDone): func(e *fsm.Event) { instFsm.enterAdminDoneState(e) }, |
| 110 | ("enter_" + uniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(e) }, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 111 | }, |
| 112 | ) |
| 113 | } else { //port unlocking requested |
| 114 | instFsm.pAdaptFsm.pFsm = fsm.NewFSM( |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 115 | uniStDisabled, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 116 | fsm.Events{ |
| 117 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 118 | {Name: uniEvStart, Src: []string{uniStDisabled}, Dst: uniStStarting}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 119 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 120 | {Name: uniEvStartAdmin, Src: []string{uniStStarting}, Dst: uniStSettingOnuG}, |
| 121 | {Name: uniEvRxOnugResp, Src: []string{uniStSettingOnuG}, Dst: uniStSettingUnis}, |
| 122 | // 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] | 123 | // maybe such could be reflected in the state machine as well (port number parametrized) |
| 124 | // 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] | 125 | {Name: uniEvRxUnisResp, Src: []string{uniStSettingUnis}, Dst: uniStAdminDone}, |
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: uniEvTimeoutSimple, Src: []string{uniStSettingOnuG}, Dst: uniStStarting}, |
| 128 | {Name: uniEvTimeoutUnis, Src: []string{uniStSettingUnis}, Dst: uniStStarting}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 129 | |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 130 | {Name: uniEvReset, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis, |
| 131 | uniStAdminDone}, Dst: uniStResetting}, |
| 132 | // exceptional treatment for all states except uniStResetting |
| 133 | {Name: uniEvRestart, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis, |
| 134 | uniStAdminDone, uniStResetting}, Dst: uniStDisabled}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 135 | }, |
| 136 | |
| 137 | fsm.Callbacks{ |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 138 | "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(e) }, |
| 139 | ("enter_" + uniStStarting): func(e *fsm.Event) { instFsm.enterAdminStartingState(e) }, |
| 140 | ("enter_" + uniStSettingOnuG): func(e *fsm.Event) { instFsm.enterSettingOnuGState(e) }, |
| 141 | ("enter_" + uniStSettingUnis): func(e *fsm.Event) { instFsm.enterSettingUnisState(e) }, |
| 142 | ("enter_" + uniStAdminDone): func(e *fsm.Event) { instFsm.enterAdminDoneState(e) }, |
| 143 | ("enter_" + uniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(e) }, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 144 | }, |
| 145 | ) |
| 146 | } |
| 147 | if instFsm.pAdaptFsm.pFsm == nil { |
| 148 | logger.Errorw("LockStateFsm's Base FSM could not be instantiated!!", log.Fields{ |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 149 | "device-id": apDeviceHandler.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 150 | return nil |
| 151 | } |
| 152 | |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 153 | logger.Infow("LockStateFsm created", log.Fields{"device-id": apDeviceHandler.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 154 | return instFsm |
| 155 | } |
| 156 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 157 | //setSuccessEvent modifies the requested event notified on success |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 158 | //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] | 159 | func (oFsm *lockStateFsm) setSuccessEvent(aEvent OnuDeviceEvent) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 160 | oFsm.requestEvent = aEvent |
| 161 | } |
| 162 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 163 | func (oFsm *lockStateFsm) enterAdminStartingState(e *fsm.Event) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 164 | logger.Debugw("LockStateFSM start", log.Fields{"in state": e.FSM.Current(), |
| 165 | "device-id": oFsm.pAdaptFsm.deviceID}) |
| 166 | // in case the used channel is not yet defined (can be re-used after restarts) |
| 167 | if oFsm.omciLockResponseReceived == nil { |
| 168 | oFsm.omciLockResponseReceived = make(chan bool) |
| 169 | logger.Debug("LockStateFSM - OMCI UniLock RxChannel defined") |
| 170 | } else { |
| 171 | // as we may 're-use' this instance of FSM and the connected channel |
| 172 | // make sure there is no 'lingering' request in the already existing channel: |
| 173 | // (simple loop sufficient as we are the only receiver) |
| 174 | for len(oFsm.omciLockResponseReceived) > 0 { |
| 175 | <-oFsm.omciLockResponseReceived |
| 176 | } |
| 177 | } |
| 178 | // start go routine for processing of LockState messages |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 179 | go oFsm.processOmciLockMessages() |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 180 | |
| 181 | //let the state machine run forward from here directly |
| 182 | pLockStateAFsm := oFsm.pAdaptFsm |
| 183 | if pLockStateAFsm != nil { |
| 184 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 185 | go func(a_pAFsm *AdapterFsm) { |
| 186 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 187 | _ = a_pAFsm.pFsm.Event(uniEvStartAdmin) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 188 | } |
| 189 | }(pLockStateAFsm) |
| 190 | } |
| 191 | } |
| 192 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 193 | func (oFsm *lockStateFsm) enterSettingOnuGState(e *fsm.Event) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 194 | var omciAdminState uint8 = 1 //default locked |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 195 | if !oFsm.adminState { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 196 | omciAdminState = 0 |
| 197 | } |
| 198 | logger.Debugw("LockStateFSM Tx Set::ONU-G:admin", log.Fields{ |
| 199 | "omciAdmin": omciAdminState, "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 200 | requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState} |
| 201 | meInstance := oFsm.pOmciCC.sendSetOnuGLS(context.TODO(), ConstDefaultOmciTimeout, true, |
| 202 | requestedAttributes, oFsm.pAdaptFsm.commChan) |
| 203 | //accept also nil as (error) return value for writing to LastTx |
| 204 | // - this avoids misinterpretation of new received OMCI messages |
| 205 | // we might already abort the processing with nil here, but maybe some auto-recovery may be tried |
| 206 | // - may be improved later, for now we just handle it with the Rx timeout or missing next event (stick in state) |
| 207 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 208 | } |
| 209 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 210 | func (oFsm *lockStateFsm) enterSettingUnisState(e *fsm.Event) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 211 | logger.Infow("LockStateFSM - starting PPTP config loop", log.Fields{ |
| 212 | "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID, "LockState": oFsm.adminState}) |
| 213 | go oFsm.performUniPortAdminSet() |
| 214 | } |
| 215 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 216 | func (oFsm *lockStateFsm) enterAdminDoneState(e *fsm.Event) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 217 | logger.Debugw("LockStateFSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID}) |
| 218 | //use DeviceHandler event notification directly, no need/support to update DeviceEntryState for lock/unlock |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 219 | oFsm.pOmciCC.pBaseDeviceHandler.deviceProcStatusUpdate(oFsm.requestEvent) |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 220 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 221 | //let's reset the state machine in order to release all resources now |
| 222 | pLockStateAFsm := oFsm.pAdaptFsm |
| 223 | if pLockStateAFsm != nil { |
| 224 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 225 | go func(a_pAFsm *AdapterFsm) { |
| 226 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 227 | _ = a_pAFsm.pFsm.Event(uniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 228 | } |
| 229 | }(pLockStateAFsm) |
| 230 | } |
| 231 | } |
| 232 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 233 | func (oFsm *lockStateFsm) enterResettingState(e *fsm.Event) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 234 | logger.Debugw("LockStateFSM resetting", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 235 | pLockStateAFsm := oFsm.pAdaptFsm |
| 236 | if pLockStateAFsm != nil { |
| 237 | // abort running message processing |
| 238 | fsmAbortMsg := Message{ |
| 239 | Type: TestMsg, |
| 240 | Data: TestMessage{ |
| 241 | TestMessageVal: AbortMessageProcessing, |
| 242 | }, |
| 243 | } |
| 244 | pLockStateAFsm.commChan <- fsmAbortMsg |
| 245 | |
| 246 | //try to restart the FSM to 'disabled' |
| 247 | // see DownloadedState: decouple event transfer |
| 248 | go func(a_pAFsm *AdapterFsm) { |
| 249 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 250 | _ = a_pAFsm.pFsm.Event(uniEvRestart) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 251 | } |
| 252 | }(pLockStateAFsm) |
| 253 | } |
| 254 | } |
| 255 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 256 | func (oFsm *lockStateFsm) processOmciLockMessages( /*ctx context.Context*/ ) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 257 | logger.Debugw("Start LockStateFsm Msg processing", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
| 258 | loop: |
| 259 | for { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 260 | // case <-ctx.Done(): |
| 261 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.pAdaptFsm.deviceID}) |
| 262 | // break loop |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 263 | message, ok := <-oFsm.pAdaptFsm.commChan |
| 264 | if !ok { |
| 265 | logger.Info("LockStateFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 266 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
| 267 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRestart) |
| 268 | break loop |
| 269 | } |
| 270 | logger.Debugw("LockStateFsm Rx Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 271 | |
| 272 | switch message.Type { |
| 273 | case TestMsg: |
| 274 | msg, _ := message.Data.(TestMessage) |
| 275 | if msg.TestMessageVal == AbortMessageProcessing { |
| 276 | logger.Infow("LockStateFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 277 | break loop |
| 278 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 279 | logger.Warnw("LockStateFsm unknown TestMessage", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "MessageVal": msg.TestMessageVal}) |
| 280 | case OMCI: |
| 281 | msg, _ := message.Data.(OmciMessage) |
| 282 | oFsm.handleOmciLockStateMessage(msg) |
| 283 | default: |
| 284 | logger.Warn("LockStateFsm Rx unknown message", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, |
| 285 | "message.Type": message.Type}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | logger.Infow("End LockStateFsm Msg processing", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 289 | } |
| 290 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 291 | func (oFsm *lockStateFsm) handleOmciLockStateMessage(msg OmciMessage) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 292 | logger.Debugw("Rx OMCI LockStateFsm Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, |
| 293 | "msgType": msg.OmciMsg.MessageType}) |
| 294 | |
| 295 | if msg.OmciMsg.MessageType == omci.SetResponseType { |
| 296 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 297 | if msgLayer == nil { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 298 | logger.Errorw("LockStateFsm - Omci Msg layer could not be detected for SetResponse", |
| 299 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 300 | return |
| 301 | } |
| 302 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 303 | if !msgOk { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 304 | logger.Errorw("LockStateFsm - Omci Msg layer could not be assigned for SetResponse", |
| 305 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 306 | return |
| 307 | } |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 308 | logger.Debugw("LockStateFsm SetResponse Data", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 309 | if msgObj.Result != me.Success { |
| 310 | logger.Errorw("LockStateFsm - Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result}) |
| 311 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 312 | return |
| 313 | } |
| 314 | // compare comments above for CreateResponse (apply also here ...) |
| 315 | if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() && |
| 316 | msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() { |
| 317 | //store the created ME into DB //TODO??? obviously the Python code does not store the config ... |
| 318 | // if, then something like: |
| 319 | //oFsm.pOnuDB.StoreMe(msgObj) |
| 320 | |
| 321 | switch oFsm.pOmciCC.pLastTxMeInstance.GetName() { |
| 322 | case "OnuG": |
| 323 | { // let the FSM proceed ... |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 324 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxOnugResp) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 325 | } |
| 326 | case "UniG", "VEIP": |
| 327 | { // let the PPTP init proceed by stopping the wait function |
| 328 | oFsm.omciLockResponseReceived <- true |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | } else { |
| 333 | logger.Errorw("LockStateFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType}) |
| 334 | return |
| 335 | } |
| 336 | } |
| 337 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 338 | func (oFsm *lockStateFsm) performUniPortAdminSet() { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 339 | var omciAdminState uint8 = 1 //default locked |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 340 | if !oFsm.adminState { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 341 | omciAdminState = 0 |
| 342 | } |
| 343 | //set UNI-G or VEIP AdminState |
| 344 | requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState} |
| 345 | |
| 346 | for uniNo, uniPort := range oFsm.pOmciCC.pBaseDeviceHandler.uniEntityMap { |
| 347 | logger.Debugw("Setting PPTP admin state", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 348 | "device-id": oFsm.pAdaptFsm.deviceID, "for PortNo": uniNo}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 349 | |
| 350 | var meInstance *me.ManagedEntity |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 351 | if uniPort.portType == uniPPTP { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 352 | meInstance = oFsm.pOmciCC.sendSetUniGLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 353 | true, requestedAttributes, oFsm.pAdaptFsm.commChan) |
| 354 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 355 | } else if uniPort.portType == uniVEIP { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 356 | meInstance = oFsm.pOmciCC.sendSetVeipLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 357 | true, requestedAttributes, oFsm.pAdaptFsm.commChan) |
| 358 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 359 | } else { |
| 360 | logger.Warnw("Unsupported PPTP type - skip", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 361 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 362 | continue |
| 363 | } |
| 364 | |
| 365 | //verify response |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 366 | err := oFsm.waitforOmciResponse(meInstance) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 367 | if err != nil { |
| 368 | logger.Errorw("PPTP Admin State set failed, aborting LockState set!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 369 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 370 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 371 | return |
| 372 | } |
| 373 | } //for all UNI ports |
| 374 | // if Config has been done for all UNI related instances let the FSM proceed |
| 375 | // while we did not check here, if there is some port at all - !? |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 376 | logger.Infow("PPTP config loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 377 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxUnisResp) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 378 | } |
| 379 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 380 | func (oFsm *lockStateFsm) waitforOmciResponse(apMeInstance *me.ManagedEntity) error { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 381 | select { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 382 | // 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] | 383 | // case <-ctx.Done(): |
| 384 | // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 385 | case <-time.After(30 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 386 | logger.Warnw("LockStateFSM uni-set timeout", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 387 | return fmt.Errorf("lockStateFsm uni-set timeout for device-id %s", oFsm.pAdaptFsm.deviceID) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 388 | case success := <-oFsm.omciLockResponseReceived: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 389 | if success { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 390 | logger.Debug("LockStateFSM uni-set response received") |
| 391 | return nil |
| 392 | } |
| 393 | // should not happen so far |
| 394 | logger.Warnw("LockStateFSM uni-set response error", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 395 | return fmt.Errorf("lockStateFsm uni-set responseError for device-id %s", oFsm.pAdaptFsm.deviceID) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 396 | } |
| 397 | } |