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