blob: 8a0428ed35ef286f9021f8bf53b201854d84310f [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"
Andrea Campanella6515c582020-10-05 11:25:00 +020022 "fmt"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000023 "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"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000032)
33
Himani Chawla6d2ae152020-09-02 13:11:20 +053034//lockStateFsm defines the structure for the state machine to lock/unlock the ONU UNI ports via OMCI
35type lockStateFsm struct {
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000036 pDeviceHandler *deviceHandler
Himani Chawla6d2ae152020-09-02 13:11:20 +053037 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,
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000067 aName string, apDeviceHandler *deviceHandler, aCommChannel chan Message) *lockStateFsm {
Himani Chawla6d2ae152020-09-02 13:11:20 +053068 instFsm := &lockStateFsm{
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000069 pDeviceHandler: apDeviceHandler,
70 pOmciCC: apDevOmciCC,
71 adminState: aAdminState,
72 requestEvent: aRequestEvent,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000073 }
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000074 instFsm.pAdaptFsm = NewAdapterFsm(aName, apDeviceHandler.deviceID, aCommChannel)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000075 if instFsm.pAdaptFsm == nil {
76 logger.Errorw("LockStateFsm's AdapterFsm could not be instantiated!!", log.Fields{
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000077 "device-id": apDeviceHandler.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000078 return nil
79 }
Himani Chawla4d908332020-08-31 12:30:20 +053080 if aAdminState { //port locking requested
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000081 instFsm.pAdaptFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +000082 uniStDisabled,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000083 fsm.Events{
84
mpagenko1cc3cb42020-07-27 15:24:38 +000085 {Name: uniEvStart, Src: []string{uniStDisabled}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000086
mpagenko1cc3cb42020-07-27 15:24:38 +000087 {Name: uniEvStartAdmin, Src: []string{uniStStarting}, Dst: uniStSettingUnis},
88 // the settingUnis state is used for multi ME config for all UNI related ports
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000089 // maybe such could be reflected in the state machine as well (port number parametrized)
90 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
mpagenko1cc3cb42020-07-27 15:24:38 +000091 {Name: uniEvRxUnisResp, Src: []string{uniStSettingUnis}, Dst: uniStSettingOnuG},
92 {Name: uniEvRxOnugResp, Src: []string{uniStSettingOnuG}, Dst: uniStAdminDone},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000093
mpagenko1cc3cb42020-07-27 15:24:38 +000094 {Name: uniEvTimeoutSimple, Src: []string{uniStSettingOnuG}, Dst: uniStStarting},
95 {Name: uniEvTimeoutUnis, Src: []string{uniStSettingUnis}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000096
mpagenko1cc3cb42020-07-27 15:24:38 +000097 {Name: uniEvReset, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis,
98 uniStAdminDone}, Dst: uniStResetting},
99 // exceptional treatment for all states except uniStResetting
100 {Name: uniEvRestart, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis,
101 uniStAdminDone, uniStResetting}, Dst: uniStDisabled},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000102 },
103
104 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000105 "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(e) },
106 ("enter_" + uniStStarting): func(e *fsm.Event) { instFsm.enterAdminStartingState(e) },
107 ("enter_" + uniStSettingOnuG): func(e *fsm.Event) { instFsm.enterSettingOnuGState(e) },
108 ("enter_" + uniStSettingUnis): func(e *fsm.Event) { instFsm.enterSettingUnisState(e) },
109 ("enter_" + uniStAdminDone): func(e *fsm.Event) { instFsm.enterAdminDoneState(e) },
110 ("enter_" + uniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(e) },
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000111 },
112 )
113 } else { //port unlocking requested
114 instFsm.pAdaptFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000115 uniStDisabled,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000116 fsm.Events{
117
mpagenko1cc3cb42020-07-27 15:24:38 +0000118 {Name: uniEvStart, Src: []string{uniStDisabled}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000119
mpagenko1cc3cb42020-07-27 15:24:38 +0000120 {Name: uniEvStartAdmin, Src: []string{uniStStarting}, Dst: uniStSettingOnuG},
121 {Name: uniEvRxOnugResp, Src: []string{uniStSettingOnuG}, Dst: uniStSettingUnis},
122 // the settingUnis state is used for multi ME config for all UNI related ports
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000123 // maybe such could be reflected in the state machine as well (port number parametrized)
124 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
mpagenko1cc3cb42020-07-27 15:24:38 +0000125 {Name: uniEvRxUnisResp, Src: []string{uniStSettingUnis}, Dst: uniStAdminDone},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000126
mpagenko1cc3cb42020-07-27 15:24:38 +0000127 {Name: uniEvTimeoutSimple, Src: []string{uniStSettingOnuG}, Dst: uniStStarting},
128 {Name: uniEvTimeoutUnis, Src: []string{uniStSettingUnis}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000129
mpagenko1cc3cb42020-07-27 15:24:38 +0000130 {Name: uniEvReset, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis,
131 uniStAdminDone}, Dst: uniStResetting},
132 // exceptional treatment for all states except uniStResetting
133 {Name: uniEvRestart, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis,
134 uniStAdminDone, uniStResetting}, Dst: uniStDisabled},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000135 },
136
137 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000138 "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(e) },
139 ("enter_" + uniStStarting): func(e *fsm.Event) { instFsm.enterAdminStartingState(e) },
140 ("enter_" + uniStSettingOnuG): func(e *fsm.Event) { instFsm.enterSettingOnuGState(e) },
141 ("enter_" + uniStSettingUnis): func(e *fsm.Event) { instFsm.enterSettingUnisState(e) },
142 ("enter_" + uniStAdminDone): func(e *fsm.Event) { instFsm.enterAdminDoneState(e) },
143 ("enter_" + uniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(e) },
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000144 },
145 )
146 }
147 if instFsm.pAdaptFsm.pFsm == nil {
148 logger.Errorw("LockStateFsm's Base FSM could not be instantiated!!", log.Fields{
Holger Hildebrandt8165eda2020-09-24 09:39:24 +0000149 "device-id": apDeviceHandler.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000150 return nil
151 }
152
Holger Hildebrandt8165eda2020-09-24 09:39:24 +0000153 logger.Infow("LockStateFsm created", log.Fields{"device-id": apDeviceHandler.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000154 return instFsm
155}
156
Himani Chawla6d2ae152020-09-02 13:11:20 +0530157//setSuccessEvent modifies the requested event notified on success
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000158//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 +0530159func (oFsm *lockStateFsm) setSuccessEvent(aEvent OnuDeviceEvent) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000160 oFsm.requestEvent = aEvent
161}
162
Himani Chawla6d2ae152020-09-02 13:11:20 +0530163func (oFsm *lockStateFsm) enterAdminStartingState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000164 logger.Debugw("LockStateFSM start", log.Fields{"in state": e.FSM.Current(),
165 "device-id": oFsm.pAdaptFsm.deviceID})
166 // in case the used channel is not yet defined (can be re-used after restarts)
167 if oFsm.omciLockResponseReceived == nil {
168 oFsm.omciLockResponseReceived = make(chan bool)
169 logger.Debug("LockStateFSM - OMCI UniLock RxChannel defined")
170 } else {
171 // as we may 're-use' this instance of FSM and the connected channel
172 // make sure there is no 'lingering' request in the already existing channel:
173 // (simple loop sufficient as we are the only receiver)
174 for len(oFsm.omciLockResponseReceived) > 0 {
175 <-oFsm.omciLockResponseReceived
176 }
177 }
178 // start go routine for processing of LockState messages
Himani Chawla6d2ae152020-09-02 13:11:20 +0530179 go oFsm.processOmciLockMessages()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000180
181 //let the state machine run forward from here directly
182 pLockStateAFsm := oFsm.pAdaptFsm
183 if pLockStateAFsm != nil {
184 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
185 go func(a_pAFsm *AdapterFsm) {
186 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530187 _ = a_pAFsm.pFsm.Event(uniEvStartAdmin)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000188 }
189 }(pLockStateAFsm)
190 }
191}
192
Himani Chawla6d2ae152020-09-02 13:11:20 +0530193func (oFsm *lockStateFsm) enterSettingOnuGState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000194 var omciAdminState uint8 = 1 //default locked
Himani Chawla4d908332020-08-31 12:30:20 +0530195 if !oFsm.adminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000196 omciAdminState = 0
197 }
198 logger.Debugw("LockStateFSM Tx Set::ONU-G:admin", log.Fields{
199 "omciAdmin": omciAdminState, "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
200 requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState}
201 meInstance := oFsm.pOmciCC.sendSetOnuGLS(context.TODO(), ConstDefaultOmciTimeout, true,
202 requestedAttributes, oFsm.pAdaptFsm.commChan)
203 //accept also nil as (error) return value for writing to LastTx
204 // - this avoids misinterpretation of new received OMCI messages
205 // we might already abort the processing with nil here, but maybe some auto-recovery may be tried
206 // - may be improved later, for now we just handle it with the Rx timeout or missing next event (stick in state)
207 oFsm.pOmciCC.pLastTxMeInstance = meInstance
208}
209
Himani Chawla6d2ae152020-09-02 13:11:20 +0530210func (oFsm *lockStateFsm) enterSettingUnisState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000211 logger.Infow("LockStateFSM - starting PPTP config loop", log.Fields{
212 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID, "LockState": oFsm.adminState})
213 go oFsm.performUniPortAdminSet()
214}
215
Himani Chawla6d2ae152020-09-02 13:11:20 +0530216func (oFsm *lockStateFsm) enterAdminDoneState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000217 logger.Debugw("LockStateFSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
218 //use DeviceHandler event notification directly, no need/support to update DeviceEntryState for lock/unlock
Himani Chawla6d2ae152020-09-02 13:11:20 +0530219 oFsm.pOmciCC.pBaseDeviceHandler.deviceProcStatusUpdate(oFsm.requestEvent)
Holger Hildebrandt8165eda2020-09-24 09:39:24 +0000220
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000221 //let's reset the state machine in order to release all resources now
222 pLockStateAFsm := oFsm.pAdaptFsm
223 if pLockStateAFsm != nil {
224 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
225 go func(a_pAFsm *AdapterFsm) {
226 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530227 _ = a_pAFsm.pFsm.Event(uniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000228 }
229 }(pLockStateAFsm)
230 }
231}
232
Himani Chawla6d2ae152020-09-02 13:11:20 +0530233func (oFsm *lockStateFsm) enterResettingState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000234 logger.Debugw("LockStateFSM resetting", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
235 pLockStateAFsm := oFsm.pAdaptFsm
236 if pLockStateAFsm != nil {
237 // abort running message processing
238 fsmAbortMsg := Message{
239 Type: TestMsg,
240 Data: TestMessage{
241 TestMessageVal: AbortMessageProcessing,
242 },
243 }
244 pLockStateAFsm.commChan <- fsmAbortMsg
245
246 //try to restart the FSM to 'disabled'
247 // see DownloadedState: decouple event transfer
248 go func(a_pAFsm *AdapterFsm) {
249 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530250 _ = a_pAFsm.pFsm.Event(uniEvRestart)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000251 }
252 }(pLockStateAFsm)
253 }
254}
255
Himani Chawla6d2ae152020-09-02 13:11:20 +0530256func (oFsm *lockStateFsm) processOmciLockMessages( /*ctx context.Context*/ ) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000257 logger.Debugw("Start LockStateFsm Msg processing", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
258loop:
259 for {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000260 // case <-ctx.Done():
261 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.pAdaptFsm.deviceID})
262 // break loop
Himani Chawla4d908332020-08-31 12:30:20 +0530263 message, ok := <-oFsm.pAdaptFsm.commChan
264 if !ok {
265 logger.Info("LockStateFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
266 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
267 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRestart)
268 break loop
269 }
270 logger.Debugw("LockStateFsm Rx Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
271
272 switch message.Type {
273 case TestMsg:
274 msg, _ := message.Data.(TestMessage)
275 if msg.TestMessageVal == AbortMessageProcessing {
276 logger.Infow("LockStateFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000277 break loop
278 }
Himani Chawla4d908332020-08-31 12:30:20 +0530279 logger.Warnw("LockStateFsm unknown TestMessage", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "MessageVal": msg.TestMessageVal})
280 case OMCI:
281 msg, _ := message.Data.(OmciMessage)
282 oFsm.handleOmciLockStateMessage(msg)
283 default:
284 logger.Warn("LockStateFsm Rx unknown message", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID,
285 "message.Type": message.Type})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000286 }
287 }
288 logger.Infow("End LockStateFsm Msg processing", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
289}
290
Himani Chawla6d2ae152020-09-02 13:11:20 +0530291func (oFsm *lockStateFsm) handleOmciLockStateMessage(msg OmciMessage) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000292 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 {
Andrea Campanella6515c582020-10-05 11:25:00 +0200298 logger.Errorw("LockStateFsm - Omci Msg layer could not be detected for SetResponse",
299 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000300 return
301 }
302 msgObj, msgOk := msgLayer.(*omci.SetResponse)
303 if !msgOk {
Andrea Campanella6515c582020-10-05 11:25:00 +0200304 logger.Errorw("LockStateFsm - Omci Msg layer could not be assigned for SetResponse",
305 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000306 return
307 }
divyadesai4d299552020-08-18 07:13:49 +0000308 logger.Debugw("LockStateFsm SetResponse Data", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000309 if msgObj.Result != me.Success {
310 logger.Errorw("LockStateFsm - Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result})
311 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
312 return
313 }
314 // compare comments above for CreateResponse (apply also here ...)
315 if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() &&
316 msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() {
317 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
318 // if, then something like:
319 //oFsm.pOnuDB.StoreMe(msgObj)
320
321 switch oFsm.pOmciCC.pLastTxMeInstance.GetName() {
322 case "OnuG":
323 { // let the FSM proceed ...
Himani Chawla4d908332020-08-31 12:30:20 +0530324 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxOnugResp)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000325 }
326 case "UniG", "VEIP":
327 { // let the PPTP init proceed by stopping the wait function
328 oFsm.omciLockResponseReceived <- true
329 }
330 }
331 }
332 } else {
333 logger.Errorw("LockStateFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType})
334 return
335 }
336}
337
Himani Chawla6d2ae152020-09-02 13:11:20 +0530338func (oFsm *lockStateFsm) performUniPortAdminSet() {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000339 var omciAdminState uint8 = 1 //default locked
Himani Chawla4d908332020-08-31 12:30:20 +0530340 if !oFsm.adminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000341 omciAdminState = 0
342 }
343 //set UNI-G or VEIP AdminState
344 requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState}
345
346 for uniNo, uniPort := range oFsm.pOmciCC.pBaseDeviceHandler.uniEntityMap {
347 logger.Debugw("Setting PPTP admin state", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000348 "device-id": oFsm.pAdaptFsm.deviceID, "for PortNo": uniNo})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000349
350 var meInstance *me.ManagedEntity
Himani Chawla6d2ae152020-09-02 13:11:20 +0530351 if uniPort.portType == uniPPTP {
Himani Chawla26e555c2020-08-31 12:30:20 +0530352 meInstance = oFsm.pOmciCC.sendSetUniGLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000353 true, requestedAttributes, oFsm.pAdaptFsm.commChan)
354 oFsm.pOmciCC.pLastTxMeInstance = meInstance
Himani Chawla6d2ae152020-09-02 13:11:20 +0530355 } else if uniPort.portType == uniVEIP {
Himani Chawla26e555c2020-08-31 12:30:20 +0530356 meInstance = oFsm.pOmciCC.sendSetVeipLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000357 true, requestedAttributes, oFsm.pAdaptFsm.commChan)
358 oFsm.pOmciCC.pLastTxMeInstance = meInstance
359 } else {
360 logger.Warnw("Unsupported PPTP type - skip",
divyadesai4d299552020-08-18 07:13:49 +0000361 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000362 continue
363 }
364
365 //verify response
mpagenko3af1f032020-06-10 08:53:41 +0000366 err := oFsm.waitforOmciResponse(meInstance)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000367 if err != nil {
368 logger.Errorw("PPTP Admin State set failed, aborting LockState set!",
divyadesai4d299552020-08-18 07:13:49 +0000369 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo})
Himani Chawla4d908332020-08-31 12:30:20 +0530370 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000371 return
372 }
373 } //for all UNI ports
374 // if Config has been done for all UNI related instances let the FSM proceed
375 // while we did not check here, if there is some port at all - !?
divyadesai4d299552020-08-18 07:13:49 +0000376 logger.Infow("PPTP config loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530377 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxUnisResp)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000378}
379
Himani Chawla6d2ae152020-09-02 13:11:20 +0530380func (oFsm *lockStateFsm) waitforOmciResponse(apMeInstance *me.ManagedEntity) error {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000381 select {
Himani Chawla4d908332020-08-31 12:30:20 +0530382 // maybe be also some outside cancel (but no context modeled for the moment ...)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000383 // case <-ctx.Done():
384 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
mpagenko3af1f032020-06-10 08:53:41 +0000385 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 +0000386 logger.Warnw("LockStateFSM uni-set timeout", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200387 return fmt.Errorf("lockStateFsm uni-set timeout for device-id %s", oFsm.pAdaptFsm.deviceID)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000388 case success := <-oFsm.omciLockResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +0530389 if success {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000390 logger.Debug("LockStateFSM uni-set response received")
391 return nil
392 }
393 // should not happen so far
394 logger.Warnw("LockStateFSM uni-set response error", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200395 return fmt.Errorf("lockStateFsm uni-set responseError for device-id %s", oFsm.pAdaptFsm.deviceID)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000396 }
397}