blob: 9c49f9b75ea991d889733f85cbfce0b6485c9aa4 [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
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000017//Package mib provides the utilities for managing the onu mib
18package mib
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000019
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"
khenaidoo7d3c5582021-08-11 18:09:44 -040029 "github.com/opencord/voltha-lib-go/v7/pkg/log"
30 //ic "github.com/opencord/voltha-protos/v5/go/inter_container"
31 //"github.com/opencord/voltha-protos/v5/go/openflow_13"
32 //"github.com/opencord/voltha-protos/v5/go/voltha"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000033 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000034)
35
dbainbri4d3a0dc2020-12-02 00:33:42 +000036func (onuDeviceEntry *OnuDeviceEntry) enterDLStartingState(ctx context.Context, e *fsm.Event) {
37 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 +000038 // in case the used channel is not yet defined (can be re-used after restarts)
39 if onuDeviceEntry.omciMessageReceived == nil {
40 onuDeviceEntry.omciMessageReceived = make(chan bool)
dbainbri4d3a0dc2020-12-02 00:33:42 +000041 logger.Debug(ctx, "MibDownload FSM - defining the BridgeInit RxChannel")
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000042 }
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000043 // start go routine for processing of MibDownload messages
dbainbri4d3a0dc2020-12-02 00:33:42 +000044 go onuDeviceEntry.processMibDownloadMessages(ctx)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000045}
46
dbainbri4d3a0dc2020-12-02 00:33:42 +000047func (onuDeviceEntry *OnuDeviceEntry) enterCreatingGalState(ctx context.Context, e *fsm.Event) {
48 logger.Debugw(ctx, "MibDownload FSM", log.Fields{"Tx create::GAL Ethernet Profile in state": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000049 onuDeviceEntry.mutexPLastTxMeInstance.Lock()
50 meInstance, err := onuDeviceEntry.PDevOmciCC.SendCreateGalEthernetProfile(log.WithSpanFromContext(context.TODO(), ctx),
51 onuDeviceEntry.baseDeviceHandler.GetOmciTimeout(), true)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000052 //accept also nil as (error) return value for writing to LastTx
53 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +030054 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000055 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +030056 logger.Errorw(ctx, "GalEthernetProfile create failed, aborting MibDownload FSM!",
57 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000058 pMibDlFsm := onuDeviceEntry.PMibDownloadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +030059 if pMibDlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000060 go func(a_pAFsm *cmn.AdapterFsm) {
61 _ = a_pAFsm.PFsm.Event(DlEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +030062 }(pMibDlFsm)
63 }
64 return
65 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000066 onuDeviceEntry.pLastTxMeInstance = meInstance
67 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000068}
69
dbainbri4d3a0dc2020-12-02 00:33:42 +000070func (onuDeviceEntry *OnuDeviceEntry) enterSettingOnu2gState(ctx context.Context, e *fsm.Event) {
71 logger.Debugw(ctx, "MibDownload FSM", log.Fields{"Tx Set::ONU2-G in state": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000072 onuDeviceEntry.mutexPLastTxMeInstance.Lock()
73 meInstance, err := onuDeviceEntry.PDevOmciCC.SendSetOnu2g(log.WithSpanFromContext(context.TODO(), ctx),
74 onuDeviceEntry.baseDeviceHandler.GetOmciTimeout(), true)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000075 //accept also nil as (error) return value for writing to LastTx
76 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +030077 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000078 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +030079 logger.Errorw(ctx, "ONU2-G set failed, aborting MibDownload FSM!",
80 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000081 pMibDlFsm := onuDeviceEntry.PMibDownloadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +030082 if pMibDlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000083 go func(a_pAFsm *cmn.AdapterFsm) {
84 _ = a_pAFsm.PFsm.Event(DlEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +030085 }(pMibDlFsm)
86 }
87 return
88 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000089 onuDeviceEntry.pLastTxMeInstance = meInstance
90 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000091}
92
dbainbri4d3a0dc2020-12-02 00:33:42 +000093func (onuDeviceEntry *OnuDeviceEntry) enterBridgeInitState(ctx context.Context, e *fsm.Event) {
94 logger.Debugw(ctx, "MibDownload FSM - starting bridge config port loop", log.Fields{
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000095 "in state": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
dbainbri4d3a0dc2020-12-02 00:33:42 +000096 go onuDeviceEntry.performInitialBridgeSetup(ctx)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000097}
98
dbainbri4d3a0dc2020-12-02 00:33:42 +000099func (onuDeviceEntry *OnuDeviceEntry) enterDownloadedState(ctx context.Context, e *fsm.Event) {
100 logger.Debugw(ctx, "MibDownload FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000101 onuDeviceEntry.transferSystemEvent(ctx, cmn.MibDownloadDone)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000102 //let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000103 pMibDlFsm := onuDeviceEntry.PMibDownloadFsm
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000104 if pMibDlFsm != nil {
105 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000106 go func(a_pAFsm *cmn.AdapterFsm) {
107 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
108 _ = a_pAFsm.PFsm.Event(DlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000109 }
110 }(pMibDlFsm)
111 }
112}
113
dbainbri4d3a0dc2020-12-02 00:33:42 +0000114func (onuDeviceEntry *OnuDeviceEntry) enterResettingState(ctx context.Context, e *fsm.Event) {
115 logger.Debugw(ctx, "MibDownload FSM resetting", log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000116 pMibDlFsm := onuDeviceEntry.PMibDownloadFsm
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000117 if pMibDlFsm != nil {
118 // abort running message processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000119 fsmAbortMsg := cmn.Message{
120 Type: cmn.TestMsg,
121 Data: cmn.TestMessage{
122 TestMessageVal: cmn.AbortMessageProcessing,
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000123 },
124 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000125 pMibDlFsm.CommChan <- fsmAbortMsg
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000126
127 //try to restart the FSM to 'disabled'
128 // see DownloadedState: decouple event transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000129 go func(a_pAFsm *cmn.AdapterFsm) {
130 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
131 _ = a_pAFsm.PFsm.Event(DlEvRestart)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000132 }
133 }(pMibDlFsm)
134 }
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000135}
136
dbainbri4d3a0dc2020-12-02 00:33:42 +0000137func (onuDeviceEntry *OnuDeviceEntry) processMibDownloadMessages(ctx context.Context) {
138 logger.Debugw(ctx, "Start MibDownload Msg processing", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000139loop:
140 for {
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000141 // case <-ctx.Done():
142 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
143 // break loop
Himani Chawla4d908332020-08-31 12:30:20 +0530144 // unless multiple channels are not involved, we should not use select
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000145 message, ok := <-onuDeviceEntry.PMibDownloadFsm.CommChan
Himani Chawla4d908332020-08-31 12:30:20 +0530146 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000147 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 +0530148 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000149 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvRestart)
Himani Chawla4d908332020-08-31 12:30:20 +0530150 break loop
151 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000152 logger.Debugw(ctx, "MibDownload Rx Msg", log.Fields{"Received message for device-id": onuDeviceEntry.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530153
154 switch message.Type {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000155 case cmn.TestMsg:
156 msg, _ := message.Data.(cmn.TestMessage)
157 if msg.TestMessageVal == cmn.AbortMessageProcessing {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000158 logger.Debugw(ctx, "MibDownload abort ProcessMsg", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000159 break loop
160 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000161 logger.Warnw(ctx, "MibDownload unknown TestMessage", log.Fields{"device-id": onuDeviceEntry.deviceID, "MessageVal": msg.TestMessageVal})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000162 case cmn.OMCI:
163 msg, _ := message.Data.(cmn.OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000164 onuDeviceEntry.handleOmciMibDownloadMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530165 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000166 logger.Warn(ctx, "MibDownload Rx Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID,
Himani Chawla4d908332020-08-31 12:30:20 +0530167 "message.Type": message.Type})
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000168 }
Himani Chawla4d908332020-08-31 12:30:20 +0530169
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000170 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000171 logger.Debugw(ctx, "End MibDownload Msg processing", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000172}
173
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000174func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadCreateResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000175 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse)
176 if msgLayer == nil {
177 logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
178 return
179 }
180 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
181 if !msgOk {
182 logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
183 return
184 }
185 logger.Debugw(ctx, "CreateResponse Data", log.Fields{"device-id": onuDeviceEntry.deviceID, "data-fields": msgObj})
186 if msgObj.Result != me.Success && msgObj.Result != me.InstanceExists {
187 logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": onuDeviceEntry.deviceID, "Error": msgObj.Result})
188 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
189 return
190 }
191 // maybe there is a way of pushing the specific create response type generally to the FSM
192 // and let the FSM verify, if the response was according to current state
193 // and possibly store the element to DB and progress - maybe some future option ...
194 // but as that is not straightforward to me I insert the type checkes manually here
195 // and feed the FSM with only 'pre-defined' events ...
196
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000197 onuDeviceEntry.mutexPLastTxMeInstance.RLock()
198 if onuDeviceEntry.pLastTxMeInstance != nil {
199 if msgObj.EntityClass == onuDeviceEntry.pLastTxMeInstance.GetClassID() &&
200 msgObj.EntityInstance == onuDeviceEntry.pLastTxMeInstance.GetEntityID() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000201 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
202 // if, then something like:
203 //onuDeviceEntry.pOnuDB.StoreMe(msgObj)
204
205 // maybe we can use just the same eventName for different state transitions like "forward"
206 // - might be checked, but so far I go for sure and have to inspect the concrete state events ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000207 switch onuDeviceEntry.pLastTxMeInstance.GetName() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000208 case "GalEthernetProfile":
209 { // let the FSM proceed ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000210 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
211 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvRxGalResp)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000212 }
213 case "MacBridgeServiceProfile",
214 "MacBridgePortConfigurationData",
215 "ExtendedVlanTaggingOperationConfigurationData":
216 { // let bridge init proceed by stopping the wait function
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000217 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000218 onuDeviceEntry.omciMessageReceived <- true
219 }
220 default:
221 {
222 logger.Warnw(ctx, "Unsupported ME name received!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000223 log.Fields{"ME name": onuDeviceEntry.pLastTxMeInstance.GetName(), "device-id": onuDeviceEntry.deviceID})
224 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000225 }
226 }
227 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000228 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000229 }
230 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000231 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000232 logger.Errorw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": onuDeviceEntry.deviceID})
233 }
234}
235
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000236func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadSetResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000237 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
238 if msgLayer == nil {
239 logger.Errorw(ctx, "Omci Msg layer could not be detected for SetResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
240 return
241 }
242 msgObj, msgOk := msgLayer.(*omci.SetResponse)
243 if !msgOk {
244 logger.Errorw(ctx, "Omci Msg layer could not be assigned for SetResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
245 return
246 }
247 logger.Debugw(ctx, "SetResponse Data", log.Fields{"device-id": onuDeviceEntry.deviceID, "data-fields": msgObj})
248 if msgObj.Result != me.Success {
249 logger.Errorw(ctx, "Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": onuDeviceEntry.deviceID,
250 "Error": msgObj.Result})
251 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
252 return
253 }
254 // compare comments above for CreateResponse (apply also here ...)
255
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000256 onuDeviceEntry.mutexPLastTxMeInstance.RLock()
257 if onuDeviceEntry.pLastTxMeInstance != nil {
258 if msgObj.EntityClass == onuDeviceEntry.pLastTxMeInstance.GetClassID() &&
259 msgObj.EntityInstance == onuDeviceEntry.pLastTxMeInstance.GetEntityID() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000260 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
261 // if, then something like:
262 //onuDeviceEntry.pOnuDB.StoreMe(msgObj)
263
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000264 switch onuDeviceEntry.pLastTxMeInstance.GetName() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000265 case "Onu2G":
266 { // let the FSM proceed ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000267 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
268 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvRxOnu2gResp)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000269 }
270 //so far that was the only MibDownlad Set Element ...
271 default:
272 {
273 logger.Warnw(ctx, "Unsupported ME name received!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000274 log.Fields{"ME name": onuDeviceEntry.pLastTxMeInstance.GetName(), "device-id": onuDeviceEntry.deviceID})
275 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000276 }
277
278 }
279 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000280 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000281 }
282 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000283 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000284 logger.Errorw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": onuDeviceEntry.deviceID})
285 }
286}
287
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000288func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000289 logger.Debugw(ctx, "Rx OMCI MibDownload Msg", log.Fields{"device-id": onuDeviceEntry.deviceID,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000290 "msgType": msg.OmciMsg.MessageType})
291
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000292 switch msg.OmciMsg.MessageType {
293 case omci.CreateResponseType:
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000294 onuDeviceEntry.handleOmciMibDownloadCreateResponseMessage(ctx, msg)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000295 //TODO
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000296 // onuDeviceEntry.PMibDownloadFsm.PFsm.Event("rx_evtocd_resp")
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000297 case omci.SetResponseType:
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000298 onuDeviceEntry.handleOmciMibDownloadSetResponseMessage(ctx, msg)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000299 default:
300 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000301 logger.Errorw(ctx, "Rx OMCI MibDownload unhandled MsgType", log.Fields{"device-id": onuDeviceEntry.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200302 "omciMsgType": msg.OmciMsg.MessageType})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000303 return
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000304 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000305 } // switch msg.OmciMsg.MessageType
306}
307
dbainbri4d3a0dc2020-12-02 00:33:42 +0000308func (onuDeviceEntry *OnuDeviceEntry) performInitialBridgeSetup(ctx context.Context) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000309 for uniNo, uniPort := range *onuDeviceEntry.baseDeviceHandler.GetUniEntityMap() {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000310 logger.Debugw(ctx, "Starting IntialBridgeSetup", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000311 "device-id": onuDeviceEntry.deviceID, "for PortNo": uniNo})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000312
313 //create MBSP
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000314 onuDeviceEntry.mutexPLastTxMeInstance.Lock()
315 meInstance, err := onuDeviceEntry.PDevOmciCC.SendCreateMBServiceProfile(
316 log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.baseDeviceHandler.GetOmciTimeout(), true)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300317 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000318 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300319 logger.Errorw(ctx, "MBServiceProfile create failed, aborting MibDownload FSM!", log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000320 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300321 return
322 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000323 onuDeviceEntry.pLastTxMeInstance = meInstance
324 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000325 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +0300326 err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000327 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000328 logger.Errorw(ctx, "InitialBridgeSetup failed at MBSP, aborting MIB Download!",
Andrea Campanella6515c582020-10-05 11:25:00 +0200329 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000330 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000331 return
332 }
333
334 //create MBPCD
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000335 onuDeviceEntry.mutexPLastTxMeInstance.Lock()
336 meInstance, err = onuDeviceEntry.PDevOmciCC.SendCreateMBPConfigDataUniSide(
337 log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.baseDeviceHandler.GetOmciTimeout(), true)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300338 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000339 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300340 logger.Errorw(ctx, "MBPConfigData create failed, aborting MibDownload FSM!",
341 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000342 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300343 return
344 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000345 onuDeviceEntry.pLastTxMeInstance = meInstance
346 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000347 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +0000348 err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000349 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000350 logger.Errorw(ctx, "InitialBridgeSetup failed at MBPCD, aborting MIB Download!",
Andrea Campanella6515c582020-10-05 11:25:00 +0200351 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000352 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000353 return
354 }
355
356 //create EVTOCD
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000357 onuDeviceEntry.mutexPLastTxMeInstance.Lock()
358 meInstance, err = onuDeviceEntry.PDevOmciCC.SendCreateEVTOConfigData(
359 log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.baseDeviceHandler.GetOmciTimeout(), true)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300360 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000361 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300362 logger.Errorw(ctx, "EVTOConfigData create failed, aborting MibDownload FSM!",
363 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000364 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300365 return
366 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000367 onuDeviceEntry.pLastTxMeInstance = meInstance
368 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000369 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +0000370 err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000371 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000372 logger.Errorw(ctx, "InitialBridgeSetup failed at EVTOCD, aborting MIB Download!",
Andrea Campanella6515c582020-10-05 11:25:00 +0200373 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000374 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000375 return
376 }
377 }
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 - !?
dbainbri4d3a0dc2020-12-02 00:33:42 +0000380 logger.Infow(ctx, "IntialBridgeSetup finished", log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000381 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvRxBridgeResp)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000382}
383
dbainbri4d3a0dc2020-12-02 00:33:42 +0000384func (onuDeviceEntry *OnuDeviceEntry) waitforOmciResponse(ctx context.Context, apMeInstance *me.ManagedEntity) error {
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000385 select {
Himani Chawla4d908332020-08-31 12:30:20 +0530386 // maybe be also some outside cancel (but no context modeled for the moment ...)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000387 // case <-ctx.Done():
388 // logger.Info("MibDownload-bridge-init message reception canceled", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000389 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 +0000390 logger.Warnw(ctx, "MibDownload-bridge-init timeout", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200391 return fmt.Errorf("mibDownloadBridgeInit timeout %s", onuDeviceEntry.deviceID)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000392 case success := <-onuDeviceEntry.omciMessageReceived:
Himani Chawla4d908332020-08-31 12:30:20 +0530393 if success {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000394 logger.Debug(ctx, "MibDownload-bridge-init response received")
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000395 return nil
396 }
397 // should not happen so far
dbainbri4d3a0dc2020-12-02 00:33:42 +0000398 logger.Warnw(ctx, "MibDownload-bridge-init response error", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200399 return fmt.Errorf("mibDownloadBridgeInit responseError %s", onuDeviceEntry.deviceID)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000400 }
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000401}