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