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