blob: 9f5f8641d69c9a1a2aaa622933a564046eb014b5 [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
mpagenko836a1fd2021-11-01 16:12:42 +000027 "github.com/opencord/omci-lib-go/v2"
28 me "github.com/opencord/omci-lib-go/v2/generated"
khenaidoo7d3c5582021-08-11 18:09:44 -040029 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000030 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000031)
32
dbainbri4d3a0dc2020-12-02 00:33:42 +000033func (onuDeviceEntry *OnuDeviceEntry) enterDLStartingState(ctx context.Context, e *fsm.Event) {
34 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 +000035 // in case the used channel is not yet defined (can be re-used after restarts)
36 if onuDeviceEntry.omciMessageReceived == nil {
37 onuDeviceEntry.omciMessageReceived = make(chan bool)
dbainbri4d3a0dc2020-12-02 00:33:42 +000038 logger.Debug(ctx, "MibDownload FSM - defining the BridgeInit RxChannel")
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000039 }
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000040 // start go routine for processing of MibDownload messages
dbainbri4d3a0dc2020-12-02 00:33:42 +000041 go onuDeviceEntry.processMibDownloadMessages(ctx)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000042}
43
dbainbri4d3a0dc2020-12-02 00:33:42 +000044func (onuDeviceEntry *OnuDeviceEntry) enterCreatingGalState(ctx context.Context, e *fsm.Event) {
45 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 +000046 onuDeviceEntry.mutexPLastTxMeInstance.Lock()
47 meInstance, err := onuDeviceEntry.PDevOmciCC.SendCreateGalEthernetProfile(log.WithSpanFromContext(context.TODO(), ctx),
48 onuDeviceEntry.baseDeviceHandler.GetOmciTimeout(), true)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000049 //accept also nil as (error) return value for writing to LastTx
50 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +030051 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000052 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +030053 logger.Errorw(ctx, "GalEthernetProfile create failed, aborting MibDownload FSM!",
54 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000055 pMibDlFsm := onuDeviceEntry.PMibDownloadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +030056 if pMibDlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000057 go func(a_pAFsm *cmn.AdapterFsm) {
58 _ = a_pAFsm.PFsm.Event(DlEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +030059 }(pMibDlFsm)
60 }
61 return
62 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000063 onuDeviceEntry.pLastTxMeInstance = meInstance
64 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000065}
66
dbainbri4d3a0dc2020-12-02 00:33:42 +000067func (onuDeviceEntry *OnuDeviceEntry) enterSettingOnu2gState(ctx context.Context, e *fsm.Event) {
68 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 +000069 onuDeviceEntry.mutexPLastTxMeInstance.Lock()
70 meInstance, err := onuDeviceEntry.PDevOmciCC.SendSetOnu2g(log.WithSpanFromContext(context.TODO(), ctx),
71 onuDeviceEntry.baseDeviceHandler.GetOmciTimeout(), true)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000072 //accept also nil as (error) return value for writing to LastTx
73 // - this avoids misinterpretation of new received OMCI messages
ozgecanetsiab36ed572021-04-01 10:38:48 +030074 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000075 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +030076 logger.Errorw(ctx, "ONU2-G set failed, aborting MibDownload FSM!",
77 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000078 pMibDlFsm := onuDeviceEntry.PMibDownloadFsm
ozgecanetsiab36ed572021-04-01 10:38:48 +030079 if pMibDlFsm != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000080 go func(a_pAFsm *cmn.AdapterFsm) {
81 _ = a_pAFsm.PFsm.Event(DlEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +030082 }(pMibDlFsm)
83 }
84 return
85 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000086 onuDeviceEntry.pLastTxMeInstance = meInstance
87 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000088}
89
dbainbri4d3a0dc2020-12-02 00:33:42 +000090func (onuDeviceEntry *OnuDeviceEntry) enterBridgeInitState(ctx context.Context, e *fsm.Event) {
91 logger.Debugw(ctx, "MibDownload FSM - starting bridge config port loop", log.Fields{
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000092 "in state": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
dbainbri4d3a0dc2020-12-02 00:33:42 +000093 go onuDeviceEntry.performInitialBridgeSetup(ctx)
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +000094}
95
dbainbri4d3a0dc2020-12-02 00:33:42 +000096func (onuDeviceEntry *OnuDeviceEntry) enterDownloadedState(ctx context.Context, e *fsm.Event) {
97 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 +000098 onuDeviceEntry.transferSystemEvent(ctx, cmn.MibDownloadDone)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000099 //let's reset the state machine in order to release all resources now
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000100 pMibDlFsm := onuDeviceEntry.PMibDownloadFsm
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000101 if pMibDlFsm != nil {
102 // obviously calling some FSM event here directly does not work - so trying to decouple it ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000103 go func(a_pAFsm *cmn.AdapterFsm) {
104 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
105 _ = a_pAFsm.PFsm.Event(DlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000106 }
107 }(pMibDlFsm)
108 }
109}
110
dbainbri4d3a0dc2020-12-02 00:33:42 +0000111func (onuDeviceEntry *OnuDeviceEntry) enterResettingState(ctx context.Context, e *fsm.Event) {
112 logger.Debugw(ctx, "MibDownload FSM resetting", log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000113 pMibDlFsm := onuDeviceEntry.PMibDownloadFsm
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000114 if pMibDlFsm != nil {
115 // abort running message processing
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000116 fsmAbortMsg := cmn.Message{
117 Type: cmn.TestMsg,
118 Data: cmn.TestMessage{
119 TestMessageVal: cmn.AbortMessageProcessing,
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000120 },
121 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000122 pMibDlFsm.CommChan <- fsmAbortMsg
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000123
124 //try to restart the FSM to 'disabled'
125 // see DownloadedState: decouple event transfer
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000126 go func(a_pAFsm *cmn.AdapterFsm) {
127 if a_pAFsm != nil && a_pAFsm.PFsm != nil {
128 _ = a_pAFsm.PFsm.Event(DlEvRestart)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000129 }
130 }(pMibDlFsm)
131 }
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000132}
133
dbainbri4d3a0dc2020-12-02 00:33:42 +0000134func (onuDeviceEntry *OnuDeviceEntry) processMibDownloadMessages(ctx context.Context) {
135 logger.Debugw(ctx, "Start MibDownload Msg processing", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000136loop:
137 for {
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000138 // case <-ctx.Done():
139 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
140 // break loop
Himani Chawla4d908332020-08-31 12:30:20 +0530141 // unless multiple channels are not involved, we should not use select
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000142 message, ok := <-onuDeviceEntry.PMibDownloadFsm.CommChan
Himani Chawla4d908332020-08-31 12:30:20 +0530143 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000144 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 +0530145 // but then we have to ensure a restart of the FSM as well - as exceptional procedure
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000146 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvRestart)
Himani Chawla4d908332020-08-31 12:30:20 +0530147 break loop
148 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000149 logger.Debugw(ctx, "MibDownload Rx Msg", log.Fields{"Received message for device-id": onuDeviceEntry.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530150
151 switch message.Type {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000152 case cmn.TestMsg:
153 msg, _ := message.Data.(cmn.TestMessage)
154 if msg.TestMessageVal == cmn.AbortMessageProcessing {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000155 logger.Debugw(ctx, "MibDownload abort ProcessMsg", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000156 break loop
157 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000158 logger.Warnw(ctx, "MibDownload unknown TestMessage", log.Fields{"device-id": onuDeviceEntry.deviceID, "MessageVal": msg.TestMessageVal})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000159 case cmn.OMCI:
160 msg, _ := message.Data.(cmn.OmciMessage)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000161 onuDeviceEntry.handleOmciMibDownloadMessage(ctx, msg)
Himani Chawla4d908332020-08-31 12:30:20 +0530162 default:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000163 logger.Warn(ctx, "MibDownload Rx Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID,
Himani Chawla4d908332020-08-31 12:30:20 +0530164 "message.Type": message.Type})
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000165 }
Himani Chawla4d908332020-08-31 12:30:20 +0530166
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000167 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000168 logger.Debugw(ctx, "End MibDownload Msg processing", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000169}
170
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000171func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadCreateResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000172 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse)
173 if msgLayer == nil {
174 logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
175 return
176 }
177 msgObj, msgOk := msgLayer.(*omci.CreateResponse)
178 if !msgOk {
179 logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
180 return
181 }
182 logger.Debugw(ctx, "CreateResponse Data", log.Fields{"device-id": onuDeviceEntry.deviceID, "data-fields": msgObj})
183 if msgObj.Result != me.Success && msgObj.Result != me.InstanceExists {
184 logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": onuDeviceEntry.deviceID, "Error": msgObj.Result})
185 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
186 return
187 }
188 // maybe there is a way of pushing the specific create response type generally to the FSM
189 // and let the FSM verify, if the response was according to current state
190 // and possibly store the element to DB and progress - maybe some future option ...
191 // but as that is not straightforward to me I insert the type checkes manually here
192 // and feed the FSM with only 'pre-defined' events ...
193
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000194 onuDeviceEntry.mutexPLastTxMeInstance.RLock()
195 if onuDeviceEntry.pLastTxMeInstance != nil {
196 if msgObj.EntityClass == onuDeviceEntry.pLastTxMeInstance.GetClassID() &&
197 msgObj.EntityInstance == onuDeviceEntry.pLastTxMeInstance.GetEntityID() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000198 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
199 // if, then something like:
200 //onuDeviceEntry.pOnuDB.StoreMe(msgObj)
201
202 // maybe we can use just the same eventName for different state transitions like "forward"
203 // - 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 +0000204 switch onuDeviceEntry.pLastTxMeInstance.GetName() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000205 case "GalEthernetProfile":
206 { // let the FSM proceed ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000207 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
208 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvRxGalResp)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000209 }
210 case "MacBridgeServiceProfile",
211 "MacBridgePortConfigurationData",
212 "ExtendedVlanTaggingOperationConfigurationData":
213 { // let bridge init proceed by stopping the wait function
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000214 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000215 onuDeviceEntry.omciMessageReceived <- true
216 }
217 default:
218 {
219 logger.Warnw(ctx, "Unsupported ME name received!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000220 log.Fields{"ME name": onuDeviceEntry.pLastTxMeInstance.GetName(), "device-id": onuDeviceEntry.deviceID})
221 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000222 }
223 }
224 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000225 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000226 }
227 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000228 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000229 logger.Errorw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": onuDeviceEntry.deviceID})
230 }
231}
232
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000233func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadSetResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000234 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
235 if msgLayer == nil {
236 logger.Errorw(ctx, "Omci Msg layer could not be detected for SetResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
237 return
238 }
239 msgObj, msgOk := msgLayer.(*omci.SetResponse)
240 if !msgOk {
241 logger.Errorw(ctx, "Omci Msg layer could not be assigned for SetResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
242 return
243 }
244 logger.Debugw(ctx, "SetResponse Data", log.Fields{"device-id": onuDeviceEntry.deviceID, "data-fields": msgObj})
245 if msgObj.Result != me.Success {
246 logger.Errorw(ctx, "Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": onuDeviceEntry.deviceID,
247 "Error": msgObj.Result})
248 // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display?
249 return
250 }
251 // compare comments above for CreateResponse (apply also here ...)
252
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000253 onuDeviceEntry.mutexPLastTxMeInstance.RLock()
254 if onuDeviceEntry.pLastTxMeInstance != nil {
255 if msgObj.EntityClass == onuDeviceEntry.pLastTxMeInstance.GetClassID() &&
256 msgObj.EntityInstance == onuDeviceEntry.pLastTxMeInstance.GetEntityID() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000257 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
258 // if, then something like:
259 //onuDeviceEntry.pOnuDB.StoreMe(msgObj)
260
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000261 switch onuDeviceEntry.pLastTxMeInstance.GetName() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000262 case "Onu2G":
263 { // let the FSM proceed ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000264 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
265 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvRxOnu2gResp)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000266 }
267 //so far that was the only MibDownlad Set Element ...
268 default:
269 {
270 logger.Warnw(ctx, "Unsupported ME name received!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000271 log.Fields{"ME name": onuDeviceEntry.pLastTxMeInstance.GetName(), "device-id": onuDeviceEntry.deviceID})
272 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000273 }
274
275 }
276 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000277 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000278 }
279 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000280 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000281 logger.Errorw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": onuDeviceEntry.deviceID})
282 }
283}
284
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000285func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000286 logger.Debugw(ctx, "Rx OMCI MibDownload Msg", log.Fields{"device-id": onuDeviceEntry.deviceID,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000287 "msgType": msg.OmciMsg.MessageType})
288
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000289 switch msg.OmciMsg.MessageType {
290 case omci.CreateResponseType:
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000291 onuDeviceEntry.handleOmciMibDownloadCreateResponseMessage(ctx, msg)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000292 //TODO
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000293 // onuDeviceEntry.PMibDownloadFsm.PFsm.Event("rx_evtocd_resp")
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000294 case omci.SetResponseType:
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000295 onuDeviceEntry.handleOmciMibDownloadSetResponseMessage(ctx, msg)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000296 default:
297 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000298 logger.Errorw(ctx, "Rx OMCI MibDownload unhandled MsgType", log.Fields{"device-id": onuDeviceEntry.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200299 "omciMsgType": msg.OmciMsg.MessageType})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000300 return
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000301 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000302 } // switch msg.OmciMsg.MessageType
303}
304
dbainbri4d3a0dc2020-12-02 00:33:42 +0000305func (onuDeviceEntry *OnuDeviceEntry) performInitialBridgeSetup(ctx context.Context) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000306 for uniNo, uniPort := range *onuDeviceEntry.baseDeviceHandler.GetUniEntityMap() {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000307 logger.Debugw(ctx, "Starting IntialBridgeSetup", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000308 "device-id": onuDeviceEntry.deviceID, "for PortNo": uniNo})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000309
310 //create MBSP
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000311 onuDeviceEntry.mutexPLastTxMeInstance.Lock()
312 meInstance, err := onuDeviceEntry.PDevOmciCC.SendCreateMBServiceProfile(
313 log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.baseDeviceHandler.GetOmciTimeout(), true)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300314 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000315 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300316 logger.Errorw(ctx, "MBServiceProfile create failed, aborting MibDownload FSM!", log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000317 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300318 return
319 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000320 onuDeviceEntry.pLastTxMeInstance = meInstance
321 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000322 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +0300323 err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000324 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000325 logger.Errorw(ctx, "InitialBridgeSetup failed at MBSP, aborting MIB Download!",
Andrea Campanella6515c582020-10-05 11:25:00 +0200326 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000327 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000328 return
329 }
330
331 //create MBPCD
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000332 onuDeviceEntry.mutexPLastTxMeInstance.Lock()
333 meInstance, err = onuDeviceEntry.PDevOmciCC.SendCreateMBPConfigDataUniSide(
334 log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.baseDeviceHandler.GetOmciTimeout(), true)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300335 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000336 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300337 logger.Errorw(ctx, "MBPConfigData create failed, aborting MibDownload FSM!",
338 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000339 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300340 return
341 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000342 onuDeviceEntry.pLastTxMeInstance = meInstance
343 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000344 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +0000345 err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000346 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000347 logger.Errorw(ctx, "InitialBridgeSetup failed at MBPCD, aborting MIB Download!",
Andrea Campanella6515c582020-10-05 11:25:00 +0200348 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000349 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000350 return
351 }
352
353 //create EVTOCD
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000354 onuDeviceEntry.mutexPLastTxMeInstance.Lock()
355 meInstance, err = onuDeviceEntry.PDevOmciCC.SendCreateEVTOConfigData(
356 log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.baseDeviceHandler.GetOmciTimeout(), true)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300357 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000358 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300359 logger.Errorw(ctx, "EVTOConfigData create failed, aborting MibDownload FSM!",
360 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000361 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300362 return
363 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000364 onuDeviceEntry.pLastTxMeInstance = meInstance
365 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000366 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +0000367 err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000368 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000369 logger.Errorw(ctx, "InitialBridgeSetup failed at EVTOCD, aborting MIB Download!",
Andrea Campanella6515c582020-10-05 11:25:00 +0200370 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000371 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000372 return
373 }
374 }
375 // if Config has been done for all UNI related instances let the FSM proceed
376 // while we did not check here, if there is some port at all - !?
dbainbri4d3a0dc2020-12-02 00:33:42 +0000377 logger.Infow(ctx, "IntialBridgeSetup finished", log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000378 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvRxBridgeResp)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000379}
380
dbainbri4d3a0dc2020-12-02 00:33:42 +0000381func (onuDeviceEntry *OnuDeviceEntry) waitforOmciResponse(ctx context.Context, apMeInstance *me.ManagedEntity) error {
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000382 select {
Himani Chawla4d908332020-08-31 12:30:20 +0530383 // maybe be also some outside cancel (but no context modeled for the moment ...)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000384 // case <-ctx.Done():
385 // logger.Info("MibDownload-bridge-init message reception canceled", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000386 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 +0000387 logger.Warnw(ctx, "MibDownload-bridge-init timeout", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200388 return fmt.Errorf("mibDownloadBridgeInit timeout %s", onuDeviceEntry.deviceID)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000389 case success := <-onuDeviceEntry.omciMessageReceived:
Himani Chawla4d908332020-08-31 12:30:20 +0530390 if success {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000391 logger.Debug(ctx, "MibDownload-bridge-init response received")
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000392 return nil
393 }
394 // should not happen so far
dbainbri4d3a0dc2020-12-02 00:33:42 +0000395 logger.Warnw(ctx, "MibDownload-bridge-init response error", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200396 return fmt.Errorf("mibDownloadBridgeInit responseError %s", onuDeviceEntry.deviceID)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000397 }
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000398}