blob: a6a9d4ed6b19bee23b854334005895a1379cc0a3 [file] [log] [blame]
Saurav Das822c4e22015-10-23 10:51:11 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Saurav Das822c4e22015-10-23 10:51:11 -07003 *
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 */
16package org.onosproject.driver.pipeline;
17
Saurav Das1ce0a7b2016-10-21 14:06:29 -070018import static java.util.concurrent.Executors.newScheduledThreadPool;
19import static org.onlab.util.Tools.groupedThreads;
Saurav Das822c4e22015-10-23 10:51:11 -070020import static org.slf4j.LoggerFactory.getLogger;
21
Saurav Das8a0732e2015-11-20 15:27:53 -080022import java.util.ArrayDeque;
Saurav Das822c4e22015-10-23 10:51:11 -070023import java.util.ArrayList;
24import java.util.Collection;
25import java.util.Collections;
Saurav Das8a0732e2015-11-20 15:27:53 -080026import java.util.Deque;
Saurav Das822c4e22015-10-23 10:51:11 -070027import java.util.List;
Sho SHIMIZU45906042016-01-13 23:05:54 -080028import java.util.Objects;
Saurav Das822c4e22015-10-23 10:51:11 -070029import java.util.Set;
30import java.util.concurrent.ConcurrentHashMap;
Saurav Das1ce0a7b2016-10-21 14:06:29 -070031import java.util.concurrent.ScheduledExecutorService;
32import java.util.concurrent.TimeUnit;
Saurav Das822c4e22015-10-23 10:51:11 -070033
Charles Chan5270ed02016-01-30 23:22:37 -080034import com.google.common.collect.ImmutableList;
Charles Chan5b9df8d2016-03-28 22:21:40 -070035import com.google.common.collect.ImmutableSet;
Saurav Das822c4e22015-10-23 10:51:11 -070036import org.onlab.osgi.ServiceDirectory;
Saurav Das822c4e22015-10-23 10:51:11 -070037import org.onlab.packet.Ethernet;
Charles Chan14967c22015-12-07 11:11:50 -080038import org.onlab.packet.IpPrefix;
Saurav Das822c4e22015-10-23 10:51:11 -070039import org.onlab.packet.MacAddress;
Saurav Das822c4e22015-10-23 10:51:11 -070040import org.onlab.packet.VlanId;
41import org.onlab.util.KryoNamespace;
42import org.onosproject.core.ApplicationId;
43import org.onosproject.core.CoreService;
Charles Chancad338a2016-09-16 18:03:11 -070044import org.onosproject.driver.extensions.Ofdpa3MplsType;
45import org.onosproject.driver.extensions.Ofdpa3SetMplsType;
Charles Chan14967c22015-12-07 11:11:50 -080046import org.onosproject.driver.extensions.OfdpaMatchVlanVid;
47import org.onosproject.driver.extensions.OfdpaSetVlanVid;
Saurav Das822c4e22015-10-23 10:51:11 -070048import org.onosproject.net.DeviceId;
49import org.onosproject.net.Port;
50import org.onosproject.net.PortNumber;
51import org.onosproject.net.behaviour.NextGroup;
52import org.onosproject.net.behaviour.Pipeliner;
53import org.onosproject.net.behaviour.PipelinerContext;
54import org.onosproject.net.device.DeviceService;
55import org.onosproject.net.driver.AbstractHandlerBehaviour;
56import org.onosproject.net.flow.DefaultFlowRule;
57import org.onosproject.net.flow.DefaultTrafficSelector;
58import org.onosproject.net.flow.DefaultTrafficTreatment;
59import org.onosproject.net.flow.FlowRule;
60import org.onosproject.net.flow.FlowRuleOperations;
61import org.onosproject.net.flow.FlowRuleOperationsContext;
62import org.onosproject.net.flow.FlowRuleService;
63import org.onosproject.net.flow.TrafficSelector;
64import org.onosproject.net.flow.TrafficTreatment;
65import org.onosproject.net.flow.criteria.Criteria;
66import org.onosproject.net.flow.criteria.Criterion;
67import org.onosproject.net.flow.criteria.EthCriterion;
68import org.onosproject.net.flow.criteria.EthTypeCriterion;
Charles Chan14967c22015-12-07 11:11:50 -080069import org.onosproject.net.flow.criteria.ExtensionCriterion;
Saurav Das822c4e22015-10-23 10:51:11 -070070import org.onosproject.net.flow.criteria.IPCriterion;
Saurav Das8a0732e2015-11-20 15:27:53 -080071import org.onosproject.net.flow.criteria.MplsBosCriterion;
72import org.onosproject.net.flow.criteria.MplsCriterion;
Saurav Das822c4e22015-10-23 10:51:11 -070073import org.onosproject.net.flow.criteria.PortCriterion;
74import org.onosproject.net.flow.criteria.VlanIdCriterion;
75import org.onosproject.net.flow.instructions.Instruction;
76import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
77import org.onosproject.net.flow.instructions.L2ModificationInstruction;
Saurav Das8a0732e2015-11-20 15:27:53 -080078import org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType;
Saurav Das822c4e22015-10-23 10:51:11 -070079import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction;
Charles Chan14967c22015-12-07 11:11:50 -080080import org.onosproject.net.flow.instructions.L3ModificationInstruction;
81import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType;
Saurav Das822c4e22015-10-23 10:51:11 -070082import org.onosproject.net.flowobjective.FilteringObjective;
83import org.onosproject.net.flowobjective.FlowObjectiveStore;
84import org.onosproject.net.flowobjective.ForwardingObjective;
85import org.onosproject.net.flowobjective.NextObjective;
86import org.onosproject.net.flowobjective.Objective;
87import org.onosproject.net.flowobjective.ObjectiveError;
Saurav Das822c4e22015-10-23 10:51:11 -070088import org.onosproject.net.group.DefaultGroupKey;
89import org.onosproject.net.group.Group;
Saurav Das822c4e22015-10-23 10:51:11 -070090import org.onosproject.net.group.GroupKey;
Saurav Das822c4e22015-10-23 10:51:11 -070091import org.onosproject.net.group.GroupService;
Saurav Das822c4e22015-10-23 10:51:11 -070092import org.onosproject.store.serializers.KryoNamespaces;
93import org.slf4j.Logger;
94
Saurav Das822c4e22015-10-23 10:51:11 -070095/**
96 * Driver for Broadcom's OF-DPA v2.0 TTP.
97 *
98 */
Charles Chan361154b2016-03-24 10:23:39 -070099public class Ofdpa2Pipeline extends AbstractHandlerBehaviour implements Pipeliner {
Saurav Das822c4e22015-10-23 10:51:11 -0700100 protected static final int PORT_TABLE = 0;
101 protected static final int VLAN_TABLE = 10;
102 protected static final int TMAC_TABLE = 20;
103 protected static final int UNICAST_ROUTING_TABLE = 30;
104 protected static final int MULTICAST_ROUTING_TABLE = 40;
105 protected static final int MPLS_TABLE_0 = 23;
106 protected static final int MPLS_TABLE_1 = 24;
Charles Chancad338a2016-09-16 18:03:11 -0700107 protected static final int MPLS_L3_TYPE = 27;
Saurav Das822c4e22015-10-23 10:51:11 -0700108 protected static final int BRIDGING_TABLE = 50;
109 protected static final int ACL_TABLE = 60;
110 protected static final int MAC_LEARNING_TABLE = 254;
111 protected static final long OFPP_MAX = 0xffffff00L;
112
Saurav Das52025962016-01-28 22:30:01 -0800113 protected static final int HIGHEST_PRIORITY = 0xffff;
Saurav Das2857f382015-11-03 14:39:27 -0800114 protected static final int DEFAULT_PRIORITY = 0x8000;
Saurav Das822c4e22015-10-23 10:51:11 -0700115 protected static final int LOWEST_PRIORITY = 0x0;
116
Saurav Das822c4e22015-10-23 10:51:11 -0700117 private final Logger log = getLogger(getClass());
Charles Chan425854b2016-04-11 15:32:12 -0700118 protected ServiceDirectory serviceDirectory;
Saurav Das822c4e22015-10-23 10:51:11 -0700119 protected FlowRuleService flowRuleService;
Charles Chan425854b2016-04-11 15:32:12 -0700120 protected CoreService coreService;
Saurav Das8a0732e2015-11-20 15:27:53 -0800121 protected GroupService groupService;
122 protected FlowObjectiveStore flowObjectiveStore;
Saurav Das822c4e22015-10-23 10:51:11 -0700123 protected DeviceId deviceId;
124 protected ApplicationId driverId;
Saurav Das822c4e22015-10-23 10:51:11 -0700125 protected DeviceService deviceService;
Charles Chan188ebf52015-12-23 00:15:11 -0800126 protected static KryoNamespace appKryo = new KryoNamespace.Builder()
Saurav Das822c4e22015-10-23 10:51:11 -0700127 .register(KryoNamespaces.API)
128 .register(GroupKey.class)
129 .register(DefaultGroupKey.class)
Charles Chan361154b2016-03-24 10:23:39 -0700130 .register(Ofdpa2GroupHandler.OfdpaNextGroup.class)
Saurav Das8a0732e2015-11-20 15:27:53 -0800131 .register(ArrayDeque.class)
Charles Chaneefdedf2016-05-23 16:45:45 -0700132 .build("Ofdpa2Pipeline");
Saurav Das822c4e22015-10-23 10:51:11 -0700133
Charles Chan425854b2016-04-11 15:32:12 -0700134 protected Ofdpa2GroupHandler groupHandler;
Saurav Das822c4e22015-10-23 10:51:11 -0700135
Saurav Das52025962016-01-28 22:30:01 -0800136 protected Set<IPCriterion> sentIpFilters = Collections.newSetFromMap(
Charles Chan188ebf52015-12-23 00:15:11 -0800137 new ConcurrentHashMap<>());
Saurav Das1ce0a7b2016-10-21 14:06:29 -0700138 // flows installations to be retried
139 protected ScheduledExecutorService executorService
140 = newScheduledThreadPool(5, groupedThreads("OfdpaPipeliner", "retry-%d", log));
141 protected static final int MAX_RETRY_ATTEMPTS = 10;
142 protected static final int RETRY_MS = 1000;
Saurav Das4f980082015-11-05 13:39:15 -0800143
Saurav Das822c4e22015-10-23 10:51:11 -0700144 @Override
145 public void init(DeviceId deviceId, PipelinerContext context) {
Saurav Das822c4e22015-10-23 10:51:11 -0700146 this.deviceId = deviceId;
147
Charles Chan188ebf52015-12-23 00:15:11 -0800148 // Initialize OFDPA group handler
Charles Chan425854b2016-04-11 15:32:12 -0700149 groupHandler = new Ofdpa2GroupHandler();
150 groupHandler.init(deviceId, context);
Saurav Das822c4e22015-10-23 10:51:11 -0700151
Charles Chan425854b2016-04-11 15:32:12 -0700152 serviceDirectory = context.directory();
Saurav Das822c4e22015-10-23 10:51:11 -0700153 coreService = serviceDirectory.get(CoreService.class);
154 flowRuleService = serviceDirectory.get(FlowRuleService.class);
155 groupService = serviceDirectory.get(GroupService.class);
156 flowObjectiveStore = context.store();
Saurav Das822c4e22015-10-23 10:51:11 -0700157 deviceService = serviceDirectory.get(DeviceService.class);
Saurav Das822c4e22015-10-23 10:51:11 -0700158
159 driverId = coreService.registerApplication(
Charles Chan425854b2016-04-11 15:32:12 -0700160 "org.onosproject.driver.Ofdpa2Pipeline");
Saurav Das822c4e22015-10-23 10:51:11 -0700161
Saurav Das822c4e22015-10-23 10:51:11 -0700162 initializePipeline();
Saurav Das822c4e22015-10-23 10:51:11 -0700163 }
164
165 protected void initializePipeline() {
Charles Chan188ebf52015-12-23 00:15:11 -0800166 // OF-DPA does not require initializing the pipeline as it puts default
167 // rules automatically in the hardware. However emulation of OFDPA in
168 // software switches does require table-miss-entries.
Saurav Das822c4e22015-10-23 10:51:11 -0700169 }
170
171 //////////////////////////////////////
172 // Flow Objectives
173 //////////////////////////////////////
174
175 @Override
176 public void filter(FilteringObjective filteringObjective) {
177 if (filteringObjective.type() == FilteringObjective.Type.PERMIT) {
178 processFilter(filteringObjective,
179 filteringObjective.op() == Objective.Operation.ADD,
180 filteringObjective.appId());
181 } else {
182 // Note that packets that don't match the PERMIT filter are
183 // automatically denied. The DENY filter is used to deny packets
184 // that are otherwise permitted by the PERMIT filter.
185 // Use ACL table flow rules here for DENY filtering objectives
186 log.debug("filter objective other than PERMIT currently not supported");
187 fail(filteringObjective, ObjectiveError.UNSUPPORTED);
188 }
189 }
190
191 @Override
192 public void forward(ForwardingObjective fwd) {
Saurav Das1ce0a7b2016-10-21 14:06:29 -0700193 Collection<FlowRule> rules = processForward(fwd);
Saurav Das25190812016-05-27 13:54:07 -0700194 if (rules == null || rules.isEmpty()) {
195 // Assumes fail message has already been generated to the objective
196 // context. Returning here prevents spurious pass message to be
197 // generated by FlowRule service for empty flowOps.
198 return;
199 }
Saurav Das1ce0a7b2016-10-21 14:06:29 -0700200 sendForward(fwd, rules);
201 }
202
203 protected void sendForward(ForwardingObjective fwd, Collection<FlowRule> rules) {
204 FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder();
Saurav Das822c4e22015-10-23 10:51:11 -0700205 switch (fwd.op()) {
Saurav Das1ce0a7b2016-10-21 14:06:29 -0700206 case ADD:
207 rules.stream()
208 .filter(Objects::nonNull)
209 .forEach(flowOpsBuilder::add);
Saurav Dasd2fded02016-12-02 15:43:47 -0800210 log.debug("Applying a add fwd-obj {} to sw:{}", fwd.id(), deviceId);
Saurav Das1ce0a7b2016-10-21 14:06:29 -0700211 break;
212 case REMOVE:
213 rules.stream()
214 .filter(Objects::nonNull)
215 .forEach(flowOpsBuilder::remove);
216 break;
217 default:
218 fail(fwd, ObjectiveError.UNKNOWN);
219 log.warn("Unknown forwarding type {}", fwd.op());
Saurav Das822c4e22015-10-23 10:51:11 -0700220 }
221
Saurav Das822c4e22015-10-23 10:51:11 -0700222 flowRuleService.apply(flowOpsBuilder.build(new FlowRuleOperationsContext() {
223 @Override
224 public void onSuccess(FlowRuleOperations ops) {
225 pass(fwd);
226 }
227
228 @Override
229 public void onError(FlowRuleOperations ops) {
230 fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
231 }
232 }));
Saurav Das822c4e22015-10-23 10:51:11 -0700233 }
234
235 @Override
236 public void next(NextObjective nextObjective) {
Saurav Das8a0732e2015-11-20 15:27:53 -0800237 NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id());
238 switch (nextObjective.op()) {
239 case ADD:
Saurav Das4f980082015-11-05 13:39:15 -0800240 if (nextGroup != null) {
Saurav Das8a0732e2015-11-20 15:27:53 -0800241 log.warn("Cannot add next {} that already exists in device {}",
242 nextObjective.id(), deviceId);
243 return;
244 }
245 log.debug("Processing NextObjective id{} in dev{} - add group",
246 nextObjective.id(), deviceId);
Charles Chan425854b2016-04-11 15:32:12 -0700247 groupHandler.addGroup(nextObjective);
Saurav Das8a0732e2015-11-20 15:27:53 -0800248 break;
249 case ADD_TO_EXISTING:
250 if (nextGroup != null) {
251 log.debug("Processing NextObjective id{} in dev{} - add bucket",
252 nextObjective.id(), deviceId);
Charles Chan425854b2016-04-11 15:32:12 -0700253 groupHandler.addBucketToGroup(nextObjective, nextGroup);
Saurav Das4f980082015-11-05 13:39:15 -0800254 } else {
Saurav Das8a0732e2015-11-20 15:27:53 -0800255 // it is possible that group-chain has not been fully created yet
Saurav Das423fe2b2015-12-04 10:52:59 -0800256 log.debug("Waiting to add bucket to group for next-id:{} in dev:{}",
257 nextObjective.id(), deviceId);
258 // by design only one pending bucket is allowed for the group
Charles Chan425854b2016-04-11 15:32:12 -0700259 groupHandler.pendingBuckets.put(nextObjective.id(), nextObjective);
Saurav Das4f980082015-11-05 13:39:15 -0800260 }
Saurav Das8a0732e2015-11-20 15:27:53 -0800261 break;
262 case REMOVE:
263 if (nextGroup == null) {
264 log.warn("Cannot remove next {} that does not exist in device {}",
265 nextObjective.id(), deviceId);
266 return;
267 }
268 log.debug("Processing NextObjective id{} in dev{} - remove group",
269 nextObjective.id(), deviceId);
Charles Chan425854b2016-04-11 15:32:12 -0700270 groupHandler.removeGroup(nextObjective, nextGroup);
Saurav Das8a0732e2015-11-20 15:27:53 -0800271 break;
272 case REMOVE_FROM_EXISTING:
273 if (nextGroup == null) {
274 log.warn("Cannot remove from next {} that does not exist in device {}",
275 nextObjective.id(), deviceId);
276 return;
277 }
278 log.debug("Processing NextObjective id{} in dev{} - remove bucket",
279 nextObjective.id(), deviceId);
Charles Chan425854b2016-04-11 15:32:12 -0700280 groupHandler.removeBucketFromGroup(nextObjective, nextGroup);
Saurav Das8a0732e2015-11-20 15:27:53 -0800281 break;
282 default:
Saurav Das4f980082015-11-05 13:39:15 -0800283 log.warn("Unsupported operation {}", nextObjective.op());
Saurav Das822c4e22015-10-23 10:51:11 -0700284 }
285 }
286
287 //////////////////////////////////////
288 // Flow handling
289 //////////////////////////////////////
290
291 /**
292 * As per OFDPA 2.0 TTP, filtering of VLAN ids, MAC addresses (for routing)
293 * and IP addresses configured on switch ports happen in different tables.
294 * Note that IP filtering rules need to be added to the ACL table, as there
295 * is no mechanism to send to controller via IP table.
296 *
297 * @param filt the filtering objective
298 * @param install indicates whether to add or remove the objective
299 * @param applicationId the application that sent this objective
300 */
Saurav Das52025962016-01-28 22:30:01 -0800301 protected void processFilter(FilteringObjective filt,
302 boolean install, ApplicationId applicationId) {
Saurav Das822c4e22015-10-23 10:51:11 -0700303 // This driver only processes filtering criteria defined with switch
304 // ports as the key
305 PortCriterion portCriterion = null;
306 EthCriterion ethCriterion = null;
307 VlanIdCriterion vidCriterion = null;
308 Collection<IPCriterion> ips = new ArrayList<IPCriterion>();
309 if (!filt.key().equals(Criteria.dummy()) &&
310 filt.key().type() == Criterion.Type.IN_PORT) {
311 portCriterion = (PortCriterion) filt.key();
312 } else {
313 log.warn("No key defined in filtering objective from app: {}. Not"
314 + "processing filtering objective", applicationId);
Saurav Das59232cf2016-04-27 18:35:50 -0700315 fail(filt, ObjectiveError.BADPARAMS);
Saurav Das822c4e22015-10-23 10:51:11 -0700316 return;
317 }
Saurav Das59232cf2016-04-27 18:35:50 -0700318 log.debug("Received filtering objective for dev/port: {}/{}", deviceId,
319 portCriterion.port());
Saurav Das822c4e22015-10-23 10:51:11 -0700320 // convert filtering conditions for switch-intfs into flowrules
321 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
322 for (Criterion criterion : filt.conditions()) {
Charles Chan5b9df8d2016-03-28 22:21:40 -0700323 if (criterion.type() == Criterion.Type.ETH_DST ||
324 criterion.type() == Criterion.Type.ETH_DST_MASKED) {
Saurav Das822c4e22015-10-23 10:51:11 -0700325 ethCriterion = (EthCriterion) criterion;
326 } else if (criterion.type() == Criterion.Type.VLAN_VID) {
327 vidCriterion = (VlanIdCriterion) criterion;
328 } else if (criterion.type() == Criterion.Type.IPV4_DST) {
329 ips.add((IPCriterion) criterion);
330 } else {
331 log.error("Unsupported filter {}", criterion);
332 fail(filt, ObjectiveError.UNSUPPORTED);
333 return;
334 }
335 }
336
Saurav Das0e99e2b2015-10-28 12:39:42 -0700337 VlanId assignedVlan = null;
Charles Chane849c192016-01-11 18:28:54 -0800338 if (vidCriterion != null) {
Charles Chand55e84d2016-03-30 17:54:24 -0700339 // Use the VLAN in metadata whenever a metadata is provided
340 if (filt.meta() != null) {
341 assignedVlan = readVlanFromTreatment(filt.meta());
342 // Use the VLAN in criterion if metadata is not present and the traffic is tagged
343 } else if (!vidCriterion.vlanId().equals(VlanId.NONE)) {
Charles Chane849c192016-01-11 18:28:54 -0800344 assignedVlan = vidCriterion.vlanId();
Charles Chand55e84d2016-03-30 17:54:24 -0700345 }
Charles Chane849c192016-01-11 18:28:54 -0800346
Charles Chand55e84d2016-03-30 17:54:24 -0700347 if (assignedVlan == null) {
348 log.error("Driver fails to extract VLAN information. "
349 + "Not proccessing VLAN filters on device {}.", deviceId);
350 log.debug("VLAN ID in criterion={}, metadata={}",
351 readVlanFromTreatment(filt.meta()), vidCriterion.vlanId());
352 fail(filt, ObjectiveError.BADPARAMS);
353 return;
Saurav Das0e99e2b2015-10-28 12:39:42 -0700354 }
355 }
356
Charles Chane849c192016-01-11 18:28:54 -0800357 if (ethCriterion == null || ethCriterion.mac().equals(MacAddress.NONE)) {
Charles Chan985b12e2016-05-11 19:47:22 -0700358 // NOTE: it is possible that a filtering objective only has vidCriterion
359 log.debug("filtering objective missing dstMac, cannot program TMAC table");
Saurav Das822c4e22015-10-23 10:51:11 -0700360 } else {
361 for (FlowRule tmacRule : processEthDstFilter(portCriterion, ethCriterion,
Saurav Das0e99e2b2015-10-28 12:39:42 -0700362 vidCriterion, assignedVlan,
363 applicationId)) {
Saurav Das822c4e22015-10-23 10:51:11 -0700364 log.debug("adding MAC filtering rules in TMAC table: {} for dev: {}",
365 tmacRule, deviceId);
366 ops = install ? ops.add(tmacRule) : ops.remove(tmacRule);
367 }
368 }
369
Charles Chan985b12e2016-05-11 19:47:22 -0700370 if (vidCriterion == null) {
371 // NOTE: it is possible that a filtering objective only has ethCriterion
372 log.debug("filtering objective missing dstMac or VLAN, "
Charles Chane849c192016-01-11 18:28:54 -0800373 + "cannot program VLAN Table");
Saurav Das822c4e22015-10-23 10:51:11 -0700374 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800375 /*
376 * NOTE: Separate vlan filtering rules and assignment rules
377 * into different stage in order to guarantee that filtering rules
Saurav Das52025962016-01-28 22:30:01 -0800378 * always go first, as required by ofdpa.
Charles Chan14967c22015-12-07 11:11:50 -0800379 */
380 List<FlowRule> allRules = processVlanIdFilter(
381 portCriterion, vidCriterion, assignedVlan, applicationId);
382 List<FlowRule> filteringRules = new ArrayList<>();
383 List<FlowRule> assignmentRules = new ArrayList<>();
384
385 allRules.forEach(flowRule -> {
386 ExtensionCriterion extCriterion =
387 (ExtensionCriterion) flowRule.selector().getCriterion(Criterion.Type.EXTENSION);
388 VlanId vlanId = ((OfdpaMatchVlanVid) extCriterion.extensionSelector()).vlanId();
Charles Chanbe8aea42016-02-24 12:04:47 -0800389 if (!vlanId.equals(VlanId.NONE)) {
Charles Chan14967c22015-12-07 11:11:50 -0800390 filteringRules.add(flowRule);
391 } else {
392 assignmentRules.add(flowRule);
393 }
394 });
395
396 for (FlowRule filteringRule : filteringRules) {
Saurav Das822c4e22015-10-23 10:51:11 -0700397 log.debug("adding VLAN filtering rule in VLAN table: {} for dev: {}",
Charles Chan14967c22015-12-07 11:11:50 -0800398 filteringRule, deviceId);
399 ops = install ? ops.add(filteringRule) : ops.remove(filteringRule);
400 }
401
402 ops.newStage();
403
404 for (FlowRule assignmentRule : assignmentRules) {
405 log.debug("adding VLAN assignment rule in VLAN table: {} for dev: {}",
406 assignmentRule, deviceId);
407 ops = install ? ops.add(assignmentRule) : ops.remove(assignmentRule);
Saurav Das822c4e22015-10-23 10:51:11 -0700408 }
409 }
410
411 for (IPCriterion ipaddr : ips) {
412 // since we ignore port information for IP rules, and the same (gateway) IP
413 // can be configured on multiple ports, we make sure that we send
414 // only a single rule to the switch.
415 if (!sentIpFilters.contains(ipaddr)) {
416 sentIpFilters.add(ipaddr);
417 log.debug("adding IP filtering rules in ACL table {} for dev: {}",
418 ipaddr, deviceId);
419 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
420 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
421 selector.matchEthType(Ethernet.TYPE_IPV4);
422 selector.matchIPDst(ipaddr.ip());
423 treatment.setOutput(PortNumber.CONTROLLER);
424 FlowRule rule = DefaultFlowRule.builder()
425 .forDevice(deviceId)
426 .withSelector(selector.build())
427 .withTreatment(treatment.build())
428 .withPriority(HIGHEST_PRIORITY)
429 .fromApp(applicationId)
430 .makePermanent()
431 .forTable(ACL_TABLE).build();
432 ops = install ? ops.add(rule) : ops.remove(rule);
433 }
434 }
435
436 // apply filtering flow rules
437 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
438 @Override
439 public void onSuccess(FlowRuleOperations ops) {
440 log.info("Applied {} filtering rules in device {}",
441 ops.stages().get(0).size(), deviceId);
442 pass(filt);
443 }
444
445 @Override
446 public void onError(FlowRuleOperations ops) {
447 log.info("Failed to apply all filtering rules in dev {}", deviceId);
448 fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED);
449 }
450 }));
451
452 }
453
454 /**
455 * Allows untagged packets into pipeline by assigning a vlan id.
Saurav Das0e99e2b2015-10-28 12:39:42 -0700456 * Vlan assignment is done by the application.
Saurav Das822c4e22015-10-23 10:51:11 -0700457 * Allows tagged packets into pipeline as per configured port-vlan info.
Saurav Das0e99e2b2015-10-28 12:39:42 -0700458 *
Charles Chanf9e98652016-09-07 16:54:23 -0700459 * @param portCriterion port on device for which this filter is programmed
460 * @param vidCriterion vlan assigned to port, or NONE for untagged
461 * @param assignedVlan assigned vlan-id for untagged packets
462 * @param applicationId for application programming this filter
Saurav Das822c4e22015-10-23 10:51:11 -0700463 * @return list of FlowRule for port-vlan filters
464 */
465 protected List<FlowRule> processVlanIdFilter(PortCriterion portCriterion,
466 VlanIdCriterion vidCriterion,
Saurav Das0e99e2b2015-10-28 12:39:42 -0700467 VlanId assignedVlan,
Saurav Das822c4e22015-10-23 10:51:11 -0700468 ApplicationId applicationId) {
Charles Chanf9e98652016-09-07 16:54:23 -0700469 return processVlanIdFilterInternal(portCriterion, vidCriterion, assignedVlan,
470 applicationId, true);
471 }
472
473 /**
474 * Internal implementation of processVlanIdFilter.
475 * <p>
476 * The is_present bit in set_vlan_vid action is required to be 0 in OFDPA i12.
477 * Since it is non-OF spec, we need an extension treatment for that.
478 * The useSetVlanExtension must be set to false for OFDPA i12.
479 * </p>
480 *
481 * @param portCriterion port on device for which this filter is programmed
482 * @param vidCriterion vlan assigned to port, or NONE for untagged
483 * @param assignedVlan assigned vlan-id for untagged packets
484 * @param applicationId for application programming this filter
485 * @param useSetVlanExtension use the setVlanVid extension that has is_present bit set to 0.
486 * @return list of FlowRule for port-vlan filters
487 */
488 protected List<FlowRule> processVlanIdFilterInternal(PortCriterion portCriterion,
489 VlanIdCriterion vidCriterion,
490 VlanId assignedVlan,
491 ApplicationId applicationId,
492 boolean useSetVlanExtension) {
Charles Chan14967c22015-12-07 11:11:50 -0800493 List<FlowRule> rules = new ArrayList<>();
Saurav Das822c4e22015-10-23 10:51:11 -0700494 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
495 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
Charles Chan14967c22015-12-07 11:11:50 -0800496 TrafficSelector.Builder preSelector = null;
497 TrafficTreatment.Builder preTreatment = null;
498
Saurav Das4f980082015-11-05 13:39:15 -0800499 treatment.transition(TMAC_TABLE);
500
Saurav Das822c4e22015-10-23 10:51:11 -0700501 if (vidCriterion.vlanId() == VlanId.NONE) {
502 // untagged packets are assigned vlans
Charles Chanbe8aea42016-02-24 12:04:47 -0800503 OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(VlanId.NONE);
Charles Chan14967c22015-12-07 11:11:50 -0800504 selector.extension(ofdpaMatchVlanVid, deviceId);
Charles Chanf9e98652016-09-07 16:54:23 -0700505 if (useSetVlanExtension) {
506 OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(assignedVlan);
507 treatment.extension(ofdpaSetVlanVid, deviceId);
508 } else {
509 treatment.setVlanId(assignedVlan);
510 }
Charles Chan14967c22015-12-07 11:11:50 -0800511
512 preSelector = DefaultTrafficSelector.builder();
513 OfdpaMatchVlanVid preOfdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan);
514 preSelector.extension(preOfdpaMatchVlanVid, deviceId);
515 preTreatment = DefaultTrafficTreatment.builder().transition(TMAC_TABLE);
516
Saurav Das4f980082015-11-05 13:39:15 -0800517 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800518 OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vidCriterion.vlanId());
519 selector.extension(ofdpaMatchVlanVid, deviceId);
Charles Chand55e84d2016-03-30 17:54:24 -0700520
521 if (!assignedVlan.equals(vidCriterion.vlanId())) {
522 OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(assignedVlan);
523 treatment.extension(ofdpaSetVlanVid, deviceId);
524 }
Saurav Das822c4e22015-10-23 10:51:11 -0700525 }
Saurav Das822c4e22015-10-23 10:51:11 -0700526
527 // ofdpa cannot match on ALL portnumber, so we need to use separate
528 // rules for each port.
Charles Chan14967c22015-12-07 11:11:50 -0800529 List<PortNumber> portnums = new ArrayList<>();
Saurav Das822c4e22015-10-23 10:51:11 -0700530 if (portCriterion.port() == PortNumber.ALL) {
531 for (Port port : deviceService.getPorts(deviceId)) {
532 if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
533 portnums.add(port.number());
534 }
535 }
536 } else {
537 portnums.add(portCriterion.port());
538 }
Saurav Das4f980082015-11-05 13:39:15 -0800539
Saurav Das822c4e22015-10-23 10:51:11 -0700540 for (PortNumber pnum : portnums) {
Saurav Das4f980082015-11-05 13:39:15 -0800541 // create rest of flowrule
Saurav Das822c4e22015-10-23 10:51:11 -0700542 selector.matchInPort(pnum);
543 FlowRule rule = DefaultFlowRule.builder()
544 .forDevice(deviceId)
545 .withSelector(selector.build())
546 .withTreatment(treatment.build())
547 .withPriority(DEFAULT_PRIORITY)
548 .fromApp(applicationId)
549 .makePermanent()
550 .forTable(VLAN_TABLE).build();
Charles Chan14967c22015-12-07 11:11:50 -0800551
552 if (preSelector != null) {
553 preSelector.matchInPort(pnum);
554 FlowRule preRule = DefaultFlowRule.builder()
555 .forDevice(deviceId)
556 .withSelector(preSelector.build())
557 .withTreatment(preTreatment.build())
558 .withPriority(DEFAULT_PRIORITY)
559 .fromApp(applicationId)
560 .makePermanent()
561 .forTable(VLAN_TABLE).build();
562 rules.add(preRule);
563 }
564
Saurav Das822c4e22015-10-23 10:51:11 -0700565 rules.add(rule);
566 }
567 return rules;
568 }
569
570 /**
571 * Allows routed packets with correct destination MAC to be directed
572 * to unicast-IP routing table or MPLS forwarding table.
Saurav Das822c4e22015-10-23 10:51:11 -0700573 *
574 * @param portCriterion port on device for which this filter is programmed
575 * @param ethCriterion dstMac of device for which is filter is programmed
576 * @param vidCriterion vlan assigned to port, or NONE for untagged
Saurav Das0e99e2b2015-10-28 12:39:42 -0700577 * @param assignedVlan assigned vlan-id for untagged packets
Saurav Das822c4e22015-10-23 10:51:11 -0700578 * @param applicationId for application programming this filter
579 * @return list of FlowRule for port-vlan filters
580
581 */
582 protected List<FlowRule> processEthDstFilter(PortCriterion portCriterion,
583 EthCriterion ethCriterion,
584 VlanIdCriterion vidCriterion,
Saurav Das0e99e2b2015-10-28 12:39:42 -0700585 VlanId assignedVlan,
Saurav Das822c4e22015-10-23 10:51:11 -0700586 ApplicationId applicationId) {
Charles Chan5270ed02016-01-30 23:22:37 -0800587 // Consider PortNumber.ANY as wildcard. Match ETH_DST only
588 if (portCriterion != null && portCriterion.port() == PortNumber.ANY) {
589 return processEthDstOnlyFilter(ethCriterion, applicationId);
590 }
591
Charles Chan5b9df8d2016-03-28 22:21:40 -0700592 // Multicast MAC
593 if (ethCriterion.mask() != null) {
594 return processMcastEthDstFilter(ethCriterion, applicationId);
595 }
596
Saurav Das822c4e22015-10-23 10:51:11 -0700597 //handling untagged packets via assigned VLAN
598 if (vidCriterion.vlanId() == VlanId.NONE) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700599 vidCriterion = (VlanIdCriterion) Criteria.matchVlanId(assignedVlan);
Saurav Das822c4e22015-10-23 10:51:11 -0700600 }
601 // ofdpa cannot match on ALL portnumber, so we need to use separate
602 // rules for each port.
603 List<PortNumber> portnums = new ArrayList<PortNumber>();
604 if (portCriterion.port() == PortNumber.ALL) {
605 for (Port port : deviceService.getPorts(deviceId)) {
606 if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
607 portnums.add(port.number());
608 }
609 }
610 } else {
611 portnums.add(portCriterion.port());
612 }
613
614 List<FlowRule> rules = new ArrayList<FlowRule>();
615 for (PortNumber pnum : portnums) {
Charles Chan14967c22015-12-07 11:11:50 -0800616 OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vidCriterion.vlanId());
Saurav Das822c4e22015-10-23 10:51:11 -0700617 // for unicast IP packets
618 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
619 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
620 selector.matchInPort(pnum);
Charles Chan14967c22015-12-07 11:11:50 -0800621 selector.extension(ofdpaMatchVlanVid, deviceId);
Saurav Das822c4e22015-10-23 10:51:11 -0700622 selector.matchEthType(Ethernet.TYPE_IPV4);
623 selector.matchEthDst(ethCriterion.mac());
624 treatment.transition(UNICAST_ROUTING_TABLE);
625 FlowRule rule = DefaultFlowRule.builder()
626 .forDevice(deviceId)
627 .withSelector(selector.build())
628 .withTreatment(treatment.build())
629 .withPriority(DEFAULT_PRIORITY)
630 .fromApp(applicationId)
631 .makePermanent()
632 .forTable(TMAC_TABLE).build();
633 rules.add(rule);
634 //for MPLS packets
635 selector = DefaultTrafficSelector.builder();
636 treatment = DefaultTrafficTreatment.builder();
637 selector.matchInPort(pnum);
Charles Chan14967c22015-12-07 11:11:50 -0800638 selector.extension(ofdpaMatchVlanVid, deviceId);
Saurav Das822c4e22015-10-23 10:51:11 -0700639 selector.matchEthType(Ethernet.MPLS_UNICAST);
640 selector.matchEthDst(ethCriterion.mac());
641 treatment.transition(MPLS_TABLE_0);
642 rule = DefaultFlowRule.builder()
643 .forDevice(deviceId)
644 .withSelector(selector.build())
645 .withTreatment(treatment.build())
646 .withPriority(DEFAULT_PRIORITY)
647 .fromApp(applicationId)
648 .makePermanent()
649 .forTable(TMAC_TABLE).build();
650 rules.add(rule);
651 }
652 return rules;
653 }
654
Charles Chan5270ed02016-01-30 23:22:37 -0800655 protected List<FlowRule> processEthDstOnlyFilter(EthCriterion ethCriterion,
656 ApplicationId applicationId) {
657 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
658 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
659 selector.matchEthType(Ethernet.TYPE_IPV4);
660 selector.matchEthDst(ethCriterion.mac());
661 treatment.transition(UNICAST_ROUTING_TABLE);
662 FlowRule rule = DefaultFlowRule.builder()
663 .forDevice(deviceId)
664 .withSelector(selector.build())
665 .withTreatment(treatment.build())
666 .withPriority(DEFAULT_PRIORITY)
667 .fromApp(applicationId)
668 .makePermanent()
669 .forTable(TMAC_TABLE).build();
670 return ImmutableList.<FlowRule>builder().add(rule).build();
671 }
672
Charles Chan5b9df8d2016-03-28 22:21:40 -0700673 protected List<FlowRule> processMcastEthDstFilter(EthCriterion ethCriterion,
674 ApplicationId applicationId) {
675 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
676 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
677 selector.matchEthType(Ethernet.TYPE_IPV4);
678 selector.matchEthDstMasked(ethCriterion.mac(), ethCriterion.mask());
679 treatment.transition(MULTICAST_ROUTING_TABLE);
680 FlowRule rule = DefaultFlowRule.builder()
681 .forDevice(deviceId)
682 .withSelector(selector.build())
683 .withTreatment(treatment.build())
684 .withPriority(DEFAULT_PRIORITY)
685 .fromApp(applicationId)
686 .makePermanent()
687 .forTable(TMAC_TABLE).build();
688 return ImmutableList.<FlowRule>builder().add(rule).build();
689 }
690
Saurav Das822c4e22015-10-23 10:51:11 -0700691 private Collection<FlowRule> processForward(ForwardingObjective fwd) {
692 switch (fwd.flag()) {
693 case SPECIFIC:
694 return processSpecific(fwd);
695 case VERSATILE:
696 return processVersatile(fwd);
697 default:
698 fail(fwd, ObjectiveError.UNKNOWN);
699 log.warn("Unknown forwarding flag {}", fwd.flag());
700 }
701 return Collections.emptySet();
702 }
703
704 /**
705 * In the OF-DPA 2.0 pipeline, versatile forwarding objectives go to the
706 * ACL table.
707 * @param fwd the forwarding objective of type 'versatile'
708 * @return a collection of flow rules to be sent to the switch. An empty
709 * collection may be returned if there is a problem in processing
710 * the flow rule
711 */
Saurav Das52025962016-01-28 22:30:01 -0800712 protected Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
Saurav Dasd2fded02016-12-02 15:43:47 -0800713 log.info("Processing versatile forwarding objective:{} in dev:{}",
714 fwd.id(), deviceId);
Saurav Das822c4e22015-10-23 10:51:11 -0700715
716 EthTypeCriterion ethType =
Saurav Das77b5e902016-01-27 17:01:59 -0800717 (EthTypeCriterion) fwd.selector().getCriterion(Criterion.Type.ETH_TYPE);
Saurav Das822c4e22015-10-23 10:51:11 -0700718 if (ethType == null) {
Saurav Dasd2fded02016-12-02 15:43:47 -0800719 log.error("Versatile forwarding objective:{} must include ethType",
720 fwd.id());
Saurav Das822c4e22015-10-23 10:51:11 -0700721 fail(fwd, ObjectiveError.BADPARAMS);
722 return Collections.emptySet();
723 }
724 if (fwd.nextId() == null && fwd.treatment() == null) {
725 log.error("Forwarding objective {} from {} must contain "
726 + "nextId or Treatment", fwd.selector(), fwd.appId());
Zsolt Haraszti9faab752016-02-17 15:55:20 -0800727 fail(fwd, ObjectiveError.BADPARAMS);
Saurav Das822c4e22015-10-23 10:51:11 -0700728 return Collections.emptySet();
729 }
Saurav Das49cb5a12016-01-16 22:54:07 -0800730
Saurav Das77b5e902016-01-27 17:01:59 -0800731 TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
732 fwd.selector().criteria().forEach(criterion -> {
733 if (criterion instanceof VlanIdCriterion) {
734 VlanId vlanId = ((VlanIdCriterion) criterion).vlanId();
735 // ensure that match does not include vlan = NONE as OF-DPA does not
736 // match untagged packets this way in the ACL table.
737 if (vlanId.equals(VlanId.NONE)) {
738 return;
739 }
740 OfdpaMatchVlanVid ofdpaMatchVlanVid =
741 new OfdpaMatchVlanVid(vlanId);
742 sbuilder.extension(ofdpaMatchVlanVid, deviceId);
743 } else {
744 sbuilder.add(criterion);
745 }
746 });
747
Saurav Das822c4e22015-10-23 10:51:11 -0700748 // XXX driver does not currently do type checking as per Tables 65-67 in
749 // OFDPA 2.0 spec. The only allowed treatment is a punt to the controller.
Saurav Das49cb5a12016-01-16 22:54:07 -0800750 TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
751 if (fwd.treatment() != null) {
752 for (Instruction ins : fwd.treatment().allInstructions()) {
753 if (ins instanceof OutputInstruction) {
754 OutputInstruction o = (OutputInstruction) ins;
755 if (o.port() == PortNumber.CONTROLLER) {
756 ttBuilder.add(o);
757 } else {
758 log.warn("Only allowed treatments in versatile forwarding "
759 + "objectives are punts to the controller");
760 }
761 } else {
762 log.warn("Cannot process instruction in versatile fwd {}", ins);
763 }
Saurav Das822c4e22015-10-23 10:51:11 -0700764 }
Charles Chan2df0e8a2017-01-09 11:45:08 -0800765 if (fwd.treatment().clearedDeferred()) {
766 ttBuilder.wipeDeferred();
767 }
Saurav Das822c4e22015-10-23 10:51:11 -0700768 }
Saurav Das822c4e22015-10-23 10:51:11 -0700769 if (fwd.nextId() != null) {
Saurav Das49cb5a12016-01-16 22:54:07 -0800770 // overide case
771 NextGroup next = getGroupForNextObjective(fwd.nextId());
772 List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
773 // we only need the top level group's key to point the flow to it
774 Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
775 if (group == null) {
776 log.warn("Group with key:{} for next-id:{} not found in dev:{}",
777 gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
778 fail(fwd, ObjectiveError.GROUPMISSING);
779 return Collections.emptySet();
780 }
781 ttBuilder.deferred().group(group.id());
Saurav Das822c4e22015-10-23 10:51:11 -0700782 }
Saurav Das49cb5a12016-01-16 22:54:07 -0800783
784 FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
785 .fromApp(fwd.appId())
786 .withPriority(fwd.priority())
787 .forDevice(deviceId)
Saurav Das77b5e902016-01-27 17:01:59 -0800788 .withSelector(sbuilder.build())
Saurav Das49cb5a12016-01-16 22:54:07 -0800789 .withTreatment(ttBuilder.build())
790 .makePermanent()
791 .forTable(ACL_TABLE);
792 return Collections.singletonList(ruleBuilder.build());
Saurav Das822c4e22015-10-23 10:51:11 -0700793 }
794
795 /**
796 * In the OF-DPA 2.0 pipeline, specific forwarding refers to the IP table
Saurav Das8a0732e2015-11-20 15:27:53 -0800797 * (unicast or multicast) or the L2 table (mac + vlan) or the MPLS table.
Saurav Das822c4e22015-10-23 10:51:11 -0700798 *
799 * @param fwd the forwarding objective of type 'specific'
800 * @return a collection of flow rules. Typically there will be only one
801 * for this type of forwarding objective. An empty set may be
802 * returned if there is an issue in processing the objective.
803 */
Saurav Das8a0732e2015-11-20 15:27:53 -0800804 protected Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
Saurav Das25190812016-05-27 13:54:07 -0700805 log.debug("Processing specific fwd objective:{} in dev:{} with next:{}",
Saurav Das4ce45962015-11-24 23:21:05 -0800806 fwd.id(), deviceId, fwd.nextId());
807 boolean isEthTypeObj = isSupportedEthTypeObjective(fwd);
808 boolean isEthDstObj = isSupportedEthDstObjective(fwd);
809
810 if (isEthTypeObj) {
811 return processEthTypeSpecific(fwd);
812 } else if (isEthDstObj) {
813 return processEthDstSpecific(fwd);
814 } else {
815 log.warn("processSpecific: Unsupported forwarding objective "
816 + "criteria fwd:{} in dev:{}", fwd.nextId(), deviceId);
Saurav Das822c4e22015-10-23 10:51:11 -0700817 fail(fwd, ObjectiveError.UNSUPPORTED);
818 return Collections.emptySet();
819 }
Saurav Das4ce45962015-11-24 23:21:05 -0800820 }
821
Saurav Das4ce45962015-11-24 23:21:05 -0800822 /**
823 * Handles forwarding rules to the IP and MPLS tables.
824 *
825 * @param fwd the forwarding objective
826 * @return A collection of flow rules, or an empty set
827 */
828 protected Collection<FlowRule> processEthTypeSpecific(ForwardingObjective fwd) {
Charles Chancad338a2016-09-16 18:03:11 -0700829 return processEthTypeSpecificInternal(fwd, false, ACL_TABLE);
Charles Chanf9e98652016-09-07 16:54:23 -0700830 }
831
832 /**
833 * Internal implementation of processEthTypeSpecific.
834 * <p>
835 * Wildcarded IPv4_DST is not supported in OFDPA i12. Therefore, we break
836 * the rule into 0.0.0.0/1 and 128.0.0.0/1.
837 * The allowDefaultRoute must be set to false for OFDPA i12.
838 * </p>
839 *
840 * @param fwd the forwarding objective
841 * @param allowDefaultRoute allow wildcarded IPv4_DST or not
Ray Milkey0bb1e102016-11-10 14:51:27 -0800842 * @param mplsNextTable next MPLS table
Charles Chanf9e98652016-09-07 16:54:23 -0700843 * @return A collection of flow rules, or an empty set
844 */
845 protected Collection<FlowRule> processEthTypeSpecificInternal(ForwardingObjective fwd,
Charles Chancad338a2016-09-16 18:03:11 -0700846 boolean allowDefaultRoute,
847 int mplsNextTable) {
Saurav Das4ce45962015-11-24 23:21:05 -0800848 TrafficSelector selector = fwd.selector();
849 EthTypeCriterion ethType =
850 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
Flavio Castroe10fa242016-01-15 12:43:51 -0800851 boolean defaultRule = false;
852 boolean popMpls = false;
Saurav Das1ce0a7b2016-10-21 14:06:29 -0700853 boolean emptyGroup = false;
Charles Chan188ebf52015-12-23 00:15:11 -0800854 int forTableId;
Saurav Das8a0732e2015-11-20 15:27:53 -0800855 TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder();
Charles Chan14967c22015-12-07 11:11:50 -0800856 TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
Flavio Castroe10fa242016-01-15 12:43:51 -0800857 TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder();
Charles Chan14967c22015-12-07 11:11:50 -0800858
Saurav Das8a0732e2015-11-20 15:27:53 -0800859 if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
Flavio Castroe10fa242016-01-15 12:43:51 -0800860 IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
Charles Chan5b9df8d2016-03-28 22:21:40 -0700861 if (ipv4Dst.isMulticast()) {
862 if (ipv4Dst.prefixLength() != 32) {
863 log.warn("Multicast specific forwarding objective can only be /32");
864 fail(fwd, ObjectiveError.BADPARAMS);
865 return ImmutableSet.of();
866 }
867 VlanId assignedVlan = readVlanFromSelector(fwd.meta());
868 if (assignedVlan == null) {
869 log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort.");
870 fail(fwd, ObjectiveError.BADPARAMS);
871 return ImmutableSet.of();
872 }
873 OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan);
874 filteredSelector.extension(ofdpaMatchVlanVid, deviceId);
875 filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst);
876 forTableId = MULTICAST_ROUTING_TABLE;
877 log.debug("processing IPv4 multicast specific forwarding objective {} -> next:{}"
878 + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
Flavio Castroe10fa242016-01-15 12:43:51 -0800879 } else {
Charles Chanf9e98652016-09-07 16:54:23 -0700880 if (ipv4Dst.prefixLength() == 0) {
881 if (allowDefaultRoute) {
882 // The entire IPV4_DST field is wildcarded intentionally
883 filteredSelector.matchEthType(Ethernet.TYPE_IPV4);
884 } else {
885 /*
886 * NOTE: The switch does not support matching 0.0.0.0/0
887 * Split it into 0.0.0.0/1 and 128.0.0.0/1
888 */
889 filteredSelector.matchEthType(Ethernet.TYPE_IPV4)
890 .matchIPDst(IpPrefix.valueOf("0.0.0.0/1"));
891 complementarySelector.matchEthType(Ethernet.TYPE_IPV4)
892 .matchIPDst(IpPrefix.valueOf("128.0.0.0/1"));
893 defaultRule = true;
894 }
Charles Chan5b9df8d2016-03-28 22:21:40 -0700895 } else {
Charles Chanf9e98652016-09-07 16:54:23 -0700896 filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700897 }
898 forTableId = UNICAST_ROUTING_TABLE;
899 log.debug("processing IPv4 unicast specific forwarding objective {} -> next:{}"
900 + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
Flavio Castroe10fa242016-01-15 12:43:51 -0800901 }
Charles Chan14967c22015-12-07 11:11:50 -0800902
903 if (fwd.treatment() != null) {
904 for (Instruction instr : fwd.treatment().allInstructions()) {
905 if (instr instanceof L3ModificationInstruction &&
906 ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) {
Saurav Das9c705342017-01-06 11:36:01 -0800907 // XXX decrementing IP ttl is done automatically for routing, this
908 // action is ignored or rejected in ofdpa as it is not fully implemented
909 //tb.deferred().add(instr);
Charles Chan14967c22015-12-07 11:11:50 -0800910 }
911 }
912 }
913
Saurav Das8a0732e2015-11-20 15:27:53 -0800914 } else {
915 filteredSelector
916 .matchEthType(Ethernet.MPLS_UNICAST)
917 .matchMplsLabel(((MplsCriterion)
918 selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
919 MplsBosCriterion bos = (MplsBosCriterion) selector
920 .getCriterion(Criterion.Type.MPLS_BOS);
921 if (bos != null) {
922 filteredSelector.matchMplsBos(bos.mplsBos());
923 }
924 forTableId = MPLS_TABLE_1;
Saurav Das4ce45962015-11-24 23:21:05 -0800925 log.debug("processing MPLS specific forwarding objective {} -> next:{}"
926 + " in dev {}", fwd.id(), fwd.nextId(), deviceId);
Saurav Das822c4e22015-10-23 10:51:11 -0700927
Charles Chan14967c22015-12-07 11:11:50 -0800928 if (fwd.treatment() != null) {
929 for (Instruction instr : fwd.treatment().allInstructions()) {
930 if (instr instanceof L2ModificationInstruction &&
931 ((L2ModificationInstruction) instr).subtype() == L2SubType.MPLS_POP) {
Saurav Das8a0732e2015-11-20 15:27:53 -0800932 popMpls = true;
Saurav Das9c705342017-01-06 11:36:01 -0800933 // OF-DPA does not pop in MPLS table. Instead it requires
934 // setting the MPLS_TYPE so pop can happen down the pipeline
Charles Chan14967c22015-12-07 11:11:50 -0800935 }
936 if (instr instanceof L3ModificationInstruction &&
937 ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) {
938 // FIXME Should modify the app to send the correct DEC_MPLS_TTL instruction
939 tb.immediate().decMplsTtl();
940 }
941 if (instr instanceof L3ModificationInstruction &&
942 ((L3ModificationInstruction) instr).subtype() == L3SubType.TTL_IN) {
943 tb.immediate().add(instr);
944 }
Saurav Das8a0732e2015-11-20 15:27:53 -0800945 }
946 }
947 }
Saurav Das822c4e22015-10-23 10:51:11 -0700948
949 if (fwd.nextId() != null) {
Saurav Das8a0732e2015-11-20 15:27:53 -0800950 if (forTableId == MPLS_TABLE_1 && !popMpls) {
951 log.warn("SR CONTINUE case cannot be handled as MPLS ECMP "
Saurav Das25190812016-05-27 13:54:07 -0700952 + "is not implemented in OF-DPA yet. Aborting this flow {} -> next:{}"
953 + "in this device {}", fwd.id(), fwd.nextId(), deviceId);
Saurav Das8a0732e2015-11-20 15:27:53 -0800954 // XXX We could convert to forwarding to a single-port, via a
955 // MPLS interface, or a MPLS SWAP (with-same) but that would
956 // have to be handled in the next-objective. Also the pop-mpls
957 // logic used here won't work in non-BoS case.
Saurav Das4ce45962015-11-24 23:21:05 -0800958 fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
Saurav Das8a0732e2015-11-20 15:27:53 -0800959 return Collections.emptySet();
960 }
961
Saurav Das423fe2b2015-12-04 10:52:59 -0800962 NextGroup next = getGroupForNextObjective(fwd.nextId());
963 if (next != null) {
964 List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
965 // we only need the top level group's key to point the flow to it
966 Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
967 if (group == null) {
968 log.warn("Group with key:{} for next-id:{} not found in dev:{}",
969 gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
970 fail(fwd, ObjectiveError.GROUPMISSING);
971 return Collections.emptySet();
972 }
973 tb.deferred().group(group.id());
Saurav Das1ce0a7b2016-10-21 14:06:29 -0700974 // check if group is empty
975 if (gkeys.size() == 1 && gkeys.get(0).size() == 1) {
976 log.warn("Found empty group 0x{} in dev:{} .. will retry fwd:{}",
977 Integer.toHexString(group.id().id()), deviceId, fwd.id());
978 emptyGroup = true;
979 }
Saurav Das25190812016-05-27 13:54:07 -0700980 } else {
981 log.warn("Cannot find group for nextId:{} in dev:{}. Aborting fwd:{}",
982 fwd.nextId(), deviceId, fwd.id());
983 fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
984 return Collections.emptySet();
Saurav Das822c4e22015-10-23 10:51:11 -0700985 }
Saurav Das822c4e22015-10-23 10:51:11 -0700986 }
Charles Chancad338a2016-09-16 18:03:11 -0700987
988 if (forTableId == MPLS_TABLE_1) {
989 if (mplsNextTable == MPLS_L3_TYPE) {
990 Ofdpa3SetMplsType setMplsType = new Ofdpa3SetMplsType(Ofdpa3MplsType.L3_PHP);
Saurav Das9c705342017-01-06 11:36:01 -0800991 // set mpls type as apply_action
992 tb.immediate().extension(setMplsType, deviceId);
Charles Chancad338a2016-09-16 18:03:11 -0700993 }
994 tb.transition(mplsNextTable);
995 } else {
996 tb.transition(ACL_TABLE);
997 }
998
Saurav Das822c4e22015-10-23 10:51:11 -0700999 FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
1000 .fromApp(fwd.appId())
1001 .withPriority(fwd.priority())
1002 .forDevice(deviceId)
Saurav Das8a0732e2015-11-20 15:27:53 -08001003 .withSelector(filteredSelector.build())
1004 .withTreatment(tb.build())
1005 .forTable(forTableId);
Saurav Das822c4e22015-10-23 10:51:11 -07001006
1007 if (fwd.permanent()) {
1008 ruleBuilder.makePermanent();
1009 } else {
1010 ruleBuilder.makeTemporary(fwd.timeout());
1011 }
Flavio Castroe10fa242016-01-15 12:43:51 -08001012 Collection<FlowRule> flowRuleCollection = new ArrayList<>();
1013 flowRuleCollection.add(ruleBuilder.build());
1014 if (defaultRule) {
1015 FlowRule.Builder rule = DefaultFlowRule.builder()
1016 .fromApp(fwd.appId())
1017 .withPriority(fwd.priority())
1018 .forDevice(deviceId)
1019 .withSelector(complementarySelector.build())
1020 .withTreatment(tb.build())
1021 .forTable(forTableId);
1022 if (fwd.permanent()) {
1023 rule.makePermanent();
1024 } else {
1025 rule.makeTemporary(fwd.timeout());
1026 }
1027 flowRuleCollection.add(rule.build());
1028 log.debug("Default rule 0.0.0.0/0 is being installed two rules");
1029 }
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001030 // XXX retrying flows may be necessary due to bug CORD-554
1031 if (emptyGroup) {
1032 executorService.schedule(new RetryFlows(fwd, flowRuleCollection),
1033 RETRY_MS, TimeUnit.MILLISECONDS);
1034 }
Flavio Castroe10fa242016-01-15 12:43:51 -08001035 return flowRuleCollection;
Saurav Das822c4e22015-10-23 10:51:11 -07001036 }
1037
Saurav Das4ce45962015-11-24 23:21:05 -08001038 /**
1039 * Handles forwarding rules to the L2 bridging table. Flow actions are not
1040 * allowed in the bridging table - instead we use L2 Interface group or
1041 * L2 flood group
1042 *
1043 * @param fwd the forwarding objective
1044 * @return A collection of flow rules, or an empty set
1045 */
1046 protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) {
1047 List<FlowRule> rules = new ArrayList<>();
1048
1049 // Build filtered selector
1050 TrafficSelector selector = fwd.selector();
1051 EthCriterion ethCriterion = (EthCriterion) selector
1052 .getCriterion(Criterion.Type.ETH_DST);
1053 VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector
1054 .getCriterion(Criterion.Type.VLAN_VID);
1055
1056 if (vlanIdCriterion == null) {
1057 log.warn("Forwarding objective for bridging requires vlan. Not "
1058 + "installing fwd:{} in dev:{}", fwd.id(), deviceId);
1059 fail(fwd, ObjectiveError.BADPARAMS);
1060 return Collections.emptySet();
1061 }
1062
1063 TrafficSelector.Builder filteredSelectorBuilder =
1064 DefaultTrafficSelector.builder();
1065 // Do not match MacAddress for subnet broadcast entry
1066 if (!ethCriterion.mac().equals(MacAddress.NONE)) {
1067 filteredSelectorBuilder.matchEthDst(ethCriterion.mac());
1068 log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}",
1069 fwd.id(), fwd.nextId(), deviceId);
1070 } else {
1071 log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} "
1072 + "in dev:{} for vlan:{}",
1073 fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId());
1074 }
Charles Chan14967c22015-12-07 11:11:50 -08001075 OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vlanIdCriterion.vlanId());
1076 filteredSelectorBuilder.extension(ofdpaMatchVlanVid, deviceId);
Saurav Das4ce45962015-11-24 23:21:05 -08001077 TrafficSelector filteredSelector = filteredSelectorBuilder.build();
1078
1079 if (fwd.treatment() != null) {
1080 log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table"
1081 + "for dev:{}. Expecting only nextId", fwd.id(), deviceId);
1082 }
1083
1084 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
1085 if (fwd.nextId() != null) {
Saurav Das423fe2b2015-12-04 10:52:59 -08001086 NextGroup next = getGroupForNextObjective(fwd.nextId());
Saurav Das4ce45962015-11-24 23:21:05 -08001087 if (next != null) {
1088 List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
1089 // we only need the top level group's key to point the flow to it
1090 Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
1091 if (group != null) {
1092 treatmentBuilder.deferred().group(group.id());
1093 } else {
1094 log.warn("Group with key:{} for next-id:{} not found in dev:{}",
1095 gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
1096 fail(fwd, ObjectiveError.GROUPMISSING);
1097 return Collections.emptySet();
1098 }
1099 }
1100 }
1101 treatmentBuilder.immediate().transition(ACL_TABLE);
1102 TrafficTreatment filteredTreatment = treatmentBuilder.build();
1103
1104 // Build bridging table entries
1105 FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
1106 flowRuleBuilder.fromApp(fwd.appId())
1107 .withPriority(fwd.priority())
1108 .forDevice(deviceId)
1109 .withSelector(filteredSelector)
1110 .withTreatment(filteredTreatment)
1111 .forTable(BRIDGING_TABLE);
1112 if (fwd.permanent()) {
1113 flowRuleBuilder.makePermanent();
1114 } else {
1115 flowRuleBuilder.makeTemporary(fwd.timeout());
1116 }
1117 rules.add(flowRuleBuilder.build());
1118 return rules;
1119 }
1120
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001121 //////////////////////////////////////
1122 // Helper Methods and Classes
1123 //////////////////////////////////////
1124
1125 private boolean isSupportedEthTypeObjective(ForwardingObjective fwd) {
1126 TrafficSelector selector = fwd.selector();
1127 EthTypeCriterion ethType = (EthTypeCriterion) selector
1128 .getCriterion(Criterion.Type.ETH_TYPE);
1129 return !((ethType == null) ||
1130 ((ethType.ethType().toShort() != Ethernet.TYPE_IPV4) &&
1131 (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)));
1132 }
1133
1134 private boolean isSupportedEthDstObjective(ForwardingObjective fwd) {
1135 TrafficSelector selector = fwd.selector();
1136 EthCriterion ethDst = (EthCriterion) selector
1137 .getCriterion(Criterion.Type.ETH_DST);
1138 VlanIdCriterion vlanId = (VlanIdCriterion) selector
1139 .getCriterion(Criterion.Type.VLAN_VID);
1140 return !(ethDst == null && vlanId == null);
1141 }
1142
Saurav Das423fe2b2015-12-04 10:52:59 -08001143 protected NextGroup getGroupForNextObjective(Integer nextId) {
1144 NextGroup next = flowObjectiveStore.getNextGroup(nextId);
1145 if (next != null) {
1146 List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
1147 if (gkeys != null && !gkeys.isEmpty()) {
1148 return next;
1149 } else {
1150 log.warn("Empty next group found in FlowObjective store for "
1151 + "next-id:{} in dev:{}", nextId, deviceId);
1152 }
1153 } else {
1154 log.warn("next-id {} not found in Flow objective store for dev:{}",
1155 nextId, deviceId);
1156 }
1157 return null;
1158 }
1159
Charles Chan188ebf52015-12-23 00:15:11 -08001160 protected static void pass(Objective obj) {
Sho SHIMIZUef7e2902016-02-12 18:38:29 -08001161 obj.context().ifPresent(context -> context.onSuccess(obj));
Saurav Das822c4e22015-10-23 10:51:11 -07001162 }
1163
Charles Chan188ebf52015-12-23 00:15:11 -08001164 protected static void fail(Objective obj, ObjectiveError error) {
Sho SHIMIZUef7e2902016-02-12 18:38:29 -08001165 obj.context().ifPresent(context -> context.onError(obj, error));
Saurav Das822c4e22015-10-23 10:51:11 -07001166 }
Saurav Das24431192016-03-07 19:13:00 -08001167
Saurav Das24431192016-03-07 19:13:00 -08001168 @Override
1169 public List<String> getNextMappings(NextGroup nextGroup) {
1170 List<String> mappings = new ArrayList<>();
1171 List<Deque<GroupKey>> gkeys = appKryo.deserialize(nextGroup.data());
1172 for (Deque<GroupKey> gkd : gkeys) {
1173 Group lastGroup = null;
Saurav Das8be4e3a2016-03-11 17:19:07 -08001174 StringBuffer gchain = new StringBuffer();
Saurav Das24431192016-03-07 19:13:00 -08001175 for (GroupKey gk : gkd) {
1176 Group g = groupService.getGroup(deviceId, gk);
Saurav Das8be4e3a2016-03-11 17:19:07 -08001177 if (g == null) {
Saurav Das25190812016-05-27 13:54:07 -07001178 gchain.append(" NoGrp").append(" -->");
Saurav Das8be4e3a2016-03-11 17:19:07 -08001179 continue;
1180 }
1181 gchain.append(" 0x").append(Integer.toHexString(g.id().id()))
1182 .append(" -->");
Saurav Das24431192016-03-07 19:13:00 -08001183 lastGroup = g;
1184 }
1185 // add port information for last group in group-chain
Saurav Das25190812016-05-27 13:54:07 -07001186 List<Instruction> lastGroupIns = new ArrayList<Instruction>();
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001187 if (lastGroup != null && !lastGroup.buckets().buckets().isEmpty()) {
Saurav Das25190812016-05-27 13:54:07 -07001188 lastGroupIns = lastGroup.buckets().buckets().get(0)
1189 .treatment().allInstructions();
1190 }
1191 for (Instruction i: lastGroupIns) {
Saurav Das24431192016-03-07 19:13:00 -08001192 if (i instanceof OutputInstruction) {
Saurav Das8be4e3a2016-03-11 17:19:07 -08001193 gchain.append(" port:").append(((OutputInstruction) i).port());
Saurav Das24431192016-03-07 19:13:00 -08001194 }
1195 }
Saurav Das8be4e3a2016-03-11 17:19:07 -08001196 mappings.add(gchain.toString());
Saurav Das24431192016-03-07 19:13:00 -08001197 }
1198 return mappings;
1199 }
Charles Chan5b9df8d2016-03-28 22:21:40 -07001200
1201 protected static VlanId readVlanFromSelector(TrafficSelector selector) {
Saurav Das59232cf2016-04-27 18:35:50 -07001202 if (selector == null) {
1203 return null;
1204 }
Charles Chan5b9df8d2016-03-28 22:21:40 -07001205 Criterion criterion = selector.getCriterion(Criterion.Type.VLAN_VID);
1206 return (criterion == null)
1207 ? null : ((VlanIdCriterion) criterion).vlanId();
1208 }
1209
1210 protected static IpPrefix readIpDstFromSelector(TrafficSelector selector) {
Saurav Das59232cf2016-04-27 18:35:50 -07001211 if (selector == null) {
1212 return null;
1213 }
Charles Chan5b9df8d2016-03-28 22:21:40 -07001214 Criterion criterion = selector.getCriterion(Criterion.Type.IPV4_DST);
1215 return (criterion == null) ? null : ((IPCriterion) criterion).ip();
1216 }
Charles Chand55e84d2016-03-30 17:54:24 -07001217
1218 private static VlanId readVlanFromTreatment(TrafficTreatment treatment) {
Saurav Das59232cf2016-04-27 18:35:50 -07001219 if (treatment == null) {
1220 return null;
1221 }
Charles Chand55e84d2016-03-30 17:54:24 -07001222 for (Instruction i : treatment.allInstructions()) {
1223 if (i instanceof ModVlanIdInstruction) {
1224 return ((ModVlanIdInstruction) i).vlanId();
1225 }
1226 }
1227 return null;
1228 }
Saurav Das1ce0a7b2016-10-21 14:06:29 -07001229
1230 /**
1231 * Utility class that retries sending flows a fixed number of times, even if
1232 * some of the attempts are successful. Used only for forwarding objectives.
1233 */
1234 protected final class RetryFlows implements Runnable {
1235 int attempts = MAX_RETRY_ATTEMPTS;
1236 private Collection<FlowRule> retryFlows;
1237 private ForwardingObjective fwd;
1238
1239 RetryFlows(ForwardingObjective fwd, Collection<FlowRule> retryFlows) {
1240 this.fwd = fwd;
1241 this.retryFlows = retryFlows;
1242 }
1243
1244 @Override
1245 public void run() {
1246 log.info("RETRY FLOWS ATTEMPT# {} for fwd:{} rules:{}",
1247 MAX_RETRY_ATTEMPTS - attempts, fwd.id(), retryFlows.size());
1248 sendForward(fwd, retryFlows);
1249 if (--attempts > 0) {
1250 executorService.schedule(this, RETRY_MS, TimeUnit.MILLISECONDS);
1251 }
1252 }
1253 }
1254
Saurav Das822c4e22015-10-23 10:51:11 -07001255}