mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1 | /* |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 2 | * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 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 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 17 | // Package avcfg provides anig and vlan configuration functionality |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 18 | package avcfg |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "encoding/binary" |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 23 | "errors" |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 24 | "fmt" |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 25 | "net" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 26 | "strconv" |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 27 | "sync" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 28 | "time" |
| 29 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 30 | meters "github.com/opencord/voltha-lib-go/v7/pkg/meters" |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 31 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 32 | gp "github.com/google/gopacket" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 33 | "github.com/looplab/fsm" |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 34 | "github.com/opencord/omci-lib-go/v2" |
| 35 | me "github.com/opencord/omci-lib-go/v2/generated" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 36 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 37 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
| 38 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 39 | of "github.com/opencord/voltha-protos/v5/go/openflow_13" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 40 | ) |
| 41 | |
| 42 | const ( |
| 43 | // internal predefined values |
| 44 | cDefaultDownstreamMode = 0 |
| 45 | cDefaultTpid = 0x8100 |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 46 | cVtfdTableSize = 12 //as per G.988 |
| 47 | cMaxAllowedFlows = cVtfdTableSize //which might be under discussion, for the moment connected to limit of VLAN's within VTFD |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 48 | ) |
| 49 | |
| 50 | const ( |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 51 | // internal offsets for requestEvent according to definition in onu_device_entry::cmn.OnuDeviceEvent |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 52 | cDeviceEventOffsetAddWithKvStore = 0 //OmciVlanFilterAddDone - OmciVlanFilterAddDone cannot use because of lint |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 53 | cDeviceEventOffsetAddNoKvStore = cmn.OmciVlanFilterAddDoneNoKvStore - cmn.OmciVlanFilterAddDone |
| 54 | cDeviceEventOffsetRemoveWithKvStore = cmn.OmciVlanFilterRemDone - cmn.OmciVlanFilterAddDone |
| 55 | cDeviceEventOffsetRemoveNoKvStore = cmn.OmciVlanFilterRemDoneNoKvStore - cmn.OmciVlanFilterAddDone |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 56 | ) |
| 57 | |
| 58 | const ( |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 59 | // bit mask offsets for EVTOCD VlanTaggingOperationTable related to 32 bits (4 bytes) |
| 60 | cFilterPrioOffset = 28 |
| 61 | cFilterVidOffset = 15 |
| 62 | cFilterTpidOffset = 12 |
| 63 | cFilterEtherTypeOffset = 0 |
| 64 | cTreatTTROffset = 30 |
| 65 | cTreatPrioOffset = 16 |
| 66 | cTreatVidOffset = 3 |
| 67 | cTreatTpidOffset = 0 |
| 68 | ) |
| 69 | const ( |
| 70 | // byte offsets for EVTOCD VlanTaggingOperationTable related to overall 16 byte size with slice byte 0 as first Byte (MSB) |
| 71 | cFilterOuterOffset = 0 |
| 72 | cFilterInnerOffset = 4 |
| 73 | cTreatOuterOffset = 8 |
| 74 | cTreatInnerOffset = 12 |
| 75 | ) |
| 76 | const ( |
| 77 | // basic values used within EVTOCD VlanTaggingOperationTable in respect to their bitfields |
| 78 | cPrioIgnoreTag uint32 = 15 |
| 79 | cPrioDefaultFilter uint32 = 14 |
| 80 | cPrioDoNotFilter uint32 = 8 |
| 81 | cDoNotFilterVid uint32 = 4096 |
| 82 | cDoNotFilterTPID uint32 = 0 |
| 83 | cDoNotFilterEtherType uint32 = 0 |
| 84 | cDoNotAddPrio uint32 = 15 |
| 85 | cCopyPrioFromInner uint32 = 8 |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 86 | cCopyPrioFromOuter uint32 = 9 |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 87 | //cDontCarePrio uint32 = 0 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 88 | cDontCareVid uint32 = 0 |
| 89 | cDontCareTpid uint32 = 0 |
| 90 | cSetOutputTpidCopyDei uint32 = 4 |
| 91 | ) |
| 92 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 93 | // events of config UNI port VLAN FSM |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 94 | const ( |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 95 | VlanEvStart = "VlanEvStart" |
| 96 | VlanEvPrepareDone = "VlanEvPrepareDone" |
| 97 | VlanEvWaitTechProf = "VlanEvWaitTechProf" |
| 98 | VlanEvCancelOutstandingConfig = "VlanEvCancelOutstandingConfig" |
| 99 | VlanEvContinueConfig = "VlanEvContinueConfig" |
| 100 | VlanEvStartConfig = "VlanEvStartConfig" |
| 101 | VlanEvRxConfigVtfd = "VlanEvRxConfigVtfd" |
| 102 | VlanEvRxConfigEvtocd = "VlanEvRxConfigEvtocd" |
| 103 | VlanEvWaitTPIncr = "VlanEvWaitTPIncr" |
| 104 | VlanEvIncrFlowConfig = "VlanEvIncrFlowConfig" |
| 105 | VlanEvRenew = "VlanEvRenew" |
| 106 | VlanEvRemFlowConfig = "VlanEvRemFlowConfig" |
| 107 | VlanEvRemFlowDone = "VlanEvRemFlowDone" |
| 108 | VlanEvFlowDataRemoved = "VlanEvFlowDataRemoved" |
| 109 | //VlanEvTimeoutSimple = "VlanEvTimeoutSimple" |
| 110 | //VlanEvTimeoutMids = "VlanEvTimeoutMids" |
| 111 | VlanEvReset = "VlanEvReset" |
| 112 | VlanEvRestart = "VlanEvRestart" |
| 113 | VlanEvSkipOmciConfig = "VlanEvSkipOmciConfig" |
| 114 | VlanEvSkipIncFlowConfig = "VlanEvSkipIncFlowConfig" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 115 | ) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 116 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 117 | // states of config UNI port VLAN FSM |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 118 | const ( |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 119 | VlanStDisabled = "VlanStDisabled" |
| 120 | VlanStPreparing = "VlanStPreparing" |
| 121 | VlanStStarting = "VlanStStarting" |
| 122 | VlanStWaitingTechProf = "VlanStWaitingTechProf" |
| 123 | VlanStConfigVtfd = "VlanStConfigVtfd" |
| 124 | VlanStConfigEvtocd = "VlanStConfigEvtocd" |
| 125 | VlanStConfigDone = "VlanStConfigDone" |
| 126 | VlanStIncrFlowWaitTP = "VlanStIncrFlowWaitTP" |
| 127 | VlanStConfigIncrFlow = "VlanStConfigIncrFlow" |
| 128 | VlanStRemoveFlow = "VlanStRemoveFlow" |
| 129 | VlanStCleanupDone = "VlanStCleanupDone" |
| 130 | VlanStResetting = "VlanStResetting" |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 131 | ) |
| 132 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 133 | // CVlanFsmIdleState - TODO: add comment |
| 134 | const CVlanFsmIdleState = VlanStConfigDone // state where no OMCI activity is done (for a longer time) |
| 135 | // CVlanFsmConfiguredState - TODO: add comment |
| 136 | const CVlanFsmConfiguredState = VlanStConfigDone // state that indicates that at least some valid user related VLAN configuration should exist |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 137 | |
| 138 | type uniRemoveVlanFlowParams struct { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 139 | isSuspendedOnAdd bool |
| 140 | removeChannel chan bool |
| 141 | cookie uint64 //just the last cookie valid for removal |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 142 | vlanRuleParams cmn.UniVlanRuleParams |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 143 | respChan *chan error |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 144 | } |
| 145 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 146 | // UniVlanConfigFsm defines the structure for the state machine for configuration of the VLAN related setting via OMCI |
| 147 | // |
| 148 | // builds upon 'VLAN rules' that are derived from multiple flows |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 149 | type UniVlanConfigFsm struct { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 150 | pDeviceHandler cmn.IdeviceHandler |
| 151 | pOnuDeviceEntry cmn.IonuDeviceEntry |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 152 | deviceID string |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 153 | pOmciCC *cmn.OmciCC |
| 154 | pOnuUniPort *cmn.OnuUniPort |
| 155 | pUniTechProf *OnuUniTechProf |
| 156 | pOnuDB *devdb.OnuDeviceDB |
| 157 | requestEvent cmn.OnuDeviceEvent |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 158 | omciMIdsResponseReceived chan bool //seperate channel needed for checking multiInstance OMCI message responses |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 159 | PAdaptFsm *cmn.AdapterFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 160 | acceptIncrementalEvtoOption bool |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 161 | isCanceled bool |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 162 | isAwaitingResponse bool |
| 163 | mutexIsAwaitingResponse sync.RWMutex |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 164 | mutexFlowParams sync.RWMutex |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 165 | chCookieDeleted chan bool //channel to indicate that a specific cookie (related to the active rule) was deleted |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 166 | actualUniFlowParam cmn.UniVlanFlowParams |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 167 | uniVlanFlowParamsSlice []cmn.UniVlanFlowParams |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 168 | uniRemoveFlowsSlice []uniRemoveVlanFlowParams |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 169 | NumUniFlows uint8 // expected number of flows should be less than 12 |
| 170 | ConfiguredUniFlow uint8 |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 171 | numRemoveFlows uint8 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 172 | numVlanFilterEntries uint8 |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 173 | vlanFilterList [cVtfdTableSize]uint16 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 174 | evtocdID uint16 |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 175 | mutexPLastTxMeInstance sync.RWMutex |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 176 | pLastTxMeInstance *me.ManagedEntity |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 177 | requestEventOffset uint8 |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 178 | TpIDWaitingFor uint8 |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 179 | signalOnFlowDelete bool |
| 180 | flowDeleteChannel chan<- bool |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 181 | //cookie value that indicates that a rule to add is delayed by waiting for deletion of some other existing rule with the same cookie |
| 182 | delayNewRuleCookie uint64 |
Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 183 | // Used to indicate if the FSM is for a reconciling flow and if it's the last flow to be reconciled |
| 184 | // thus notification needs to be sent on chan. |
| 185 | lastFlowToReconcile bool |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 186 | } |
| 187 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 188 | // NewUniVlanConfigFsm is the 'constructor' for the state machine to config the PON ANI ports |
| 189 | // |
| 190 | // of ONU UNI ports via OMCI |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 191 | func NewUniVlanConfigFsm(ctx context.Context, apDeviceHandler cmn.IdeviceHandler, apOnuDeviceEntry cmn.IonuDeviceEntry, apDevOmciCC *cmn.OmciCC, apUniPort *cmn.OnuUniPort, |
| 192 | apUniTechProf *OnuUniTechProf, apOnuDB *devdb.OnuDeviceDB, aTechProfileID uint8, |
| 193 | aRequestEvent cmn.OnuDeviceEvent, aName string, aCommChannel chan cmn.Message, aAcceptIncrementalEvto bool, |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 194 | aCookieSlice []uint64, aMatchVlan uint16, aMatchPcp uint8, aSetVlan uint16, aSetPcp uint8, innerCvlan uint16, lastFlowToRec bool, aMeter *of.OfpMeterConfig, respChan *chan error) *UniVlanConfigFsm { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 195 | instFsm := &UniVlanConfigFsm{ |
| 196 | pDeviceHandler: apDeviceHandler, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 197 | pOnuDeviceEntry: apOnuDeviceEntry, |
| 198 | deviceID: apDeviceHandler.GetDeviceID(), |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 199 | pOmciCC: apDevOmciCC, |
| 200 | pOnuUniPort: apUniPort, |
| 201 | pUniTechProf: apUniTechProf, |
| 202 | pOnuDB: apOnuDB, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 203 | requestEvent: aRequestEvent, |
| 204 | acceptIncrementalEvtoOption: aAcceptIncrementalEvto, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 205 | NumUniFlows: 0, |
| 206 | ConfiguredUniFlow: 0, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 207 | numRemoveFlows: 0, |
Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 208 | lastFlowToReconcile: lastFlowToRec, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 211 | instFsm.PAdaptFsm = cmn.NewAdapterFsm(aName, instFsm.deviceID, aCommChannel) |
| 212 | if instFsm.PAdaptFsm == nil { |
| 213 | logger.Errorw(ctx, "UniVlanConfigFsm's cmn.AdapterFsm could not be instantiated!!", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 214 | "device-id": instFsm.deviceID}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 215 | // Push response on the response channel |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 216 | instFsm.pushReponseOnFlowResponseChannel(ctx, respChan, fmt.Errorf("adapter-fsm-could-not-be-instantiated")) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 217 | return nil |
| 218 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 219 | instFsm.PAdaptFsm.PFsm = fsm.NewFSM( |
| 220 | VlanStDisabled, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 221 | fsm.Events{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 222 | {Name: VlanEvStart, Src: []string{VlanStDisabled}, Dst: VlanStPreparing}, |
| 223 | {Name: VlanEvPrepareDone, Src: []string{VlanStPreparing}, Dst: VlanStStarting}, |
| 224 | {Name: VlanEvWaitTechProf, Src: []string{VlanStStarting}, Dst: VlanStWaitingTechProf}, |
| 225 | {Name: VlanEvCancelOutstandingConfig, Src: []string{VlanStWaitingTechProf}, Dst: VlanStConfigDone}, |
| 226 | {Name: VlanEvContinueConfig, Src: []string{VlanStWaitingTechProf}, Dst: VlanStConfigVtfd}, |
| 227 | {Name: VlanEvStartConfig, Src: []string{VlanStStarting}, Dst: VlanStConfigVtfd}, |
| 228 | {Name: VlanEvRxConfigVtfd, Src: []string{VlanStConfigVtfd}, Dst: VlanStConfigEvtocd}, |
| 229 | {Name: VlanEvRxConfigEvtocd, Src: []string{VlanStConfigEvtocd, VlanStConfigIncrFlow}, |
| 230 | Dst: VlanStConfigDone}, |
| 231 | {Name: VlanEvRenew, Src: []string{VlanStConfigDone}, Dst: VlanStStarting}, |
| 232 | {Name: VlanEvWaitTPIncr, Src: []string{VlanStConfigDone}, Dst: VlanStIncrFlowWaitTP}, |
| 233 | {Name: VlanEvIncrFlowConfig, Src: []string{VlanStConfigDone, VlanStIncrFlowWaitTP}, |
| 234 | Dst: VlanStConfigIncrFlow}, |
| 235 | {Name: VlanEvRemFlowConfig, Src: []string{VlanStConfigDone}, Dst: VlanStRemoveFlow}, |
| 236 | {Name: VlanEvRemFlowDone, Src: []string{VlanStRemoveFlow}, Dst: VlanStCleanupDone}, |
| 237 | {Name: VlanEvFlowDataRemoved, Src: []string{VlanStCleanupDone}, Dst: VlanStConfigDone}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 238 | /* |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 239 | {Name: VlanEvTimeoutSimple, Src: []string{ |
| 240 | VlanStCreatingDot1PMapper, VlanStCreatingMBPCD, VlanStSettingTconts, VlanStSettingDot1PMapper}, Dst: VlanStStarting}, |
| 241 | {Name: VlanEvTimeoutMids, Src: []string{ |
| 242 | VlanStCreatingGemNCTPs, VlanStCreatingGemIWs, VlanStSettingPQs}, Dst: VlanStStarting}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 243 | */ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 244 | // exceptional treatment for all states except VlanStResetting |
| 245 | {Name: VlanEvReset, Src: []string{VlanStStarting, VlanStWaitingTechProf, |
| 246 | VlanStConfigVtfd, VlanStConfigEvtocd, VlanStConfigDone, VlanStConfigIncrFlow, |
nikesh.krishnan | c7c0bce | 2023-12-20 21:36:35 +0530 | [diff] [blame] | 247 | VlanStRemoveFlow, VlanStCleanupDone, VlanStPreparing}, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 248 | Dst: VlanStResetting}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 249 | // the only way to get to resource-cleared disabled state again is via "resseting" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 250 | {Name: VlanEvRestart, Src: []string{VlanStResetting}, Dst: VlanStDisabled}, |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 251 | // transitions for reconcile handling according to VOL-3834 |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 252 | {Name: VlanEvSkipOmciConfig, Src: []string{VlanStPreparing}, Dst: VlanStConfigDone}, |
| 253 | {Name: VlanEvSkipOmciConfig, Src: []string{VlanStConfigDone}, Dst: VlanStConfigIncrFlow}, |
| 254 | {Name: VlanEvSkipIncFlowConfig, Src: []string{VlanStConfigIncrFlow}, Dst: VlanStConfigDone}, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 255 | }, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 256 | fsm.Callbacks{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 257 | "enter_state": func(e *fsm.Event) { instFsm.PAdaptFsm.LogFsmStateChange(ctx, e) }, |
| 258 | "enter_" + VlanStPreparing: func(e *fsm.Event) { instFsm.enterPreparing(ctx, e) }, |
| 259 | "enter_" + VlanStStarting: func(e *fsm.Event) { instFsm.enterConfigStarting(ctx, e) }, |
| 260 | "enter_" + VlanStConfigVtfd: func(e *fsm.Event) { instFsm.enterConfigVtfd(ctx, e) }, |
| 261 | "enter_" + VlanStConfigEvtocd: func(e *fsm.Event) { instFsm.enterConfigEvtocd(ctx, e) }, |
| 262 | "enter_" + VlanStConfigDone: func(e *fsm.Event) { instFsm.enterVlanConfigDone(ctx, e) }, |
| 263 | "enter_" + VlanStConfigIncrFlow: func(e *fsm.Event) { instFsm.enterConfigIncrFlow(ctx, e) }, |
| 264 | "enter_" + VlanStRemoveFlow: func(e *fsm.Event) { instFsm.enterRemoveFlow(ctx, e) }, |
| 265 | "enter_" + VlanStCleanupDone: func(e *fsm.Event) { instFsm.enterVlanCleanupDone(ctx, e) }, |
| 266 | "enter_" + VlanStResetting: func(e *fsm.Event) { instFsm.enterResetting(ctx, e) }, |
| 267 | "enter_" + VlanStDisabled: func(e *fsm.Event) { instFsm.enterDisabled(ctx, e) }, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 268 | }, |
| 269 | ) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 270 | if instFsm.PAdaptFsm.PFsm == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 271 | logger.Errorw(ctx, "UniVlanConfigFsm's Base FSM could not be instantiated!!", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 272 | "device-id": instFsm.deviceID}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 273 | // Push response on the response channel |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 274 | instFsm.pushReponseOnFlowResponseChannel(ctx, respChan, fmt.Errorf("adapter-base-fsm-could-not-be-instantiated")) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 275 | return nil |
| 276 | } |
| 277 | |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 278 | _ = instFsm.initUniFlowParams(ctx, aTechProfileID, aCookieSlice, aMatchVlan, aMatchPcp, aSetVlan, aSetPcp, innerCvlan, aMeter, respChan) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 279 | logger.Debugw(ctx, "UniVlanConfigFsm created", log.Fields{"device-id": instFsm.deviceID, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 280 | "accIncrEvto": instFsm.acceptIncrementalEvtoOption}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 281 | return instFsm |
| 282 | } |
| 283 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 284 | // initUniFlowParams is a simplified form of SetUniFlowParams() used for first flow parameters configuration |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 285 | func (oFsm *UniVlanConfigFsm) initUniFlowParams(ctx context.Context, aTpID uint8, aCookieSlice []uint64, |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 286 | aMatchVlan uint16, aMatchPcp uint8, aSetVlan uint16, aSetPcp uint8, innerCvlan uint16, aMeter *of.OfpMeterConfig, respChan *chan error) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 287 | loRuleParams := cmn.UniVlanRuleParams{ |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 288 | TpID: aTpID, |
| 289 | MatchVid: uint32(aMatchVlan), |
| 290 | MatchPcp: uint32(aMatchPcp), |
| 291 | SetVid: uint32(aSetVlan), |
| 292 | SetPcp: uint32(aSetPcp), |
| 293 | InnerCvlan: innerCvlan, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 294 | } |
| 295 | // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters |
Abhilash Laxmeshwar | c7c29d8 | 2022-03-03 18:38:45 +0530 | [diff] [blame] | 296 | loRuleParams.TagsToRemove = 1 //one tag to remove as default setting |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 297 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 298 | if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 299 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 300 | loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 301 | //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther) |
| 302 | } else { |
| 303 | if !oFsm.acceptIncrementalEvtoOption { |
| 304 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 305 | loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 309 | if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 310 | // no prio/vid filtering requested |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 311 | loRuleParams.TagsToRemove = 0 //no tag pop action |
| 312 | loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering |
| 313 | if loRuleParams.SetPcp == cCopyPrioFromInner { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 314 | //in case of no filtering and configured PrioCopy ensure default prio setting to 0 |
| 315 | // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged |
| 316 | // might collide with NoMatchVid/CopyPrio(/setVid) setting |
| 317 | // this was some precondition setting taken over from py adapter .. |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 318 | loRuleParams.SetPcp = 0 |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 319 | } |
| 320 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 321 | |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 322 | loFlowParams := cmn.UniVlanFlowParams{VlanRuleParams: loRuleParams, RespChan: respChan} |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 323 | loFlowParams.CookieSlice = make([]uint64, 0) |
| 324 | loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...) |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 325 | if aMeter != nil { |
| 326 | loFlowParams.Meter = aMeter |
| 327 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 328 | |
| 329 | //no mutex protection is required for initial access and adding the first flow is always possible |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 330 | oFsm.uniVlanFlowParamsSlice = make([]cmn.UniVlanFlowParams, 0) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 331 | oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 332 | logger.Debugw(ctx, "first UniVlanConfigFsm flow added", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 333 | "Cookies": oFsm.uniVlanFlowParamsSlice[0].CookieSlice, |
| 334 | "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16), |
| 335 | "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16), |
| 336 | "SetPcp": loRuleParams.SetPcp, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 337 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID}) |
Holger Hildebrandt | 968eb8f | 2021-09-17 07:41:12 +0000 | [diff] [blame] | 338 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 339 | if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() { |
Holger Hildebrandt | 968eb8f | 2021-09-17 07:41:12 +0000 | [diff] [blame] | 340 | oFsm.reconcileVlanFilterList(ctx, uint16(loRuleParams.SetVid)) |
| 341 | } |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 342 | //cmp also usage in EVTOCDE create in omci_cc |
| 343 | oFsm.evtocdID = cmn.MacBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.MacBpNo) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 344 | oFsm.NumUniFlows = 1 |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 345 | oFsm.uniRemoveFlowsSlice = make([]uniRemoveVlanFlowParams, 0) //initially nothing to remove |
| 346 | |
| 347 | //permanently store flow config for reconcile case |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 348 | if err := oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID, |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 349 | &oFsm.uniVlanFlowParamsSlice, true); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 350 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 351 | return err |
| 352 | } |
| 353 | |
| 354 | return nil |
| 355 | } |
| 356 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 357 | // CancelProcessing ensures that suspended processing at waiting on some response is aborted and reset of FSM |
mpagenko | 7314399 | 2021-04-09 15:17:10 +0000 | [diff] [blame] | 358 | func (oFsm *UniVlanConfigFsm) CancelProcessing(ctx context.Context) { |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 359 | if oFsm == nil { |
| 360 | logger.Error(ctx, "no valid UniVlanConfigFsm!") |
| 361 | return |
| 362 | } |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 363 | logger.Debugw(ctx, "CancelProcessing entered", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 364 | //mutex protection is required for possible concurrent access to FSM members |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 365 | oFsm.mutexIsAwaitingResponse.Lock() |
| 366 | oFsm.isCanceled = true |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 367 | if oFsm.isAwaitingResponse { |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 368 | //attention: for an unbuffered channel the sender is blocked until the value is received (processed)! |
| 369 | // accordingly the mutex must be released before sending to channel here (mutex acquired in receiver) |
| 370 | oFsm.mutexIsAwaitingResponse.Unlock() |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 371 | //use channel to indicate that the response waiting shall be aborted |
| 372 | oFsm.omciMIdsResponseReceived <- false |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 373 | } else { |
| 374 | oFsm.mutexIsAwaitingResponse.Unlock() |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 375 | } |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 376 | |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 377 | // in any case (even if it might be automatically requested by above cancellation of waiting) ensure resetting the FSM |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 378 | PAdaptFsm := oFsm.PAdaptFsm |
| 379 | if PAdaptFsm != nil { |
| 380 | if fsmErr := PAdaptFsm.PFsm.Event(VlanEvReset); fsmErr != nil { |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 381 | logger.Errorw(ctx, "reset-event failed in UniVlanConfigFsm!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 382 | log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID}) |
Holger Hildebrandt | b4563ab | 2021-04-14 10:27:20 +0000 | [diff] [blame] | 383 | } |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 387 | // GetWaitingTpID returns the TpId that the FSM might be waiting for continuation (0 if none) |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 388 | func (oFsm *UniVlanConfigFsm) GetWaitingTpID(ctx context.Context) uint8 { |
| 389 | if oFsm == nil { |
| 390 | logger.Error(ctx, "no valid UniVlanConfigFsm!") |
| 391 | return 0 |
| 392 | } |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 393 | //mutex protection is required for possible concurrent access to FSM members |
| 394 | oFsm.mutexFlowParams.RLock() |
| 395 | defer oFsm.mutexFlowParams.RUnlock() |
| 396 | return oFsm.TpIDWaitingFor |
| 397 | } |
| 398 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 399 | // SetUniFlowParams verifies on existence of flow parameters to be configured, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 400 | // optionally udates the cookie list or appends a new flow if there is space |
| 401 | // if possible the FSM is trigggerd to start with the processing |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 402 | // ignore complexity by now |
| 403 | // nolint: gocyclo |
| 404 | func (oFsm *UniVlanConfigFsm) SetUniFlowParams(ctx context.Context, aTpID uint8, aCookieSlice []uint64, |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 405 | aMatchVlan uint16, aMatchPcp uint8, aSetVlan uint16, aSetPcp uint8, aInnerCvlan uint16, lastFlowToReconcile bool, aMeter *of.OfpMeterConfig, respChan *chan error) error { |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 406 | if oFsm == nil { |
| 407 | logger.Error(ctx, "no valid UniVlanConfigFsm!") |
| 408 | return fmt.Errorf("no-valid-UniVlanConfigFsm") |
| 409 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 410 | loRuleParams := cmn.UniVlanRuleParams{ |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 411 | TpID: aTpID, |
| 412 | MatchVid: uint32(aMatchVlan), |
| 413 | MatchPcp: uint32(aMatchPcp), |
| 414 | SetVid: uint32(aSetVlan), |
| 415 | SetPcp: uint32(aSetPcp), |
| 416 | InnerCvlan: aInnerCvlan, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 417 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 418 | var err error |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 419 | // some automatic adjustments on the filter/treat parameters as not specifically configured/ensured by flow configuration parameters |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 420 | loRuleParams.TagsToRemove = 1 //one tag to remove as default setting |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 421 | if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 422 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
| 423 | loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
| 424 | //TODO!!: maybe be needed to be re-checked at flow deletion (but assume all flows are always deleted togehther) |
| 425 | } else { |
| 426 | if !oFsm.acceptIncrementalEvtoOption { |
| 427 | //then matchVlan is don't care and should be overwritten to 'transparent' here to avoid unneeded multiple flow entries |
| 428 | loRuleParams.MatchVid = uint32(of.OfpVlanId_OFPVID_PRESENT) |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | if loRuleParams.MatchVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 433 | // no prio/vid filtering requested |
| 434 | loRuleParams.TagsToRemove = 0 //no tag pop action |
| 435 | loRuleParams.MatchPcp = cPrioIgnoreTag // no vlan tag filtering |
| 436 | if loRuleParams.SetPcp == cCopyPrioFromInner { |
| 437 | //in case of no filtering and configured PrioCopy ensure default prio setting to 0 |
| 438 | // which is required for stacking of untagged, but obviously also ensures prio setting for prio/singletagged |
| 439 | // might collide with NoMatchVid/CopyPrio(/setVid) setting |
| 440 | // this was some precondition setting taken over from py adapter .. |
| 441 | loRuleParams.SetPcp = 0 |
| 442 | } |
| 443 | } |
| 444 | |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 445 | //check if there is some ongoing delete-request running for this flow. If so, block here until this is finished. |
| 446 | // might be accordingly rwCore processing runs into timeout in specific situations - needs to be observed ... |
| 447 | // this is to protect uniVlanFlowParams from adding new or re-writing the same cookie to the rule currently under deletion |
| 448 | oFsm.mutexFlowParams.RLock() |
| 449 | if len(oFsm.uniRemoveFlowsSlice) > 0 { |
| 450 | for flow, removeUniFlowParams := range oFsm.uniRemoveFlowsSlice { |
| 451 | if removeUniFlowParams.vlanRuleParams == loRuleParams { |
| 452 | // the flow to add is the same as the one already in progress of deleting |
| 453 | logger.Infow(ctx, "UniVlanConfigFsm flow setting - suspending rule-add due to ongoing removal", log.Fields{ |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 454 | "device-id": oFsm.deviceID, "cookie": removeUniFlowParams.cookie, "remove-index": flow}) |
| 455 | if flow >= len(oFsm.uniRemoveFlowsSlice) { |
| 456 | logger.Errorw(ctx, "abort UniVlanConfigFsm flow add - inconsistent RemoveFlowsSlice", log.Fields{ |
| 457 | "device-id": oFsm.deviceID, "slice length": len(oFsm.uniRemoveFlowsSlice)}) |
| 458 | oFsm.mutexFlowParams.RUnlock() |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 459 | err = fmt.Errorf("abort UniVlanConfigFsm flow add - inconsistent RemoveFlowsSlice %s", oFsm.deviceID) |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 460 | oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 461 | return err |
| 462 | |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 463 | } |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 464 | pRemoveParams := &oFsm.uniRemoveFlowsSlice[flow] //wants to modify the uniRemoveFlowsSlice element directly! |
| 465 | oFsm.mutexFlowParams.RUnlock() |
| 466 | if err := oFsm.suspendAddRule(ctx, pRemoveParams); err != nil { |
| 467 | logger.Errorw(ctx, "UniVlanConfigFsm suspension on add aborted - abort complete add-request", log.Fields{ |
| 468 | "device-id": oFsm.deviceID, "cookie": removeUniFlowParams.cookie}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 469 | err = fmt.Errorf("abort UniVlanConfigFsm suspension on add %s", oFsm.deviceID) |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 470 | oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 471 | return err |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 472 | } |
| 473 | oFsm.mutexFlowParams.RLock() |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 474 | break //this specific rule should only exist once per uniRemoveFlowsSlice |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | } |
| 478 | oFsm.mutexFlowParams.RUnlock() |
| 479 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 480 | flowEntryMatch := false |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 481 | flowCookieModify := false |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 482 | requestAppendRule := false |
Andrea Campanella | f66ac6e | 2021-05-24 17:09:20 +0200 | [diff] [blame] | 483 | oFsm.lastFlowToReconcile = lastFlowToReconcile |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 484 | //mutex protection is required for possible concurrent access to FSM members |
| 485 | oFsm.mutexFlowParams.Lock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 486 | for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice { |
| 487 | //TODO: Verify if using e.g. hashes for the structures here for comparison may generate |
| 488 | // countable run time optimization (perhaps with including the hash in kvStore storage?) |
| 489 | if storedUniFlowParams.VlanRuleParams == loRuleParams { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 490 | flowEntryMatch = true |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 491 | logger.Debugw(ctx, "UniVlanConfigFsm flow setting - rule already exists", log.Fields{ |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 492 | "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16), |
| 493 | "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16), |
| 494 | "SetPcp": loRuleParams.SetPcp, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 495 | "device-id": oFsm.deviceID, " uni-id": oFsm.pOnuUniPort.UniID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 496 | var cookieMatch bool |
| 497 | for _, newCookie := range aCookieSlice { // for all cookies available in the arguments |
| 498 | cookieMatch = false |
| 499 | for _, cookie := range storedUniFlowParams.CookieSlice { |
| 500 | if cookie == newCookie { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 501 | logger.Debugw(ctx, "UniVlanConfigFsm flow setting - and cookie already exists", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 502 | "device-id": oFsm.deviceID, "cookie": cookie}) |
| 503 | cookieMatch = true |
| 504 | break //found new cookie - no further search for this requested cookie |
| 505 | } |
| 506 | } |
| 507 | if !cookieMatch { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 508 | delayedCookie := oFsm.delayNewRuleForCookie(ctx, aCookieSlice) |
| 509 | if delayedCookie != 0 { |
| 510 | //a delay for adding the cookie to this rule is requested |
| 511 | // take care of the mutex which is already locked here, need to unlock/lock accordingly to prevent deadlock in suspension |
| 512 | oFsm.mutexFlowParams.Unlock() |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 513 | if deleteSuccess := oFsm.suspendNewRule(ctx); !deleteSuccess { |
| 514 | logger.Errorw(ctx, "UniVlanConfigFsm suspended add-cookie-to-rule aborted", log.Fields{ |
| 515 | "device-id": oFsm.deviceID, "cookie": delayedCookie}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 516 | err = fmt.Errorf(" UniVlanConfigFsm suspended add-cookie-to-rule aborted %s", oFsm.deviceID) |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 517 | oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 518 | return err |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 519 | } |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 520 | flowCookieModify, requestAppendRule = oFsm.reviseFlowConstellation(ctx, delayedCookie, loRuleParams) |
mpagenko | d6c0552 | 2021-08-23 15:59:06 +0000 | [diff] [blame] | 521 | oFsm.mutexFlowParams.Lock() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 522 | } else { |
| 523 | logger.Debugw(ctx, "UniVlanConfigFsm flow setting -adding new cookie", log.Fields{ |
| 524 | "device-id": oFsm.deviceID, "cookie": newCookie}) |
| 525 | //as range works with copies of the slice we have to write to the original slice!! |
| 526 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(oFsm.uniVlanFlowParamsSlice[flow].CookieSlice, |
| 527 | newCookie) |
| 528 | flowCookieModify = true |
| 529 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 530 | } |
| 531 | } //for all new cookies |
| 532 | break // found rule - no further rule search |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 533 | } |
| 534 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 535 | oFsm.mutexFlowParams.Unlock() |
| 536 | |
| 537 | if !flowEntryMatch { //it is (was) a new rule |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 538 | delayedCookie, deleteSuccess := oFsm.suspendIfRequiredNewRule(ctx, aCookieSlice) |
| 539 | if !deleteSuccess { |
| 540 | logger.Errorw(ctx, "UniVlanConfigFsm suspended add-new-rule aborted", log.Fields{ |
| 541 | "device-id": oFsm.deviceID, "cookie": delayedCookie}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 542 | err = fmt.Errorf(" UniVlanConfigFsm suspended add-new-rule aborted %s", oFsm.deviceID) |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 543 | oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 544 | return err |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 545 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 546 | requestAppendRule = true //default assumption here is that rule is to be appended |
| 547 | flowCookieModify = true //and that the the flow data base is to be updated |
| 548 | if delayedCookie != 0 { //it was suspended |
| 549 | flowCookieModify, requestAppendRule = oFsm.reviseFlowConstellation(ctx, delayedCookie, loRuleParams) |
| 550 | } |
| 551 | } |
| 552 | kvStoreWrite := false //default setting is to not write to kvStore immediately - will be done on FSM execution finally |
| 553 | if requestAppendRule { |
| 554 | oFsm.mutexFlowParams.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 555 | if oFsm.NumUniFlows < cMaxAllowedFlows { |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 556 | loFlowParams := cmn.UniVlanFlowParams{VlanRuleParams: loRuleParams, RespChan: respChan} |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 557 | loFlowParams.CookieSlice = make([]uint64, 0) |
| 558 | loFlowParams.CookieSlice = append(loFlowParams.CookieSlice, aCookieSlice...) |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 559 | if aMeter != nil { |
| 560 | loFlowParams.Meter = aMeter |
| 561 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 562 | oFsm.uniVlanFlowParamsSlice = append(oFsm.uniVlanFlowParamsSlice, loFlowParams) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 563 | logger.Debugw(ctx, "UniVlanConfigFsm flow add", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 564 | "Cookies": oFsm.uniVlanFlowParamsSlice[oFsm.NumUniFlows].CookieSlice, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 565 | "MatchVid": strconv.FormatInt(int64(loRuleParams.MatchVid), 16), |
| 566 | "SetVid": strconv.FormatInt(int64(loRuleParams.SetVid), 16), |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 567 | "SetPcp": loRuleParams.SetPcp, "numberofFlows": oFsm.NumUniFlows + 1, |
| 568 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 569 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 570 | if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() { |
Holger Hildebrandt | 968eb8f | 2021-09-17 07:41:12 +0000 | [diff] [blame] | 571 | oFsm.reconcileVlanFilterList(ctx, uint16(loRuleParams.SetVid)) |
| 572 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 573 | oFsm.NumUniFlows++ |
| 574 | pConfigVlanStateBaseFsm := oFsm.PAdaptFsm.PFsm |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 575 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 576 | if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 577 | logger.Debugw(ctx, "reconciling - skip omci-config of additional vlan rule", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 578 | log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID}) |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 579 | //attention: take care to release the mutexFlowParams when calling the FSM directly - |
| 580 | // synchronous FSM 'event/state' functions may rely on this mutex |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 581 | oFsm.mutexFlowParams.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 582 | if pConfigVlanStateBaseFsm.Is(VlanStConfigDone) { |
| 583 | if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvSkipOmciConfig); fsmErr != nil { |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 584 | logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 585 | log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID}) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 586 | err = fsmErr |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 587 | oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 588 | return err |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 589 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 590 | } |
| 591 | return nil |
| 592 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 593 | // note: theoretical it would be possible to clear the same rule from the remove slice |
| 594 | // (for entries that have not yet been started with removal) |
| 595 | // but that is getting quite complicated - maybe a future optimization in case it should prove reasonable |
| 596 | // anyway the precondition here is that the FSM checks for rules to delete first and adds new rules afterwards |
Holger Hildebrandt | 47555e7 | 2020-09-21 11:07:24 +0000 | [diff] [blame] | 597 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 598 | if pConfigVlanStateBaseFsm.Is(VlanStConfigDone) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 599 | //have to re-trigger the FSM to proceed with outstanding incremental flow configuration |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 600 | if oFsm.ConfiguredUniFlow == 0 { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 601 | // this is a restart with a complete new flow, we can re-use the initial flow config control |
| 602 | // including the check, if the related techProfile is (still) available (probably also removed in between) |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 603 | //attention: take care to release the mutexFlowParams when calling the FSM directly - |
| 604 | // synchronous FSM 'event/state' functions may rely on this mutex |
| 605 | oFsm.mutexFlowParams.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 606 | if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvRenew); fsmErr != nil { |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 607 | logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!", |
| 608 | log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID}) |
| 609 | } |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 610 | } else { |
| 611 | //some further flows are to be configured |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 612 | //store the actual rule that shall be worked upon in the following transient states |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 613 | if len(oFsm.uniVlanFlowParamsSlice) < int(oFsm.ConfiguredUniFlow) { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 614 | //check introduced after having observed some panic here |
| 615 | logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm - inconsistent counter", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 616 | log.Fields{"ConfiguredUniFlow": oFsm.ConfiguredUniFlow, |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 617 | "sliceLen": len(oFsm.uniVlanFlowParamsSlice), "device-id": oFsm.deviceID}) |
| 618 | oFsm.mutexFlowParams.Unlock() |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 619 | err = fmt.Errorf("abort UniVlanConfigFsm on add due to internal counter mismatch %s", oFsm.deviceID) |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 620 | oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 621 | return err |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 622 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 623 | |
| 624 | oFsm.actualUniFlowParam = oFsm.uniVlanFlowParamsSlice[oFsm.ConfiguredUniFlow] |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 625 | //tpId of the next rule to be configured |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 626 | tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 627 | oFsm.TpIDWaitingFor = tpID |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 628 | loSetVlan := oFsm.actualUniFlowParam.VlanRuleParams.SetVid |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 629 | //attention: take care to release the mutexFlowParams when calling the FSM directly - |
| 630 | // synchronous FSM 'event/state' functions may rely on this mutex |
mpagenko | 45cc6a3 | 2021-07-23 10:06:57 +0000 | [diff] [blame] | 631 | // but it must be released already before calling getTechProfileDone() as it may already be locked |
| 632 | // by the techProfile processing call to VlanFsm.IsFlowRemovePending() (see VOL-4207) |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 633 | oFsm.mutexFlowParams.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 634 | loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.UniID, tpID) |
mpagenko | 45cc6a3 | 2021-07-23 10:06:57 +0000 | [diff] [blame] | 635 | logger.Debugw(ctx, "UniVlanConfigFsm - incremental config request (on setConfig)", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 636 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, |
mpagenko | 45cc6a3 | 2021-07-23 10:06:57 +0000 | [diff] [blame] | 637 | "set-Vlan": loSetVlan, "tp-id": tpID, "ProfDone": loTechProfDone}) |
| 638 | |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 639 | var fsmErr error |
| 640 | if loTechProfDone { |
| 641 | // let the vlan processing continue with next rule |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 642 | fsmErr = pConfigVlanStateBaseFsm.Event(VlanEvIncrFlowConfig) |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 643 | } else { |
| 644 | // set to waiting for Techprofile |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 645 | fsmErr = pConfigVlanStateBaseFsm.Event(VlanEvWaitTPIncr) |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 646 | } |
| 647 | if fsmErr != nil { |
| 648 | logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!", |
| 649 | log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID}) |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 650 | oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, fsmErr) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 651 | return fsmErr |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 652 | } |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 653 | } |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 654 | } else { |
| 655 | // if not in the appropriate state a new entry will be automatically considered later |
| 656 | // when the configDone state is reached |
| 657 | oFsm.mutexFlowParams.Unlock() |
| 658 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 659 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 660 | logger.Errorw(ctx, "UniVlanConfigFsm flow limit exceeded", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 661 | "device-id": oFsm.deviceID, "flow-number": oFsm.NumUniFlows}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 662 | oFsm.mutexFlowParams.Unlock() |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 663 | err = fmt.Errorf(" UniVlanConfigFsm flow limit exceeded %s", oFsm.deviceID) |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 664 | oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, err) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 665 | return err |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 666 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 667 | } else { |
| 668 | // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 669 | kvStoreWrite = true // ensure actual data write to kvStore immediately (no FSM activity) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 670 | // push response on response channel as there is nothing to be done for this flow |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 671 | oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, nil) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 672 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 673 | oFsm.mutexFlowParams.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 674 | if oFsm.NumUniFlows == oFsm.ConfiguredUniFlow { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 675 | //all requested rules really have been configured |
| 676 | // state transition notification is checked in deviceHandler |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 677 | oFsm.mutexFlowParams.RUnlock() |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 678 | if oFsm.pDeviceHandler != nil { |
| 679 | //also the related TechProfile was already configured |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 680 | logger.Debugw(ctx, "UniVlanConfigFsm rule already set - send immediate add-success event for reason update", log.Fields{ |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 681 | "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 682 | // success indication without the need to write to kvStore (done already below with updated data from StorePersUniFlowConfig()) |
| 683 | go oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetAddNoKvStore)) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 684 | } |
| 685 | } else { |
| 686 | // avoid device reason update as the rule config connected to this flow may still be in progress |
| 687 | // and the device reason should only be updated on success of rule config |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 688 | logger.Debugw(ctx, "UniVlanConfigFsm rule already set but configuration ongoing, suppress early add-success event for reason update", |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 689 | log.Fields{"device-id": oFsm.deviceID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 690 | "NumberofRules": oFsm.NumUniFlows, "Configured rules": oFsm.ConfiguredUniFlow}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 691 | oFsm.mutexFlowParams.RUnlock() |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 692 | } |
| 693 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 694 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 695 | if flowCookieModify { // some change was done to the flow entries |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 696 | //permanently store flow config for reconcile case |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 697 | oFsm.mutexFlowParams.RLock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 698 | if err := oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID, |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 699 | &oFsm.uniVlanFlowParamsSlice, kvStoreWrite); err != nil { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 700 | oFsm.mutexFlowParams.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 701 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 702 | return err |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 703 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 704 | oFsm.mutexFlowParams.RUnlock() |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 705 | } |
| 706 | return nil |
| 707 | } |
| 708 | |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 709 | func (oFsm *UniVlanConfigFsm) suspendAddRule(ctx context.Context, apRemoveFlowParams *uniRemoveVlanFlowParams) error { |
| 710 | oFsm.mutexFlowParams.Lock() |
| 711 | deleteChannel := apRemoveFlowParams.removeChannel |
| 712 | apRemoveFlowParams.isSuspendedOnAdd = true |
| 713 | oFsm.mutexFlowParams.Unlock() |
| 714 | |
| 715 | // isSuspendedOnAdd is not reset here-after as the assumption is, that after |
| 716 | select { |
| 717 | case success := <-deleteChannel: |
| 718 | //no need to reset isSuspendedOnAdd as in this case the removeElement will be deleted completely |
| 719 | if success { |
| 720 | logger.Infow(ctx, "resume adding this rule after having completed deletion", log.Fields{ |
| 721 | "device-id": oFsm.deviceID}) |
| 722 | return nil |
| 723 | } |
| 724 | return fmt.Errorf("suspend aborted, also aborting add-activity: %s", oFsm.deviceID) |
| 725 | case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): |
| 726 | oFsm.mutexFlowParams.Lock() |
| 727 | if apRemoveFlowParams != nil { |
| 728 | apRemoveFlowParams.isSuspendedOnAdd = false |
| 729 | } |
| 730 | oFsm.mutexFlowParams.Unlock() |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 731 | logger.Errorw(ctx, "timeout waiting for deletion of rule, also aborting add-activity", log.Fields{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 732 | "device-id": oFsm.deviceID}) |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 733 | return fmt.Errorf("suspend aborted on timeout, also aborting add-activity: %s", oFsm.deviceID) |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 734 | } |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 735 | } |
| 736 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 737 | // VOL-3828 flow config sequence workaround ########### start ########## |
| 738 | func (oFsm *UniVlanConfigFsm) delayNewRuleForCookie(ctx context.Context, aCookieSlice []uint64) uint64 { |
| 739 | //assumes mutexFlowParams.Lock() protection from caller! |
| 740 | if oFsm.delayNewRuleCookie == 0 && len(aCookieSlice) == 1 { |
| 741 | // if not already waiting, limitation for this workaround is to just have one overlapping cookie/rule |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 742 | // suspend check is done only if there is only one cookie in the request |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 743 | // background: more elements only expected in reconcile use case, where no conflicting sequence is to be expected |
| 744 | newCookie := aCookieSlice[0] |
| 745 | for _, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice { |
| 746 | for _, cookie := range storedUniFlowParams.CookieSlice { |
| 747 | if cookie == newCookie { |
| 748 | logger.Debugw(ctx, "UniVlanConfigFsm flow setting - new cookie still exists for some rule", log.Fields{ |
| 749 | "device-id": oFsm.deviceID, "cookie": cookie, "exists with SetVlan": storedUniFlowParams.VlanRuleParams.SetVid}) |
| 750 | oFsm.delayNewRuleCookie = newCookie |
| 751 | return newCookie //found new cookie in some existing rule |
| 752 | } |
| 753 | } // for all stored cookies of the actual inspected rule |
| 754 | } //for all rules |
| 755 | } |
| 756 | return 0 //no delay requested |
| 757 | } |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 758 | func (oFsm *UniVlanConfigFsm) suspendNewRule(ctx context.Context) bool { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 759 | oFsm.mutexFlowParams.RLock() |
| 760 | logger.Infow(ctx, "Need to suspend adding this rule as long as the cookie is still connected to some other rule", log.Fields{ |
| 761 | "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie}) |
| 762 | oFsm.mutexFlowParams.RUnlock() |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 763 | cookieDeleted := true //default assumption also for timeout (just try to continue as if removed) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 764 | select { |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 765 | case cookieDeleted = <-oFsm.chCookieDeleted: |
| 766 | logger.Infow(ctx, "resume adding this rule after having deleted cookie in some other rule or abort", log.Fields{ |
| 767 | "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie, "deleted": cookieDeleted}) |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 768 | case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 769 | logger.Errorw(ctx, "timeout waiting for deletion of cookie in some other rule, just try to continue", log.Fields{ |
| 770 | "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie}) |
| 771 | } |
| 772 | oFsm.mutexFlowParams.Lock() |
| 773 | oFsm.delayNewRuleCookie = 0 |
| 774 | oFsm.mutexFlowParams.Unlock() |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 775 | return cookieDeleted |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 776 | } |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 777 | func (oFsm *UniVlanConfigFsm) suspendIfRequiredNewRule(ctx context.Context, aCookieSlice []uint64) (uint64, bool) { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 778 | oFsm.mutexFlowParams.Lock() |
| 779 | delayedCookie := oFsm.delayNewRuleForCookie(ctx, aCookieSlice) |
| 780 | oFsm.mutexFlowParams.Unlock() |
| 781 | |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 782 | deleteSuccess := true |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 783 | if delayedCookie != 0 { |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 784 | deleteSuccess = oFsm.suspendNewRule(ctx) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 785 | } |
mpagenko | bc4170a | 2021-08-17 16:42:10 +0000 | [diff] [blame] | 786 | return delayedCookie, deleteSuccess |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 787 | } |
| 788 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 789 | // returns flowModified, RuleAppendRequest |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 790 | func (oFsm *UniVlanConfigFsm) reviseFlowConstellation(ctx context.Context, aCookie uint64, aUniVlanRuleParams cmn.UniVlanRuleParams) (bool, bool) { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 791 | flowEntryMatch := false |
| 792 | oFsm.mutexFlowParams.Lock() |
| 793 | defer oFsm.mutexFlowParams.Unlock() |
| 794 | for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice { |
| 795 | if storedUniFlowParams.VlanRuleParams == aUniVlanRuleParams { |
| 796 | flowEntryMatch = true |
| 797 | logger.Debugw(ctx, "UniVlanConfigFsm flow revise - rule already exists", log.Fields{ |
| 798 | "device-id": oFsm.deviceID}) |
| 799 | cookieMatch := false |
| 800 | for _, cookie := range storedUniFlowParams.CookieSlice { |
| 801 | if cookie == aCookie { |
| 802 | logger.Debugw(ctx, "UniVlanConfigFsm flow revise - and cookie already exists", log.Fields{ |
| 803 | "device-id": oFsm.deviceID, "cookie": cookie}) |
| 804 | cookieMatch = true |
| 805 | break //found new cookie - no further search for this requested cookie |
| 806 | } |
| 807 | } |
| 808 | if !cookieMatch { |
| 809 | logger.Debugw(ctx, "UniVlanConfigFsm flow revise -adding new cookie", log.Fields{ |
| 810 | "device-id": oFsm.deviceID, "cookie": aCookie}) |
| 811 | //as range works with copies of the slice we have to write to the original slice!! |
| 812 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append(oFsm.uniVlanFlowParamsSlice[flow].CookieSlice, |
| 813 | aCookie) |
| 814 | return true, false //flowModified, NoRuleAppend |
| 815 | } |
| 816 | break // found rule - no further rule search |
| 817 | } |
| 818 | } |
| 819 | if !flowEntryMatch { //it is a new rule |
| 820 | return true, true //flowModified, RuleAppend |
| 821 | } |
| 822 | return false, false //flowNotModified, NoRuleAppend |
| 823 | } |
| 824 | |
| 825 | // VOL-3828 flow config sequence workaround ########### end ########## |
| 826 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 827 | // RemoveUniFlowParams verifies on existence of flow cookie, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 828 | // if found removes cookie from flow cookie list and if this is empty |
| 829 | // initiates removal of the flow related configuration from the ONU (via OMCI) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 830 | func (oFsm *UniVlanConfigFsm) RemoveUniFlowParams(ctx context.Context, aCookie uint64, respChan *chan error) error { |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 831 | if oFsm == nil { |
| 832 | logger.Error(ctx, "no valid UniVlanConfigFsm!") |
| 833 | return fmt.Errorf("no-valid-UniVlanConfigFsm") |
| 834 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 835 | var deletedCookie uint64 |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 836 | flowCookieMatch := false |
| 837 | //mutex protection is required for possible concurrent access to FSM members |
| 838 | oFsm.mutexFlowParams.Lock() |
| 839 | defer oFsm.mutexFlowParams.Unlock() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 840 | remove_loop: |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 841 | for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice { |
| 842 | for i, cookie := range storedUniFlowParams.CookieSlice { |
| 843 | if cookie == aCookie { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 844 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal - cookie found", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 845 | "device-id": oFsm.deviceID, "cookie": cookie}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 846 | deletedCookie = aCookie |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 847 | //remove the cookie from the cookie slice and verify it is getting empty |
| 848 | if len(storedUniFlowParams.CookieSlice) == 1 { |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 849 | // had to shift content to function due to sca complexity |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 850 | flowCookieMatch = oFsm.removeRuleComplete(ctx, storedUniFlowParams, aCookie, respChan) |
mpagenko | dee02a6 | 2021-07-21 10:56:10 +0000 | [diff] [blame] | 851 | //persistencyData write is now part of removeRuleComplete() (on success) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 852 | } else { |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 853 | flowCookieMatch = true |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 854 | //cut off the requested cookie by slicing out this element |
| 855 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = append( |
| 856 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[:i], |
| 857 | oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[i+1:]...) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 858 | // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately |
| 859 | // state transition notification is checked in deviceHandler |
| 860 | if oFsm.pDeviceHandler != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 861 | // success indication without the need to write to kvStore (done already below with updated data from StorePersUniFlowConfig()) |
| 862 | go oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetRemoveNoKvStore)) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 863 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 864 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal - rule persists with still valid cookies", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 865 | "device-id": oFsm.deviceID, "cookies": oFsm.uniVlanFlowParamsSlice[flow].CookieSlice}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 866 | if deletedCookie == oFsm.delayNewRuleCookie { |
| 867 | //the delayedNewCookie is the one that is currently deleted, but the rule still exist with other cookies |
| 868 | //as long as there are further cookies for this rule indicate there is still some cookie to be deleted |
| 869 | //simply use the first one |
| 870 | oFsm.delayNewRuleCookie = oFsm.uniVlanFlowParamsSlice[flow].CookieSlice[0] |
| 871 | logger.Debugw(ctx, "UniVlanConfigFsm remaining cookie awaited for deletion before new rule add", log.Fields{ |
| 872 | "device-id": oFsm.deviceID, "cookie": oFsm.delayNewRuleCookie}) |
| 873 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 874 | // Push response on the response channel |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 875 | oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, nil) |
mpagenko | dee02a6 | 2021-07-21 10:56:10 +0000 | [diff] [blame] | 876 | //permanently store the modified flow config for reconcile case and immediately write to KvStore |
| 877 | if oFsm.pDeviceHandler != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 878 | if err := oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID, |
mpagenko | dee02a6 | 2021-07-21 10:56:10 +0000 | [diff] [blame] | 879 | &oFsm.uniVlanFlowParamsSlice, true); err != nil { |
| 880 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID}) |
| 881 | return err |
| 882 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 883 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 884 | } |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 885 | break remove_loop //found the cookie - no further search for this requested cookie |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 886 | } |
| 887 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 888 | } //search all flows |
| 889 | if !flowCookieMatch { //some cookie remove-request for a cookie that does not exist in the FSM data |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 890 | logger.Warnw(ctx, "UniVlanConfigFsm flow removal - remove-cookie not found", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 891 | "device-id": oFsm.deviceID, "remove-cookie": aCookie}) |
| 892 | // but accept the request with success as no such cookie (flow) does exist |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 893 | // no activity within the FSM for OMCI processing, the deviceReason may be updated immediately |
| 894 | // state transition notification is checked in deviceHandler |
| 895 | if oFsm.pDeviceHandler != nil { |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 896 | // success indication without the need to write to kvStore (no change) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 897 | go oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent(oFsm.requestEvent+cDeviceEventOffsetRemoveNoKvStore)) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 898 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 899 | // Push response on the response channel |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 900 | oFsm.pushReponseOnFlowResponseChannel(ctx, respChan, nil) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 901 | return nil |
| 902 | } //unknown cookie |
| 903 | |
| 904 | return nil |
| 905 | } |
| 906 | |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 907 | // removeRuleComplete initiates the complete removal of a VLAN rule (from single cookie element) |
mpagenko | dee02a6 | 2021-07-21 10:56:10 +0000 | [diff] [blame] | 908 | // requires mutexFlowParams to be locked at call |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 909 | func (oFsm *UniVlanConfigFsm) removeRuleComplete(ctx context.Context, |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 910 | aUniFlowParams cmn.UniVlanFlowParams, aCookie uint64, respChan *chan error) bool { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 911 | pConfigVlanStateBaseFsm := oFsm.PAdaptFsm.PFsm |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 912 | var cancelPendingConfig bool = false |
| 913 | var loRemoveParams uniRemoveVlanFlowParams = uniRemoveVlanFlowParams{} |
| 914 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal - full flow removal", log.Fields{ |
| 915 | "device-id": oFsm.deviceID}) |
| 916 | //rwCore flow recovery may be the reason for this delete, in which case the flowToBeDeleted may be the same |
| 917 | // as the one still waiting in the FSM as toAdd but waiting for TechProfileConfig |
| 918 | // so we have to check if we have to abort the outstanding AddRequest and regard the current DelRequest as done |
| 919 | // if the Fsm is in some other transient (config) state, we will reach the DelRequest later and correctly process it then |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 920 | if pConfigVlanStateBaseFsm.Is(VlanStWaitingTechProf) { |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 921 | logger.Debugw(ctx, "UniVlanConfigFsm was waiting for TechProf config with add-request, just aborting the outstanding add", |
| 922 | log.Fields{"device-id": oFsm.deviceID}) |
| 923 | cancelPendingConfig = true |
| 924 | } else { |
| 925 | //create a new element for the removeVlanFlow slice |
| 926 | loRemoveParams = uniRemoveVlanFlowParams{ |
| 927 | vlanRuleParams: aUniFlowParams.VlanRuleParams, |
| 928 | cookie: aCookie, |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 929 | respChan: respChan, |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 930 | } |
| 931 | loRemoveParams.removeChannel = make(chan bool) |
| 932 | oFsm.uniRemoveFlowsSlice = append(oFsm.uniRemoveFlowsSlice, loRemoveParams) |
| 933 | } |
| 934 | |
| 935 | usedTpID := aUniFlowParams.VlanRuleParams.TpID |
| 936 | if len(oFsm.uniVlanFlowParamsSlice) <= 1 { |
| 937 | //at this point it is evident that no flow anymore will refer to a still possibly active Techprofile |
| 938 | //request that this profile gets deleted before a new flow add is allowed (except for some aborted add) |
| 939 | if !cancelPendingConfig { |
mpagenko | 3ce9fa0 | 2021-07-28 13:26:54 +0000 | [diff] [blame] | 940 | // ensure mutexFlowParams not locked before calling some TPProcessing activity (that might already be pending on it) |
| 941 | oFsm.mutexFlowParams.Unlock() |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 942 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal requested - set TechProfile to-delete", log.Fields{ |
| 943 | "device-id": oFsm.deviceID}) |
| 944 | if oFsm.pUniTechProf != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 945 | oFsm.pUniTechProf.SetProfileToDelete(oFsm.pOnuUniPort.UniID, usedTpID, true) |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 946 | } |
mpagenko | 3ce9fa0 | 2021-07-28 13:26:54 +0000 | [diff] [blame] | 947 | oFsm.mutexFlowParams.Lock() |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 948 | } |
| 949 | } else { |
| 950 | if !cancelPendingConfig { |
| 951 | oFsm.updateTechProfileToDelete(ctx, usedTpID) |
| 952 | } |
| 953 | } |
| 954 | //trigger the FSM to remove the relevant rule |
| 955 | if cancelPendingConfig { |
| 956 | //as the uniFlow parameters are already stored (for add) but no explicit removal is done anymore |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 957 | // the paramSlice has to be updated with rule-removal, which also then updates NumUniFlows |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 958 | //call from 'non-configured' state of the rules |
| 959 | if err := oFsm.removeFlowFromParamsSlice(ctx, aCookie, false); err != nil { |
| 960 | //something quite inconsistent detected, perhaps just try to recover with FSM reset |
| 961 | oFsm.mutexFlowParams.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 962 | if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvReset); fsmErr != nil { |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 963 | logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!", |
| 964 | log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID}) |
| 965 | } |
| 966 | return false //data base update could not be done, return like cookie not found |
| 967 | } |
| 968 | |
| 969 | oFsm.requestEventOffset = uint8(cDeviceEventOffsetRemoveWithKvStore) //offset for last flow-remove activity (with kvStore request) |
| 970 | //attention: take care to release and re-take the mutexFlowParams when calling the FSM directly - |
| 971 | // synchronous FSM 'event/state' functions may rely on this mutex |
| 972 | oFsm.mutexFlowParams.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 973 | if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvCancelOutstandingConfig); fsmErr != nil { |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 974 | logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!", |
| 975 | log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID}) |
| 976 | } |
| 977 | oFsm.mutexFlowParams.Lock() |
| 978 | return true |
| 979 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 980 | if pConfigVlanStateBaseFsm.Is(VlanStConfigDone) { |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 981 | logger.Debugw(ctx, "UniVlanConfigFsm rule removal request", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 982 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 983 | "tp-id": loRemoveParams.vlanRuleParams.TpID, |
| 984 | "set-Vlan": loRemoveParams.vlanRuleParams.SetVid}) |
| 985 | //have to re-trigger the FSM to proceed with outstanding incremental flow configuration |
| 986 | //attention: take care to release and re-take the mutexFlowParams when calling the FSM directly - |
| 987 | // synchronous FSM 'event/state' functions may rely on this mutex |
| 988 | oFsm.mutexFlowParams.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 989 | if fsmErr := pConfigVlanStateBaseFsm.Event(VlanEvRemFlowConfig); fsmErr != nil { |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 990 | logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm!", |
| 991 | log.Fields{"fsmState": pConfigVlanStateBaseFsm.Current(), "error": fsmErr, "device-id": oFsm.deviceID}) |
| 992 | } |
| 993 | oFsm.mutexFlowParams.Lock() |
| 994 | } // if not in the appropriate state a new entry will be automatically considered later |
| 995 | // when the configDone state is reached |
| 996 | return true |
| 997 | } |
| 998 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 999 | // removeFlowFromParamsSlice removes a flow from stored uniVlanFlowParamsSlice based on the cookie |
| 1000 | // |
| 1001 | // it assumes that adding cookies for this flow (including the actual one to delete) was prevented |
| 1002 | // from the start of the deletion request to avoid to much interference |
| 1003 | // so when called, there can only be one cookie active for this flow |
| 1004 | // |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1005 | // requires mutexFlowParams to be locked at call |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 1006 | func (oFsm *UniVlanConfigFsm) removeFlowFromParamsSlice(ctx context.Context, aCookie uint64, aWasConfigured bool) error { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1007 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal from ParamsSlice", log.Fields{ |
| 1008 | "device-id": oFsm.deviceID, "cookie": aCookie}) |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 1009 | cookieFound := false |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1010 | removeFromSlice_loop: |
| 1011 | for flow, storedUniFlowParams := range oFsm.uniVlanFlowParamsSlice { |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 1012 | // if UniFlowParams exists, cookieSlice should always have at least one element |
| 1013 | cookieSliceLen := len(storedUniFlowParams.CookieSlice) |
| 1014 | if cookieSliceLen == 1 { |
| 1015 | if storedUniFlowParams.CookieSlice[0] == aCookie { |
| 1016 | cookieFound = true |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1017 | } |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 1018 | } else if cookieSliceLen == 0 { |
| 1019 | errStr := "UniVlanConfigFsm unexpected cookie slice length 0 - removal in uniVlanFlowParamsSlice aborted" |
| 1020 | logger.Errorw(ctx, errStr, log.Fields{"device-id": oFsm.deviceID}) |
| 1021 | return errors.New(errStr) |
| 1022 | } else { |
| 1023 | errStr := "UniVlanConfigFsm flow removal unexpected cookie slice length, but rule removal continued" |
| 1024 | logger.Errorw(ctx, errStr, log.Fields{ |
| 1025 | "cookieSliceLen": len(oFsm.uniVlanFlowParamsSlice), "device-id": oFsm.deviceID}) |
| 1026 | for _, cookie := range storedUniFlowParams.CookieSlice { |
| 1027 | if cookie == aCookie { |
| 1028 | cookieFound = true |
| 1029 | break |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | if cookieFound { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1034 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal from ParamsSlice - cookie found", log.Fields{ |
| 1035 | "device-id": oFsm.deviceID, "cookie": aCookie}) |
| 1036 | //remove the actual element from the addVlanFlow slice |
| 1037 | // oFsm.uniVlanFlowParamsSlice[flow].CookieSlice = nil //automatically done by garbage collector |
| 1038 | if len(oFsm.uniVlanFlowParamsSlice) <= 1 { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1039 | oFsm.NumUniFlows = 0 //no more flows |
| 1040 | oFsm.ConfiguredUniFlow = 0 //no more flows configured |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1041 | oFsm.uniVlanFlowParamsSlice = nil //reset the slice |
| 1042 | //at this point it is evident that no flow anymore refers to a still possibly active Techprofile |
| 1043 | //request that this profile gets deleted before a new flow add is allowed |
| 1044 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal from ParamsSlice - no more flows", log.Fields{ |
| 1045 | "device-id": oFsm.deviceID}) |
| 1046 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1047 | oFsm.NumUniFlows-- |
| 1048 | if aWasConfigured && oFsm.ConfiguredUniFlow > 0 { |
| 1049 | oFsm.ConfiguredUniFlow-- |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1050 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1051 | if !aWasConfigured { |
| 1052 | // We did not actually process this flow but was removed before that. |
| 1053 | // Indicate success response for the flow to caller who is blocking on a response |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 1054 | oFsm.pushReponseOnFlowResponseChannel(ctx, storedUniFlowParams.RespChan, nil) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1057 | //cut off the requested flow by slicing out this element |
| 1058 | oFsm.uniVlanFlowParamsSlice = append( |
| 1059 | oFsm.uniVlanFlowParamsSlice[:flow], oFsm.uniVlanFlowParamsSlice[flow+1:]...) |
| 1060 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal - specific flow removed from data", log.Fields{ |
| 1061 | "device-id": oFsm.deviceID}) |
| 1062 | } |
| 1063 | break removeFromSlice_loop //found the cookie - no further search for this requested cookie |
| 1064 | } |
| 1065 | } //search all flows |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 1066 | if !cookieFound { |
| 1067 | errStr := "UniVlanConfigFsm cookie for removal not found, internal counter not updated" |
| 1068 | logger.Errorw(ctx, errStr, log.Fields{"device-id": oFsm.deviceID}) |
| 1069 | return errors.New(errStr) |
| 1070 | } |
mpagenko | dee02a6 | 2021-07-21 10:56:10 +0000 | [diff] [blame] | 1071 | //if the cookie was found and removed from uniVlanFlowParamsSlice above now write the modified persistency data |
| 1072 | // KVStore update will be done after reaching the requested FSM end state (not immediately here) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1073 | if err := oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID, |
mpagenko | dee02a6 | 2021-07-21 10:56:10 +0000 | [diff] [blame] | 1074 | &oFsm.uniVlanFlowParamsSlice, false); err != nil { |
| 1075 | logger.Errorw(ctx, err.Error(), log.Fields{"device-id": oFsm.deviceID}) |
| 1076 | return err |
| 1077 | } |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 1078 | return nil |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | // requires mutexFlowParams to be locked at call |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1082 | func (oFsm *UniVlanConfigFsm) updateTechProfileToDelete(ctx context.Context, usedTpID uint8) { |
| 1083 | //here we have to check, if there are still other flows referencing to the actual ProfileId |
| 1084 | // before we can request that this profile gets deleted before a new flow add is allowed |
| 1085 | tpIDInOtherFlows := false |
| 1086 | for _, tpUniFlowParams := range oFsm.uniVlanFlowParamsSlice { |
| 1087 | if tpUniFlowParams.VlanRuleParams.TpID == usedTpID { |
| 1088 | tpIDInOtherFlows = true |
| 1089 | break // search loop can be left |
| 1090 | } |
| 1091 | } |
| 1092 | if tpIDInOtherFlows { |
| 1093 | logger.Debugw(ctx, "UniVlanConfigFsm tp-id used in deleted flow is still used in other flows", log.Fields{ |
| 1094 | "device-id": oFsm.deviceID, "tp-id": usedTpID}) |
| 1095 | } else { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1096 | logger.Debugw(ctx, "UniVlanConfigFsm tp-id used in deleted flow is not used anymore - set TechProfile to-delete", log.Fields{ |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1097 | "device-id": oFsm.deviceID, "tp-id": usedTpID}) |
mpagenko | 3ce9fa0 | 2021-07-28 13:26:54 +0000 | [diff] [blame] | 1098 | // ensure mutexFlowParams not locked before calling some TPProcessing activity (that might already be pending on it) |
| 1099 | oFsm.mutexFlowParams.Unlock() |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1100 | if oFsm.pUniTechProf != nil { |
| 1101 | //request that this profile gets deleted before a new flow add is allowed |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1102 | oFsm.pUniTechProf.SetProfileToDelete(oFsm.pOnuUniPort.UniID, usedTpID, true) |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1103 | } |
mpagenko | 3ce9fa0 | 2021-07-28 13:26:54 +0000 | [diff] [blame] | 1104 | oFsm.mutexFlowParams.Lock() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1108 | func (oFsm *UniVlanConfigFsm) enterPreparing(ctx context.Context, e *fsm.Event) { |
| 1109 | logger.Debugw(ctx, "UniVlanConfigFsm preparing", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1110 | |
| 1111 | // this FSM is not intended for re-start, needs always new creation for a new run |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1112 | // (self-destroying - compare enterDisabled()) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1113 | oFsm.omciMIdsResponseReceived = make(chan bool) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1114 | oFsm.chCookieDeleted = make(chan bool) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1115 | // start go routine for processing of LockState messages |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1116 | go oFsm.processOmciVlanMessages(ctx) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1117 | //let the state machine run forward from here directly |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1118 | pConfigVlanStateAFsm := oFsm.PAdaptFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1119 | if pConfigVlanStateAFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1120 | if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1121 | logger.Debugw(ctx, "reconciling - skip omci-config of vlan rule", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1122 | log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID}) |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1123 | // Can't call FSM Event directly, decoupling it |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1124 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1125 | _ = a_pAFsm.PFsm.Event(VlanEvSkipOmciConfig) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1126 | }(pConfigVlanStateAFsm) |
| 1127 | return |
| 1128 | } |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1129 | // Can't call FSM Event directly, decoupling it |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1130 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1131 | _ = a_pAFsm.PFsm.Event(VlanEvPrepareDone) |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1132 | }(pConfigVlanStateAFsm) |
| 1133 | return |
| 1134 | } |
| 1135 | logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{ |
| 1136 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 1137 | //should never happen, else: recovery would be needed from outside the FSM |
| 1138 | } |
| 1139 | |
| 1140 | func (oFsm *UniVlanConfigFsm) enterConfigStarting(ctx context.Context, e *fsm.Event) { |
| 1141 | logger.Debugw(ctx, "UniVlanConfigFsm start vlan configuration", log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1142 | pConfigVlanStateAFsm := oFsm.PAdaptFsm |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1143 | if pConfigVlanStateAFsm != nil { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1144 | oFsm.mutexFlowParams.Lock() |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1145 | //possibly the entry is not valid anymore based on intermediate delete requests |
| 1146 | //just a basic protection ... |
| 1147 | if len(oFsm.uniVlanFlowParamsSlice) == 0 { |
| 1148 | oFsm.mutexFlowParams.Unlock() |
| 1149 | logger.Debugw(ctx, "UniVlanConfigFsm start: no rule entry anymore available", log.Fields{ |
| 1150 | "device-id": oFsm.deviceID}) |
| 1151 | // Can't call FSM Event directly, decoupling it |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1152 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1153 | _ = a_pAFsm.PFsm.Event(VlanEvReset) |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1154 | }(pConfigVlanStateAFsm) |
| 1155 | return |
| 1156 | } |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1157 | //access to uniVlanFlowParamsSlice is done on first element only here per definition |
| 1158 | //store the actual rule that shall be worked upon in the following transient states |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1159 | oFsm.actualUniFlowParam = oFsm.uniVlanFlowParamsSlice[0] |
| 1160 | tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1161 | oFsm.TpIDWaitingFor = tpID |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1162 | loSetVlan := oFsm.actualUniFlowParam.VlanRuleParams.SetVid |
mpagenko | 45cc6a3 | 2021-07-23 10:06:57 +0000 | [diff] [blame] | 1163 | //attention: take care to release the mutexFlowParams when calling the FSM directly - |
| 1164 | // synchronous FSM 'event/state' functions may rely on this mutex |
| 1165 | // but it must be released already before calling getTechProfileDone() as it may already be locked |
| 1166 | // by the techProfile processing call to VlanFsm.IsFlowRemovePending() (see VOL-4207) |
Girish Gowdra | 24dd113 | 2021-07-06 15:25:40 -0700 | [diff] [blame] | 1167 | oFsm.mutexFlowParams.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1168 | loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.UniID, uint8(tpID)) |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1169 | logger.Debugw(ctx, "UniVlanConfigFsm - start with first rule", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1170 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, |
mpagenko | 45cc6a3 | 2021-07-23 10:06:57 +0000 | [diff] [blame] | 1171 | "set-Vlan": loSetVlan, "tp-id": tpID, "ProfDone": loTechProfDone}) |
Girish Gowdra | 24dd113 | 2021-07-06 15:25:40 -0700 | [diff] [blame] | 1172 | |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1173 | // Can't call FSM Event directly, decoupling it |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1174 | go func(aPAFsm *cmn.AdapterFsm, aTechProfDone bool) { |
| 1175 | if aPAFsm != nil && aPAFsm.PFsm != nil { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1176 | if aTechProfDone { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1177 | // let the vlan processing begin |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1178 | _ = aPAFsm.PFsm.Event(VlanEvStartConfig) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1179 | } else { |
| 1180 | // set to waiting for Techprofile |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1181 | _ = aPAFsm.PFsm.Event(VlanEvWaitTechProf) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1182 | } |
| 1183 | } |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1184 | }(pConfigVlanStateAFsm, loTechProfDone) |
| 1185 | } else { |
| 1186 | logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{ |
| 1187 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 1188 | //should never happen, else: recovery would be needed from outside the FSM |
| 1189 | return |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1190 | } |
| 1191 | } |
| 1192 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1193 | func (oFsm *UniVlanConfigFsm) enterConfigVtfd(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1194 | //mutex protection is required for possible concurrent access to FSM members |
| 1195 | oFsm.mutexFlowParams.Lock() |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1196 | oFsm.TpIDWaitingFor = 0 //reset indication to avoid misinterpretation |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1197 | if oFsm.actualUniFlowParam.VlanRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1198 | // meaning transparent setup - no specific VTFD setting required |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1199 | oFsm.mutexFlowParams.Unlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1200 | logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD config required", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1201 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1202 | // let the FSM proceed ... (from within this state all internal pointers may be expected to be correct) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1203 | pConfigVlanStateAFsm := oFsm.PAdaptFsm |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1204 | // Can't call FSM Event directly, decoupling it |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1205 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1206 | _ = a_pAFsm.PFsm.Event(VlanEvRxConfigVtfd) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1207 | }(pConfigVlanStateAFsm) |
| 1208 | } else { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1209 | // This attribute uniquely identifies each instance of this managed entity. Through an identical ID, |
| 1210 | // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME. |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1211 | vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.actualUniFlowParam.VlanRuleParams.TpID)) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1212 | logger.Debugw(ctx, "UniVlanConfigFsm create VTFD", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1213 | "EntitytId": strconv.FormatInt(int64(vtfdID), 16), |
Mahir Gunyel | 6781f96 | 2021-05-16 23:30:08 -0700 | [diff] [blame] | 1214 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID, |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1215 | "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": oFsm.actualUniFlowParam.VlanRuleParams.TpID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1216 | // setVid is assumed to be masked already by the caller to 12 bit |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1217 | oFsm.vlanFilterList[0] = uint16(oFsm.actualUniFlowParam.VlanRuleParams.SetVid) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1218 | oFsm.mutexFlowParams.Unlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1219 | vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1220 | vtfdFilterList[0] = oFsm.vlanFilterList[0] |
| 1221 | oFsm.numVlanFilterEntries = 1 |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1222 | meParams := me.ParamData{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1223 | EntityID: vtfdID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1224 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 1225 | me.VlanTaggingFilterData_VlanFilterList: vtfdFilterList, //omci lib wants a slice for serialization |
| 1226 | me.VlanTaggingFilterData_ForwardOperation: uint8(0x10), //VID investigation |
| 1227 | me.VlanTaggingFilterData_NumberOfEntries: oFsm.numVlanFilterEntries, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1228 | }, |
| 1229 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1230 | logger.Debugw(ctx, "UniVlanConfigFsm sendcreate VTFD", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1231 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1232 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1233 | meInstance, err := oFsm.pOmciCC.SendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 1234 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1235 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1236 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1237 | logger.Errorw(ctx, "VTFD create failed, aborting UniVlanConfig FSM!", |
| 1238 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1239 | pConfigVlanStateAFsm := oFsm.PAdaptFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1240 | if pConfigVlanStateAFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1241 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1242 | _ = a_pAFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1243 | }(pConfigVlanStateAFsm) |
| 1244 | } |
| 1245 | return |
| 1246 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1247 | //accept also nil as (error) return value for writing to LastTx |
| 1248 | // - this avoids misinterpretation of new received OMCI messages |
| 1249 | //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]: |
| 1250 | // send shall return (dual format) error code that can be used here for immediate error treatment |
| 1251 | // (relevant to all used sendXX() methods in this (and other) FSM's) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1252 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1253 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1254 | } |
| 1255 | } |
| 1256 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1257 | func (oFsm *UniVlanConfigFsm) enterConfigEvtocd(ctx context.Context, e *fsm.Event) { |
| 1258 | logger.Debugw(ctx, "UniVlanConfigFsm - start config EVTOCD loop", log.Fields{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1259 | "device-id": oFsm.deviceID}) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1260 | oFsm.requestEventOffset = uint8(cDeviceEventOffsetAddWithKvStore) //0 offset for last flow-add activity |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1261 | go func() { |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1262 | //using the first element in the slice because it's the first flow per definition here |
| 1263 | errEvto := oFsm.performConfigEvtocdEntries(ctx, 0) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1264 | //This is correct passing scenario |
| 1265 | if errEvto == nil { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1266 | oFsm.mutexFlowParams.RLock() |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1267 | tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID |
| 1268 | vlanID := oFsm.actualUniFlowParam.VlanRuleParams.SetVid |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1269 | configuredUniFlows := oFsm.ConfiguredUniFlow |
mpagenko | 3ce9fa0 | 2021-07-28 13:26:54 +0000 | [diff] [blame] | 1270 | // ensure mutexFlowParams not locked before calling some TPProcessing activity (that might already be pending on it) |
| 1271 | oFsm.mutexFlowParams.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1272 | for _, gemPort := range oFsm.pUniTechProf.getMulticastGemPorts(ctx, oFsm.pOnuUniPort.UniID, uint8(tpID)) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1273 | logger.Infow(ctx, "Setting multicast MEs, with first flow", log.Fields{"deviceID": oFsm.deviceID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1274 | "techProfile": tpID, "gemPort": gemPort, "vlanID": vlanID, "ConfiguredUniFlow": configuredUniFlows}) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1275 | errCreateAllMulticastME := oFsm.performSettingMulticastME(ctx, tpID, gemPort, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1276 | vlanID) |
| 1277 | if errCreateAllMulticastME != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1278 | logger.Errorw(ctx, "Multicast ME create failed, aborting AniConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1279 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1280 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1281 | } |
| 1282 | } |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 1283 | //If this first flow contains a meter, then create TD for related gems. |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1284 | if oFsm.actualUniFlowParam.Meter != nil { |
| 1285 | logger.Debugw(ctx, "Creating Traffic Descriptor", log.Fields{"device-id": oFsm.deviceID, "meter": oFsm.actualUniFlowParam.Meter}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1286 | for _, gemPort := range oFsm.pUniTechProf.getBidirectionalGemPortIDsForTP(ctx, oFsm.pOnuUniPort.UniID, tpID) { |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1287 | logger.Debugw(ctx, "Creating Traffic Descriptor for gem", log.Fields{"device-id": oFsm.deviceID, "meter": oFsm.actualUniFlowParam.Meter, "gem": gemPort}) |
| 1288 | errCreateTrafficDescriptor := oFsm.createTrafficDescriptor(ctx, oFsm.actualUniFlowParam.Meter, tpID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1289 | oFsm.pOnuUniPort.UniID, gemPort) |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 1290 | if errCreateTrafficDescriptor != nil { |
| 1291 | logger.Errorw(ctx, "Create Traffic Descriptor create failed, aborting Ani Config FSM!", |
| 1292 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1293 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 1294 | } |
| 1295 | } |
| 1296 | } |
| 1297 | |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1298 | //TODO Possibly insert new state for multicast --> possibly another jira/later time. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1299 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvRxConfigEvtocd) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1300 | } |
| 1301 | }() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1304 | func (oFsm *UniVlanConfigFsm) enterVlanConfigDone(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1305 | |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1306 | oFsm.mutexFlowParams.Lock() |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1307 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1308 | logger.Infow(ctx, "UniVlanConfigFsm config done - checking on more flows", log.Fields{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1309 | "device-id": oFsm.deviceID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1310 | "overall-uni-rules": oFsm.NumUniFlows, "configured-uni-rules": oFsm.ConfiguredUniFlow}) |
mpagenko | 101ac94 | 2021-11-16 15:01:29 +0000 | [diff] [blame] | 1311 | if len(oFsm.uniVlanFlowParamsSlice) > 0 && !oFsm.pDeviceHandler.IsReconciling() { |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 1312 | oFsm.pushReponseOnFlowResponseChannel(ctx, oFsm.actualUniFlowParam.RespChan, nil) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1315 | pConfigVlanStateAFsm := oFsm.PAdaptFsm |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1316 | if pConfigVlanStateAFsm == nil { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1317 | oFsm.mutexFlowParams.Unlock() |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1318 | logger.Errorw(ctx, "UniVlanConfigFsm abort: invalid FSM pointer", log.Fields{ |
| 1319 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 1320 | //should never happen, else: recovery would be needed from outside the FSM |
| 1321 | return |
| 1322 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1323 | pConfigVlanStateBaseFsm := pConfigVlanStateAFsm.PFsm |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1324 | if len(oFsm.uniRemoveFlowsSlice) > 0 { |
| 1325 | //some further flows are to be removed, removal always starts with the first element |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1326 | logger.Debugw(ctx, "UniVlanConfigFsm rule removal from ConfigDone", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1327 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1328 | "tp-id": oFsm.uniRemoveFlowsSlice[0].vlanRuleParams.TpID, |
| 1329 | "set-Vlan": oFsm.uniRemoveFlowsSlice[0].vlanRuleParams.SetVid}) |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1330 | oFsm.mutexFlowParams.Unlock() |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1331 | // Can't call FSM Event directly, decoupling it |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1332 | go func(a_pBaseFsm *fsm.FSM) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1333 | _ = a_pBaseFsm.Event(VlanEvRemFlowConfig) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1334 | }(pConfigVlanStateBaseFsm) |
| 1335 | return |
| 1336 | } |
Holger Hildebrandt | 7741f27 | 2022-01-18 08:17:39 +0000 | [diff] [blame] | 1337 | if oFsm.lastFlowToReconcile { |
| 1338 | //note: lastFlowToReconcile does not mean that this block may run only once within reconcilement here, |
| 1339 | // due to asynchronous event processing from SetUniFlowParams() it may be executed multiple times |
| 1340 | logger.Debugw(ctx, "reconciling - flow processing finished", log.Fields{ |
| 1341 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID}) |
| 1342 | oFsm.pDeviceHandler.SendChUniVlanConfigFinished(uint16(oFsm.pOnuUniPort.UniID)) |
| 1343 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1344 | if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() { |
| 1345 | oFsm.ConfiguredUniFlow = oFsm.NumUniFlows |
Holger Hildebrandt | 1b8f4ad | 2021-03-25 15:53:51 +0000 | [diff] [blame] | 1346 | logger.Debugw(ctx, "reconciling - skip enterVlanConfigDone processing", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1347 | log.Fields{"NumUniFlows": oFsm.NumUniFlows, "ConfiguredUniFlow": oFsm.ConfiguredUniFlow, "device-id": oFsm.deviceID}) |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1348 | oFsm.mutexFlowParams.Unlock() |
Holger Hildebrandt | 1b8f4ad | 2021-03-25 15:53:51 +0000 | [diff] [blame] | 1349 | return |
| 1350 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1351 | if oFsm.NumUniFlows > oFsm.ConfiguredUniFlow { |
| 1352 | if oFsm.ConfiguredUniFlow == 0 { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1353 | oFsm.mutexFlowParams.Unlock() |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1354 | // this is a restart with a complete new flow, we can re-use the initial flow config control |
| 1355 | // including the check, if the related techProfile is (still) available (probably also removed in between) |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1356 | // Can't call FSM Event directly, decoupling it |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1357 | go func(a_pBaseFsm *fsm.FSM) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1358 | _ = a_pBaseFsm.Event(VlanEvRenew) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1359 | }(pConfigVlanStateBaseFsm) |
| 1360 | return |
| 1361 | } |
| 1362 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1363 | //some further flows are to be configured |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1364 | //store the actual rule that shall be worked upon in the following transient states |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1365 | if len(oFsm.uniVlanFlowParamsSlice) < int(oFsm.ConfiguredUniFlow) { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1366 | //check introduced after having observed some panic in this processing |
| 1367 | logger.Errorw(ctx, "error in FsmEvent handling UniVlanConfigFsm in ConfigDone - inconsistent counter", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1368 | log.Fields{"ConfiguredUniFlow": oFsm.ConfiguredUniFlow, |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1369 | "sliceLen": len(oFsm.uniVlanFlowParamsSlice), "device-id": oFsm.deviceID}) |
| 1370 | oFsm.mutexFlowParams.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1371 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1372 | _ = a_pAFsm.PFsm.Event(VlanEvReset) |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1373 | }(pConfigVlanStateAFsm) |
| 1374 | return |
| 1375 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1376 | oFsm.actualUniFlowParam = oFsm.uniVlanFlowParamsSlice[oFsm.ConfiguredUniFlow] |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1377 | //tpId of the next rule to be configured |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1378 | tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1379 | oFsm.TpIDWaitingFor = tpID |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1380 | loSetVlan := oFsm.actualUniFlowParam.VlanRuleParams.SetVid |
mpagenko | 45cc6a3 | 2021-07-23 10:06:57 +0000 | [diff] [blame] | 1381 | //attention: take care to release the mutexFlowParams when calling the FSM directly - |
| 1382 | // synchronous FSM 'event/state' functions may rely on this mutex |
| 1383 | // but it must be released already before calling getTechProfileDone() as it may already be locked |
| 1384 | // by the techProfile processing call to VlanFsm.IsFlowRemovePending() (see VOL-4207) |
| 1385 | oFsm.mutexFlowParams.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1386 | loTechProfDone := oFsm.pUniTechProf.getTechProfileDone(ctx, oFsm.pOnuUniPort.UniID, tpID) |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1387 | logger.Debugw(ctx, "UniVlanConfigFsm - incremental config request", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1388 | "device-id": oFsm.deviceID, "uni-id": oFsm.pOnuUniPort.UniID, |
mpagenko | 45cc6a3 | 2021-07-23 10:06:57 +0000 | [diff] [blame] | 1389 | "set-Vlan": loSetVlan, "tp-id": tpID, "ProfDone": loTechProfDone}) |
| 1390 | |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1391 | // Can't call FSM Event directly, decoupling it |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1392 | go func(aPBaseFsm *fsm.FSM, aTechProfDone bool) { |
| 1393 | if aTechProfDone { |
| 1394 | // let the vlan processing continue with next rule |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1395 | _ = aPBaseFsm.Event(VlanEvIncrFlowConfig) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1396 | } else { |
| 1397 | // set to waiting for Techprofile |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1398 | _ = aPBaseFsm.Event(VlanEvWaitTPIncr) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1399 | } |
| 1400 | }(pConfigVlanStateBaseFsm, loTechProfDone) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1401 | return |
| 1402 | } |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1403 | oFsm.mutexFlowParams.Unlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1404 | logger.Debugw(ctx, "UniVlanConfigFsm - VLAN config done: send dh event notification", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1405 | "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1406 | // it might appear that some flows are requested also after 'flowPushed' event has been generated ... |
| 1407 | // state transition notification is checked in deviceHandler |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1408 | // note: 'flowPushed' event is only generated if all 'pending' rules are configured |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1409 | if oFsm.pDeviceHandler != nil { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1410 | //making use of the add->remove successor enum assumption/definition |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1411 | go oFsm.pDeviceHandler.DeviceProcStatusUpdate(ctx, cmn.OnuDeviceEvent(uint8(oFsm.requestEvent)+oFsm.requestEventOffset)) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1412 | } |
| 1413 | } |
| 1414 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1415 | func (oFsm *UniVlanConfigFsm) enterConfigIncrFlow(ctx context.Context, e *fsm.Event) { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1416 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1417 | if oFsm.pDeviceHandler.IsSkipOnuConfigReconciling() { |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1418 | logger.Debugw(ctx, "reconciling - skip further processing for incremental flow", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1419 | log.Fields{"fsmState": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID}) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1420 | go func(a_pBaseFsm *fsm.FSM) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1421 | _ = a_pBaseFsm.Event(VlanEvSkipIncFlowConfig) |
| 1422 | }(oFsm.PAdaptFsm.PFsm) |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 1423 | return |
| 1424 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1425 | oFsm.mutexFlowParams.Lock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1426 | logger.Debugw(ctx, "UniVlanConfigFsm - start config further incremental flow", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1427 | "recent flow-number": oFsm.ConfiguredUniFlow, |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1428 | "device-id": oFsm.deviceID}) |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1429 | oFsm.TpIDWaitingFor = 0 //reset indication to avoid misinterpretation |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1430 | |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1431 | if oFsm.actualUniFlowParam.VlanRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1432 | // meaning transparent setup - no specific VTFD setting required |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1433 | logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD config required", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1434 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1435 | } else { |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 1436 | //TODO!!!: it was not really intended to keep this enter* FSM method waiting on OMCI response (preventing other state transitions) |
| 1437 | // so it would be conceptually better to wait for the response in background like for the other multi-entity processing |
| 1438 | // but as the OMCI sequence must be ensured, a separate new state would be required - perhaps later |
| 1439 | // in practice should have no influence by now as no other state transition is currently accepted (while cancel() is ensured) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1440 | if oFsm.numVlanFilterEntries == 0 { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1441 | // This attribute uniquely identifies each instance of this managed entity. Through an identical ID, |
| 1442 | // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME. |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1443 | vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.actualUniFlowParam.VlanRuleParams.TpID)) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1444 | //no VTFD yet created |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1445 | logger.Debugw(ctx, "UniVlanConfigFsm create VTFD", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1446 | "EntitytId": strconv.FormatInt(int64(vtfdID), 16), |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1447 | "device-id": oFsm.deviceID, |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1448 | "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": oFsm.actualUniFlowParam.VlanRuleParams.TpID}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1449 | // 'SetVid' below is assumed to be masked already by the caller to 12 bit |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1450 | oFsm.vlanFilterList[0] = uint16(oFsm.actualUniFlowParam.VlanRuleParams.SetVid) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1451 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1452 | vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1453 | vtfdFilterList[0] = oFsm.vlanFilterList[0] |
| 1454 | oFsm.numVlanFilterEntries = 1 |
| 1455 | meParams := me.ParamData{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1456 | EntityID: vtfdID, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1457 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 1458 | me.VlanTaggingFilterData_VlanFilterList: vtfdFilterList, |
| 1459 | me.VlanTaggingFilterData_ForwardOperation: uint8(0x10), //VID investigation |
| 1460 | me.VlanTaggingFilterData_NumberOfEntries: oFsm.numVlanFilterEntries, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1461 | }, |
| 1462 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1463 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1464 | meInstance, err := oFsm.pOmciCC.SendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 1465 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1466 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1467 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1468 | oFsm.mutexFlowParams.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1469 | logger.Errorw(ctx, "VTFD create failed, aborting UniVlanConfig FSM!", |
| 1470 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1471 | pConfigVlanStateAFsm := oFsm.PAdaptFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1472 | if pConfigVlanStateAFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1473 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1474 | _ = a_pAFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1475 | }(pConfigVlanStateAFsm) |
| 1476 | } |
| 1477 | return |
| 1478 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1479 | //accept also nil as (error) return value for writing to LastTx |
| 1480 | // - this avoids misinterpretation of new received OMCI messages |
| 1481 | //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]: |
| 1482 | // send shall return (dual format) error code that can be used here for immediate error treatment |
| 1483 | // (relevant to all used sendXX() methods in this (and other) FSM's) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1484 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1485 | oFsm.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1486 | } else { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1487 | // This attribute uniquely identifies each instance of this managed entity. Through an identical ID, |
| 1488 | // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME. |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1489 | vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(oFsm.actualUniFlowParam.VlanRuleParams.TpID)) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1490 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1491 | logger.Debugw(ctx, "UniVlanConfigFsm set VTFD", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1492 | "EntitytId": strconv.FormatInt(int64(vtfdID), 16), |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1493 | "device-id": oFsm.deviceID, |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1494 | "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": oFsm.actualUniFlowParam.VlanRuleParams.TpID}) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1495 | // setVid is assumed to be masked already by the caller to 12 bit |
| 1496 | oFsm.vlanFilterList[oFsm.numVlanFilterEntries] = |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1497 | uint16(oFsm.actualUniFlowParam.VlanRuleParams.SetVid) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1498 | vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1499 | |
| 1500 | // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME |
| 1501 | // VTFD has to be created afresh with a new entity ID that has the same entity ID as the MBPCD ME for every |
| 1502 | // new vlan associated with a different TP. |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1503 | vtfdFilterList[0] = uint16(oFsm.actualUniFlowParam.VlanRuleParams.SetVid) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1504 | |
| 1505 | oFsm.numVlanFilterEntries++ |
| 1506 | meParams := me.ParamData{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1507 | EntityID: vtfdID, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1508 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 1509 | me.VlanTaggingFilterData_VlanFilterList: vtfdFilterList, |
| 1510 | me.VlanTaggingFilterData_ForwardOperation: uint8(0x10), //VID investigation |
| 1511 | me.VlanTaggingFilterData_NumberOfEntries: oFsm.numVlanFilterEntries, |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1512 | }, |
| 1513 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1514 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1515 | meInstance, err := oFsm.pOmciCC.SendCreateVtfdVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 1516 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1517 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1518 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1519 | oFsm.mutexFlowParams.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1520 | logger.Errorw(ctx, "UniVlanFsm create Vlan Tagging Filter ME result error", |
| 1521 | log.Fields{"device-id": oFsm.deviceID, "Error": err}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1522 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1523 | return |
| 1524 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1525 | //accept also nil as (error) return value for writing to LastTx |
| 1526 | // - this avoids misinterpretation of new received OMCI messages |
| 1527 | //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]: |
| 1528 | // send shall return (dual format) error code that can be used here for immediate error treatment |
| 1529 | // (relevant to all used sendXX() methods in this (and other) FSM's) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1530 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1531 | oFsm.mutexPLastTxMeInstance.Unlock() |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1532 | } |
| 1533 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1534 | err := oFsm.waitforOmciResponse(ctx) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1535 | if err != nil { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1536 | oFsm.mutexFlowParams.Unlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1537 | logger.Errorw(ctx, "VTFD create/set failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1538 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1539 | pConfigVlanStateBaseFsm := oFsm.PAdaptFsm.PFsm |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1540 | // Can't call FSM Event directly, decoupling it |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1541 | go func(a_pBaseFsm *fsm.FSM) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1542 | _ = a_pBaseFsm.Event(VlanEvReset) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1543 | }(pConfigVlanStateBaseFsm) |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1544 | return |
| 1545 | } |
| 1546 | } |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1547 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1548 | oFsm.requestEventOffset = uint8(cDeviceEventOffsetAddWithKvStore) //0 offset for last flow-add activity |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1549 | oFsm.mutexFlowParams.Unlock() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1550 | go func() { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1551 | oFsm.mutexFlowParams.RLock() |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1552 | tpID := oFsm.actualUniFlowParam.VlanRuleParams.TpID |
| 1553 | configuredUniFlow := oFsm.ConfiguredUniFlow |
mpagenko | 3ce9fa0 | 2021-07-28 13:26:54 +0000 | [diff] [blame] | 1554 | // ensure mutexFlowParams not locked before calling some TPProcessing activity (that might already be pending on it) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1555 | oFsm.mutexFlowParams.RUnlock() |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1556 | errEvto := oFsm.performConfigEvtocdEntries(ctx, configuredUniFlow) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1557 | //This is correct passing scenario |
| 1558 | if errEvto == nil { |
| 1559 | //TODO Possibly insert new state for multicast --> possibly another jira/later time. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1560 | for _, gemPort := range oFsm.pUniTechProf.getMulticastGemPorts(ctx, oFsm.pOnuUniPort.UniID, uint8(tpID)) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1561 | oFsm.mutexFlowParams.RLock() |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1562 | vlanID := oFsm.actualUniFlowParam.VlanRuleParams.SetVid |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1563 | logger.Infow(ctx, "Setting multicast MEs for additional flows", log.Fields{"deviceID": oFsm.deviceID, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1564 | "techProfile": tpID, "gemPort": gemPort, |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1565 | "vlanID": vlanID, "ConfiguredUniFlow": configuredUniFlow}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1566 | oFsm.mutexFlowParams.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1567 | errCreateAllMulticastME := oFsm.performSettingMulticastME(ctx, tpID, gemPort, vlanID) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1568 | if errCreateAllMulticastME != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1569 | logger.Errorw(ctx, "Multicast ME create failed, aborting AniConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1570 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1571 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1572 | } |
| 1573 | } |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 1574 | //If this incremental flow contains a meter, then create TD for related gems. |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1575 | if oFsm.actualUniFlowParam.Meter != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1576 | for _, gemPort := range oFsm.pUniTechProf.getBidirectionalGemPortIDsForTP(ctx, oFsm.pOnuUniPort.UniID, tpID) { |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1577 | logger.Debugw(ctx, "Creating Traffic Descriptor for gem", log.Fields{"device-id": oFsm.deviceID, "meter": oFsm.actualUniFlowParam.Meter, "gem": gemPort}) |
| 1578 | errCreateTrafficDescriptor := oFsm.createTrafficDescriptor(ctx, oFsm.actualUniFlowParam.Meter, tpID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1579 | oFsm.pOnuUniPort.UniID, gemPort) |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 1580 | if errCreateTrafficDescriptor != nil { |
| 1581 | logger.Errorw(ctx, "Create Traffic Descriptor create failed, aborting Ani Config FSM!", |
| 1582 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1583 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 1584 | } |
| 1585 | } |
| 1586 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1587 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvRxConfigEvtocd) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1588 | } |
| 1589 | }() |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1592 | func (oFsm *UniVlanConfigFsm) enterRemoveFlow(ctx context.Context, e *fsm.Event) { |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1593 | oFsm.mutexFlowParams.RLock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1594 | logger.Debugw(ctx, "UniVlanConfigFsm - start removing the top remove-flow", log.Fields{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1595 | "with last cookie": oFsm.uniRemoveFlowsSlice[0].cookie, |
| 1596 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1597 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1598 | pConfigVlanStateBaseFsm := oFsm.PAdaptFsm.PFsm |
| 1599 | loAllowSpecificOmciConfig := oFsm.pDeviceHandler.IsReadyForOmciConfig() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1600 | loVlanEntryClear := uint8(0) |
| 1601 | loVlanEntryRmPos := uint8(0x80) //with indication 'invalid' in bit 7 |
| 1602 | //shallow copy is sufficient as no reference variables are used within struct |
| 1603 | loRuleParams := oFsm.uniRemoveFlowsSlice[0].vlanRuleParams |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 1604 | oFsm.mutexFlowParams.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1605 | logger.Debugw(ctx, "UniVlanConfigFsm - remove-flow parameters are", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1606 | "match vid": loRuleParams.MatchVid, "match Pcp": loRuleParams.MatchPcp, |
| 1607 | "set vid": strconv.FormatInt(int64(loRuleParams.SetVid), 16), |
| 1608 | "device-id": oFsm.deviceID}) |
| 1609 | |
| 1610 | if loRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 1611 | // meaning transparent setup - no specific VTFD setting required |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1612 | logger.Debugw(ctx, "UniVlanConfigFsm: no VTFD removal required for transparent flow", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1613 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID}) |
| 1614 | } else { |
| 1615 | vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization and 're-copy' |
| 1616 | if oFsm.numVlanFilterEntries == 1 { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1617 | vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(loRuleParams.TpID)) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1618 | //only one active VLAN entry (hopefully the SetVID we want to remove - should be, but not verified ..) |
| 1619 | // so we can just delete the VTFD entry |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1620 | logger.Debugw(ctx, "UniVlanConfigFsm: VTFD delete (no more vlan filters)", |
Mahir Gunyel | 6781f96 | 2021-05-16 23:30:08 -0700 | [diff] [blame] | 1621 | log.Fields{"current vlan list": oFsm.vlanFilterList, "EntitytId": strconv.FormatInt(int64(vtfdID), 16), |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1622 | "device-id": oFsm.deviceID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1623 | "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": loRuleParams.TpID}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1624 | loVlanEntryClear = 1 //full VlanFilter clear request |
| 1625 | if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1626 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1627 | meInstance, err := oFsm.pOmciCC.SendDeleteVtfd(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 1628 | oFsm.PAdaptFsm.CommChan, vtfdID) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1629 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1630 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1631 | logger.Errorw(ctx, "UniVlanFsm delete Vlan Tagging Filter ME result error", |
| 1632 | log.Fields{"device-id": oFsm.deviceID, "Error": err}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1633 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1634 | return |
| 1635 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1636 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1637 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1638 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1639 | logger.Debugw(ctx, "UniVlanConfigFsm delete VTFD OMCI handling skipped based on device state", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1640 | "device-id": oFsm.deviceID, "device-state": oFsm.pDeviceHandler.GetDeviceReasonString()}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1641 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1642 | } else { |
| 1643 | //many VTFD already should exists - find and remove the one concerned by the actual remove rule |
| 1644 | // by updating the VTFD per set command with new valid list |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1645 | logger.Debugw(ctx, "UniVlanConfigFsm: VTFD removal of requested VLAN from the list on OMCI", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1646 | log.Fields{"current vlan list": oFsm.vlanFilterList, |
| 1647 | "set-vlan": loRuleParams.SetVid, "device-id": oFsm.deviceID}) |
| 1648 | for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ { |
| 1649 | if loRuleParams.SetVid == uint32(oFsm.vlanFilterList[i]) { |
| 1650 | loVlanEntryRmPos = i |
| 1651 | break //abort search |
| 1652 | } |
| 1653 | } |
| 1654 | if loVlanEntryRmPos < cVtfdTableSize { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1655 | vtfdID, _ := cmn.GenerateANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo), uint16(loRuleParams.TpID)) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1656 | //valid entry was found - to be eclipsed |
| 1657 | loVlanEntryClear = 2 //VlanFilter remove request for a specific entry |
| 1658 | for i := uint8(0); i < oFsm.numVlanFilterEntries; i++ { |
| 1659 | if i < loVlanEntryRmPos { |
| 1660 | vtfdFilterList[i] = oFsm.vlanFilterList[i] //copy original |
| 1661 | } else if i < (cVtfdTableSize - 1) { |
| 1662 | vtfdFilterList[i] = oFsm.vlanFilterList[i+1] //copy successor (including 0 elements) |
| 1663 | } else { |
| 1664 | vtfdFilterList[i] = 0 //set last byte if needed |
| 1665 | } |
| 1666 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1667 | logger.Debugw(ctx, "UniVlanConfigFsm set VTFD", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1668 | "EntitytId": strconv.FormatInt(int64(vtfdID), 16), |
Mahir Gunyel | 6781f96 | 2021-05-16 23:30:08 -0700 | [diff] [blame] | 1669 | "new vlan list": vtfdFilterList, "device-id": oFsm.deviceID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1670 | "macBpNo": oFsm.pOnuUniPort.MacBpNo, "TpID": loRuleParams.TpID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1671 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1672 | if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 1673 | // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1674 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1675 | meInstance, err := oFsm.pOmciCC.SendDeleteVtfd(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 1676 | oFsm.PAdaptFsm.CommChan, vtfdID) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1677 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1678 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1679 | logger.Errorw(ctx, "UniVlanFsm delete Vlan Tagging Filter ME result error", |
| 1680 | log.Fields{"device-id": oFsm.deviceID, "Error": err}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1681 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1682 | return |
| 1683 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1684 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 1685 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1686 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1687 | logger.Debugw(ctx, "UniVlanConfigFsm set VTFD OMCI handling skipped based on device state", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1688 | "device-id": oFsm.deviceID, "device-state": oFsm.pDeviceHandler.GetDeviceReasonString()}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1689 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1690 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1691 | logger.Warnw(ctx, "UniVlanConfigFsm: requested VLAN for removal not found in list - ignore and continue (no VTFD set)", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1692 | log.Fields{"device-id": oFsm.deviceID}) |
| 1693 | } |
| 1694 | } |
| 1695 | if loVlanEntryClear > 0 { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1696 | if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state |
| 1697 | //waiting on response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1698 | err := oFsm.waitforOmciResponse(ctx) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1699 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1700 | logger.Errorw(ctx, "VTFD delete/reset failed, aborting VlanConfig FSM!", |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1701 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1702 | // Can't call FSM Event directly, decoupling it |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1703 | go func(a_pBaseFsm *fsm.FSM) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1704 | _ = a_pBaseFsm.Event(VlanEvReset) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1705 | }(pConfigVlanStateBaseFsm) |
| 1706 | return |
| 1707 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1710 | oFsm.mutexFlowParams.Lock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1711 | if loVlanEntryClear == 1 { |
| 1712 | oFsm.vlanFilterList[0] = 0 //first entry is the only that can contain the previous only-one element |
| 1713 | oFsm.numVlanFilterEntries = 0 |
| 1714 | } else if loVlanEntryClear == 2 { |
| 1715 | // new VlanFilterList should be one entry smaller now - copy from last configured entry |
| 1716 | // this loop now includes the 0 element on previous last valid entry |
| 1717 | for i := uint8(0); i <= oFsm.numVlanFilterEntries; i++ { |
| 1718 | oFsm.vlanFilterList[i] = vtfdFilterList[i] |
| 1719 | } |
| 1720 | oFsm.numVlanFilterEntries-- |
| 1721 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 1722 | oFsm.mutexFlowParams.Unlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1723 | } |
| 1724 | } |
| 1725 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1726 | if loAllowSpecificOmciConfig { //specific OMCI config is expected to work acc. to the device state |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1727 | go oFsm.removeEvtocdEntries(ctx, loRuleParams) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1728 | } else { |
| 1729 | // OMCI processing is not done, expectation is to have the ONU in some basic config state accordingly |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1730 | logger.Debugw(ctx, "UniVlanConfigFsm remove EVTOCD OMCI handling skipped based on device state", log.Fields{ |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1731 | "device-id": oFsm.deviceID}) |
mpagenko | 9a304ea | 2020-12-16 15:54:01 +0000 | [diff] [blame] | 1732 | // Can't call FSM Event directly, decoupling it |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1733 | go func(a_pBaseFsm *fsm.FSM) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1734 | _ = a_pBaseFsm.Event(VlanEvRemFlowDone, loRuleParams.TpID) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 1735 | }(pConfigVlanStateBaseFsm) |
| 1736 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1739 | func (oFsm *UniVlanConfigFsm) enterVlanCleanupDone(ctx context.Context, e *fsm.Event) { |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 1740 | var tpID uint8 |
| 1741 | // Extract the tpID |
| 1742 | if len(e.Args) > 0 { |
| 1743 | tpID = e.Args[0].(uint8) |
| 1744 | logger.Debugw(ctx, "UniVlanConfigFsm - flow removed for tp id", log.Fields{"device-id": oFsm.deviceID, "tpID": e.Args[0].(uint8)}) |
| 1745 | } else { |
| 1746 | logger.Warnw(ctx, "UniVlanConfigFsm - tp id not available", log.Fields{"device-id": oFsm.deviceID}) |
| 1747 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1748 | oFsm.mutexFlowParams.Lock() |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1749 | deletedCookie := oFsm.uniRemoveFlowsSlice[0].cookie |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1750 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1751 | pConfigVlanStateAFsm := oFsm.PAdaptFsm |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 1752 | if pConfigVlanStateAFsm == nil { |
| 1753 | logger.Errorw(ctx, "invalid Fsm pointer - unresolvable - abort", |
| 1754 | log.Fields{"device-id": oFsm.deviceID}) |
| 1755 | //would have to be fixed from outside somehow |
| 1756 | return |
| 1757 | } |
| 1758 | |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1759 | // here we need o finally remove the removed data also from uniVlanFlowParamsSlice and possibly have to |
| 1760 | // stop the suspension of a add-activity waiting for the end of removal |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 1761 | //call from 'configured' state of the rule |
| 1762 | if err := oFsm.removeFlowFromParamsSlice(ctx, deletedCookie, true); err != nil { |
| 1763 | //something quite inconsistent detected, perhaps just try to recover with FSM reset |
| 1764 | oFsm.mutexFlowParams.Unlock() |
| 1765 | logger.Errorw(ctx, "UniVlanConfigFsm - could not clear database - abort", log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1766 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1767 | _ = a_pAFsm.PFsm.Event(VlanEvReset) |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 1768 | }(pConfigVlanStateAFsm) |
| 1769 | return |
| 1770 | } |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1771 | if oFsm.uniRemoveFlowsSlice[0].isSuspendedOnAdd { |
| 1772 | removeChannel := oFsm.uniRemoveFlowsSlice[0].removeChannel |
| 1773 | oFsm.mutexFlowParams.Unlock() |
| 1774 | removeChannel <- true |
| 1775 | oFsm.mutexFlowParams.Lock() |
| 1776 | } |
| 1777 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1778 | logger.Debugw(ctx, "UniVlanConfigFsm - removing the removal data", log.Fields{ |
| 1779 | "in state": e.FSM.Current(), "device-id": oFsm.deviceID, |
| 1780 | "removed cookie": deletedCookie, "waitForDeleteCookie": oFsm.delayNewRuleCookie}) |
| 1781 | |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1782 | // Store the reference to the flow response channel before this entry in the slice is deleted |
| 1783 | flowRespChan := oFsm.uniRemoveFlowsSlice[0].respChan |
| 1784 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1785 | if len(oFsm.uniRemoveFlowsSlice) <= 1 { |
| 1786 | oFsm.uniRemoveFlowsSlice = nil //reset the slice |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1787 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal - last remove-flow deleted", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1788 | "device-id": oFsm.deviceID}) |
| 1789 | } else { |
| 1790 | //cut off the actual flow by slicing out the first element |
| 1791 | oFsm.uniRemoveFlowsSlice = append( |
| 1792 | oFsm.uniRemoveFlowsSlice[:0], |
| 1793 | oFsm.uniRemoveFlowsSlice[1:]...) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1794 | logger.Debugw(ctx, "UniVlanConfigFsm flow removal - specific flow deleted from data", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1795 | "device-id": oFsm.deviceID}) |
| 1796 | } |
| 1797 | oFsm.mutexFlowParams.Unlock() |
| 1798 | |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1799 | oFsm.requestEventOffset = uint8(cDeviceEventOffsetRemoveWithKvStore) //offset for last flow-remove activity (with kvStore request) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1800 | //return to the basic config verification state |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 1801 | // Can't call FSM Event directly, decoupling it |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1802 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1803 | _ = a_pAFsm.PFsm.Event(VlanEvFlowDataRemoved) |
mpagenko | f582d6a | 2021-06-18 15:58:10 +0000 | [diff] [blame] | 1804 | }(pConfigVlanStateAFsm) |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 1805 | |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 1806 | oFsm.mutexFlowParams.Lock() |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 1807 | noOfFlowRem := len(oFsm.uniRemoveFlowsSlice) |
mpagenko | f1fc386 | 2021-02-16 10:09:52 +0000 | [diff] [blame] | 1808 | if deletedCookie == oFsm.delayNewRuleCookie { |
| 1809 | // flush the channel CookieDeleted to ensure it is not lingering from some previous (aborted) activity |
| 1810 | select { |
| 1811 | case <-oFsm.chCookieDeleted: |
| 1812 | logger.Debug(ctx, "flushed CookieDeleted") |
| 1813 | default: |
| 1814 | } |
| 1815 | oFsm.chCookieDeleted <- true // let the waiting AddFlow thread continue |
| 1816 | } |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 1817 | // If all pending flow-removes are completed and TP ID is valid go on processing any pending TP delete |
| 1818 | if oFsm.signalOnFlowDelete && noOfFlowRem == 0 && tpID > 0 { |
| 1819 | logger.Debugw(ctx, "signal flow removal for pending TP delete", log.Fields{"device-id": oFsm.deviceID, "tpID": tpID}) |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 1820 | // If we are here then all flows are removed. |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 1821 | if len(oFsm.flowDeleteChannel) == 0 { //channel not yet in use |
| 1822 | oFsm.flowDeleteChannel <- true |
| 1823 | oFsm.signalOnFlowDelete = false |
| 1824 | } |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 1825 | } |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 1826 | oFsm.mutexFlowParams.Unlock() |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 1827 | |
| 1828 | // send response on the response channel for the removed flow. |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 1829 | oFsm.pushReponseOnFlowResponseChannel(ctx, flowRespChan, nil) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1832 | func (oFsm *UniVlanConfigFsm) enterResetting(ctx context.Context, e *fsm.Event) { |
| 1833 | logger.Debugw(ctx, "UniVlanConfigFsm resetting", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1834 | |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 1835 | oFsm.mutexPLastTxMeInstance.Lock() |
| 1836 | oFsm.pLastTxMeInstance = nil //to avoid misinterpretation in case of some lingering frame reception processing |
| 1837 | oFsm.mutexPLastTxMeInstance.Unlock() |
| 1838 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1839 | pConfigVlanStateAFsm := oFsm.PAdaptFsm |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1840 | if pConfigVlanStateAFsm != nil { |
| 1841 | // abort running message processing |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1842 | fsmAbortMsg := cmn.Message{ |
| 1843 | Type: cmn.TestMsg, |
| 1844 | Data: cmn.TestMessage{ |
| 1845 | TestMessageVal: cmn.AbortMessageProcessing, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1846 | }, |
| 1847 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1848 | pConfigVlanStateAFsm.CommChan <- fsmAbortMsg |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1849 | |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 1850 | //internal data is not explicitly removed, this is left to garbage collection after complete FSM removal |
| 1851 | // but some channels have to be cleared to avoid unintended waiting for events, that have no meaning anymore now |
| 1852 | |
| 1853 | oFsm.mutexFlowParams.RLock() |
| 1854 | if oFsm.delayNewRuleCookie != 0 { |
| 1855 | // looks like the waiting AddFlow is stuck |
| 1856 | oFsm.mutexFlowParams.RUnlock() |
| 1857 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1858 | select { |
| 1859 | case oFsm.chCookieDeleted <- false: // let the waiting AddFlow thread terminate |
| 1860 | default: |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1861 | } |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 1862 | oFsm.mutexFlowParams.RLock() |
| 1863 | } |
| 1864 | if len(oFsm.uniRemoveFlowsSlice) > 0 { |
| 1865 | for _, removeUniFlowParams := range oFsm.uniRemoveFlowsSlice { |
| 1866 | if removeUniFlowParams.isSuspendedOnAdd { |
| 1867 | removeChannel := removeUniFlowParams.removeChannel |
| 1868 | logger.Debugw(ctx, "UniVlanConfigFsm flow clear-up - abort suspended rule-add", log.Fields{ |
| 1869 | "device-id": oFsm.deviceID, "cookie": removeUniFlowParams.cookie}) |
| 1870 | oFsm.mutexFlowParams.RUnlock() |
| 1871 | //use asynchronous channel sending to avoid stucking on non-waiting receiver |
| 1872 | select { |
| 1873 | case removeChannel <- false: |
| 1874 | default: |
| 1875 | } |
| 1876 | oFsm.mutexFlowParams.RLock() |
| 1877 | } |
| 1878 | // Send response on response channel if the caller is waiting on it. |
| 1879 | var err error = nil |
| 1880 | if !oFsm.isCanceled { |
| 1881 | //only if the FSM is not canceled on external request use some error indication for the respChan |
| 1882 | // so only at real internal FSM abortion some error code is sent back |
| 1883 | // on the deleteFlow with the hope the system may handle such error situation (possibly retrying) |
| 1884 | err = fmt.Errorf("internal-error") |
| 1885 | } |
| 1886 | //if the FSM was cancelled on external request the assumption is, that all processing has to be stopped |
| 1887 | // assumed in connection with some ONU down/removal indication in which case all flows can be considered as removed |
| 1888 | oFsm.pushReponseOnFlowResponseChannel(ctx, removeUniFlowParams.respChan, err) |
| 1889 | } |
| 1890 | } |
| 1891 | |
| 1892 | if oFsm.pDeviceHandler != nil { |
| 1893 | if len(oFsm.uniVlanFlowParamsSlice) > 0 { |
| 1894 | if !oFsm.isCanceled { |
| 1895 | //if the FSM is not canceled on external request use "internal-error" for the respChan |
| 1896 | for _, vlanRule := range oFsm.uniVlanFlowParamsSlice { |
| 1897 | // Send response on response channel if the caller is waiting on it with according error indication. |
| 1898 | oFsm.pushReponseOnFlowResponseChannel(ctx, vlanRule.RespChan, fmt.Errorf("internal-error")) |
| 1899 | } |
| 1900 | //permanently remove possibly stored persistent data |
| 1901 | var emptySlice = make([]cmn.UniVlanFlowParams, 0) |
| 1902 | _ = oFsm.pDeviceHandler.StorePersUniFlowConfig(ctx, oFsm.pOnuUniPort.UniID, &emptySlice, true) //ignore errors |
| 1903 | } else { |
| 1904 | // reset (cancel) of all Fsm is always accompanied by global persistency data removal |
| 1905 | // no need to remove specific data in this case here |
nikesh.krishnan | c7c0bce | 2023-12-20 21:36:35 +0530 | [diff] [blame] | 1906 | for _, vlanRule := range oFsm.uniVlanFlowParamsSlice { |
| 1907 | // Send response on response channel if the caller is waiting on it with according error indication. |
| 1908 | oFsm.pushReponseOnFlowResponseChannel(ctx, vlanRule.RespChan, fmt.Errorf("config-cancelled")) |
| 1909 | } |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 1910 | logger.Debugw(ctx, "UniVlanConfigFsm persistency data not cleared", log.Fields{"device-id": oFsm.deviceID}) |
| 1911 | } |
| 1912 | } |
| 1913 | oFsm.mutexFlowParams.RUnlock() |
| 1914 | |
| 1915 | //try to let the FSM proceed to 'disabled' |
| 1916 | // Can't call FSM Event directly, decoupling it |
| 1917 | go func(a_pAFsm *cmn.AdapterFsm) { |
| 1918 | if a_pAFsm != nil && a_pAFsm.PFsm != nil { |
| 1919 | _ = a_pAFsm.PFsm.Event(VlanEvRestart) |
| 1920 | } |
| 1921 | }(pConfigVlanStateAFsm) |
| 1922 | return |
| 1923 | } |
| 1924 | oFsm.mutexFlowParams.RUnlock() |
| 1925 | logger.Warnw(ctx, "UniVlanConfigFsm - device handler already vanished", |
| 1926 | log.Fields{"device-id": oFsm.deviceID}) |
| 1927 | return |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1928 | } |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 1929 | logger.Warnw(ctx, "UniVlanConfigFsm - FSM pointer already vanished", |
| 1930 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1933 | func (oFsm *UniVlanConfigFsm) enterDisabled(ctx context.Context, e *fsm.Event) { |
| 1934 | logger.Debugw(ctx, "UniVlanConfigFsm enters disabled state", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1935 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1936 | if oFsm.pDeviceHandler != nil { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 1937 | //request removal of 'reference' in the Handler (completely clear the FSM and its data) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1938 | go oFsm.pDeviceHandler.RemoveVlanFilterFsm(ctx, oFsm.pOnuUniPort) |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 1939 | return |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1940 | } |
mpagenko | 0f54322 | 2021-11-03 16:24:14 +0000 | [diff] [blame] | 1941 | logger.Warnw(ctx, "UniVlanConfigFsm - device handler already vanished", |
| 1942 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1943 | } |
| 1944 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1945 | func (oFsm *UniVlanConfigFsm) processOmciVlanMessages(ctx context.Context) { //ctx context.Context? |
| 1946 | logger.Debugw(ctx, "Start UniVlanConfigFsm Msg processing", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1947 | loop: |
| 1948 | for { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1949 | // case <-ctx.Done(): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1950 | // logger.Info(ctx,"MibSync Msg", log.Fields{"Message handling canceled via context for device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1951 | // break loop |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1952 | message, ok := <-oFsm.PAdaptFsm.CommChan |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1953 | if !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1954 | logger.Info(ctx, "UniVlanConfigFsm Rx Msg - could not read from channel", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1955 | // 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] | 1956 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1957 | break loop |
| 1958 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1959 | logger.Debugw(ctx, "UniVlanConfigFsm Rx Msg", log.Fields{"device-id": oFsm.deviceID}) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1960 | |
| 1961 | switch message.Type { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1962 | case cmn.TestMsg: |
| 1963 | msg, _ := message.Data.(cmn.TestMessage) |
| 1964 | if msg.TestMessageVal == cmn.AbortMessageProcessing { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1965 | logger.Infow(ctx, "UniVlanConfigFsm abort ProcessMsg", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1966 | break loop |
| 1967 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1968 | logger.Warnw(ctx, "UniVlanConfigFsm unknown TestMessage", log.Fields{"device-id": oFsm.deviceID, "MessageVal": msg.TestMessageVal}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1969 | case cmn.OMCI: |
| 1970 | msg, _ := message.Data.(cmn.OmciMessage) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1971 | oFsm.handleOmciVlanConfigMessage(ctx, msg) |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1972 | default: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1973 | logger.Warn(ctx, "UniVlanConfigFsm Rx unknown message", log.Fields{"device-id": oFsm.deviceID, |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 1974 | "message.Type": message.Type}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1975 | } |
| 1976 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1977 | logger.Infow(ctx, "End UniVlanConfigFsm Msg processing", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1978 | } |
| 1979 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1980 | func (oFsm *UniVlanConfigFsm) handleOmciVlanConfigMessage(ctx context.Context, msg cmn.OmciMessage) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1981 | logger.Debugw(ctx, "Rx OMCI UniVlanConfigFsm Msg", log.Fields{"device-id": oFsm.deviceID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1982 | "msgType": msg.OmciMsg.MessageType}) |
| 1983 | |
| 1984 | switch msg.OmciMsg.MessageType { |
| 1985 | case omci.CreateResponseType: |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1986 | { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-( |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1987 | if err := oFsm.handleOmciCreateResponseMessage(ctx, msg.OmciPacket); err != nil { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 1988 | logger.Warnw(ctx, "CreateResponse handling aborted", |
| 1989 | log.Fields{"device-id": oFsm.deviceID, "err": err}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1990 | return |
| 1991 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1992 | } //CreateResponseType |
| 1993 | case omci.SetResponseType: |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1994 | { //leave that here as direct code as most often used |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1995 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 1996 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 1997 | logger.Errorw(ctx, "Omci Msg layer could not be detected for SetResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 1998 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 1999 | return |
| 2000 | } |
| 2001 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 2002 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2003 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for SetResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2004 | log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2005 | return |
| 2006 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2007 | logger.Debugw(ctx, "UniVlanConfigFsm SetResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2008 | if msgObj.Result != me.Success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2009 | logger.Errorw(ctx, "UniVlanConfigFsm Omci SetResponse Error - later: drive FSM to abort state ?", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2010 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
Holger Hildebrandt | 7e13846 | 2023-03-29 12:12:14 +0000 | [diff] [blame] | 2011 | // possibly force FSM into abort or ignore some errors for some messages? |
| 2012 | oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass, |
| 2013 | msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2014 | return |
| 2015 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2016 | oFsm.mutexPLastTxMeInstance.RLock() |
| 2017 | if oFsm.pLastTxMeInstance != nil { |
| 2018 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 2019 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 2020 | switch oFsm.pLastTxMeInstance.GetName() { |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 2021 | case "VlanTaggingFilterData", "ExtendedVlanTaggingOperationConfigurationData", "MulticastOperationsProfile", "GemPortNetworkCtp": |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2022 | { // let the MultiEntity config proceed by stopping the wait function |
| 2023 | oFsm.mutexPLastTxMeInstance.RUnlock() |
| 2024 | oFsm.omciMIdsResponseReceived <- true |
| 2025 | return |
| 2026 | } |
| 2027 | default: |
| 2028 | { |
| 2029 | logger.Warnw(ctx, "Unsupported ME name received!", |
| 2030 | log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID}) |
| 2031 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2032 | } |
| 2033 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2034 | } else { |
| 2035 | logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2036 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2037 | oFsm.mutexPLastTxMeInstance.RUnlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2038 | } //SetResponseType |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2039 | case omci.DeleteResponseType: |
| 2040 | { // had to shift that to a method to cope with StaticCodeAnalysis restrictions :-( |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2041 | if err := oFsm.handleOmciDeleteResponseMessage(ctx, msg.OmciPacket); err != nil { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 2042 | logger.Warnw(ctx, "DeleteResponse handling aborted", |
| 2043 | log.Fields{"device-id": oFsm.deviceID, "err": err}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2044 | return |
| 2045 | } |
| 2046 | } //DeleteResponseType |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2047 | default: |
| 2048 | { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2049 | logger.Errorw(ctx, "Rx OMCI unhandled MsgType", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2050 | log.Fields{"omciMsgType": msg.OmciMsg.MessageType, "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2051 | return |
| 2052 | } |
| 2053 | } |
| 2054 | } |
| 2055 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2056 | func (oFsm *UniVlanConfigFsm) handleOmciCreateResponseMessage(ctx context.Context, apOmciPacket *gp.Packet) error { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2057 | msgLayer := (*apOmciPacket).Layer(omci.LayerTypeCreateResponse) |
| 2058 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2059 | logger.Errorw(ctx, "Omci Msg layer could not be detected for CreateResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2060 | log.Fields{"device-id": oFsm.deviceID}) |
| 2061 | return fmt.Errorf("omci msg layer could not be detected for CreateResponse for device-id %x", |
| 2062 | oFsm.deviceID) |
| 2063 | } |
| 2064 | msgObj, msgOk := msgLayer.(*omci.CreateResponse) |
| 2065 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2066 | logger.Errorw(ctx, "Omci Msg layer could not be assigned for CreateResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2067 | log.Fields{"device-id": oFsm.deviceID}) |
| 2068 | return fmt.Errorf("omci msg layer could not be assigned for CreateResponse for device-id %x", |
| 2069 | oFsm.deviceID) |
| 2070 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2071 | logger.Debugw(ctx, "UniVlanConfigFsm CreateResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2072 | if msgObj.Result != me.Success && msgObj.Result != me.InstanceExists { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2073 | logger.Errorw(ctx, "Omci CreateResponse Error - later: drive FSM to abort state ?", log.Fields{"device-id": oFsm.deviceID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2074 | "Error": msgObj.Result}) |
Holger Hildebrandt | 7e13846 | 2023-03-29 12:12:14 +0000 | [diff] [blame] | 2075 | // possibly force FSM into abort or ignore some errors for some messages? |
| 2076 | oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass, |
| 2077 | msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2078 | return fmt.Errorf("omci CreateResponse Error for device-id %x", |
| 2079 | oFsm.deviceID) |
| 2080 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2081 | oFsm.mutexPLastTxMeInstance.RLock() |
| 2082 | if oFsm.pLastTxMeInstance != nil { |
| 2083 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 2084 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 2085 | // to satisfy StaticCodeAnalysis I had to move the small processing into a separate method :-( |
| 2086 | switch oFsm.pLastTxMeInstance.GetName() { |
| 2087 | case "VlanTaggingFilterData", "MulticastOperationsProfile", |
| 2088 | "MulticastSubscriberConfigInfo", "MacBridgePortConfigurationData", |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 2089 | "ExtendedVlanTaggingOperationConfigurationData", "TrafficDescriptor": |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2090 | { |
| 2091 | oFsm.mutexPLastTxMeInstance.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2092 | if oFsm.PAdaptFsm.PFsm.Current() == VlanStConfigVtfd { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2093 | // Only if CreateResponse is received from first flow entry - let the FSM proceed ... |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2094 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvRxConfigVtfd) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2095 | } else { // let the MultiEntity config proceed by stopping the wait function |
| 2096 | oFsm.omciMIdsResponseReceived <- true |
| 2097 | } |
| 2098 | return nil |
| 2099 | } |
| 2100 | default: |
| 2101 | { |
| 2102 | logger.Warnw(ctx, "Unsupported ME name received!", |
| 2103 | log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2104 | } |
| 2105 | } |
| 2106 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2107 | } else { |
| 2108 | logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2109 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2110 | oFsm.mutexPLastTxMeInstance.RUnlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2111 | return nil |
| 2112 | } |
| 2113 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2114 | func (oFsm *UniVlanConfigFsm) handleOmciDeleteResponseMessage(ctx context.Context, apOmciPacket *gp.Packet) error { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2115 | msgLayer := (*apOmciPacket).Layer(omci.LayerTypeDeleteResponse) |
| 2116 | if msgLayer == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2117 | logger.Errorw(ctx, "UniVlanConfigFsm - Omci Msg layer could not be detected for DeleteResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2118 | log.Fields{"device-id": oFsm.deviceID}) |
| 2119 | return fmt.Errorf("omci msg layer could not be detected for DeleteResponse for device-id %x", |
| 2120 | oFsm.deviceID) |
| 2121 | } |
| 2122 | msgObj, msgOk := msgLayer.(*omci.DeleteResponse) |
| 2123 | if !msgOk { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2124 | logger.Errorw(ctx, "UniVlanConfigFsm - Omci Msg layer could not be assigned for DeleteResponse", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2125 | log.Fields{"device-id": oFsm.deviceID}) |
| 2126 | return fmt.Errorf("omci msg layer could not be assigned for DeleteResponse for device-id %x", |
| 2127 | oFsm.deviceID) |
| 2128 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2129 | logger.Debugw(ctx, "UniVlanConfigFsm DeleteResponse Data", log.Fields{"device-id": oFsm.deviceID, "data-fields": msgObj}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2130 | if msgObj.Result != me.Success { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2131 | logger.Errorw(ctx, "UniVlanConfigFsm - Omci DeleteResponse Error - later: drive FSM to abort state ?", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2132 | log.Fields{"device-id": oFsm.deviceID, "Error": msgObj.Result}) |
Holger Hildebrandt | 7e13846 | 2023-03-29 12:12:14 +0000 | [diff] [blame] | 2133 | // possibly force FSM into abort or ignore some errors for some messages? |
| 2134 | oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureResponseErr, msgObj.EntityClass, |
| 2135 | msgObj.EntityInstance, msgObj.EntityClass.String(), msgObj.Result) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2136 | return fmt.Errorf("omci DeleteResponse Error for device-id %x", |
| 2137 | oFsm.deviceID) |
| 2138 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2139 | oFsm.mutexPLastTxMeInstance.RLock() |
| 2140 | if oFsm.pLastTxMeInstance != nil { |
| 2141 | if msgObj.EntityClass == oFsm.pLastTxMeInstance.GetClassID() && |
| 2142 | msgObj.EntityInstance == oFsm.pLastTxMeInstance.GetEntityID() { |
| 2143 | switch oFsm.pLastTxMeInstance.GetName() { |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 2144 | case "VlanTaggingFilterData", "ExtendedVlanTaggingOperationConfigurationData", "TrafficDescriptor": |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2145 | { // let the MultiEntity config proceed by stopping the wait function |
| 2146 | oFsm.mutexPLastTxMeInstance.RUnlock() |
| 2147 | oFsm.omciMIdsResponseReceived <- true |
| 2148 | return nil |
| 2149 | } |
| 2150 | default: |
| 2151 | { |
| 2152 | logger.Warnw(ctx, "Unsupported ME name received!", |
| 2153 | log.Fields{"ME name": oFsm.pLastTxMeInstance.GetName(), "device-id": oFsm.deviceID}) |
| 2154 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2155 | } |
| 2156 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2157 | } else { |
| 2158 | logger.Warnw(ctx, "Pointer to last Tx MeInstance is nil!", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2159 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2160 | oFsm.mutexPLastTxMeInstance.RUnlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2161 | return nil |
| 2162 | } |
| 2163 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2164 | func (oFsm *UniVlanConfigFsm) performConfigEvtocdEntries(ctx context.Context, aFlowEntryNo uint8) error { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2165 | oFsm.mutexFlowParams.RLock() |
| 2166 | evtocdID := oFsm.evtocdID |
| 2167 | oFsm.mutexFlowParams.RUnlock() |
| 2168 | |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 2169 | if aFlowEntryNo == 0 { |
| 2170 | // EthType set only at first flow element |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2171 | // EVTOCD ME is expected to exist at this point already from MIB-Download (with AssociationType/Pointer) |
| 2172 | // we need to extend the configuration by EthType definition and, to be sure, downstream 'inverse' mode |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2173 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Create::EVTOCD", log.Fields{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2174 | "EntitytId": strconv.FormatInt(int64(evtocdID), 16), |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2175 | "i/oEthType": strconv.FormatInt(int64(cDefaultTpid), 16), |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2176 | "device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2177 | associationType := 2 // default to UniPPTP |
| 2178 | if oFsm.pOnuUniPort.PortType == cmn.UniVEIP { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2179 | associationType = 10 |
| 2180 | } |
| 2181 | // Create the EVTOCD ME |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2182 | meParams := me.ParamData{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2183 | EntityID: evtocdID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2184 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2185 | me.ExtendedVlanTaggingOperationConfigurationData_AssociationType: uint8(associationType), |
| 2186 | me.ExtendedVlanTaggingOperationConfigurationData_AssociatedMePointer: oFsm.pOnuUniPort.EntityID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2187 | }, |
| 2188 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2189 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2190 | meInstance, err := oFsm.pOmciCC.SendCreateEvtocdVar(context.TODO(), oFsm.pDeviceHandler.GetOmciTimeout(), |
| 2191 | true, oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2192 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2193 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2194 | logger.Errorw(ctx, "CreateEvtocdVar create failed, aborting UniVlanConfigFsm!", |
| 2195 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2196 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2197 | return fmt.Errorf("evtocd instance create failed %s, error %s", oFsm.deviceID, err) |
| 2198 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2199 | //accept also nil as (error) return value for writing to LastTx |
| 2200 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2201 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2202 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2203 | |
| 2204 | //verify response |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2205 | err = oFsm.waitforOmciResponse(ctx) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2206 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2207 | logger.Errorw(ctx, "Evtocd create failed, aborting VlanConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2208 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2209 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2210 | return fmt.Errorf("evtocd create failed %s, error %s", oFsm.deviceID, err) |
| 2211 | } |
| 2212 | |
| 2213 | // Set the EVTOCD ME default params |
| 2214 | meParams = me.ParamData{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2215 | EntityID: evtocdID, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2216 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2217 | me.ExtendedVlanTaggingOperationConfigurationData_InputTpid: uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base |
| 2218 | me.ExtendedVlanTaggingOperationConfigurationData_OutputTpid: uint16(cDefaultTpid), //could be possibly retrieved from flow config one day, by now just like py-code base |
| 2219 | me.ExtendedVlanTaggingOperationConfigurationData_DownstreamMode: uint8(cDefaultDownstreamMode), |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2220 | }, |
| 2221 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2222 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2223 | meInstance, err = oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), |
| 2224 | oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 2225 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2226 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2227 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2228 | logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!", |
| 2229 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2230 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2231 | return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err) |
| 2232 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2233 | //accept also nil as (error) return value for writing to LastTx |
| 2234 | // - this avoids misinterpretation of new received OMCI messages |
| 2235 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2236 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2237 | |
| 2238 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2239 | err = oFsm.waitforOmciResponse(ctx) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2240 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2241 | logger.Errorw(ctx, "Evtocd set TPID failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2242 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2243 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2244 | return fmt.Errorf("evtocd set TPID failed %s, error %s", oFsm.deviceID, err) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2245 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 2246 | } //first flow element |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2247 | |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 2248 | oFsm.mutexFlowParams.RLock() |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 2249 | if oFsm.actualUniFlowParam.VlanRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) && |
| 2250 | uint32(oFsm.actualUniFlowParam.VlanRuleParams.InnerCvlan) == uint32(of.OfpVlanId_OFPVID_NONE) { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2251 | //transparent transmission required |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 2252 | oFsm.mutexFlowParams.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2253 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD single tagged transparent rule", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2254 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2255 | sliceEvtocdRule := make([]uint8, 16) |
| 2256 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 2257 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 2258 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 2259 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 2260 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 2261 | |
| 2262 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 2263 | cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule |
| 2264 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid |
| 2265 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 2266 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 2267 | |
| 2268 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 2269 | 0<<cTreatTTROffset| // Do not pop any tags |
| 2270 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 2271 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 2272 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 2273 | |
| 2274 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 2275 | cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag |
| 2276 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 2277 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
| 2278 | |
| 2279 | meParams := me.ParamData{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2280 | EntityID: evtocdID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2281 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2282 | me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2283 | }, |
| 2284 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2285 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2286 | meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), |
| 2287 | oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 2288 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2289 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2290 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2291 | logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!", |
| 2292 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2293 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2294 | return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err) |
| 2295 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2296 | //accept also nil as (error) return value for writing to LastTx |
| 2297 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2298 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2299 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2300 | |
| 2301 | //verify response |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2302 | err = oFsm.waitforOmciResponse(ctx) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2303 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2304 | logger.Errorw(ctx, "Evtocd set transparent singletagged rule failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2305 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2306 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2307 | return fmt.Errorf("evtocd set transparent singletagged rule failed %s, error %s", oFsm.deviceID, err) |
| 2308 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2309 | } |
| 2310 | } else { |
| 2311 | // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario |
| 2312 | if oFsm.acceptIncrementalEvtoOption { |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2313 | matchPcp := oFsm.actualUniFlowParam.VlanRuleParams.MatchPcp |
| 2314 | matchVid := oFsm.actualUniFlowParam.VlanRuleParams.MatchVid |
| 2315 | setPcp := oFsm.actualUniFlowParam.VlanRuleParams.SetPcp |
| 2316 | setVid := oFsm.actualUniFlowParam.VlanRuleParams.SetVid |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 2317 | innerCvlan := oFsm.actualUniFlowParam.VlanRuleParams.InnerCvlan |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2318 | sliceEvtocdRule := make([]uint8, 16) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2319 | |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 2320 | if uint32(oFsm.actualUniFlowParam.VlanRuleParams.InnerCvlan) == uint32(of.OfpVlanId_OFPVID_NONE) { |
| 2321 | // this defines VID translation scenario: singletagged->singletagged (if not transparent) |
| 2322 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD single tagged translation rule", log.Fields{ |
| 2323 | "match-pcp": matchPcp, "match-vid": matchVid, "set-pcp": setPcp, "set-vid:": setVid, "device-id": oFsm.deviceID}) |
| 2324 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 2325 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 2326 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 2327 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 2328 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2329 | |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 2330 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 2331 | oFsm.actualUniFlowParam.VlanRuleParams.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN |
| 2332 | oFsm.actualUniFlowParam.VlanRuleParams.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID |
| 2333 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 2334 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2335 | |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 2336 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 2337 | oFsm.actualUniFlowParam.VlanRuleParams.TagsToRemove<<cTreatTTROffset| // either 1 or 0 |
| 2338 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 2339 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 2340 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 2341 | |
| 2342 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 2343 | oFsm.actualUniFlowParam.VlanRuleParams.SetPcp<<cTreatPrioOffset| // as configured in flow |
| 2344 | oFsm.actualUniFlowParam.VlanRuleParams.SetVid<<cTreatVidOffset| //as configured in flow |
| 2345 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
| 2346 | |
| 2347 | } else { |
| 2348 | //Double tagged case, if innerCvlan is 4096 then transparent, else match on the innerCvlan |
| 2349 | //As of now only a match and no action can be done on the inner tag . |
| 2350 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD double tagged translation rule", log.Fields{ |
| 2351 | "match-pcp": matchPcp, "match-vid": matchVid, "set-pcp": setPcp, "set-vid:": setVid, "inner-cvlan:": innerCvlan, "device-id": oFsm.deviceID}) |
| 2352 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 2353 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 2354 | oFsm.actualUniFlowParam.VlanRuleParams.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or filter priority |
| 2355 | oFsm.actualUniFlowParam.VlanRuleParams.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID |
| 2356 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 2357 | |
| 2358 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 2359 | cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule |
| 2360 | uint32(innerCvlan)<<cFilterVidOffset| // transparent of innercvlan is 4096 or filter with innercvlan |
| 2361 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 2362 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 2363 | |
| 2364 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 2365 | oFsm.actualUniFlowParam.VlanRuleParams.TagsToRemove<<cTreatTTROffset| // either 1 or 0 |
| 2366 | cCopyPrioFromOuter<<cTreatPrioOffset| // add tag and copy prio from outer from the received frame |
| 2367 | setVid<<cTreatVidOffset| // Set VID |
| 2368 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 2369 | |
| 2370 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 2371 | cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag |
| 2372 | uint32(innerCvlan)<<cTreatVidOffset| //as configured in flow |
| 2373 | cDontCareTpid<<cTreatTpidOffset) // Set TPID = 0x8100 |
| 2374 | } |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 2375 | oFsm.mutexFlowParams.RUnlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2376 | meParams := me.ParamData{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2377 | EntityID: evtocdID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2378 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2379 | me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2380 | }, |
| 2381 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2382 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2383 | meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), |
| 2384 | oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 2385 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2386 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2387 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2388 | logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!", |
| 2389 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2390 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2391 | return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err) |
| 2392 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2393 | //accept also nil as (error) return value for writing to LastTx |
| 2394 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2395 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2396 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2397 | |
| 2398 | //verify response |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2399 | err = oFsm.waitforOmciResponse(ctx) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2400 | if err != nil { |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 2401 | logger.Errorw(ctx, "Evtocd set rule failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2402 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2403 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 2404 | return fmt.Errorf("evtocd set rule failed %s, error %s", oFsm.deviceID, err) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2405 | } |
| 2406 | } else { |
| 2407 | //not transparent and not acceptIncrementalEvtoOption untagged/priotagged->singletagged |
| 2408 | { // just for local var's |
| 2409 | // this defines stacking scenario: untagged->singletagged |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2410 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD untagged->singletagged rule", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2411 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2412 | sliceEvtocdRule := make([]uint8, 16) |
| 2413 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 2414 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 2415 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 2416 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 2417 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 2418 | |
| 2419 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 2420 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an inner-tag rule |
| 2421 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid |
| 2422 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 2423 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 2424 | |
| 2425 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 2426 | 0<<cTreatTTROffset| // Do not pop any tags |
| 2427 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 2428 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 2429 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 2430 | |
| 2431 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 2432 | 0<<cTreatPrioOffset| // vlan prio set to 0 |
| 2433 | // (as done in Py code, maybe better option would be setPcp here, which still could be 0?) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2434 | oFsm.actualUniFlowParam.VlanRuleParams.SetVid<<cTreatVidOffset| // Outer VID don't care |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2435 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
| 2436 | |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 2437 | oFsm.mutexFlowParams.RUnlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2438 | meParams := me.ParamData{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2439 | EntityID: evtocdID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2440 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2441 | me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2442 | }, |
| 2443 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2444 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2445 | meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), |
| 2446 | oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 2447 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2448 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2449 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2450 | logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!", |
| 2451 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2452 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2453 | return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err) |
| 2454 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2455 | //accept also nil as (error) return value for writing to LastTx |
| 2456 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2457 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2458 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2459 | |
| 2460 | //verify response |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2461 | err = oFsm.waitforOmciResponse(ctx) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2462 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2463 | logger.Errorw(ctx, "Evtocd set untagged->singletagged rule failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2464 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2465 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2466 | return fmt.Errorf("evtocd set untagged->singletagged rule failed %s, error %s", oFsm.deviceID, err) |
| 2467 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2468 | } |
Holger Hildebrandt | 394c552 | 2020-09-11 11:23:01 +0000 | [diff] [blame] | 2469 | } // just for local var's |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2470 | { // just for local var's |
| 2471 | // this defines 'stacking' scenario: priotagged->singletagged |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2472 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD priotagged->singletagged rule", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2473 | "device-id": oFsm.deviceID}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2474 | sliceEvtocdRule := make([]uint8, 16) |
| 2475 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 2476 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 2477 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 2478 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 2479 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 2480 | |
| 2481 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 2482 | cPrioDoNotFilter<<cFilterPrioOffset| // Do not Filter on innerprio |
| 2483 | 0<<cFilterVidOffset| // filter on inner vid 0 (prioTagged) |
| 2484 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 2485 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 2486 | |
| 2487 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 2488 | 1<<cTreatTTROffset| // pop the prio-tag |
| 2489 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 2490 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 2491 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 2492 | |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 2493 | oFsm.mutexFlowParams.RLock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2494 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 2495 | cCopyPrioFromInner<<cTreatPrioOffset| // vlan copy from PrioTag |
| 2496 | // (as done in Py code, maybe better option would be setPcp here, which still could be PrioCopy?) |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 2497 | oFsm.actualUniFlowParam.VlanRuleParams.SetVid<<cTreatVidOffset| // Outer VID as configured |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2498 | cSetOutputTpidCopyDei<<cTreatTpidOffset) // Set TPID = 0x8100 |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 2499 | oFsm.mutexFlowParams.RUnlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2500 | |
| 2501 | meParams := me.ParamData{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2502 | EntityID: evtocdID, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2503 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2504 | me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2505 | }, |
| 2506 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2507 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2508 | meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), |
| 2509 | oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 2510 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2511 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2512 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2513 | logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!", |
| 2514 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2515 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2516 | return fmt.Errorf("evtocd instance set failed %s, error %s", oFsm.deviceID, err) |
| 2517 | } |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2518 | //accept also nil as (error) return value for writing to LastTx |
| 2519 | // - this avoids misinterpretation of new received OMCI messages |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2520 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2521 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2522 | |
| 2523 | //verify response |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2524 | err = oFsm.waitforOmciResponse(ctx) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2525 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2526 | logger.Errorw(ctx, "Evtocd set priotagged->singletagged rule failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2527 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2528 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2529 | return fmt.Errorf("evtocd set priotagged->singletagged rule failed %s, error %s", oFsm.deviceID, err) |
| 2530 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2531 | } |
| 2532 | } //just for local var's |
| 2533 | } |
| 2534 | } |
| 2535 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2536 | // if Config has been done for all EVTOCD entries let the FSM proceed |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2537 | logger.Debugw(ctx, "EVTOCD set loop finished", log.Fields{"device-id": oFsm.deviceID}) |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2538 | oFsm.mutexFlowParams.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2539 | oFsm.ConfiguredUniFlow++ // one (more) flow configured |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2540 | oFsm.mutexFlowParams.Unlock() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2541 | return nil |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2542 | } |
| 2543 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2544 | func (oFsm *UniVlanConfigFsm) removeEvtocdEntries(ctx context.Context, aRuleParams cmn.UniVlanRuleParams) { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2545 | oFsm.mutexFlowParams.RLock() |
| 2546 | evtocdID := oFsm.evtocdID |
| 2547 | oFsm.mutexFlowParams.RUnlock() |
| 2548 | |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2549 | // configured Input/Output TPID is not modified again - no influence if no filter is applied |
| 2550 | if aRuleParams.SetVid == uint32(of.OfpVlanId_OFPVID_PRESENT) { |
| 2551 | //transparent transmission was set |
| 2552 | //perhaps the config is not needed for removal, |
| 2553 | // but the specific InnerTpid setting is removed in favor of the real default forwarding rule |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2554 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD reset to default single tagged rule", log.Fields{ |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2555 | "device-id": oFsm.deviceID}) |
| 2556 | sliceEvtocdRule := make([]uint8, 16) |
| 2557 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 2558 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 2559 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 2560 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 2561 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 2562 | |
| 2563 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 2564 | cPrioDefaultFilter<<cFilterPrioOffset| // default inner-tag rule |
| 2565 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid |
| 2566 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 2567 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 2568 | |
| 2569 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 2570 | 0<<cTreatTTROffset| // Do not pop any tags |
| 2571 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 2572 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 2573 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
| 2574 | |
| 2575 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 2576 | cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag |
| 2577 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 2578 | cDontCareTpid<<cTreatTpidOffset) // copy TPID and DEI |
| 2579 | |
| 2580 | meParams := me.ParamData{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2581 | EntityID: evtocdID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2582 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2583 | me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2584 | }, |
| 2585 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2586 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2587 | meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), |
| 2588 | oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 2589 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2590 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2591 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2592 | logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!", |
| 2593 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2594 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2595 | return |
| 2596 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2597 | //accept also nil as (error) return value for writing to LastTx |
| 2598 | // - this avoids misinterpretation of new received OMCI messages |
| 2599 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2600 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2601 | |
| 2602 | //verify response |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2603 | err = oFsm.waitforOmciResponse(ctx) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2604 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2605 | logger.Errorw(ctx, "Evtocd reset singletagged rule failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2606 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2607 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2608 | return |
| 2609 | } |
| 2610 | } else { |
| 2611 | // according to py-code acceptIncrementalEvto program option decides upon stacking or translation scenario |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2612 | oFsm.mutexFlowParams.RLock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2613 | if oFsm.acceptIncrementalEvtoOption { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2614 | oFsm.mutexFlowParams.RUnlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2615 | sliceEvtocdRule := make([]uint8, 16) |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 2616 | if uint32(aRuleParams.InnerCvlan) == uint32(of.OfpVlanId_OFPVID_NONE) { |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2617 | |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 2618 | // this defines VID translation scenario: singletagged->singletagged (if not transparent) |
| 2619 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD clear single tagged translation rule", log.Fields{ |
| 2620 | "device-id": oFsm.deviceID, "match-vlan": aRuleParams.MatchVid}) |
| 2621 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 2622 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 2623 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 2624 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 2625 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2626 | |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 2627 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 2628 | aRuleParams.MatchPcp<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN |
| 2629 | aRuleParams.MatchVid<<cFilterVidOffset| // either DNFonVid or real filter VID |
| 2630 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 2631 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2632 | |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 2633 | // delete indication for the indicated Filter |
| 2634 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], 0xFFFFFFFF) |
| 2635 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], 0xFFFFFFFF) |
| 2636 | |
| 2637 | } else { |
| 2638 | // this defines VID translation scenario: dobletagged-doubletagged (if not transparent) |
| 2639 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD clear double tagged rule", log.Fields{ |
| 2640 | "device-id": oFsm.deviceID, "match-vlan": aRuleParams.MatchVid, "innerCvlan": aRuleParams.InnerCvlan}) |
| 2641 | sliceEvtocdRule := make([]uint8, 16) |
| 2642 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 2643 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 2644 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 2645 | aRuleParams.MatchVid<<cFilterVidOffset| // Do not filter on outer vid |
| 2646 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 2647 | |
| 2648 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 2649 | cPrioIgnoreTag<<cFilterPrioOffset| // either DNFonPrio or ignore tag (default) on innerVLAN |
| 2650 | cDoNotFilterVid<<cFilterVidOffset| // DNFonVid or ignore tag |
| 2651 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 2652 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 2653 | |
| 2654 | // delete indication for the indicated Filter |
| 2655 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], 0xFFFFFFFF) |
| 2656 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], 0xFFFFFFFF) |
| 2657 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2658 | meParams := me.ParamData{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2659 | EntityID: evtocdID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2660 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2661 | me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2662 | }, |
| 2663 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2664 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2665 | meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), |
| 2666 | oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 2667 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2668 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2669 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2670 | logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!", |
| 2671 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2672 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2673 | return |
| 2674 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2675 | //accept also nil as (error) return value for writing to LastTx |
| 2676 | // - this avoids misinterpretation of new received OMCI messages |
| 2677 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2678 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2679 | |
| 2680 | //verify response |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2681 | err = oFsm.waitforOmciResponse(ctx) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2682 | if err != nil { |
Abhilash Laxmeshwar | 81b5ccf | 2022-03-17 15:04:18 +0530 | [diff] [blame] | 2683 | logger.Errorw(ctx, "Evtocd clear rule failed, aborting VlanConfig FSM!", |
| 2684 | log.Fields{"device-id": oFsm.deviceID, |
| 2685 | "match-vlan": aRuleParams.MatchVid, |
| 2686 | "InnerCvlan": aRuleParams.InnerCvlan}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2687 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2688 | return |
| 2689 | } |
| 2690 | } else { |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2691 | // VOL-3685 |
| 2692 | // NOTE: With ALPHA ONUs it was seen that just resetting a particular entry in the EVTOCD table |
| 2693 | // and re-configuring a new entry would not work. The old entry is removed and new entry is created |
| 2694 | // indeed, but the traffic landing upstream would carry old vlan sometimes. |
| 2695 | // This is only a WORKAROUND which basically deletes the entire EVTOCD ME and re-creates it again |
| 2696 | // later when the flow is being re-installed. |
| 2697 | // Of course this is applicable to case only where single service (or single tcont) is in use and |
| 2698 | // there is only one service vlan (oFsm.acceptIncrementalEvtoOption is false in this case). |
| 2699 | // Interstingly this problem has not been observed in multi-tcont (or multi-service) scenario (in |
| 2700 | // which case the oFsm.acceptIncrementalEvtoOption is set to true). |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2701 | if oFsm.ConfiguredUniFlow == 1 && !oFsm.acceptIncrementalEvtoOption { |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2702 | oFsm.mutexFlowParams.RUnlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2703 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Remove::EVTOCD", log.Fields{"device-id": oFsm.deviceID}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2704 | // When there are no more EVTOCD vlan configurations on the ONU and acceptIncrementalEvtoOption |
| 2705 | // is not enabled, delete the EVTOCD ME. |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2706 | meParams := me.ParamData{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2707 | EntityID: evtocdID, |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2708 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2709 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2710 | meInstance, err := oFsm.pOmciCC.SendDeleteEvtocd(log.WithSpanFromContext(context.TODO(), ctx), |
| 2711 | oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 2712 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2713 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2714 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2715 | logger.Errorw(ctx, "DeleteEvtocdVar delete failed, aborting UniVlanConfigFsm!", |
| 2716 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2717 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2718 | return |
| 2719 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2720 | //accept also nil as (error) return value for writing to LastTx |
| 2721 | // - this avoids misinterpretation of new received OMCI messages |
| 2722 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2723 | oFsm.mutexPLastTxMeInstance.Unlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2724 | |
| 2725 | //verify response |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2726 | err = oFsm.waitforOmciResponse(ctx) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2727 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2728 | logger.Errorw(ctx, "Evtocd delete rule failed, aborting VlanConfig FSM!", |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2729 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2730 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2731 | return |
| 2732 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2733 | } else { |
| 2734 | // NOTE : We should ideally never ether this section when oFsm.acceptIncrementalEvtoOption is set to false |
| 2735 | // This is true for only ATT/DT workflow |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2736 | logger.Debugw(ctx, "UniVlanConfigFsm: Remove EVTOCD set operation", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2737 | log.Fields{"configured-flow": oFsm.ConfiguredUniFlow, "incremental-evto": oFsm.acceptIncrementalEvtoOption}) |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2738 | oFsm.mutexFlowParams.RUnlock() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2739 | //not transparent and not acceptIncrementalEvtoOption: untagged/priotagged->singletagged |
| 2740 | { // just for local var's |
| 2741 | // this defines stacking scenario: untagged->singletagged |
| 2742 | //TODO!! in theory there could be different rules running in setting different PCP/VID'S |
| 2743 | // for untagged/priotagged, last rule wins (and remains the only one), maybe that should be |
| 2744 | // checked already at flow-add (and rejected) - to be observed if such is possible in Voltha |
| 2745 | // delete now assumes there is only one such rule! |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2746 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD reset untagged rule to default", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2747 | "device-id": oFsm.deviceID}) |
| 2748 | sliceEvtocdRule := make([]uint8, 16) |
| 2749 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 2750 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 2751 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 2752 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 2753 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2754 | |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2755 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 2756 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an inner-tag rule |
| 2757 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on inner vid |
| 2758 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 2759 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2760 | |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2761 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], |
| 2762 | 0<<cTreatTTROffset| // Do not pop any tags |
| 2763 | cDoNotAddPrio<<cTreatPrioOffset| // do not add outer tag |
| 2764 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 2765 | cDontCareTpid<<cTreatTpidOffset) // Outer TPID field don't care |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2766 | |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2767 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], |
| 2768 | cDoNotAddPrio<<cTreatPrioOffset| // do not add inner tag |
| 2769 | cDontCareVid<<cTreatVidOffset| // Outer VID don't care |
| 2770 | cDontCareTpid<<cTreatTpidOffset) // copy TPID and DEI |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2771 | |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2772 | meParams := me.ParamData{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2773 | EntityID: evtocdID, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2774 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2775 | me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2776 | }, |
| 2777 | } |
Girish Gowdra | 754ffb1 | 2021-06-30 16:30:12 -0700 | [diff] [blame] | 2778 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2779 | meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(context.TODO(), |
| 2780 | oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 2781 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2782 | if err != nil { |
Girish Gowdra | 754ffb1 | 2021-06-30 16:30:12 -0700 | [diff] [blame] | 2783 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2784 | logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!", |
| 2785 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2786 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2787 | return |
| 2788 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2789 | //accept also nil as (error) return value for writing to LastTx |
| 2790 | // - this avoids misinterpretation of new received OMCI messages |
| 2791 | oFsm.pLastTxMeInstance = meInstance |
Girish Gowdra | 754ffb1 | 2021-06-30 16:30:12 -0700 | [diff] [blame] | 2792 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2793 | |
| 2794 | //verify response |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2795 | err = oFsm.waitforOmciResponse(ctx) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2796 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2797 | logger.Errorw(ctx, "Evtocd reset untagged rule to default failed, aborting VlanConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2798 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2799 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2800 | return |
| 2801 | } |
| 2802 | } // just for local var's |
| 2803 | { // just for local var's |
| 2804 | // this defines 'stacking' scenario: priotagged->singletagged |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2805 | logger.Debugw(ctx, "UniVlanConfigFsm Tx Set::EVTOCD delete priotagged rule", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2806 | "device-id": oFsm.deviceID}) |
| 2807 | sliceEvtocdRule := make([]uint8, 16) |
| 2808 | // fill vlan tagging operation table bit fields using network=bigEndian order and using slice offset 0 as highest 'word' |
| 2809 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterOuterOffset:], |
| 2810 | cPrioIgnoreTag<<cFilterPrioOffset| // Not an outer-tag rule |
| 2811 | cDoNotFilterVid<<cFilterVidOffset| // Do not filter on outer vid |
| 2812 | cDoNotFilterTPID<<cFilterTpidOffset) // Do not filter on outer TPID field |
| 2813 | |
| 2814 | binary.BigEndian.PutUint32(sliceEvtocdRule[cFilterInnerOffset:], |
| 2815 | cPrioDoNotFilter<<cFilterPrioOffset| // Do not Filter on innerprio |
| 2816 | 0<<cFilterVidOffset| // filter on inner vid 0 (prioTagged) |
| 2817 | cDoNotFilterTPID<<cFilterTpidOffset| // Do not filter on inner TPID field |
| 2818 | cDoNotFilterEtherType<<cFilterEtherTypeOffset) // Do not filter of EtherType |
| 2819 | |
| 2820 | // delete indication for the indicated Filter |
| 2821 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatOuterOffset:], 0xFFFFFFFF) |
| 2822 | binary.BigEndian.PutUint32(sliceEvtocdRule[cTreatInnerOffset:], 0xFFFFFFFF) |
| 2823 | |
| 2824 | meParams := me.ParamData{ |
mpagenko | f1d21d1 | 2021-06-11 13:14:45 +0000 | [diff] [blame] | 2825 | EntityID: evtocdID, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2826 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2827 | me.ExtendedVlanTaggingOperationConfigurationData_ReceivedFrameVlanTaggingOperationTable: sliceEvtocdRule, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2828 | }, |
| 2829 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2830 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2831 | meInstance, err := oFsm.pOmciCC.SendSetEvtocdVar(log.WithSpanFromContext(context.TODO(), ctx), |
| 2832 | oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 2833 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2834 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2835 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2836 | logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!", |
| 2837 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2838 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2839 | return |
| 2840 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2841 | //accept also nil as (error) return value for writing to LastTx |
| 2842 | // - this avoids misinterpretation of new received OMCI messages |
| 2843 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2844 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2845 | |
| 2846 | //verify response |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2847 | err = oFsm.waitforOmciResponse(ctx) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2848 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2849 | logger.Errorw(ctx, "Evtocd delete priotagged rule failed, aborting VlanConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2850 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2851 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2852 | return |
| 2853 | } |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2854 | } |
| 2855 | } //just for local var's |
| 2856 | } |
| 2857 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 2858 | // if Config has been done for all EVTOCD entries let the FSM proceed |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2859 | logger.Debugw(ctx, "EVTOCD filter remove loop finished", log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2860 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvRemFlowDone, aRuleParams.TpID) |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2861 | } |
| 2862 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2863 | func (oFsm *UniVlanConfigFsm) waitforOmciResponse(ctx context.Context) error { |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2864 | oFsm.mutexIsAwaitingResponse.Lock() |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 2865 | if oFsm.isCanceled { |
| 2866 | // FSM already canceled before entering wait |
| 2867 | logger.Debugw(ctx, "UniVlanConfigFsm wait-for-multi-entity-response aborted (on enter)", log.Fields{"for device-id": oFsm.deviceID}) |
| 2868 | oFsm.mutexIsAwaitingResponse.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2869 | return fmt.Errorf(cmn.CErrWaitAborted) |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 2870 | } |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2871 | oFsm.isAwaitingResponse = true |
| 2872 | oFsm.mutexIsAwaitingResponse.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2873 | select { |
Himani Chawla | 26e555c | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2874 | // maybe be also some outside cancel (but no context modeled for the moment ...) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2875 | // case <-ctx.Done(): |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2876 | // logger.Infow(ctx,"LockState-bridge-init message reception canceled", log.Fields{"for device-id": oFsm.deviceID}) |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 2877 | case <-time.After(oFsm.pOmciCC.GetMaxOmciTimeoutWithRetries() * time.Second): //AS FOR THE OTHER OMCI FSM's |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2878 | logger.Warnw(ctx, "UniVlanConfigFsm multi entity timeout", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2879 | oFsm.mutexIsAwaitingResponse.Lock() |
| 2880 | oFsm.isAwaitingResponse = false |
| 2881 | oFsm.mutexIsAwaitingResponse.Unlock() |
Holger Hildebrandt | 7e13846 | 2023-03-29 12:12:14 +0000 | [diff] [blame] | 2882 | oFsm.mutexPLastTxMeInstance.RLock() |
| 2883 | if oFsm.pLastTxMeInstance != nil { |
| 2884 | oFsm.pOmciCC.NotifyAboutOnuConfigFailure(ctx, cmn.OnuConfigFailureTimeout, oFsm.pLastTxMeInstance.GetClassID(), |
| 2885 | oFsm.pLastTxMeInstance.GetEntityID(), oFsm.pLastTxMeInstance.GetClassID().String(), 0) |
| 2886 | } |
| 2887 | oFsm.mutexPLastTxMeInstance.RUnlock() |
mpagenko | 01e726e | 2020-10-23 09:45:29 +0000 | [diff] [blame] | 2888 | return fmt.Errorf("uniVlanConfigFsm multi entity timeout %s", oFsm.deviceID) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2889 | case success := <-oFsm.omciMIdsResponseReceived: |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 2890 | if success { |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 2891 | logger.Debugw(ctx, "UniVlanConfigFsm multi entity response received", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2892 | oFsm.mutexIsAwaitingResponse.Lock() |
| 2893 | oFsm.isAwaitingResponse = false |
| 2894 | oFsm.mutexIsAwaitingResponse.Unlock() |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2895 | return nil |
| 2896 | } |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2897 | // waiting was aborted (probably on external request) |
mpagenko | cf48e45 | 2021-04-23 09:23:00 +0000 | [diff] [blame] | 2898 | logger.Debugw(ctx, "UniVlanConfigFsm wait-for-multi-entity-response aborted", log.Fields{"for device-id": oFsm.deviceID}) |
mpagenko | 7d6bb02 | 2021-03-11 15:07:55 +0000 | [diff] [blame] | 2899 | oFsm.mutexIsAwaitingResponse.Lock() |
| 2900 | oFsm.isAwaitingResponse = false |
| 2901 | oFsm.mutexIsAwaitingResponse.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2902 | return fmt.Errorf(cmn.CErrWaitAborted) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 2903 | } |
| 2904 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2905 | |
mpagenko | 551a4d4 | 2020-12-08 18:09:20 +0000 | [diff] [blame] | 2906 | func (oFsm *UniVlanConfigFsm) performSettingMulticastME(ctx context.Context, tpID uint8, multicastGemPortID uint16, vlanID uint32) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2907 | logger.Debugw(ctx, "Setting Multicast MEs", log.Fields{"device-id": oFsm.deviceID, "tpID": tpID, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2908 | "multicastGemPortID": multicastGemPortID, "vlanID": vlanID}) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2909 | errCreateMOP := oFsm.performCreatingMulticastOperationProfile(ctx) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2910 | if errCreateMOP != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2911 | logger.Errorw(ctx, "MulticastOperationProfile create failed, aborting AniConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2912 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2913 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2914 | return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, errCreateMOP) |
| 2915 | } |
| 2916 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2917 | errSettingMOP := oFsm.performSettingMulticastOperationProfile(ctx, multicastGemPortID, vlanID) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2918 | if errSettingMOP != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2919 | logger.Errorw(ctx, "MulticastOperationProfile setting failed, aborting AniConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2920 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2921 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2922 | return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, errSettingMOP) |
| 2923 | } |
| 2924 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2925 | errCreateMSCI := oFsm.performCreatingMulticastSubscriberConfigInfo(ctx) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2926 | if errCreateMSCI != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2927 | logger.Errorw(ctx, "MulticastOperationProfile setting failed, aborting AniConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2928 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2929 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2930 | return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, errCreateMSCI) |
| 2931 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2932 | macBpCdEID, errMacBpCdEID := cmn.GenerateMcastANISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo)) |
Mahir Gunyel | 6781f96 | 2021-05-16 23:30:08 -0700 | [diff] [blame] | 2933 | if errMacBpCdEID != nil { |
| 2934 | logger.Errorw(ctx, "MulticastMacBridgePortConfigData entity id generation failed, aborting AniConfig FSM!", |
| 2935 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2936 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
Mahir Gunyel | 6781f96 | 2021-05-16 23:30:08 -0700 | [diff] [blame] | 2937 | return fmt.Errorf("generateMcastANISideMBPCDEID responseError %s, error %s", oFsm.deviceID, errMacBpCdEID) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2938 | |
Mahir Gunyel | 6781f96 | 2021-05-16 23:30:08 -0700 | [diff] [blame] | 2939 | } |
| 2940 | logger.Debugw(ctx, "UniVlanConfigFsm set macBpCdEID for mcast", log.Fields{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2941 | "EntitytId": strconv.FormatInt(int64(macBpCdEID), 16), "macBpNo": oFsm.pOnuUniPort.MacBpNo, |
| 2942 | "in state": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2943 | meParams := me.ParamData{ |
Mahir Gunyel | 6781f96 | 2021-05-16 23:30:08 -0700 | [diff] [blame] | 2944 | EntityID: macBpCdEID, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2945 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2946 | me.MacBridgePortConfigurationData_BridgeIdPointer: cmn.MacBridgeServiceProfileEID + uint16(oFsm.pOnuUniPort.MacBpNo), |
| 2947 | me.MacBridgePortConfigurationData_PortNum: 0xf0, //fixed unique ANI side indication |
| 2948 | me.MacBridgePortConfigurationData_TpType: 6, //MCGemIWTP |
| 2949 | me.MacBridgePortConfigurationData_TpPointer: multicastGemPortID, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2950 | }, |
| 2951 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2952 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2953 | meInstance, err := oFsm.pOmciCC.SendCreateMBPConfigDataVar(context.TODO(), |
| 2954 | oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2955 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2956 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2957 | logger.Errorw(ctx, "MBPConfigDataVar create failed, aborting AniConfig FSM!", |
| 2958 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2959 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2960 | return fmt.Errorf("creatingMulticastSubscriberConfigInfo createError #{oFsm.deviceID}, error #{err}") |
| 2961 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2962 | //accept also nil as (error) return value for writing to LastTx |
| 2963 | // - this avoids misinterpretation of new received OMCI messages |
| 2964 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2965 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2966 | err = oFsm.waitforOmciResponse(ctx) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2967 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2968 | logger.Errorw(ctx, "CreateMBPConfigData failed, aborting AniConfig FSM!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2969 | log.Fields{"device-id": oFsm.deviceID, "MBPConfigDataID": cmn.MacBridgeServiceProfileEID}) |
| 2970 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2971 | return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s, error %s", oFsm.deviceID, err) |
| 2972 | } |
| 2973 | |
| 2974 | // ==> Start creating VTFD for mcast vlan |
| 2975 | |
| 2976 | // This attribute uniquely identifies each instance of this managed entity. Through an identical ID, |
| 2977 | // this managed entity is implicitly linked to an instance of the MAC bridge port configuration data ME. |
Mahir Gunyel | 6781f96 | 2021-05-16 23:30:08 -0700 | [diff] [blame] | 2978 | mcastVtfdID := macBpCdEID |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2979 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 2980 | logger.Debugw(ctx, "UniVlanConfigFsm set VTFD for mcast", log.Fields{ |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2981 | "EntitytId": strconv.FormatInt(int64(mcastVtfdID), 16), "mcastVlanID": vlanID, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2982 | "in state": oFsm.PAdaptFsm.PFsm.Current(), "device-id": oFsm.deviceID}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2983 | vtfdFilterList := make([]uint16, cVtfdTableSize) //needed for parameter serialization |
| 2984 | |
| 2985 | // FIXME: VOL-3685: Issues with resetting a table entry in EVTOCD ME |
| 2986 | // VTFD has to be created afresh with a new entity ID that has the same entity ID as the MBPCD ME for every |
| 2987 | // new vlan associated with a different TP. |
| 2988 | vtfdFilterList[0] = uint16(vlanID) |
| 2989 | |
| 2990 | meParams = me.ParamData{ |
| 2991 | EntityID: mcastVtfdID, |
| 2992 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2993 | me.VlanTaggingFilterData_VlanFilterList: vtfdFilterList, |
| 2994 | me.VlanTaggingFilterData_ForwardOperation: uint8(0x10), //VID investigation |
| 2995 | me.VlanTaggingFilterData_NumberOfEntries: oFsm.numVlanFilterEntries, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 2996 | }, |
| 2997 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 2998 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2999 | meInstance, err = oFsm.pOmciCC.SendCreateVtfdVar(context.TODO(), |
| 3000 | oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3001 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3002 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3003 | logger.Errorw(ctx, "CreateVtfdVar create failed, aborting UniVlanConfigFsm!", |
| 3004 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3005 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3006 | return fmt.Errorf("createMcastVlanFilterData creationError %s, error %s", oFsm.deviceID, err) |
| 3007 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3008 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3009 | oFsm.mutexPLastTxMeInstance.Unlock() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3010 | err = oFsm.waitforOmciResponse(ctx) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3011 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3012 | logger.Errorw(ctx, "CreateMcastVlanFilterData failed, aborting AniConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3013 | log.Fields{"device-id": oFsm.deviceID, "mcastVtfdID": mcastVtfdID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3014 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3015 | return fmt.Errorf("createMcastVlanFilterData responseError %s, error %s", oFsm.deviceID, err) |
| 3016 | } |
| 3017 | |
| 3018 | return nil |
| 3019 | } |
| 3020 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3021 | func (oFsm *UniVlanConfigFsm) performCreatingMulticastSubscriberConfigInfo(ctx context.Context) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3022 | instID, err := cmn.GenerateUNISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo)) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3023 | if err != nil { |
Mahir Gunyel | 6781f96 | 2021-05-16 23:30:08 -0700 | [diff] [blame] | 3024 | logger.Errorw(ctx, "error generrating me instance id", |
| 3025 | log.Fields{"device-id": oFsm.deviceID, "error": err}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3026 | return err |
| 3027 | } |
Mahir Gunyel | 6781f96 | 2021-05-16 23:30:08 -0700 | [diff] [blame] | 3028 | logger.Debugw(ctx, "UniVlanConfigFsm create MulticastSubscriberConfigInfo", |
| 3029 | log.Fields{"device-id": oFsm.deviceID, "EntityId": instID}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3030 | meParams := me.ParamData{ |
| 3031 | EntityID: instID, |
| 3032 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3033 | me.MulticastSubscriberConfigInfo_MeType: 0, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3034 | //Direct reference to the Operation profile |
| 3035 | //TODO ANI side used on UNI side, not the clearest option. |
ozgecanetsia | 5c88b76 | 2021-03-23 10:27:15 +0300 | [diff] [blame] | 3036 | "MulticastOperationsProfilePointer": instID, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3037 | }, |
| 3038 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3039 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3040 | meInstance, err := oFsm.pOmciCC.SendCreateMulticastSubConfigInfoVar(context.TODO(), |
| 3041 | oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 3042 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3043 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3044 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3045 | logger.Errorw(ctx, "CreateMulticastSubConfigInfoVar create failed, aborting UniVlanConfigFSM!", |
| 3046 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3047 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3048 | return fmt.Errorf("creatingMulticastSubscriberConfigInfo interface creationError %s, error %s", |
| 3049 | oFsm.deviceID, err) |
| 3050 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3051 | //accept also nil as (error) return value for writing to LastTx |
| 3052 | // - this avoids misinterpretation of new received OMCI messages |
| 3053 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3054 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3055 | //verify response |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3056 | err = oFsm.waitforOmciResponse(ctx) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3057 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3058 | logger.Errorw(ctx, "CreateMulticastSubConfigInfo create failed, aborting AniConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3059 | log.Fields{"device-id": oFsm.deviceID, "MulticastSubConfigInfo": instID}) |
| 3060 | return fmt.Errorf("creatingMulticastSubscriberConfigInfo responseError %s", oFsm.deviceID) |
| 3061 | } |
| 3062 | return nil |
| 3063 | } |
| 3064 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3065 | func (oFsm *UniVlanConfigFsm) performCreatingMulticastOperationProfile(ctx context.Context) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3066 | instID, err := cmn.GenerateUNISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo)) |
ozgecanetsia | 5c88b76 | 2021-03-23 10:27:15 +0300 | [diff] [blame] | 3067 | if err != nil { |
ozgecanetsia | 72e1c9f | 2021-05-26 17:26:29 +0300 | [diff] [blame] | 3068 | logger.Errorw(ctx, "error generating me instance id", |
| 3069 | log.Fields{"device-id": oFsm.deviceID, "error": err}) |
ozgecanetsia | 5c88b76 | 2021-03-23 10:27:15 +0300 | [diff] [blame] | 3070 | return err |
| 3071 | } |
Mahir Gunyel | 6781f96 | 2021-05-16 23:30:08 -0700 | [diff] [blame] | 3072 | logger.Debugw(ctx, "UniVlanConfigFsm create MulticastOperationProfile", |
| 3073 | log.Fields{"device-id": oFsm.deviceID, "EntityId": instID}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3074 | meParams := me.ParamData{ |
| 3075 | EntityID: instID, |
| 3076 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3077 | me.MulticastOperationsProfile_IgmpVersion: 2, |
| 3078 | me.MulticastOperationsProfile_IgmpFunction: 0, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3079 | //0 means false |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3080 | me.MulticastOperationsProfile_ImmediateLeave: 0, |
| 3081 | me.MulticastOperationsProfile_Robustness: 2, |
| 3082 | me.MulticastOperationsProfile_QuerierIpAddress: 0, |
| 3083 | me.MulticastOperationsProfile_QueryInterval: 125, |
| 3084 | me.MulticastOperationsProfile_QueryMaxResponseTime: 100, |
| 3085 | me.MulticastOperationsProfile_LastMemberQueryInterval: 10, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3086 | //0 means false |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3087 | me.MulticastOperationsProfile_UnauthorizedJoinRequestBehaviour: 0, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3088 | }, |
| 3089 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3090 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3091 | meInstance, err := oFsm.pOmciCC.SendCreateMulticastOperationProfileVar(context.TODO(), |
| 3092 | oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 3093 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3094 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3095 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3096 | logger.Errorw(ctx, "CreateMulticastOperationProfileVar create failed, aborting UniVlanConfigFsm!", |
| 3097 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3098 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3099 | return fmt.Errorf("createMulticastOperationProfileVar responseError %s, error %s", oFsm.deviceID, err) |
| 3100 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3101 | //accept also nil as (error) return value for writing to LastTx |
| 3102 | // - this avoids misinterpretation of new received OMCI messages |
| 3103 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3104 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3105 | //verify response |
ozgecanetsia | 5c88b76 | 2021-03-23 10:27:15 +0300 | [diff] [blame] | 3106 | err = oFsm.waitforOmciResponse(ctx) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3107 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3108 | logger.Errorw(ctx, "CreateMulticastOperationProfile create failed, aborting AniConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3109 | log.Fields{"device-id": oFsm.deviceID, "MulticastOperationProfileID": instID}) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3110 | return fmt.Errorf("createMulticastOperationProfile responseError %s, error %s", oFsm.deviceID, err) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3111 | } |
| 3112 | return nil |
| 3113 | } |
| 3114 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3115 | func (oFsm *UniVlanConfigFsm) performSettingMulticastOperationProfile(ctx context.Context, multicastGemPortID uint16, vlanID uint32) error { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3116 | instID, err := cmn.GenerateUNISideMBPCDEID(uint16(oFsm.pOnuUniPort.MacBpNo)) |
ozgecanetsia | 5c88b76 | 2021-03-23 10:27:15 +0300 | [diff] [blame] | 3117 | if err != nil { |
ozgecanetsia | 72e1c9f | 2021-05-26 17:26:29 +0300 | [diff] [blame] | 3118 | logger.Errorw(ctx, "error generating me instance id", |
| 3119 | log.Fields{"device-id": oFsm.deviceID, "error": err}) |
ozgecanetsia | 5c88b76 | 2021-03-23 10:27:15 +0300 | [diff] [blame] | 3120 | return err |
| 3121 | } |
Mahir Gunyel | 6781f96 | 2021-05-16 23:30:08 -0700 | [diff] [blame] | 3122 | logger.Debugw(ctx, "UniVlanConfigFsm set MulticastOperationProfile", |
| 3123 | log.Fields{"device-id": oFsm.deviceID, "EntityId": instID}) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3124 | //TODO check that this is correct |
| 3125 | // Table control |
| 3126 | //setCtrl = 1 |
| 3127 | //rowPartId = 0 |
| 3128 | //test = 0 |
| 3129 | //rowKey = 0 |
| 3130 | tableCtrlStr := "0100000000000000" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3131 | tableCtrl := cmn.AsByteSlice(tableCtrlStr) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3132 | dynamicAccessCL := make([]uint8, 24) |
| 3133 | copy(dynamicAccessCL, tableCtrl) |
| 3134 | //Multicast GemPortId |
| 3135 | binary.BigEndian.PutUint16(dynamicAccessCL[2:], multicastGemPortID) |
| 3136 | // python version waits for installation of flows, see line 723 onward of |
| 3137 | // brcm_openomci_onu_handler.py |
| 3138 | binary.BigEndian.PutUint16(dynamicAccessCL[4:], uint16(vlanID)) |
| 3139 | //Source IP all to 0 |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3140 | binary.BigEndian.PutUint32(dynamicAccessCL[6:], cmn.IPToInt32(net.IPv4(0, 0, 0, 0))) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3141 | //TODO start and end are hardcoded, get from TP |
| 3142 | // Destination IP address start of range |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3143 | binary.BigEndian.PutUint32(dynamicAccessCL[10:], cmn.IPToInt32(net.IPv4(225, 0, 0, 0))) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3144 | // Destination IP address end of range |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3145 | binary.BigEndian.PutUint32(dynamicAccessCL[14:], cmn.IPToInt32(net.IPv4(239, 255, 255, 255))) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3146 | //imputed group bandwidth |
| 3147 | binary.BigEndian.PutUint16(dynamicAccessCL[18:], 0) |
| 3148 | |
| 3149 | meParams := me.ParamData{ |
| 3150 | EntityID: instID, |
| 3151 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3152 | me.MulticastOperationsProfile_DynamicAccessControlListTable: dynamicAccessCL, |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3153 | }, |
| 3154 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3155 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3156 | meInstance, err := oFsm.pOmciCC.SendSetMulticastOperationProfileVar(context.TODO(), |
| 3157 | oFsm.pDeviceHandler.GetOmciTimeout(), true, |
| 3158 | oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3159 | if err != nil { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3160 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3161 | logger.Errorw(ctx, "SetMulticastOperationProfileVar set failed, aborting UniVlanConfigFsm!", |
| 3162 | log.Fields{"device-id": oFsm.deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3163 | _ = oFsm.PAdaptFsm.PFsm.Event(VlanEvReset) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3164 | return fmt.Errorf("setMulticastOperationProfile responseError %s, error %s", oFsm.deviceID, err) |
| 3165 | } |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3166 | //accept also nil as (error) return value for writing to LastTx |
| 3167 | // - this avoids misinterpretation of new received OMCI messages |
| 3168 | oFsm.pLastTxMeInstance = meInstance |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 3169 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3170 | //verify response |
ozgecanetsia | 5c88b76 | 2021-03-23 10:27:15 +0300 | [diff] [blame] | 3171 | err = oFsm.waitforOmciResponse(ctx) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3172 | if err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 3173 | logger.Errorw(ctx, "CreateMulticastOperationProfile create failed, aborting AniConfig FSM!", |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3174 | log.Fields{"device-id": oFsm.deviceID, "MulticastOperationProfileID": instID}) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 3175 | return fmt.Errorf("createMulticastOperationProfile responseError %s, error %s", oFsm.deviceID, err) |
ozgecanetsia | b5000ef | 2020-11-27 14:38:20 +0300 | [diff] [blame] | 3176 | } |
| 3177 | return nil |
| 3178 | } |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 3179 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 3180 | func (oFsm *UniVlanConfigFsm) createTrafficDescriptor(ctx context.Context, aMeter *of.OfpMeterConfig, |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3181 | tpID uint8, uniID uint8, gemPortID uint16) error { |
| 3182 | logger.Infow(ctx, "Starting create traffic descriptor", log.Fields{"device-id": oFsm.deviceID, "uniID": uniID, "tpID": tpID}) |
| 3183 | // uniTPKey generate id to Traffic Descriptor ME. We need to create two of them. They should be unique. Because of that |
| 3184 | // I created unique TD ID by flow direction. |
| 3185 | // TODO! Traffic descriptor ME ID will check |
| 3186 | trafficDescriptorID := gemPortID |
| 3187 | if aMeter == nil { |
| 3188 | return fmt.Errorf("meter not found %s", oFsm.deviceID) |
| 3189 | } |
| 3190 | trafficShapingInfo, err := meters.GetTrafficShapingInfo(ctx, aMeter) |
| 3191 | if err != nil { |
| 3192 | logger.Errorw(ctx, "Traffic Shaping Info get failed", log.Fields{"device-id": oFsm.deviceID}) |
| 3193 | return err |
| 3194 | } |
ozgecanetsia | f5c7684 | 2021-11-18 10:43:47 +0300 | [diff] [blame] | 3195 | cir := (trafficShapingInfo.Cir + trafficShapingInfo.Gir) * 125 // kbps --> bps --> Bps |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3196 | cbs := trafficShapingInfo.Cbs |
ozgecanetsia | f5c7684 | 2021-11-18 10:43:47 +0300 | [diff] [blame] | 3197 | pir := trafficShapingInfo.Pir * 125 // kbps --> bps --> Bps |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3198 | pbs := trafficShapingInfo.Pbs |
| 3199 | |
| 3200 | logger.Infow(ctx, "cir-pir-cbs-pbs", log.Fields{"device-id": oFsm.deviceID, "cir": cir, "pir": pir, "cbs": cbs, "pbs": pbs}) |
| 3201 | meParams := me.ParamData{ |
| 3202 | EntityID: trafficDescriptorID, |
| 3203 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3204 | me.TrafficDescriptor_Cir: cir, |
| 3205 | me.TrafficDescriptor_Pir: pir, |
| 3206 | me.TrafficDescriptor_Cbs: cbs, |
| 3207 | me.TrafficDescriptor_Pbs: pbs, |
| 3208 | me.TrafficDescriptor_ColourMode: 1, |
| 3209 | me.TrafficDescriptor_IngressColourMarking: 3, |
| 3210 | me.TrafficDescriptor_EgressColourMarking: 3, |
| 3211 | me.TrafficDescriptor_MeterType: 1, |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3212 | }, |
| 3213 | } |
Girish Gowdra | 754ffb1 | 2021-06-30 16:30:12 -0700 | [diff] [blame] | 3214 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3215 | meInstance, errCreateTD := oFsm.pOmciCC.SendCreateTDVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.GetOmciTimeout(), |
| 3216 | true, oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3217 | if errCreateTD != nil { |
Girish Gowdra | 754ffb1 | 2021-06-30 16:30:12 -0700 | [diff] [blame] | 3218 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3219 | logger.Errorw(ctx, "Traffic Descriptor create failed", log.Fields{"device-id": oFsm.deviceID}) |
| 3220 | return err |
| 3221 | } |
| 3222 | oFsm.pLastTxMeInstance = meInstance |
Girish Gowdra | 754ffb1 | 2021-06-30 16:30:12 -0700 | [diff] [blame] | 3223 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3224 | err = oFsm.waitforOmciResponse(ctx) |
| 3225 | if err != nil { |
| 3226 | logger.Errorw(ctx, "Traffic Descriptor create failed, aborting VlanConfig FSM!", log.Fields{"device-id": oFsm.deviceID}) |
| 3227 | return err |
| 3228 | } |
| 3229 | |
Girish Gowdra | 09e5f21 | 2021-09-30 16:28:36 -0700 | [diff] [blame] | 3230 | // Note: in the below request the gemport entity id is same as the gemport id and the traffic descriptor entity id is also same as gemport id |
| 3231 | err = oFsm.setTrafficDescriptorToGemPortNWCTP(ctx, gemPortID, gemPortID) |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3232 | if err != nil { |
| 3233 | logger.Errorw(ctx, "Traffic Descriptor set failed to Gem Port Network CTP, aborting VlanConfig FSM!", log.Fields{"device-id": oFsm.deviceID}) |
| 3234 | return err |
| 3235 | } |
| 3236 | logger.Infow(ctx, "Set TD Info to GemPortNWCTP successfully", log.Fields{"device-id": oFsm.deviceID, "gem-port-id": gemPortID, "td-id": trafficDescriptorID}) |
| 3237 | |
| 3238 | return nil |
| 3239 | } |
| 3240 | |
Girish Gowdra | 09e5f21 | 2021-09-30 16:28:36 -0700 | [diff] [blame] | 3241 | func (oFsm *UniVlanConfigFsm) setTrafficDescriptorToGemPortNWCTP(ctx context.Context, gemPortEntityID uint16, trafficDescriptorEntityID uint16) error { |
| 3242 | logger.Debugw(ctx, "Starting Set Traffic Descriptor to GemPortNWCTP", |
| 3243 | log.Fields{"device-id": oFsm.deviceID, "gem-port-entity-id": gemPortEntityID, "traffic-descriptor-entity-id": trafficDescriptorEntityID}) |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3244 | meParams := me.ParamData{ |
Girish Gowdra | 09e5f21 | 2021-09-30 16:28:36 -0700 | [diff] [blame] | 3245 | EntityID: gemPortEntityID, |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3246 | Attributes: me.AttributeValueMap{ |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3247 | me.GemPortNetworkCtp_TrafficDescriptorProfilePointerForUpstream: trafficDescriptorEntityID, |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3248 | }, |
| 3249 | } |
Girish Gowdra | 754ffb1 | 2021-06-30 16:30:12 -0700 | [diff] [blame] | 3250 | oFsm.mutexPLastTxMeInstance.Lock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3251 | meInstance, err := oFsm.pOmciCC.SendSetGemNCTPVar(log.WithSpanFromContext(context.TODO(), ctx), |
| 3252 | oFsm.pDeviceHandler.GetOmciTimeout(), true, oFsm.PAdaptFsm.CommChan, meParams) |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3253 | if err != nil { |
Girish Gowdra | 754ffb1 | 2021-06-30 16:30:12 -0700 | [diff] [blame] | 3254 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3255 | logger.Errorw(ctx, "GemNCTP set failed", log.Fields{"device-id": oFsm.deviceID}) |
| 3256 | return err |
| 3257 | } |
| 3258 | oFsm.pLastTxMeInstance = meInstance |
Girish Gowdra | 754ffb1 | 2021-06-30 16:30:12 -0700 | [diff] [blame] | 3259 | oFsm.mutexPLastTxMeInstance.Unlock() |
ozgecanetsia | 82b91a6 | 2021-05-21 18:54:49 +0300 | [diff] [blame] | 3260 | err = oFsm.waitforOmciResponse(ctx) |
| 3261 | if err != nil { |
| 3262 | logger.Errorw(ctx, "Upstream Traffic Descriptor set failed, aborting VlanConfig FSM!", log.Fields{"device-id": oFsm.deviceID}) |
| 3263 | return err |
| 3264 | } |
| 3265 | return nil |
| 3266 | } |
| 3267 | |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 3268 | // IsFlowRemovePending returns true if there are pending flows to remove, else false. |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 3269 | func (oFsm *UniVlanConfigFsm) IsFlowRemovePending(ctx context.Context, aFlowDeleteChannel chan<- bool) bool { |
| 3270 | if oFsm == nil { |
| 3271 | logger.Error(ctx, "no valid UniVlanConfigFsm!") |
| 3272 | return false |
| 3273 | } |
mpagenko | bb47bc2 | 2021-04-20 13:29:09 +0000 | [diff] [blame] | 3274 | oFsm.mutexFlowParams.Lock() |
| 3275 | defer oFsm.mutexFlowParams.Unlock() |
| 3276 | if len(oFsm.uniRemoveFlowsSlice) > 0 { |
| 3277 | //flow removal is still ongoing/pending |
| 3278 | oFsm.signalOnFlowDelete = true |
| 3279 | oFsm.flowDeleteChannel = aFlowDeleteChannel |
| 3280 | return true |
| 3281 | } |
| 3282 | return false |
Girish Gowdra | 26a4092 | 2021-01-29 17:14:34 -0800 | [diff] [blame] | 3283 | } |
Holger Hildebrandt | 968eb8f | 2021-09-17 07:41:12 +0000 | [diff] [blame] | 3284 | |
| 3285 | func (oFsm *UniVlanConfigFsm) reconcileVlanFilterList(ctx context.Context, aSetVid uint16) { |
| 3286 | // VOL-4342 - reconcile vlanFilterList[] for possible later flow removal |
| 3287 | if aSetVid == uint16(of.OfpVlanId_OFPVID_PRESENT) { |
| 3288 | logger.Debugw(ctx, "reconciling - transparent setup: no VTFD config was required", |
| 3289 | log.Fields{"device-id": oFsm.deviceID}) |
| 3290 | } else { |
| 3291 | oFsm.vlanFilterList[oFsm.numVlanFilterEntries] = aSetVid |
| 3292 | logger.Debugw(ctx, "reconciling - Vid of VTFD stored in list", log.Fields{ |
| 3293 | "index": oFsm.numVlanFilterEntries, |
| 3294 | "vid": strconv.FormatInt(int64(oFsm.vlanFilterList[oFsm.numVlanFilterEntries]), 16), |
| 3295 | "device-id": oFsm.deviceID}) |
| 3296 | oFsm.numVlanFilterEntries++ |
| 3297 | } |
| 3298 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3299 | |
Holger Hildebrandt | c192bc4 | 2021-10-28 14:38:31 +0000 | [diff] [blame] | 3300 | // pushReponseOnFlowResponseChannel pushes response on the response channel if available |
| 3301 | func (oFsm *UniVlanConfigFsm) pushReponseOnFlowResponseChannel(ctx context.Context, respChan *chan error, err error) { |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 3302 | if respChan != nil { |
| 3303 | // Do it in a non blocking fashion, so that in case the flow handler routine has shutdown for any reason, we do not block here |
| 3304 | select { |
| 3305 | case *respChan <- err: |
| 3306 | logger.Debugw(ctx, "submitted-response-for-flow", log.Fields{"device-id": oFsm.deviceID, "err": err}) |
| 3307 | default: |
| 3308 | } |
| 3309 | } |
| 3310 | } |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 3311 | |
| 3312 | // PrepareForGarbageCollection - remove references to prepare for garbage collection |
| 3313 | func (oFsm *UniVlanConfigFsm) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) { |
| 3314 | logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID}) |
| 3315 | oFsm.pDeviceHandler = nil |
| 3316 | oFsm.pOnuDeviceEntry = nil |
| 3317 | oFsm.pOmciCC = nil |
| 3318 | } |