blob: 167cb445995ea63c72b85b251a1a426c38f741d5 [file] [log] [blame]
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +00001/*
Joey Armstrong7f9c4df2022-12-26 19:39:59 -05002 * Copyright 2020-2023 Open Networking Foundation (ONF) and the ONF Contributors
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +00003 *
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})
Holger Hildebrandt7e138462023-03-29 12:12:14 +0000185 // possibly force FSM into abort or ignore some errors for some messages?
186 onuDeviceEntry.PDevOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
187 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000188 return
189 }
190 // maybe there is a way of pushing the specific create response type generally to the FSM
191 // and let the FSM verify, if the response was according to current state
192 // and possibly store the element to DB and progress - maybe some future option ...
193 // but as that is not straightforward to me I insert the type checkes manually here
194 // and feed the FSM with only 'pre-defined' events ...
195
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000196 onuDeviceEntry.mutexPLastTxMeInstance.RLock()
197 if onuDeviceEntry.pLastTxMeInstance != nil {
198 if msgObj.EntityClass == onuDeviceEntry.pLastTxMeInstance.GetClassID() &&
199 msgObj.EntityInstance == onuDeviceEntry.pLastTxMeInstance.GetEntityID() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000200 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
201 // if, then something like:
202 //onuDeviceEntry.pOnuDB.StoreMe(msgObj)
203
204 // maybe we can use just the same eventName for different state transitions like "forward"
205 // - 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 +0000206 switch onuDeviceEntry.pLastTxMeInstance.GetName() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000207 case "GalEthernetProfile":
208 { // let the FSM proceed ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000209 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
210 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvRxGalResp)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000211 }
212 case "MacBridgeServiceProfile",
213 "MacBridgePortConfigurationData",
214 "ExtendedVlanTaggingOperationConfigurationData":
215 { // let bridge init proceed by stopping the wait function
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000216 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000217 onuDeviceEntry.omciMessageReceived <- true
218 }
219 default:
220 {
221 logger.Warnw(ctx, "Unsupported ME name received!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000222 log.Fields{"ME name": onuDeviceEntry.pLastTxMeInstance.GetName(), "device-id": onuDeviceEntry.deviceID})
223 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000224 }
225 }
226 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000227 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000228 }
229 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000230 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000231 logger.Errorw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": onuDeviceEntry.deviceID})
232 }
233}
234
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000235func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadSetResponseMessage(ctx context.Context, msg cmn.OmciMessage) {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000236 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse)
237 if msgLayer == nil {
238 logger.Errorw(ctx, "Omci Msg layer could not be detected for SetResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
239 return
240 }
241 msgObj, msgOk := msgLayer.(*omci.SetResponse)
242 if !msgOk {
243 logger.Errorw(ctx, "Omci Msg layer could not be assigned for SetResponse", log.Fields{"device-id": onuDeviceEntry.deviceID})
244 return
245 }
246 logger.Debugw(ctx, "SetResponse Data", log.Fields{"device-id": onuDeviceEntry.deviceID, "data-fields": msgObj})
247 if msgObj.Result != me.Success {
248 logger.Errorw(ctx, "Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": onuDeviceEntry.deviceID,
249 "Error": msgObj.Result})
Holger Hildebrandt7e138462023-03-29 12:12:14 +0000250 // possibly force FSM into abort or ignore some errors for some messages?
251 onuDeviceEntry.PDevOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass,
252 msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000253 return
254 }
255 // compare comments above for CreateResponse (apply also here ...)
256
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000257 onuDeviceEntry.mutexPLastTxMeInstance.RLock()
258 if onuDeviceEntry.pLastTxMeInstance != nil {
259 if msgObj.EntityClass == onuDeviceEntry.pLastTxMeInstance.GetClassID() &&
260 msgObj.EntityInstance == onuDeviceEntry.pLastTxMeInstance.GetEntityID() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000261 //store the created ME into DB //TODO??? obviously the Python code does not store the config ...
262 // if, then something like:
263 //onuDeviceEntry.pOnuDB.StoreMe(msgObj)
264
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000265 switch onuDeviceEntry.pLastTxMeInstance.GetName() {
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000266 case "Onu2G":
267 { // let the FSM proceed ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000268 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
269 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvRxOnu2gResp)
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000270 }
271 //so far that was the only MibDownlad Set Element ...
272 default:
273 {
274 logger.Warnw(ctx, "Unsupported ME name received!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000275 log.Fields{"ME name": onuDeviceEntry.pLastTxMeInstance.GetName(), "device-id": onuDeviceEntry.deviceID})
276 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000277 }
278
279 }
280 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000281 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000282 }
283 } else {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000284 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000285 logger.Errorw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": onuDeviceEntry.deviceID})
286 }
287}
288
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000289func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadMessage(ctx context.Context, msg cmn.OmciMessage) {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000290 logger.Debugw(ctx, "Rx OMCI MibDownload Msg", log.Fields{"device-id": onuDeviceEntry.deviceID,
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000291 "msgType": msg.OmciMsg.MessageType})
292
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000293 switch msg.OmciMsg.MessageType {
294 case omci.CreateResponseType:
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000295 onuDeviceEntry.handleOmciMibDownloadCreateResponseMessage(ctx, msg)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000296 //TODO
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000297 // onuDeviceEntry.PMibDownloadFsm.PFsm.Event("rx_evtocd_resp")
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000298 case omci.SetResponseType:
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000299 onuDeviceEntry.handleOmciMibDownloadSetResponseMessage(ctx, msg)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000300 default:
301 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000302 logger.Errorw(ctx, "Rx OMCI MibDownload unhandled MsgType", log.Fields{"device-id": onuDeviceEntry.deviceID,
Andrea Campanella6515c582020-10-05 11:25:00 +0200303 "omciMsgType": msg.OmciMsg.MessageType})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000304 return
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000305 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000306 } // switch msg.OmciMsg.MessageType
307}
308
dbainbri4d3a0dc2020-12-02 00:33:42 +0000309func (onuDeviceEntry *OnuDeviceEntry) performInitialBridgeSetup(ctx context.Context) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000310 for uniNo, uniPort := range *onuDeviceEntry.baseDeviceHandler.GetUniEntityMap() {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000311 logger.Debugw(ctx, "Starting IntialBridgeSetup", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000312 "device-id": onuDeviceEntry.deviceID, "for PortNo": uniNo})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000313
314 //create MBSP
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000315 onuDeviceEntry.mutexPLastTxMeInstance.Lock()
316 meInstance, err := onuDeviceEntry.PDevOmciCC.SendCreateMBServiceProfile(
317 log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.baseDeviceHandler.GetOmciTimeout(), true)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300318 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000319 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300320 logger.Errorw(ctx, "MBServiceProfile create failed, aborting MibDownload FSM!", log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000321 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300322 return
323 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000324 onuDeviceEntry.pLastTxMeInstance = meInstance
325 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000326 //verify response
ozgecanetsiab36ed572021-04-01 10:38:48 +0300327 err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000328 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000329 logger.Errorw(ctx, "InitialBridgeSetup failed at MBSP, aborting MIB Download!",
Andrea Campanella6515c582020-10-05 11:25:00 +0200330 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000331 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000332 return
333 }
334
335 //create MBPCD
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000336 onuDeviceEntry.mutexPLastTxMeInstance.Lock()
337 meInstance, err = onuDeviceEntry.PDevOmciCC.SendCreateMBPConfigDataUniSide(
338 log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.baseDeviceHandler.GetOmciTimeout(), true)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300339 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000340 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300341 logger.Errorw(ctx, "MBPConfigData create failed, aborting MibDownload FSM!",
342 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000343 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300344 return
345 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000346 onuDeviceEntry.pLastTxMeInstance = meInstance
347 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000348 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +0000349 err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000350 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000351 logger.Errorw(ctx, "InitialBridgeSetup failed at MBPCD, aborting MIB Download!",
Andrea Campanella6515c582020-10-05 11:25:00 +0200352 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000353 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000354 return
355 }
356
357 //create EVTOCD
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000358 onuDeviceEntry.mutexPLastTxMeInstance.Lock()
359 meInstance, err = onuDeviceEntry.PDevOmciCC.SendCreateEVTOConfigData(
360 log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.baseDeviceHandler.GetOmciTimeout(), true)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300361 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000362 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
ozgecanetsiab36ed572021-04-01 10:38:48 +0300363 logger.Errorw(ctx, "EVTOConfigData create failed, aborting MibDownload FSM!",
364 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000365 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
ozgecanetsiab36ed572021-04-01 10:38:48 +0300366 return
367 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000368 onuDeviceEntry.pLastTxMeInstance = meInstance
369 onuDeviceEntry.mutexPLastTxMeInstance.Unlock()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000370 //verify response
dbainbri4d3a0dc2020-12-02 00:33:42 +0000371 err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000372 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000373 logger.Errorw(ctx, "InitialBridgeSetup failed at EVTOCD, aborting MIB Download!",
Andrea Campanella6515c582020-10-05 11:25:00 +0200374 log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000375 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvReset)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000376 return
377 }
378 }
379 // if Config has been done for all UNI related instances let the FSM proceed
380 // while we did not check here, if there is some port at all - !?
dbainbri4d3a0dc2020-12-02 00:33:42 +0000381 logger.Infow(ctx, "IntialBridgeSetup finished", log.Fields{"device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000382 _ = onuDeviceEntry.PMibDownloadFsm.PFsm.Event(DlEvRxBridgeResp)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000383}
384
dbainbri4d3a0dc2020-12-02 00:33:42 +0000385func (onuDeviceEntry *OnuDeviceEntry) waitforOmciResponse(ctx context.Context, apMeInstance *me.ManagedEntity) error {
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000386 select {
Himani Chawla4d908332020-08-31 12:30:20 +0530387 // maybe be also some outside cancel (but no context modeled for the moment ...)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000388 // case <-ctx.Done():
389 // logger.Info("MibDownload-bridge-init message reception canceled", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000390 case <-time.After(onuDeviceEntry.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug
Holger Hildebrandt7e138462023-03-29 12:12:14 +0000391 onuDeviceEntry.mutexPLastTxMeInstance.RLock()
392 if onuDeviceEntry.pLastTxMeInstance != nil {
393 onuDeviceEntry.PDevOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureTimeout,
394 onuDeviceEntry.pLastTxMeInstance.GetClassID(), onuDeviceEntry.pLastTxMeInstance.GetEntityID(),
395 onuDeviceEntry.pLastTxMeInstance.GetClassID().String(), 0)
396 }
397 onuDeviceEntry.mutexPLastTxMeInstance.RUnlock()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000398 logger.Warnw(ctx, "MibDownload-bridge-init timeout", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200399 return fmt.Errorf("mibDownloadBridgeInit timeout %s", onuDeviceEntry.deviceID)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000400 case success := <-onuDeviceEntry.omciMessageReceived:
Himani Chawla4d908332020-08-31 12:30:20 +0530401 if success {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000402 logger.Debug(ctx, "MibDownload-bridge-init response received")
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000403 return nil
404 }
405 // should not happen so far
dbainbri4d3a0dc2020-12-02 00:33:42 +0000406 logger.Warnw(ctx, "MibDownload-bridge-init response error", log.Fields{"for device-id": onuDeviceEntry.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200407 return fmt.Errorf("mibDownloadBridgeInit responseError %s", onuDeviceEntry.deviceID)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000408 }
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +0000409}