blob: ea2ed16af1bd844ca4bf2754c0d009814b5c65cf [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"
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"
Andrea Campanellaab7b6a52020-10-06 16:17:13 +0200231 //ConnState is reachable given the fact that no cable was pulled and it can be re-enabled through OMCI.
232 logger.Debugw("call DeviceStateUpdate", log.Fields{"ConnectStatus": voltha.ConnectStatus_REACHABLE,
233 "OperStatus": voltha.OperStatus_UNKNOWN, "device-id": oFsm.pDeviceHandler.deviceID, "reason": oFsm.pDeviceHandler.deviceReason})
234 if err := oFsm.pDeviceHandler.coreProxy.DeviceReasonUpdate(context.TODO(), oFsm.pDeviceHandler.deviceID,
235 oFsm.pDeviceHandler.deviceReason); err != nil {
236 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
237 logger.Errorw("error-updating-device-reason", log.Fields{"device-id": oFsm.pDeviceHandler.deviceID, "error": err})
238 }
Holger Hildebrandt8165eda2020-09-24 09:39:24 +0000239 if err := oFsm.pDeviceHandler.coreProxy.DeviceStateUpdate(context.TODO(), oFsm.pDeviceHandler.deviceID,
Andrea Campanellaab7b6a52020-10-06 16:17:13 +0200240 voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN); err != nil {
Holger Hildebrandt8165eda2020-09-24 09:39:24 +0000241 //TODO with VOL-3045/VOL-3046: return the error and stop further processing
242 logger.Errorw("error-updating-device-state", log.Fields{"device-id": oFsm.pDeviceHandler.deviceID, "error": err})
243 }
244 }
245
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000246 //let's reset the state machine in order to release all resources now
247 pLockStateAFsm := oFsm.pAdaptFsm
248 if pLockStateAFsm != nil {
249 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
250 go func(a_pAFsm *AdapterFsm) {
251 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530252 _ = a_pAFsm.pFsm.Event(uniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000253 }
254 }(pLockStateAFsm)
255 }
256}
257
Himani Chawla6d2ae152020-09-02 13:11:20 +0530258func (oFsm *lockStateFsm) enterResettingState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000259 logger.Debugw("LockStateFSM resetting", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
260 pLockStateAFsm := oFsm.pAdaptFsm
261 if pLockStateAFsm != nil {
262 // abort running message processing
263 fsmAbortMsg := Message{
264 Type: TestMsg,
265 Data: TestMessage{
266 TestMessageVal: AbortMessageProcessing,
267 },
268 }
269 pLockStateAFsm.commChan <- fsmAbortMsg
270
271 //try to restart the FSM to 'disabled'
272 // see DownloadedState: decouple event transfer
273 go func(a_pAFsm *AdapterFsm) {
274 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530275 _ = a_pAFsm.pFsm.Event(uniEvRestart)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000276 }
277 }(pLockStateAFsm)
278 }
279}
280
Himani Chawla6d2ae152020-09-02 13:11:20 +0530281func (oFsm *lockStateFsm) processOmciLockMessages( /*ctx context.Context*/ ) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000282 logger.Debugw("Start LockStateFsm Msg processing", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
283loop:
284 for {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000285 // case <-ctx.Done():
286 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.pAdaptFsm.deviceID})
287 // break loop
Himani Chawla4d908332020-08-31 12:30:20 +0530288 message, ok := <-oFsm.pAdaptFsm.commChan
289 if !ok {
290 logger.Info("LockStateFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
291 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
292 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRestart)
293 break loop
294 }
295 logger.Debugw("LockStateFsm Rx Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
296
297 switch message.Type {
298 case TestMsg:
299 msg, _ := message.Data.(TestMessage)
300 if msg.TestMessageVal == AbortMessageProcessing {
301 logger.Infow("LockStateFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000302 break loop
303 }
Himani Chawla4d908332020-08-31 12:30:20 +0530304 logger.Warnw("LockStateFsm unknown TestMessage", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "MessageVal": msg.TestMessageVal})
305 case OMCI:
306 msg, _ := message.Data.(OmciMessage)
307 oFsm.handleOmciLockStateMessage(msg)
308 default:
309 logger.Warn("LockStateFsm Rx unknown message", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID,
310 "message.Type": message.Type})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000311 }
312 }
313 logger.Infow("End LockStateFsm Msg processing", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
314}
315
Himani Chawla6d2ae152020-09-02 13:11:20 +0530316func (oFsm *lockStateFsm) handleOmciLockStateMessage(msg OmciMessage) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000317 logger.Debugw("Rx OMCI LockStateFsm Msg", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID,
318 "msgType": msg.OmciMsg.MessageType})
319
320 if msg.OmciMsg.MessageType == omci.SetResponseType {
321 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
322 if msgLayer == nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200323 logger.Errorw("LockStateFsm - Omci Msg layer could not be detected for SetResponse",
324 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000325 return
326 }
327 msgObj, msgOk := msgLayer.(*omci.SetResponse)
328 if !msgOk {
Andrea Campanella6515c582020-10-05 11:25:00 +0200329 logger.Errorw("LockStateFsm - Omci Msg layer could not be assigned for SetResponse",
330 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000331 return
332 }
divyadesai4d299552020-08-18 07:13:49 +0000333 logger.Debugw("LockStateFsm SetResponse Data", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "data-fields": msgObj})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000334 if msgObj.Result != me.Success {
335 logger.Errorw("LockStateFsm - Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result})
336 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
337 return
338 }
339 // compare comments above for CreateResponse (apply also here ...)
340 if msgObj.EntityClass == oFsm.pOmciCC.pLastTxMeInstance.GetClassID() &&
341 msgObj.EntityInstance == oFsm.pOmciCC.pLastTxMeInstance.GetEntityID() {
342 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
343 // if, then something like:
344 //oFsm.pOnuDB.StoreMe(msgObj)
345
346 switch oFsm.pOmciCC.pLastTxMeInstance.GetName() {
347 case "OnuG":
348 { // let the FSM proceed ...
Himani Chawla4d908332020-08-31 12:30:20 +0530349 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxOnugResp)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000350 }
351 case "UniG", "VEIP":
352 { // let the PPTP init proceed by stopping the wait function
353 oFsm.omciLockResponseReceived <- true
354 }
355 }
356 }
357 } else {
358 logger.Errorw("LockStateFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType})
359 return
360 }
361}
362
Himani Chawla6d2ae152020-09-02 13:11:20 +0530363func (oFsm *lockStateFsm) performUniPortAdminSet() {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000364 var omciAdminState uint8 = 1 //default locked
Himani Chawla4d908332020-08-31 12:30:20 +0530365 if !oFsm.adminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000366 omciAdminState = 0
367 }
368 //set UNI-G or VEIP AdminState
369 requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState}
370
371 for uniNo, uniPort := range oFsm.pOmciCC.pBaseDeviceHandler.uniEntityMap {
372 logger.Debugw("Setting PPTP admin state", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000373 "device-id": oFsm.pAdaptFsm.deviceID, "for PortNo": uniNo})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000374
375 var meInstance *me.ManagedEntity
Himani Chawla6d2ae152020-09-02 13:11:20 +0530376 if uniPort.portType == uniPPTP {
Himani Chawla26e555c2020-08-31 12:30:20 +0530377 meInstance = oFsm.pOmciCC.sendSetUniGLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000378 true, requestedAttributes, oFsm.pAdaptFsm.commChan)
379 oFsm.pOmciCC.pLastTxMeInstance = meInstance
Himani Chawla6d2ae152020-09-02 13:11:20 +0530380 } else if uniPort.portType == uniVEIP {
Himani Chawla26e555c2020-08-31 12:30:20 +0530381 meInstance = oFsm.pOmciCC.sendSetVeipLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000382 true, requestedAttributes, oFsm.pAdaptFsm.commChan)
383 oFsm.pOmciCC.pLastTxMeInstance = meInstance
384 } else {
385 logger.Warnw("Unsupported PPTP type - skip",
divyadesai4d299552020-08-18 07:13:49 +0000386 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000387 continue
388 }
389
390 //verify response
mpagenko3af1f032020-06-10 08:53:41 +0000391 err := oFsm.waitforOmciResponse(meInstance)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000392 if err != nil {
393 logger.Errorw("PPTP Admin State set failed, aborting LockState set!",
divyadesai4d299552020-08-18 07:13:49 +0000394 log.Fields{"device-id": oFsm.pAdaptFsm.deviceID, "Port": uniNo})
Himani Chawla4d908332020-08-31 12:30:20 +0530395 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000396 return
397 }
398 } //for all UNI ports
399 // if Config has been done for all UNI related instances let the FSM proceed
400 // while we did not check here, if there is some port at all - !?
divyadesai4d299552020-08-18 07:13:49 +0000401 logger.Infow("PPTP config loop finished", log.Fields{"device-id": oFsm.pAdaptFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530402 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxUnisResp)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000403}
404
Himani Chawla6d2ae152020-09-02 13:11:20 +0530405func (oFsm *lockStateFsm) waitforOmciResponse(apMeInstance *me.ManagedEntity) error {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000406 select {
Himani Chawla4d908332020-08-31 12:30:20 +0530407 // maybe be also some outside cancel (but no context modeled for the moment ...)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000408 // case <-ctx.Done():
409 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
mpagenko3af1f032020-06-10 08:53:41 +0000410 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 +0000411 logger.Warnw("LockStateFSM uni-set timeout", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200412 return fmt.Errorf("lockStateFsm uni-set timeout for device-id %s", oFsm.pAdaptFsm.deviceID)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000413 case success := <-oFsm.omciLockResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +0530414 if success {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000415 logger.Debug("LockStateFSM uni-set response received")
416 return nil
417 }
418 // should not happen so far
419 logger.Warnw("LockStateFSM uni-set response error", log.Fields{"for device-id": oFsm.pAdaptFsm.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200420 return fmt.Errorf("lockStateFsm uni-set responseError for device-id %s", oFsm.pAdaptFsm.deviceID)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000421 }
422}