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