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