blob: 9d83e2c0a93958d85236f87e134e5d3009d27fca [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
Pier Ventre5c4a0762016-11-21 10:28:13 -080046import static org.easymock.EasyMock.*;
Pier Ventre766995d2016-10-05 22:15:56 -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;
Pier Ventre5c4a0762016-11-21 10:28:13 -080051import static org.onosproject.net.NetTestTools.APP_ID;
Pier Ventre766995d2016-10-05 22:15:56 -070052import static org.onosproject.net.flow.criteria.Criterion.Type.*;
53import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
54
55/**
56 * This set of tests are meant to test the encapsulation
57 * in the LinkCollectionIntent.
58 */
59public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectionTest {
60
61 @Before
62 public void setUp() {
63 sut = new LinkCollectionIntentCompiler();
64 coreService = createMock(CoreService.class);
Pier Ventre5c4a0762016-11-21 10:28:13 -080065 expect(coreService.registerApplication("org.onosproject.net.intent")).andReturn(appId);
Pier Ventre766995d2016-10-05 22:15:56 -070066 sut.coreService = coreService;
67
Thomas Vachuska23235962017-02-03 11:44:15 -080068 Intent.unbindIdGenerator(idGenerator);
Pier Ventre766995d2016-10-05 22:15:56 -070069 Intent.bindIdGenerator(idGenerator);
70
71 intentExtensionService = createMock(IntentExtensionService.class);
72 intentExtensionService.registerCompiler(LinkCollectionIntent.class, sut);
73 intentExtensionService.unregisterCompiler(LinkCollectionIntent.class);
74
75 registrator = new IntentConfigurableRegistrator();
76 registrator.extensionService = intentExtensionService;
77 registrator.cfgService = new ComponentConfigAdapter();
78 registrator.activate();
79
80 sut.registrator = registrator;
81 sut.resourceService = new MockResourceService();
82
Pier Ventre81c47bf2016-11-04 07:26:22 -070083 LinkCollectionCompiler.optimize = false;
84 LinkCollectionCompiler.copyTtl = false;
85
Pier Ventre766995d2016-10-05 22:15:56 -070086 replay(coreService, intentExtensionService);
87 }
88
89 @After
90 public void tearDown() {
91 Intent.unbindIdGenerator(idGenerator);
92 }
93
94 /**
95 * We test the proper compilation of mp2Sp1 with the VLAN
96 * encapsulation, trivial selector.
97 */
98 @Test
99 public void testVlanEncapsulationForMp() {
100
101 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800102 .appId(APP_ID).selector(selector).treatment(treatment)
103 .constraints(constraintsForVlan).links(linksForMp2Sp)
Pier Ventre766995d2016-10-05 22:15:56 -0700104 .filteredIngressPoints(ImmutableSet.of(
105 new FilteredConnectPoint(d1p10),
106 new FilteredConnectPoint(d1p11),
107 new FilteredConnectPoint(d2p10)
108 ))
109 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10)))
110 .build();
111
112 sut.activate();
113 /*
114 * We use the FIRST_FIT to simplify tests.
115 */
116 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
117
118 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
119 assertThat(compiled, hasSize(1));
120
121 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
122 assertThat(rules, hasSize(5));
123
124 Collection<FlowRule> rulesS1 = rules.stream()
125 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
126 .collect(Collectors.toSet());
127 assertThat(rulesS1, hasSize(2));
128 FlowRule ruleS1 = rulesS1.stream()
129 .filter(rule -> {
130 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
131 return inPort.port().equals(d1p10.port());
Pier Ventre5c4a0762016-11-21 10:28:13 -0800132 }).findFirst().get();
Pier Ventre766995d2016-10-05 22:15:56 -0700133 assertThat(ruleS1.selector(), is(
134 DefaultTrafficSelector
135 .builder(intent.selector())
136 .matchInPort(d1p10.port())
137 .build()
138 ));
139 assertThat(ruleS1.treatment(), is(
140 DefaultTrafficTreatment
141 .builder()
142 .pushVlan()
143 .setVlanId(VlanId.vlanId(LABEL))
144 .setOutput(d1p0.port())
145 .build()
146 ));
147
148 ruleS1 = rulesS1.stream()
149 .filter(rule -> {
150 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
151 return inPort.port().equals(d1p11.port());
152 })
153 .findFirst()
154 .get();
155 assertThat(ruleS1.selector(), is(
156 DefaultTrafficSelector
157 .builder(intent.selector())
158 .matchInPort(d1p11.port())
159 .build()
160 ));
161 assertThat(ruleS1.treatment(), is(
162 DefaultTrafficTreatment
163 .builder()
164 .pushVlan()
165 .setVlanId(VlanId.vlanId(LABEL))
166 .setOutput(d1p0.port())
167 .build()
168 ));
169
170 Collection<FlowRule> rulesS2 = rules.stream()
171 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
172 .collect(Collectors.toSet());
173 assertThat(rulesS2, hasSize(2));
174 FlowRule ruleS2 = rulesS2.stream()
175 .filter(rule -> {
176 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
177 return inPort.port().equals(d2p10.port());
178 })
179 .findFirst()
180 .get();
181 assertThat(ruleS2.selector(), is(
182 DefaultTrafficSelector
183 .builder(intent.selector())
184 .matchInPort(d2p10.port())
185 .build()
186 ));
187 assertThat(ruleS2.treatment(), is(
188 DefaultTrafficTreatment
189 .builder()
190 .pushVlan()
191 .setVlanId(VlanId.vlanId(LABEL))
192 .setOutput(d2p1.port())
193 .build()
194 ));
195
196 ruleS2 = rulesS2.stream()
197 .filter(rule -> {
198 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
199 return inPort.port().equals(d2p0.port());
200 })
201 .findFirst()
202 .get();
203 assertThat(ruleS2.selector(), is(
204 DefaultTrafficSelector
205 .builder()
206 .matchInPort(d2p0.port())
207 .matchVlanId(VlanId.vlanId(LABEL))
208 .build()
209 ));
210 assertThat(ruleS2.treatment(), is(
211 DefaultTrafficTreatment
212 .builder()
213 .setVlanId(VlanId.vlanId(LABEL))
214 .setOutput(d2p1.port())
215 .build()
216 ));
217
218 Collection<FlowRule> rulesS3 = rules.stream()
219 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
220 .collect(Collectors.toSet());
221 assertThat(rulesS3, hasSize(1));
222 FlowRule ruleS3 = rulesS3.iterator().next();
223 assertThat(ruleS3.selector(), is(
224 DefaultTrafficSelector
225 .builder()
226 .matchInPort(d3p0.port())
227 .matchVlanId(VlanId.vlanId(LABEL))
228 .build()
229 ));
230 assertThat(ruleS3.treatment(), is(
231 DefaultTrafficTreatment
232 .builder()
233 .popVlan()
234 .setOutput(d3p10.port())
235 .build()
236 ));
237
238 sut.deactivate();
239 }
240
241 /**
242 * We test the proper compilation of sp2mp with the MPLS
243 * encapsulation and trivial selector.
244 */
245 @Test
246 public void testMplsEncapsulationForSp() {
247
248 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800249 .appId(APP_ID).selector(selector).treatment(treatment)
250 .constraints(constraintsForMPLS).links(linksForSp2Mp)
Pier Ventre766995d2016-10-05 22:15:56 -0700251 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10)))
252 .filteredEgressPoints(ImmutableSet.of(
253 new FilteredConnectPoint(d1p10),
254 new FilteredConnectPoint(d1p11),
255 new FilteredConnectPoint(d2p10)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800256 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700257
258 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800259
Pier Ventre766995d2016-10-05 22:15:56 -0700260 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
261
262 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
263 assertThat(compiled, hasSize(1));
264
265 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
266 assertThat(rules, hasSize(3));
267
268 Collection<FlowRule> rulesS3 = rules.stream()
269 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
270 .collect(Collectors.toSet());
271 assertThat(rulesS3, hasSize(1));
272 FlowRule ruleS3 = rulesS3.iterator().next();
273 assertThat(ruleS3.selector(), is(
274 DefaultTrafficSelector
275 .builder()
276 .matchInPort(d3p10.port())
277 .build()
278 ));
279 assertThat(ruleS3.treatment(), is(
280 DefaultTrafficTreatment
281 .builder()
282 .pushMpls()
Pier Ventre81c47bf2016-11-04 07:26:22 -0700283 .setMpls(MplsLabel.mplsLabel(LABEL))
Pier Ventre766995d2016-10-05 22:15:56 -0700284 .setOutput(d3p0.port())
285 .build()
286 ));
287
288 Collection<FlowRule> rulesS2 = rules.stream()
289 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
290 .collect(Collectors.toSet());
291 assertThat(rulesS2, hasSize(1));
292 FlowRule ruleS2 = rulesS2.iterator().next();
293 assertThat(ruleS2.selector(), is(
294 DefaultTrafficSelector
295 .builder()
296 .matchInPort(d2p1.port())
297 .matchMplsLabel(MplsLabel.mplsLabel((LABEL)))
298 .matchEthType(Ethernet.MPLS_UNICAST)
299 .build()
300 ));
301 assertThat(ruleS2.treatment(), is(
302 DefaultTrafficTreatment
303 .builder()
304 .setMpls(MplsLabel.mplsLabel(LABEL))
305 .setOutput(d2p0.port())
306 .popMpls(IPV4.ethType())
307 .setOutput(d2p10.port())
308 .build()
309 ));
310
311 Collection<FlowRule> rulesS1 = rules.stream()
312 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
313 .collect(Collectors.toSet());
314 assertThat(rulesS1, hasSize(1));
315 FlowRule ruleS1 = rulesS1.iterator().next();
316 assertThat(ruleS1.selector(), is(
317 DefaultTrafficSelector
318 .builder()
319 .matchInPort(d1p0.port())
320 .matchMplsLabel(MplsLabel.mplsLabel((LABEL)))
321 .matchEthType(Ethernet.MPLS_UNICAST)
322 .build()
323 ));
324 assertThat(ruleS1.treatment(), is(
325 DefaultTrafficTreatment
326 .builder()
327 .popMpls(IPV4.ethType())
328 .setOutput(d1p10.port())
329 .popMpls(IPV4.ethType())
330 .setOutput(d1p11.port())
331 .build()
332 ));
333
334 sut.deactivate();
335
336 }
337
338 /**
339 * We test the proper compilation of mp2sp with the MPLS
340 * encapsulation and filtered selector.
341 */
342 @Test
343 public void testMplsEncapsulationFilteredForMp() {
344
345 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800346 .appId(APP_ID).selector(selector).treatment(treatment)
347 .constraints(constraintsForMPLS).links(linksForMp2Sp)
Pier Ventre766995d2016-10-05 22:15:56 -0700348 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan69Selector)))
349 .filteredIngressPoints(ImmutableSet.of(
350 new FilteredConnectPoint(d1p10, vlan100Selector),
351 new FilteredConnectPoint(d1p11, vlan200Selector),
352 new FilteredConnectPoint(d2p10, vlan300Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800353 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700354
355 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800356
Pier Ventre766995d2016-10-05 22:15:56 -0700357 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
358
359 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
360 assertThat(compiled, hasSize(1));
361
362 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
363 assertThat(rules, hasSize(5));
364
365 Collection<FlowRule> rulesS1 = rules.stream()
366 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
367 .collect(Collectors.toSet());
368 assertThat(rulesS1, hasSize(2));
369 FlowRule ruleS1 = rulesS1.stream()
370 .filter(rule -> {
371 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
372 return inPort.port().equals(d1p10.port());
373 })
374 .findFirst()
375 .get();
376 assertThat(ruleS1.selector(), is(
377 DefaultTrafficSelector
378 .builder(vlan100Selector)
379 .matchInPort(d1p10.port())
380 .build()
381 ));
382 assertThat(ruleS1.treatment(), is(
383 DefaultTrafficTreatment
384 .builder()
385 .popVlan()
386 .pushMpls()
387 .setMpls(MplsLabel.mplsLabel(LABEL))
388 .setOutput(d1p0.port())
389 .build()
390 ));
391
392 ruleS1 = rulesS1.stream()
393 .filter(rule -> {
394 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
395 return inPort.port().equals(d1p11.port());
396 })
397 .findFirst()
398 .get();
399 assertThat(ruleS1.selector(), is(
400 DefaultTrafficSelector
401 .builder(vlan200Selector)
402 .matchInPort(d1p11.port())
403 .build()
404 ));
405 assertThat(ruleS1.treatment(), is(
406 DefaultTrafficTreatment
407 .builder()
408 .popVlan()
409 .pushMpls()
410 .setMpls(MplsLabel.mplsLabel(LABEL))
411 .setOutput(d1p0.port())
412 .build()
413 ));
414
415 Collection<FlowRule> rulesS2 = rules.stream()
416 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
417 .collect(Collectors.toSet());
418 assertThat(rulesS2, hasSize(2));
419 FlowRule ruleS2 = rulesS2.stream()
420 .filter(rule -> {
421 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
422 return inPort.port().equals(d2p10.port());
423 })
424 .findFirst()
425 .get();
426 assertThat(ruleS2.selector(), is(
427 DefaultTrafficSelector
428 .builder(vlan300Selector)
429 .matchInPort(d2p10.port())
430 .build()
431 ));
432 assertThat(ruleS2.treatment(), is(
433 DefaultTrafficTreatment
434 .builder()
435 .popVlan()
436 .pushMpls()
437 .setMpls(MplsLabel.mplsLabel(LABEL))
438 .setOutput(d2p1.port())
439 .build()
440 ));
441
442 ruleS2 = rulesS2.stream()
443 .filter(rule -> {
444 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
445 return inPort.port().equals(d2p0.port());
446 })
447 .findFirst()
448 .get();
449 assertThat(ruleS2.selector(), is(
450 DefaultTrafficSelector
451 .builder()
452 .matchInPort(d2p0.port())
453 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
454 .matchEthType(Ethernet.MPLS_UNICAST)
455 .build()
456 ));
457 assertThat(ruleS2.treatment(), is(
458 DefaultTrafficTreatment
459 .builder()
460 .setMpls(MplsLabel.mplsLabel(LABEL))
461 .setOutput(d2p1.port())
462 .build()
463 ));
464
465 Collection<FlowRule> rulesS3 = rules.stream()
466 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
467 .collect(Collectors.toSet());
468 assertThat(rulesS3, hasSize(1));
469 FlowRule ruleS3 = rulesS3.iterator().next();
470 assertThat(ruleS3.selector(), is(
471 DefaultTrafficSelector
472 .builder()
473 .matchInPort(d3p0.port())
474 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
475 .matchEthType(Ethernet.MPLS_UNICAST)
476 .build()
477 ));
478 assertThat(ruleS3.treatment(), is(
479 DefaultTrafficTreatment
480 .builder()
481 .popMpls(IPV4.ethType())
482 .pushVlan()
483 .setVlanId(((VlanIdCriterion) vlan69Selector.getCriterion(VLAN_VID)).vlanId())
484 .setOutput(d3p10.port())
485 .build()
486 ));
487
488 sut.deactivate();
489
490 }
491
492 /**
493 * We test the proper compilation of sp2mp with the VLAN
494 * encapsulation and filtered selector.
495 */
496 @Test
497 public void testVlanEncapsulationFilteredForSp() {
498
499 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800500 .appId(APP_ID).selector(selector).treatment(treatment)
501 .constraints(constraintsForVlan).links(linksForSp2Mp)
Pier Ventre766995d2016-10-05 22:15:56 -0700502 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls69Selector)))
503 .filteredEgressPoints(ImmutableSet.of(
504 new FilteredConnectPoint(d1p10, mpls100Selector),
505 new FilteredConnectPoint(d1p11, mpls200Selector),
506 new FilteredConnectPoint(d2p10, mpls80Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800507 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700508
509 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800510
Pier Ventre766995d2016-10-05 22:15:56 -0700511 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
512
513 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
514 assertThat(compiled, hasSize(1));
515
516 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
517 assertThat(rules, hasSize(3));
518
519 Collection<FlowRule> rulesS3 = rules.stream()
520 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
521 .collect(Collectors.toSet());
522 assertThat(rulesS3, hasSize(1));
523 FlowRule ruleS3 = rulesS3.iterator().next();
524 assertThat(ruleS3.selector(), is(
525 DefaultTrafficSelector
526 .builder(mpls69Selector)
527 .matchInPort(d3p10.port())
528 .build()
529 ));
530 assertThat(ruleS3.treatment(), is(
531 DefaultTrafficTreatment
532 .builder()
533 .popMpls(IPV4.ethType())
534 .pushVlan()
535 .setVlanId(VlanId.vlanId(LABEL))
536 .setOutput(d3p0.port())
537 .build()
538 ));
539
540 Collection<FlowRule> rulesS2 = rules.stream()
541 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
542 .collect(Collectors.toSet());
543 assertThat(rulesS2, hasSize(1));
544 FlowRule ruleS2 = rulesS2.iterator().next();
545 assertThat(ruleS2.selector(), is(
546 DefaultTrafficSelector
547 .builder()
548 .matchInPort(d2p1.port())
549 .matchVlanId(VlanId.vlanId(LABEL))
550 .build()
551 ));
552 assertThat(ruleS2.treatment(), is(
553 DefaultTrafficTreatment
554 .builder()
555 .setVlanId(VlanId.vlanId(LABEL))
556 .setOutput(d2p0.port())
557 .popVlan()
558 .pushMpls()
559 .setMpls(((MplsCriterion) mpls80Selector.getCriterion(MPLS_LABEL)).label())
560 .setOutput(d2p10.port())
561 .build()
562 ));
563
564 Collection<FlowRule> rulesS1 = rules.stream()
565 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
566 .collect(Collectors.toSet());
567 assertThat(rulesS1, hasSize(1));
568 FlowRule ruleS1 = rulesS1.iterator().next();
569 assertThat(ruleS1.selector(), is(
570 DefaultTrafficSelector
571 .builder()
572 .matchInPort(d1p0.port())
573 .matchVlanId(VlanId.vlanId(LABEL))
574 .build()
575 ));
576 assertThat(ruleS1.treatment(), is(
577 DefaultTrafficTreatment
578 .builder()
579 .popVlan()
580 .pushMpls()
581 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
582 .setOutput(d1p10.port())
583 .popVlan()
584 .pushMpls()
585 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
586 .setOutput(d1p11.port())
587 .build()
588 ));
589
590 sut.deactivate();
591
592 }
593
594 /**
595 * We test the proper compilation of mp2sp with the VLAN
596 * encapsulation, filtered selectors, intent selector and intent treatment.
597 */
598 @Test
599 public void testVlanEncapsulationNonTrivialForMp() {
600
601 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800602 .appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment)
603 .constraints(constraintsForVlan).links(linksForMp2Sp)
Pier Ventre766995d2016-10-05 22:15:56 -0700604 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls69Selector)))
605 .filteredIngressPoints(ImmutableSet.of(
606 new FilteredConnectPoint(d1p10, mpls80Selector),
607 new FilteredConnectPoint(d1p11, mpls100Selector),
608 new FilteredConnectPoint(d2p10, mpls200Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800609 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700610
611 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800612
Pier Ventre766995d2016-10-05 22:15:56 -0700613 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
614
615 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
616 assertThat(compiled, hasSize(1));
617
618 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
619 assertThat(rules, hasSize(5));
620
621 Collection<FlowRule> rulesS1 = rules.stream()
622 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
623 .collect(Collectors.toSet());
624 assertThat(rulesS1, hasSize(2));
625 FlowRule ruleS1 = rulesS1.stream()
626 .filter(rule -> {
627 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
628 return inPort.port().equals(d1p10.port());
629 })
630 .findFirst()
631 .get();
632 assertThat(ruleS1.selector(), is(
633 DefaultTrafficSelector
634 .builder(ipPrefixSelector)
635 .matchInPort(d1p10.port())
636 .matchMplsLabel(((MplsCriterion) mpls80Selector.getCriterion(MPLS_LABEL)).label())
637 .build()
638 ));
639 assertThat(ruleS1.treatment(), is(
640 DefaultTrafficTreatment
641 .builder()
642 .popMpls(IPV4.ethType())
643 .pushVlan()
644 .setVlanId(VlanId.vlanId(LABEL))
645 .setOutput(d1p0.port())
646 .build()
647 ));
648
649 ruleS1 = rulesS1.stream()
650 .filter(rule -> {
651 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
652 return inPort.port().equals(d1p11.port());
653 })
654 .findFirst()
655 .get();
656 assertThat(ruleS1.selector(), is(
657 DefaultTrafficSelector
658 .builder(ipPrefixSelector)
659 .matchInPort(d1p11.port())
660 .matchMplsLabel(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
661 .build()
662 ));
663 assertThat(ruleS1.treatment(), is(
664 DefaultTrafficTreatment
665 .builder()
666 .popMpls(IPV4.ethType())
667 .pushVlan()
668 .setVlanId(VlanId.vlanId(LABEL))
669 .setOutput(d1p0.port())
670 .build()
671 ));
672
673 Collection<FlowRule> rulesS2 = rules.stream()
674 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
675 .collect(Collectors.toSet());
676 assertThat(rulesS2, hasSize(2));
677 FlowRule ruleS2 = rulesS2.stream()
678 .filter(rule -> {
679 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
680 return inPort.port().equals(d2p10.port());
681 })
682 .findFirst()
683 .get();
684 assertThat(ruleS2.selector(), is(
685 DefaultTrafficSelector
686 .builder(ipPrefixSelector)
687 .matchInPort(d2p10.port())
688 .matchMplsLabel(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
689 .build()
690 ));
691 assertThat(ruleS2.treatment(), is(
692 DefaultTrafficTreatment
693 .builder()
694 .popMpls(IPV4.ethType())
695 .pushVlan()
696 .setVlanId(VlanId.vlanId(LABEL))
697 .setOutput(d2p1.port())
698 .build()
699 ));
700
701 ruleS2 = rulesS2.stream()
702 .filter(rule -> {
703 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
704 return inPort.port().equals(d2p0.port());
705 })
706 .findFirst()
707 .get();
708 assertThat(ruleS2.selector(), is(
709 DefaultTrafficSelector
710 .builder()
711 .matchInPort(d2p0.port())
712 .matchVlanId(VlanId.vlanId(LABEL))
713 .build()
714 ));
715 assertThat(ruleS2.treatment(), is(
716 DefaultTrafficTreatment
717 .builder()
718 .setVlanId(VlanId.vlanId(LABEL))
719 .setOutput(d2p1.port())
720 .build()
721 ));
722
723 Collection<FlowRule> rulesS3 = rules.stream()
724 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
725 .collect(Collectors.toSet());
726 assertThat(rulesS3, hasSize(1));
727 FlowRule ruleS3 = rulesS3.iterator().next();
728 assertThat(ruleS3.selector(), is(
729 DefaultTrafficSelector
730 .builder()
731 .matchInPort(d3p0.port())
732 .matchVlanId(VlanId.vlanId(LABEL))
733 .build()
734 ));
735 assertThat(ruleS3.treatment(), is(
736 DefaultTrafficTreatment
737 .builder(ethDstTreatment)
738 .popVlan()
739 .pushMpls()
740 .setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label())
741 .setOutput(d3p10.port())
742 .build()
743 ));
744
745 sut.deactivate();
746
747 }
748
749 /**
750 * We test the proper compilation of sp2mp with the MPLS
751 * encapsulation, filtered selector, intent selector, and
752 * intent treatment.
753 */
754 @Test
755 public void testMplsEncapsulationNonTrivialForSp() {
756
757 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800758 .appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment)
759 .constraints(constraintsForMPLS).links(linksForSp2Mp)
Pier Ventre766995d2016-10-05 22:15:56 -0700760 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan69Selector)))
761 .filteredEgressPoints(ImmutableSet.of(
762 new FilteredConnectPoint(d1p10, vlan100Selector),
763 new FilteredConnectPoint(d1p11, vlan200Selector),
764 new FilteredConnectPoint(d2p10, vlan300Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800765 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700766
767 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800768
Pier Ventre766995d2016-10-05 22:15:56 -0700769 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
770
771 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
772 assertThat(compiled, hasSize(1));
773
774 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
775 assertThat(rules, hasSize(3));
776
777 Collection<FlowRule> rulesS3 = rules.stream()
778 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
779 .collect(Collectors.toSet());
780 assertThat(rulesS3, hasSize(1));
781 FlowRule ruleS3 = rulesS3.iterator().next();
782 assertThat(ruleS3.selector(), is(
783 DefaultTrafficSelector
784 .builder(ipPrefixSelector)
785 .matchInPort(d3p10.port())
786 .matchVlanId(((VlanIdCriterion) vlan69Selector.getCriterion(VLAN_VID)).vlanId())
787 .build()
788 ));
789 assertThat(ruleS3.treatment(), is(
790 DefaultTrafficTreatment
791 .builder()
792 .popVlan()
793 .pushMpls()
794 .setMpls(MplsLabel.mplsLabel(LABEL))
795 .setOutput(d3p0.port())
796 .build()
797 ));
798
799 Collection<FlowRule> rulesS2 = rules.stream()
800 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
801 .collect(Collectors.toSet());
802 assertThat(rulesS2, hasSize(1));
803 FlowRule ruleS2 = rulesS2.iterator().next();
804 assertThat(ruleS2.selector(), is(
805 DefaultTrafficSelector
806 .builder()
807 .matchInPort(d2p1.port())
808 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
809 .matchEthType(Ethernet.MPLS_UNICAST)
810 .build()
811 ));
812 assertThat(ruleS2.treatment(), is(
813 DefaultTrafficTreatment
814 .builder()
815 .setMpls(MplsLabel.mplsLabel(LABEL))
816 .setOutput(d2p0.port())
817 .setEthDst(((ModEtherInstruction) ethDstTreatment
818 .allInstructions()
819 .stream()
820 .filter(instruction -> instruction instanceof ModEtherInstruction)
821 .findFirst().get()).mac())
822 .popMpls(IPV4.ethType())
823 .pushVlan()
824 .setVlanId(((VlanIdCriterion) vlan300Selector.getCriterion(VLAN_VID)).vlanId())
825 .setOutput(d2p10.port())
826 .build()
827 ));
828
829 Collection<FlowRule> rulesS1 = rules.stream()
830 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
831 .collect(Collectors.toSet());
832 assertThat(rulesS1, hasSize(1));
833 FlowRule ruleS1 = rulesS1.iterator().next();
834 assertThat(ruleS1.selector(), is(
835 DefaultTrafficSelector
836 .builder()
837 .matchInPort(d1p0.port())
838 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
839 .matchEthType(Ethernet.MPLS_UNICAST)
840 .build()
841 ));
842 assertThat(ruleS1.treatment(), is(
843 DefaultTrafficTreatment
844 .builder()
845 .setEthDst(((ModEtherInstruction) ethDstTreatment
846 .allInstructions()
847 .stream()
848 .filter(instruction -> instruction instanceof ModEtherInstruction)
849 .findFirst().get()).mac())
850 .popMpls(IPV4.ethType())
851 .pushVlan()
852 .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
853 .setOutput(d1p10.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) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
862 .setOutput(d1p11.port())
863 .build()
864 ));
865
866 sut.deactivate();
867
868 }
869
870 /**
871 * We test the proper compilation of mp2sp with the MPLS
872 * encapsulation and filtered selectors of different type.
873 */
874 @Test
875 public void testMplsEncapsulationDifferentFilterForMp() {
876
877 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800878 .appId(APP_ID).selector(selector).treatment(treatment)
879 .constraints(constraintsForMPLS).links(linksForMp2Sp)
Pier Ventre766995d2016-10-05 22:15:56 -0700880 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls100Selector)))
881 .filteredIngressPoints(ImmutableSet.of(
882 new FilteredConnectPoint(d1p10, vlan100Selector),
883 new FilteredConnectPoint(d1p11, mpls200Selector),
884 new FilteredConnectPoint(d2p10, vlan200Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800885 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700886
887 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800888
Pier Ventre766995d2016-10-05 22:15:56 -0700889 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
890
891 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
892 assertThat(compiled, hasSize(1));
893
894 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
895 assertThat(rules, hasSize(5));
896
897 Collection<FlowRule> rulesS1 = rules.stream()
898 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
899 .collect(Collectors.toSet());
900 assertThat(rulesS1, hasSize(2));
901 FlowRule ruleS1 = rulesS1.stream()
902 .filter(rule -> {
903 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
904 return inPort.port().equals(d1p10.port());
905 })
906 .findFirst()
907 .get();
908 assertThat(ruleS1.selector(), is(
909 DefaultTrafficSelector
910 .builder(vlan100Selector)
911 .matchInPort(d1p10.port())
912 .build()
913 ));
914 assertThat(ruleS1.treatment(), is(
915 DefaultTrafficTreatment
916 .builder()
917 .popVlan()
918 .pushMpls()
919 .setMpls(MplsLabel.mplsLabel(LABEL))
920 .setOutput(d1p0.port())
921 .build()
922 ));
923
924 ruleS1 = rulesS1.stream()
925 .filter(rule -> {
926 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
927 return inPort.port().equals(d1p11.port());
928 })
929 .findFirst()
930 .get();
931 assertThat(ruleS1.selector(), is(
932 DefaultTrafficSelector
933 .builder(mpls200Selector)
934 .matchInPort(d1p11.port())
935 .build()
936 ));
937 assertThat(ruleS1.treatment(), is(
938 DefaultTrafficTreatment
939 .builder()
940 .setMpls(MplsLabel.mplsLabel(LABEL))
941 .setOutput(d1p0.port())
942 .build()
943 ));
944
945 Collection<FlowRule> rulesS2 = rules.stream()
946 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
947 .collect(Collectors.toSet());
948 assertThat(rulesS2, hasSize(2));
949 FlowRule ruleS2 = rulesS2.stream()
950 .filter(rule -> {
951 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
952 return inPort.port().equals(d2p10.port());
953 })
954 .findFirst()
955 .get();
956 assertThat(ruleS2.selector(), is(
957 DefaultTrafficSelector
958 .builder(vlan200Selector)
959 .matchInPort(d2p10.port())
960 .build()
961 ));
962 assertThat(ruleS2.treatment(), is(
963 DefaultTrafficTreatment
964 .builder()
965 .popVlan()
966 .pushMpls()
967 .setMpls(MplsLabel.mplsLabel(LABEL))
968 .setOutput(d2p1.port())
969 .build()
970 ));
971
972 ruleS2 = rulesS2.stream()
973 .filter(rule -> {
974 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
975 return inPort.port().equals(d2p0.port());
976 })
977 .findFirst()
978 .get();
979 assertThat(ruleS2.selector(), is(
980 DefaultTrafficSelector
981 .builder()
982 .matchInPort(d2p0.port())
983 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
984 .matchEthType(Ethernet.MPLS_UNICAST)
985 .build()
986 ));
987 assertThat(ruleS2.treatment(), is(
988 DefaultTrafficTreatment
989 .builder()
990 .setMpls(MplsLabel.mplsLabel(LABEL))
991 .setOutput(d2p1.port())
992 .build()
993 ));
994
995 Collection<FlowRule> rulesS3 = rules.stream()
996 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
997 .collect(Collectors.toSet());
998 assertThat(rulesS3, hasSize(1));
999 FlowRule ruleS3 = rulesS3.iterator().next();
1000 assertThat(ruleS3.selector(), is(
1001 DefaultTrafficSelector
1002 .builder()
1003 .matchInPort(d3p0.port())
1004 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1005 .matchEthType(Ethernet.MPLS_UNICAST)
1006 .build()
1007 ));
1008 assertThat(ruleS3.treatment(), is(
1009 DefaultTrafficTreatment
1010 .builder()
1011 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1012 .setOutput(d3p10.port())
1013 .build()
1014 ));
1015
1016 sut.deactivate();
1017
1018 }
1019
1020 /**
1021 * We test the proper compilation of sp2mp with the VLAN
1022 * encapsulation and filtered selectors of different type.
1023 */
1024 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001025 public void testVlanEncapsulationDifferentFilterForSp() {
Pier Ventre766995d2016-10-05 22:15:56 -07001026
1027 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001028 .appId(APP_ID).selector(selector).treatment(treatment)
1029 .constraints(constraintsForVlan).links(linksForSp2Mp)
Pier Ventre766995d2016-10-05 22:15:56 -07001030 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan200Selector)))
1031 .filteredEgressPoints(ImmutableSet.of(
1032 new FilteredConnectPoint(d1p10, mpls100Selector),
1033 new FilteredConnectPoint(d1p11, vlan100Selector),
1034 new FilteredConnectPoint(d2p10, mpls200Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001035 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -07001036
1037 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001038
Pier Ventre766995d2016-10-05 22:15:56 -07001039 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1040
1041 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1042 assertThat(compiled, hasSize(1));
1043
1044 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1045 assertThat(rules, hasSize(3));
1046
1047 Collection<FlowRule> rulesS3 = rules.stream()
1048 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
1049 .collect(Collectors.toSet());
1050 assertThat(rulesS3, hasSize(1));
1051 FlowRule ruleS3 = rulesS3.iterator().next();
1052 assertThat(ruleS3.selector(), is(
1053 DefaultTrafficSelector
1054 .builder(vlan200Selector)
1055 .matchInPort(d3p10.port())
1056 .build()
1057 ));
1058 assertThat(ruleS3.treatment(), is(
1059 DefaultTrafficTreatment
1060 .builder()
1061 .setVlanId(VlanId.vlanId(LABEL))
1062 .setOutput(d3p0.port())
1063 .build()
1064 ));
1065
1066 Collection<FlowRule> rulesS2 = rules.stream()
1067 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1068 .collect(Collectors.toSet());
1069 assertThat(rulesS2, hasSize(1));
1070 FlowRule ruleS2 = rulesS2.iterator().next();
1071 assertThat(ruleS2.selector(), is(
1072 DefaultTrafficSelector
1073 .builder()
1074 .matchInPort(d2p1.port())
1075 .matchVlanId(VlanId.vlanId(LABEL))
1076 .build()
1077 ));
1078 assertThat(ruleS2.treatment(), is(
1079 DefaultTrafficTreatment
1080 .builder()
1081 .setVlanId(VlanId.vlanId(LABEL))
1082 .setOutput(d2p0.port())
1083 .popVlan()
1084 .pushMpls()
1085 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1086 .setOutput(d2p10.port())
1087 .build()
1088 ));
1089
1090 Collection<FlowRule> rulesS1 = rules.stream()
1091 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1092 .collect(Collectors.toSet());
1093 assertThat(rulesS1, hasSize(1));
1094 FlowRule ruleS1 = rulesS1.iterator().next();
1095 assertThat(ruleS1.selector(), is(
1096 DefaultTrafficSelector
1097 .builder()
1098 .matchInPort(d1p0.port())
1099 .matchVlanId(VlanId.vlanId(LABEL))
1100 .build()
1101 ));
1102 assertThat(ruleS1.treatment(), is(
1103 DefaultTrafficTreatment
1104 .builder()
1105 .popVlan()
1106 .pushMpls()
1107 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1108 .setOutput(d1p10.port())
1109 .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
1110 .setOutput(d1p11.port())
1111 .build()
1112 ));
1113
1114 sut.deactivate();
1115
1116 }
1117
1118 /**
Pier Ventre5c4a0762016-11-21 10:28:13 -08001119 * We test the proper compilation of sp2mp with trivial selector,
1120 * trivial treatment, vlan encapsulation and co-located
1121 * ingress/egress points.
Pier Ventre766995d2016-10-05 22:15:56 -07001122 */
1123 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001124 public void testCoLocatedPointsTrivialForSp() {
Pier Ventre766995d2016-10-05 22:15:56 -07001125
1126 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001127 .appId(APP_ID).selector(selector).treatment(treatment)
1128 .applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc)
Pier Ventre766995d2016-10-05 22:15:56 -07001129 .constraints(constraintsForVlan)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001130 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10)))
1131 .filteredEgressPoints(ImmutableSet.of(
1132 new FilteredConnectPoint(d1p11),
1133 new FilteredConnectPoint(d2p10),
1134 new FilteredConnectPoint(d3p10)
1135 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -07001136
1137 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001138
Pier Ventre766995d2016-10-05 22:15:56 -07001139 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1140
1141 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1142 assertThat(compiled, hasSize(1));
1143
1144 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1145 assertThat(rules, hasSize(3));
1146
1147 Collection<FlowRule> rulesS1 = rules.stream()
1148 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1149 .collect(Collectors.toSet());
1150 assertThat(rulesS1, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001151
Pier Ventre766995d2016-10-05 22:15:56 -07001152 FlowRule ruleS1 = rulesS1.iterator().next();
1153 assertThat(ruleS1.selector(), is(
1154 DefaultTrafficSelector
Pier Ventre5c4a0762016-11-21 10:28:13 -08001155 .builder(selector)
Pier Ventre766995d2016-10-05 22:15:56 -07001156 .matchInPort(d1p10.port())
1157 .build()
1158 ));
1159 assertThat(ruleS1.treatment(), is(
1160 DefaultTrafficTreatment
1161 .builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001162 .pushVlan()
Pier Ventre766995d2016-10-05 22:15:56 -07001163 .setVlanId(VlanId.vlanId(LABEL))
1164 .setOutput(d1p0.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001165 .setOutput(d1p11.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001166 .build()
1167 ));
1168
1169 Collection<FlowRule> rulesS2 = rules.stream()
1170 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1171 .collect(Collectors.toSet());
1172 assertThat(rulesS2, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001173
Pier Ventre766995d2016-10-05 22:15:56 -07001174 FlowRule ruleS2 = rulesS2.iterator().next();
1175 assertThat(ruleS2.selector(), is(
1176 DefaultTrafficSelector
1177 .builder()
1178 .matchInPort(d2p0.port())
1179 .matchVlanId(VlanId.vlanId(LABEL))
1180 .build()
1181 ));
1182 assertThat(ruleS2.treatment(), is(
1183 DefaultTrafficTreatment
1184 .builder()
1185 .setVlanId(VlanId.vlanId(LABEL))
1186 .setOutput(d2p1.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001187 .popVlan()
1188 .setOutput(d2p10.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001189 .build()
1190 ));
1191
1192 Collection<FlowRule> rulesS3 = rules.stream()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001193 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
Pier Ventre766995d2016-10-05 22:15:56 -07001194 .collect(Collectors.toSet());
1195 assertThat(rulesS3, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001196
Pier Ventre766995d2016-10-05 22:15:56 -07001197 FlowRule ruleS3 = rulesS3.iterator().next();
1198 assertThat(ruleS3.selector(), is(
1199 DefaultTrafficSelector
1200 .builder()
1201 .matchInPort(d3p0.port())
1202 .matchVlanId(VlanId.vlanId(LABEL))
1203 .build()
1204 ));
1205 assertThat(ruleS3.treatment(), is(
1206 DefaultTrafficTreatment
1207 .builder()
1208 .popVlan()
Pier Ventre766995d2016-10-05 22:15:56 -07001209 .setOutput(d3p10.port())
1210 .build()
1211 ));
1212
1213 sut.deactivate();
1214
1215 }
1216
1217 /**
Pier Ventre5c4a0762016-11-21 10:28:13 -08001218 * We test the proper compilation of mp2sp with trivial selector,
1219 * trivial treatment, mpls encapsulation and co-located
1220 * ingress/egress points.
Pier Ventre766995d2016-10-05 22:15:56 -07001221 */
1222 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001223 public void testCoLocatedPointsTrivialForMp() {
Pier Ventre766995d2016-10-05 22:15:56 -07001224
1225 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001226 .appId(APP_ID).selector(selector).treatment(treatment)
1227 .links(linksForMp2SpCoLoc).constraints(constraintsForMPLS)
1228 .filteredIngressPoints(ImmutableSet.of(
1229 new FilteredConnectPoint(d1p10),
1230 new FilteredConnectPoint(d2p10)
1231 ))
1232 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11)))
1233 .build();
1234
1235 sut.activate();
1236
1237 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1238
1239 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1240 assertThat(compiled, hasSize(1));
1241
1242 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1243 assertThat(rules, hasSize(3));
1244
1245 Collection<FlowRule> rulesS1 = rules.stream()
1246 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1247 .collect(Collectors.toSet());
1248 assertThat(rulesS1, hasSize(2));
1249
1250 FlowRule ruleS1 = rulesS1.stream()
1251 .filter(rule -> {
1252 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1253 return inPort.port().equals(d1p10.port());
1254 })
1255 .findFirst()
1256 .get();
1257 assertThat(ruleS1.selector(), is(
1258 DefaultTrafficSelector
1259 .builder()
1260 .matchInPort(d1p10.port())
1261 .build()
1262 ));
1263 assertThat(ruleS1.treatment(), is(
1264 DefaultTrafficTreatment
1265 .builder()
1266 .setOutput(d1p11.port())
1267 .build()
1268 ));
1269
1270 ruleS1 = rulesS1.stream()
1271 .filter(rule -> {
1272 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1273 return inPort.port().equals(d1p0.port());
1274 })
1275 .findFirst()
1276 .get();
1277 assertThat(ruleS1.selector(), is(
1278 DefaultTrafficSelector
1279 .builder()
1280 .matchEthType(Ethernet.MPLS_UNICAST)
1281 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1282 .matchInPort(d1p0.port())
1283 .build()
1284 ));
1285 assertThat(ruleS1.treatment(), is(
1286 DefaultTrafficTreatment
1287 .builder()
1288 .popMpls(IPV4.ethType())
1289 .setOutput(d1p11.port())
1290 .build()
1291 ));
1292
1293 Collection<FlowRule> rulesS2 = rules.stream()
1294 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1295 .collect(Collectors.toSet());
1296 assertThat(rulesS2, hasSize(1));
1297
1298 FlowRule ruleS2 = rulesS2.iterator().next();
1299 assertThat(ruleS2.selector(), is(
1300 DefaultTrafficSelector
1301 .builder()
1302 .matchInPort(d2p10.port())
1303 .build()
1304 ));
1305 assertThat(ruleS2.treatment(), is(
1306 DefaultTrafficTreatment
1307 .builder()
1308 .pushMpls()
1309 .setMpls(MplsLabel.mplsLabel(LABEL))
1310 .setOutput(d2p0.port())
1311 .build()
1312 ));
1313
1314 sut.deactivate();
1315
1316 }
1317
1318 /**
1319 * We test the proper compilation of sp2mp with trivial selector,
1320 * trivial treatment, mpls encapsulation and co-located
1321 * filtered ingress/egress points.
1322 */
1323 @Test
1324 public void testCoLocatedFilteredPointsTrivialForSp() {
1325
1326 intent = LinkCollectionIntent.builder()
1327 .appId(APP_ID).selector(selector).treatment(treatment)
1328 .applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc)
Pier Ventre766995d2016-10-05 22:15:56 -07001329 .constraints(constraintsForMPLS)
Pier Ventre766995d2016-10-05 22:15:56 -07001330 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector)))
Pier Ventre5c4a0762016-11-21 10:28:13 -08001331 .filteredEgressPoints(ImmutableSet.of(
1332 new FilteredConnectPoint(d1p11, vlan200Selector),
1333 new FilteredConnectPoint(d2p10, vlan300Selector),
1334 new FilteredConnectPoint(d3p10, vlan69Selector)
1335 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -07001336
1337 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001338
Pier Ventre766995d2016-10-05 22:15:56 -07001339 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1340
1341 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1342 assertThat(compiled, hasSize(1));
1343
1344 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1345 assertThat(rules, hasSize(3));
1346
1347 Collection<FlowRule> rulesS1 = rules.stream()
1348 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1349 .collect(Collectors.toSet());
1350 assertThat(rulesS1, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001351
Pier Ventre766995d2016-10-05 22:15:56 -07001352 FlowRule ruleS1 = rulesS1.iterator().next();
1353 assertThat(ruleS1.selector(), is(
1354 DefaultTrafficSelector
1355 .builder(vlan100Selector)
1356 .matchInPort(d1p10.port())
1357 .build()
1358 ));
1359 assertThat(ruleS1.treatment(), is(
1360 DefaultTrafficTreatment
1361 .builder()
1362 .popVlan()
1363 .pushMpls()
1364 .setMpls(MplsLabel.mplsLabel(LABEL))
1365 .setOutput(d1p0.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001366 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1367 .setOutput(d1p11.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001368 .build()
1369 ));
1370
Pier Ventre5c4a0762016-11-21 10:28:13 -08001371
Pier Ventre766995d2016-10-05 22:15:56 -07001372 Collection<FlowRule> rulesS2 = rules.stream()
1373 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1374 .collect(Collectors.toSet());
1375 assertThat(rulesS2, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001376
Pier Ventre766995d2016-10-05 22:15:56 -07001377 FlowRule ruleS2 = rulesS2.iterator().next();
1378 assertThat(ruleS2.selector(), is(
1379 DefaultTrafficSelector
1380 .builder()
1381 .matchInPort(d2p0.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001382 .matchEthType(Ethernet.MPLS_UNICAST)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001383 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
Pier Ventre766995d2016-10-05 22:15:56 -07001384 .build()
1385 ));
1386 assertThat(ruleS2.treatment(), is(
1387 DefaultTrafficTreatment
1388 .builder()
1389 .setMpls(MplsLabel.mplsLabel(LABEL))
1390 .setOutput(d2p1.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001391 .popMpls(IPV4.ethType())
1392 .pushVlan()
1393 .setVlanId(((VlanIdCriterion) vlan300Selector.getCriterion(VLAN_VID)).vlanId())
1394 .setOutput(d2p10.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001395 .build()
1396 ));
1397
Pier Ventre5c4a0762016-11-21 10:28:13 -08001398
Pier Ventre766995d2016-10-05 22:15:56 -07001399 Collection<FlowRule> rulesS3 = rules.stream()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001400 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
Pier Ventre766995d2016-10-05 22:15:56 -07001401 .collect(Collectors.toSet());
1402 assertThat(rulesS3, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001403
Pier Ventre766995d2016-10-05 22:15:56 -07001404 FlowRule ruleS3 = rulesS3.iterator().next();
1405 assertThat(ruleS3.selector(), is(
1406 DefaultTrafficSelector
1407 .builder()
1408 .matchInPort(d3p0.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001409 .matchEthType(Ethernet.MPLS_UNICAST)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001410 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
Pier Ventre766995d2016-10-05 22:15:56 -07001411 .build()
1412 ));
1413 assertThat(ruleS3.treatment(), is(
1414 DefaultTrafficTreatment
1415 .builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001416 .popMpls(IPV4.ethType())
1417 .pushVlan()
1418 .setVlanId(((VlanIdCriterion) vlan69Selector.getCriterion(VLAN_VID)).vlanId())
Pier Ventre766995d2016-10-05 22:15:56 -07001419 .setOutput(d3p10.port())
1420 .build()
1421 ));
1422
1423 sut.deactivate();
1424
1425 }
1426
Pier Ventreffe88d62016-10-13 14:34:40 -07001427 /**
Pier Ventre5c4a0762016-11-21 10:28:13 -08001428 * We test the proper compilation of mp2sp with trivial selector,
1429 * trivial treatment, vlan encapsulation and co-located
1430 * filtered ingress/egress points.
Pier Ventreffe88d62016-10-13 14:34:40 -07001431 */
1432 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001433 public void testCoLocatedFilteredPointsTrivialForMp() {
Pier Ventreffe88d62016-10-13 14:34:40 -07001434
1435 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001436 .appId(APP_ID).selector(selector).treatment(treatment).links(linksForMp2SpCoLoc)
Pier Ventreffe88d62016-10-13 14:34:40 -07001437 .constraints(constraintsForVlan)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001438 .filteredIngressPoints(ImmutableSet.of(
1439 new FilteredConnectPoint(d1p10, mpls100Selector),
1440 new FilteredConnectPoint(d2p10, mpls200Selector)
1441 ))
1442 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls69Selector)))
Pier Ventreffe88d62016-10-13 14:34:40 -07001443 .build();
1444
1445 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001446
Pier Ventreffe88d62016-10-13 14:34:40 -07001447 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1448
1449 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1450 assertThat(compiled, hasSize(1));
1451
1452 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1453 assertThat(rules, hasSize(3));
1454
1455 Collection<FlowRule> rulesS1 = rules.stream()
1456 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1457 .collect(Collectors.toSet());
Pier Ventre5c4a0762016-11-21 10:28:13 -08001458 assertThat(rulesS1, hasSize(2));
1459
1460 FlowRule ruleS1 = rulesS1.stream()
1461 .filter(rule -> {
1462 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1463 return inPort.port().equals(d1p10.port());
1464 })
1465 .findFirst()
1466 .get();
Pier Ventreffe88d62016-10-13 14:34:40 -07001467 assertThat(ruleS1.selector(), is(
1468 DefaultTrafficSelector
Pier Ventre5c4a0762016-11-21 10:28:13 -08001469 .builder(mpls100Selector)
Pier Ventreffe88d62016-10-13 14:34:40 -07001470 .matchInPort(d1p10.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001471 .build()
1472 ));
1473 assertThat(ruleS1.treatment(), is(
1474 DefaultTrafficTreatment
1475 .builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001476 .setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label())
1477 .setOutput(d1p11.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001478 .build()
1479 ));
1480
Pier Ventre5c4a0762016-11-21 10:28:13 -08001481 ruleS1 = rulesS1.stream()
1482 .filter(rule -> {
1483 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1484 return inPort.port().equals(d1p0.port());
1485 })
1486 .findFirst()
1487 .get();
1488 assertThat(ruleS1.selector(), is(
Pier Ventreffe88d62016-10-13 14:34:40 -07001489 DefaultTrafficSelector
1490 .builder()
Pier Ventreffe88d62016-10-13 14:34:40 -07001491 .matchVlanId(VlanId.vlanId(LABEL))
Pier Ventre5c4a0762016-11-21 10:28:13 -08001492 .matchInPort(d1p0.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001493 .build()
1494 ));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001495 assertThat(ruleS1.treatment(), is(
Pier Ventreffe88d62016-10-13 14:34:40 -07001496 DefaultTrafficTreatment
1497 .builder()
Pier Ventreffe88d62016-10-13 14:34:40 -07001498 .popVlan()
1499 .pushMpls()
1500 .setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001501 .setOutput(d1p11.port())
1502 .build()
1503 ));
1504
1505 Collection<FlowRule> rulesS2 = rules.stream()
1506 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1507 .collect(Collectors.toSet());
1508 assertThat(rulesS2, hasSize(1));
1509 FlowRule ruleS2 = rulesS2.iterator().next();
1510 assertThat(ruleS2.selector(), is(
1511 DefaultTrafficSelector
1512 .builder(mpls200Selector)
1513 .matchInPort(d2p10.port())
1514 .build()
1515 ));
1516 assertThat(ruleS2.treatment(), is(
1517 DefaultTrafficTreatment
1518 .builder()
1519 .popMpls(IPV4.ethType())
1520 .pushVlan()
1521 .setVlanId(VlanId.vlanId(LABEL))
1522 .setOutput(d2p0.port())
1523 .build()
1524 ));
1525
1526 sut.deactivate();
1527
1528 }
1529
1530 /**
1531 * We test the proper compilation of sp2mp with trivial selector,
1532 * trivial treatment, vlan encapsulation and co-located
1533 * different filtered ingress/egress points.
1534 */
1535 @Test
1536 public void testCoLocatedDifferentFilteredPointsTrivialForSp() {
1537
1538 intent = LinkCollectionIntent.builder()
1539 .appId(APP_ID).selector(selector).treatment(treatment)
1540 .applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc)
1541 .constraints(constraintsForVlan)
1542 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector)))
1543 .filteredEgressPoints(ImmutableSet.of(
1544 new FilteredConnectPoint(d1p11, mpls100Selector),
1545 new FilteredConnectPoint(d2p10, vlan200Selector),
1546 new FilteredConnectPoint(d3p10, mpls200Selector)
1547 )).build();
1548
1549 sut.activate();
1550
1551 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1552
1553 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1554 assertThat(compiled, hasSize(1));
1555
1556 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1557 assertThat(rules, hasSize(3));
1558
1559 Collection<FlowRule> rulesS1 = rules.stream()
1560 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1561 .collect(Collectors.toSet());
1562 assertThat(rulesS1, hasSize(1));
1563 FlowRule ruleS1 = rulesS1.iterator().next();
1564 assertThat(ruleS1.selector(), is(
1565 DefaultTrafficSelector
1566 .builder(vlan100Selector)
1567 .matchInPort(d1p10.port())
1568 .build()
1569 ));
1570 assertThat(ruleS1.treatment(), is(
1571 DefaultTrafficTreatment
1572 .builder()
1573 .setVlanId(VlanId.vlanId(LABEL))
1574 .setOutput(d1p0.port())
1575 .popVlan()
1576 .pushMpls()
1577 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1578 .setOutput(d1p11.port())
1579 .build()
1580 ));
1581
1582 Collection<FlowRule> rulesS2 = rules.stream()
1583 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1584 .collect(Collectors.toSet());
1585 assertThat(rulesS2, hasSize(1));
1586 FlowRule ruleS2 = rulesS2.iterator().next();
1587 assertThat(ruleS2.selector(), is(
1588 DefaultTrafficSelector
1589 .builder()
1590 .matchInPort(d2p0.port())
1591 .matchVlanId(VlanId.vlanId(LABEL))
1592 .build()
1593 ));
1594 assertThat(ruleS2.treatment(), is(
1595 DefaultTrafficTreatment
1596 .builder()
1597 .setVlanId(VlanId.vlanId(LABEL))
1598 .setOutput(d2p1.port())
1599 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1600 .setOutput(d2p10.port())
1601 .build()
1602 ));
1603
1604 Collection<FlowRule> rulesS3 = rules.stream()
1605 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
1606 .collect(Collectors.toSet());
1607 assertThat(rulesS3, hasSize(1));
1608 FlowRule ruleS3 = rulesS3.iterator().next();
1609 assertThat(ruleS3.selector(), is(
1610 DefaultTrafficSelector
1611 .builder()
1612 .matchVlanId(VlanId.vlanId(LABEL))
1613 .matchInPort(d3p0.port())
1614 .build()
1615 ));
1616 assertThat(ruleS3.treatment(), is(
1617 DefaultTrafficTreatment
1618 .builder()
1619 .popVlan()
1620 .pushMpls()
1621 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
Pier Ventreffe88d62016-10-13 14:34:40 -07001622 .setOutput(d3p10.port())
1623 .build()
1624 ));
1625
1626 sut.deactivate();
1627
1628 }
1629
1630 /**
Pier Ventre5c4a0762016-11-21 10:28:13 -08001631 * We test the proper compilation of mp2sp with trivial selector,
1632 * trivial treatment, mpls encapsulation and co-located
1633 * filtered ingress/egress points.
Pier Ventreffe88d62016-10-13 14:34:40 -07001634 */
1635 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001636 public void testCoLocatedDifferentFilteredPointsTrivialForMp() {
Pier Ventreffe88d62016-10-13 14:34:40 -07001637
1638 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001639 .appId(APP_ID).selector(selector).treatment(treatment)
1640 .links(linksForMp2SpCoLoc).constraints(constraintsForMPLS)
1641 .filteredIngressPoints(ImmutableSet.of(
1642 new FilteredConnectPoint(d1p10, mpls100Selector),
1643 new FilteredConnectPoint(d2p10, vlan100Selector)
1644 ))
1645 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls200Selector)))
Pier Ventreffe88d62016-10-13 14:34:40 -07001646 .build();
1647
1648 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001649
1650 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1651
1652 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1653 assertThat(compiled, hasSize(1));
1654
1655 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1656 assertThat(rules, hasSize(3));
1657
1658 Collection<FlowRule> rulesS1 = rules.stream()
1659 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1660 .collect(Collectors.toSet());
1661 assertThat(rulesS1, hasSize(2));
1662 FlowRule ruleS1 = rulesS1.stream()
1663 .filter(rule -> {
1664 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1665 return inPort.port().equals(d1p10.port());
1666 })
1667 .findFirst()
1668 .get();
1669 assertThat(ruleS1.selector(), is(
1670 DefaultTrafficSelector
1671 .builder(mpls100Selector)
1672 .matchInPort(d1p10.port())
1673 .build()
1674 ));
1675 assertThat(ruleS1.treatment(), is(
1676 DefaultTrafficTreatment
1677 .builder()
1678 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1679 .setOutput(d1p11.port())
1680 .build()
1681 ));
1682 ruleS1 = rulesS1.stream()
1683 .filter(rule -> {
1684 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1685 return inPort.port().equals(d1p0.port());
1686 })
1687 .findFirst()
1688 .get();
1689 assertThat(ruleS1.selector(), is(
1690 DefaultTrafficSelector
1691 .builder()
1692 .matchEthType(Ethernet.MPLS_UNICAST)
1693 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1694 .matchInPort(d1p0.port())
1695 .build()
1696 ));
1697 assertThat(ruleS1.treatment(), is(
1698 DefaultTrafficTreatment
1699 .builder()
1700 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1701 .setOutput(d1p11.port())
1702 .build()
1703 ));
1704
1705 Collection<FlowRule> rulesS2 = rules.stream()
1706 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1707 .collect(Collectors.toSet());
1708 assertThat(rulesS2, hasSize(1));
1709 FlowRule ruleS2 = rulesS2.iterator().next();
1710 assertThat(ruleS2.selector(), is(
1711 DefaultTrafficSelector
1712 .builder(vlan100Selector)
1713 .matchInPort(d2p10.port())
1714 .build()
1715 ));
1716 assertThat(ruleS2.treatment(), is(
1717 DefaultTrafficTreatment
1718 .builder()
1719 .popVlan()
1720 .pushMpls()
1721 .setMpls(MplsLabel.mplsLabel(LABEL))
1722 .setOutput(d2p0.port())
1723 .build()
1724 ));
1725
1726 sut.deactivate();
1727
1728 }
1729
1730 /**
1731 * We test the proper compilation of sp2mp with selector,
1732 * treatment, mpls encapsulation and co-located
1733 * different filtered ingress/egress points.
1734 */
1735 @Test
1736 public void testCoLocatedDifferentFilteredPointsNonTrivialForSp() {
1737
1738 intent = LinkCollectionIntent.builder()
1739 .appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment)
1740 .applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc)
1741 .constraints(constraintsForMPLS)
1742 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector)))
1743 .filteredEgressPoints(ImmutableSet.of(
1744 new FilteredConnectPoint(d1p11, mpls100Selector),
1745 new FilteredConnectPoint(d2p10, vlan200Selector),
1746 new FilteredConnectPoint(d3p10, mpls200Selector)
1747 )).build();
1748
1749 sut.activate();
1750
Pier Ventreffe88d62016-10-13 14:34:40 -07001751 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1752
1753 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1754 assertThat(compiled, hasSize(1));
1755
1756 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1757 assertThat(rules, hasSize(3));
1758
1759 Collection<FlowRule> rulesS1 = rules.stream()
1760 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1761 .collect(Collectors.toSet());
1762 assertThat(rulesS1, hasSize(1));
1763 FlowRule ruleS1 = rulesS1.iterator().next();
1764 assertThat(ruleS1.selector(), is(
1765 DefaultTrafficSelector
1766 .builder(ipPrefixSelector)
1767 .matchInPort(d1p10.port())
1768 .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
1769 .build()
1770 ));
1771 assertThat(ruleS1.treatment(), is(
1772 DefaultTrafficTreatment
1773 .builder()
1774 .popVlan()
1775 .pushMpls()
1776 .setMpls(MplsLabel.mplsLabel(LABEL))
1777 .setOutput(d1p0.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001778 .setEthDst(((ModEtherInstruction) ethDstTreatment
1779 .allInstructions()
1780 .stream()
1781 .filter(instruction -> instruction instanceof ModEtherInstruction)
1782 .findFirst().get()).mac())
1783 .popVlan()
1784 .pushMpls()
1785 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1786 .setOutput(d1p11.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001787 .build()
1788 ));
1789
1790 Collection<FlowRule> rulesS2 = rules.stream()
1791 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1792 .collect(Collectors.toSet());
1793 assertThat(rulesS2, hasSize(1));
1794 FlowRule ruleS2 = rulesS2.iterator().next();
1795 assertThat(ruleS2.selector(), is(
1796 DefaultTrafficSelector
1797 .builder()
1798 .matchInPort(d2p0.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001799 .matchEthType(Ethernet.MPLS_UNICAST)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001800 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
Pier Ventreffe88d62016-10-13 14:34:40 -07001801 .build()
1802 ));
1803 assertThat(ruleS2.treatment(), is(
1804 DefaultTrafficTreatment
1805 .builder()
1806 .setMpls(MplsLabel.mplsLabel(LABEL))
1807 .setOutput(d2p1.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001808 .setEthDst(((ModEtherInstruction) ethDstTreatment
1809 .allInstructions()
1810 .stream()
1811 .filter(instruction -> instruction instanceof ModEtherInstruction)
1812 .findFirst().get()).mac())
1813 .popMpls(IPV4.ethType())
1814 .pushVlan()
1815 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1816 .setOutput(d2p10.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001817 .build()
1818 ));
1819
1820 Collection<FlowRule> rulesS3 = rules.stream()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001821 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
Pier Ventreffe88d62016-10-13 14:34:40 -07001822 .collect(Collectors.toSet());
1823 assertThat(rulesS3, hasSize(1));
1824 FlowRule ruleS3 = rulesS3.iterator().next();
1825 assertThat(ruleS3.selector(), is(
1826 DefaultTrafficSelector
1827 .builder()
Pier Ventreffe88d62016-10-13 14:34:40 -07001828 .matchEthType(Ethernet.MPLS_UNICAST)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001829 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1830 .matchInPort(d3p0.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001831 .build()
1832 ));
1833 assertThat(ruleS3.treatment(), is(
1834 DefaultTrafficTreatment
1835 .builder()
1836 .setEthDst(((ModEtherInstruction) ethDstTreatment
1837 .allInstructions()
1838 .stream()
1839 .filter(instruction -> instruction instanceof ModEtherInstruction)
1840 .findFirst().get()).mac())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001841 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
Pier Ventreffe88d62016-10-13 14:34:40 -07001842 .setOutput(d3p10.port())
1843 .build()
1844 ));
1845
1846 sut.deactivate();
1847
1848 }
1849
Pier Ventre5c4a0762016-11-21 10:28:13 -08001850 /**
1851 * We test the proper compilation of mp2sp with selector,
1852 * treatment, vlan encapsulation and co-located
1853 * filtered ingress/egress points.
1854 */
1855 @Test
1856 public void testCoLocatedDifferentFilteredPointsNonTrivialForMp() {
1857
1858 intent = LinkCollectionIntent.builder()
1859 .appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment)
1860 .links(linksForMp2SpCoLoc).constraints(constraintsForVlan)
1861 .filteredIngressPoints(ImmutableSet.of(
1862 new FilteredConnectPoint(d1p10, mpls100Selector),
1863 new FilteredConnectPoint(d2p10, vlan100Selector)
1864 ))
1865 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls200Selector)))
1866 .build();
1867
1868 sut.activate();
1869
1870 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1871
1872 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1873 assertThat(compiled, hasSize(1));
1874
1875 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1876 assertThat(rules, hasSize(3));
1877
1878 Collection<FlowRule> rulesS1 = rules.stream()
1879 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1880 .collect(Collectors.toSet());
1881 assertThat(rulesS1, hasSize(2));
1882 FlowRule ruleS1 = rulesS1.stream()
1883 .filter(rule -> {
1884 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1885 return inPort.port().equals(d1p10.port());
1886 })
1887 .findFirst()
1888 .get();
1889 assertThat(ruleS1.selector(), is(
1890 DefaultTrafficSelector
1891 .builder(ipPrefixSelector)
1892 .matchInPort(d1p10.port())
1893 .matchMplsLabel(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1894 .build()
1895 ));
1896 assertThat(ruleS1.treatment(), is(
1897 DefaultTrafficTreatment
1898 .builder()
1899 .setEthDst(((ModEtherInstruction) ethDstTreatment
1900 .allInstructions()
1901 .stream()
1902 .filter(instruction -> instruction instanceof ModEtherInstruction)
1903 .findFirst().get()).mac())
1904 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1905 .setOutput(d1p11.port())
1906 .build()
1907 ));
1908
1909 ruleS1 = rulesS1.stream()
1910 .filter(rule -> {
1911 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1912 return inPort.port().equals(d1p0.port());
1913 })
1914 .findFirst()
1915 .get();
1916 assertThat(ruleS1.selector(), is(
1917 DefaultTrafficSelector
1918 .builder()
1919 .matchVlanId(VlanId.vlanId(LABEL))
1920 .matchInPort(d1p0.port())
1921 .build()
1922 ));
1923 assertThat(ruleS1.treatment(), is(
1924 DefaultTrafficTreatment
1925 .builder()
1926 .setEthDst(((ModEtherInstruction) ethDstTreatment
1927 .allInstructions()
1928 .stream()
1929 .filter(instruction -> instruction instanceof ModEtherInstruction)
1930 .findFirst().get()).mac())
1931 .popVlan()
1932 .pushMpls()
1933 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1934 .setOutput(d1p11.port())
1935 .build()
1936 ));
1937
1938 Collection<FlowRule> rulesS2 = rules.stream()
1939 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1940 .collect(Collectors.toSet());
1941 assertThat(rulesS2, hasSize(1));
1942 FlowRule ruleS2 = rulesS2.iterator().next();
1943 assertThat(ruleS2.selector(), is(
1944 DefaultTrafficSelector
1945 .builder(ipPrefixSelector)
1946 .matchInPort(d2p10.port())
1947 .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
1948 .build()
1949 ));
1950 assertThat(ruleS2.treatment(), is(
1951 DefaultTrafficTreatment
1952 .builder()
1953 .setVlanId(VlanId.vlanId(LABEL))
1954 .setOutput(d2p0.port())
1955 .build()
1956 ));
1957
1958 sut.deactivate();
1959
1960 }
1961
Pier Ventre766995d2016-10-05 22:15:56 -07001962}