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