blob: 11a6b04a8a0fb166081c1ee7cd78196106f3c362 [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
mpagenko01e726e2020-10-23 09:45:29 +000037 deviceID string
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
mpagenko01e726e2020-10-23 09:45:29 +000043 pLastTxMeInstance *me.ManagedEntity
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000044}
45
mpagenko1cc3cb42020-07-27 15:24:38 +000046const (
47 // events of lock/unlock UNI port FSM
48 uniEvStart = "uniEvStart"
49 uniEvStartAdmin = "uniEvStartAdmin"
50 uniEvRxUnisResp = "uniEvRxUnisResp"
51 uniEvRxOnugResp = "uniEvRxOnugResp"
52 uniEvTimeoutSimple = "uniEvTimeoutSimple"
53 uniEvTimeoutUnis = "uniEvTimeoutUnis"
54 uniEvReset = "uniEvReset"
55 uniEvRestart = "uniEvRestart"
56)
57const (
58 // states of lock/unlock UNI port FSM
59 uniStDisabled = "uniStDisabled"
60 uniStStarting = "uniStStarting"
61 uniStSettingUnis = "uniStSettingUnis"
62 uniStSettingOnuG = "uniStSettingOnuG"
63 uniStAdminDone = "uniStAdminDone"
64 uniStResetting = "uniStResetting"
65)
66
Himani Chawla6d2ae152020-09-02 13:11:20 +053067//newLockStateFsm is the 'constructor' for the state machine to lock/unlock the ONU UNI ports via OMCI
68func newLockStateFsm(apDevOmciCC *omciCC, aAdminState bool, aRequestEvent OnuDeviceEvent,
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000069 aName string, apDeviceHandler *deviceHandler, aCommChannel chan Message) *lockStateFsm {
Himani Chawla6d2ae152020-09-02 13:11:20 +053070 instFsm := &lockStateFsm{
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000071 pDeviceHandler: apDeviceHandler,
mpagenko01e726e2020-10-23 09:45:29 +000072 deviceID: apDeviceHandler.deviceID,
Holger Hildebrandt8165eda2020-09-24 09:39:24 +000073 pOmciCC: apDevOmciCC,
74 adminState: aAdminState,
75 requestEvent: aRequestEvent,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000076 }
mpagenko01e726e2020-10-23 09:45:29 +000077 instFsm.pAdaptFsm = NewAdapterFsm(aName, instFsm.deviceID, aCommChannel)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000078 if instFsm.pAdaptFsm == nil {
79 logger.Errorw("LockStateFsm's AdapterFsm could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +000080 "device-id": instFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000081 return nil
82 }
Himani Chawla4d908332020-08-31 12:30:20 +053083 if aAdminState { //port locking requested
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000084 instFsm.pAdaptFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +000085 uniStDisabled,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000086 fsm.Events{
87
mpagenko1cc3cb42020-07-27 15:24:38 +000088 {Name: uniEvStart, Src: []string{uniStDisabled}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000089
mpagenko1cc3cb42020-07-27 15:24:38 +000090 {Name: uniEvStartAdmin, Src: []string{uniStStarting}, Dst: uniStSettingUnis},
91 // the settingUnis state is used for multi ME config for all UNI related ports
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000092 // maybe such could be reflected in the state machine as well (port number parametrized)
93 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
mpagenko1cc3cb42020-07-27 15:24:38 +000094 {Name: uniEvRxUnisResp, Src: []string{uniStSettingUnis}, Dst: uniStSettingOnuG},
95 {Name: uniEvRxOnugResp, Src: []string{uniStSettingOnuG}, Dst: uniStAdminDone},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000096
mpagenko1cc3cb42020-07-27 15:24:38 +000097 {Name: uniEvTimeoutSimple, Src: []string{uniStSettingOnuG}, Dst: uniStStarting},
98 {Name: uniEvTimeoutUnis, Src: []string{uniStSettingUnis}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000099
mpagenko1cc3cb42020-07-27 15:24:38 +0000100 {Name: uniEvReset, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis,
101 uniStAdminDone}, Dst: uniStResetting},
102 // exceptional treatment for all states except uniStResetting
103 {Name: uniEvRestart, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis,
104 uniStAdminDone, uniStResetting}, Dst: uniStDisabled},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000105 },
106
107 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000108 "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(e) },
109 ("enter_" + uniStStarting): func(e *fsm.Event) { instFsm.enterAdminStartingState(e) },
110 ("enter_" + uniStSettingOnuG): func(e *fsm.Event) { instFsm.enterSettingOnuGState(e) },
111 ("enter_" + uniStSettingUnis): func(e *fsm.Event) { instFsm.enterSettingUnisState(e) },
112 ("enter_" + uniStAdminDone): func(e *fsm.Event) { instFsm.enterAdminDoneState(e) },
113 ("enter_" + uniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(e) },
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000114 },
115 )
116 } else { //port unlocking requested
117 instFsm.pAdaptFsm.pFsm = fsm.NewFSM(
mpagenko1cc3cb42020-07-27 15:24:38 +0000118 uniStDisabled,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000119 fsm.Events{
120
mpagenko1cc3cb42020-07-27 15:24:38 +0000121 {Name: uniEvStart, Src: []string{uniStDisabled}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000122
mpagenko1cc3cb42020-07-27 15:24:38 +0000123 {Name: uniEvStartAdmin, Src: []string{uniStStarting}, Dst: uniStSettingOnuG},
124 {Name: uniEvRxOnugResp, Src: []string{uniStSettingOnuG}, Dst: uniStSettingUnis},
125 // the settingUnis state is used for multi ME config for all UNI related ports
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000126 // maybe such could be reflected in the state machine as well (port number parametrized)
127 // but that looks not straightforward here - so we keep it simple here for the beginning(?)
mpagenko1cc3cb42020-07-27 15:24:38 +0000128 {Name: uniEvRxUnisResp, Src: []string{uniStSettingUnis}, Dst: uniStAdminDone},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000129
mpagenko1cc3cb42020-07-27 15:24:38 +0000130 {Name: uniEvTimeoutSimple, Src: []string{uniStSettingOnuG}, Dst: uniStStarting},
131 {Name: uniEvTimeoutUnis, Src: []string{uniStSettingUnis}, Dst: uniStStarting},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000132
mpagenko1cc3cb42020-07-27 15:24:38 +0000133 {Name: uniEvReset, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis,
134 uniStAdminDone}, Dst: uniStResetting},
135 // exceptional treatment for all states except uniStResetting
136 {Name: uniEvRestart, Src: []string{uniStStarting, uniStSettingOnuG, uniStSettingUnis,
137 uniStAdminDone, uniStResetting}, Dst: uniStDisabled},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000138 },
139
140 fsm.Callbacks{
mpagenko1cc3cb42020-07-27 15:24:38 +0000141 "enter_state": func(e *fsm.Event) { instFsm.pAdaptFsm.logFsmStateChange(e) },
142 ("enter_" + uniStStarting): func(e *fsm.Event) { instFsm.enterAdminStartingState(e) },
143 ("enter_" + uniStSettingOnuG): func(e *fsm.Event) { instFsm.enterSettingOnuGState(e) },
144 ("enter_" + uniStSettingUnis): func(e *fsm.Event) { instFsm.enterSettingUnisState(e) },
145 ("enter_" + uniStAdminDone): func(e *fsm.Event) { instFsm.enterAdminDoneState(e) },
146 ("enter_" + uniStResetting): func(e *fsm.Event) { instFsm.enterResettingState(e) },
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000147 },
148 )
149 }
150 if instFsm.pAdaptFsm.pFsm == nil {
151 logger.Errorw("LockStateFsm's Base FSM could not be instantiated!!", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000152 "device-id": instFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000153 return nil
154 }
155
mpagenko01e726e2020-10-23 09:45:29 +0000156 logger.Infow("LockStateFsm created", log.Fields{"device-id": instFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000157 return instFsm
158}
159
Himani Chawla6d2ae152020-09-02 13:11:20 +0530160//setSuccessEvent modifies the requested event notified on success
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000161//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 +0530162func (oFsm *lockStateFsm) setSuccessEvent(aEvent OnuDeviceEvent) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000163 oFsm.requestEvent = aEvent
164}
165
Himani Chawla6d2ae152020-09-02 13:11:20 +0530166func (oFsm *lockStateFsm) enterAdminStartingState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000167 logger.Debugw("LockStateFSM start", log.Fields{"in state": e.FSM.Current(),
mpagenko01e726e2020-10-23 09:45:29 +0000168 "device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000169 // in case the used channel is not yet defined (can be re-used after restarts)
170 if oFsm.omciLockResponseReceived == nil {
171 oFsm.omciLockResponseReceived = make(chan bool)
172 logger.Debug("LockStateFSM - OMCI UniLock RxChannel defined")
173 } else {
174 // as we may 're-use' this instance of FSM and the connected channel
175 // make sure there is no 'lingering' request in the already existing channel:
176 // (simple loop sufficient as we are the only receiver)
177 for len(oFsm.omciLockResponseReceived) > 0 {
178 <-oFsm.omciLockResponseReceived
179 }
180 }
181 // start go routine for processing of LockState messages
Himani Chawla6d2ae152020-09-02 13:11:20 +0530182 go oFsm.processOmciLockMessages()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000183
184 //let the state machine run forward from here directly
185 pLockStateAFsm := oFsm.pAdaptFsm
186 if pLockStateAFsm != nil {
187 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
188 go func(a_pAFsm *AdapterFsm) {
189 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530190 _ = a_pAFsm.pFsm.Event(uniEvStartAdmin)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000191 }
192 }(pLockStateAFsm)
193 }
194}
195
Himani Chawla6d2ae152020-09-02 13:11:20 +0530196func (oFsm *lockStateFsm) enterSettingOnuGState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000197 var omciAdminState uint8 = 1 //default locked
Himani Chawla4d908332020-08-31 12:30:20 +0530198 if !oFsm.adminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000199 omciAdminState = 0
200 }
201 logger.Debugw("LockStateFSM Tx Set::ONU-G:admin", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000202 "omciAdmin": omciAdminState, "in state": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000203 requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState}
204 meInstance := oFsm.pOmciCC.sendSetOnuGLS(context.TODO(), ConstDefaultOmciTimeout, true,
205 requestedAttributes, oFsm.pAdaptFsm.commChan)
206 //accept also nil as (error) return value for writing to LastTx
207 // - this avoids misinterpretation of new received OMCI messages
208 // we might already abort the processing with nil here, but maybe some auto-recovery may be tried
209 // - may be improved later, for now we just handle it with the Rx timeout or missing next event (stick in state)
mpagenko01e726e2020-10-23 09:45:29 +0000210 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000211}
212
Himani Chawla6d2ae152020-09-02 13:11:20 +0530213func (oFsm *lockStateFsm) enterSettingUnisState(e *fsm.Event) {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000214 logger.Infow("LockStateFSM - starting PPTP config loop", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000215 "in state": e.FSM.Current(), "device-id": oFsm.deviceID, "LockState": oFsm.adminState})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000216 go oFsm.performUniPortAdminSet()
217}
218
Himani Chawla6d2ae152020-09-02 13:11:20 +0530219func (oFsm *lockStateFsm) enterAdminDoneState(e *fsm.Event) {
mpagenko01e726e2020-10-23 09:45:29 +0000220 logger.Debugw("LockStateFSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000221 //use DeviceHandler event notification directly, no need/support to update DeviceEntryState for lock/unlock
mpagenko01e726e2020-10-23 09:45:29 +0000222 oFsm.pDeviceHandler.deviceProcStatusUpdate(oFsm.requestEvent)
Holger Hildebrandt8165eda2020-09-24 09:39:24 +0000223
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000224 //let's reset the state machine in order to release all resources now
225 pLockStateAFsm := oFsm.pAdaptFsm
226 if pLockStateAFsm != nil {
227 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
228 go func(a_pAFsm *AdapterFsm) {
229 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530230 _ = a_pAFsm.pFsm.Event(uniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000231 }
232 }(pLockStateAFsm)
233 }
234}
235
Himani Chawla6d2ae152020-09-02 13:11:20 +0530236func (oFsm *lockStateFsm) enterResettingState(e *fsm.Event) {
mpagenko01e726e2020-10-23 09:45:29 +0000237 logger.Debugw("LockStateFSM resetting", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000238 pLockStateAFsm := oFsm.pAdaptFsm
239 if pLockStateAFsm != nil {
240 // abort running message processing
241 fsmAbortMsg := Message{
242 Type: TestMsg,
243 Data: TestMessage{
244 TestMessageVal: AbortMessageProcessing,
245 },
246 }
247 pLockStateAFsm.commChan <- fsmAbortMsg
248
249 //try to restart the FSM to 'disabled'
250 // see DownloadedState: decouple event transfer
251 go func(a_pAFsm *AdapterFsm) {
252 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530253 _ = a_pAFsm.pFsm.Event(uniEvRestart)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000254 }
255 }(pLockStateAFsm)
mpagenko01e726e2020-10-23 09:45:29 +0000256 oFsm.pLastTxMeInstance = nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000257 }
258}
259
Himani Chawla6d2ae152020-09-02 13:11:20 +0530260func (oFsm *lockStateFsm) processOmciLockMessages( /*ctx context.Context*/ ) {
mpagenko01e726e2020-10-23 09:45:29 +0000261 logger.Debugw("Start LockStateFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000262loop:
263 for {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000264 // case <-ctx.Done():
mpagenko01e726e2020-10-23 09:45:29 +0000265 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000266 // break loop
Himani Chawla4d908332020-08-31 12:30:20 +0530267 message, ok := <-oFsm.pAdaptFsm.commChan
268 if !ok {
mpagenko01e726e2020-10-23 09:45:29 +0000269 logger.Info("LockStateFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530270 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
271 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRestart)
272 break loop
273 }
mpagenko01e726e2020-10-23 09:45:29 +0000274 logger.Debugw("LockStateFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530275
276 switch message.Type {
277 case TestMsg:
278 msg, _ := message.Data.(TestMessage)
279 if msg.TestMessageVal == AbortMessageProcessing {
mpagenko01e726e2020-10-23 09:45:29 +0000280 logger.Infow("LockStateFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000281 break loop
282 }
mpagenko01e726e2020-10-23 09:45:29 +0000283 logger.Warnw("LockStateFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal})
Himani Chawla4d908332020-08-31 12:30:20 +0530284 case OMCI:
285 msg, _ := message.Data.(OmciMessage)
286 oFsm.handleOmciLockStateMessage(msg)
287 default:
mpagenko01e726e2020-10-23 09:45:29 +0000288 logger.Warn("LockStateFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID,
Himani Chawla4d908332020-08-31 12:30:20 +0530289 "message.Type": message.Type})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000290 }
291 }
mpagenko01e726e2020-10-23 09:45:29 +0000292 logger.Infow("End LockStateFsm Msg processing", log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000293}
294
Himani Chawla6d2ae152020-09-02 13:11:20 +0530295func (oFsm *lockStateFsm) handleOmciLockStateMessage(msg OmciMessage) {
mpagenko01e726e2020-10-23 09:45:29 +0000296 logger.Debugw("Rx OMCI LockStateFsm Msg", log.Fields{"device-id": oFsm.deviceID,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000297 "msgType": msg.OmciMsg.MessageType})
298
299 if msg.OmciMsg.MessageType == omci.SetResponseType {
300 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
301 if msgLayer == nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200302 logger.Errorw("LockStateFsm - Omci Msg layer could not be detected for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +0000303 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000304 return
305 }
306 msgObj, msgOk := msgLayer.(*omci.SetResponse)
307 if !msgOk {
Andrea Campanella6515c582020-10-05 11:25:00 +0200308 logger.Errorw("LockStateFsm - Omci Msg layer could not be assigned for SetResponse",
mpagenko01e726e2020-10-23 09:45:29 +0000309 log.Fields{"device-id": oFsm.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000310 return
311 }
mpagenko01e726e2020-10-23 09:45:29 +0000312 logger.Debugw("LockStateFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000313 if msgObj.Result != me.Success {
314 logger.Errorw("LockStateFsm - Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"Error": msgObj.Result})
315 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
316 return
317 }
318 // compare comments above for CreateResponse (apply also here ...)
mpagenko01e726e2020-10-23 09:45:29 +0000319 if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() &&
320 msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000321 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
322 // if, then something like:
323 //oFsm.pOnuDB.StoreMe(msgObj)
324
mpagenko01e726e2020-10-23 09:45:29 +0000325 switch oFsm.pLastTxMeInstance.GetName() {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000326 case "OnuG":
327 { // let the FSM proceed ...
Himani Chawla4d908332020-08-31 12:30:20 +0530328 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxOnugResp)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000329 }
330 case "UniG", "VEIP":
331 { // let the PPTP init proceed by stopping the wait function
332 oFsm.omciLockResponseReceived <- true
333 }
334 }
335 }
336 } else {
337 logger.Errorw("LockStateFsm - Rx OMCI unhandled MsgType", log.Fields{"omciMsgType": msg.OmciMsg.MessageType})
338 return
339 }
340}
341
Himani Chawla6d2ae152020-09-02 13:11:20 +0530342func (oFsm *lockStateFsm) performUniPortAdminSet() {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000343 var omciAdminState uint8 = 1 //default locked
Himani Chawla4d908332020-08-31 12:30:20 +0530344 if !oFsm.adminState {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000345 omciAdminState = 0
346 }
347 //set UNI-G or VEIP AdminState
348 requestedAttributes := me.AttributeValueMap{"AdministrativeState": omciAdminState}
349
350 for uniNo, uniPort := range oFsm.pOmciCC.pBaseDeviceHandler.uniEntityMap {
351 logger.Debugw("Setting PPTP admin state", log.Fields{
mpagenko01e726e2020-10-23 09:45:29 +0000352 "device-id": oFsm.deviceID, "for PortNo": uniNo})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000353
354 var meInstance *me.ManagedEntity
Himani Chawla6d2ae152020-09-02 13:11:20 +0530355 if uniPort.portType == uniPPTP {
Himani Chawla26e555c2020-08-31 12:30:20 +0530356 meInstance = oFsm.pOmciCC.sendSetUniGLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000357 true, requestedAttributes, oFsm.pAdaptFsm.commChan)
mpagenko01e726e2020-10-23 09:45:29 +0000358 oFsm.pLastTxMeInstance = meInstance
Himani Chawla6d2ae152020-09-02 13:11:20 +0530359 } else if uniPort.portType == uniVEIP {
Himani Chawla26e555c2020-08-31 12:30:20 +0530360 meInstance = oFsm.pOmciCC.sendSetVeipLS(context.TODO(), uniPort.entityID, ConstDefaultOmciTimeout,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000361 true, requestedAttributes, oFsm.pAdaptFsm.commChan)
mpagenko01e726e2020-10-23 09:45:29 +0000362 oFsm.pLastTxMeInstance = meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000363 } else {
364 logger.Warnw("Unsupported PPTP type - skip",
mpagenko01e726e2020-10-23 09:45:29 +0000365 log.Fields{"device-id": oFsm.deviceID, "Port": uniNo})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000366 continue
367 }
368
369 //verify response
mpagenko3af1f032020-06-10 08:53:41 +0000370 err := oFsm.waitforOmciResponse(meInstance)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000371 if err != nil {
372 logger.Errorw("PPTP Admin State set failed, aborting LockState set!",
mpagenko01e726e2020-10-23 09:45:29 +0000373 log.Fields{"device-id": oFsm.deviceID, "Port": uniNo})
Himani Chawla4d908332020-08-31 12:30:20 +0530374 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvReset)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000375 return
376 }
377 } //for all UNI ports
378 // if Config has been done for all UNI related instances let the FSM proceed
379 // while we did not check here, if there is some port at all - !?
mpagenko01e726e2020-10-23 09:45:29 +0000380 logger.Infow("PPTP config loop finished", log.Fields{"device-id": oFsm.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530381 _ = oFsm.pAdaptFsm.pFsm.Event(uniEvRxUnisResp)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000382}
383
Himani Chawla6d2ae152020-09-02 13:11:20 +0530384func (oFsm *lockStateFsm) waitforOmciResponse(apMeInstance *me.ManagedEntity) error {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000385 select {
Himani Chawla4d908332020-08-31 12:30:20 +0530386 // maybe be also some outside cancel (but no context modeled for the moment ...)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000387 // case <-ctx.Done():
mpagenko01e726e2020-10-23 09:45:29 +0000388 // logger.Infow("LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID})
mpagenko3af1f032020-06-10 08:53:41 +0000389 case <-time.After(30 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
mpagenko01e726e2020-10-23 09:45:29 +0000390 logger.Warnw("LockStateFSM uni-set timeout", log.Fields{"for device-id": oFsm.deviceID})
391 return fmt.Errorf("lockStateFsm uni-set timeout for device-id %s", oFsm.deviceID)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000392 case success := <-oFsm.omciLockResponseReceived:
Himani Chawla4d908332020-08-31 12:30:20 +0530393 if success {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000394 logger.Debug("LockStateFSM uni-set response received")
395 return nil
396 }
397 // should not happen so far
mpagenko01e726e2020-10-23 09:45:29 +0000398 logger.Warnw("LockStateFSM uni-set response error", log.Fields{"for device-id": oFsm.deviceID})
399 return fmt.Errorf("lockStateFsm uni-set responseError for device-id %s", oFsm.deviceID)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000400 }
401}