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