Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 16 | package org.onosproject.driver.pipeline.ofdpa; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 17 | |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Lists; |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 20 | import com.google.common.collect.Sets; |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 21 | import org.apache.commons.lang3.tuple.Pair; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 22 | import org.onlab.osgi.ServiceDirectory; |
Jonghwan Hyun | 800d9d0 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 23 | import org.onlab.packet.EthType; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 24 | import org.onlab.packet.Ethernet; |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 25 | import org.onlab.packet.EthType.EtherType; |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 26 | import org.onlab.packet.IpAddress; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 27 | import org.onlab.packet.IpPrefix; |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 28 | import org.onlab.packet.MacAddress; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 29 | import org.onlab.packet.VlanId; |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 30 | import org.onlab.util.AbstractAccumulator; |
| 31 | import org.onlab.util.Accumulator; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 32 | import org.onlab.util.KryoNamespace; |
| 33 | import org.onosproject.core.ApplicationId; |
| 34 | import org.onosproject.core.CoreService; |
Jonghwan Hyun | 800d9d0 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 35 | import org.onosproject.driver.extensions.Ofdpa3CopyField; |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 36 | import org.onosproject.driver.extensions.Ofdpa3MplsType; |
| 37 | import org.onosproject.driver.extensions.Ofdpa3SetMplsType; |
Jonghwan Hyun | 800d9d0 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 38 | import org.onosproject.driver.extensions.OfdpaMatchActsetOutput; |
| 39 | import org.onosproject.driver.extensions.OfdpaMatchAllowVlanTranslation; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 40 | import org.onosproject.driver.extensions.OfdpaMatchVlanVid; |
| 41 | import org.onosproject.driver.extensions.OfdpaSetVlanVid; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 42 | import org.onosproject.net.DeviceId; |
| 43 | import org.onosproject.net.Port; |
| 44 | import org.onosproject.net.PortNumber; |
| 45 | import org.onosproject.net.behaviour.NextGroup; |
| 46 | import org.onosproject.net.behaviour.Pipeliner; |
| 47 | import org.onosproject.net.behaviour.PipelinerContext; |
| 48 | import org.onosproject.net.device.DeviceService; |
| 49 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 50 | import org.onosproject.net.flow.DefaultFlowRule; |
| 51 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 52 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 53 | import org.onosproject.net.flow.FlowRule; |
| 54 | import org.onosproject.net.flow.FlowRuleOperations; |
| 55 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 56 | import org.onosproject.net.flow.FlowRuleService; |
| 57 | import org.onosproject.net.flow.TrafficSelector; |
| 58 | import org.onosproject.net.flow.TrafficTreatment; |
| 59 | import org.onosproject.net.flow.criteria.Criteria; |
| 60 | import org.onosproject.net.flow.criteria.Criterion; |
| 61 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 62 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 63 | import org.onosproject.net.flow.criteria.IPCriterion; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 64 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; |
| 65 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 66 | import org.onosproject.net.flow.criteria.MplsBosCriterion; |
| 67 | import org.onosproject.net.flow.criteria.MplsCriterion; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 68 | import org.onosproject.net.flow.criteria.PortCriterion; |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 69 | import org.onosproject.net.flow.criteria.TcpPortCriterion; |
| 70 | import org.onosproject.net.flow.criteria.UdpPortCriterion; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 71 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 72 | import org.onosproject.net.flow.instructions.Instruction; |
| 73 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
Charles Chan | f76de30 | 2018-06-15 18:54:18 -0700 | [diff] [blame] | 74 | import org.onosproject.net.flow.instructions.Instructions.NoActionInstruction; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 75 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 76 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType; |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 77 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 78 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
| 79 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 80 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 81 | import org.onosproject.net.flowobjective.FlowObjectiveStore; |
| 82 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 83 | import org.onosproject.net.flowobjective.NextObjective; |
| 84 | import org.onosproject.net.flowobjective.Objective; |
| 85 | import org.onosproject.net.flowobjective.ObjectiveError; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 86 | import org.onosproject.net.group.DefaultGroupKey; |
| 87 | import org.onosproject.net.group.Group; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 88 | import org.onosproject.net.group.GroupKey; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 89 | import org.onosproject.net.group.GroupService; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 90 | import org.onosproject.store.serializers.KryoNamespaces; |
| 91 | import org.slf4j.Logger; |
| 92 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 93 | import java.util.ArrayDeque; |
| 94 | import java.util.ArrayList; |
| 95 | import java.util.Collection; |
| 96 | import java.util.Collections; |
| 97 | import java.util.Deque; |
| 98 | import java.util.List; |
| 99 | import java.util.Objects; |
Jonghwan Hyun | 800d9d0 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 100 | import java.util.Optional; |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 101 | import java.util.Timer; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 102 | import java.util.concurrent.ScheduledExecutorService; |
| 103 | import java.util.concurrent.TimeUnit; |
Harshada Chaundkar | cb78751 | 2019-08-05 15:33:30 +0000 | [diff] [blame] | 104 | import java.util.concurrent.atomic.AtomicBoolean; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 105 | |
| 106 | import static java.util.concurrent.Executors.newScheduledThreadPool; |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 107 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
pier | 5be3904 | 2019-10-04 10:54:07 +0200 | [diff] [blame] | 108 | import static org.onlab.packet.MacAddress.*; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 109 | import static org.onlab.util.Tools.groupedThreads; |
Jonghwan Hyun | 800d9d0 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 110 | import static org.onosproject.driver.extensions.Ofdpa3CopyField.OXM_ID_PACKET_REG_1; |
| 111 | import static org.onosproject.driver.extensions.Ofdpa3CopyField.OXM_ID_VLAN_VID; |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 112 | import static org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.*; |
pier | 9469f3e | 2019-04-17 17:05:08 +0200 | [diff] [blame] | 113 | import static org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.*; |
pier | 7afc752 | 2019-05-10 13:19:15 +0200 | [diff] [blame] | 114 | import static org.onosproject.net.flowobjective.ForwardingObjective.Flag.SPECIFIC; |
Pier Luigi | 075f101 | 2018-02-01 10:23:12 +0100 | [diff] [blame] | 115 | import static org.onosproject.net.group.GroupDescription.Type.SELECT; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 116 | import static org.slf4j.LoggerFactory.getLogger; |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 117 | import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_BOS; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 118 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 119 | /** |
| 120 | * Driver for Broadcom's OF-DPA v2.0 TTP. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 121 | */ |
Charles Chan | 361154b | 2016-03-24 10:23:39 -0700 | [diff] [blame] | 122 | public class Ofdpa2Pipeline extends AbstractHandlerBehaviour implements Pipeliner { |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 123 | // Timer for the accumulator |
| 124 | private static final Timer TIMER = new Timer("fwdobj-batching"); |
| 125 | private Accumulator<Pair<ForwardingObjective, Collection<FlowRule>>> accumulator; |
pier | 9469f3e | 2019-04-17 17:05:08 +0200 | [diff] [blame] | 126 | // Internal objects |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 127 | private final Logger log = getLogger(getClass()); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 128 | protected ServiceDirectory serviceDirectory; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 129 | protected FlowRuleService flowRuleService; |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 130 | protected CoreService coreService; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 131 | protected GroupService groupService; |
| 132 | protected FlowObjectiveStore flowObjectiveStore; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 133 | protected DeviceId deviceId; |
| 134 | protected ApplicationId driverId; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 135 | protected DeviceService deviceService; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 136 | protected static KryoNamespace appKryo = new KryoNamespace.Builder() |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 137 | .register(KryoNamespaces.API) |
| 138 | .register(GroupKey.class) |
| 139 | .register(DefaultGroupKey.class) |
| 140 | .register(OfdpaNextGroup.class) |
| 141 | .register(ArrayDeque.class) |
| 142 | .build("Ofdpa2Pipeline"); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 143 | |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 144 | protected Ofdpa2GroupHandler groupHandler; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 145 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 146 | // flows installations to be retried |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 147 | private ScheduledExecutorService retryExecutorService |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 148 | = newScheduledThreadPool(5, groupedThreads("OfdpaPipeliner", "retry-%d", log)); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 149 | |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 150 | // accumulator executor service |
| 151 | private ScheduledExecutorService accumulatorExecutorService |
| 152 | = newSingleThreadScheduledExecutor(groupedThreads("OfdpaPipeliner", "acc-%d", log)); |
| 153 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 154 | @Override |
| 155 | public void init(DeviceId deviceId, PipelinerContext context) { |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 156 | this.deviceId = deviceId; |
| 157 | |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 158 | serviceDirectory = context.directory(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 159 | coreService = serviceDirectory.get(CoreService.class); |
| 160 | flowRuleService = serviceDirectory.get(FlowRuleService.class); |
| 161 | groupService = serviceDirectory.get(GroupService.class); |
| 162 | flowObjectiveStore = context.store(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 163 | deviceService = serviceDirectory.get(DeviceService.class); |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 164 | // Init the accumulator, if enabled |
pier | 9469f3e | 2019-04-17 17:05:08 +0200 | [diff] [blame] | 165 | if (isAccumulatorEnabled(this)) { |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 166 | accumulator = new ForwardingObjectiveAccumulator(context.accumulatorMaxObjectives(), |
| 167 | context.accumulatorMaxBatchMillis(), |
| 168 | context.accumulatorMaxIdleMillis()); |
| 169 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 170 | |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 171 | initDriverId(); |
| 172 | initGroupHander(context); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 173 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 174 | initializePipeline(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 175 | } |
| 176 | |
pier | 7afc752 | 2019-05-10 13:19:15 +0200 | [diff] [blame] | 177 | void setupAccumulatorForTests(int maxFwd, int maxBatchMS, int maxIdleMS) { |
| 178 | if (accumulator == null) { |
| 179 | accumulator = new ForwardingObjectiveAccumulator(maxFwd, |
| 180 | maxBatchMS, |
| 181 | maxIdleMS); |
| 182 | } |
| 183 | } |
| 184 | |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 185 | protected void initDriverId() { |
| 186 | driverId = coreService.registerApplication( |
| 187 | "org.onosproject.driver.Ofdpa2Pipeline"); |
| 188 | } |
| 189 | |
| 190 | protected void initGroupHander(PipelinerContext context) { |
| 191 | groupHandler = new Ofdpa2GroupHandler(); |
| 192 | groupHandler.init(deviceId, context); |
| 193 | } |
| 194 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 195 | protected void initializePipeline() { |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 196 | // OF-DPA does not require initializing the pipeline as it puts default |
| 197 | // rules automatically in the hardware. However emulation of OFDPA in |
| 198 | // software switches does require table-miss-entries. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 201 | /** |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 202 | * Determines whether this pipeline requires MPLS POP instruction. |
| 203 | * |
| 204 | * @return true to use MPLS POP instruction |
| 205 | */ |
| 206 | public boolean requireMplsPop() { |
| 207 | return true; |
| 208 | } |
| 209 | |
| 210 | /** |
Harshada Chaundkar | cb78751 | 2019-08-05 15:33:30 +0000 | [diff] [blame] | 211 | * Determines whether this pipeline requires one additional flow matching on ethType 0x86dd in ACL table. |
| 212 | * |
| 213 | * @return true to create one additional flow matching on ethType 0x86dd in ACL table |
| 214 | */ |
| 215 | protected boolean requireEthType() { |
| 216 | return true; |
| 217 | } |
| 218 | |
| 219 | /** |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 220 | * Determines whether this pipeline requires MPLS BOS match. |
| 221 | * |
| 222 | * @return true to use MPLS BOS match |
| 223 | */ |
| 224 | public boolean requireMplsBosMatch() { |
| 225 | return true; |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Determines whether this pipeline requires MPLS TTL decrement and copy. |
| 230 | * |
| 231 | * @return true to use MPLS TTL decrement and copy |
| 232 | */ |
| 233 | public boolean requireMplsTtlModification() { |
| 234 | return true; |
| 235 | } |
| 236 | |
| 237 | /** |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 238 | * Determines whether this pipeline requires OFDPA match and set VLAN extensions. |
| 239 | * |
| 240 | * @return true to use the extensions |
| 241 | */ |
| 242 | protected boolean requireVlanExtensions() { |
| 243 | return true; |
| 244 | } |
| 245 | |
Saurav Das | 86d13e8 | 2017-04-28 17:03:48 -0700 | [diff] [blame] | 246 | /** |
| 247 | * Determines whether in-port should be matched on in TMAC table rules. |
| 248 | * |
| 249 | * @return true if match on in-port should be programmed |
| 250 | */ |
| 251 | protected boolean matchInPortTmacTable() { |
| 252 | return true; |
| 253 | } |
| 254 | |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 255 | /** |
| 256 | * Determines whether matching L4 destination port on IPv6 packets is supported in ACL table. |
| 257 | * |
| 258 | * @return true if matching L4 destination port on IPv6 packets is supported in ACL table. |
| 259 | */ |
| 260 | protected boolean supportIpv6L4Dst() { |
| 261 | return true; |
| 262 | } |
| 263 | |
Saurav Das | c568c34 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 264 | /** |
| 265 | * Determines whether this driver should continue to retry flows that point |
| 266 | * to empty groups. See CORD-554. |
| 267 | * |
| 268 | * @return true if the driver should retry flows |
| 269 | */ |
| 270 | protected boolean shouldRetry() { |
| 271 | return true; |
| 272 | } |
| 273 | |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 274 | /** |
| 275 | * Determines whether this driver requires unicast flow to be installed before multicast flow |
| 276 | * in TMAC table. |
| 277 | * |
| 278 | * @return true if required |
| 279 | */ |
| 280 | protected boolean requireUnicastBeforeMulticast() { |
| 281 | return false; |
| 282 | } |
| 283 | |
Andrea Campanella | d980c6d | 2018-04-30 11:48:55 +0200 | [diff] [blame] | 284 | /** |
| 285 | * Determines whether this driver supports installing a clearDeferred action on table 30. |
| 286 | * |
| 287 | * @return true if required |
| 288 | */ |
| 289 | protected boolean supportsUnicastBlackHole() { |
| 290 | return true; |
| 291 | } |
| 292 | |
Charles Chan | ab59160 | 2019-01-22 17:25:04 -0800 | [diff] [blame] | 293 | protected boolean requirePuntTable() { |
| 294 | return false; |
| 295 | } |
| 296 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 297 | ////////////////////////////////////// |
| 298 | // Flow Objectives |
| 299 | ////////////////////////////////////// |
| 300 | |
| 301 | @Override |
| 302 | public void filter(FilteringObjective filteringObjective) { |
| 303 | if (filteringObjective.type() == FilteringObjective.Type.PERMIT) { |
| 304 | processFilter(filteringObjective, |
| 305 | filteringObjective.op() == Objective.Operation.ADD, |
| 306 | filteringObjective.appId()); |
| 307 | } else { |
| 308 | // Note that packets that don't match the PERMIT filter are |
| 309 | // automatically denied. The DENY filter is used to deny packets |
| 310 | // that are otherwise permitted by the PERMIT filter. |
| 311 | // Use ACL table flow rules here for DENY filtering objectives |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 312 | log.warn("filter objective other than PERMIT currently not supported"); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 313 | fail(filteringObjective, ObjectiveError.UNSUPPORTED); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | @Override |
| 318 | public void forward(ForwardingObjective fwd) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 319 | Collection<FlowRule> rules = processForward(fwd); |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 320 | if (rules == null || rules.isEmpty()) { |
| 321 | // Assumes fail message has already been generated to the objective |
| 322 | // context. Returning here prevents spurious pass message to be |
| 323 | // generated by FlowRule service for empty flowOps. |
| 324 | return; |
| 325 | } |
pier | 7afc752 | 2019-05-10 13:19:15 +0200 | [diff] [blame] | 326 | // Let's accumulate flow rules if accumulator is active and fwd objective is not versatile. |
| 327 | // Otherwise send directly, without adding futher delay |
| 328 | if (accumulator != null && Objects.equals(fwd.flag(), SPECIFIC)) { |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 329 | accumulator.add(Pair.of(fwd, rules)); |
| 330 | } else { |
| 331 | sendForwards(Collections.singletonList(Pair.of(fwd, rules))); |
| 332 | } |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 333 | } |
| 334 | |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 335 | // Builds the batch using the accumulated flow rules |
| 336 | private void sendForwards(List<Pair<ForwardingObjective, Collection<FlowRule>>> pairs) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 337 | FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder(); |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 338 | log.debug("Sending {} fwd-objs", pairs.size()); |
| 339 | List<Objective> fwdObjs = Lists.newArrayList(); |
| 340 | // Iterates over all accumulated flow rules and then build an unique batch |
| 341 | pairs.forEach(pair -> { |
| 342 | ForwardingObjective fwd = pair.getLeft(); |
| 343 | Collection<FlowRule> rules = pair.getRight(); |
| 344 | switch (fwd.op()) { |
| 345 | case ADD: |
| 346 | rules.stream() |
| 347 | .filter(Objects::nonNull) |
| 348 | .forEach(flowOpsBuilder::add); |
| 349 | log.debug("Applying a add fwd-obj {} to sw:{}", fwd.id(), deviceId); |
| 350 | fwdObjs.add(fwd); |
| 351 | break; |
| 352 | case REMOVE: |
| 353 | rules.stream() |
| 354 | .filter(Objects::nonNull) |
| 355 | .forEach(flowOpsBuilder::remove); |
| 356 | log.debug("Deleting a flow rule to sw:{}", deviceId); |
| 357 | fwdObjs.add(fwd); |
| 358 | break; |
| 359 | default: |
| 360 | fail(fwd, ObjectiveError.UNKNOWN); |
| 361 | log.warn("Unknown forwarding type {}", fwd.op()); |
| 362 | } |
| 363 | }); |
| 364 | // Finally applies the operations |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 365 | flowRuleService.apply(flowOpsBuilder.build(new FlowRuleOperationsContext() { |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 366 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 367 | @Override |
| 368 | public void onSuccess(FlowRuleOperations ops) { |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 369 | log.trace("Flow rule operations onSuccess {}", ops); |
pier | 9469f3e | 2019-04-17 17:05:08 +0200 | [diff] [blame] | 370 | fwdObjs.forEach(OfdpaPipelineUtility::pass); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | @Override |
| 374 | public void onError(FlowRuleOperations ops) { |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 375 | ObjectiveError error = ObjectiveError.FLOWINSTALLATIONFAILED; |
| 376 | log.warn("Flow rule operations onError {}. Reason = {}", ops, error); |
| 377 | fwdObjs.forEach(fwdObj -> fail(fwdObj, error)); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 378 | } |
| 379 | })); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | @Override |
| 383 | public void next(NextObjective nextObjective) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 384 | NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id()); |
| 385 | switch (nextObjective.op()) { |
| 386 | case ADD: |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 387 | if (nextGroup != null) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 388 | log.warn("Cannot add next {} that already exists in device {}", |
| 389 | nextObjective.id(), deviceId); |
| 390 | return; |
| 391 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 392 | log.debug("Processing NextObjective id {} in dev {} - add group", |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 393 | nextObjective.id(), deviceId); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 394 | groupHandler.addGroup(nextObjective); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 395 | break; |
| 396 | case ADD_TO_EXISTING: |
| 397 | if (nextGroup != null) { |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 398 | log.debug("Processing NextObjective id {} in dev {} - add bucket", |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 399 | nextObjective.id(), deviceId); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 400 | groupHandler.addBucketToGroup(nextObjective, nextGroup); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 401 | } else { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 402 | // it is possible that group-chain has not been fully created yet |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 403 | log.debug("Waiting to add bucket to group for next-id:{} in dev:{}", |
| 404 | nextObjective.id(), deviceId); |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 405 | |
| 406 | // by design multiple pending bucket is allowed for the group |
| 407 | groupHandler.pendingBuckets.compute(nextObjective.id(), (nextId, pendBkts) -> { |
| 408 | if (pendBkts == null) { |
| 409 | pendBkts = Sets.newHashSet(); |
| 410 | } |
| 411 | pendBkts.add(nextObjective); |
| 412 | return pendBkts; |
| 413 | }); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 414 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 415 | break; |
| 416 | case REMOVE: |
| 417 | if (nextGroup == null) { |
| 418 | log.warn("Cannot remove next {} that does not exist in device {}", |
| 419 | nextObjective.id(), deviceId); |
| 420 | return; |
| 421 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 422 | log.debug("Processing NextObjective id {} in dev {} - remove group", |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 423 | nextObjective.id(), deviceId); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 424 | groupHandler.removeGroup(nextObjective, nextGroup); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 425 | break; |
| 426 | case REMOVE_FROM_EXISTING: |
| 427 | if (nextGroup == null) { |
| 428 | log.warn("Cannot remove from next {} that does not exist in device {}", |
| 429 | nextObjective.id(), deviceId); |
| 430 | return; |
| 431 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 432 | log.debug("Processing NextObjective id {} in dev {} - remove bucket", |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 433 | nextObjective.id(), deviceId); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 434 | groupHandler.removeBucketFromGroup(nextObjective, nextGroup); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 435 | break; |
Jonghwan Hyun | f810a7a | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 436 | case MODIFY: |
| 437 | if (nextGroup == null) { |
| 438 | log.warn("Cannot modify next {} that does not exist in device {}", |
| 439 | nextObjective.id(), deviceId); |
| 440 | return; |
| 441 | } |
Ruchi Sahota | ef0761c | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 442 | log.debug("Processing NextObjective id {} in dev {} group {} - modify bucket", |
| 443 | nextObjective.id(), deviceId, nextGroup); |
Jonghwan Hyun | f810a7a | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 444 | groupHandler.modifyBucketFromGroup(nextObjective, nextGroup); |
| 445 | break; |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 446 | case VERIFY: |
| 447 | if (nextGroup == null) { |
| 448 | log.warn("Cannot verify next {} that does not exist in device {}", |
| 449 | nextObjective.id(), deviceId); |
| 450 | return; |
| 451 | } |
| 452 | log.debug("Processing NextObjective id {} in dev {} - verify", |
| 453 | nextObjective.id(), deviceId); |
| 454 | groupHandler.verifyGroup(nextObjective, nextGroup); |
| 455 | break; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 456 | default: |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 457 | log.warn("Unsupported operation {}", nextObjective.op()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | |
| 461 | ////////////////////////////////////// |
| 462 | // Flow handling |
| 463 | ////////////////////////////////////// |
| 464 | |
| 465 | /** |
Yi Tseng | 0fdc07e | 2017-04-24 19:17:08 -0700 | [diff] [blame] | 466 | * As per OFDPA 2.0 TTP, filtering of VLAN ids and MAC addresses (for routing) |
| 467 | * configured on switch ports happen in different tables. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 468 | * |
| 469 | * @param filt the filtering objective |
| 470 | * @param install indicates whether to add or remove the objective |
| 471 | * @param applicationId the application that sent this objective |
| 472 | */ |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 473 | protected void processFilter(FilteringObjective filt, |
| 474 | boolean install, ApplicationId applicationId) { |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 475 | // This driver only processes filtering criteria defined with switch |
| 476 | // ports as the key |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 477 | PortCriterion portCriterion = null; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 478 | EthCriterion ethCriterion = null; |
| 479 | VlanIdCriterion vidCriterion = null; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 480 | if (!filt.key().equals(Criteria.dummy()) && |
| 481 | filt.key().type() == Criterion.Type.IN_PORT) { |
| 482 | portCriterion = (PortCriterion) filt.key(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 483 | } |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 484 | if (portCriterion == null) { |
| 485 | log.debug("No IN_PORT defined in filtering objective from app: {}", |
| 486 | applicationId); |
| 487 | } else { |
| 488 | log.debug("Received filtering objective for dev/port: {}/{}", deviceId, |
| 489 | portCriterion.port()); |
| 490 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 491 | // convert filtering conditions for switch-intfs into flowrules |
| 492 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 493 | for (Criterion criterion : filt.conditions()) { |
Yi Tseng | 0fdc07e | 2017-04-24 19:17:08 -0700 | [diff] [blame] | 494 | switch (criterion.type()) { |
| 495 | case ETH_DST: |
| 496 | case ETH_DST_MASKED: |
| 497 | ethCriterion = (EthCriterion) criterion; |
| 498 | break; |
| 499 | case VLAN_VID: |
| 500 | vidCriterion = (VlanIdCriterion) criterion; |
| 501 | break; |
| 502 | default: |
| 503 | log.warn("Unsupported filter {}", criterion); |
| 504 | fail(filt, ObjectiveError.UNSUPPORTED); |
| 505 | return; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 509 | VlanId assignedVlan = null; |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 510 | if (vidCriterion != null) { |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 511 | // Use the VLAN in criterion if metadata is not present and the traffic is tagged |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 512 | if (!vidCriterion.vlanId().equals(VlanId.NONE)) { |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 513 | assignedVlan = vidCriterion.vlanId(); |
Pier | e5bff48 | 2018-03-07 11:42:50 +0100 | [diff] [blame] | 514 | } |
| 515 | // If the meta VLAN is present let's update the assigned vlan |
| 516 | if (filt.meta() != null) { |
| 517 | VlanId metaVlan = readVlanFromTreatment(filt.meta()); |
| 518 | if (metaVlan != null) { |
| 519 | assignedVlan = metaVlan; |
| 520 | } |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 521 | } |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 522 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 523 | if (assignedVlan == null) { |
| 524 | log.error("Driver fails to extract VLAN information. " |
Frank Wang | d8ab096 | 2017-08-11 11:09:30 +0800 | [diff] [blame] | 525 | + "Not processing VLAN filters on device {}.", deviceId); |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 526 | log.debug("VLAN ID in criterion={}, metadata={}", |
| 527 | readVlanFromTreatment(filt.meta()), vidCriterion.vlanId()); |
| 528 | fail(filt, ObjectiveError.BADPARAMS); |
| 529 | return; |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
Yi Tseng | 3a77b4f | 2017-02-06 15:02:17 -0800 | [diff] [blame] | 533 | if (ethCriterion == null || ethCriterion.mac().equals(NONE)) { |
Charles Chan | 985b12e | 2016-05-11 19:47:22 -0700 | [diff] [blame] | 534 | // NOTE: it is possible that a filtering objective only has vidCriterion |
Daniel Ginsburg | c1d47e9 | 2018-04-30 19:27:19 -0400 | [diff] [blame] | 535 | log.debug("filtering objective missing dstMac, won't program TMAC table"); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 536 | } else { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 537 | MacAddress unicastMac = readEthDstFromTreatment(filt.meta()); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 538 | List<List<FlowRule>> allStages = processEthDstFilter(portCriterion, ethCriterion, |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 539 | vidCriterion, assignedVlan, unicastMac, applicationId); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 540 | for (List<FlowRule> flowRules : allStages) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 541 | log.trace("Starting a new flow rule stage for TMAC table flow"); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 542 | ops.newStage(); |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 543 | |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 544 | for (FlowRule flowRule : flowRules) { |
pier | 5be3904 | 2019-10-04 10:54:07 +0200 | [diff] [blame] | 545 | log.trace("{} flow rule in TMAC table: {} for dev: {}", |
| 546 | (install) ? "adding" : "removing", flowRule, deviceId); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 547 | if (install) { |
| 548 | ops = ops.add(flowRule); |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 549 | } else { |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 550 | // NOTE: Only remove TMAC flow when there is no more enabled port within the |
| 551 | // same VLAN on this device if TMAC doesn't support matching on in_port. |
pier | 5be3904 | 2019-10-04 10:54:07 +0200 | [diff] [blame] | 552 | if (filt.meta() != null && filt.meta().clearedDeferred()) { |
| 553 | // TMac mcast does not match on the input port - we have to remove it |
| 554 | // only if this is the last port |
| 555 | FlowRule rule = buildTmacRuleForMcastFromUnicast(flowRule, applicationId); |
| 556 | // IPv6 or IPv4 tmac rule |
| 557 | if (rule != null) { |
| 558 | // Add first the mcast rule and then open a new stage for the unicast |
| 559 | ops = ops.remove(rule); |
| 560 | ops.newStage(); |
| 561 | } |
| 562 | ops = ops.remove(flowRule); |
| 563 | } else if (matchInPortTmacTable()) { |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 564 | ops = ops.remove(flowRule); |
| 565 | } else { |
pier | 5be3904 | 2019-10-04 10:54:07 +0200 | [diff] [blame] | 566 | log.debug("Abort TMAC flow removal on {}. " + |
| 567 | "Some other ports still share this TMAC flow", deviceId); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 568 | } |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 569 | } |
| 570 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | |
Charles Chan | 985b12e | 2016-05-11 19:47:22 -0700 | [diff] [blame] | 574 | if (vidCriterion == null) { |
| 575 | // NOTE: it is possible that a filtering objective only has ethCriterion |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 576 | log.info("filtering objective missing VLAN, cannot program VLAN Table"); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 577 | } else { |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 578 | List<List<FlowRule>> allStages = processVlanIdFilter( |
pier | 6aef5b7 | 2019-06-10 17:10:26 +0200 | [diff] [blame] | 579 | portCriterion, vidCriterion, assignedVlan, applicationId, install); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 580 | for (List<FlowRule> flowRules : allStages) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 581 | log.trace("Starting a new flow rule stage for VLAN table flow"); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 582 | ops.newStage(); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 583 | |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 584 | for (FlowRule flowRule : flowRules) { |
| 585 | log.trace("{} flow rules in VLAN table: {} for dev: {}", |
| 586 | (install) ? "adding" : "removing", flowRule, deviceId); |
| 587 | ops = install ? ops.add(flowRule) : ops.remove(flowRule); |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 588 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 592 | // apply filtering flow rules |
| 593 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 594 | @Override |
| 595 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 596 | log.debug("Applied {} filtering rules in device {}", |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 597 | ops.stages().get(0).size(), deviceId); |
| 598 | pass(filt); |
| 599 | } |
| 600 | |
| 601 | @Override |
| 602 | public void onError(FlowRuleOperations ops) { |
| 603 | log.info("Failed to apply all filtering rules in dev {}", deviceId); |
| 604 | fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 605 | } |
| 606 | })); |
| 607 | |
| 608 | } |
| 609 | |
| 610 | /** |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 611 | * Internal implementation of processVlanIdFilter. |
| 612 | * <p> |
| 613 | * The is_present bit in set_vlan_vid action is required to be 0 in OFDPA i12. |
| 614 | * Since it is non-OF spec, we need an extension treatment for that. |
| 615 | * The useVlanExtension must be set to false for OFDPA i12. |
| 616 | * </p> |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 617 | * <p> |
| 618 | * NOTE: Separate VLAN filtering rules and assignment rules |
| 619 | * into different stages in order to guarantee that filtering rules |
| 620 | * always go first, as required by OFDPA. |
| 621 | * </p> |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 622 | * |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 623 | * @param portCriterion port on device for which this filter is programmed |
| 624 | * @param vidCriterion vlan assigned to port, or NONE for untagged |
| 625 | * @param assignedVlan assigned vlan-id for untagged packets |
| 626 | * @param applicationId for application programming this filter |
pier | 6aef5b7 | 2019-06-10 17:10:26 +0200 | [diff] [blame] | 627 | * @param install indicates whether to add or remove the objective |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 628 | * @return stages of flow rules for port-vlan filters |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 629 | */ |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 630 | protected List<List<FlowRule>> processVlanIdFilter(PortCriterion portCriterion, |
pier | 6aef5b7 | 2019-06-10 17:10:26 +0200 | [diff] [blame] | 631 | VlanIdCriterion vidCriterion, |
| 632 | VlanId assignedVlan, |
| 633 | ApplicationId applicationId, |
| 634 | boolean install) { |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 635 | List<FlowRule> filteringRules = new ArrayList<>(); |
| 636 | List<FlowRule> assignmentRules = new ArrayList<>(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 637 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 638 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 639 | TrafficSelector.Builder preSelector = null; |
| 640 | TrafficTreatment.Builder preTreatment = null; |
| 641 | |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 642 | treatment.transition(TMAC_TABLE); |
| 643 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 644 | if (vidCriterion.vlanId() == VlanId.NONE) { |
| 645 | // untagged packets are assigned vlans |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 646 | preSelector = DefaultTrafficSelector.builder(); |
| 647 | if (requireVlanExtensions()) { |
| 648 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(VlanId.NONE); |
| 649 | selector.extension(ofdpaMatchVlanVid, deviceId); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 650 | OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(assignedVlan); |
| 651 | treatment.extension(ofdpaSetVlanVid, deviceId); |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 652 | |
| 653 | OfdpaMatchVlanVid preOfdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan); |
| 654 | preSelector.extension(preOfdpaMatchVlanVid, deviceId); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 655 | } else { |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 656 | selector.matchVlanId(VlanId.NONE); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 657 | treatment.setVlanId(assignedVlan); |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 658 | |
| 659 | preSelector.matchVlanId(assignedVlan); |
| 660 | } |
| 661 | preTreatment = DefaultTrafficTreatment.builder().transition(TMAC_TABLE); |
| 662 | } else { |
| 663 | if (requireVlanExtensions()) { |
| 664 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vidCriterion.vlanId()); |
| 665 | selector.extension(ofdpaMatchVlanVid, deviceId); |
| 666 | } else { |
| 667 | selector.matchVlanId(vidCriterion.vlanId()); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 668 | } |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 669 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 670 | if (!assignedVlan.equals(vidCriterion.vlanId())) { |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 671 | if (requireVlanExtensions()) { |
Charles Chan | c03782d | 2017-01-31 13:57:55 -0800 | [diff] [blame] | 672 | OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(assignedVlan); |
| 673 | treatment.extension(ofdpaSetVlanVid, deviceId); |
| 674 | } else { |
| 675 | treatment.setVlanId(assignedVlan); |
| 676 | } |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 677 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 678 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 679 | |
| 680 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 681 | // rules for each port. |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 682 | List<PortNumber> portnums = new ArrayList<>(); |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 683 | if (portCriterion != null) { |
| 684 | if (PortNumber.ALL.equals(portCriterion.port())) { |
| 685 | for (Port port : deviceService.getPorts(deviceId)) { |
| 686 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 687 | portnums.add(port.number()); |
| 688 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 689 | } |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 690 | } else { |
| 691 | portnums.add(portCriterion.port()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 692 | } |
| 693 | } else { |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 694 | log.warn("Filtering Objective missing Port Criterion . " + |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 695 | "VLAN Table cannot be programmed for {}", deviceId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 696 | } |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 697 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 698 | for (PortNumber pnum : portnums) { |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 699 | // create rest of flowrule |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 700 | selector.matchInPort(pnum); |
| 701 | FlowRule rule = DefaultFlowRule.builder() |
| 702 | .forDevice(deviceId) |
| 703 | .withSelector(selector.build()) |
| 704 | .withTreatment(treatment.build()) |
| 705 | .withPriority(DEFAULT_PRIORITY) |
| 706 | .fromApp(applicationId) |
| 707 | .makePermanent() |
| 708 | .forTable(VLAN_TABLE).build(); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 709 | assignmentRules.add(rule); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 710 | |
| 711 | if (preSelector != null) { |
| 712 | preSelector.matchInPort(pnum); |
| 713 | FlowRule preRule = DefaultFlowRule.builder() |
| 714 | .forDevice(deviceId) |
| 715 | .withSelector(preSelector.build()) |
| 716 | .withTreatment(preTreatment.build()) |
| 717 | .withPriority(DEFAULT_PRIORITY) |
| 718 | .fromApp(applicationId) |
| 719 | .makePermanent() |
| 720 | .forTable(VLAN_TABLE).build(); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 721 | filteringRules.add(preRule); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 722 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 723 | } |
pier | 6aef5b7 | 2019-06-10 17:10:26 +0200 | [diff] [blame] | 724 | return install ? ImmutableList.of(filteringRules, assignmentRules) : |
| 725 | ImmutableList.of(assignmentRules, filteringRules); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | /** |
| 729 | * Allows routed packets with correct destination MAC to be directed |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 730 | * to unicast routing table, multicast routing table or MPLS forwarding table. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 731 | * |
| 732 | * @param portCriterion port on device for which this filter is programmed |
| 733 | * @param ethCriterion dstMac of device for which is filter is programmed |
| 734 | * @param vidCriterion vlan assigned to port, or NONE for untagged |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 735 | * @param assignedVlan assigned vlan-id for untagged packets |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 736 | * @param unicastMac some switches require a unicast TMAC flow to be programmed before multicast |
| 737 | * TMAC flow. This MAC address will be used for the unicast TMAC flow. |
| 738 | * This is unused if the filtering objective is a unicast. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 739 | * @param applicationId for application programming this filter |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 740 | * @return stages of flow rules for port-vlan filters |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 741 | |
| 742 | */ |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 743 | protected List<List<FlowRule>> processEthDstFilter(PortCriterion portCriterion, |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 744 | EthCriterion ethCriterion, |
| 745 | VlanIdCriterion vidCriterion, |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 746 | VlanId assignedVlan, |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 747 | MacAddress unicastMac, |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 748 | ApplicationId applicationId) { |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 749 | // Consider PortNumber.ANY as wildcard. Match ETH_DST only |
Sivachidambaram Subramanian | c598d06 | 2017-05-16 22:42:06 +0530 | [diff] [blame] | 750 | if (portCriterion != null && PortNumber.ANY.equals(portCriterion.port())) { |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 751 | return processEthDstOnlyFilter(ethCriterion, applicationId); |
| 752 | } |
| 753 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 754 | // Multicast MAC |
| 755 | if (ethCriterion.mask() != null) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 756 | return processMcastEthDstFilter(ethCriterion, assignedVlan, unicastMac, applicationId); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 759 | //handling untagged packets via assigned VLAN |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 760 | if (vidCriterion != null && vidCriterion.vlanId() == VlanId.NONE) { |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 761 | vidCriterion = (VlanIdCriterion) Criteria.matchVlanId(assignedVlan); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 762 | } |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 763 | List<FlowRule> rules = new ArrayList<>(); |
| 764 | OfdpaMatchVlanVid ofdpaMatchVlanVid = null; |
| 765 | if (vidCriterion != null && requireVlanExtensions()) { |
| 766 | ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vidCriterion.vlanId()); |
| 767 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 768 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 769 | // rules for each port. |
Yuta HIGUCHI | 2dce08a | 2017-04-20 21:57:48 -0700 | [diff] [blame] | 770 | List<PortNumber> portnums = new ArrayList<>(); |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 771 | if (portCriterion != null) { |
| 772 | if (PortNumber.ALL.equals(portCriterion.port())) { |
| 773 | for (Port port : deviceService.getPorts(deviceId)) { |
| 774 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 775 | portnums.add(port.number()); |
| 776 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 777 | } |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 778 | } else { |
| 779 | portnums.add(portCriterion.port()); |
| 780 | } |
| 781 | for (PortNumber pnum : portnums) { |
| 782 | rules.add(buildTmacRuleForIpv4(ethCriterion, |
| 783 | vidCriterion, |
| 784 | ofdpaMatchVlanVid, |
| 785 | applicationId, |
| 786 | pnum)); |
| 787 | rules.add(buildTmacRuleForMpls(ethCriterion, |
| 788 | vidCriterion, |
| 789 | ofdpaMatchVlanVid, |
| 790 | applicationId, |
| 791 | pnum)); |
| 792 | rules.add(buildTmacRuleForIpv6(ethCriterion, |
| 793 | vidCriterion, |
| 794 | ofdpaMatchVlanVid, |
| 795 | applicationId, |
| 796 | pnum)); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 797 | } |
| 798 | } else { |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 799 | rules.add(buildTmacRuleForIpv4(ethCriterion, |
| 800 | vidCriterion, |
| 801 | ofdpaMatchVlanVid, |
| 802 | applicationId, |
| 803 | null)); |
| 804 | rules.add(buildTmacRuleForMpls(ethCriterion, |
| 805 | vidCriterion, |
| 806 | ofdpaMatchVlanVid, |
| 807 | applicationId, |
| 808 | null)); |
| 809 | rules.add(buildTmacRuleForIpv6(ethCriterion, |
| 810 | vidCriterion, |
| 811 | ofdpaMatchVlanVid, |
| 812 | applicationId, |
| 813 | null)); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 814 | } |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 815 | return ImmutableList.of(rules); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 818 | /** |
| 819 | * Builds TMAC rules for IPv4 packets. |
| 820 | * |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 821 | * @param ethCriterion dst mac matching |
| 822 | * @param vidCriterion vlan id assigned to the port |
| 823 | * @param ofdpaMatchVlanVid OFDPA vlan id matching |
| 824 | * @param applicationId application id |
| 825 | * @param pnum port number |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 826 | * @return TMAC rule for IPV4 packets |
| 827 | */ |
| 828 | private FlowRule buildTmacRuleForIpv4(EthCriterion ethCriterion, |
| 829 | VlanIdCriterion vidCriterion, |
| 830 | OfdpaMatchVlanVid ofdpaMatchVlanVid, |
| 831 | ApplicationId applicationId, |
| 832 | PortNumber pnum) { |
| 833 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 834 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 835 | if (pnum != null) { |
| 836 | if (matchInPortTmacTable()) { |
| 837 | selector.matchInPort(pnum); |
| 838 | } else { |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 839 | log.debug("Pipeline does not support IN_PORT matching in TMAC table, " + |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 840 | "ignoring the IN_PORT criteria"); |
| 841 | } |
| 842 | } |
| 843 | if (vidCriterion != null) { |
| 844 | if (requireVlanExtensions()) { |
| 845 | selector.extension(ofdpaMatchVlanVid, deviceId); |
| 846 | } else { |
| 847 | selector.matchVlanId(vidCriterion.vlanId()); |
| 848 | } |
| 849 | } |
| 850 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 851 | selector.matchEthDst(ethCriterion.mac()); |
| 852 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 853 | return DefaultFlowRule.builder() |
| 854 | .forDevice(deviceId) |
| 855 | .withSelector(selector.build()) |
| 856 | .withTreatment(treatment.build()) |
| 857 | .withPriority(DEFAULT_PRIORITY) |
| 858 | .fromApp(applicationId) |
| 859 | .makePermanent() |
| 860 | .forTable(TMAC_TABLE).build(); |
| 861 | } |
| 862 | |
| 863 | /** |
| 864 | * Builds TMAC rule for MPLS packets. |
| 865 | * |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 866 | * @param ethCriterion dst mac matching |
| 867 | * @param vidCriterion vlan id assigned to the port |
| 868 | * @param ofdpaMatchVlanVid OFDPA vlan id matching |
| 869 | * @param applicationId application id |
| 870 | * @param pnum port number |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 871 | * @return TMAC rule for MPLS packets |
| 872 | */ |
| 873 | private FlowRule buildTmacRuleForMpls(EthCriterion ethCriterion, |
| 874 | VlanIdCriterion vidCriterion, |
| 875 | OfdpaMatchVlanVid ofdpaMatchVlanVid, |
| 876 | ApplicationId applicationId, |
| 877 | PortNumber pnum) { |
| 878 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 879 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 880 | if (pnum != null) { |
| 881 | if (matchInPortTmacTable()) { |
| 882 | selector.matchInPort(pnum); |
| 883 | } else { |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 884 | log.debug("Pipeline does not support IN_PORT matching in TMAC table, " + |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 885 | "ignoring the IN_PORT criteria"); |
| 886 | } |
| 887 | } |
| 888 | if (vidCriterion != null) { |
| 889 | if (requireVlanExtensions()) { |
| 890 | selector.extension(ofdpaMatchVlanVid, deviceId); |
| 891 | } else { |
| 892 | selector.matchVlanId(vidCriterion.vlanId()); |
| 893 | } |
| 894 | } |
| 895 | selector.matchEthType(Ethernet.MPLS_UNICAST); |
| 896 | selector.matchEthDst(ethCriterion.mac()); |
| 897 | treatment.transition(MPLS_TABLE_0); |
| 898 | return DefaultFlowRule.builder() |
| 899 | .forDevice(deviceId) |
| 900 | .withSelector(selector.build()) |
| 901 | .withTreatment(treatment.build()) |
| 902 | .withPriority(DEFAULT_PRIORITY) |
| 903 | .fromApp(applicationId) |
| 904 | .makePermanent() |
| 905 | .forTable(TMAC_TABLE).build(); |
| 906 | } |
| 907 | |
| 908 | /** |
| 909 | * Builds TMAC rules for IPv6 packets. |
| 910 | * |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 911 | * @param ethCriterion dst mac matching |
| 912 | * @param vidCriterion vlan id assigned to the port |
| 913 | * @param ofdpaMatchVlanVid OFDPA vlan id matching |
| 914 | * @param applicationId application id |
| 915 | * @param pnum port number |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 916 | * @return TMAC rule for IPV6 packets |
| 917 | */ |
| 918 | private FlowRule buildTmacRuleForIpv6(EthCriterion ethCriterion, |
| 919 | VlanIdCriterion vidCriterion, |
| 920 | OfdpaMatchVlanVid ofdpaMatchVlanVid, |
| 921 | ApplicationId applicationId, |
| 922 | PortNumber pnum) { |
| 923 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 924 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 925 | if (pnum != null) { |
| 926 | if (matchInPortTmacTable()) { |
| 927 | selector.matchInPort(pnum); |
| 928 | } else { |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 929 | log.debug("Pipeline does not support IN_PORT matching in TMAC table, " + |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 930 | "ignoring the IN_PORT criteria"); |
| 931 | } |
| 932 | } |
| 933 | if (vidCriterion != null) { |
| 934 | if (requireVlanExtensions()) { |
| 935 | selector.extension(ofdpaMatchVlanVid, deviceId); |
| 936 | } else { |
| 937 | selector.matchVlanId(vidCriterion.vlanId()); |
| 938 | } |
| 939 | } |
| 940 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 941 | selector.matchEthDst(ethCriterion.mac()); |
| 942 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 943 | return DefaultFlowRule.builder() |
| 944 | .forDevice(deviceId) |
| 945 | .withSelector(selector.build()) |
| 946 | .withTreatment(treatment.build()) |
| 947 | .withPriority(DEFAULT_PRIORITY) |
| 948 | .fromApp(applicationId) |
| 949 | .makePermanent() |
| 950 | .forTable(TMAC_TABLE).build(); |
| 951 | } |
| 952 | |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 953 | protected List<List<FlowRule>> processEthDstOnlyFilter(EthCriterion ethCriterion, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 954 | ApplicationId applicationId) { |
Pier Luigi | 0e35863 | 2017-01-31 09:35:05 -0800 | [diff] [blame] | 955 | ImmutableList.Builder<FlowRule> builder = ImmutableList.builder(); |
| 956 | |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 957 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 958 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 959 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 960 | selector.matchEthDst(ethCriterion.mac()); |
| 961 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 962 | FlowRule rule = DefaultFlowRule.builder() |
| 963 | .forDevice(deviceId) |
| 964 | .withSelector(selector.build()) |
| 965 | .withTreatment(treatment.build()) |
| 966 | .withPriority(DEFAULT_PRIORITY) |
| 967 | .fromApp(applicationId) |
| 968 | .makePermanent() |
| 969 | .forTable(TMAC_TABLE).build(); |
Pier Luigi | 0e35863 | 2017-01-31 09:35:05 -0800 | [diff] [blame] | 970 | builder.add(rule); |
| 971 | |
| 972 | selector = DefaultTrafficSelector.builder(); |
| 973 | treatment = DefaultTrafficTreatment.builder(); |
| 974 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 975 | selector.matchEthDst(ethCriterion.mac()); |
| 976 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 977 | rule = DefaultFlowRule.builder() |
| 978 | .forDevice(deviceId) |
| 979 | .withSelector(selector.build()) |
| 980 | .withTreatment(treatment.build()) |
| 981 | .withPriority(DEFAULT_PRIORITY) |
| 982 | .fromApp(applicationId) |
| 983 | .makePermanent() |
| 984 | .forTable(TMAC_TABLE).build(); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 985 | return ImmutableList.of(builder.add(rule).build()); |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 986 | } |
| 987 | |
pier | 5be3904 | 2019-10-04 10:54:07 +0200 | [diff] [blame] | 988 | private FlowRule buildTmacRuleForMcastFromUnicast(FlowRule tmacRuleForUnicast, ApplicationId applicationId) { |
| 989 | final TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 990 | final TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 991 | FlowRule rule; |
| 992 | // Build the selector |
| 993 | for (Criterion criterion : tmacRuleForUnicast.selector().criteria()) { |
| 994 | if (criterion instanceof VlanIdCriterion) { |
| 995 | if (requireVlanExtensions()) { |
| 996 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(((VlanIdCriterion) criterion).vlanId()); |
| 997 | selector.extension(ofdpaMatchVlanVid, deviceId); |
| 998 | } else { |
| 999 | selector.add(criterion); |
| 1000 | } |
| 1001 | } else if (criterion instanceof EthTypeCriterion) { |
| 1002 | selector.add(criterion); |
| 1003 | if (Objects.equals(((EthTypeCriterion) criterion).ethType(), |
| 1004 | EtherType.IPV4.ethType())) { |
| 1005 | selector.matchEthDstMasked(IPV4_MULTICAST, IPV4_MULTICAST_MASK); |
| 1006 | } else if (Objects.equals(((EthTypeCriterion) criterion).ethType(), |
| 1007 | EtherType.IPV6.ethType())) { |
| 1008 | selector.matchEthDstMasked(IPV6_MULTICAST, IPV6_MULTICAST_MASK); |
| 1009 | } else { |
| 1010 | // We don't need for mpls rules |
| 1011 | return null; |
| 1012 | } |
| 1013 | } |
| 1014 | } |
| 1015 | // Build the treatment |
| 1016 | treatment.transition(MULTICAST_ROUTING_TABLE); |
| 1017 | // Build the flowrule |
| 1018 | rule = DefaultFlowRule.builder() |
| 1019 | .forDevice(deviceId) |
| 1020 | .withSelector(selector.build()) |
| 1021 | .withTreatment(treatment.build()) |
| 1022 | .withPriority(DEFAULT_PRIORITY) |
| 1023 | .fromApp(applicationId) |
| 1024 | .makePermanent() |
| 1025 | .forTable(TMAC_TABLE).build(); |
| 1026 | log.info("Building flowRule {}", rule); |
| 1027 | return rule; |
| 1028 | } |
| 1029 | |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 1030 | List<List<FlowRule>> processMcastEthDstFilter(EthCriterion ethCriterion, |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1031 | VlanId assignedVlan, |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1032 | MacAddress unicastMac, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1033 | ApplicationId applicationId) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1034 | ImmutableList.Builder<FlowRule> unicastFlows = ImmutableList.builder(); |
| 1035 | ImmutableList.Builder<FlowRule> multicastFlows = ImmutableList.builder(); |
| 1036 | TrafficSelector.Builder selector; |
| 1037 | TrafficTreatment.Builder treatment; |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1038 | FlowRule rule; |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 1039 | |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1040 | if (IPV4_MULTICAST.equals(ethCriterion.mac())) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1041 | if (requireUnicastBeforeMulticast()) { |
| 1042 | selector = DefaultTrafficSelector.builder(); |
| 1043 | treatment = DefaultTrafficTreatment.builder(); |
| 1044 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 1045 | selector.matchEthDst(unicastMac); |
Charles Chan | 056e0c1 | 2018-05-10 22:19:49 +0000 | [diff] [blame] | 1046 | selector.matchVlanId(assignedVlan); |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1047 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 1048 | rule = DefaultFlowRule.builder() |
| 1049 | .forDevice(deviceId) |
| 1050 | .withSelector(selector.build()) |
| 1051 | .withTreatment(treatment.build()) |
Charles Chan | 056e0c1 | 2018-05-10 22:19:49 +0000 | [diff] [blame] | 1052 | .withPriority(DEFAULT_PRIORITY) |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1053 | .fromApp(applicationId) |
| 1054 | .makePermanent() |
| 1055 | .forTable(TMAC_TABLE).build(); |
| 1056 | unicastFlows.add(rule); |
| 1057 | } |
| 1058 | |
| 1059 | selector = DefaultTrafficSelector.builder(); |
| 1060 | treatment = DefaultTrafficTreatment.builder(); |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1061 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 1062 | selector.matchEthDstMasked(ethCriterion.mac(), ethCriterion.mask()); |
Charles Chan | 056e0c1 | 2018-05-10 22:19:49 +0000 | [diff] [blame] | 1063 | selector.matchVlanId(assignedVlan); |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1064 | treatment.transition(MULTICAST_ROUTING_TABLE); |
| 1065 | rule = DefaultFlowRule.builder() |
| 1066 | .forDevice(deviceId) |
| 1067 | .withSelector(selector.build()) |
| 1068 | .withTreatment(treatment.build()) |
Charles Chan | 056e0c1 | 2018-05-10 22:19:49 +0000 | [diff] [blame] | 1069 | .withPriority(DEFAULT_PRIORITY) |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1070 | .fromApp(applicationId) |
| 1071 | .makePermanent() |
| 1072 | .forTable(TMAC_TABLE).build(); |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1073 | multicastFlows.add(rule); |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | if (IPV6_MULTICAST.equals(ethCriterion.mac())) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1077 | if (requireUnicastBeforeMulticast()) { |
| 1078 | selector = DefaultTrafficSelector.builder(); |
| 1079 | treatment = DefaultTrafficTreatment.builder(); |
| 1080 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 1081 | selector.matchEthDst(unicastMac); |
Charles Chan | 056e0c1 | 2018-05-10 22:19:49 +0000 | [diff] [blame] | 1082 | selector.matchVlanId(assignedVlan); |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1083 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 1084 | rule = DefaultFlowRule.builder() |
| 1085 | .forDevice(deviceId) |
| 1086 | .withSelector(selector.build()) |
| 1087 | .withTreatment(treatment.build()) |
Charles Chan | 056e0c1 | 2018-05-10 22:19:49 +0000 | [diff] [blame] | 1088 | .withPriority(DEFAULT_PRIORITY) |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1089 | .fromApp(applicationId) |
| 1090 | .makePermanent() |
| 1091 | .forTable(TMAC_TABLE).build(); |
| 1092 | unicastFlows.add(rule); |
| 1093 | } |
| 1094 | |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1095 | selector = DefaultTrafficSelector.builder(); |
| 1096 | treatment = DefaultTrafficTreatment.builder(); |
| 1097 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 1098 | selector.matchEthDstMasked(ethCriterion.mac(), ethCriterion.mask()); |
Charles Chan | 056e0c1 | 2018-05-10 22:19:49 +0000 | [diff] [blame] | 1099 | selector.matchVlanId(assignedVlan); |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1100 | treatment.transition(MULTICAST_ROUTING_TABLE); |
| 1101 | rule = DefaultFlowRule.builder() |
| 1102 | .forDevice(deviceId) |
| 1103 | .withSelector(selector.build()) |
| 1104 | .withTreatment(treatment.build()) |
Charles Chan | 056e0c1 | 2018-05-10 22:19:49 +0000 | [diff] [blame] | 1105 | .withPriority(DEFAULT_PRIORITY) |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1106 | .fromApp(applicationId) |
| 1107 | .makePermanent() |
| 1108 | .forTable(TMAC_TABLE).build(); |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1109 | multicastFlows.add(rule); |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1110 | } |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1111 | return ImmutableList.of(unicastFlows.build(), multicastFlows.build()); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1114 | private Collection<FlowRule> processForward(ForwardingObjective fwd) { |
| 1115 | switch (fwd.flag()) { |
| 1116 | case SPECIFIC: |
| 1117 | return processSpecific(fwd); |
| 1118 | case VERSATILE: |
| 1119 | return processVersatile(fwd); |
Jonghwan Hyun | 800d9d0 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 1120 | case EGRESS: |
| 1121 | return processEgress(fwd); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1122 | default: |
| 1123 | fail(fwd, ObjectiveError.UNKNOWN); |
| 1124 | log.warn("Unknown forwarding flag {}", fwd.flag()); |
| 1125 | } |
| 1126 | return Collections.emptySet(); |
| 1127 | } |
| 1128 | |
| 1129 | /** |
Jonghwan Hyun | 800d9d0 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 1130 | * In the OF-DPA 2.0 pipeline, egress forwarding objectives go to the |
| 1131 | * egress tables. |
| 1132 | * @param fwd the forwarding objective of type 'egress' |
| 1133 | * @return a collection of flow rules to be sent to the switch. An empty |
| 1134 | * collection may be returned if there is a problem in processing |
| 1135 | * the flow rule |
| 1136 | */ |
| 1137 | protected Collection<FlowRule> processEgress(ForwardingObjective fwd) { |
| 1138 | log.debug("Processing egress forwarding objective:{} in dev:{}", |
| 1139 | fwd, deviceId); |
| 1140 | |
| 1141 | List<FlowRule> rules = new ArrayList<>(); |
| 1142 | |
| 1143 | // Build selector |
| 1144 | TrafficSelector.Builder sb = DefaultTrafficSelector.builder(); |
| 1145 | VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) fwd.selector().getCriterion(Criterion.Type.VLAN_VID); |
| 1146 | if (vlanIdCriterion == null) { |
| 1147 | log.error("Egress forwarding objective:{} must include vlanId", fwd.id()); |
| 1148 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1149 | return rules; |
| 1150 | } |
| 1151 | |
| 1152 | Optional<Instruction> outInstr = fwd.treatment().allInstructions().stream() |
| 1153 | .filter(instruction -> instruction instanceof OutputInstruction).findFirst(); |
| 1154 | if (!outInstr.isPresent()) { |
| 1155 | log.error("Egress forwarding objective:{} must include output port", fwd.id()); |
| 1156 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1157 | return rules; |
| 1158 | } |
| 1159 | |
| 1160 | PortNumber portNumber = ((OutputInstruction) outInstr.get()).port(); |
| 1161 | |
| 1162 | sb.matchVlanId(vlanIdCriterion.vlanId()); |
| 1163 | OfdpaMatchActsetOutput actsetOutput = new OfdpaMatchActsetOutput(portNumber); |
| 1164 | sb.extension(actsetOutput, deviceId); |
| 1165 | |
| 1166 | sb.extension(new OfdpaMatchAllowVlanTranslation(ALLOW_VLAN_TRANSLATION), deviceId); |
| 1167 | |
| 1168 | // Build a flow rule for Egress VLAN Flow table |
| 1169 | TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); |
| 1170 | tb.transition(EGRESS_DSCP_PCP_REMARK_FLOW_TABLE); |
| 1171 | if (fwd.treatment() != null) { |
| 1172 | for (Instruction instr : fwd.treatment().allInstructions()) { |
| 1173 | if (instr instanceof L2ModificationInstruction && |
| 1174 | ((L2ModificationInstruction) instr).subtype() == L2SubType.VLAN_ID) { |
| 1175 | tb.immediate().add(instr); |
| 1176 | } |
| 1177 | if (instr instanceof L2ModificationInstruction && |
| 1178 | ((L2ModificationInstruction) instr).subtype() == L2SubType.VLAN_PUSH) { |
| 1179 | tb.immediate().pushVlan(); |
| 1180 | EthType ethType = ((L2ModificationInstruction.ModVlanHeaderInstruction) instr).ethernetType(); |
| 1181 | if (ethType.equals(EtherType.QINQ.ethType())) { |
| 1182 | // Build a flow rule for Egress TPID Flow table |
| 1183 | TrafficSelector tpidSelector = DefaultTrafficSelector.builder() |
| 1184 | .extension(actsetOutput, deviceId) |
| 1185 | .matchVlanId(VlanId.ANY).build(); |
| 1186 | |
| 1187 | TrafficTreatment tpidTreatment = DefaultTrafficTreatment.builder() |
| 1188 | .extension(new Ofdpa3CopyField(COPY_FIELD_NBITS, COPY_FIELD_OFFSET, |
| 1189 | COPY_FIELD_OFFSET, OXM_ID_VLAN_VID, |
| 1190 | OXM_ID_PACKET_REG_1), |
| 1191 | deviceId) |
| 1192 | .popVlan() |
| 1193 | .pushVlan(EtherType.QINQ.ethType()) |
| 1194 | .extension(new Ofdpa3CopyField(COPY_FIELD_NBITS, COPY_FIELD_OFFSET, |
| 1195 | COPY_FIELD_OFFSET, OXM_ID_PACKET_REG_1, |
| 1196 | OXM_ID_VLAN_VID), |
| 1197 | deviceId) |
| 1198 | .build(); |
| 1199 | |
| 1200 | FlowRule.Builder tpidRuleBuilder = DefaultFlowRule.builder() |
| 1201 | .fromApp(fwd.appId()) |
| 1202 | .withPriority(fwd.priority()) |
| 1203 | .forDevice(deviceId) |
| 1204 | .withSelector(tpidSelector) |
| 1205 | .withTreatment(tpidTreatment) |
| 1206 | .makePermanent() |
| 1207 | .forTable(EGRESS_TPID_FLOW_TABLE); |
| 1208 | rules.add(tpidRuleBuilder.build()); |
| 1209 | } |
| 1210 | } |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 1215 | .fromApp(fwd.appId()) |
| 1216 | .withPriority(fwd.priority()) |
| 1217 | .forDevice(deviceId) |
| 1218 | .withSelector(sb.build()) |
| 1219 | .withTreatment(tb.build()) |
| 1220 | .makePermanent() |
| 1221 | .forTable(EGRESS_VLAN_FLOW_TABLE); |
| 1222 | rules.add(ruleBuilder.build()); |
| 1223 | return rules; |
| 1224 | } |
| 1225 | |
| 1226 | /** |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1227 | * In the OF-DPA 2.0 pipeline, versatile forwarding objectives go to the |
| 1228 | * ACL table. |
| 1229 | * @param fwd the forwarding objective of type 'versatile' |
| 1230 | * @return a collection of flow rules to be sent to the switch. An empty |
| 1231 | * collection may be returned if there is a problem in processing |
| 1232 | * the flow rule |
| 1233 | */ |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 1234 | protected Collection<FlowRule> processVersatile(ForwardingObjective fwd) { |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1235 | log.debug("Processing versatile forwarding objective:{} in dev:{}", |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 1236 | fwd.id(), deviceId); |
Harshada Chaundkar | cb78751 | 2019-08-05 15:33:30 +0000 | [diff] [blame] | 1237 | List<FlowRule> flowRules = new ArrayList<>(); |
| 1238 | final AtomicBoolean ethTypeUsed = new AtomicBoolean(false); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1239 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1240 | if (fwd.nextId() == null && fwd.treatment() == null) { |
| 1241 | log.error("Forwarding objective {} from {} must contain " |
| 1242 | + "nextId or Treatment", fwd.selector(), fwd.appId()); |
Zsolt Haraszti | 9faab75 | 2016-02-17 15:55:20 -0800 | [diff] [blame] | 1243 | fail(fwd, ObjectiveError.BADPARAMS); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1244 | return Collections.emptySet(); |
| 1245 | } |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1246 | |
Saurav Das | 77b5e90 | 2016-01-27 17:01:59 -0800 | [diff] [blame] | 1247 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 1248 | fwd.selector().criteria().forEach(criterion -> { |
| 1249 | if (criterion instanceof VlanIdCriterion) { |
| 1250 | VlanId vlanId = ((VlanIdCriterion) criterion).vlanId(); |
| 1251 | // ensure that match does not include vlan = NONE as OF-DPA does not |
| 1252 | // match untagged packets this way in the ACL table. |
| 1253 | if (vlanId.equals(VlanId.NONE)) { |
| 1254 | return; |
| 1255 | } |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 1256 | if (requireVlanExtensions()) { |
| 1257 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vlanId); |
| 1258 | sbuilder.extension(ofdpaMatchVlanVid, deviceId); |
| 1259 | } else { |
| 1260 | sbuilder.matchVlanId(vlanId); |
| 1261 | } |
Charles Chan | 09bf269 | 2018-01-11 11:48:18 -0800 | [diff] [blame] | 1262 | } else if (criterion instanceof Icmpv6TypeCriterion) { |
| 1263 | byte icmpv6Type = (byte) ((Icmpv6TypeCriterion) criterion).icmpv6Type(); |
| 1264 | sbuilder.matchIcmpv6Type(icmpv6Type); |
| 1265 | } else if (criterion instanceof Icmpv6CodeCriterion) { |
| 1266 | byte icmpv6Code = (byte) ((Icmpv6CodeCriterion) criterion).icmpv6Code(); |
| 1267 | sbuilder.matchIcmpv6Type(icmpv6Code); |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1268 | } else if (criterion instanceof TcpPortCriterion || criterion instanceof UdpPortCriterion) { |
| 1269 | // FIXME: QMX switches do not support L4 dst port matching in ACL table. |
| 1270 | // Currently L4 dst port matching is only used by DHCP relay feature |
| 1271 | // and therefore is safe to be replaced with L4 src port matching. |
| 1272 | // We need to revisit this if L4 dst port is used for other purpose in the future. |
| 1273 | if (!supportIpv6L4Dst() && isIpv6(fwd.selector())) { |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1274 | switch (criterion.type()) { |
| 1275 | case UDP_DST: |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1276 | case UDP_DST_MASKED: |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1277 | case TCP_DST: |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1278 | case TCP_DST_MASKED: |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1279 | break; |
| 1280 | default: |
| 1281 | sbuilder.add(criterion); |
| 1282 | } |
| 1283 | } else { |
| 1284 | sbuilder.add(criterion); |
| 1285 | } |
Harshada Chaundkar | cb78751 | 2019-08-05 15:33:30 +0000 | [diff] [blame] | 1286 | } else if (criterion instanceof EthTypeCriterion) { |
| 1287 | sbuilder.add(criterion); |
| 1288 | ethTypeUsed.set(true); |
Saurav Das | 77b5e90 | 2016-01-27 17:01:59 -0800 | [diff] [blame] | 1289 | } else { |
| 1290 | sbuilder.add(criterion); |
| 1291 | } |
| 1292 | }); |
Harshada Chaundkar | cb78751 | 2019-08-05 15:33:30 +0000 | [diff] [blame] | 1293 | |
| 1294 | TrafficTreatment.Builder ttBuilder = versatileTreatmentBuilder(fwd); |
| 1295 | if (ttBuilder == null) { |
| 1296 | return Collections.emptySet(); |
| 1297 | } |
| 1298 | |
| 1299 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 1300 | .fromApp(fwd.appId()) |
| 1301 | .withPriority(fwd.priority()) |
| 1302 | .forDevice(deviceId) |
| 1303 | .withSelector(sbuilder.build()) |
| 1304 | .withTreatment(ttBuilder.build()) |
| 1305 | .makePermanent() |
| 1306 | .forTable(ACL_TABLE); |
| 1307 | |
| 1308 | flowRules.add(ruleBuilder.build()); |
| 1309 | |
| 1310 | if (!ethTypeUsed.get() && requireEthType()) { |
| 1311 | log.debug("{} doesn't match on ethType but requireEthType is true, adding complementary ACL flow.", |
| 1312 | sbuilder.toString()); |
| 1313 | sbuilder.matchEthType(Ethernet.TYPE_IPV6); |
| 1314 | FlowRule.Builder ethTypeRuleBuilder = DefaultFlowRule.builder() |
| 1315 | .fromApp(fwd.appId()) |
| 1316 | .withPriority(fwd.priority()) |
| 1317 | .forDevice(deviceId) |
| 1318 | .withSelector(sbuilder.build()) |
| 1319 | .withTreatment(ttBuilder.build()) |
| 1320 | .makePermanent() |
| 1321 | .forTable(ACL_TABLE); |
| 1322 | flowRules.add(ethTypeRuleBuilder.build()); |
| 1323 | } |
| 1324 | return flowRules; |
Charles Chan | ab59160 | 2019-01-22 17:25:04 -0800 | [diff] [blame] | 1325 | } |
Saurav Das | 77b5e90 | 2016-01-27 17:01:59 -0800 | [diff] [blame] | 1326 | |
Charles Chan | ab59160 | 2019-01-22 17:25:04 -0800 | [diff] [blame] | 1327 | /** |
| 1328 | * Helper function to create traffic treatment builder for versatile forwarding objectives. |
| 1329 | * |
| 1330 | * @param fwd original forwarding objective |
| 1331 | * @return treatment builder for the flow rule, or null if there is an error. |
| 1332 | */ |
| 1333 | protected TrafficTreatment.Builder versatileTreatmentBuilder(ForwardingObjective fwd) { |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1334 | // XXX driver does not currently do type checking as per Tables 65-67 in |
| 1335 | // OFDPA 2.0 spec. The only allowed treatment is a punt to the controller. |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1336 | TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder(); |
| 1337 | if (fwd.treatment() != null) { |
| 1338 | for (Instruction ins : fwd.treatment().allInstructions()) { |
| 1339 | if (ins instanceof OutputInstruction) { |
| 1340 | OutputInstruction o = (OutputInstruction) ins; |
Ray Milkey | fe0e085 | 2018-01-18 11:14:05 -0800 | [diff] [blame] | 1341 | if (PortNumber.CONTROLLER.equals(o.port())) { |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1342 | ttBuilder.add(o); |
| 1343 | } else { |
| 1344 | log.warn("Only allowed treatments in versatile forwarding " |
| 1345 | + "objectives are punts to the controller"); |
| 1346 | } |
Charles Chan | f76de30 | 2018-06-15 18:54:18 -0700 | [diff] [blame] | 1347 | } else if (ins instanceof NoActionInstruction) { |
| 1348 | // No action is allowed and nothing needs to be done |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1349 | } else { |
| 1350 | log.warn("Cannot process instruction in versatile fwd {}", ins); |
| 1351 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1352 | } |
Charles Chan | 2df0e8a | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 1353 | if (fwd.treatment().clearedDeferred()) { |
| 1354 | ttBuilder.wipeDeferred(); |
| 1355 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1356 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1357 | if (fwd.nextId() != null) { |
Charles Chan | ab59160 | 2019-01-22 17:25:04 -0800 | [diff] [blame] | 1358 | // Override case |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1359 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 1360 | if (next == null) { |
| 1361 | fail(fwd, ObjectiveError.BADPARAMS); |
Charles Chan | ab59160 | 2019-01-22 17:25:04 -0800 | [diff] [blame] | 1362 | return null; |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 1363 | } |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1364 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1365 | // we only need the top level group's key to point the flow to it |
| 1366 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 1367 | if (group == null) { |
| 1368 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
Charles Chan | ab59160 | 2019-01-22 17:25:04 -0800 | [diff] [blame] | 1369 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1370 | fail(fwd, ObjectiveError.GROUPMISSING); |
Charles Chan | ab59160 | 2019-01-22 17:25:04 -0800 | [diff] [blame] | 1371 | return null; |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1372 | } |
| 1373 | ttBuilder.deferred().group(group.id()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1374 | } |
Charles Chan | ab59160 | 2019-01-22 17:25:04 -0800 | [diff] [blame] | 1375 | return ttBuilder; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | /** |
| 1379 | * In the OF-DPA 2.0 pipeline, specific forwarding refers to the IP table |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1380 | * (unicast or multicast) or the L2 table (mac + vlan) or the MPLS table. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1381 | * |
| 1382 | * @param fwd the forwarding objective of type 'specific' |
| 1383 | * @return a collection of flow rules. Typically there will be only one |
| 1384 | * for this type of forwarding objective. An empty set may be |
| 1385 | * returned if there is an issue in processing the objective. |
| 1386 | */ |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1387 | private Collection<FlowRule> processSpecific(ForwardingObjective fwd) { |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 1388 | log.debug("Processing specific fwd objective:{} in dev:{} with next:{}", |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1389 | fwd.id(), deviceId, fwd.nextId()); |
| 1390 | boolean isEthTypeObj = isSupportedEthTypeObjective(fwd); |
| 1391 | boolean isEthDstObj = isSupportedEthDstObjective(fwd); |
| 1392 | |
| 1393 | if (isEthTypeObj) { |
| 1394 | return processEthTypeSpecific(fwd); |
| 1395 | } else if (isEthDstObj) { |
| 1396 | return processEthDstSpecific(fwd); |
| 1397 | } else { |
| 1398 | log.warn("processSpecific: Unsupported forwarding objective " |
| 1399 | + "criteria fwd:{} in dev:{}", fwd.nextId(), deviceId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1400 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 1401 | return Collections.emptySet(); |
| 1402 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1403 | } |
| 1404 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1405 | /** |
| 1406 | * Handles forwarding rules to the IP and MPLS tables. |
| 1407 | * |
| 1408 | * @param fwd the forwarding objective |
| 1409 | * @return A collection of flow rules, or an empty set |
| 1410 | */ |
| 1411 | protected Collection<FlowRule> processEthTypeSpecific(ForwardingObjective fwd) { |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1412 | return processEthTypeSpecificInternal(fwd, false, ACL_TABLE); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | /** |
| 1416 | * Internal implementation of processEthTypeSpecific. |
| 1417 | * <p> |
| 1418 | * Wildcarded IPv4_DST is not supported in OFDPA i12. Therefore, we break |
| 1419 | * the rule into 0.0.0.0/1 and 128.0.0.0/1. |
| 1420 | * The allowDefaultRoute must be set to false for OFDPA i12. |
| 1421 | * </p> |
| 1422 | * |
| 1423 | * @param fwd the forwarding objective |
| 1424 | * @param allowDefaultRoute allow wildcarded IPv4_DST or not |
Ray Milkey | 0bb1e10 | 2016-11-10 14:51:27 -0800 | [diff] [blame] | 1425 | * @param mplsNextTable next MPLS table |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 1426 | * @return A collection of flow rules, or an empty set |
| 1427 | */ |
| 1428 | protected Collection<FlowRule> processEthTypeSpecificInternal(ForwardingObjective fwd, |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1429 | boolean allowDefaultRoute, |
| 1430 | int mplsNextTable) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1431 | TrafficSelector selector = fwd.selector(); |
| 1432 | EthTypeCriterion ethType = |
| 1433 | (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1434 | boolean emptyGroup = false; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1435 | int forTableId; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1436 | TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder(); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1437 | TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1438 | TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder(); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1439 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1440 | if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) { |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1441 | if (buildIpv4Selector(filteredSelector, complementarySelector, fwd, allowDefaultRoute) < 0) { |
| 1442 | return Collections.emptyList(); |
| 1443 | } |
| 1444 | // We need to set properly the next table |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1445 | IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip(); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1446 | if (ipv4Dst.isMulticast()) { |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1447 | forTableId = MULTICAST_ROUTING_TABLE; |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1448 | } else { |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1449 | forTableId = UNICAST_ROUTING_TABLE; |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1450 | } |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1451 | |
Charles Chan | 236653d | 2018-03-05 11:28:23 -0800 | [diff] [blame] | 1452 | // TODO decrementing IP ttl is done automatically for routing, this |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1453 | // action is ignored or rejected in ofdpa as it is not fully implemented |
Charles Chan | 236653d | 2018-03-05 11:28:23 -0800 | [diff] [blame] | 1454 | // if (fwd.treatment() != null) { |
| 1455 | // for (Instruction instr : fwd.treatment().allInstructions()) { |
| 1456 | // if (instr instanceof L3ModificationInstruction && |
| 1457 | // ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) { |
| 1458 | // tb.deferred().add(instr); |
| 1459 | // } |
| 1460 | // } |
| 1461 | // } |
| 1462 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1463 | } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV6) { |
| 1464 | if (buildIpv6Selector(filteredSelector, fwd) < 0) { |
| 1465 | return Collections.emptyList(); |
| 1466 | } |
Kalhee Kim | 3d26bf0 | 2017-10-04 14:59:11 +0000 | [diff] [blame] | 1467 | //We need to set the proper next table |
| 1468 | IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip(); |
| 1469 | if (ipv6Dst.isMulticast()) { |
| 1470 | forTableId = MULTICAST_ROUTING_TABLE; |
| 1471 | } else { |
| 1472 | forTableId = UNICAST_ROUTING_TABLE; |
| 1473 | } |
| 1474 | |
Charles Chan | 236653d | 2018-03-05 11:28:23 -0800 | [diff] [blame] | 1475 | // TODO decrementing IP ttl is done automatically for routing, this |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1476 | // action is ignored or rejected in ofdpa as it is not fully implemented |
Charles Chan | 236653d | 2018-03-05 11:28:23 -0800 | [diff] [blame] | 1477 | // if (fwd.treatment() != null) { |
| 1478 | // for (Instruction instr : fwd.treatment().allInstructions()) { |
| 1479 | // if (instr instanceof L3ModificationInstruction && |
| 1480 | // ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) { |
| 1481 | // tb.deferred().add(instr); |
| 1482 | // } |
| 1483 | // } |
| 1484 | // } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1485 | } else { |
| 1486 | filteredSelector |
| 1487 | .matchEthType(Ethernet.MPLS_UNICAST) |
| 1488 | .matchMplsLabel(((MplsCriterion) |
| 1489 | selector.getCriterion(Criterion.Type.MPLS_LABEL)).label()); |
| 1490 | MplsBosCriterion bos = (MplsBosCriterion) selector |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 1491 | .getCriterion(MPLS_BOS); |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 1492 | if (bos != null && requireMplsBosMatch()) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1493 | filteredSelector.matchMplsBos(bos.mplsBos()); |
| 1494 | } |
| 1495 | forTableId = MPLS_TABLE_1; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1496 | log.debug("processing MPLS specific forwarding objective {} -> next:{}" |
| 1497 | + " in dev {}", fwd.id(), fwd.nextId(), deviceId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1498 | |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1499 | if (fwd.treatment() != null) { |
| 1500 | for (Instruction instr : fwd.treatment().allInstructions()) { |
| 1501 | if (instr instanceof L2ModificationInstruction && |
| 1502 | ((L2ModificationInstruction) instr).subtype() == L2SubType.MPLS_POP) { |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1503 | // OF-DPA does not pop in MPLS table in some cases. For the L3 VPN, it requires |
Saurav Das | 9c70534 | 2017-01-06 11:36:01 -0800 | [diff] [blame] | 1504 | // setting the MPLS_TYPE so pop can happen down the pipeline |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 1505 | if (requireMplsPop()) { |
| 1506 | if (mplsNextTable == MPLS_TYPE_TABLE && isNotMplsBos(selector)) { |
| 1507 | tb.immediate().popMpls(); |
| 1508 | } |
| 1509 | } else { |
| 1510 | // Skip mpls pop action for mpls_unicast label |
| 1511 | if (instr instanceof ModMplsHeaderInstruction && |
| 1512 | !((ModMplsHeaderInstruction) instr).ethernetType() |
| 1513 | .equals(EtherType.MPLS_UNICAST.ethType())) { |
| 1514 | tb.immediate().add(instr); |
| 1515 | } |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1516 | } |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1517 | } |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 1518 | |
| 1519 | if (requireMplsTtlModification()) { |
| 1520 | if (instr instanceof L3ModificationInstruction && |
| 1521 | ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) { |
| 1522 | // FIXME Should modify the app to send the correct DEC_MPLS_TTL instruction |
| 1523 | tb.immediate().decMplsTtl(); |
| 1524 | } |
| 1525 | if (instr instanceof L3ModificationInstruction && |
| 1526 | ((L3ModificationInstruction) instr).subtype() == L3SubType.TTL_IN) { |
| 1527 | tb.immediate().add(instr); |
| 1528 | } |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1529 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1530 | } |
| 1531 | } |
| 1532 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1533 | |
| 1534 | if (fwd.nextId() != null) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1535 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 1536 | if (next != null) { |
| 1537 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1538 | // we only need the top level group's key to point the flow to it |
| 1539 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 1540 | if (group == null) { |
| 1541 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 1542 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 1543 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 1544 | return Collections.emptySet(); |
| 1545 | } |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1546 | if (isNotMplsBos(selector) && group.type().equals(SELECT)) { |
| 1547 | log.warn("SR CONTINUE case cannot be handled as MPLS ECMP " |
| 1548 | + "is not implemented in OF-DPA yet. Aborting flow {} -> next:{} " |
| 1549 | + "in this device {}", fwd.id(), fwd.nextId(), deviceId); |
| 1550 | fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 1551 | return Collections.emptySet(); |
| 1552 | } |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1553 | tb.deferred().group(group.id()); |
Saurav Das | c568c34 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 1554 | // retrying flows may be necessary due to bug CORD-554 |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1555 | if (gkeys.size() == 1 && gkeys.get(0).size() == 1) { |
Saurav Das | c568c34 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 1556 | if (shouldRetry()) { |
| 1557 | log.warn("Found empty group 0x{} in dev:{} .. will retry fwd:{}", |
| 1558 | Integer.toHexString(group.id().id()), deviceId, |
| 1559 | fwd.id()); |
| 1560 | emptyGroup = true; |
| 1561 | } |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1562 | } |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 1563 | } else { |
| 1564 | log.warn("Cannot find group for nextId:{} in dev:{}. Aborting fwd:{}", |
| 1565 | fwd.nextId(), deviceId, fwd.id()); |
| 1566 | fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 1567 | return Collections.emptySet(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1568 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1569 | } |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1570 | |
| 1571 | if (forTableId == MPLS_TABLE_1) { |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 1572 | if (mplsNextTable == MPLS_L3_TYPE_TABLE) { |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1573 | Ofdpa3SetMplsType setMplsType = new Ofdpa3SetMplsType(Ofdpa3MplsType.L3_PHP); |
Saurav Das | 9c70534 | 2017-01-06 11:36:01 -0800 | [diff] [blame] | 1574 | // set mpls type as apply_action |
| 1575 | tb.immediate().extension(setMplsType, deviceId); |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1576 | } |
| 1577 | tb.transition(mplsNextTable); |
| 1578 | } else { |
| 1579 | tb.transition(ACL_TABLE); |
| 1580 | } |
| 1581 | |
Andrea Campanella | d980c6d | 2018-04-30 11:48:55 +0200 | [diff] [blame] | 1582 | if (fwd.treatment() != null && fwd.treatment().clearedDeferred()) { |
| 1583 | if (supportsUnicastBlackHole()) { |
| 1584 | tb.wipeDeferred(); |
| 1585 | } else { |
| 1586 | log.warn("Clear Deferred is not supported Unicast Routing Table on device {}", deviceId); |
| 1587 | return Collections.emptySet(); |
| 1588 | } |
| 1589 | } |
| 1590 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1591 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 1592 | .fromApp(fwd.appId()) |
| 1593 | .withPriority(fwd.priority()) |
| 1594 | .forDevice(deviceId) |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1595 | .withSelector(filteredSelector.build()) |
| 1596 | .withTreatment(tb.build()) |
| 1597 | .forTable(forTableId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1598 | |
| 1599 | if (fwd.permanent()) { |
| 1600 | ruleBuilder.makePermanent(); |
| 1601 | } else { |
| 1602 | ruleBuilder.makeTemporary(fwd.timeout()); |
| 1603 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1604 | Collection<FlowRule> flowRuleCollection = new ArrayList<>(); |
| 1605 | flowRuleCollection.add(ruleBuilder.build()); |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1606 | if (!allowDefaultRoute) { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1607 | flowRuleCollection.add( |
| 1608 | defaultRoute(fwd, complementarySelector, forTableId, tb) |
| 1609 | ); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1610 | log.debug("Default rule 0.0.0.0/0 is being installed two rules"); |
| 1611 | } |
Saurav Das | c568c34 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 1612 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1613 | if (emptyGroup) { |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 1614 | retryExecutorService.schedule(new RetryFlows(fwd, flowRuleCollection), |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1615 | RETRY_MS, TimeUnit.MILLISECONDS); |
| 1616 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1617 | return flowRuleCollection; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1620 | private int buildIpv4Selector(TrafficSelector.Builder builderToUpdate, |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1621 | TrafficSelector.Builder extBuilder, |
| 1622 | ForwardingObjective fwd, |
| 1623 | boolean allowDefaultRoute) { |
| 1624 | TrafficSelector selector = fwd.selector(); |
| 1625 | |
| 1626 | IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip(); |
| 1627 | if (ipv4Dst.isMulticast()) { |
| 1628 | if (ipv4Dst.prefixLength() != 32) { |
| 1629 | log.warn("Multicast specific forwarding objective can only be /32"); |
| 1630 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1631 | return -1; |
| 1632 | } |
| 1633 | VlanId assignedVlan = readVlanFromSelector(fwd.meta()); |
| 1634 | if (assignedVlan == null) { |
| 1635 | log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort."); |
| 1636 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1637 | return -1; |
| 1638 | } |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 1639 | if (requireVlanExtensions()) { |
| 1640 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan); |
| 1641 | builderToUpdate.extension(ofdpaMatchVlanVid, deviceId); |
| 1642 | } else { |
| 1643 | builderToUpdate.matchVlanId(assignedVlan); |
| 1644 | } |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1645 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); |
| 1646 | log.debug("processing IPv4 multicast specific forwarding objective {} -> next:{}" |
| 1647 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
| 1648 | } else { |
| 1649 | if (ipv4Dst.prefixLength() == 0) { |
| 1650 | if (allowDefaultRoute) { |
| 1651 | // The entire IPV4_DST field is wildcarded intentionally |
| 1652 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV4); |
| 1653 | } else { |
| 1654 | // NOTE: The switch does not support matching 0.0.0.0/0 |
| 1655 | // Split it into 0.0.0.0/1 and 128.0.0.0/1 |
| 1656 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV4) |
| 1657 | .matchIPDst(IpPrefix.valueOf("0.0.0.0/1")); |
| 1658 | extBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 1659 | .matchIPDst(IpPrefix.valueOf("128.0.0.0/1")); |
| 1660 | } |
| 1661 | } else { |
| 1662 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); |
| 1663 | } |
| 1664 | log.debug("processing IPv4 unicast specific forwarding objective {} -> next:{}" |
| 1665 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
| 1666 | } |
| 1667 | return 0; |
| 1668 | } |
| 1669 | |
| 1670 | /** |
| 1671 | * Helper method to build Ipv6 selector using the selector provided by |
| 1672 | * a forwarding objective. |
| 1673 | * |
| 1674 | * @param builderToUpdate the builder to update |
| 1675 | * @param fwd the selector to read |
| 1676 | * @return 0 if the update ends correctly. -1 if the matches |
| 1677 | * are not yet supported |
| 1678 | */ |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1679 | int buildIpv6Selector(TrafficSelector.Builder builderToUpdate, |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1680 | ForwardingObjective fwd) { |
| 1681 | |
| 1682 | TrafficSelector selector = fwd.selector(); |
| 1683 | |
| 1684 | IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip(); |
| 1685 | if (ipv6Dst.isMulticast()) { |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 1686 | if (ipv6Dst.prefixLength() != IpAddress.INET6_BIT_LENGTH) { |
| 1687 | log.warn("Multicast specific forwarding objective can only be /128"); |
| 1688 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1689 | return -1; |
| 1690 | } |
| 1691 | VlanId assignedVlan = readVlanFromSelector(fwd.meta()); |
| 1692 | if (assignedVlan == null) { |
| 1693 | log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort."); |
| 1694 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1695 | return -1; |
| 1696 | } |
| 1697 | if (requireVlanExtensions()) { |
| 1698 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan); |
| 1699 | builderToUpdate.extension(ofdpaMatchVlanVid, deviceId); |
| 1700 | } else { |
| 1701 | builderToUpdate.matchVlanId(assignedVlan); |
| 1702 | } |
| 1703 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Dst(ipv6Dst); |
| 1704 | log.debug("processing IPv6 multicast specific forwarding objective {} -> next:{}" |
| 1705 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
| 1706 | } else { |
| 1707 | if (ipv6Dst.prefixLength() != 0) { |
| 1708 | builderToUpdate.matchIPv6Dst(ipv6Dst); |
| 1709 | } |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1710 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV6); |
| 1711 | log.debug("processing IPv6 unicast specific forwarding objective {} -> next:{}" |
| 1712 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 1713 | } |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1714 | return 0; |
| 1715 | } |
| 1716 | |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1717 | FlowRule defaultRoute(ForwardingObjective fwd, |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1718 | TrafficSelector.Builder complementarySelector, |
| 1719 | int forTableId, |
| 1720 | TrafficTreatment.Builder tb) { |
| 1721 | FlowRule.Builder rule = DefaultFlowRule.builder() |
| 1722 | .fromApp(fwd.appId()) |
| 1723 | .withPriority(fwd.priority()) |
| 1724 | .forDevice(deviceId) |
| 1725 | .withSelector(complementarySelector.build()) |
| 1726 | .withTreatment(tb.build()) |
| 1727 | .forTable(forTableId); |
| 1728 | if (fwd.permanent()) { |
| 1729 | rule.makePermanent(); |
| 1730 | } else { |
| 1731 | rule.makeTemporary(fwd.timeout()); |
| 1732 | } |
| 1733 | return rule.build(); |
| 1734 | } |
| 1735 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1736 | /** |
| 1737 | * Handles forwarding rules to the L2 bridging table. Flow actions are not |
| 1738 | * allowed in the bridging table - instead we use L2 Interface group or |
| 1739 | * L2 flood group |
| 1740 | * |
| 1741 | * @param fwd the forwarding objective |
| 1742 | * @return A collection of flow rules, or an empty set |
| 1743 | */ |
| 1744 | protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) { |
| 1745 | List<FlowRule> rules = new ArrayList<>(); |
| 1746 | |
| 1747 | // Build filtered selector |
| 1748 | TrafficSelector selector = fwd.selector(); |
| 1749 | EthCriterion ethCriterion = (EthCriterion) selector |
| 1750 | .getCriterion(Criterion.Type.ETH_DST); |
| 1751 | VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector |
| 1752 | .getCriterion(Criterion.Type.VLAN_VID); |
| 1753 | |
| 1754 | if (vlanIdCriterion == null) { |
| 1755 | log.warn("Forwarding objective for bridging requires vlan. Not " |
| 1756 | + "installing fwd:{} in dev:{}", fwd.id(), deviceId); |
| 1757 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1758 | return Collections.emptySet(); |
| 1759 | } |
| 1760 | |
| 1761 | TrafficSelector.Builder filteredSelectorBuilder = |
| 1762 | DefaultTrafficSelector.builder(); |
Yi Tseng | 3a77b4f | 2017-02-06 15:02:17 -0800 | [diff] [blame] | 1763 | |
| 1764 | if (!ethCriterion.mac().equals(NONE) && |
| 1765 | !ethCriterion.mac().equals(BROADCAST)) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1766 | filteredSelectorBuilder.matchEthDst(ethCriterion.mac()); |
| 1767 | log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}", |
| 1768 | fwd.id(), fwd.nextId(), deviceId); |
| 1769 | } else { |
Yi Tseng | 3a77b4f | 2017-02-06 15:02:17 -0800 | [diff] [blame] | 1770 | // Use wildcard DST_MAC if the MacAddress is None or Broadcast |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1771 | log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} " |
| 1772 | + "in dev:{} for vlan:{}", |
| 1773 | fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId()); |
| 1774 | } |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 1775 | if (requireVlanExtensions()) { |
| 1776 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vlanIdCriterion.vlanId()); |
| 1777 | filteredSelectorBuilder.extension(ofdpaMatchVlanVid, deviceId); |
| 1778 | } else { |
| 1779 | filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId()); |
| 1780 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1781 | TrafficSelector filteredSelector = filteredSelectorBuilder.build(); |
| 1782 | |
| 1783 | if (fwd.treatment() != null) { |
| 1784 | log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table" |
| 1785 | + "for dev:{}. Expecting only nextId", fwd.id(), deviceId); |
| 1786 | } |
| 1787 | |
| 1788 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1789 | if (fwd.nextId() != null) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1790 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1791 | if (next != null) { |
| 1792 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1793 | // we only need the top level group's key to point the flow to it |
| 1794 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 1795 | if (group != null) { |
| 1796 | treatmentBuilder.deferred().group(group.id()); |
| 1797 | } else { |
| 1798 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 1799 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 1800 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 1801 | return Collections.emptySet(); |
| 1802 | } |
| 1803 | } |
| 1804 | } |
| 1805 | treatmentBuilder.immediate().transition(ACL_TABLE); |
| 1806 | TrafficTreatment filteredTreatment = treatmentBuilder.build(); |
| 1807 | |
| 1808 | // Build bridging table entries |
| 1809 | FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); |
| 1810 | flowRuleBuilder.fromApp(fwd.appId()) |
| 1811 | .withPriority(fwd.priority()) |
| 1812 | .forDevice(deviceId) |
| 1813 | .withSelector(filteredSelector) |
| 1814 | .withTreatment(filteredTreatment) |
| 1815 | .forTable(BRIDGING_TABLE); |
| 1816 | if (fwd.permanent()) { |
| 1817 | flowRuleBuilder.makePermanent(); |
| 1818 | } else { |
| 1819 | flowRuleBuilder.makeTemporary(fwd.timeout()); |
| 1820 | } |
| 1821 | rules.add(flowRuleBuilder.build()); |
| 1822 | return rules; |
| 1823 | } |
| 1824 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1825 | ////////////////////////////////////// |
| 1826 | // Helper Methods and Classes |
| 1827 | ////////////////////////////////////// |
| 1828 | |
| 1829 | private boolean isSupportedEthTypeObjective(ForwardingObjective fwd) { |
| 1830 | TrafficSelector selector = fwd.selector(); |
| 1831 | EthTypeCriterion ethType = (EthTypeCriterion) selector |
| 1832 | .getCriterion(Criterion.Type.ETH_TYPE); |
| 1833 | return !((ethType == null) || |
| 1834 | ((ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1835 | (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) && |
| 1836 | (ethType.ethType().toShort() != Ethernet.TYPE_IPV6)); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | private boolean isSupportedEthDstObjective(ForwardingObjective fwd) { |
| 1840 | TrafficSelector selector = fwd.selector(); |
| 1841 | EthCriterion ethDst = (EthCriterion) selector |
| 1842 | .getCriterion(Criterion.Type.ETH_DST); |
| 1843 | VlanIdCriterion vlanId = (VlanIdCriterion) selector |
| 1844 | .getCriterion(Criterion.Type.VLAN_VID); |
| 1845 | return !(ethDst == null && vlanId == null); |
| 1846 | } |
| 1847 | |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1848 | NextGroup getGroupForNextObjective(Integer nextId) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1849 | NextGroup next = flowObjectiveStore.getNextGroup(nextId); |
| 1850 | if (next != null) { |
| 1851 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1852 | if (gkeys != null && !gkeys.isEmpty()) { |
| 1853 | return next; |
| 1854 | } else { |
| 1855 | log.warn("Empty next group found in FlowObjective store for " |
| 1856 | + "next-id:{} in dev:{}", nextId, deviceId); |
| 1857 | } |
| 1858 | } else { |
| 1859 | log.warn("next-id {} not found in Flow objective store for dev:{}", |
| 1860 | nextId, deviceId); |
| 1861 | } |
| 1862 | return null; |
| 1863 | } |
| 1864 | |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1865 | @Override |
| 1866 | public List<String> getNextMappings(NextGroup nextGroup) { |
| 1867 | List<String> mappings = new ArrayList<>(); |
| 1868 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(nextGroup.data()); |
| 1869 | for (Deque<GroupKey> gkd : gkeys) { |
| 1870 | Group lastGroup = null; |
Yuta HIGUCHI | 2dce08a | 2017-04-20 21:57:48 -0700 | [diff] [blame] | 1871 | StringBuilder gchain = new StringBuilder(); |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1872 | for (GroupKey gk : gkd) { |
| 1873 | Group g = groupService.getGroup(deviceId, gk); |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1874 | if (g == null) { |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 1875 | gchain.append(" NoGrp").append(" -->"); |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1876 | continue; |
| 1877 | } |
| 1878 | gchain.append(" 0x").append(Integer.toHexString(g.id().id())) |
| 1879 | .append(" -->"); |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1880 | lastGroup = g; |
| 1881 | } |
| 1882 | // add port information for last group in group-chain |
Yuta HIGUCHI | 2dce08a | 2017-04-20 21:57:48 -0700 | [diff] [blame] | 1883 | List<Instruction> lastGroupIns = new ArrayList<>(); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1884 | if (lastGroup != null && !lastGroup.buckets().buckets().isEmpty()) { |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 1885 | lastGroupIns = lastGroup.buckets().buckets().get(0) |
| 1886 | .treatment().allInstructions(); |
| 1887 | } |
| 1888 | for (Instruction i: lastGroupIns) { |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1889 | if (i instanceof OutputInstruction) { |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1890 | gchain.append(" port:").append(((OutputInstruction) i).port()); |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1891 | } |
| 1892 | } |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1893 | mappings.add(gchain.toString()); |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1894 | } |
| 1895 | return mappings; |
| 1896 | } |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1897 | |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1898 | /** |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1899 | * Utility class that retries sending flows a fixed number of times, even if |
| 1900 | * some of the attempts are successful. Used only for forwarding objectives. |
| 1901 | */ |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 1902 | public final class RetryFlows implements Runnable { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1903 | int attempts = MAX_RETRY_ATTEMPTS; |
| 1904 | private Collection<FlowRule> retryFlows; |
| 1905 | private ForwardingObjective fwd; |
| 1906 | |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1907 | RetryFlows(ForwardingObjective fwd, Collection<FlowRule> retryFlows) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1908 | this.fwd = fwd; |
| 1909 | this.retryFlows = retryFlows; |
| 1910 | } |
| 1911 | |
| 1912 | @Override |
| 1913 | public void run() { |
| 1914 | log.info("RETRY FLOWS ATTEMPT# {} for fwd:{} rules:{}", |
| 1915 | MAX_RETRY_ATTEMPTS - attempts, fwd.id(), retryFlows.size()); |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 1916 | sendForwards(Collections.singletonList(Pair.of(fwd, retryFlows))); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1917 | if (--attempts > 0) { |
pier | 8b3aef4 | 2019-03-11 15:14:02 -0700 | [diff] [blame] | 1918 | retryExecutorService.schedule(this, RETRY_MS, TimeUnit.MILLISECONDS); |
| 1919 | } |
| 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | // Flow rules accumulator for reducing the number of transactions required to the devices. |
| 1924 | private final class ForwardingObjectiveAccumulator |
| 1925 | extends AbstractAccumulator<Pair<ForwardingObjective, Collection<FlowRule>>> { |
| 1926 | |
| 1927 | ForwardingObjectiveAccumulator(int maxFwd, int maxBatchMS, int maxIdleMS) { |
| 1928 | super(TIMER, maxFwd, maxBatchMS, maxIdleMS); |
| 1929 | } |
| 1930 | |
| 1931 | @Override |
| 1932 | public void processItems(List<Pair<ForwardingObjective, Collection<FlowRule>>> pairs) { |
| 1933 | // Triggers creation of a batch using the list of flowrules generated from fwdobjs. |
| 1934 | accumulatorExecutorService.execute(new FlowRulesBuilderTask(pairs)); |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | // Task for building batch of flow rules in a separate thread. |
| 1939 | private final class FlowRulesBuilderTask implements Runnable { |
| 1940 | private final List<Pair<ForwardingObjective, Collection<FlowRule>>> pairs; |
| 1941 | |
| 1942 | FlowRulesBuilderTask(List<Pair<ForwardingObjective, Collection<FlowRule>>> pairs) { |
| 1943 | this.pairs = pairs; |
| 1944 | } |
| 1945 | |
| 1946 | @Override |
| 1947 | public void run() { |
| 1948 | try { |
| 1949 | sendForwards(pairs); |
| 1950 | } catch (Exception e) { |
| 1951 | log.warn("Unable to send forwards", e); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1952 | } |
| 1953 | } |
| 1954 | } |
| 1955 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1956 | } |