blob: ef79ee3ae14e04b2289948b8d630fa4ef988aff0 [file] [log] [blame]
Saurav Dase3274c82015-05-24 17:21:56 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Saurav Dase3274c82015-05-24 17:21:56 -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 Dase3274c82015-05-24 17:21:56 -070018import org.onlab.osgi.ServiceDirectory;
19import org.onlab.packet.Ethernet;
Saurav Das337c7a42015-06-02 15:12:06 -070020import org.onlab.packet.MacAddress;
21import org.onlab.packet.VlanId;
Saurav Dase3274c82015-05-24 17:21:56 -070022import org.onlab.util.KryoNamespace;
23import org.onosproject.core.ApplicationId;
24import org.onosproject.core.CoreService;
25import org.onosproject.net.DeviceId;
Saurav Das337c7a42015-06-02 15:12:06 -070026import org.onosproject.net.PortNumber;
Saurav Dase3274c82015-05-24 17:21:56 -070027import org.onosproject.net.behaviour.NextGroup;
28import org.onosproject.net.behaviour.Pipeliner;
29import org.onosproject.net.behaviour.PipelinerContext;
30import org.onosproject.net.driver.AbstractHandlerBehaviour;
31import org.onosproject.net.flow.DefaultFlowRule;
32import org.onosproject.net.flow.DefaultTrafficSelector;
33import org.onosproject.net.flow.DefaultTrafficTreatment;
34import org.onosproject.net.flow.FlowRule;
35import org.onosproject.net.flow.FlowRuleOperations;
36import org.onosproject.net.flow.FlowRuleOperationsContext;
37import org.onosproject.net.flow.FlowRuleService;
38import org.onosproject.net.flow.TrafficSelector;
39import org.onosproject.net.flow.TrafficTreatment;
40import org.onosproject.net.flow.criteria.Criteria;
41import org.onosproject.net.flow.criteria.Criterion;
42import org.onosproject.net.flow.criteria.EthCriterion;
43import org.onosproject.net.flow.criteria.EthTypeCriterion;
44import org.onosproject.net.flow.criteria.IPCriterion;
Saurav Dase3274c82015-05-24 17:21:56 -070045import org.onosproject.net.flow.criteria.PortCriterion;
46import org.onosproject.net.flow.criteria.VlanIdCriterion;
Saurav Das337c7a42015-06-02 15:12:06 -070047import org.onosproject.net.flow.instructions.Instruction;
48import org.onosproject.net.flow.instructions.L2ModificationInstruction;
Saurav Dase3274c82015-05-24 17:21:56 -070049import org.onosproject.net.flowobjective.FilteringObjective;
50import org.onosproject.net.flowobjective.FlowObjectiveStore;
51import org.onosproject.net.flowobjective.ForwardingObjective;
52import org.onosproject.net.flowobjective.NextObjective;
53import org.onosproject.net.flowobjective.Objective;
54import org.onosproject.net.flowobjective.ObjectiveError;
Saurav Das337c7a42015-06-02 15:12:06 -070055import org.onosproject.store.serializers.KryoNamespaces;
Saurav Dase3274c82015-05-24 17:21:56 -070056import org.slf4j.Logger;
57
Saurav Das337c7a42015-06-02 15:12:06 -070058import java.util.ArrayList;
Saurav Dase3274c82015-05-24 17:21:56 -070059import java.util.Collection;
60import java.util.Collections;
Saurav Das337c7a42015-06-02 15:12:06 -070061import java.util.List;
Sho SHIMIZU45906042016-01-13 23:05:54 -080062import java.util.Objects;
Saurav Das337c7a42015-06-02 15:12:06 -070063import java.util.concurrent.ConcurrentHashMap;
Saurav Dase3274c82015-05-24 17:21:56 -070064
Saurav Dase3274c82015-05-24 17:21:56 -070065import static org.slf4j.LoggerFactory.getLogger;
66
67/**
68 * Pica pipeline handler.
69 */
70public class PicaPipeline extends AbstractHandlerBehaviour implements Pipeliner {
71
Saurav Das337c7a42015-06-02 15:12:06 -070072 protected static final int IP_UNICAST_TABLE = 252;
73 protected static final int ACL_TABLE = 0;
Saurav Dase3274c82015-05-24 17:21:56 -070074
Saurav Das337c7a42015-06-02 15:12:06 -070075 //private static final int CONTROLLER_PRIORITY = 255;
Saurav Dase3274c82015-05-24 17:21:56 -070076 private static final int DROP_PRIORITY = 0;
77 private static final int HIGHEST_PRIORITY = 0xffff;
78
79 private final Logger log = getLogger(getClass());
80
81 private ServiceDirectory serviceDirectory;
82 private FlowRuleService flowRuleService;
83 private CoreService coreService;
Saurav Dase3274c82015-05-24 17:21:56 -070084 private FlowObjectiveStore flowObjectiveStore;
85 private DeviceId deviceId;
86 private ApplicationId appId;
Saurav Das337c7a42015-06-02 15:12:06 -070087 private Collection<Filter> filters;
88 private Collection<ForwardingObjective> pendingVersatiles;
Saurav Dase3274c82015-05-24 17:21:56 -070089
90 private KryoNamespace appKryo = new KryoNamespace.Builder()
Saurav Das337c7a42015-06-02 15:12:06 -070091 .register(KryoNamespaces.API)
Saurav Dase3274c82015-05-24 17:21:56 -070092 .register(PicaGroup.class)
Charles Chaneefdedf2016-05-23 16:45:45 -070093 .build("PicaPipeline");
Saurav Dase3274c82015-05-24 17:21:56 -070094
Saurav Dase3274c82015-05-24 17:21:56 -070095 @Override
96 public void init(DeviceId deviceId, PipelinerContext context) {
97 this.serviceDirectory = context.directory();
98 this.deviceId = deviceId;
99
Saurav Dase3274c82015-05-24 17:21:56 -0700100 coreService = serviceDirectory.get(CoreService.class);
101 flowRuleService = serviceDirectory.get(FlowRuleService.class);
Saurav Dase3274c82015-05-24 17:21:56 -0700102 flowObjectiveStore = context.store();
Saurav Das337c7a42015-06-02 15:12:06 -0700103 filters = Collections.newSetFromMap(new ConcurrentHashMap<Filter, Boolean>());
104 pendingVersatiles = Collections.newSetFromMap(
105 new ConcurrentHashMap<ForwardingObjective, Boolean>());
Saurav Dase3274c82015-05-24 17:21:56 -0700106 appId = coreService.registerApplication(
107 "org.onosproject.driver.OVSPicaPipeline");
108
109 initializePipeline();
110 }
111
112 @Override
113 public void filter(FilteringObjective filteringObjective) {
114 if (filteringObjective.type() == FilteringObjective.Type.PERMIT) {
115 processFilter(filteringObjective,
116 filteringObjective.op() == Objective.Operation.ADD,
117 filteringObjective.appId());
118 } else {
119 fail(filteringObjective, ObjectiveError.UNSUPPORTED);
120 }
121 }
122
123 @Override
124 public void forward(ForwardingObjective fwd) {
125 Collection<FlowRule> rules;
126 FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder();
127
128 rules = processForward(fwd);
129 switch (fwd.op()) {
130 case ADD:
131 rules.stream()
Sho SHIMIZU45906042016-01-13 23:05:54 -0800132 .filter(Objects::nonNull)
Saurav Dase3274c82015-05-24 17:21:56 -0700133 .forEach(flowBuilder::add);
134 break;
135 case REMOVE:
136 rules.stream()
Sho SHIMIZU45906042016-01-13 23:05:54 -0800137 .filter(Objects::nonNull)
Saurav Dase3274c82015-05-24 17:21:56 -0700138 .forEach(flowBuilder::remove);
139 break;
140 default:
141 fail(fwd, ObjectiveError.UNKNOWN);
142 log.warn("Unknown forwarding type {}", fwd.op());
143 }
144
145
146 flowRuleService.apply(flowBuilder.build(new FlowRuleOperationsContext() {
147 @Override
148 public void onSuccess(FlowRuleOperations ops) {
149 pass(fwd);
150 }
151
152 @Override
153 public void onError(FlowRuleOperations ops) {
154 fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
155 }
156 }));
157
158 }
159
160 @Override
161 public void next(NextObjective nextObjective) {
162 switch (nextObjective.type()) {
163 case SIMPLE:
164 Collection<TrafficTreatment> treatments = nextObjective.next();
Saurav Das337c7a42015-06-02 15:12:06 -0700165 if (treatments.size() != 1) {
166 log.error("Next Objectives of type Simple should only have a "
167 + "single Traffic Treatment. Next Objective Id:{}", nextObjective.id());
168 fail(nextObjective, ObjectiveError.BADPARAMS);
169 return;
Saurav Dase3274c82015-05-24 17:21:56 -0700170 }
Saurav Das337c7a42015-06-02 15:12:06 -0700171 TrafficTreatment treatment = treatments.iterator().next();
172 TrafficTreatment.Builder filteredTreatment = DefaultTrafficTreatment.builder();
173 VlanId modVlanId;
174 for (Instruction ins : treatment.allInstructions()) {
175 if (ins.type() == Instruction.Type.L2MODIFICATION) {
176 L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
177 switch (l2ins.subtype()) {
178 case ETH_DST:
179 filteredTreatment.setEthDst(
180 ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
181 break;
182 case ETH_SRC:
183 filteredTreatment.setEthSrc(
184 ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
185 break;
186 case VLAN_ID:
187 modVlanId = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
188 filteredTreatment.setVlanId(modVlanId);
189 break;
190 default:
191 break;
192 }
193 } else if (ins.type() == Instruction.Type.OUTPUT) {
194 //long portNum = ((Instructions.OutputInstruction) ins).port().toLong();
195 filteredTreatment.add(ins);
196 } else {
197 // Ignore the vlan_pcp action since it's does matter much.
198 log.warn("Driver does not handle this type of TrafficTreatment"
199 + " instruction in nextObjectives: {}", ins.type());
200 }
201 }
202 // store for future use
203 flowObjectiveStore.putNextGroup(nextObjective.id(),
204 new PicaGroup(filteredTreatment.build()));
Saurav Dase3274c82015-05-24 17:21:56 -0700205 break;
206 case HASHED:
207 case BROADCAST:
208 case FAILOVER:
209 fail(nextObjective, ObjectiveError.UNSUPPORTED);
210 log.warn("Unsupported next objective type {}", nextObjective.type());
211 break;
212 default:
213 fail(nextObjective, ObjectiveError.UNKNOWN);
214 log.warn("Unknown next objective type {}", nextObjective.type());
215 }
216
217 }
218
219 private Collection<FlowRule> processForward(ForwardingObjective fwd) {
220 switch (fwd.flag()) {
221 case SPECIFIC:
222 return processSpecific(fwd);
223 case VERSATILE:
224 return processVersatile(fwd);
225 default:
226 fail(fwd, ObjectiveError.UNKNOWN);
227 log.warn("Unknown forwarding flag {}", fwd.flag());
228 }
229 return Collections.emptySet();
230 }
231
232 private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
233 log.debug("Processing versatile forwarding objective");
234 TrafficSelector selector = fwd.selector();
Saurav Das598a02f2015-08-31 18:19:30 -0700235 TrafficTreatment treatment = fwd.treatment();
236 Collection<FlowRule> flowrules = new ArrayList<FlowRule>();
237
238 // first add this rule for basic single-table operation
239 // or non-ARP related multi-table operation
240 FlowRule rule = DefaultFlowRule.builder()
241 .forDevice(deviceId)
242 .withSelector(selector)
243 .withTreatment(treatment)
244 .withPriority(fwd.priority())
245 .fromApp(fwd.appId())
246 .makePermanent()
247 .forTable(ACL_TABLE).build();
248 flowrules.add(rule);
Saurav Dase3274c82015-05-24 17:21:56 -0700249
250 EthTypeCriterion ethType =
251 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
252 if (ethType == null) {
Saurav Das598a02f2015-08-31 18:19:30 -0700253 log.warn("No ethType in versatile forwarding obj. Not processing further.");
254 return flowrules;
Saurav Dase3274c82015-05-24 17:21:56 -0700255 }
Saurav Das337c7a42015-06-02 15:12:06 -0700256
Saurav Das598a02f2015-08-31 18:19:30 -0700257 // now deal with possible mix of ARP with filtering objectives
258 // in multi-table scenarios
alshabibcaf1ca22015-06-25 15:18:16 -0700259 if (ethType.ethType().toShort() == Ethernet.TYPE_ARP) {
Saurav Das337c7a42015-06-02 15:12:06 -0700260 if (filters.isEmpty()) {
261 pendingVersatiles.add(fwd);
Saurav Das598a02f2015-08-31 18:19:30 -0700262 return flowrules;
Saurav Das337c7a42015-06-02 15:12:06 -0700263 }
Saurav Das337c7a42015-06-02 15:12:06 -0700264 for (Filter filter : filters) {
265 flowrules.addAll(processVersatilesWithFilters(filter, fwd));
266 }
Saurav Dase3274c82015-05-24 17:21:56 -0700267 }
Saurav Das598a02f2015-08-31 18:19:30 -0700268 return flowrules;
Saurav Dase3274c82015-05-24 17:21:56 -0700269 }
270
Saurav Das337c7a42015-06-02 15:12:06 -0700271 private Collection<FlowRule> processVersatilesWithFilters(
272 Filter filt, ForwardingObjective fwd) {
273 Collection<FlowRule> flows = new ArrayList<FlowRule>();
274
275 // rule for ARP replies
276 log.debug("adding ARP rule in ACL table");
277 TrafficSelector.Builder sel = DefaultTrafficSelector.builder();
278 TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
279 sel.matchInPort(filt.port());
280 sel.matchVlanId(filt.vlanId());
281 sel.matchEthDst(filt.mac());
282 sel.matchEthType(Ethernet.TYPE_ARP);
283 treat.setOutput(PortNumber.CONTROLLER);
284 FlowRule rule = DefaultFlowRule.builder()
285 .forDevice(deviceId)
286 .withSelector(sel.build())
287 .withTreatment(treat.build())
288 .withPriority(HIGHEST_PRIORITY)
289 .fromApp(appId)
290 .makePermanent()
291 .forTable(ACL_TABLE).build();
292 flows.add(rule);
293
294 // rule for ARP Broadcast
295 sel = DefaultTrafficSelector.builder();
296 treat = DefaultTrafficTreatment.builder();
297 sel.matchInPort(filt.port());
298 sel.matchVlanId(filt.vlanId());
299 sel.matchEthDst(MacAddress.BROADCAST);
300 sel.matchEthType(Ethernet.TYPE_ARP);
301 treat.setOutput(PortNumber.CONTROLLER);
302 rule = DefaultFlowRule.builder()
303 .forDevice(deviceId)
304 .withSelector(sel.build())
305 .withTreatment(treat.build())
306 .withPriority(HIGHEST_PRIORITY)
307 .fromApp(appId)
308 .makePermanent()
309 .forTable(ACL_TABLE).build();
310 flows.add(rule);
311
312 return flows;
313 }
314
315
Saurav Dase3274c82015-05-24 17:21:56 -0700316 private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
317 log.debug("Processing specific forwarding objective");
318 TrafficSelector selector = fwd.selector();
319 EthTypeCriterion ethType =
320 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
alshabibcaf1ca22015-06-25 15:18:16 -0700321 if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
Saurav Dase3274c82015-05-24 17:21:56 -0700322 fail(fwd, ObjectiveError.UNSUPPORTED);
323 return Collections.emptySet();
324 }
325
Saurav Das337c7a42015-06-02 15:12:06 -0700326 List<FlowRule> ipflows = new ArrayList<FlowRule>();
327 for (Filter f: filters) {
328 TrafficSelector filteredSelector =
329 DefaultTrafficSelector.builder()
330 .matchEthType(Ethernet.TYPE_IPV4)
331 .matchIPDst(
Saurav Dase3274c82015-05-24 17:21:56 -0700332 ((IPCriterion)
333 selector.getCriterion(Criterion.Type.IPV4_DST)).ip())
Saurav Das337c7a42015-06-02 15:12:06 -0700334 .matchEthDst(f.mac())
335 .matchVlanId(f.vlanId())
336 .build();
337 TrafficTreatment tt = null;
338 if (fwd.nextId() != null) {
339 NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
340 if (next == null) {
341 log.error("next-id {} does not exist in store", fwd.nextId());
342 return Collections.emptySet();
343 }
344 tt = appKryo.deserialize(next.data());
345 if (tt == null) {
346 log.error("Error in deserializing next-id {}", fwd.nextId());
347 return Collections.emptySet();
348 }
Saurav Dase3274c82015-05-24 17:21:56 -0700349 }
Saurav Das337c7a42015-06-02 15:12:06 -0700350
351 FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
352 .fromApp(fwd.appId())
353 .withPriority(fwd.priority())
354 .forDevice(deviceId)
355 .withSelector(filteredSelector)
356 .withTreatment(tt);
357 if (fwd.permanent()) {
358 ruleBuilder.makePermanent();
359 } else {
360 ruleBuilder.makeTemporary(fwd.timeout());
361 }
362 ruleBuilder.forTable(IP_UNICAST_TABLE);
363 ipflows.add(ruleBuilder.build());
Saurav Dase3274c82015-05-24 17:21:56 -0700364 }
365
Saurav Das337c7a42015-06-02 15:12:06 -0700366 return ipflows;
Saurav Dase3274c82015-05-24 17:21:56 -0700367 }
368
369 private void processFilter(FilteringObjective filt, boolean install,
370 ApplicationId applicationId) {
371 // This driver only processes filtering criteria defined with switch
372 // ports as the key
373 PortCriterion p;
374 if (!filt.key().equals(Criteria.dummy()) &&
375 filt.key().type() == Criterion.Type.IN_PORT) {
376 p = (PortCriterion) filt.key();
377 } else {
378 log.warn("No key defined in filtering objective from app: {}. Not"
379 + "processing filtering objective", applicationId);
380 fail(filt, ObjectiveError.UNKNOWN);
381 return;
382 }
Saurav Das337c7a42015-06-02 15:12:06 -0700383
Ray Milkeyfd4f8d32018-01-17 15:24:52 -0800384 EthCriterion e = null;
385 VlanIdCriterion v = null;
Saurav Das337c7a42015-06-02 15:12:06 -0700386 Collection<IPCriterion> ips = new ArrayList<IPCriterion>();
Saurav Dase3274c82015-05-24 17:21:56 -0700387 // convert filtering conditions for switch-intfs into flowrules
388 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
389 for (Criterion c : filt.conditions()) {
390 if (c.type() == Criterion.Type.ETH_DST) {
Saurav Das337c7a42015-06-02 15:12:06 -0700391 e = (EthCriterion) c;
Saurav Dase3274c82015-05-24 17:21:56 -0700392 } else if (c.type() == Criterion.Type.VLAN_VID) {
Saurav Das337c7a42015-06-02 15:12:06 -0700393 v = (VlanIdCriterion) c;
Saurav Dase3274c82015-05-24 17:21:56 -0700394 } else if (c.type() == Criterion.Type.IPV4_DST) {
Saurav Das337c7a42015-06-02 15:12:06 -0700395 ips.add((IPCriterion) c);
Saurav Dase3274c82015-05-24 17:21:56 -0700396 } else {
Saurav Das337c7a42015-06-02 15:12:06 -0700397 log.error("Unsupported filter {}", c);
Saurav Dase3274c82015-05-24 17:21:56 -0700398 fail(filt, ObjectiveError.UNSUPPORTED);
Saurav Das337c7a42015-06-02 15:12:06 -0700399 return;
Saurav Dase3274c82015-05-24 17:21:56 -0700400 }
401 }
Saurav Das337c7a42015-06-02 15:12:06 -0700402
Ray Milkeyfd4f8d32018-01-17 15:24:52 -0800403 if (v == null || e == null) {
404 log.warn("Pica Pipeline ETH_DST and/or VLAN_ID not specified");
405 fail(filt, ObjectiveError.BADPARAMS);
406 return;
407 }
408
Saurav Das337c7a42015-06-02 15:12:06 -0700409 // cache for later use
410 Filter filter = new Filter(p, e, v, ips);
411 filters.add(filter);
412
413 // apply any pending versatile forwarding objectives
414 for (ForwardingObjective fwd : pendingVersatiles) {
415 Collection<FlowRule> ret = processVersatilesWithFilters(filter, fwd);
416 for (FlowRule fr : ret) {
417 ops.add(fr);
418 }
419 }
420
421 for (IPCriterion ipaddr : ips) {
422 log.debug("adding IP filtering rules in ACL table: {}", ipaddr.ip());
423 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
424 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
425 selector.matchInPort(p.port());
426 selector.matchVlanId(v.vlanId());
427 selector.matchEthDst(e.mac());
428 selector.matchEthType(Ethernet.TYPE_IPV4);
429 selector.matchIPDst(ipaddr.ip()); // router IPs to the controller
430 treatment.setOutput(PortNumber.CONTROLLER);
431 FlowRule rule = DefaultFlowRule.builder()
432 .forDevice(deviceId)
433 .withSelector(selector.build())
434 .withTreatment(treatment.build())
435 .withPriority(HIGHEST_PRIORITY)
436 .fromApp(applicationId)
437 .makePermanent()
438 .forTable(ACL_TABLE).build();
439 ops = ops.add(rule);
440 }
441
Saurav Dase3274c82015-05-24 17:21:56 -0700442 // apply filtering flow rules
443 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
444 @Override
445 public void onSuccess(FlowRuleOperations ops) {
446 pass(filt);
447 log.info("Applied filtering rules");
448 }
449
450 @Override
451 public void onError(FlowRuleOperations ops) {
452 fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED);
453 log.info("Failed to apply filtering rules");
454 }
455 }));
456 }
457
458 private void pass(Objective obj) {
Sho SHIMIZUef7e2902016-02-12 18:38:29 -0800459 obj.context().ifPresent(context -> context.onSuccess(obj));
Saurav Dase3274c82015-05-24 17:21:56 -0700460 }
461
462 private void fail(Objective obj, ObjectiveError error) {
Sho SHIMIZUef7e2902016-02-12 18:38:29 -0800463 obj.context().ifPresent(context -> context.onError(obj, error));
Saurav Dase3274c82015-05-24 17:21:56 -0700464 }
465
466 private void initializePipeline() {
Saurav Das337c7a42015-06-02 15:12:06 -0700467 //processIpUnicastTable(true);
Jonathan Hartb35540a2015-11-17 09:30:56 -0800468 processAclTable(true);
Saurav Dase3274c82015-05-24 17:21:56 -0700469 }
470
Jonathan Hartb35540a2015-11-17 09:30:56 -0800471 private void processAclTable(boolean install) {
Saurav Dase3274c82015-05-24 17:21:56 -0700472 TrafficSelector.Builder selector;
473 TrafficTreatment.Builder treatment;
474 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
475 FlowRule rule;
476
477 //Drop rule
478 selector = DefaultTrafficSelector.builder();
479 treatment = DefaultTrafficTreatment.builder();
480
Saurav Dase3274c82015-05-24 17:21:56 -0700481 rule = DefaultFlowRule.builder()
482 .forDevice(deviceId)
483 .withSelector(selector.build())
484 .withTreatment(treatment.build())
485 .withPriority(DROP_PRIORITY)
486 .fromApp(appId)
487 .makePermanent()
Saurav Das337c7a42015-06-02 15:12:06 -0700488 .forTable(ACL_TABLE).build();
Saurav Dase3274c82015-05-24 17:21:56 -0700489
490 ops = install ? ops.add(rule) : ops.remove(rule);
491
492 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
493 @Override
494 public void onSuccess(FlowRuleOperations ops) {
Saurav Das337c7a42015-06-02 15:12:06 -0700495 log.info("Provisioned ACL table");
Saurav Dase3274c82015-05-24 17:21:56 -0700496 }
497
498 @Override
499 public void onError(FlowRuleOperations ops) {
Saurav Das337c7a42015-06-02 15:12:06 -0700500 log.info("Failed to provision ACL table");
Saurav Dase3274c82015-05-24 17:21:56 -0700501 }
502 }));
503 }
504
Saurav Das337c7a42015-06-02 15:12:06 -0700505 private class Filter {
506 private PortCriterion port;
507 private VlanIdCriterion vlan;
508 private EthCriterion eth;
Saurav Dase3274c82015-05-24 17:21:56 -0700509
Saurav Das337c7a42015-06-02 15:12:06 -0700510 @SuppressWarnings("unused")
511 private Collection<IPCriterion> ips;
Saurav Dase3274c82015-05-24 17:21:56 -0700512
Saurav Das337c7a42015-06-02 15:12:06 -0700513 public Filter(PortCriterion p, EthCriterion e, VlanIdCriterion v,
514 Collection<IPCriterion> ips) {
515 this.eth = e;
516 this.port = p;
517 this.vlan = v;
518 this.ips = ips;
Saurav Dase3274c82015-05-24 17:21:56 -0700519 }
Saurav Dase3274c82015-05-24 17:21:56 -0700520
Saurav Das337c7a42015-06-02 15:12:06 -0700521 public PortNumber port() {
522 return port.port();
523 }
Saurav Dase3274c82015-05-24 17:21:56 -0700524
Saurav Das337c7a42015-06-02 15:12:06 -0700525 public VlanId vlanId() {
526 return vlan.vlanId();
527 }
Saurav Dase3274c82015-05-24 17:21:56 -0700528
Saurav Das337c7a42015-06-02 15:12:06 -0700529 public MacAddress mac() {
530 return eth.mac();
Saurav Dase3274c82015-05-24 17:21:56 -0700531 }
532 }
533
534 private class PicaGroup implements NextGroup {
Saurav Das337c7a42015-06-02 15:12:06 -0700535 TrafficTreatment nextActions;
Saurav Dase3274c82015-05-24 17:21:56 -0700536
Saurav Das337c7a42015-06-02 15:12:06 -0700537 public PicaGroup(TrafficTreatment next) {
538 this.nextActions = next;
Saurav Dase3274c82015-05-24 17:21:56 -0700539 }
540
541 @Override
542 public byte[] data() {
Saurav Das337c7a42015-06-02 15:12:06 -0700543 return appKryo.serialize(nextActions);
Saurav Dase3274c82015-05-24 17:21:56 -0700544 }
Saurav Dase3274c82015-05-24 17:21:56 -0700545 }
Saurav Das24431192016-03-07 19:13:00 -0800546
547 @Override
548 public List<String> getNextMappings(NextGroup nextGroup) {
549 // TODO Implementation deferred to vendor
550 return null;
551 }
Saurav Dase3274c82015-05-24 17:21:56 -0700552}