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