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}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 48 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 49 | meInstance, err := onuDeviceEntry.PDevOmciCC.sendCreateGalEthernetProfile(log.WithSpanFromContext(context.TODO(), ctx), onuDeviceEntry.pOpenOnuAc.omciTimeout, true) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 50 | //accept also nil as (error) return value for writing to LastTx |
| 51 | // - this avoids misinterpretation of new received OMCI messages |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 52 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 53 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 54 | logger.Errorw(ctx, "GalEthernetProfile create failed, aborting MibDownload FSM!", |
| 55 | log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 56 | pMibDlFsm := onuDeviceEntry.pMibDownloadFsm |
| 57 | if pMibDlFsm != nil { |
| 58 | go func(a_pAFsm *AdapterFsm) { |
| 59 | _ = a_pAFsm.pFsm.Event(dlEvReset) |
| 60 | }(pMibDlFsm) |
| 61 | } |
| 62 | return |
| 63 | } |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 64 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 65 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 66 | } |
| 67 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 68 | func (onuDeviceEntry *OnuDeviceEntry) enterSettingOnu2gState(ctx context.Context, e *fsm.Event) { |
| 69 | logger.Debugw(ctx, "MibDownload FSM", log.Fields{"Tx Set::ONU2-G in state": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 70 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 71 | meInstance, err := onuDeviceEntry.PDevOmciCC.sendSetOnu2g(log.WithSpanFromContext(context.TODO(), ctx), |
| 72 | onuDeviceEntry.pOpenOnuAc.omciTimeout, true) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 73 | //accept also nil as (error) return value for writing to LastTx |
| 74 | // - this avoids misinterpretation of new received OMCI messages |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 75 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 76 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 77 | logger.Errorw(ctx, "ONU2-G set failed, aborting MibDownload FSM!", |
| 78 | log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 79 | pMibDlFsm := onuDeviceEntry.pMibDownloadFsm |
| 80 | if pMibDlFsm != nil { |
| 81 | go func(a_pAFsm *AdapterFsm) { |
| 82 | _ = a_pAFsm.pFsm.Event(dlEvReset) |
| 83 | }(pMibDlFsm) |
| 84 | } |
| 85 | return |
| 86 | } |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 87 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 88 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 89 | } |
| 90 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 91 | func (onuDeviceEntry *OnuDeviceEntry) enterBridgeInitState(ctx context.Context, e *fsm.Event) { |
| 92 | logger.Debugw(ctx, "MibDownload FSM - starting bridge config port loop", log.Fields{ |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 93 | "in state": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 94 | go onuDeviceEntry.performInitialBridgeSetup(ctx) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 95 | } |
| 96 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 97 | func (onuDeviceEntry *OnuDeviceEntry) enterDownloadedState(ctx context.Context, e *fsm.Event) { |
| 98 | logger.Debugw(ctx, "MibDownload FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID}) |
| 99 | onuDeviceEntry.transferSystemEvent(ctx, MibDownloadDone) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 100 | //let's reset the state machine in order to release all resources now |
| 101 | pMibDlFsm := onuDeviceEntry.pMibDownloadFsm |
| 102 | if pMibDlFsm != nil { |
| 103 | // obviously calling some FSM event here directly does not work - so trying to decouple it ... |
| 104 | go func(a_pAFsm *AdapterFsm) { |
| 105 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 106 | _ = a_pAFsm.pFsm.Event(dlEvReset) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 107 | } |
| 108 | }(pMibDlFsm) |
| 109 | } |
| 110 | } |
| 111 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 112 | func (onuDeviceEntry *OnuDeviceEntry) enterResettingState(ctx context.Context, e *fsm.Event) { |
| 113 | logger.Debugw(ctx, "MibDownload FSM resetting", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 114 | pMibDlFsm := onuDeviceEntry.pMibDownloadFsm |
| 115 | if pMibDlFsm != nil { |
| 116 | // abort running message processing |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 117 | fsmAbortMsg := Message{ |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 118 | Type: TestMsg, |
| 119 | Data: TestMessage{ |
| 120 | TestMessageVal: AbortMessageProcessing, |
| 121 | }, |
| 122 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 123 | pMibDlFsm.commChan <- fsmAbortMsg |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 124 | |
| 125 | //try to restart the FSM to 'disabled' |
| 126 | // see DownloadedState: decouple event transfer |
| 127 | go func(a_pAFsm *AdapterFsm) { |
| 128 | if a_pAFsm != nil && a_pAFsm.pFsm != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 129 | _ = a_pAFsm.pFsm.Event(dlEvRestart) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 130 | } |
| 131 | }(pMibDlFsm) |
| 132 | } |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 133 | } |
| 134 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 135 | func (onuDeviceEntry *OnuDeviceEntry) processMibDownloadMessages(ctx context.Context) { |
| 136 | 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] | 137 | loop: |
| 138 | for { |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 139 | // case <-ctx.Done(): |
| 140 | // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID}) |
| 141 | // break loop |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 142 | // unless multiple channels are not involved, we should not use select |
| 143 | message, ok := <-onuDeviceEntry.pMibDownloadFsm.commChan |
| 144 | if !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 145 | 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] | 146 | // but then we have to ensure a restart of the FSM as well - as exceptional procedure |
| 147 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvRestart) |
| 148 | break loop |
| 149 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 150 | 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] | 151 | |
| 152 | switch message.Type { |
| 153 | case TestMsg: |
| 154 | msg, _ := message.Data.(TestMessage) |
| 155 | if msg.TestMessageVal == AbortMessageProcessing { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 156 | 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] | 157 | break loop |
| 158 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 159 | 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] | 160 | case OMCI: |
| 161 | msg, _ := message.Data.(OmciMessage) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 162 | onuDeviceEntry.handleOmciMibDownloadMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 163 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 164 | 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] | 165 | "message.Type": message.Type}) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 166 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 167 | |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 168 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 169 | 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] | 170 | } |
| 171 | |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 172 | func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadCreateResponseMessage(ctx context.Context, msg OmciMessage) { |
| 173 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse) |
| 174 | if msgLayer == nil { |
| 175 | logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 176 | return |
| 177 | } |
| 178 | msgObj, msgOk := msgLayer.(*omci.CreateResponse) |
| 179 | if !msgOk { |
| 180 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 181 | return |
| 182 | } |
| 183 | logger.Debugw(ctx, "CreateResponse Data", log.Fields{"device-id": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
| 184 | if msgObj.Result != me.Success && msgObj.Result != me.InstanceExists { |
| 185 | logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": onuDeviceEntry.deviceID, "Error": msgObj.Result}) |
| 186 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 187 | return |
| 188 | } |
| 189 | // maybe there is a way of pushing the specific create response type generally to the FSM |
| 190 | // and let the FSM verify, if the response was according to current state |
| 191 | // and possibly store the element to DB and progress - maybe some future option ... |
| 192 | // but as that is not straightforward to me I insert the type checkes manually here |
| 193 | // and feed the FSM with only 'pre-defined' events ... |
| 194 | |
| 195 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RLock() |
| 196 | if onuDeviceEntry.PDevOmciCC.pLastTxMeInstance != nil { |
| 197 | if msgObj.EntityClass == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetClassID() && |
| 198 | msgObj.EntityInstance == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetEntityID() { |
| 199 | //store the created ME into DB //TODO??? obviously the Python code does not store the config ... |
| 200 | // if, then something like: |
| 201 | //onuDeviceEntry.pOnuDB.StoreMe(msgObj) |
| 202 | |
| 203 | // maybe we can use just the same eventName for different state transitions like "forward" |
| 204 | // - might be checked, but so far I go for sure and have to inspect the concrete state events ... |
| 205 | switch onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetName() { |
| 206 | case "GalEthernetProfile": |
| 207 | { // let the FSM proceed ... |
| 208 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock() |
| 209 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvRxGalResp) |
| 210 | } |
| 211 | case "MacBridgeServiceProfile", |
| 212 | "MacBridgePortConfigurationData", |
| 213 | "ExtendedVlanTaggingOperationConfigurationData": |
| 214 | { // let bridge init proceed by stopping the wait function |
| 215 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock() |
| 216 | onuDeviceEntry.omciMessageReceived <- true |
| 217 | } |
| 218 | default: |
| 219 | { |
| 220 | logger.Warnw(ctx, "Unsupported ME name received!", |
| 221 | log.Fields{"ME name": onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetName(), "device-id": onuDeviceEntry.deviceID}) |
| 222 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock() |
| 223 | } |
| 224 | } |
| 225 | } else { |
| 226 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock() |
| 227 | } |
| 228 | } else { |
| 229 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock() |
| 230 | logger.Errorw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadSetResponseMessage(ctx context.Context, msg OmciMessage) { |
| 235 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 236 | if msgLayer == nil { |
| 237 | logger.Errorw(ctx, "Omci Msg layer could not be detected for SetResponse", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 238 | return |
| 239 | } |
| 240 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 241 | if !msgOk { |
| 242 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for SetResponse", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 243 | return |
| 244 | } |
| 245 | logger.Debugw(ctx, "SetResponse Data", log.Fields{"device-id": onuDeviceEntry.deviceID, "data-fields": msgObj}) |
| 246 | if msgObj.Result != me.Success { |
| 247 | logger.Errorw(ctx, "Omci SetResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": onuDeviceEntry.deviceID, |
| 248 | "Error": msgObj.Result}) |
| 249 | // possibly force FSM into abort or ignore some errors for some messages? store error for mgmt display? |
| 250 | return |
| 251 | } |
| 252 | // compare comments above for CreateResponse (apply also here ...) |
| 253 | |
| 254 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RLock() |
| 255 | if onuDeviceEntry.PDevOmciCC.pLastTxMeInstance != nil { |
| 256 | if msgObj.EntityClass == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetClassID() && |
| 257 | msgObj.EntityInstance == onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetEntityID() { |
| 258 | //store the created ME into DB //TODO??? obviously the Python code does not store the config ... |
| 259 | // if, then something like: |
| 260 | //onuDeviceEntry.pOnuDB.StoreMe(msgObj) |
| 261 | |
| 262 | switch onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetName() { |
| 263 | case "Onu2G": |
| 264 | { // let the FSM proceed ... |
| 265 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock() |
| 266 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvRxOnu2gResp) |
| 267 | } |
| 268 | //so far that was the only MibDownlad Set Element ... |
| 269 | default: |
| 270 | { |
| 271 | logger.Warnw(ctx, "Unsupported ME name received!", |
| 272 | log.Fields{"ME name": onuDeviceEntry.PDevOmciCC.pLastTxMeInstance.GetName(), "device-id": onuDeviceEntry.deviceID}) |
| 273 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock() |
| 274 | } |
| 275 | |
| 276 | } |
| 277 | } else { |
| 278 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock() |
| 279 | } |
| 280 | } else { |
| 281 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.RUnlock() |
| 282 | logger.Errorw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 283 | } |
| 284 | } |
| 285 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 286 | func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadMessage(ctx context.Context, msg OmciMessage) { |
| 287 | 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] | 288 | "msgType": msg.OmciMsg.MessageType}) |
| 289 | |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 290 | switch msg.OmciMsg.MessageType { |
| 291 | case omci.CreateResponseType: |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 292 | onuDeviceEntry.handleOmciMibDownloadCreateResponseMessage(ctx, msg) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 293 | //TODO |
| 294 | // onuDeviceEntry.pMibDownloadFsm.pFsm.Event("rx_evtocd_resp") |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 295 | case omci.SetResponseType: |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 296 | onuDeviceEntry.handleOmciMibDownloadSetResponseMessage(ctx, msg) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 297 | default: |
| 298 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 299 | 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] | 300 | "omciMsgType": msg.OmciMsg.MessageType}) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 301 | return |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 302 | } |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 303 | } // switch msg.OmciMsg.MessageType |
| 304 | } |
| 305 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 306 | func (onuDeviceEntry *OnuDeviceEntry) performInitialBridgeSetup(ctx context.Context) { |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 307 | for uniNo, uniPort := range onuDeviceEntry.baseDeviceHandler.uniEntityMap { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 308 | logger.Debugw(ctx, "Starting IntialBridgeSetup", log.Fields{ |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 309 | "device-id": onuDeviceEntry.deviceID, "for PortNo": uniNo}) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 310 | |
| 311 | //create MBSP |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 312 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 313 | meInstance, err := onuDeviceEntry.PDevOmciCC.sendCreateMBServiceProfile( |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 314 | log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.pOpenOnuAc.omciTimeout, true) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 315 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 316 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 317 | logger.Errorw(ctx, "MBServiceProfile create failed, aborting MibDownload FSM!", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 318 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset) |
| 319 | return |
| 320 | } |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 321 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 322 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 323 | //verify response |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 324 | err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 325 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 326 | logger.Errorw(ctx, "InitialBridgeSetup failed at MBSP, aborting MIB Download!", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 327 | log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 328 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 329 | return |
| 330 | } |
| 331 | |
| 332 | //create MBPCD |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 333 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Lock() |
Mahir Gunyel | 6781f96 | 2021-05-16 23:30:08 -0700 | [diff] [blame] | 334 | meInstance, err = onuDeviceEntry.PDevOmciCC.sendCreateMBPConfigDataUniSide( |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 335 | log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.pOpenOnuAc.omciTimeout, true) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 336 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 337 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 338 | logger.Errorw(ctx, "MBPConfigData create failed, aborting MibDownload FSM!", |
| 339 | log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 340 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset) |
| 341 | return |
| 342 | } |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 343 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 344 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 345 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 346 | err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 347 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 348 | logger.Errorw(ctx, "InitialBridgeSetup failed at MBPCD, aborting MIB Download!", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 349 | log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 350 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 351 | return |
| 352 | } |
| 353 | |
| 354 | //create EVTOCD |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 355 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Lock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 356 | meInstance, err = onuDeviceEntry.PDevOmciCC.sendCreateEVTOConfigData( |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 357 | log.WithSpanFromContext(context.TODO(), ctx), uniPort, onuDeviceEntry.pOpenOnuAc.omciTimeout, true) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 358 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 359 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 360 | logger.Errorw(ctx, "EVTOConfigData create failed, aborting MibDownload FSM!", |
| 361 | log.Fields{"device-id": onuDeviceEntry.deviceID}) |
| 362 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset) |
| 363 | return |
| 364 | } |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 365 | onuDeviceEntry.PDevOmciCC.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 366 | onuDeviceEntry.PDevOmciCC.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 367 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 368 | err = onuDeviceEntry.waitforOmciResponse(ctx, meInstance) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 369 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 370 | logger.Errorw(ctx, "InitialBridgeSetup failed at EVTOCD, aborting MIB Download!", |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 371 | log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 372 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvReset) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 373 | return |
| 374 | } |
| 375 | } |
| 376 | // if Config has been done for all UNI related instances let the FSM proceed |
| 377 | // while we did not check here, if there is some port at all - !? |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 378 | logger.Infow(ctx, "IntialBridgeSetup finished", log.Fields{"device-id": onuDeviceEntry.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 379 | _ = onuDeviceEntry.pMibDownloadFsm.pFsm.Event(dlEvRxBridgeResp) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 380 | } |
| 381 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 382 | func (onuDeviceEntry *OnuDeviceEntry) waitforOmciResponse(ctx context.Context, apMeInstance *me.ManagedEntity) error { |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 383 | select { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 384 | // 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] | 385 | // case <-ctx.Done(): |
| 386 | // logger.Info("MibDownload-bridge-init message reception canceled", log.Fields{"for device-id": onuDeviceEntry.deviceID}) |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 387 | case <-time.After(onuDeviceEntry.PDevOmciCC.GetMaxOmciTimeoutWithRetries() * 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] | 388 | 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] | 389 | return fmt.Errorf("mibDownloadBridgeInit timeout %s", onuDeviceEntry.deviceID) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 390 | case success := <-onuDeviceEntry.omciMessageReceived: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 391 | if success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 392 | logger.Debug(ctx, "MibDownload-bridge-init response received") |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 393 | return nil |
| 394 | } |
| 395 | // should not happen so far |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 396 | 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] | 397 | return fmt.Errorf("mibDownloadBridgeInit responseError %s", onuDeviceEntry.deviceID) |
Holger Hildebrandt | dd23cc2 | 2020-05-19 13:32:18 +0000 | [diff] [blame] | 398 | } |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 399 | } |