blob: 0726be467e88243e57a890fc9595541cb5151a62 [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"
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000030 "github.com/opencord/voltha-protos/v3/go/voltha"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000031 //ic "github.com/opencord/voltha-protos/v3/go/inter_container"
32 //"github.com/opencord/voltha-protos/v3/go/openflow_13"
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000033)
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 {
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000037 pDeviceHandler *deviceHandler
Himani Chawla6d2ae152020-09-02 13:11:20 +053038 pOmciCC *omciCC
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000039 adminState bool
40 requestEvent OnuDeviceEvent
41 omciLockResponseReceived chan bool //seperate channel needed for checking UNI port OMCi message responses
42 pAdaptFsm *AdapterFsm
43}
44
mpagenko1cc3cb42020-07-27 15:24:38 +000045const (
46 // events of lock/unlock UNI port FSM
47 uniEvStart = "uniEvStart"
48 uniEvStartAdmin = "uniEvStartAdmin"
49 uniEvRxUnisResp = "uniEvRxUnisResp"
50 uniEvRxOnugResp = "uniEvRxOnugResp"
51 uniEvTimeoutSimple = "uniEvTimeoutSimple"
52 uniEvTimeoutUnis = "uniEvTimeoutUnis"
53 uniEvReset = "uniEvReset"
54 uniEvRestart = "uniEvRestart"
55)
56const (
57 // states of lock/unlock UNI port FSM
58 uniStDisabled = "uniStDisabled"
59 uniStStarting = "uniStStarting"
60 uniStSettingUnis = "uniStSettingUnis"
61 uniStSettingOnuG = "uniStSettingOnuG"
62 uniStAdminDone = "uniStAdminDone"
63 uniStResetting = "uniStResetting"
64)
65
Himani Chawla6d2ae152020-09-02 13:11:20 +053066//newLockStateFsm is the 'constructor' for the state machine to lock/unlock the ONU UNI ports via OMCI
67func newLockStateFsm(apDevOmciCC *omciCC, aAdminState bool, aRequestEvent OnuDeviceEvent,
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000068 aName string, apDeviceHandler *deviceHandler, aCommChannel chan Message) *lockStateFsm {
Himani Chawla6d2ae152020-09-02 13:11:20 +053069 instFsm := &lockStateFsm{
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000070 pDeviceHandler: apDeviceHandler,
71 pOmciCC: apDevOmciCC,
72 adminState: aAdminState,
73 requestEvent: aRequestEvent,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000074 }
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000075 instFsm.pAdaptFsm = NewAdapterFsm(aName, apDeviceHandler.deviceID, aCommChannel)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000076 if instFsm.pAdaptFsm == nil {
77 logger.Errorw("LockStateFsm's AdapterFsm could not be instantiated!!", log.Fields{
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000078 "device-id": apDeviceHandler.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000079 return nil
80 }
Himani Chawla4d908332020-08-31 12:30:20 +053081 if aAdminState { //port locking requested
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000082 instFsm.pAdaptFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +000083 uniStDisabled,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000084 fsm.Events{
85
mpagenko1cc3cb42020-07-27 15:24:38 +000086 {Name: uniEvStart, Src: []string{uniStDisabled}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000087
mpagenko1cc3cb42020-07-27 15:24:38 +000088 {Name: uniEvStartAdmin, Src: []string{uniStStarting}, Dst: uniStSettingUnis},
89 // the settingUnis state is used for multi ME config for all UNI related ports
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000090 // maybe such could be reflected in the state machine as well (port number parametrized)
91 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
mpagenko1cc3cb42020-07-27 15:24:38 +000092 {Name: uniEvRxUnisResp, Src: []string{uniStSettingUnis}, Dst: uniStSettingOnuG},
93 {Name: uniEvRxOnugResp, Src: []string{uniStSettingOnuG}, Dst: uniStAdminDone},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000094
mpagenko1cc3cb42020-07-27 15:24:38 +000095 {Name: uniEvTimeoutSimple, Src: []string{uniStSettingOnuG}, Dst: uniStStarting},
96 {Name: uniEvTimeoutUnis, Src: []string{uniStSettingUnis}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000097
mpagenko1cc3cb42020-07-27 15:24:38 +000098 {Name: uniEvReset, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis,
99 uniStAdminDone}, Dst: uniStResetting},
100 // exceptional treatment for all states except uniStResetting
101 {Name: uniEvRestart, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis,
102 uniStAdminDone, uniStResetting}, Dst: uniStDisabled},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000103 },
104
105 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000106 "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(e) },
107 ("enter_" + uniStStarting): func(e *fsm.Event) { instFsm.enterAdminStartingState(e) },
108 ("enter_" + uniStSettingOnuG): func(e *fsm.Event) { instFsm.enterSettingOnuGState(e) },
109 ("enter_" + uniStSettingUnis): func(e *fsm.Event) { instFsm.enterSettingUnisState(e) },
110 ("enter_" + uniStAdminDone): func(e *fsm.Event) { instFsm.enterAdminDoneState(e) },
111 ("enter_" + uniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(e) },
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000112 },
113 )
114 } else { //port unlocking requested
115 instFsm.pAdaptFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000116 uniStDisabled,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000117 fsm.Events{
118
mpagenko1cc3cb42020-07-27 15:24:38 +0000119 {Name: uniEvStart, Src: []string{uniStDisabled}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000120
mpagenko1cc3cb42020-07-27 15:24:38 +0000121 {Name: uniEvStartAdmin, Src: []string{uniStStarting}, Dst: uniStSettingOnuG},
122 {Name: uniEvRxOnugResp, Src: []string{uniStSettingOnuG}, Dst: uniStSettingUnis},
123 // the settingUnis state is used for multi ME config for all UNI related ports
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000124 // maybe such could be reflected in the state machine as well (port number parametrized)
125 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
mpagenko1cc3cb42020-07-27 15:24:38 +0000126 {Name: uniEvRxUnisResp, Src: []string{uniStSettingUnis}, Dst: uniStAdminDone},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000127
mpagenko1cc3cb42020-07-27 15:24:38 +0000128 {Name: uniEvTimeoutSimple, Src: []string{uniStSettingOnuG}, Dst: uniStStarting},
129 {Name: uniEvTimeoutUnis, Src: []string{uniStSettingUnis}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000130
mpagenko1cc3cb42020-07-27 15:24:38 +0000131 {Name: uniEvReset, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis,
132 uniStAdminDone}, Dst: uniStResetting},
133 // exceptional treatment for all states except uniStResetting
134 {Name: uniEvRestart, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis,
135 uniStAdminDone, uniStResetting}, Dst: uniStDisabled},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000136 },
137
138 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000139 "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(e) },
140 ("enter_" + uniStStarting): func(e *fsm.Event) { instFsm.enterAdminStartingState(e) },
141 ("enter_" + uniStSettingOnuG): func(e *fsm.Event) { instFsm.enterSettingOnuGState(e) },
142 ("enter_" + uniStSettingUnis): func(e *fsm.Event) { instFsm.enterSettingUnisState(e) },
143 ("enter_" + uniStAdminDone): func(e *fsm.Event) { instFsm.enterAdminDoneState(e) },
144 ("enter_" + uniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(e) },
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000145 },
146 )
147 }
148 if instFsm.pAdaptFsm.pFsm == nil {
149 logger.Errorw("LockStateFsm's Base FSM could not be instantiated!!", log.Fields{
Holger Hildebrandt8165eda2020-09-24 09:39:24 +0000150 "device-id": apDeviceHandler.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000151 return nil
152 }
153
Holger Hildebrandt8165eda2020-09-24 09:39:24 +0000154 logger.Infow("LockStateFsm created", log.Fields{"device-id": apDeviceHandler.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000155 return instFsm
156}
157
Himani Chawla6d2ae152020-09-02 13:11:20 +0530158//setSuccessEvent modifies the requested event notified on success
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000159//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 +0530160func (oFsm *lockStateFsm) setSuccessEvent(aEvent OnuDeviceEvent) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000161 oFsm.requestEvent = aEvent
162}
163
Himani Chawla6d2ae152020-09-02 13:11:20 +0530164func (oFsm *lockStateFsm) enterAdminStartingState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000165 logger.Debugw("LockStateFSM start", log.Fields{"in state": e.FSM.Current(),
166 "device-id": oFsm.pAdaptFsm.deviceID})
167 // in case the used channel is not yet defined (can be re-used after restarts)
168 if oFsm.omciLockResponseReceived == nil {
169 oFsm.omciLockResponseReceived = make(chan bool)
170 logger.Debug("LockStateFSM - OMCI UniLock RxChannel defined")
171 } else {
172 // as we may 're-use' this instance of FSM and the connected channel
173 // make sure there is no 'lingering' request in the already existing channel:
174 // (simple loop sufficient as we are the only receiver)
175 for len(oFsm.omciLockResponseReceived) > 0 {
176 <-oFsm.omciLockResponseReceived
177 }
178 }
179 // start go routine for processing of LockState messages
Himani Chawla6d2ae152020-09-02 13:11:20 +0530180 go oFsm.processOmciLockMessages()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000181
182 //let the state machine run forward from here directly
183 pLockStateAFsm := oFsm.pAdaptFsm
184 if pLockStateAFsm != nil {
185 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
186 go func(a_pAFsm *AdapterFsm) {
187 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530188 _ = a_pAFsm.pFsm.Event(uniEvStartAdmin)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000189 }
190 }(pLockStateAFsm)
191 }
192}
193
Himani Chawla6d2ae152020-09-02 13:11:20 +0530194func (oFsm *lockStateFsm) enterSettingOnuGState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000195 var omciAdminState uint8 = 1 //default locked
Himani Chawla4d908332020-08-31 12:30:20 +0530196 if !oFsm.adminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000197 omciAdminState = 0
198 }
199 logger.Debugw("LockStateFSM Tx Set::ONU-G:admin", log.Fields{
200 "omciAdmin": omciAdminState, "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
201 requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState}
202 meInstance := oFsm.pOmciCC.sendSetOnuGLS(context.TODO(), ConstDefaultOmciTimeout, true,
203 requestedAttributes, oFsm.pAdaptFsm.commChan)
204 //accept also nil as (error) return value for writing to LastTx
205 // - this avoids misinterpretation of new received OMCI messages
206 // we might already abort the processing with nil here, but maybe some auto-recovery may be tried
207 // - may be improved later, for now we just handle it with the Rx timeout or missing next event (stick in state)
208 oFsm.pOmciCC.pLastTxMeInstance = meInstance
209}
210
Himani Chawla6d2ae152020-09-02 13:11:20 +0530211func (oFsm *lockStateFsm) enterSettingUnisState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000212 logger.Infow("LockStateFSM - starting PPTP config loop", log.Fields{
213 "in state": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID, "LockState": oFsm.adminState})
214 go oFsm.performUniPortAdminSet()
215}
216
Himani Chawla6d2ae152020-09-02 13:11:20 +0530217func (oFsm *lockStateFsm) enterAdminDoneState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000218 logger.Debugw("LockStateFSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oFsm.pAdaptFsm.deviceID})
219 //use DeviceHandler event notification directly, no need/support to update DeviceEntryState for lock/unlock
Himani Chawla6d2ae152020-09-02 13:11:20 +0530220 oFsm.pOmciCC.pBaseDeviceHandler.deviceProcStatusUpdate(oFsm.requestEvent)
Holger Hildebrandt8165eda2020-09-24 09:39:24 +0000221
222 //VOL-3493/VOL-3495: postpone setting of deviceReason, conn- and operStatus until all omci-related communication regarding
223 //device disabling has finished successfully
224 if oFsm.adminState {
225 if err := oFsm.pDeviceHandler.coreProxy.DeviceReasonUpdate(context.TODO(),
226 oFsm.pDeviceHandler.deviceID, "omci-admin-lock"); err != nil {
227 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
228 logger.Errorw("error-updating-reason-state", log.Fields{"device-id": oFsm.pDeviceHandler.deviceID, "error": err})
229 }
230 oFsm.pDeviceHandler.deviceReason = "omci-admin-lock"
231 //200604: ConnState improved to 'unreachable' (was not set in python-code), OperState 'unknown' seems to be best choice
232 logger.Debugw("call DeviceStateUpdate", log.Fields{"ConnectStatus": voltha.ConnectStatus_UNREACHABLE,
233 "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": oFsm.pDeviceHandler.deviceID})
234 if err := oFsm.pDeviceHandler.coreProxy.DeviceStateUpdate(context.TODO(), oFsm.pDeviceHandler.deviceID,
235 voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN); err != nil {
236 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
237 logger.Errorw("error-updating-device-state", log.Fields{"device-id": oFsm.pDeviceHandler.deviceID, "error": err})
238 }
239 }
240
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000241 //let's reset the state machine in order to release all resources now
242 pLockStateAFsm := oFsm.pAdaptFsm
243 if pLockStateAFsm != nil {
244 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
245 go func(a_pAFsm *AdapterFsm) {
246 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530247 _ = a_pAFsm.pFsm.Event(uniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000248 }
249 }(pLockStateAFsm)
250 }
251}
252
Himani Chawla6d2ae152020-09-02 13:11:20 +0530253func (oFsm *lockStateFsm) enterResettingState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000254 logger.Debugw("LockStateFSM resetting", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
255 pLockStateAFsm := oFsm.pAdaptFsm
256 if pLockStateAFsm != nil {
257 // abort running message processing
258 fsmAbortMsg := Message{
259 Type: TestMsg,
260 Data: TestMessage{
261 TestMessageVal: AbortMessageProcessing,
262 },
263 }
264 pLockStateAFsm.commChan <- fsmAbortMsg
265
266 //try to restart the FSM to 'disabled'
267 // see DownloadedState: decouple event transfer
268 go func(a_pAFsm *AdapterFsm) {
269 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530270 _ = a_pAFsm.pFsm.Event(uniEvRestart)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000271 }
272 }(pLockStateAFsm)
273 }
274}
275
Himani Chawla6d2ae152020-09-02 13:11:20 +0530276func (oFsm *lockStateFsm) processOmciLockMessages( /*ctx context.Context*/ ) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000277 logger.Debugw("Start LockStateFsm Msg processing", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
278loop:
279 for {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000280 // case <-ctx.Done():
281 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.pAdaptFsm.deviceID})
282 // break loop
Himani Chawla4d908332020-08-31 12:30:20 +0530283 message, ok := <-oFsm.pAdaptFsm.commChan
284 if !ok {
285 logger.Info("LockStateFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
286 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
287 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRestart)
288 break loop
289 }
290 logger.Debugw("LockStateFsm Rx Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
291
292 switch message.Type {
293 case TestMsg:
294 msg, _ := message.Data.(TestMessage)
295 if msg.TestMessageVal == AbortMessageProcessing {
296 logger.Infow("LockStateFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000297 break loop
298 }
Himani Chawla4d908332020-08-31 12:30:20 +0530299 logger.Warnw("LockStateFsm unknown TestMessage", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "MessageVal": msg.TestMessageVal})
300 case OMCI:
301 msg, _ := message.Data.(OmciMessage)
302 oFsm.handleOmciLockStateMessage(msg)
303 default:
304 logger.Warn("LockStateFsm Rx unknown message", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID,
305 "message.Type": message.Type})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000306 }
307 }
308 logger.Infow("End LockStateFsm Msg processing", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
309}
310
Himani Chawla6d2ae152020-09-02 13:11:20 +0530311func (oFsm *lockStateFsm) handleOmciLockStateMessage(msg OmciMessage) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000312 logger.Debugw("Rx OMCI LockStateFsm Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID,
313 "msgType": msg.OmciMsg.MessageType})
314
315 if msg.OmciMsg.MessageType == omci.SetResponseType {
316 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
317 if msgLayer == nil {
318 logger.Error("LockStateFsm - Omci Msg layer could not be detected for SetResponse")
319 return
320 }
321 msgObj, msgOk := msgLayer.(*omci.SetResponse)
322 if !msgOk {
323 logger.Error("LockStateFsm - Omci Msg layer could not be assigned for SetResponse")
324 return
325 }
divyadesai4d299552020-08-18 07:13:49 +0000326 logger.Debugw("LockStateFsm SetResponse Data", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000327 if msgObj.Result != me.Success {
328 logger.Errorw("LockStateFsm - Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result})
329 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
330 return
331 }
332 // compare comments above for CreateResponse (apply also here ...)
333 if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() &&
334 msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() {
335 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
336 // if, then something like:
337 //oFsm.pOnuDB.StoreMe(msgObj)
338
339 switch oFsm.pOmciCC.pLastTxMeInstance.GetName() {
340 case "OnuG":
341 { // let the FSM proceed ...
Himani Chawla4d908332020-08-31 12:30:20 +0530342 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxOnugResp)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000343 }
344 case "UniG", "VEIP":
345 { // let the PPTP init proceed by stopping the wait function
346 oFsm.omciLockResponseReceived <- true
347 }
348 }
349 }
350 } else {
351 logger.Errorw("LockStateFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType})
352 return
353 }
354}
355
Himani Chawla6d2ae152020-09-02 13:11:20 +0530356func (oFsm *lockStateFsm) performUniPortAdminSet() {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000357 var omciAdminState uint8 = 1 //default locked
Himani Chawla4d908332020-08-31 12:30:20 +0530358 if !oFsm.adminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000359 omciAdminState = 0
360 }
361 //set UNI-G or VEIP AdminState
362 requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState}
363
364 for uniNo, uniPort := range oFsm.pOmciCC.pBaseDeviceHandler.uniEntityMap {
365 logger.Debugw("Setting PPTP admin state", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000366 "device-id": oFsm.pAdaptFsm.deviceID, "for PortNo": uniNo})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000367
368 var meInstance *me.ManagedEntity
Himani Chawla6d2ae152020-09-02 13:11:20 +0530369 if uniPort.portType == uniPPTP {
Himani Chawla26e555c2020-08-31 12:30:20 +0530370 meInstance = oFsm.pOmciCC.sendSetUniGLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000371 true, requestedAttributes, oFsm.pAdaptFsm.commChan)
372 oFsm.pOmciCC.pLastTxMeInstance = meInstance
Himani Chawla6d2ae152020-09-02 13:11:20 +0530373 } else if uniPort.portType == uniVEIP {
Himani Chawla26e555c2020-08-31 12:30:20 +0530374 meInstance = oFsm.pOmciCC.sendSetVeipLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000375 true, requestedAttributes, oFsm.pAdaptFsm.commChan)
376 oFsm.pOmciCC.pLastTxMeInstance = meInstance
377 } else {
378 logger.Warnw("Unsupported PPTP type - skip",
divyadesai4d299552020-08-18 07:13:49 +0000379 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000380 continue
381 }
382
383 //verify response
mpagenko3af1f032020-06-10 08:53:41 +0000384 err := oFsm.waitforOmciResponse(meInstance)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000385 if err != nil {
386 logger.Errorw("PPTP Admin State set failed, aborting LockState set!",
divyadesai4d299552020-08-18 07:13:49 +0000387 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo})
Himani Chawla4d908332020-08-31 12:30:20 +0530388 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000389 return
390 }
391 } //for all UNI ports
392 // if Config has been done for all UNI related instances let the FSM proceed
393 // while we did not check here, if there is some port at all - !?
divyadesai4d299552020-08-18 07:13:49 +0000394 logger.Infow("PPTP config loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530395 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxUnisResp)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000396}
397
Himani Chawla6d2ae152020-09-02 13:11:20 +0530398func (oFsm *lockStateFsm) waitforOmciResponse(apMeInstance *me.ManagedEntity) error {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000399 select {
Himani Chawla4d908332020-08-31 12:30:20 +0530400 // maybe be also some outside cancel (but no context modeled for the moment ...)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000401 // case <-ctx.Done():
402 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
mpagenko3af1f032020-06-10 08:53:41 +0000403 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 +0000404 logger.Warnw("LockStateFSM uni-set timeout", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530405 return errors.New("lockStateFsm uni-set timeout")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000406 case success := <-oFsm.omciLockResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +0530407 if success {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000408 logger.Debug("LockStateFSM uni-set response received")
409 return nil
410 }
411 // should not happen so far
412 logger.Warnw("LockStateFSM uni-set response error", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530413 return errors.New("lockStateFsm uni-set responseError")
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000414 }
415}