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