Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 1 | /* |
| 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 |
| 18 | package adaptercoreonu |
| 19 | |
| 20 | import ( |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 21 | "context" |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 22 | "fmt" |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 23 | "time" |
| 24 | |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 25 | "github.com/looplab/fsm" |
| 26 | |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 27 | "github.com/opencord/omci-lib-go" |
| 28 | me "github.com/opencord/omci-lib-go/generated" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 29 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
| 30 | //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 Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 33 | ) |
| 34 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 35 | func (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 Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 37 | // 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) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 40 | logger.Debug(ctx, "MibDownload FSM - defining the BridgeInit RxChannel") |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 41 | } |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 42 | // start go routine for processing of MibDownload messages |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 43 | go onuDeviceEntry.processMibDownloadMessages(ctx) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 44 | } |
| 45 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 46 | func (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}) |
| 48 | meInstance := onuDeviceEntry.PDevOmciCC.sendCreateGalEthernetProfile(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 49 | //accept also nil as (error) return value for writing to LastTx |
| 50 | // - this avoids misinterpretation of new received OMCI messages |
| 51 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
| 52 | } |
| 53 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 54 | func (onuDeviceEntry *OnuDeviceEntry) enterSettingOnu2gState(ctx context.Context, e *fsm.Event) { |
| 55 | logger.Debugw(ctx, "MibDownload FSM", log.Fields{"Tx Set::ONU2-G in state": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 56 | meInstance := onuDeviceEntry.PDevOmciCC.sendSetOnu2g(log.WithSpanFromContext(context.TODO(), ctx), ConstDefaultOmciTimeout, true) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 57 | //accept also nil as (error) return value for writing to LastTx |
| 58 | // - this avoids misinterpretation of new received OMCI messages |
| 59 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
| 60 | } |
| 61 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 62 | func (onuDeviceEntry *OnuDeviceEntry) enterBridgeInitState(ctx context.Context, e *fsm.Event) { |
| 63 | logger.Debugw(ctx, "MibDownload FSM - starting bridge config port loop", log.Fields{ |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 64 | "in state": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 65 | go onuDeviceEntry.performInitialBridgeSetup(ctx) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 66 | } |
| 67 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 68 | func (onuDeviceEntry *OnuDeviceEntry) enterDownloadedState(ctx context.Context, e *fsm.Event) { |
| 69 | logger.Debugw(ctx, "MibDownload FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 70 | onuDeviceEntry.transferSystemEvent(ctx, MibDownloadDone) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 71 | //let's reset the state machine in order to release all resources now |
| 72 | pMibDlFsm := onuDeviceEntry.pMibDownloadFsm |
| 73 | if pMibDlFsm != nil { |
| 74 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 75 | go func(a_pAFsm *AdapterFsm) { |
| 76 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 77 | _ = a_pAFsm.pFsm.Event(dlEvReset) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 78 | } |
| 79 | }(pMibDlFsm) |
| 80 | } |
| 81 | } |
| 82 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 83 | func (onuDeviceEntry *OnuDeviceEntry) enterResettingState(ctx context.Context, e *fsm.Event) { |
| 84 | logger.Debugw(ctx, "MibDownload FSM resetting", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 85 | pMibDlFsm := onuDeviceEntry.pMibDownloadFsm |
| 86 | if pMibDlFsm != nil { |
| 87 | // abort running message processing |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 88 | fsmAbortMsg := Message{ |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 89 | Type: TestMsg, |
| 90 | Data: TestMessage{ |
| 91 | TestMessageVal: AbortMessageProcessing, |
| 92 | }, |
| 93 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 94 | pMibDlFsm.commChan <- fsmAbortMsg |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 95 | |
| 96 | //try to restart the FSM to 'disabled' |
| 97 | // see DownloadedState: decouple event transfer |
| 98 | go func(a_pAFsm *AdapterFsm) { |
| 99 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 100 | _ = a_pAFsm.pFsm.Event(dlEvRestart) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 101 | } |
| 102 | }(pMibDlFsm) |
| 103 | } |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 104 | } |
| 105 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 106 | func (onuDeviceEntry *OnuDeviceEntry) processMibDownloadMessages(ctx context.Context) { |
| 107 | logger.Debugw(ctx, "Start MibDownload Msg processing", log.Fields{"for device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 108 | loop: |
| 109 | for { |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 110 | // case <-ctx.Done(): |
| 111 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID}) |
| 112 | // break loop |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 113 | // unless multiple channels are not involved, we should not use select |
| 114 | message, ok := <-onuDeviceEntry.pMibDownloadFsm.commChan |
| 115 | if !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 116 | logger.Info(ctx, "MibDownload Rx Msg", log.Fields{"Message couldn't be read from channel for device-id": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 117 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
| 118 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvRestart) |
| 119 | break loop |
| 120 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 121 | logger.Debugw(ctx, "MibDownload Rx Msg", log.Fields{"Received message for device-id": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 122 | |
| 123 | switch message.Type { |
| 124 | case TestMsg: |
| 125 | msg, _ := message.Data.(TestMessage) |
| 126 | if msg.TestMessageVal == AbortMessageProcessing { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 127 | logger.Debugw(ctx, "MibDownload abort ProcessMsg", log.Fields{"for device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 128 | break loop |
| 129 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 130 | logger.Warnw(ctx, "MibDownload unknown TestMessage", log.Fields{"device-id": onuDeviceEntry.deviceID, "MessageVal": msg.TestMessageVal}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 131 | case OMCI: |
| 132 | msg, _ := message.Data.(OmciMessage) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 133 | onuDeviceEntry.handleOmciMibDownloadMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 134 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 135 | logger.Warn(ctx, "MibDownload Rx Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 136 | "message.Type": message.Type}) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 137 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 138 | |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 139 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 140 | logger.Debugw(ctx, "End MibDownload Msg processing", log.Fields{"for device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 141 | } |
| 142 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 143 | func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadMessage(ctx context.Context, msg OmciMessage) { |
| 144 | logger.Debugw(ctx, "Rx OMCI MibDownload Msg", log.Fields{"device-id": onuDeviceEntry.deviceID, |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 145 | "msgType": msg.OmciMsg.MessageType}) |
| 146 | |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 147 | switch msg.OmciMsg.MessageType { |
| 148 | case omci.CreateResponseType: |
| 149 | { |
| 150 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 151 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 152 | logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 153 | return |
| 154 | } |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 155 | msgObj, msgOk := msgLayer.(*omci.CreateResponse) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 156 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 157 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 158 | return |
| 159 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 160 | logger.Debugw(ctx, "CreateResponse Data", log.Fields{"device-id": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 161 | if msgObj.Result != me.Success && msgObj.Result != me.InstanceExists { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 162 | logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": onuDeviceEntry.deviceID, "Error": msgObj.Result}) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 163 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 164 | return |
| 165 | } |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 166 | // maybe there is a way of pushing the specific create response type generally to the FSM |
| 167 | // and let the FSM verify, if the response was according to current state |
| 168 | // and possibly store the element to DB and progress - maybe some future option ... |
| 169 | // but as that is not straightforward to me I insert the type checkes manually here |
| 170 | // and feed the FSM with only 'pre-defined' events ... |
| 171 | if msgObj.EntityClass == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetClassID() && |
| 172 | msgObj.EntityInstance == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetEntityID() { |
| 173 | //store the created ME into DB //TODO??? obviously the Python code does not store the config ... |
| 174 | // if, then something like: |
| 175 | //onuDeviceEntry.pOnuDB.StoreMe(msgObj) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 176 | |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 177 | // maybe we can use just the same eventName for different state transitions like "forward" |
| 178 | // - might be checked, but so far I go for sure and have to inspect the concrete state events ... |
| 179 | switch onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetName() { |
| 180 | case "GalEthernetProfile": |
| 181 | { // let the FSM proceed ... |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 182 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvRxGalResp) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 183 | } |
| 184 | case "MacBridgeServiceProfile", |
| 185 | "MacBridgePortConfigurationData", |
| 186 | "ExtendedVlanTaggingOperationConfigurationData": |
| 187 | { // let bridge init proceed by stopping the wait function |
| 188 | onuDeviceEntry.omciMessageReceived <- true |
| 189 | } |
| 190 | } |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 191 | } |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 192 | } //CreateResponseType |
| 193 | //TODO |
| 194 | // onuDeviceEntry.pMibDownloadFsm.pFsm.Event("rx_evtocd_resp") |
| 195 | |
| 196 | case omci.SetResponseType: |
| 197 | { |
| 198 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 199 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 200 | logger.Errorw(ctx, "Omci Msg layer could not be detected for SetResponse", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 201 | return |
| 202 | } |
| 203 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 204 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 205 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for SetResponse", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 206 | return |
| 207 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 208 | logger.Debugw(ctx, "SetResponse Data", log.Fields{"device-id": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 209 | if msgObj.Result != me.Success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 210 | logger.Errorw(ctx, "Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": onuDeviceEntry.deviceID, |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 211 | "Error": msgObj.Result}) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 212 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 213 | return |
| 214 | } |
| 215 | // compare comments above for CreateResponse (apply also here ...) |
| 216 | if msgObj.EntityClass == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetClassID() && |
| 217 | msgObj.EntityInstance == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetEntityID() { |
| 218 | //store the created ME into DB //TODO??? obviously the Python code does not store the config ... |
| 219 | // if, then something like: |
| 220 | //onuDeviceEntry.pOnuDB.StoreMe(msgObj) |
| 221 | |
| 222 | switch onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetName() { |
| 223 | case "Onu2G": |
| 224 | { // let the FSM proceed ... |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 225 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvRxOnu2gResp) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 226 | } |
| 227 | //so far that was the only MibDownlad Set Element ... |
| 228 | } |
| 229 | } |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 230 | } //SetResponseType |
| 231 | default: |
| 232 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 233 | logger.Errorw(ctx, "Rx OMCI MibDownload unhandled MsgType", log.Fields{"device-id": onuDeviceEntry.deviceID, |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 234 | "omciMsgType": msg.OmciMsg.MessageType}) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 235 | return |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 236 | } |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 237 | } // switch msg.OmciMsg.MessageType |
| 238 | } |
| 239 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 240 | func (onuDeviceEntry *OnuDeviceEntry) performInitialBridgeSetup(ctx context.Context) { |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 241 | for uniNo, uniPort := range onuDeviceEntry.baseDeviceHandler.uniEntityMap { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 242 | logger.Debugw(ctx, "Starting IntialBridgeSetup", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 243 | "device-id": onuDeviceEntry.deviceID, "for PortNo": uniNo}) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 244 | |
| 245 | //create MBSP |
| 246 | meInstance := onuDeviceEntry.PDevOmciCC.sendCreateMBServiceProfile( |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 247 | log.WithSpanFromContext(context.TODO(), ctx), uniPort, ConstDefaultOmciTimeout, true) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 248 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
| 249 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 250 | err := onuDeviceEntry.waitforOmciResponse(ctx, meInstance) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 251 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 252 | logger.Errorw(ctx, "InitialBridgeSetup failed at MBSP, aborting MIB Download!", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 253 | log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 254 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 255 | return |
| 256 | } |
| 257 | |
| 258 | //create MBPCD |
| 259 | meInstance = onuDeviceEntry.PDevOmciCC.sendCreateMBPConfigData( |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 260 | log.WithSpanFromContext(context.TODO(), ctx), uniPort, ConstDefaultOmciTimeout, true) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 261 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
| 262 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 263 | err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 264 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 265 | logger.Errorw(ctx, "InitialBridgeSetup failed at MBPCD, aborting MIB Download!", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 266 | log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 267 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 268 | return |
| 269 | } |
| 270 | |
| 271 | //create EVTOCD |
| 272 | meInstance = onuDeviceEntry.PDevOmciCC.sendCreateEVTOConfigData( |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 273 | log.WithSpanFromContext(context.TODO(), ctx), uniPort, ConstDefaultOmciTimeout, true) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 274 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
| 275 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 276 | err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 277 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 278 | logger.Errorw(ctx, "InitialBridgeSetup failed at EVTOCD, aborting MIB Download!", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 279 | log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 280 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 281 | return |
| 282 | } |
| 283 | } |
| 284 | // if Config has been done for all UNI related instances let the FSM proceed |
| 285 | // while we did not check here, if there is some port at all - !? |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 286 | logger.Infow(ctx, "IntialBridgeSetup finished", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 287 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvRxBridgeResp) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 288 | } |
| 289 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 290 | func (onuDeviceEntry *OnuDeviceEntry) waitforOmciResponse(ctx context.Context, apMeInstance *me.ManagedEntity) error { |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 291 | select { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 292 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 293 | // case <-ctx.Done(): |
| 294 | // logger.Info("MibDownload-bridge-init message reception canceled", log.Fields{"for device-id": onuDeviceEntry.deviceID}) |
mpagenko | 3af1f03 | 2020-06-10 08:53:41 +0000 | [diff] [blame] | 295 | case <-time.After(30 * time.Second): //3s was detected to be to less in 8*8 bbsim test with debug Info/Debug |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 296 | logger.Warnw(ctx, "MibDownload-bridge-init timeout", log.Fields{"for device-id": onuDeviceEntry.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 297 | return fmt.Errorf("mibDownloadBridgeInit timeout %s", onuDeviceEntry.deviceID) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 298 | case success := <-onuDeviceEntry.omciMessageReceived: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 299 | if success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 300 | logger.Debug(ctx, "MibDownload-bridge-init response received") |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 301 | return nil |
| 302 | } |
| 303 | // should not happen so far |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 304 | logger.Warnw(ctx, "MibDownload-bridge-init response error", log.Fields{"for device-id": onuDeviceEntry.deviceID}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 305 | return fmt.Errorf("mibDownloadBridgeInit responseError %s", onuDeviceEntry.deviceID) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 306 | } |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 307 | } |