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