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 | } |
| 79 | if aAdminState == true { //port locking requested |
| 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 { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [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 |
| 194 | if oFsm.adminState == false { |
| 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 { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [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 { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [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 { |
| 258 | select { |
| 259 | // case <-ctx.Done(): |
| 260 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.pAdaptFsm.deviceID}) |
| 261 | // break loop |
| 262 | case message, ok := <-oFsm.pAdaptFsm.commChan: |
| 263 | if !ok { |
| 264 | logger.Info("LockStateFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 265 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 266 | oFsm.pAdaptFsm.pFsm.Event(uniEvRestart) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 267 | break loop |
| 268 | } |
| 269 | logger.Debugw("LockStateFsm Rx Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 270 | |
| 271 | switch message.Type { |
| 272 | case TestMsg: |
| 273 | msg, _ := message.Data.(TestMessage) |
| 274 | if msg.TestMessageVal == AbortMessageProcessing { |
| 275 | logger.Infow("LockStateFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
| 276 | break loop |
| 277 | } |
| 278 | logger.Warnw("LockStateFsm unknown TestMessage", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "MessageVal": msg.TestMessageVal}) |
| 279 | case OMCI: |
| 280 | msg, _ := message.Data.(OmciMessage) |
| 281 | oFsm.handleOmciLockStateMessage(msg) |
| 282 | default: |
| 283 | logger.Warn("LockStateFsm Rx unknown message", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, |
| 284 | "message.Type": message.Type}) |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | logger.Infow("End LockStateFsm Msg processing", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
| 289 | } |
| 290 | |
| 291 | func (oFsm *LockStateFsm) handleOmciLockStateMessage(msg OmciMessage) { |
| 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 { |
| 298 | logger.Error("LockStateFsm - Omci Msg layer could not be detected for SetResponse") |
| 299 | return |
| 300 | } |
| 301 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 302 | if !msgOk { |
| 303 | logger.Error("LockStateFsm - Omci Msg layer could not be assigned for SetResponse") |
| 304 | return |
| 305 | } |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 306 | 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] | 307 | if msgObj.Result != me.Success { |
| 308 | logger.Errorw("LockStateFsm - Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result}) |
| 309 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 310 | return |
| 311 | } |
| 312 | // compare comments above for CreateResponse (apply also here ...) |
| 313 | if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() && |
| 314 | msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() { |
| 315 | //store the created ME into DB //TODO??? obviously the Python code does not store the config ... |
| 316 | // if, then something like: |
| 317 | //oFsm.pOnuDB.StoreMe(msgObj) |
| 318 | |
| 319 | switch oFsm.pOmciCC.pLastTxMeInstance.GetName() { |
| 320 | case "OnuG": |
| 321 | { // let the FSM proceed ... |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 322 | oFsm.pAdaptFsm.pFsm.Event(uniEvRxOnugResp) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 323 | } |
| 324 | case "UniG", "VEIP": |
| 325 | { // let the PPTP init proceed by stopping the wait function |
| 326 | oFsm.omciLockResponseReceived <- true |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | } else { |
| 331 | logger.Errorw("LockStateFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType}) |
| 332 | return |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | func (oFsm *LockStateFsm) performUniPortAdminSet() { |
| 337 | var omciAdminState uint8 = 1 //default locked |
| 338 | if oFsm.adminState == false { |
| 339 | omciAdminState = 0 |
| 340 | } |
| 341 | //set UNI-G or VEIP AdminState |
| 342 | requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState} |
| 343 | |
| 344 | for uniNo, uniPort := range oFsm.pOmciCC.pBaseDeviceHandler.uniEntityMap { |
| 345 | logger.Debugw("Setting PPTP admin state", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 346 | "device-id": oFsm.pAdaptFsm.deviceID, "for PortNo": uniNo}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 347 | |
| 348 | var meInstance *me.ManagedEntity |
| 349 | if uniPort.portType == UniPPTP { |
| 350 | meInstance = oFsm.pOmciCC.sendSetUniGLS(context.TODO(), uniPort.entityId, ConstDefaultOmciTimeout, |
| 351 | true, requestedAttributes, oFsm.pAdaptFsm.commChan) |
| 352 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 353 | } else if uniPort.portType == UniVEIP { |
| 354 | meInstance = oFsm.pOmciCC.sendSetVeipLS(context.TODO(), uniPort.entityId, ConstDefaultOmciTimeout, |
| 355 | true, requestedAttributes, oFsm.pAdaptFsm.commChan) |
| 356 | oFsm.pOmciCC.pLastTxMeInstance = meInstance |
| 357 | } else { |
| 358 | logger.Warnw("Unsupported PPTP type - skip", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 359 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo}) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 360 | continue |
| 361 | } |
| 362 | |
| 363 | //verify response |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 364 | err := oFsm.waitforOmciResponse(meInstance) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 365 | if err != nil { |
| 366 | logger.Errorw("PPTP Admin State set failed, aborting LockState set!", |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 367 | log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo}) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 368 | oFsm.pAdaptFsm.pFsm.Event(uniEvReset) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 369 | return |
| 370 | } |
| 371 | } //for all UNI ports |
| 372 | // if Config has been done for all UNI related instances let the FSM proceed |
| 373 | // while we did not check here, if there is some port at all - !? |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 374 | logger.Infow("PPTP config loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID}) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 375 | oFsm.pAdaptFsm.pFsm.Event(uniEvRxUnisResp) |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 376 | return |
| 377 | } |
| 378 | |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 379 | func (oFsm *LockStateFsm) waitforOmciResponse(apMeInstance *me.ManagedEntity) error { |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 380 | select { |
| 381 | // maybe be also some outside cancel (but no context modelled for the moment ...) |
| 382 | // case <-ctx.Done(): |
| 383 | // 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] | 384 | 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] | 385 | logger.Warnw("LockStateFSM uni-set timeout", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
| 386 | return errors.New("LockStateFsm uni-set timeout") |
| 387 | case success := <-oFsm.omciLockResponseReceived: |
| 388 | if success == true { |
| 389 | logger.Debug("LockStateFSM uni-set response received") |
| 390 | return nil |
| 391 | } |
| 392 | // should not happen so far |
| 393 | logger.Warnw("LockStateFSM uni-set response error", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID}) |
| 394 | return errors.New("LockStateFsm uni-set responseError") |
| 395 | } |
| 396 | } |