blob: 01b86ba9a110a65341b378c2de498f3504f22048 [file] [log] [blame]
Pier Ventre81c47bf2016-11-04 07:26:22 -07001/*
2 * Copyright 2016-present 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 */
16
17package org.onosproject.net.intent.impl.compiler;
18
19import com.google.common.collect.ImmutableSet;
20import org.junit.After;
21import org.junit.Before;
22import org.junit.Test;
23import org.onlab.packet.Ethernet;
24import org.onlab.packet.MplsLabel;
25import org.onlab.packet.VlanId;
26import org.onosproject.cfg.ComponentConfigAdapter;
27import org.onosproject.core.CoreService;
28import org.onosproject.net.FilteredConnectPoint;
29import org.onosproject.net.flow.DefaultTrafficSelector;
30import org.onosproject.net.flow.DefaultTrafficTreatment;
31import org.onosproject.net.flow.FlowRule;
32import org.onosproject.net.flow.criteria.MplsCriterion;
33import org.onosproject.net.flow.criteria.VlanIdCriterion;
34import org.onosproject.net.intent.FlowRuleIntent;
35import org.onosproject.net.intent.Intent;
36import org.onosproject.net.intent.IntentExtensionService;
37import org.onosproject.net.intent.LinkCollectionIntent;
38import org.onosproject.net.resource.MockResourceService;
39
40import java.util.Collection;
41import java.util.Collections;
42import java.util.List;
43import java.util.stream.Collectors;
44
45import static org.easymock.EasyMock.*;
46import static org.hamcrest.MatcherAssert.assertThat;
47import static org.hamcrest.Matchers.hasSize;
48import static org.hamcrest.core.Is.is;
49import static org.onlab.packet.EthType.EtherType.IPV4;
50import static org.onosproject.net.NetTestTools.*;
51import static org.onosproject.net.flow.criteria.Criterion.Type.*;
52import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
53
54/**
55 * This set of tests are meant to test the encapsulation
56 * in the LinkCollectionIntent.
57 */
58public class LinkCollectionOptimizationTest extends AbstractLinkCollectionTest {
59
60 @Before
61 public void setUp() {
62 sut = new LinkCollectionIntentCompiler();
63 coreService = createMock(CoreService.class);
64 expect(coreService.registerApplication("org.onosproject.net.intent"))
65 .andReturn(appId);
66 sut.coreService = coreService;
67
Thomas Vachuska23235962017-02-03 11:44:15 -080068 Intent.unbindIdGenerator(idGenerator);
Pier Ventre81c47bf2016-11-04 07:26:22 -070069 Intent.bindIdGenerator(idGenerator);
70
71 intentExtensionService = createMock(IntentExtensionService.class);
72 intentExtensionService.registerCompiler(LinkCollectionIntent.class, sut);
73 intentExtensionService.unregisterCompiler(LinkCollectionIntent.class);
74
75 registrator = new IntentConfigurableRegistrator();
76 registrator.extensionService = intentExtensionService;
77 registrator.cfgService = new ComponentConfigAdapter();
78 registrator.activate();
79
80 sut.registrator = registrator;
81 sut.resourceService = new MockResourceService();
82
83 /*
84 * We activate the optimizations.
85 */
86 LinkCollectionCompiler.optimize = true;
87 LinkCollectionCompiler.copyTtl = true;
88
89 replay(coreService, intentExtensionService);
90 }
91
92 @After
93 public void tearDown() {
94 Intent.unbindIdGenerator(idGenerator);
95 }
96
97 /**
98 * We test the proper optimization of sp2mp with dec tll
99 * and dec mpls ttl.
100 */
101 @Test
102 public void testDecTtlOptimization() {
103
104 intent = LinkCollectionIntent.builder()
105 .appId(APP_ID)
106 .selector(selector)
107 .treatment(decTllTreatment)
108 .links(linksForSp2Mp)
109 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10)))
110 .filteredEgressPoints(ImmutableSet.of(
111 new FilteredConnectPoint(d1p10),
112 new FilteredConnectPoint(d1p11),
113 new FilteredConnectPoint(d2p10)
114 ))
115 .applyTreatmentOnEgress(true)
116 .build();
117
118 sut.activate();
119
120 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
121 assertThat(compiled, hasSize(1));
122
123 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
124 assertThat(rules, hasSize(3));
125
126 Collection<FlowRule> rulesS3 = rules.stream()
127 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
128 .collect(Collectors.toSet());
129 assertThat(rulesS3, hasSize(1));
130 FlowRule ruleS3 = rulesS3.iterator().next();
131 assertThat(ruleS3.selector(), is(
132 DefaultTrafficSelector
133 .builder()
134 .matchInPort(d3p10.port())
135 .build()
136 ));
137 assertThat(ruleS3.treatment(), is(
138 DefaultTrafficTreatment
139 .builder()
140 .setOutput(d3p0.port())
141 .build()
142 ));
143
144 Collection<FlowRule> rulesS2 = rules.stream()
145 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
146 .collect(Collectors.toSet());
147 assertThat(rulesS2, hasSize(1));
148 FlowRule ruleS2 = rulesS2.iterator().next();
149 assertThat(ruleS2.selector(), is(
150 DefaultTrafficSelector
151 .builder()
152 .matchInPort(d2p1.port())
153 .build()
154 ));
155 assertThat(ruleS2.treatment(), is(
156 DefaultTrafficTreatment
157 .builder()
158 .setOutput(d2p0.port())
159 .decMplsTtl()
160 .decNwTtl()
161 .setOutput(d2p10.port())
162 .build()
163 ));
164
165 Collection<FlowRule> rulesS1 = rules.stream()
166 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
167 .collect(Collectors.toSet());
168 assertThat(rulesS1, hasSize(1));
169 FlowRule ruleS1 = rulesS1.iterator().next();
170 assertThat(ruleS1.selector(), is(
171 DefaultTrafficSelector
172 .builder()
173 .matchInPort(d1p0.port())
174 .build()
175 ));
176 assertThat(ruleS1.treatment(), is(
177 DefaultTrafficTreatment
178 .builder()
179 .decMplsTtl()
180 .decNwTtl()
181 .setOutput(d1p10.port())
182 .setOutput(d1p11.port())
183 .build()
184 ));
185
186 sut.deactivate();
187
188 }
189
190 /**
191 * We test the proper optimization of sp2mp with VLAN
192 * ingress point and different egress points: 1) it is
193 * a simple ingress point; 2) it is a vlan ingress point;
194 * 3) It is a simple ingress point. 1) and 2) share the same
195 * egress switch. The outcomes of the test are the re-ordering
196 * of the actions and the proper optimization of the chain.
197 */
198 @Test
199 public void testVlanOrder() {
200
201 intent = LinkCollectionIntent.builder()
202 .appId(APP_ID)
203 .selector(selector)
204 .treatment(treatment)
205 .links(linksForSp2Mp)
206 .applyTreatmentOnEgress(true)
207 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan100Selector)))
208 .filteredEgressPoints(ImmutableSet.of(
209 new FilteredConnectPoint(d1p10),
210 new FilteredConnectPoint(d1p11, vlan200Selector),
211 new FilteredConnectPoint(d2p10)
212 ))
213 .build();
214
215 sut.activate();
216
217 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
218 assertThat(compiled, hasSize(1));
219
220 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
221 assertThat(rules, hasSize(3));
222
223 Collection<FlowRule> rulesS3 = rules.stream()
224 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
225 .collect(Collectors.toSet());
226 assertThat(rulesS3, hasSize(1));
227 FlowRule ruleS3 = rulesS3.iterator().next();
228 assertThat(ruleS3.selector(), is(
229 DefaultTrafficSelector
230 .builder(vlan100Selector)
231 .matchInPort(d3p10.port())
232 .build()
233 ));
234 assertThat(ruleS3.treatment(), is(
235 DefaultTrafficTreatment
236 .builder()
237 .setOutput(d3p0.port())
238 .build()
239 ));
240
241 Collection<FlowRule> rulesS2 = rules.stream()
242 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
243 .collect(Collectors.toSet());
244 assertThat(rulesS2, hasSize(1));
245 FlowRule ruleS2 = rulesS2.iterator().next();
246 assertThat(ruleS2.selector(), is(
247 DefaultTrafficSelector
248 .builder(vlan100Selector)
249 .matchInPort(d2p1.port())
250 .build()
251 ));
252 assertThat(ruleS2.treatment(), is(
253 DefaultTrafficTreatment
254 .builder()
255 .setOutput(d2p0.port())
256 .popVlan()
257 .setOutput(d2p10.port())
258 .build()
259 ));
260
261 Collection<FlowRule> rulesS1 = rules.stream()
262 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
263 .collect(Collectors.toSet());
264 assertThat(rulesS1, hasSize(1));
265 FlowRule ruleS1 = rulesS1.iterator().next();
266 assertThat(ruleS1.selector(), is(
267 DefaultTrafficSelector
268 .builder(vlan100Selector)
269 .matchInPort(d1p0.port())
270 .build()
271 ));
272 assertThat(ruleS1.treatment(), is(
273 DefaultTrafficTreatment
274 .builder()
275 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
276 .setOutput(d1p11.port())
277 .popVlan()
278 .setOutput(d1p10.port())
279 .build()
280 ));
281
282 sut.deactivate();
283
284 }
285
286 /**
287 * We test the proper optimization of sp2mp with MPLS
288 * ingress point and different egress points: 1) it is
289 * a vlan ingress point; 2) it is a mpls ingress point;
290 * 3) It is a simple ingress point. 1) and 2) share the same
291 * egress switch. The outcomes of the test are the re-ordering
292 * of the actions and the proper optimization of the chain.
293 */
294 @Test
295 public void testMplsOrder() {
296
297 intent = LinkCollectionIntent.builder()
298 .appId(APP_ID)
299 .selector(selector)
300 .treatment(treatment)
301 .links(linksForSp2Mp)
302 .applyTreatmentOnEgress(true)
303 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls100Selector)))
304 .filteredEgressPoints(ImmutableSet.of(
305 new FilteredConnectPoint(d1p10, vlan100Selector),
306 new FilteredConnectPoint(d1p11, mpls200Selector),
307 new FilteredConnectPoint(d2p10)
308 ))
309 .build();
310
311 sut.activate();
312
313 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
314 assertThat(compiled, hasSize(1));
315
316 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
317 assertThat(rules, hasSize(3));
318
319 Collection<FlowRule> rulesS3 = rules.stream()
320 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
321 .collect(Collectors.toSet());
322 assertThat(rulesS3, hasSize(1));
323 FlowRule ruleS3 = rulesS3.iterator().next();
324 assertThat(ruleS3.selector(), is(
325 DefaultTrafficSelector
326 .builder(mpls100Selector)
327 .matchInPort(d3p10.port())
328 .build()
329 ));
330 assertThat(ruleS3.treatment(), is(
331 DefaultTrafficTreatment
332 .builder()
333 .setOutput(d3p0.port())
334 .build()
335 ));
336
337 Collection<FlowRule> rulesS2 = rules.stream()
338 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
339 .collect(Collectors.toSet());
340 assertThat(rulesS2, hasSize(1));
341 FlowRule ruleS2 = rulesS2.iterator().next();
342 assertThat(ruleS2.selector(), is(
343 DefaultTrafficSelector
344 .builder(mpls100Selector)
345 .matchInPort(d2p1.port())
346 .build()
347 ));
348 assertThat(ruleS2.treatment(), is(
349 DefaultTrafficTreatment
350 .builder()
351 .setOutput(d2p0.port())
352 .copyTtlIn()
353 .popMpls(IPV4.ethType())
354 .setOutput(d2p10.port())
355 .build()
356 ));
357
358 Collection<FlowRule> rulesS1 = rules.stream()
359 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
360 .collect(Collectors.toSet());
361 assertThat(rulesS1, hasSize(1));
362 FlowRule ruleS1 = rulesS1.iterator().next();
363 assertThat(ruleS1.selector(), is(
364 DefaultTrafficSelector
365 .builder(mpls100Selector)
366 .matchInPort(d1p0.port())
367 .build()
368 ));
369 assertThat(ruleS1.treatment(), is(
370 DefaultTrafficTreatment
371 .builder()
372 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
373 .setOutput(d1p11.port())
374 .copyTtlIn()
375 .popMpls(IPV4.ethType())
376 .pushVlan()
377 .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
378 .setOutput(d1p10.port())
379 .build()
380 ));
381
382 sut.deactivate();
383
384 }
385
386 /**
387 * We test the proper optimization of sp2mp with untagged
388 * ingress point and different egress points: 1) it is
389 * a vlan ingress point; 2) it is a mpls ingress point;
390 * 3) It is a simple ingress point. 1) and 2) share the same
391 * egress switch. The outcomes of the test are the re-ordering
392 * of the actions and the proper optimization of the chain.
393 */
394 @Test
395 public void testUntaggedOrder() {
396
397 intent = LinkCollectionIntent.builder()
398 .appId(APP_ID)
399 .selector(selector)
400 .treatment(treatment)
401 .links(linksForSp2Mp)
402 .applyTreatmentOnEgress(true)
403 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10)))
404 .filteredEgressPoints(ImmutableSet.of(
405 new FilteredConnectPoint(d1p10, vlan100Selector),
406 new FilteredConnectPoint(d1p11, mpls200Selector),
407 new FilteredConnectPoint(d1p12),
408 new FilteredConnectPoint(d2p10)
409 ))
410 .build();
411
412 sut.activate();
413
414 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
415 assertThat(compiled, hasSize(1));
416
417 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
418 assertThat(rules, hasSize(3));
419
420 Collection<FlowRule> rulesS3 = rules.stream()
421 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
422 .collect(Collectors.toSet());
423 assertThat(rulesS3, hasSize(1));
424 FlowRule ruleS3 = rulesS3.iterator().next();
425 assertThat(ruleS3.selector(), is(
426 DefaultTrafficSelector
427 .builder()
428 .matchInPort(d3p10.port())
429 .build()
430 ));
431 assertThat(ruleS3.treatment(), is(
432 DefaultTrafficTreatment
433 .builder()
434 .setOutput(d3p0.port())
435 .build()
436 ));
437
438
439 Collection<FlowRule> rulesS2 = rules.stream()
440 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
441 .collect(Collectors.toSet());
442 assertThat(rulesS2, hasSize(1));
443 FlowRule ruleS2 = rulesS2.iterator().next();
444 assertThat(ruleS2.selector(), is(
445 DefaultTrafficSelector
446 .builder()
447 .matchInPort(d2p1.port())
448 .build()
449 ));
450 assertThat(ruleS2.treatment(), is(
451 DefaultTrafficTreatment
452 .builder()
453 .setOutput(d2p0.port())
454 .setOutput(d2p10.port())
455 .build()
456 ));
457
458
459 Collection<FlowRule> rulesS1 = rules.stream()
460 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
461 .collect(Collectors.toSet());
462 assertThat(rulesS1, hasSize(1));
463 FlowRule ruleS1 = rulesS1.iterator().next();
464 assertThat(ruleS1.selector(), is(
465 DefaultTrafficSelector
466 .builder()
467 .matchInPort(d1p0.port())
468 .build()
469 ));
470 assertThat(ruleS1.treatment(), is(
471 DefaultTrafficTreatment
472 .builder()
473 .setOutput(d1p12.port())
474 .pushVlan()
475 .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
476 .setOutput(d1p10.port())
477 .popVlan()
478 .pushMpls()
479 .copyTtlOut()
480 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
481 .setOutput(d1p11.port())
482 .build()
483 ));
484
485 sut.deactivate();
486
487 }
488
489 /**
490 * We test the proper optimization of sp2mp with VLAN ingress point,
491 * simple egress point, non trivial intent treatment and non trivial
492 * intent selector. The outcomes of the test are the proper optimization
493 * of the actions. It is expected that the actions related to the intent
494 * treatment and intent selector are not optimized. The optimization is
495 * performed only on the dec ttl actions and on the actions which create
496 * traffic slices. The rationale is that in the intent treatment we expect
497 * actions like set something so it is fine to perform them several times.
498 */
499 @Test
500 public void testPoPVlanOptimization() {
501
502 intent = LinkCollectionIntent.builder()
503 .appId(APP_ID)
504 .selector(ipPrefixSelector)
505 .treatment(ethDstTreatment)
506 .links(linksForSp2Mp)
507 .applyTreatmentOnEgress(true)
508 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan100Selector)))
509 .filteredEgressPoints(ImmutableSet.of(
510 new FilteredConnectPoint(d1p10),
511 new FilteredConnectPoint(d1p11),
512 new FilteredConnectPoint(d1p12),
513 new FilteredConnectPoint(d2p10)
514 ))
515 .build();
516
517 sut.activate();
518
519 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
520 assertThat(compiled, hasSize(1));
521
522 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
523 assertThat(rules, hasSize(3));
524
525 Collection<FlowRule> rulesS3 = rules.stream()
526 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
527 .collect(Collectors.toSet());
528 assertThat(rulesS3, hasSize(1));
529 FlowRule ruleS3 = rulesS3.iterator().next();
530 assertThat(ruleS3.selector(), is(
531 DefaultTrafficSelector
532 .builder(ipPrefixSelector)
533 .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
534 .matchInPort(d3p10.port())
535 .build()
536 ));
537 assertThat(ruleS3.treatment(), is(
538 DefaultTrafficTreatment
539 .builder()
540 .setOutput(d3p0.port())
541 .build()
542 ));
543
544 Collection<FlowRule> rulesS2 = rules.stream()
545 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
546 .collect(Collectors.toSet());
547 assertThat(rulesS2, hasSize(1));
548 FlowRule ruleS2 = rulesS2.iterator().next();
549 assertThat(ruleS2.selector(), is(
550 DefaultTrafficSelector
551 .builder(ipPrefixSelector)
552 .matchInPort(d2p1.port())
553 .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
554 .build()
555 ));
556 assertThat(ruleS2.treatment(), is(
557 DefaultTrafficTreatment
558 .builder()
559 .setOutput(d2p0.port())
560 .setEthDst(((ModEtherInstruction) ethDstTreatment
561 .allInstructions()
562 .stream()
563 .filter(instruction -> instruction instanceof ModEtherInstruction)
564 .findFirst().get()).mac())
565 .popVlan()
566 .setOutput(d2p10.port())
567 .build()
568 ));
569
570 Collection<FlowRule> rulesS1 = rules.stream()
571 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
572 .collect(Collectors.toSet());
573 assertThat(rulesS1, hasSize(1));
574 FlowRule ruleS1 = rulesS1.iterator().next();
575 assertThat(ruleS1.selector(), is(
576 DefaultTrafficSelector
577 .builder(ipPrefixSelector)
578 .matchInPort(d1p0.port())
579 .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
580 .build()
581 ));
582 assertThat(ruleS1.treatment(), is(
583 DefaultTrafficTreatment
584 .builder()
585 .setEthDst(((ModEtherInstruction) ethDstTreatment
586 .allInstructions()
587 .stream()
588 .filter(instruction -> instruction instanceof ModEtherInstruction)
589 .findFirst().get()).mac())
590 .popVlan()
591 .setOutput(d1p12.port())
592 .setEthDst(((ModEtherInstruction) ethDstTreatment
593 .allInstructions()
594 .stream()
595 .filter(instruction -> instruction instanceof ModEtherInstruction)
596 .findFirst().get()).mac())
597 .setOutput(d1p10.port())
598 .setEthDst(((ModEtherInstruction) ethDstTreatment
599 .allInstructions()
600 .stream()
601 .filter(instruction -> instruction instanceof ModEtherInstruction)
602 .findFirst().get()).mac())
603 .setOutput(d1p11.port())
604 .build()
605 ));
606
607 sut.deactivate();
608
609 }
610
611 /**
612 * We test the proper optimization of sp2mp with the VLAN
613 * encapsulation and trivial selector.
614 */
615 @Test
616 public void testOptimizationMplsEncapTrivialSelectors() {
617
618 intent = LinkCollectionIntent.builder()
619 .appId(APP_ID)
620 .selector(selector)
621 .treatment(treatment)
622 .constraints(constraintsForMPLS)
623 .links(linksForSp2Mp)
624 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10)))
625 .filteredEgressPoints(ImmutableSet.of(
626 new FilteredConnectPoint(d1p10),
627 new FilteredConnectPoint(d1p11),
628 new FilteredConnectPoint(d2p10)
629 ))
630 .build();
631
632 sut.activate();
633 /*
634 * We use the FIRST_FIT to simplify tests.
635 */
636 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
637
638 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
639 assertThat(compiled, hasSize(1));
640
641 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
642 assertThat(rules, hasSize(3));
643
644 Collection<FlowRule> rulesS3 = rules.stream()
645 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
646 .collect(Collectors.toSet());
647 assertThat(rulesS3, hasSize(1));
648 FlowRule ruleS3 = rulesS3.iterator().next();
649 assertThat(ruleS3.selector(), is(
650 DefaultTrafficSelector
651 .builder()
652 .matchInPort(d3p10.port())
653 .build()
654 ));
655 assertThat(ruleS3.treatment(), is(
656 DefaultTrafficTreatment
657 .builder()
658 .pushMpls()
659 .copyTtlOut()
660 .setMpls(MplsLabel.mplsLabel(LABEL))
661 .setOutput(d3p0.port())
662 .build()
663 ));
664
665 Collection<FlowRule> rulesS2 = rules.stream()
666 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
667 .collect(Collectors.toSet());
668 assertThat(rulesS2, hasSize(1));
669 FlowRule ruleS2 = rulesS2.iterator().next();
670 assertThat(ruleS2.selector(), is(
671 DefaultTrafficSelector
672 .builder()
673 .matchInPort(d2p1.port())
674 .matchMplsLabel(MplsLabel.mplsLabel((LABEL)))
675 .matchEthType(Ethernet.MPLS_UNICAST)
676 .build()
677 ));
678 assertThat(ruleS2.treatment(), is(
679 DefaultTrafficTreatment
680 .builder()
681 .setMpls(MplsLabel.mplsLabel(LABEL))
682 .setOutput(d2p0.port())
683 .copyTtlIn()
684 .popMpls(IPV4.ethType())
685 .setOutput(d2p10.port())
686 .build()
687 ));
688
689 Collection<FlowRule> rulesS1 = rules.stream()
690 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
691 .collect(Collectors.toSet());
692 assertThat(rulesS1, hasSize(1));
693 FlowRule ruleS1 = rulesS1.iterator().next();
694 assertThat(ruleS1.selector(), is(
695 DefaultTrafficSelector
696 .builder()
697 .matchInPort(d1p0.port())
698 .matchMplsLabel(MplsLabel.mplsLabel((LABEL)))
699 .matchEthType(Ethernet.MPLS_UNICAST)
700 .build()
701 ));
702 assertThat(ruleS1.treatment(), is(
703 DefaultTrafficTreatment
704 .builder()
705 .copyTtlIn()
706 .popMpls(IPV4.ethType())
707 .setOutput(d1p10.port())
708 .setOutput(d1p11.port())
709 .build()
710 ));
711
712 sut.deactivate();
713
714 }
715
716 /**
717 * We test the proper optimization of sp2mp with the VLAN
718 * encapsulation, filtered selectors.
719 */
720 @Test
721 public void testOptimizationVlanEncapMplsSelectors() {
722
723 intent = LinkCollectionIntent.builder()
724 .appId(APP_ID)
725 .selector(selector)
726 .treatment(treatment)
727 .constraints(constraintsForVlan)
728 .links(linksForSp2Mp)
729 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls80Selector)))
730 .filteredEgressPoints(ImmutableSet.of(
731 new FilteredConnectPoint(d1p10, mpls100Selector),
732 new FilteredConnectPoint(d1p11, mpls200Selector),
733 new FilteredConnectPoint(d2p10, mpls69Selector)
734 ))
735 .build();
736
737 sut.activate();
738 /*
739 * We use the FIRST_FIT to simplify tests.
740 */
741 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
742
743 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
744 assertThat(compiled, hasSize(1));
745
746 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
747 assertThat(rules, hasSize(3));
748
749 Collection<FlowRule> rulesS3 = rules.stream()
750 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
751 .collect(Collectors.toSet());
752 assertThat(rulesS3, hasSize(1));
753 FlowRule ruleS3 = rulesS3.iterator().next();
754 assertThat(ruleS3.selector(), is(
755 DefaultTrafficSelector
756 .builder(mpls80Selector)
757 .matchInPort(d3p10.port())
758 .build()
759 ));
760 assertThat(ruleS3.treatment(), is(
761 DefaultTrafficTreatment
762 .builder()
763 .copyTtlIn()
764 .popMpls(IPV4.ethType())
765 .pushVlan()
766 .setVlanId(VlanId.vlanId(LABEL))
767 .setOutput(d3p0.port())
768 .build()
769 ));
770
771 Collection<FlowRule> rulesS2 = rules.stream()
772 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
773 .collect(Collectors.toSet());
774 assertThat(rulesS2, hasSize(1));
775 FlowRule ruleS2 = rulesS2.iterator().next();
776 assertThat(ruleS2.selector(), is(
777 DefaultTrafficSelector
778 .builder()
779 .matchInPort(d2p1.port())
780 .matchVlanId(VlanId.vlanId(LABEL))
781 .build()
782 ));
783 assertThat(ruleS2.treatment(), is(
784 DefaultTrafficTreatment
785 .builder()
786 .setVlanId(VlanId.vlanId(LABEL))
787 .setOutput(d2p0.port())
788 .popVlan()
789 .pushMpls()
790 .copyTtlOut()
791 .setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label())
792 .setOutput(d2p10.port())
793 .build()
794 ));
795
796 Collection<FlowRule> rulesS1 = rules.stream()
797 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
798 .collect(Collectors.toSet());
799 assertThat(rulesS1, hasSize(1));
800 FlowRule ruleS1 = rulesS1.iterator().next();
801 assertThat(ruleS1.selector(), is(
802 DefaultTrafficSelector
803 .builder()
804 .matchInPort(d1p0.port())
805 .matchVlanId(VlanId.vlanId(LABEL))
806 .build()
807 ));
808 assertThat(ruleS1.treatment(), is(
809 DefaultTrafficTreatment
810 .builder()
811 .popVlan()
812 .pushMpls()
813 .copyTtlOut()
814 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
815 .setOutput(d1p10.port())
816 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
817 .setOutput(d1p11.port())
818 .build()
819 ));
820
821 sut.deactivate();
822
823 }
824
825 /**
826 * We test the proper optimization of sp2mp with the MPLS
827 * encapsulation, filtered selectors, intent selector, and
828 * intent treatment.
829 */
830 @Test
831 public void testOptimizationMplsEncapNonTrivial() {
832
833 intent = LinkCollectionIntent.builder()
834 .appId(APP_ID)
835 .selector(ipPrefixSelector)
836 .treatment(ethDstTreatment)
837 .constraints(constraintsForMPLS)
838 .links(linksForSp2Mp)
839 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan69Selector)))
840 .filteredEgressPoints(ImmutableSet.of(
841 new FilteredConnectPoint(d1p10, vlan100Selector),
842 new FilteredConnectPoint(d1p11, vlan200Selector),
843 new FilteredConnectPoint(d2p10, vlan300Selector)
844 ))
845 .build();
846
847 sut.activate();
848 /*
849 * We use the FIRST_FIT to simplify tests.
850 */
851 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
852
853 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
854 assertThat(compiled, hasSize(1));
855
856 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
857 assertThat(rules, hasSize(3));
858
859 Collection<FlowRule> rulesS3 = rules.stream()
860 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
861 .collect(Collectors.toSet());
862 assertThat(rulesS3, hasSize(1));
863 FlowRule ruleS3 = rulesS3.iterator().next();
864 assertThat(ruleS3.selector(), is(
865 DefaultTrafficSelector
866 .builder(ipPrefixSelector)
867 .matchInPort(d3p10.port())
868 .matchVlanId(((VlanIdCriterion) vlan69Selector.getCriterion(VLAN_VID)).vlanId())
869 .build()
870 ));
871 assertThat(ruleS3.treatment(), is(
872 DefaultTrafficTreatment
873 .builder()
874 .popVlan()
875 .pushMpls()
876 .copyTtlOut()
877 .setMpls(MplsLabel.mplsLabel(LABEL))
878 .setOutput(d3p0.port())
879 .build()
880 ));
881
882 Collection<FlowRule> rulesS2 = rules.stream()
883 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
884 .collect(Collectors.toSet());
885 assertThat(rulesS2, hasSize(1));
886 FlowRule ruleS2 = rulesS2.iterator().next();
887 assertThat(ruleS2.selector(), is(
888 DefaultTrafficSelector
889 .builder()
890 .matchInPort(d2p1.port())
891 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
892 .matchEthType(Ethernet.MPLS_UNICAST)
893 .build()
894 ));
895 assertThat(ruleS2.treatment(), is(
896 DefaultTrafficTreatment
897 .builder()
898 .setMpls(MplsLabel.mplsLabel(LABEL))
899 .setOutput(d2p0.port())
900 .setEthDst(((ModEtherInstruction) ethDstTreatment
901 .allInstructions()
902 .stream()
903 .filter(instruction -> instruction instanceof ModEtherInstruction)
904 .findFirst().get()).mac())
905 .copyTtlIn()
906 .popMpls(IPV4.ethType())
907 .pushVlan()
908 .setVlanId(((VlanIdCriterion) vlan300Selector.getCriterion(VLAN_VID)).vlanId())
909 .setOutput(d2p10.port())
910 .build()
911 ));
912
913 Collection<FlowRule> rulesS1 = rules.stream()
914 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
915 .collect(Collectors.toSet());
916 assertThat(rulesS1, hasSize(1));
917 FlowRule ruleS1 = rulesS1.iterator().next();
918 assertThat(ruleS1.selector(), is(
919 DefaultTrafficSelector
920 .builder()
921 .matchInPort(d1p0.port())
922 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
923 .matchEthType(Ethernet.MPLS_UNICAST)
924 .build()
925 ));
926 assertThat(ruleS1.treatment(), is(
927 DefaultTrafficTreatment
928 .builder()
929 .setEthDst(((ModEtherInstruction) ethDstTreatment
930 .allInstructions()
931 .stream()
932 .filter(instruction -> instruction instanceof ModEtherInstruction)
933 .findFirst().get()).mac())
934 .copyTtlIn()
935 .popMpls(IPV4.ethType())
936 .pushVlan()
937 .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
938 .setOutput(d1p10.port())
939 .setEthDst(((ModEtherInstruction) ethDstTreatment
940 .allInstructions()
941 .stream()
942 .filter(instruction -> instruction instanceof ModEtherInstruction)
943 .findFirst().get()).mac())
944 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
945 .setOutput(d1p11.port())
946 .build()
947 ));
948
949 sut.deactivate();
950
951 }
952
953 /**
954 * We test the proper compilation of sp2mp with the VLAN
955 * encapsulation and filtered selectors of different type.
956 */
957 @Test
958 public void testOptimizationVlanEncapDifferentSelectors() {
959
960 intent = LinkCollectionIntent.builder()
961 .appId(APP_ID)
962 .selector(selector)
963 .treatment(treatment)
964 .constraints(constraintsForVlan)
965 .links(linksForSp2Mp)
966 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan69Selector)))
967 .filteredEgressPoints(ImmutableSet.of(
968 new FilteredConnectPoint(d1p10, mpls100Selector),
969 new FilteredConnectPoint(d1p11, vlan200Selector),
970 new FilteredConnectPoint(d1p12),
971 new FilteredConnectPoint(d2p10, mpls200Selector)
972 ))
973 .build();
974
975 sut.activate();
976 /*
977 * We use the FIRST_FIT to simplify tests.
978 */
979 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
980
981 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
982 assertThat(compiled, hasSize(1));
983
984 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
985 assertThat(rules, hasSize(3));
986
987 Collection<FlowRule> rulesS3 = rules.stream()
988 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
989 .collect(Collectors.toSet());
990 assertThat(rulesS3, hasSize(1));
991 FlowRule ruleS3 = rulesS3.iterator().next();
992 assertThat(ruleS3.selector(), is(
993 DefaultTrafficSelector
994 .builder(vlan69Selector)
995 .matchInPort(d3p10.port())
996 .build()
997 ));
998 assertThat(ruleS3.treatment(), is(
999 DefaultTrafficTreatment
1000 .builder()
1001 .setVlanId(VlanId.vlanId(LABEL))
1002 .setOutput(d3p0.port())
1003 .build()
1004 ));
1005
1006 Collection<FlowRule> rulesS2 = rules.stream()
1007 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1008 .collect(Collectors.toSet());
1009 assertThat(rulesS2, hasSize(1));
1010 FlowRule ruleS2 = rulesS2.iterator().next();
1011 assertThat(ruleS2.selector(), is(
1012 DefaultTrafficSelector
1013 .builder()
1014 .matchInPort(d2p1.port())
1015 .matchVlanId(VlanId.vlanId(LABEL))
1016 .build()
1017 ));
1018 assertThat(ruleS2.treatment(), is(
1019 DefaultTrafficTreatment
1020 .builder()
1021 .setVlanId(VlanId.vlanId(LABEL))
1022 .setOutput(d2p0.port())
1023 .popVlan()
1024 .pushMpls()
1025 .copyTtlOut()
1026 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1027 .setOutput(d2p10.port())
1028 .build()
1029 ));
1030
1031 Collection<FlowRule> rulesS1 = rules.stream()
1032 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1033 .collect(Collectors.toSet());
1034 assertThat(rulesS1, hasSize(1));
1035 FlowRule ruleS1 = rulesS1.iterator().next();
1036 assertThat(ruleS1.selector(), is(
1037 DefaultTrafficSelector
1038 .builder()
1039 .matchInPort(d1p0.port())
1040 .matchVlanId(VlanId.vlanId(LABEL))
1041 .build()
1042 ));
1043 assertThat(ruleS1.treatment(), is(
1044 DefaultTrafficTreatment
1045 .builder()
1046 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1047 .setOutput(d1p11.port())
1048 .popVlan()
1049 .setOutput(d1p12.port())
1050 .pushMpls()
1051 .copyTtlOut()
1052 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1053 .setOutput(d1p10.port())
1054 .build()
1055 ));
1056
1057 sut.deactivate();
1058
1059 }
1060
Pier Ventre5c4a0762016-11-21 10:28:13 -08001061 /**
1062 * We test the proper optimization of sp2mp with trivial selector,
1063 * trivial treatment, vlan encapsulation and co-located
1064 * ingress/egress points.
1065 */
1066 @Test
1067 public void testOptimizationCoLocatedPointsTrivialForSp() {
1068
1069 intent = LinkCollectionIntent.builder()
1070 .appId(APP_ID)
1071 .selector(selector)
1072 .treatment(treatment)
1073 .applyTreatmentOnEgress(true)
1074 .links(linksForSp2MpCoLoc)
1075 .constraints(constraintsForVlan)
1076 .filteredIngressPoints(ImmutableSet.of(
1077 new FilteredConnectPoint(d1p10)
1078 ))
1079 .filteredEgressPoints(ImmutableSet.of(
1080 new FilteredConnectPoint(d1p11),
1081 new FilteredConnectPoint(d2p10),
1082 new FilteredConnectPoint(d3p10)
1083 ))
1084 .build();
1085
1086 sut.activate();
1087
1088 /*
1089 * We use the FIRST_FIT to simplify tests.
1090 */
1091 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1092
1093 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1094 assertThat(compiled, hasSize(1));
1095
1096 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1097 assertThat(rules, hasSize(3));
1098
1099 Collection<FlowRule> rulesS1 = rules.stream()
1100 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1101 .collect(Collectors.toSet());
1102 assertThat(rulesS1, hasSize(1));
1103
1104 FlowRule ruleS1 = rulesS1.iterator().next();
1105 assertThat(ruleS1.selector(), is(
1106 DefaultTrafficSelector
1107 .builder(selector)
1108 .matchInPort(d1p10.port())
1109 .build()
1110 ));
1111 assertThat(ruleS1.treatment(), is(
1112 DefaultTrafficTreatment
1113 .builder()
1114 .pushVlan()
1115 .setVlanId(VlanId.vlanId(LABEL))
1116 .setOutput(d1p0.port())
1117 .popVlan()
1118 .setOutput(d1p11.port())
1119 .build()
1120 ));
1121
1122 Collection<FlowRule> rulesS2 = rules.stream()
1123 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1124 .collect(Collectors.toSet());
1125 assertThat(rulesS2, hasSize(1));
1126
1127 FlowRule ruleS2 = rulesS2.iterator().next();
1128 assertThat(ruleS2.selector(), is(
1129 DefaultTrafficSelector
1130 .builder()
1131 .matchInPort(d2p0.port())
1132 .matchVlanId(VlanId.vlanId(LABEL))
1133 .build()
1134 ));
1135 assertThat(ruleS2.treatment(), is(
1136 DefaultTrafficTreatment
1137 .builder()
1138 .setVlanId(VlanId.vlanId(LABEL))
1139 .setOutput(d2p1.port())
1140 .popVlan()
1141 .setOutput(d2p10.port())
1142 .build()
1143 ));
1144
1145 Collection<FlowRule> rulesS3 = rules.stream()
1146 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
1147 .collect(Collectors.toSet());
1148 assertThat(rulesS3, hasSize(1));
1149
1150 FlowRule ruleS3 = rulesS3.iterator().next();
1151 assertThat(ruleS3.selector(), is(
1152 DefaultTrafficSelector
1153 .builder()
1154 .matchInPort(d3p0.port())
1155 .matchVlanId(VlanId.vlanId(LABEL))
1156 .build()
1157 ));
1158 assertThat(ruleS3.treatment(), is(
1159 DefaultTrafficTreatment
1160 .builder()
1161 .popVlan()
1162 .setOutput(d3p10.port())
1163 .build()
1164 ));
1165
1166 sut.deactivate();
1167
1168 }
1169
1170 /**
1171 * We test the proper optimization of sp2mp with trivial selector,
1172 * trivial treatment, mpls encapsulation and co-located
1173 * filtered ingress/egress points.
1174 */
1175 @Test
1176 public void testCoLocatedFilteredPointsTrivialForSp() {
1177
1178 intent = LinkCollectionIntent.builder()
1179 .appId(APP_ID)
1180 .selector(selector)
1181 .treatment(treatment)
1182 .applyTreatmentOnEgress(true)
1183 .links(linksForSp2MpCoLoc)
1184 .constraints(constraintsForMPLS)
1185 .filteredIngressPoints(ImmutableSet.of(
1186 new FilteredConnectPoint(d1p10, vlan100Selector)
1187 ))
1188 .filteredEgressPoints(ImmutableSet.of(
1189 new FilteredConnectPoint(d1p11, vlan200Selector),
1190 new FilteredConnectPoint(d2p10, vlan300Selector),
1191 new FilteredConnectPoint(d3p10, vlan69Selector)
1192 ))
1193 .build();
1194
1195 sut.activate();
1196
1197 /*
1198 * We use the FIRST_FIT to simplify tests.
1199 */
1200 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1201
1202 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1203 assertThat(compiled, hasSize(1));
1204
1205 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1206 assertThat(rules, hasSize(3));
1207
1208 Collection<FlowRule> rulesS1 = rules.stream()
1209 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1210 .collect(Collectors.toSet());
1211 assertThat(rulesS1, hasSize(1));
1212
1213 FlowRule ruleS1 = rulesS1.iterator().next();
1214 assertThat(ruleS1.selector(), is(
1215 DefaultTrafficSelector
1216 .builder(vlan100Selector)
1217 .matchInPort(d1p10.port())
1218 .build()
1219 ));
1220 assertThat(ruleS1.treatment(), is(
1221 DefaultTrafficTreatment
1222 .builder()
1223 .popVlan()
1224 .pushMpls()
1225 .copyTtlOut()
1226 .setMpls(MplsLabel.mplsLabel(LABEL))
1227 .setOutput(d1p0.port())
1228 .copyTtlIn()
1229 .popMpls(IPV4.ethType())
1230 .pushVlan()
1231 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1232 .setOutput(d1p11.port())
1233 .build()
1234 ));
1235
1236
1237 Collection<FlowRule> rulesS2 = rules.stream()
1238 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1239 .collect(Collectors.toSet());
1240 assertThat(rulesS2, hasSize(1));
1241
1242 FlowRule ruleS2 = rulesS2.iterator().next();
1243 assertThat(ruleS2.selector(), is(
1244 DefaultTrafficSelector
1245 .builder()
1246 .matchInPort(d2p0.port())
1247 .matchEthType(Ethernet.MPLS_UNICAST)
1248 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1249 .build()
1250 ));
1251 assertThat(ruleS2.treatment(), is(
1252 DefaultTrafficTreatment
1253 .builder()
1254 .setMpls(MplsLabel.mplsLabel(LABEL))
1255 .setOutput(d2p1.port())
1256 .copyTtlIn()
1257 .popMpls(IPV4.ethType())
1258 .pushVlan()
1259 .setVlanId(((VlanIdCriterion) vlan300Selector.getCriterion(VLAN_VID)).vlanId())
1260 .setOutput(d2p10.port())
1261 .build()
1262 ));
1263
1264
1265 Collection<FlowRule> rulesS3 = rules.stream()
1266 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
1267 .collect(Collectors.toSet());
1268 assertThat(rulesS3, hasSize(1));
1269
1270 FlowRule ruleS3 = rulesS3.iterator().next();
1271 assertThat(ruleS3.selector(), is(
1272 DefaultTrafficSelector
1273 .builder()
1274 .matchInPort(d3p0.port())
1275 .matchEthType(Ethernet.MPLS_UNICAST)
1276 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1277 .build()
1278 ));
1279 assertThat(ruleS3.treatment(), is(
1280 DefaultTrafficTreatment
1281 .builder()
1282 .copyTtlIn()
1283 .popMpls(IPV4.ethType())
1284 .pushVlan()
1285 .setVlanId(((VlanIdCriterion) vlan69Selector.getCriterion(VLAN_VID)).vlanId())
1286 .setOutput(d3p10.port())
1287 .build()
1288 ));
1289
1290 sut.deactivate();
1291
1292 }
1293
1294 /**
1295 * We test the proper optimization of sp2mp with trivial selector,
1296 * trivial treatment, vlan encapsulation and co-located
1297 * different filtered ingress/egress points.
1298 */
1299 @Test
1300 public void testCoLocatedDifferentFilteredPointsTrivialForSp() {
1301
1302 intent = LinkCollectionIntent.builder()
1303 .appId(APP_ID)
1304 .selector(selector)
1305 .treatment(treatment)
1306 .applyTreatmentOnEgress(true)
1307 .links(linksForSp2MpCoLoc)
1308 .constraints(constraintsForVlan)
1309 .filteredIngressPoints(ImmutableSet.of(
1310 new FilteredConnectPoint(d1p10, vlan100Selector)
1311 ))
1312 .filteredEgressPoints(ImmutableSet.of(
1313 new FilteredConnectPoint(d1p11, mpls100Selector),
1314 new FilteredConnectPoint(d2p10, vlan200Selector),
1315 new FilteredConnectPoint(d3p10, mpls200Selector)
1316 ))
1317 .build();
1318
1319 sut.activate();
1320
1321 /*
1322 * We use the FIRST_FIT to simplify tests.
1323 */
1324 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1325
1326 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1327 assertThat(compiled, hasSize(1));
1328
1329 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1330 assertThat(rules, hasSize(3));
1331
1332 Collection<FlowRule> rulesS1 = rules.stream()
1333 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1334 .collect(Collectors.toSet());
1335 assertThat(rulesS1, hasSize(1));
1336
1337 FlowRule ruleS1 = rulesS1.iterator().next();
1338 assertThat(ruleS1.selector(), is(
1339 DefaultTrafficSelector
1340 .builder(vlan100Selector)
1341 .matchInPort(d1p10.port())
1342 .build()
1343 ));
1344 assertThat(ruleS1.treatment(), is(
1345 DefaultTrafficTreatment
1346 .builder()
1347 .setVlanId(VlanId.vlanId(LABEL))
1348 .setOutput(d1p0.port())
1349 .popVlan()
1350 .pushMpls()
1351 .copyTtlOut()
1352 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1353 .setOutput(d1p11.port())
1354 .build()
1355 ));
1356
1357
1358 Collection<FlowRule> rulesS2 = rules.stream()
1359 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1360 .collect(Collectors.toSet());
1361 assertThat(rulesS2, hasSize(1));
1362
1363 FlowRule ruleS2 = rulesS2.iterator().next();
1364 assertThat(ruleS2.selector(), is(
1365 DefaultTrafficSelector
1366 .builder()
1367 .matchInPort(d2p0.port())
1368 .matchVlanId(VlanId.vlanId(LABEL))
1369 .build()
1370 ));
1371 assertThat(ruleS2.treatment(), is(
1372 DefaultTrafficTreatment
1373 .builder()
1374 .setVlanId(VlanId.vlanId(LABEL))
1375 .setOutput(d2p1.port())
1376 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1377 .setOutput(d2p10.port())
1378 .build()
1379 ));
1380
1381
1382 Collection<FlowRule> rulesS3 = rules.stream()
1383 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
1384 .collect(Collectors.toSet());
1385 assertThat(rulesS3, hasSize(1));
1386
1387 FlowRule ruleS3 = rulesS3.iterator().next();
1388 assertThat(ruleS3.selector(), is(
1389 DefaultTrafficSelector
1390 .builder()
1391 .matchVlanId(VlanId.vlanId(LABEL))
1392 .matchInPort(d3p0.port())
1393 .build()
1394 ));
1395 assertThat(ruleS3.treatment(), is(
1396 DefaultTrafficTreatment
1397 .builder()
1398 .popVlan()
1399 .pushMpls()
1400 .copyTtlOut()
1401 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1402 .setOutput(d3p10.port())
1403 .build()
1404 ));
1405
1406 sut.deactivate();
1407
1408 }
1409
1410 /**
1411 * We test the proper optimization of sp2mp with selector,
1412 * treatment, mpls encapsulation and co-located
1413 * different filtered ingress/egress points.
1414 */
1415 @Test
1416 public void testCoLocatedDifferentFilteredPointsNonTrivialForSp() {
1417
1418 intent = LinkCollectionIntent.builder()
1419 .appId(APP_ID)
1420 .selector(ipPrefixSelector)
1421 .treatment(ethDstTreatment)
1422 .applyTreatmentOnEgress(true)
1423 .links(linksForSp2MpCoLoc)
1424 .constraints(constraintsForMPLS)
1425 .filteredIngressPoints(ImmutableSet.of(
1426 new FilteredConnectPoint(d1p10, vlan100Selector)
1427 ))
1428 .filteredEgressPoints(ImmutableSet.of(
1429 new FilteredConnectPoint(d1p11, mpls100Selector),
1430 new FilteredConnectPoint(d2p10, vlan200Selector),
1431 new FilteredConnectPoint(d3p10, mpls200Selector)
1432 ))
1433 .build();
1434
1435 sut.activate();
1436
1437 /*
1438 * We use the FIRST_FIT to simplify tests.
1439 */
1440 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1441
1442 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1443 assertThat(compiled, hasSize(1));
1444
1445 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1446 assertThat(rules, hasSize(3));
1447
1448 Collection<FlowRule> rulesS1 = rules.stream()
1449 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1450 .collect(Collectors.toSet());
1451 assertThat(rulesS1, hasSize(1));
1452
1453 FlowRule ruleS1 = rulesS1.iterator().next();
1454 assertThat(ruleS1.selector(), is(
1455 DefaultTrafficSelector
1456 .builder(ipPrefixSelector)
1457 .matchInPort(d1p10.port())
1458 .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
1459 .build()
1460 ));
1461 assertThat(ruleS1.treatment(), is(
1462 DefaultTrafficTreatment
1463 .builder()
1464 .popVlan()
1465 .pushMpls()
1466 .copyTtlOut()
1467 .setMpls(MplsLabel.mplsLabel(LABEL))
1468 .setOutput(d1p0.port())
1469 .setEthDst(((ModEtherInstruction) ethDstTreatment
1470 .allInstructions()
1471 .stream()
1472 .filter(instruction -> instruction instanceof ModEtherInstruction)
1473 .findFirst().get()).mac())
1474 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1475 .setOutput(d1p11.port())
1476 .build()
1477 ));
1478
1479
1480 Collection<FlowRule> rulesS2 = rules.stream()
1481 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1482 .collect(Collectors.toSet());
1483 assertThat(rulesS2, hasSize(1));
1484
1485 FlowRule ruleS2 = rulesS2.iterator().next();
1486 assertThat(ruleS2.selector(), is(
1487 DefaultTrafficSelector
1488 .builder()
1489 .matchInPort(d2p0.port())
1490 .matchEthType(Ethernet.MPLS_UNICAST)
1491 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1492 .build()
1493 ));
1494 assertThat(ruleS2.treatment(), is(
1495 DefaultTrafficTreatment
1496 .builder()
1497 .setMpls(MplsLabel.mplsLabel(LABEL))
1498 .setOutput(d2p1.port())
1499 .setEthDst(((ModEtherInstruction) ethDstTreatment
1500 .allInstructions()
1501 .stream()
1502 .filter(instruction -> instruction instanceof ModEtherInstruction)
1503 .findFirst().get()).mac())
1504 .copyTtlIn()
1505 .popMpls(IPV4.ethType())
1506 .pushVlan()
1507 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1508 .setOutput(d2p10.port())
1509 .build()
1510 ));
1511
1512
1513 Collection<FlowRule> rulesS3 = rules.stream()
1514 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
1515 .collect(Collectors.toSet());
1516 assertThat(rulesS3, hasSize(1));
1517
1518 FlowRule ruleS3 = rulesS3.iterator().next();
1519 assertThat(ruleS3.selector(), is(
1520 DefaultTrafficSelector
1521 .builder()
1522 .matchEthType(Ethernet.MPLS_UNICAST)
1523 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1524 .matchInPort(d3p0.port())
1525 .build()
1526 ));
1527 assertThat(ruleS3.treatment(), is(
1528 DefaultTrafficTreatment
1529 .builder()
1530 .setEthDst(((ModEtherInstruction) ethDstTreatment
1531 .allInstructions()
1532 .stream()
1533 .filter(instruction -> instruction instanceof ModEtherInstruction)
1534 .findFirst().get()).mac())
1535 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1536 .setOutput(d3p10.port())
1537 .build()
1538 ));
1539
1540 sut.deactivate();
1541
1542 }
1543
Pier Ventre81c47bf2016-11-04 07:26:22 -07001544}