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