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