blob: be63eadfa6f8a2d9ceed70bd32bd48acdc43d29e [file] [log] [blame]
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +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 (
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000021 "context"
Andrea Campanella6515c582020-10-05 11:25:00 +020022 "fmt"
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000023 "time"
24
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000025 "github.com/looplab/fsm"
26
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000027 "github.com/opencord/omci-lib-go"
28 me "github.com/opencord/omci-lib-go/generated"
Girish Gowdra50e56422021-06-01 16:46:04 -070029 "github.com/opencord/voltha-lib-go/v5/pkg/log"
dbainbri4d3a0dc2020-12-02 00:33:42 +000030 //ic "github.com/opencord/voltha-protos/v4/go/inter_container"
31 //"github.com/opencord/voltha-protos/v4/go/openflow_13"
32 //"github.com/opencord/voltha-protos/v4/go/voltha"
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000033)
34
dbainbri4d3a0dc2020-12-02 00:33:42 +000035func (onuDeviceEntry *OnuDeviceEntry) enterDLStartingState(ctx context.Context, e *fsm.Event) {
36 logger.Debugw(ctx, "MibDownload FSM", log.Fields{"Start downloading OMCI MIB in state": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000037 // in case the used channel is not yet defined (can be re-used after restarts)
38 if onuDeviceEntry.omciMessageReceived == nil {
39 onuDeviceEntry.omciMessageReceived = make(chan bool)
dbainbri4d3a0dc2020-12-02 00:33:42 +000040 logger.Debug(ctx, "MibDownload FSM - defining the BridgeInit RxChannel")
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000041 }
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000042 // start go routine for processing of MibDownload messages
dbainbri4d3a0dc2020-12-02 00:33:42 +000043 go onuDeviceEntry.processMibDownloadMessages(ctx)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000044}
45
dbainbri4d3a0dc2020-12-02 00:33:42 +000046func (onuDeviceEntry *OnuDeviceEntry) enterCreatingGalState(ctx context.Context, e *fsm.Event) {
47 logger.Debugw(ctx, "MibDownload FSM", log.Fields{"Tx create::GAL Ethernet Profile in state": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000048 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +030049 meInstance, err := onuDeviceEntry.PDevOmciCC.sendCreateGalEthernetProfile(log.WithSpanFromContext(context.TODO(), ctx), onuDeviceEntry.pOpenOnuAc.omciTimeout, true)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000050 //accept also nil as (error) return value for writing to LastTx
51 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +030052 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000053 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +030054 logger.Errorw(ctx, "GalEthernetProfile create failed, aborting MibDownload FSM!",
55 log.Fields{"device-id": onuDeviceEntry.deviceID})
56 pMibDlFsm := onuDeviceEntry.pMibDownloadFsm
57 if pMibDlFsm != nil {
58 go func(a_pAFsm *AdapterFsm) {
59 _ = a_pAFsm.pFsm.Event(dlEvReset)
60 }(pMibDlFsm)
61 }
62 return
63 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000064 onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000065 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000066}
67
dbainbri4d3a0dc2020-12-02 00:33:42 +000068func (onuDeviceEntry *OnuDeviceEntry) enterSettingOnu2gState(ctx context.Context, e *fsm.Event) {
69 logger.Debugw(ctx, "MibDownload FSM", log.Fields{"Tx Set::ONU2-G in state": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000070 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +030071 meInstance, err := onuDeviceEntry.PDevOmciCC.sendSetOnu2g(log.WithSpanFromContext(context.TODO(), ctx),
72 onuDeviceEntry.pOpenOnuAc.omciTimeout, true)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000073 //accept also nil as (error) return value for writing to LastTx
74 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +030075 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000076 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +030077 logger.Errorw(ctx, "ONU2-G set failed, aborting MibDownload FSM!",
78 log.Fields{"device-id": onuDeviceEntry.deviceID})
79 pMibDlFsm := onuDeviceEntry.pMibDownloadFsm
80 if pMibDlFsm != nil {
81 go func(a_pAFsm *AdapterFsm) {
82 _ = a_pAFsm.pFsm.Event(dlEvReset)
83 }(pMibDlFsm)
84 }
85 return
86 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000087 onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +000088 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000089}
90
dbainbri4d3a0dc2020-12-02 00:33:42 +000091func (onuDeviceEntry *OnuDeviceEntry) enterBridgeInitState(ctx context.Context, e *fsm.Event) {
92 logger.Debugw(ctx, "MibDownload FSM - starting bridge config port loop", log.Fields{
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000093 "in state": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
dbainbri4d3a0dc2020-12-02 00:33:42 +000094 go onuDeviceEntry.performInitialBridgeSetup(ctx)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000095}
96
dbainbri4d3a0dc2020-12-02 00:33:42 +000097func (onuDeviceEntry *OnuDeviceEntry) enterDownloadedState(ctx context.Context, e *fsm.Event) {
98 logger.Debugw(ctx, "MibDownload FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
99 onuDeviceEntry.transferSystemEvent(ctx, MibDownloadDone)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000100 //let's reset the state machine in order to release all resources now
101 pMibDlFsm := onuDeviceEntry.pMibDownloadFsm
102 if pMibDlFsm != nil {
103 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
104 go func(a_pAFsm *AdapterFsm) {
105 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530106 _ = a_pAFsm.pFsm.Event(dlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000107 }
108 }(pMibDlFsm)
109 }
110}
111
dbainbri4d3a0dc2020-12-02 00:33:42 +0000112func (onuDeviceEntry *OnuDeviceEntry) enterResettingState(ctx context.Context, e *fsm.Event) {
113 logger.Debugw(ctx, "MibDownload FSM resetting", log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000114 pMibDlFsm := onuDeviceEntry.pMibDownloadFsm
115 if pMibDlFsm != nil {
116 // abort running message processing
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000117 fsmAbortMsg := Message{
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000118 Type: TestMsg,
119 Data: TestMessage{
120 TestMessageVal: AbortMessageProcessing,
121 },
122 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000123 pMibDlFsm.commChan <- fsmAbortMsg
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000124
125 //try to restart the FSM to 'disabled'
126 // see DownloadedState: decouple event transfer
127 go func(a_pAFsm *AdapterFsm) {
128 if a_pAFsm != nil && a_pAFsm.pFsm != nil {
Himani Chawla4d908332020-08-31 12:30:20 +0530129 _ = a_pAFsm.pFsm.Event(dlEvRestart)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000130 }
131 }(pMibDlFsm)
132 }
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000133}
134
dbainbri4d3a0dc2020-12-02 00:33:42 +0000135func (onuDeviceEntry *OnuDeviceEntry) processMibDownloadMessages(ctx context.Context) {
136 logger.Debugw(ctx, "Start MibDownload Msg processing", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000137loop:
138 for {
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000139 // case <-ctx.Done():
140 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
141 // break loop
Himani Chawla4d908332020-08-31 12:30:20 +0530142 // unless multiple channels are not involved, we should not use select
143 message, ok := <-onuDeviceEntry.pMibDownloadFsm.commChan
144 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000145 logger.Info(ctx, "MibDownload Rx Msg", log.Fields{"Message couldn't be read from channel for device-id": onuDeviceEntry.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530146 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
147 _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvRestart)
148 break loop
149 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000150 logger.Debugw(ctx, "MibDownload Rx Msg", log.Fields{"Received message for device-id": onuDeviceEntry.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530151
152 switch message.Type {
153 case TestMsg:
154 msg, _ := message.Data.(TestMessage)
155 if msg.TestMessageVal == AbortMessageProcessing {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000156 logger.Debugw(ctx, "MibDownload abort ProcessMsg", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000157 break loop
158 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000159 logger.Warnw(ctx, "MibDownload unknown TestMessage", log.Fields{"device-id": onuDeviceEntry.deviceID, "MessageVal": msg.TestMessageVal})
Himani Chawla4d908332020-08-31 12:30:20 +0530160 case OMCI:
161 msg, _ := message.Data.(OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000162 onuDeviceEntry.handleOmciMibDownloadMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530163 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000164 logger.Warn(ctx, "MibDownload Rx Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID,
Himani Chawla4d908332020-08-31 12:30:20 +0530165 "message.Type": message.Type})
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000166 }
Himani Chawla4d908332020-08-31 12:30:20 +0530167
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000168 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000169 logger.Debugw(ctx, "End MibDownload Msg processing", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000170}
171
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000172func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadCreateResponseMessage(ctx context.Context, msg OmciMessage) {
173 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse)
174 if msgLayer == nil {
175 logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
176 return
177 }
178 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
179 if !msgOk {
180 logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
181 return
182 }
183 logger.Debugw(ctx, "CreateResponse Data", log.Fields{"device-id": onuDeviceEntry.deviceID, "data-fields": msgObj})
184 if msgObj.Result != me.Success && msgObj.Result != me.InstanceExists {
185 logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": onuDeviceEntry.deviceID, "Error": msgObj.Result})
186 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
187 return
188 }
189 // maybe there is a way of pushing the specific create response type generally to the FSM
190 // and let the FSM verify, if the response was according to current state
191 // and possibly store the element to DB and progress - maybe some future option ...
192 // but as that is not straightforward to me I insert the type checkes manually here
193 // and feed the FSM with only 'pre-defined' events ...
194
195 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RLock()
196 if onuDeviceEntry.PDevOmciCC.pLastTxMeInstance != nil {
197 if msgObj.EntityClass == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetClassID() &&
198 msgObj.EntityInstance == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetEntityID() {
199 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
200 // if, then something like:
201 //onuDeviceEntry.pOnuDB.StoreMe(msgObj)
202
203 // maybe we can use just the same eventName for different state transitions like "forward"
204 // - might be checked, but so far I go for sure and have to inspect the concrete state events ...
205 switch onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetName() {
206 case "GalEthernetProfile":
207 { // let the FSM proceed ...
208 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock()
209 _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvRxGalResp)
210 }
211 case "MacBridgeServiceProfile",
212 "MacBridgePortConfigurationData",
213 "ExtendedVlanTaggingOperationConfigurationData":
214 { // let bridge init proceed by stopping the wait function
215 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock()
216 onuDeviceEntry.omciMessageReceived <- true
217 }
218 default:
219 {
220 logger.Warnw(ctx, "Unsupported ME name received!",
221 log.Fields{"ME name": onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetName(), "device-id": onuDeviceEntry.deviceID})
222 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock()
223 }
224 }
225 } else {
226 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock()
227 }
228 } else {
229 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock()
230 logger.Errorw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": onuDeviceEntry.deviceID})
231 }
232}
233
234func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadSetResponseMessage(ctx context.Context, msg OmciMessage) {
235 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
236 if msgLayer == nil {
237 logger.Errorw(ctx, "Omci Msg layer could not be detected for SetResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
238 return
239 }
240 msgObj, msgOk := msgLayer.(*omci.SetResponse)
241 if !msgOk {
242 logger.Errorw(ctx, "Omci Msg layer could not be assigned for SetResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
243 return
244 }
245 logger.Debugw(ctx, "SetResponse Data", log.Fields{"device-id": onuDeviceEntry.deviceID, "data-fields": msgObj})
246 if msgObj.Result != me.Success {
247 logger.Errorw(ctx, "Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": onuDeviceEntry.deviceID,
248 "Error": msgObj.Result})
249 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
250 return
251 }
252 // compare comments above for CreateResponse (apply also here ...)
253
254 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RLock()
255 if onuDeviceEntry.PDevOmciCC.pLastTxMeInstance != nil {
256 if msgObj.EntityClass == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetClassID() &&
257 msgObj.EntityInstance == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetEntityID() {
258 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
259 // if, then something like:
260 //onuDeviceEntry.pOnuDB.StoreMe(msgObj)
261
262 switch onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetName() {
263 case "Onu2G":
264 { // let the FSM proceed ...
265 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock()
266 _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvRxOnu2gResp)
267 }
268 //so far that was the only MibDownlad Set Element ...
269 default:
270 {
271 logger.Warnw(ctx, "Unsupported ME name received!",
272 log.Fields{"ME name": onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetName(), "device-id": onuDeviceEntry.deviceID})
273 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock()
274 }
275
276 }
277 } else {
278 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock()
279 }
280 } else {
281 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock()
282 logger.Errorw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": onuDeviceEntry.deviceID})
283 }
284}
285
dbainbri4d3a0dc2020-12-02 00:33:42 +0000286func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadMessage(ctx context.Context, msg OmciMessage) {
287 logger.Debugw(ctx, "Rx OMCI MibDownload Msg", log.Fields{"device-id": onuDeviceEntry.deviceID,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000288 "msgType": msg.OmciMsg.MessageType})
289
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000290 switch msg.OmciMsg.MessageType {
291 case omci.CreateResponseType:
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000292 onuDeviceEntry.handleOmciMibDownloadCreateResponseMessage(ctx, msg)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000293 //TODO
294 // onuDeviceEntry.pMibDownloadFsm.pFsm.Event("rx_evtocd_resp")
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000295 case omci.SetResponseType:
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000296 onuDeviceEntry.handleOmciMibDownloadSetResponseMessage(ctx, msg)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000297 default:
298 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000299 logger.Errorw(ctx, "Rx OMCI MibDownload unhandled MsgType", log.Fields{"device-id": onuDeviceEntry.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200300 "omciMsgType": msg.OmciMsg.MessageType})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000301 return
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000302 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000303 } // switch msg.OmciMsg.MessageType
304}
305
dbainbri4d3a0dc2020-12-02 00:33:42 +0000306func (onuDeviceEntry *OnuDeviceEntry) performInitialBridgeSetup(ctx context.Context) {
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000307 for uniNo, uniPort := range onuDeviceEntry.baseDeviceHandler.uniEntityMap {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000308 logger.Debugw(ctx, "Starting IntialBridgeSetup", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000309 "device-id": onuDeviceEntry.deviceID, "for PortNo": uniNo})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000310
311 //create MBSP
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000312 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300313 meInstance, err := onuDeviceEntry.PDevOmciCC.sendCreateMBServiceProfile(
Girish Gowdra0b235842021-03-09 13:06:46 -0800314 log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.pOpenOnuAc.omciTimeout, true)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300315 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000316 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300317 logger.Errorw(ctx, "MBServiceProfile create failed, aborting MibDownload FSM!", log.Fields{"device-id": onuDeviceEntry.deviceID})
318 _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset)
319 return
320 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000321 onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000322 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000323 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +0300324 err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000325 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000326 logger.Errorw(ctx, "InitialBridgeSetup failed at MBSP, aborting MIB Download!",
Andrea Campanella6515c582020-10-05 11:25:00 +0200327 log.Fields{"device-id": onuDeviceEntry.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530328 _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000329 return
330 }
331
332 //create MBPCD
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000333 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Lock()
Mahir Gunyel6781f962021-05-16 23:30:08 -0700334 meInstance, err = onuDeviceEntry.PDevOmciCC.sendCreateMBPConfigDataUniSide(
Girish Gowdra0b235842021-03-09 13:06:46 -0800335 log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.pOpenOnuAc.omciTimeout, true)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300336 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000337 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300338 logger.Errorw(ctx, "MBPConfigData create failed, aborting MibDownload FSM!",
339 log.Fields{"device-id": onuDeviceEntry.deviceID})
340 _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset)
341 return
342 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000343 onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000344 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000345 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +0000346 err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000347 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000348 logger.Errorw(ctx, "InitialBridgeSetup failed at MBPCD, aborting MIB Download!",
Andrea Campanella6515c582020-10-05 11:25:00 +0200349 log.Fields{"device-id": onuDeviceEntry.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530350 _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000351 return
352 }
353
354 //create EVTOCD
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000355 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Lock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300356 meInstance, err = onuDeviceEntry.PDevOmciCC.sendCreateEVTOConfigData(
Girish Gowdra0b235842021-03-09 13:06:46 -0800357 log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.pOpenOnuAc.omciTimeout, true)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300358 if err != nil {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000359 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300360 logger.Errorw(ctx, "EVTOConfigData create failed, aborting MibDownload FSM!",
361 log.Fields{"device-id": onuDeviceEntry.deviceID})
362 _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset)
363 return
364 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000365 onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000366 onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000367 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +0000368 err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000369 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000370 logger.Errorw(ctx, "InitialBridgeSetup failed at EVTOCD, aborting MIB Download!",
Andrea Campanella6515c582020-10-05 11:25:00 +0200371 log.Fields{"device-id": onuDeviceEntry.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530372 _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000373 return
374 }
375 }
376 // if Config has been done for all UNI related instances let the FSM proceed
377 // while we did not check here, if there is some port at all - !?
dbainbri4d3a0dc2020-12-02 00:33:42 +0000378 logger.Infow(ctx, "IntialBridgeSetup finished", log.Fields{"device-id": onuDeviceEntry.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530379 _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvRxBridgeResp)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000380}
381
dbainbri4d3a0dc2020-12-02 00:33:42 +0000382func (onuDeviceEntry *OnuDeviceEntry) waitforOmciResponse(ctx context.Context, apMeInstance *me.ManagedEntity) error {
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000383 select {
Himani Chawla4d908332020-08-31 12:30:20 +0530384 // maybe be also some outside cancel (but no context modeled for the moment ...)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000385 // case <-ctx.Done():
386 // logger.Info("MibDownload-bridge-init message reception canceled", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000387 case <-time.After(onuDeviceEntry.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
dbainbri4d3a0dc2020-12-02 00:33:42 +0000388 logger.Warnw(ctx, "MibDownload-bridge-init timeout", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200389 return fmt.Errorf("mibDownloadBridgeInit timeout %s", onuDeviceEntry.deviceID)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000390 case success := <-onuDeviceEntry.omciMessageReceived:
Himani Chawla4d908332020-08-31 12:30:20 +0530391 if success {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000392 logger.Debug(ctx, "MibDownload-bridge-init response received")
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000393 return nil
394 }
395 // should not happen so far
dbainbri4d3a0dc2020-12-02 00:33:42 +0000396 logger.Warnw(ctx, "MibDownload-bridge-init response error", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200397 return fmt.Errorf("mibDownloadBridgeInit responseError %s", onuDeviceEntry.deviceID)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000398 }
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000399}