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