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