blob: d196b738a617cefeb36a6a291e1db7f049392d17 [file] [log] [blame]
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001/*
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
18package adaptercoreonu
19
20import (
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
Himani Chawla6d2ae152020-09-02 13:11:20 +053035//lockStateFsm defines the structure for the state machine to lock/unlock the ONU UNI ports via OMCI
36type lockStateFsm struct {
37 pOmciCC *omciCC
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000038 adminState bool
39 requestEvent OnuDeviceEvent
40 omciLockResponseReceived chan bool //seperate channel needed for checking UNI port OMCi message responses
41 pAdaptFsm *AdapterFsm
42}
43
mpagenko1cc3cb42020-07-27 15:24:38 +000044const (
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)
55const (
56 // states of lock/unlock UNI port FSM
57 uniStDisabled = "uniStDisabled"
58 uniStStarting = "uniStStarting"
59 uniStSettingUnis = "uniStSettingUnis"
60 uniStSettingOnuG = "uniStSettingOnuG"
61 uniStAdminDone = "uniStAdminDone"
62 uniStResetting = "uniStResetting"
63)
64
Himani Chawla6d2ae152020-09-02 13:11:20 +053065//newLockStateFsm is the 'constructor' for the state machine to lock/unlock the ONU UNI ports via OMCI
66func newLockStateFsm(apDevOmciCC *omciCC, aAdminState bool, aRequestEvent OnuDeviceEvent,
67 aName string, aDeviceID string, aCommChannel chan Message) *lockStateFsm {
68 instFsm := &lockStateFsm{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000069 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 Chawla4d908332020-08-31 12:30:20 +053079 if aAdminState { //port locking requested
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000080 instFsm.pAdaptFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +000081 uniStDisabled,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000082 fsm.Events{
83
mpagenko1cc3cb42020-07-27 15:24:38 +000084 {Name: uniEvStart, Src: []string{uniStDisabled}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000085
mpagenko1cc3cb42020-07-27 15:24:38 +000086 {Name: uniEvStartAdmin, Src: []string{uniStStarting}, Dst: uniStSettingUnis},
87 // the settingUnis state is used for multi ME config for all UNI related ports
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000088 // 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(?)
mpagenko1cc3cb42020-07-27 15:24:38 +000090 {Name: uniEvRxUnisResp, Src: []string{uniStSettingUnis}, Dst: uniStSettingOnuG},
91 {Name: uniEvRxOnugResp, Src: []string{uniStSettingOnuG}, Dst: uniStAdminDone},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000092
mpagenko1cc3cb42020-07-27 15:24:38 +000093 {Name: uniEvTimeoutSimple, Src: []string{uniStSettingOnuG}, Dst: uniStStarting},
94 {Name: uniEvTimeoutUnis, Src: []string{uniStSettingUnis}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000095
mpagenko1cc3cb42020-07-27 15:24:38 +000096 {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 Hildebrandtccd390c2020-05-29 13:49:04 +0000101 },
102
103 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000104 "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 Hildebrandtccd390c2020-05-29 13:49:04 +0000110 },
111 )
112 } else { //port unlocking requested
113 instFsm.pAdaptFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000114 uniStDisabled,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000115 fsm.Events{
116
mpagenko1cc3cb42020-07-27 15:24:38 +0000117 {Name: uniEvStart, Src: []string{uniStDisabled}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000118
mpagenko1cc3cb42020-07-27 15:24:38 +0000119 {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 Hildebrandtccd390c2020-05-29 13:49:04 +0000122 // 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(?)
mpagenko1cc3cb42020-07-27 15:24:38 +0000124 {Name: uniEvRxUnisResp, Src: []string{uniStSettingUnis}, Dst: uniStAdminDone},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000125
mpagenko1cc3cb42020-07-27 15:24:38 +0000126 {Name: uniEvTimeoutSimple, Src: []string{uniStSettingOnuG}, Dst: uniStStarting},
127 {Name: uniEvTimeoutUnis, Src: []string{uniStSettingUnis}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000128
mpagenko1cc3cb42020-07-27 15:24:38 +0000129 {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 Hildebrandtccd390c2020-05-29 13:49:04 +0000134 },
135
136 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000137 "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 Hildebrandtccd390c2020-05-29 13:49:04 +0000143 },
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
Himani Chawla6d2ae152020-09-02 13:11:20 +0530156//setSuccessEvent modifies the requested event notified on success
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000157//assumption is that this is only called in the disabled (idle) state of the FSM, hence no sem protection required
Himani Chawla6d2ae152020-09-02 13:11:20 +0530158func (oFsm *lockStateFsm) setSuccessEvent(aEvent OnuDeviceEvent) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000159 oFsm.requestEvent = aEvent
160}
161
Himani Chawla6d2ae152020-09-02 13:11:20 +0530162func (oFsm *lockStateFsm) enterAdminStartingState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000163 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
Himani Chawla6d2ae152020-09-02 13:11:20 +0530178 go oFsm.processOmciLockMessages()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000179
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 Chawla4d908332020-08-31 12:30:20 +0530186 _ = a_pAFsm.pFsm.Event(uniEvStartAdmin)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000187 }
188 }(pLockStateAFsm)
189 }
190}
191
Himani Chawla6d2ae152020-09-02 13:11:20 +0530192func (oFsm *lockStateFsm) enterSettingOnuGState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000193 var omciAdminState uint8 = 1 //default locked
Himani Chawla4d908332020-08-31 12:30:20 +0530194 if !oFsm.adminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000195 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
Himani Chawla6d2ae152020-09-02 13:11:20 +0530209func (oFsm *lockStateFsm) enterSettingUnisState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000210 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
Himani Chawla6d2ae152020-09-02 13:11:20 +0530215func (oFsm *lockStateFsm) enterAdminDoneState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000216 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
Himani Chawla6d2ae152020-09-02 13:11:20 +0530218 oFsm.pOmciCC.pBaseDeviceHandler.deviceProcStatusUpdate(oFsm.requestEvent)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000219 //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 Chawla4d908332020-08-31 12:30:20 +0530225 _ = a_pAFsm.pFsm.Event(uniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000226 }
227 }(pLockStateAFsm)
228 }
229}
230
Himani Chawla6d2ae152020-09-02 13:11:20 +0530231func (oFsm *lockStateFsm) enterResettingState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000232 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 Chawla4d908332020-08-31 12:30:20 +0530248 _ = a_pAFsm.pFsm.Event(uniEvRestart)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000249 }
250 }(pLockStateAFsm)
251 }
252}
253
Himani Chawla6d2ae152020-09-02 13:11:20 +0530254func (oFsm *lockStateFsm) processOmciLockMessages( /*ctx context.Context*/ ) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000255 logger.Debugw("Start LockStateFsm Msg processing", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
256loop:
257 for {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000258 // 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 Chawla4d908332020-08-31 12:30:20 +0530261 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 Hildebrandtccd390c2020-05-29 13:49:04 +0000275 break loop
276 }
Himani Chawla4d908332020-08-31 12:30:20 +0530277 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 Hildebrandtccd390c2020-05-29 13:49:04 +0000284 }
285 }
286 logger.Infow("End LockStateFsm Msg processing", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
287}
288
Himani Chawla6d2ae152020-09-02 13:11:20 +0530289func (oFsm *lockStateFsm) handleOmciLockStateMessage(msg OmciMessage) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000290 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 }
divyadesai4d299552020-08-18 07:13:49 +0000304 logger.Debugw("LockStateFsm SetResponse Data", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000305 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 Chawla4d908332020-08-31 12:30:20 +0530320 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxOnugResp)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000321 }
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
Himani Chawla6d2ae152020-09-02 13:11:20 +0530334func (oFsm *lockStateFsm) performUniPortAdminSet() {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000335 var omciAdminState uint8 = 1 //default locked
Himani Chawla4d908332020-08-31 12:30:20 +0530336 if !oFsm.adminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000337 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{
divyadesai4d299552020-08-18 07:13:49 +0000344 "device-id": oFsm.pAdaptFsm.deviceID, "for PortNo": uniNo})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000345
346 var meInstance *me.ManagedEntity
Himani Chawla6d2ae152020-09-02 13:11:20 +0530347 if uniPort.portType == uniPPTP {
Himani Chawla26e555c2020-08-31 12:30:20 +0530348 meInstance = oFsm.pOmciCC.sendSetUniGLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000349 true, requestedAttributes, oFsm.pAdaptFsm.commChan)
350 oFsm.pOmciCC.pLastTxMeInstance = meInstance
Himani Chawla6d2ae152020-09-02 13:11:20 +0530351 } else if uniPort.portType == uniVEIP {
Himani Chawla26e555c2020-08-31 12:30:20 +0530352 meInstance = oFsm.pOmciCC.sendSetVeipLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000353 true, requestedAttributes, oFsm.pAdaptFsm.commChan)
354 oFsm.pOmciCC.pLastTxMeInstance = meInstance
355 } else {
356 logger.Warnw("Unsupported PPTP type - skip",
divyadesai4d299552020-08-18 07:13:49 +0000357 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000358 continue
359 }
360
361 //verify response
mpagenko3af1f032020-06-10 08:53:41 +0000362 err := oFsm.waitforOmciResponse(meInstance)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000363 if err != nil {
364 logger.Errorw("PPTP Admin State set failed, aborting LockState set!",
divyadesai4d299552020-08-18 07:13:49 +0000365 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo})
Himani Chawla4d908332020-08-31 12:30:20 +0530366 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000367 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 - !?
divyadesai4d299552020-08-18 07:13:49 +0000372 logger.Infow("PPTP config loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530373 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxUnisResp)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000374}
375
Himani Chawla6d2ae152020-09-02 13:11:20 +0530376func (oFsm *lockStateFsm) waitforOmciResponse(apMeInstance *me.ManagedEntity) error {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000377 select {
Himani Chawla4d908332020-08-31 12:30:20 +0530378 // maybe be also some outside cancel (but no context modeled for the moment ...)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000379 // case <-ctx.Done():
380 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
mpagenko3af1f032020-06-10 08:53:41 +0000381 case <-time.After(30 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000382 logger.Warnw("LockStateFSM uni-set timeout", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530383 return errors.New("lockStateFsm uni-set timeout")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000384 case success := <-oFsm.omciLockResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +0530385 if success {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000386 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})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530391 return errors.New("lockStateFsm uni-set responseError")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000392 }
393}