blob: 32d6b103ede7c79854f018d83893d28c7b215b00 [file] [log] [blame]
Saurav Dase3274c82015-05-24 17:21:56 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
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;
62import java.util.concurrent.ConcurrentHashMap;
Saurav Dase3274c82015-05-24 17:21:56 -070063
Saurav Dase3274c82015-05-24 17:21:56 -070064import static org.slf4j.LoggerFactory.getLogger;
65
66/**
67 * Pica pipeline handler.
68 */
69public class PicaPipeline extends AbstractHandlerBehaviour implements Pipeliner {
70
Saurav Das337c7a42015-06-02 15:12:06 -070071 protected static final int IP_UNICAST_TABLE = 252;
72 protected static final int ACL_TABLE = 0;
Saurav Dase3274c82015-05-24 17:21:56 -070073
Saurav Das337c7a42015-06-02 15:12:06 -070074 //private static final int CONTROLLER_PRIORITY = 255;
Saurav Dase3274c82015-05-24 17:21:56 -070075 private static final int DROP_PRIORITY = 0;
76 private static final int HIGHEST_PRIORITY = 0xffff;
77
78 private final Logger log = getLogger(getClass());
79
80 private ServiceDirectory serviceDirectory;
81 private FlowRuleService flowRuleService;
82 private CoreService coreService;
Saurav Dase3274c82015-05-24 17:21:56 -070083 private FlowObjectiveStore flowObjectiveStore;
84 private DeviceId deviceId;
85 private ApplicationId appId;
Saurav Das337c7a42015-06-02 15:12:06 -070086 private Collection<Filter> filters;
87 private Collection<ForwardingObjective> pendingVersatiles;
Saurav Dase3274c82015-05-24 17:21:56 -070088
89 private KryoNamespace appKryo = new KryoNamespace.Builder()
Saurav Das337c7a42015-06-02 15:12:06 -070090 .register(KryoNamespaces.API)
Saurav Dase3274c82015-05-24 17:21:56 -070091 .register(PicaGroup.class)
92 .register(byte[].class)
93 .build();
94
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()
132 .filter(rule -> rule != null)
133 .forEach(flowBuilder::add);
134 break;
135 case REMOVE:
136 rules.stream()
137 .filter(rule -> rule != null)
138 .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
384 EthCriterion e = null; VlanIdCriterion v = null;
385 Collection<IPCriterion> ips = new ArrayList<IPCriterion>();
Saurav Dase3274c82015-05-24 17:21:56 -0700386 // convert filtering conditions for switch-intfs into flowrules
387 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
388 for (Criterion c : filt.conditions()) {
389 if (c.type() == Criterion.Type.ETH_DST) {
Saurav Das337c7a42015-06-02 15:12:06 -0700390 e = (EthCriterion) c;
Saurav Dase3274c82015-05-24 17:21:56 -0700391 } else if (c.type() == Criterion.Type.VLAN_VID) {
Saurav Das337c7a42015-06-02 15:12:06 -0700392 v = (VlanIdCriterion) c;
Saurav Dase3274c82015-05-24 17:21:56 -0700393 } else if (c.type() == Criterion.Type.IPV4_DST) {
Saurav Das337c7a42015-06-02 15:12:06 -0700394 ips.add((IPCriterion) c);
Saurav Dase3274c82015-05-24 17:21:56 -0700395 } else {
Saurav Das337c7a42015-06-02 15:12:06 -0700396 log.error("Unsupported filter {}", c);
Saurav Dase3274c82015-05-24 17:21:56 -0700397 fail(filt, ObjectiveError.UNSUPPORTED);
Saurav Das337c7a42015-06-02 15:12:06 -0700398 return;
Saurav Dase3274c82015-05-24 17:21:56 -0700399 }
400 }
Saurav Das337c7a42015-06-02 15:12:06 -0700401
402 // cache for later use
403 Filter filter = new Filter(p, e, v, ips);
404 filters.add(filter);
405
406 // apply any pending versatile forwarding objectives
407 for (ForwardingObjective fwd : pendingVersatiles) {
408 Collection<FlowRule> ret = processVersatilesWithFilters(filter, fwd);
409 for (FlowRule fr : ret) {
410 ops.add(fr);
411 }
412 }
413
414 for (IPCriterion ipaddr : ips) {
415 log.debug("adding IP filtering rules in ACL table: {}", ipaddr.ip());
416 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
417 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
418 selector.matchInPort(p.port());
419 selector.matchVlanId(v.vlanId());
420 selector.matchEthDst(e.mac());
421 selector.matchEthType(Ethernet.TYPE_IPV4);
422 selector.matchIPDst(ipaddr.ip()); // router IPs to the controller
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 = ops.add(rule);
433 }
434
Saurav Dase3274c82015-05-24 17:21:56 -0700435 // apply filtering flow rules
436 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
437 @Override
438 public void onSuccess(FlowRuleOperations ops) {
439 pass(filt);
440 log.info("Applied filtering rules");
441 }
442
443 @Override
444 public void onError(FlowRuleOperations ops) {
445 fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED);
446 log.info("Failed to apply filtering rules");
447 }
448 }));
449 }
450
451 private void pass(Objective obj) {
452 if (obj.context().isPresent()) {
453 obj.context().get().onSuccess(obj);
454 }
455 }
456
457 private void fail(Objective obj, ObjectiveError error) {
458 if (obj.context().isPresent()) {
459 obj.context().get().onError(obj, error);
460 }
461 }
462
463 private void initializePipeline() {
Saurav Das337c7a42015-06-02 15:12:06 -0700464 //processIpUnicastTable(true);
465 processACLTable(true);
Saurav Dase3274c82015-05-24 17:21:56 -0700466 }
467
Saurav Das337c7a42015-06-02 15:12:06 -0700468 private void processACLTable(boolean install) {
Saurav Dase3274c82015-05-24 17:21:56 -0700469 TrafficSelector.Builder selector;
470 TrafficTreatment.Builder treatment;
471 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
472 FlowRule rule;
473
474 //Drop rule
475 selector = DefaultTrafficSelector.builder();
476 treatment = DefaultTrafficTreatment.builder();
477
Saurav Dase3274c82015-05-24 17:21:56 -0700478 rule = DefaultFlowRule.builder()
479 .forDevice(deviceId)
480 .withSelector(selector.build())
481 .withTreatment(treatment.build())
482 .withPriority(DROP_PRIORITY)
483 .fromApp(appId)
484 .makePermanent()
Saurav Das337c7a42015-06-02 15:12:06 -0700485 .forTable(ACL_TABLE).build();
Saurav Dase3274c82015-05-24 17:21:56 -0700486
487 ops = install ? ops.add(rule) : ops.remove(rule);
488
489 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
490 @Override
491 public void onSuccess(FlowRuleOperations ops) {
Saurav Das337c7a42015-06-02 15:12:06 -0700492 log.info("Provisioned ACL table");
Saurav Dase3274c82015-05-24 17:21:56 -0700493 }
494
495 @Override
496 public void onError(FlowRuleOperations ops) {
Saurav Das337c7a42015-06-02 15:12:06 -0700497 log.info("Failed to provision ACL table");
Saurav Dase3274c82015-05-24 17:21:56 -0700498 }
499 }));
500 }
501
Saurav Das337c7a42015-06-02 15:12:06 -0700502 private class Filter {
503 private PortCriterion port;
504 private VlanIdCriterion vlan;
505 private EthCriterion eth;
Saurav Dase3274c82015-05-24 17:21:56 -0700506
Saurav Das337c7a42015-06-02 15:12:06 -0700507 @SuppressWarnings("unused")
508 private Collection<IPCriterion> ips;
Saurav Dase3274c82015-05-24 17:21:56 -0700509
Saurav Das337c7a42015-06-02 15:12:06 -0700510 public Filter(PortCriterion p, EthCriterion e, VlanIdCriterion v,
511 Collection<IPCriterion> ips) {
512 this.eth = e;
513 this.port = p;
514 this.vlan = v;
515 this.ips = ips;
Saurav Dase3274c82015-05-24 17:21:56 -0700516 }
Saurav Dase3274c82015-05-24 17:21:56 -0700517
Saurav Das337c7a42015-06-02 15:12:06 -0700518 public PortNumber port() {
519 return port.port();
520 }
Saurav Dase3274c82015-05-24 17:21:56 -0700521
Saurav Das337c7a42015-06-02 15:12:06 -0700522 public VlanId vlanId() {
523 return vlan.vlanId();
524 }
Saurav Dase3274c82015-05-24 17:21:56 -0700525
Saurav Das337c7a42015-06-02 15:12:06 -0700526 public MacAddress mac() {
527 return eth.mac();
Saurav Dase3274c82015-05-24 17:21:56 -0700528 }
529 }
530
531 private class PicaGroup implements NextGroup {
Saurav Das337c7a42015-06-02 15:12:06 -0700532 TrafficTreatment nextActions;
Saurav Dase3274c82015-05-24 17:21:56 -0700533
Saurav Das337c7a42015-06-02 15:12:06 -0700534 public PicaGroup(TrafficTreatment next) {
535 this.nextActions = next;
Saurav Dase3274c82015-05-24 17:21:56 -0700536 }
537
538 @Override
539 public byte[] data() {
Saurav Das337c7a42015-06-02 15:12:06 -0700540 return appKryo.serialize(nextActions);
Saurav Dase3274c82015-05-24 17:21:56 -0700541 }
Saurav Dase3274c82015-05-24 17:21:56 -0700542 }
543}