Pier
Committed by Gerrit Code Review

Fix PathCompiler in case of VLAN encapsulation

constraint and 1 hop.

Change-Id: Iea82fb4076c79bfa3770836459ffe5f25b5a79c1
...@@ -484,7 +484,7 @@ public class PathCompiler<T> { ...@@ -484,7 +484,7 @@ public class PathCompiler<T> {
484 .filter(constraint -> constraint instanceof EncapsulationConstraint) 484 .filter(constraint -> constraint instanceof EncapsulationConstraint)
485 .map(x -> (EncapsulationConstraint) x).findAny(); 485 .map(x -> (EncapsulationConstraint) x).findAny();
486 //if no encapsulation or is involved only a single switch use the default behaviour 486 //if no encapsulation or is involved only a single switch use the default behaviour
487 - if (!encapConstraint.isPresent() || links.size() == 1) { 487 + if (!encapConstraint.isPresent() || links.size() == 2) {
488 for (int i = 0; i < links.size() - 1; i++) { 488 for (int i = 0; i < links.size() - 1; i++) {
489 ConnectPoint ingress = links.get(i).dst(); 489 ConnectPoint ingress = links.get(i).dst();
490 ConnectPoint egress = links.get(i + 1).src(); 490 ConnectPoint egress = links.get(i + 1).src();
...@@ -492,6 +492,7 @@ public class PathCompiler<T> { ...@@ -492,6 +492,7 @@ public class PathCompiler<T> {
492 ingress, egress, intent.priority(), 492 ingress, egress, intent.priority(),
493 isLast(links, i), flows, devices); 493 isLast(links, i), flows, devices);
494 } 494 }
495 + return;
495 } 496 }
496 497
497 encapConstraint.map(EncapsulationConstraint::encapType) 498 encapConstraint.map(EncapsulationConstraint::encapType)
......
...@@ -67,6 +67,7 @@ import static org.junit.Assert.assertNotEquals; ...@@ -67,6 +67,7 @@ import static org.junit.Assert.assertNotEquals;
67 import static org.junit.Assert.assertTrue; 67 import static org.junit.Assert.assertTrue;
68 import static org.onosproject.net.DefaultEdgeLink.createEdgeLink; 68 import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
69 import static org.onosproject.net.Link.Type.DIRECT; 69 import static org.onosproject.net.Link.Type.DIRECT;
70 +import static org.onosproject.net.Link.Type.INDIRECT;
70 import static org.onosproject.net.NetTestTools.APP_ID; 71 import static org.onosproject.net.NetTestTools.APP_ID;
71 import static org.onosproject.net.NetTestTools.PID; 72 import static org.onosproject.net.NetTestTools.PID;
72 import static org.onosproject.net.NetTestTools.connectPoint; 73 import static org.onosproject.net.NetTestTools.connectPoint;
...@@ -93,6 +94,53 @@ public class PathIntentCompilerTest { ...@@ -93,6 +94,53 @@ public class PathIntentCompilerTest {
93 94
94 private final ApplicationId appId = new TestApplicationId("test"); 95 private final ApplicationId appId = new TestApplicationId("test");
95 private final ProviderId pid = new ProviderId("of", "test"); 96 private final ProviderId pid = new ProviderId("of", "test");
97 +
98 + // Edge scenario
99 + private final ConnectPoint d1p2 = connectPoint("s1", 2);
100 + private final ConnectPoint d1p3 = connectPoint("s1", 3);
101 + private final List<Link> edgeNet = Arrays.asList(
102 + createEdgeLink(d1p2, true),
103 + createEdgeLink(d1p3, false)
104 + );
105 + private final int edgeHops = edgeNet.size() - 1;
106 + private PathIntent edgeIntentNoVlan;
107 + private PathIntent edgeIntentIngressVlan;
108 + private PathIntent edgeIntentEgressVlan;
109 + private PathIntent edgeIntentVlan;
110 +
111 + // Single-hop scenario - indirect
112 + private final ConnectPoint d1p4 = connectPoint("s1", 4);
113 + private final ConnectPoint d2p2 = connectPoint("s2", 2);
114 + private final ConnectPoint d2p3 = connectPoint("s2", 3);
115 + private final ConnectPoint d3p2 = connectPoint("s3", 2);
116 + private final List<Link> singleHopIndirect = Arrays.asList(
117 + DefaultLink.builder().providerId(PID).src(d1p4).dst(d2p2).type(DIRECT).build(),
118 + DefaultLink.builder().providerId(PID).src(d2p3).dst(d3p2).type(INDIRECT).build()
119 + );
120 + private final int singleHopIndirectHops = singleHopIndirect.size() - 1;
121 + private PathIntent singleHopIndirectIntentNoVlan;
122 + private PathIntent singleHopIndirectIntentIngressVlan;
123 + private PathIntent singleHopIndirectIntentEgressVlan;
124 + private PathIntent singleHopIndirectIntentVlan;
125 +
126 +
127 + // Single-hop scenario- direct
128 + private final ConnectPoint d1p5 = connectPoint("s1", 5);
129 + private final ConnectPoint d2p4 = connectPoint("s2", 4);
130 + private final ConnectPoint d2p5 = connectPoint("s2", 5);
131 + private final ConnectPoint d3p3 = connectPoint("s3", 3);
132 + private final List<Link> singleHopDirect = Arrays.asList(
133 + DefaultLink.builder().providerId(PID).src(d1p5).dst(d2p4).type(DIRECT).build(),
134 + DefaultLink.builder().providerId(PID).src(d2p5).dst(d3p3).type(DIRECT).build()
135 + );
136 + private final int singleHopDirectHops = singleHopDirect.size() - 1;
137 + private PathIntent singleHopDirectIntentNoVlan;
138 + private PathIntent singleHopDirectIntentIngressVlan;
139 + private PathIntent singleHopDirectIntentEgressVlan;
140 + private PathIntent singleHopDirectIntentVlan;
141 +
142 +
143 + // Multi-hop scenario
96 private final ConnectPoint d1p1 = connectPoint("s1", 0); 144 private final ConnectPoint d1p1 = connectPoint("s1", 0);
97 private final ConnectPoint d2p0 = connectPoint("s2", 0); 145 private final ConnectPoint d2p0 = connectPoint("s2", 0);
98 private final ConnectPoint d2p1 = connectPoint("s2", 1); 146 private final ConnectPoint d2p1 = connectPoint("s2", 1);
...@@ -163,6 +211,115 @@ public class PathIntentCompilerTest { ...@@ -163,6 +211,115 @@ public class PathIntentCompilerTest {
163 .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.MPLS))) 211 .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.MPLS)))
164 .path(new DefaultPath(pid, links, hops)) 212 .path(new DefaultPath(pid, links, hops))
165 .build(); 213 .build();
214 +
215 + edgeIntentNoVlan = PathIntent.builder()
216 + .appId(APP_ID)
217 + .selector(selector)
218 + .treatment(treatment)
219 + .priority(PRIORITY)
220 + .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN)))
221 + .path(new DefaultPath(pid, edgeNet, edgeHops))
222 + .build();
223 +
224 + edgeIntentIngressVlan = PathIntent.builder()
225 + .appId(APP_ID)
226 + .selector(vlanSelector)
227 + .treatment(treatment)
228 + .priority(PRIORITY)
229 + .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN)))
230 + .path(new DefaultPath(pid, edgeNet, edgeHops))
231 + .build();
232 +
233 + edgeIntentEgressVlan = PathIntent.builder()
234 + .appId(APP_ID)
235 + .selector(selector)
236 + .treatment(vlanTreatment)
237 + .priority(PRIORITY)
238 + .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN)))
239 + .path(new DefaultPath(pid, edgeNet, edgeHops))
240 + .build();
241 +
242 + edgeIntentVlan = PathIntent.builder()
243 + .appId(APP_ID)
244 + .selector(vlanSelector)
245 + .treatment(vlanTreatment)
246 + .priority(PRIORITY)
247 + .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN)))
248 + .path(new DefaultPath(pid, edgeNet, edgeHops))
249 + .build();
250 +
251 + singleHopIndirectIntentNoVlan = PathIntent.builder()
252 + .appId(APP_ID)
253 + .selector(selector)
254 + .treatment(treatment)
255 + .priority(PRIORITY)
256 + .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN)))
257 + .path(new DefaultPath(pid, singleHopIndirect, singleHopIndirectHops))
258 + .build();
259 +
260 + singleHopIndirectIntentIngressVlan = PathIntent.builder()
261 + .appId(APP_ID)
262 + .selector(vlanSelector)
263 + .treatment(treatment)
264 + .priority(PRIORITY)
265 + .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN)))
266 + .path(new DefaultPath(pid, singleHopIndirect, singleHopIndirectHops))
267 + .build();
268 +
269 + singleHopIndirectIntentEgressVlan = PathIntent.builder()
270 + .appId(APP_ID)
271 + .selector(selector)
272 + .treatment(vlanTreatment)
273 + .priority(PRIORITY)
274 + .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN)))
275 + .path(new DefaultPath(pid, singleHopIndirect, singleHopIndirectHops))
276 + .build();
277 +
278 + singleHopIndirectIntentVlan = PathIntent.builder()
279 + .appId(APP_ID)
280 + .selector(vlanSelector)
281 + .treatment(vlanTreatment)
282 + .priority(PRIORITY)
283 + .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN)))
284 + .path(new DefaultPath(pid, singleHopIndirect, singleHopIndirectHops))
285 + .build();
286 +
287 + singleHopDirectIntentNoVlan = PathIntent.builder()
288 + .appId(APP_ID)
289 + .selector(selector)
290 + .treatment(treatment)
291 + .priority(PRIORITY)
292 + .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN)))
293 + .path(new DefaultPath(pid, singleHopDirect, singleHopDirectHops))
294 + .build();
295 +
296 + singleHopDirectIntentIngressVlan = PathIntent.builder()
297 + .appId(APP_ID)
298 + .selector(vlanSelector)
299 + .treatment(treatment)
300 + .priority(PRIORITY)
301 + .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN)))
302 + .path(new DefaultPath(pid, singleHopDirect, singleHopDirectHops))
303 + .build();
304 +
305 + singleHopDirectIntentEgressVlan = PathIntent.builder()
306 + .appId(APP_ID)
307 + .selector(selector)
308 + .treatment(vlanTreatment)
309 + .priority(PRIORITY)
310 + .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN)))
311 + .path(new DefaultPath(pid, singleHopDirect, singleHopDirectHops))
312 + .build();
313 +
314 + singleHopDirectIntentVlan = PathIntent.builder()
315 + .appId(APP_ID)
316 + .selector(vlanSelector)
317 + .treatment(vlanTreatment)
318 + .priority(PRIORITY)
319 + .constraints(ImmutableList.of(new EncapsulationConstraint(EncapsulationType.VLAN)))
320 + .path(new DefaultPath(pid, singleHopDirect, singleHopDirectHops))
321 + .build();
322 +
166 intentExtensionService = createMock(IntentExtensionService.class); 323 intentExtensionService = createMock(IntentExtensionService.class);
167 intentExtensionService.registerCompiler(PathIntent.class, sut); 324 intentExtensionService.registerCompiler(PathIntent.class, sut);
168 intentExtensionService.unregisterCompiler(PathIntent.class); 325 intentExtensionService.unregisterCompiler(PathIntent.class);
...@@ -185,6 +342,435 @@ public class PathIntentCompilerTest { ...@@ -185,6 +342,435 @@ public class PathIntentCompilerTest {
185 Intent.unbindIdGenerator(idGenerator); 342 Intent.unbindIdGenerator(idGenerator);
186 } 343 }
187 344
345 +
346 + /**
347 + * Tests the compilation behavior of the path intent compiler in case of
348 + * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
349 + * and edge communication. No ingress VLAN. No egress VLAN.
350 + */
351 + @Test
352 + public void testVlanEncapCompileEdgeNoVlan() {
353 + sut.activate();
354 +
355 + List<Intent> compiled = sut.compile(edgeIntentNoVlan, Collections.emptyList());
356 + assertThat(compiled, hasSize(1));
357 +
358 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
359 + assertThat(rules, hasSize(1));
360 +
361 + FlowRule rule = rules.stream()
362 + .filter(x -> x.deviceId().equals(d1p2.deviceId()))
363 + .findFirst()
364 + .get();
365 + verifyIdAndPriority(rule, d1p2.deviceId());
366 +
367 + assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d1p2.port())
368 + .build()));
369 + assertThat(rule.treatment(),
370 + is(DefaultTrafficTreatment.builder().setOutput(d1p3.port()).build()));
371 +
372 + sut.deactivate();
373 + }
374 +
375 + /**
376 + * Tests the compilation behavior of the path intent compiler in case of
377 + * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
378 + * and edge communication. Ingress VLAN. No egress VLAN.
379 + */
380 + @Test
381 + public void testVlanEncapCompileEdgeIngressVlan() {
382 + sut.activate();
383 +
384 + List<Intent> compiled = sut.compile(edgeIntentIngressVlan, Collections.emptyList());
385 + assertThat(compiled, hasSize(1));
386 +
387 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
388 + assertThat(rules, hasSize(1));
389 +
390 + FlowRule rule = rules.stream()
391 + .filter(x -> x.deviceId().equals(d1p2.deviceId()))
392 + .findFirst()
393 + .get();
394 + verifyIdAndPriority(rule, d1p2.deviceId());
395 +
396 + assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d1p2.port())
397 + .matchVlanId(ingressVlan).build()));
398 + assertThat(rule.treatment(),
399 + is(DefaultTrafficTreatment.builder().setOutput(d1p3.port()).build()));
400 +
401 + sut.deactivate();
402 + }
403 +
404 + /**
405 + * Tests the compilation behavior of the path intent compiler in case of
406 + * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
407 + * and edge communication. No ingress VLAN. Egress VLAN.
408 + */
409 + @Test
410 + public void testVlanEncapCompileEdgeEgressVlan() {
411 + sut.activate();
412 +
413 + List<Intent> compiled = sut.compile(edgeIntentEgressVlan, Collections.emptyList());
414 + assertThat(compiled, hasSize(1));
415 +
416 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
417 + assertThat(rules, hasSize(1));
418 +
419 + FlowRule rule = rules.stream()
420 + .filter(x -> x.deviceId().equals(d1p2.deviceId()))
421 + .findFirst()
422 + .get();
423 + verifyIdAndPriority(rule, d1p2.deviceId());
424 +
425 + assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d1p2.port())
426 + .build()));
427 + assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan)
428 + .setOutput(d1p3.port()).build()));
429 +
430 + Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream()
431 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction)
432 + .map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x)
433 + .collect(Collectors.toSet());
434 + assertThat(rule.treatment().allInstructions().stream()
435 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction)
436 + .collect(Collectors.toSet()), hasSize(1));
437 + assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
438 + assertThat(rule.treatment().allInstructions().stream()
439 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction)
440 + .collect(Collectors.toSet()), hasSize(0));
441 +
442 + sut.deactivate();
443 + }
444 +
445 + /**
446 + * Tests the compilation behavior of the path intent compiler in case of
447 + * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
448 + * and edge communication. Ingress VLAN. Egress VLAN.
449 + */
450 + @Test
451 + public void testVlanEncapCompileEdgeVlan() {
452 + sut.activate();
453 +
454 + List<Intent> compiled = sut.compile(edgeIntentVlan, Collections.emptyList());
455 + assertThat(compiled, hasSize(1));
456 +
457 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
458 + assertThat(rules, hasSize(1));
459 +
460 + FlowRule rule = rules.stream()
461 + .filter(x -> x.deviceId().equals(d1p2.deviceId()))
462 + .findFirst()
463 + .get();
464 + verifyIdAndPriority(rule, d1p2.deviceId());
465 +
466 + assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d1p2.port())
467 + .matchVlanId(ingressVlan).build()));
468 + assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan)
469 + .setOutput(d1p3.port()).build()));
470 +
471 + Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream()
472 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction)
473 + .map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x)
474 + .collect(Collectors.toSet());
475 + assertThat(rule.treatment().allInstructions().stream()
476 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction)
477 + .collect(Collectors.toSet()), hasSize(1));
478 + assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
479 + assertThat(rule.treatment().allInstructions().stream()
480 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction)
481 + .collect(Collectors.toSet()), hasSize(0));
482 +
483 + sut.deactivate();
484 + }
485 +
486 + /**
487 + * Tests the compilation behavior of the path intent compiler in case of
488 + * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
489 + * and single-hop-indirect-link scenario. No ingress VLAN. No egress VLAN.
490 + */
491 + @Test
492 + public void testVlanEncapCompileSingleHopIndirectNoVlan() {
493 + sut.activate();
494 +
495 + List<Intent> compiled = sut.compile(singleHopIndirectIntentNoVlan, Collections.emptyList());
496 + assertThat(compiled, hasSize(1));
497 +
498 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
499 + assertThat(rules, hasSize(1));
500 +
501 +
502 + FlowRule rule = rules.stream()
503 + .filter(x -> x.deviceId().equals(d2p2.deviceId()))
504 + .findFirst()
505 + .get();
506 + verifyIdAndPriority(rule, d2p2.deviceId());
507 +
508 + assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p2.port())
509 + .build()));
510 + assertThat(rule.treatment(),
511 + is(DefaultTrafficTreatment.builder().setOutput(d2p3.port()).build()));
512 +
513 + sut.deactivate();
514 + }
515 +
516 + /**
517 + * Tests the compilation behavior of the path intent compiler in case of
518 + * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
519 + * and single-hop-indirect-link scenario. Ingress VLAN. No egress VLAN.
520 + */
521 + @Test
522 + public void testVlanEncapCompileSingleHopIndirectIngressVlan() {
523 + sut.activate();
524 +
525 + List<Intent> compiled = sut.compile(singleHopIndirectIntentIngressVlan, Collections.emptyList());
526 + assertThat(compiled, hasSize(1));
527 +
528 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
529 + assertThat(rules, hasSize(1));
530 +
531 +
532 + FlowRule rule = rules.stream()
533 + .filter(x -> x.deviceId().equals(d2p2.deviceId()))
534 + .findFirst()
535 + .get();
536 + verifyIdAndPriority(rule, d2p2.deviceId());
537 +
538 + assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p2.port())
539 + .matchVlanId(ingressVlan).build()));
540 + assertThat(rule.treatment(),
541 + is(DefaultTrafficTreatment.builder().setOutput(d2p3.port()).build()));
542 +
543 + sut.deactivate();
544 + }
545 +
546 + /**
547 + * Tests the compilation behavior of the path intent compiler in case of
548 + * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
549 + * and single-hop-indirect-link scenario. No ingress VLAN. Egress VLAN.
550 + */
551 + @Test
552 + public void testVlanEncapCompileSingleHopIndirectEgressVlan() {
553 + sut.activate();
554 +
555 + List<Intent> compiled = sut.compile(singleHopIndirectIntentEgressVlan, Collections.emptyList());
556 + assertThat(compiled, hasSize(1));
557 +
558 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
559 + assertThat(rules, hasSize(1));
560 +
561 +
562 + FlowRule rule = rules.stream()
563 + .filter(x -> x.deviceId().equals(d2p2.deviceId()))
564 + .findFirst()
565 + .get();
566 + verifyIdAndPriority(rule, d2p2.deviceId());
567 +
568 + assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p2.port())
569 + .build()));
570 + assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan)
571 + .setOutput(d2p3.port()).build()));
572 +
573 + Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream()
574 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction)
575 + .map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x)
576 + .collect(Collectors.toSet());
577 + assertThat(rule.treatment().allInstructions().stream()
578 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction)
579 + .collect(Collectors.toSet()), hasSize(1));
580 + assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
581 + assertThat(rule.treatment().allInstructions().stream()
582 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction)
583 + .collect(Collectors.toSet()), hasSize(0));
584 +
585 + sut.deactivate();
586 + }
587 +
588 + /**
589 + * Tests the compilation behavior of the path intent compiler in case of
590 + * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
591 + * and single-hop-indirect-link scenario. Ingress VLAN. Egress VLAN.
592 + */
593 + @Test
594 + public void testVlanEncapCompileSingleHopIndirectVlan() {
595 + sut.activate();
596 +
597 + List<Intent> compiled = sut.compile(singleHopIndirectIntentVlan, Collections.emptyList());
598 + assertThat(compiled, hasSize(1));
599 +
600 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
601 + assertThat(rules, hasSize(1));
602 +
603 +
604 + FlowRule rule = rules.stream()
605 + .filter(x -> x.deviceId().equals(d2p2.deviceId()))
606 + .findFirst()
607 + .get();
608 + verifyIdAndPriority(rule, d2p2.deviceId());
609 +
610 + assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p2.port())
611 + .matchVlanId(ingressVlan).build()));
612 + assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan)
613 + .setOutput(d2p3.port()).build()));
614 +
615 + Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream()
616 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction)
617 + .map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x)
618 + .collect(Collectors.toSet());
619 + assertThat(rule.treatment().allInstructions().stream()
620 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction)
621 + .collect(Collectors.toSet()), hasSize(1));
622 + assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
623 + assertThat(rule.treatment().allInstructions().stream()
624 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction)
625 + .collect(Collectors.toSet()), hasSize(0));
626 +
627 + sut.deactivate();
628 + }
629 +
630 + /**
631 + * Tests the compilation behavior of the path intent compiler in case of
632 + * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
633 + * and single-hop-direct-link scenario. No ingress VLAN. No egress VLAN.
634 + */
635 + @Test
636 + public void testVlanEncapCompileSingleHopDirectNoVlan() {
637 + sut.activate();
638 +
639 + List<Intent> compiled = sut.compile(singleHopDirectIntentNoVlan, Collections.emptyList());
640 + assertThat(compiled, hasSize(1));
641 +
642 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
643 + assertThat(rules, hasSize(1));
644 +
645 +
646 + FlowRule rule = rules.stream()
647 + .filter(x -> x.deviceId().equals(d2p4.deviceId()))
648 + .findFirst()
649 + .get();
650 + verifyIdAndPriority(rule, d2p4.deviceId());
651 +
652 + assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p4.port())
653 + .build()));
654 + assertThat(rule.treatment(),
655 + is(DefaultTrafficTreatment.builder().setOutput(d2p5.port()).build()));
656 +
657 + sut.deactivate();
658 + }
659 +
660 + /**
661 + * Tests the compilation behavior of the path intent compiler in case of
662 + * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
663 + * and single-hop-direct-link scenario. Ingress VLAN. No egress VLAN.
664 + */
665 + @Test
666 + public void testVlanEncapCompileSingleHopDirectIngressVlan() {
667 + sut.activate();
668 +
669 + List<Intent> compiled = sut.compile(singleHopDirectIntentIngressVlan, Collections.emptyList());
670 + assertThat(compiled, hasSize(1));
671 +
672 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
673 + assertThat(rules, hasSize(1));
674 +
675 +
676 + FlowRule rule = rules.stream()
677 + .filter(x -> x.deviceId().equals(d2p4.deviceId()))
678 + .findFirst()
679 + .get();
680 + verifyIdAndPriority(rule, d2p4.deviceId());
681 +
682 + assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p4.port())
683 + .matchVlanId(ingressVlan).build()));
684 + assertThat(rule.treatment(),
685 + is(DefaultTrafficTreatment.builder().setOutput(d2p5.port()).build()));
686 +
687 + sut.deactivate();
688 + }
689 +
690 + /**
691 + * Tests the compilation behavior of the path intent compiler in case of
692 + * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
693 + * and single-hop-direct-link scenario. No ingress VLAN. Egress VLAN.
694 + */
695 + @Test
696 + public void testVlanEncapCompileSingleHopDirectEgressVlan() {
697 + sut.activate();
698 +
699 + List<Intent> compiled = sut.compile(singleHopDirectIntentEgressVlan, Collections.emptyList());
700 + assertThat(compiled, hasSize(1));
701 +
702 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
703 + assertThat(rules, hasSize(1));
704 +
705 +
706 + FlowRule rule = rules.stream()
707 + .filter(x -> x.deviceId().equals(d2p4.deviceId()))
708 + .findFirst()
709 + .get();
710 + verifyIdAndPriority(rule, d2p4.deviceId());
711 +
712 + assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p4.port())
713 + .build()));
714 + assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan)
715 + .setOutput(d2p5.port()).build()));
716 +
717 + Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream()
718 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction)
719 + .map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x)
720 + .collect(Collectors.toSet());
721 + assertThat(rule.treatment().allInstructions().stream()
722 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction)
723 + .collect(Collectors.toSet()), hasSize(1));
724 + assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
725 + assertThat(rule.treatment().allInstructions().stream()
726 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction)
727 + .collect(Collectors.toSet()), hasSize(0));
728 +
729 + sut.deactivate();
730 + }
731 +
732 + /**
733 + * Tests the compilation behavior of the path intent compiler in case of
734 + * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
735 + * and single-hop-direct-link scenario. Ingress VLAN. Egress VLAN.
736 + */
737 + @Test
738 + public void testVlanEncapCompileSingleHopDirectVlan() {
739 + sut.activate();
740 +
741 + List<Intent> compiled = sut.compile(singleHopDirectIntentVlan, Collections.emptyList());
742 + assertThat(compiled, hasSize(1));
743 +
744 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
745 + assertThat(rules, hasSize(1));
746 +
747 +
748 + FlowRule rule = rules.stream()
749 + .filter(x -> x.deviceId().equals(d2p4.deviceId()))
750 + .findFirst()
751 + .get();
752 + verifyIdAndPriority(rule, d2p4.deviceId());
753 +
754 + assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p4.port())
755 + .matchVlanId(ingressVlan).build()));
756 + assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan)
757 + .setOutput(d2p5.port()).build()));
758 +
759 + Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream()
760 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction)
761 + .map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x)
762 + .collect(Collectors.toSet());
763 + assertThat(rule.treatment().allInstructions().stream()
764 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction)
765 + .collect(Collectors.toSet()), hasSize(1));
766 + assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
767 + assertThat(rule.treatment().allInstructions().stream()
768 + .filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction)
769 + .collect(Collectors.toSet()), hasSize(0));
770 +
771 + sut.deactivate();
772 + }
773 +
188 /** 774 /**
189 * Tests the compilation behavior of the path intent compiler. 775 * Tests the compilation behavior of the path intent compiler.
190 */ 776 */
......