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