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