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" |
Andrea Campanella | ab7b6a5 | 2020-10-06 16:17:13 +0200 | [diff] [blame^] | 231 | //ConnState is reachable given the fact that no cable was pulled and it can be re-enabled through OMCI. |
| 232 | logger.Debugw("call DeviceStateUpdate", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE, |
| 233 | "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": oFsm.pDeviceHandler.deviceID, "reason": oFsm.pDeviceHandler.deviceReason}) |
| 234 | if err := oFsm.pDeviceHandler.coreProxy.DeviceReasonUpdate(context.TODO(), oFsm.pDeviceHandler.deviceID, |
| 235 | oFsm.pDeviceHandler.deviceReason); err != nil { |
| 236 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 237 | logger.Errorw("error-updating-device-reason", log.Fields{"device-id": oFsm.pDeviceHandler.deviceID, "error": err}) |
| 238 | } |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 239 | if err := oFsm.pDeviceHandler.coreProxy.DeviceStateUpdate(context.TODO(), oFsm.pDeviceHandler.deviceID, |
Andrea Campanella | ab7b6a5 | 2020-10-06 16:17:13 +0200 | [diff] [blame^] | 240 | voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN); err != nil { |
Holger Hildebrandt | 8165eda | 2020-09-24 09:39:24 +0000 | [diff] [blame] | 241 | //TODO with VOL-3045/VOL-3046: return the error and stop further processing |
| 242 | logger.Errorw("error-updating-device-state", log.Fields{"device-id": oFsm.pDeviceHandler.deviceID, "error": err}) |
| 243 | } |
| 244 | } |
| 245 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 246 | //let's reset the state machine in order to release all resources now |
| 247 | pLockStateAFsm := oFsm.pAdaptFsm |
| 248 | if pLockStateAFsm != nil { |
| 249 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 250 | go func(a_pAFsm *AdapterFsm) { |
| 251 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 252 | _ = a_pAFsm.pFsm.Event(uniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 253 | } |
| 254 | }(pLockStateAFsm) |
| 255 | } |
| 256 | } |
| 257 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 258 | func (oFsm *lockStateFsm) enterResettingState(e *fsm.Event) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 259 | logger.Debugw("LockStateFSM resetting", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 260 | pLockStateAFsm := oFsm.pAdaptFsm |
| 261 | if pLockStateAFsm != nil { |
| 262 | // abort running message processing |
| 263 | fsmAbortMsg := Message{ |
| 264 | Type: TestMsg, |
| 265 | Data: TestMessage{ |
| 266 | TestMessageVal: AbortMessageProcessing, |
| 267 | }, |
| 268 | } |
| 269 | pLockStateAFsm.commChan <- fsmAbortMsg |
| 270 | |
| 271 | //try to restart the FSM to 'disabled' |
| 272 | // see DownloadedState: decouple event transfer |
| 273 | go func(a_pAFsm *AdapterFsm) { |
| 274 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 275 | _ = a_pAFsm.pFsm.Event(uniEvRestart) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 276 | } |
| 277 | }(pLockStateAFsm) |
| 278 | } |
| 279 | } |
| 280 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 281 | func (oFsm *lockStateFsm) processOmciLockMessages( /*ctx context.Context*/ ) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 282 | logger.Debugw("Start LockStateFsm Msg processing", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
| 283 | loop: |
| 284 | for { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 285 | // case <-ctx.Done(): |
| 286 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.pAdaptFsm.deviceID}) |
| 287 | // break loop |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 288 | message, ok := <-oFsm.pAdaptFsm.commChan |
| 289 | if !ok { |
| 290 | logger.Info("LockStateFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 291 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
| 292 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRestart) |
| 293 | break loop |
| 294 | } |
| 295 | logger.Debugw("LockStateFsm Rx Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 296 | |
| 297 | switch message.Type { |
| 298 | case TestMsg: |
| 299 | msg, _ := message.Data.(TestMessage) |
| 300 | if msg.TestMessageVal == AbortMessageProcessing { |
| 301 | 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] | 302 | break loop |
| 303 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 304 | logger.Warnw("LockStateFsm unknown TestMessage", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "MessageVal": msg.TestMessageVal}) |
| 305 | case OMCI: |
| 306 | msg, _ := message.Data.(OmciMessage) |
| 307 | oFsm.handleOmciLockStateMessage(msg) |
| 308 | default: |
| 309 | logger.Warn("LockStateFsm Rx unknown message", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, |
| 310 | "message.Type": message.Type}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | logger.Infow("End LockStateFsm Msg processing", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 314 | } |
| 315 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 316 | func (oFsm *lockStateFsm) handleOmciLockStateMessage(msg OmciMessage) { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 317 | logger.Debugw("Rx OMCI LockStateFsm Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, |
| 318 | "msgType": msg.OmciMsg.MessageType}) |
| 319 | |
| 320 | if msg.OmciMsg.MessageType == omci.SetResponseType { |
| 321 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 322 | if msgLayer == nil { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 323 | logger.Errorw("LockStateFsm - Omci Msg layer could not be detected for SetResponse", |
| 324 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 325 | return |
| 326 | } |
| 327 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 328 | if !msgOk { |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 329 | logger.Errorw("LockStateFsm - Omci Msg layer could not be assigned for SetResponse", |
| 330 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 331 | return |
| 332 | } |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 333 | 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] | 334 | if msgObj.Result != me.Success { |
| 335 | logger.Errorw("LockStateFsm - Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result}) |
| 336 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 337 | return |
| 338 | } |
| 339 | // compare comments above for CreateResponse (apply also here ...) |
| 340 | if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() && |
| 341 | msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() { |
| 342 | //store the created ME into DB //TODO??? obviously the Python code does not store the config ... |
| 343 | // if, then something like: |
| 344 | //oFsm.pOnuDB.StoreMe(msgObj) |
| 345 | |
| 346 | switch oFsm.pOmciCC.pLastTxMeInstance.GetName() { |
| 347 | case "OnuG": |
| 348 | { // let the FSM proceed ... |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 349 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxOnugResp) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 350 | } |
| 351 | case "UniG", "VEIP": |
| 352 | { // let the PPTP init proceed by stopping the wait function |
| 353 | oFsm.omciLockResponseReceived <- true |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | } else { |
| 358 | logger.Errorw("LockStateFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType}) |
| 359 | return |
| 360 | } |
| 361 | } |
| 362 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 363 | func (oFsm *lockStateFsm) performUniPortAdminSet() { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 364 | var omciAdminState uint8 = 1 //default locked |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 365 | if !oFsm.adminState { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 366 | omciAdminState = 0 |
| 367 | } |
| 368 | //set UNI-G or VEIP AdminState |
| 369 | requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState} |
| 370 | |
| 371 | for uniNo, uniPort := range oFsm.pOmciCC.pBaseDeviceHandler.uniEntityMap { |
| 372 | logger.Debugw("Setting PPTP admin state", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 373 | "device-id": oFsm.pAdaptFsm.deviceID, "for PortNo": uniNo}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 374 | |
| 375 | var meInstance *me.ManagedEntity |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 376 | if uniPort.portType == uniPPTP { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 377 | meInstance = oFsm.pOmciCC.sendSetUniGLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 378 | true, requestedAttributes, oFsm.pAdaptFsm.commChan) |
| 379 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 380 | } else if uniPort.portType == uniVEIP { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 381 | meInstance = oFsm.pOmciCC.sendSetVeipLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 382 | true, requestedAttributes, oFsm.pAdaptFsm.commChan) |
| 383 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 384 | } else { |
| 385 | logger.Warnw("Unsupported PPTP type - skip", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 386 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 387 | continue |
| 388 | } |
| 389 | |
| 390 | //verify response |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 391 | err := oFsm.waitforOmciResponse(meInstance) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 392 | if err != nil { |
| 393 | logger.Errorw("PPTP Admin State set failed, aborting LockState set!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 394 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 395 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 396 | return |
| 397 | } |
| 398 | } //for all UNI ports |
| 399 | // if Config has been done for all UNI related instances let the FSM proceed |
| 400 | // while we did not check here, if there is some port at all - !? |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 401 | 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] | 402 | _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxUnisResp) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 405 | func (oFsm *lockStateFsm) waitforOmciResponse(apMeInstance *me.ManagedEntity) error { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 406 | select { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 407 | // 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] | 408 | // case <-ctx.Done(): |
| 409 | // 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] | 410 | 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] | 411 | 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] | 412 | 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] | 413 | case success := <-oFsm.omciLockResponseReceived: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 414 | if success { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 415 | logger.Debug("LockStateFSM uni-set response received") |
| 416 | return nil |
| 417 | } |
| 418 | // should not happen so far |
| 419 | 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] | 420 | 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] | 421 | } |
| 422 | } |