blob: 27ef08bc2ef9b7ec73c04caea6b156bfedb6142f [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
68 Intent.bindIdGenerator(idGenerator);
69
70 intentExtensionService = createMock(IntentExtensionService.class);
71 intentExtensionService.registerCompiler(LinkCollectionIntent.class, sut);
72 intentExtensionService.unregisterCompiler(LinkCollectionIntent.class);
73
74 registrator = new IntentConfigurableRegistrator();
75 registrator.extensionService = intentExtensionService;
76 registrator.cfgService = new ComponentConfigAdapter();
77 registrator.activate();
78
79 sut.registrator = registrator;
80 sut.resourceService = new MockResourceService();
81
Pier Ventre81c47bf2016-11-04 07:26:22 -070082 LinkCollectionCompiler.optimize = false;
83 LinkCollectionCompiler.copyTtl = false;
84
Pier Ventre766995d2016-10-05 22:15:56 -070085 replay(coreService, intentExtensionService);
86 }
87
88 @After
89 public void tearDown() {
90 Intent.unbindIdGenerator(idGenerator);
91 }
92
93 /**
94 * We test the proper compilation of mp2Sp1 with the VLAN
95 * encapsulation, trivial selector.
96 */
97 @Test
98 public void testVlanEncapsulationForMp() {
99
100 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800101 .appId(APP_ID).selector(selector).treatment(treatment)
102 .constraints(constraintsForVlan).links(linksForMp2Sp)
Pier Ventre766995d2016-10-05 22:15:56 -0700103 .filteredIngressPoints(ImmutableSet.of(
104 new FilteredConnectPoint(d1p10),
105 new FilteredConnectPoint(d1p11),
106 new FilteredConnectPoint(d2p10)
107 ))
108 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10)))
109 .build();
110
111 sut.activate();
112 /*
113 * We use the FIRST_FIT to simplify tests.
114 */
115 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
116
117 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
118 assertThat(compiled, hasSize(1));
119
120 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
121 assertThat(rules, hasSize(5));
122
123 Collection<FlowRule> rulesS1 = rules.stream()
124 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
125 .collect(Collectors.toSet());
126 assertThat(rulesS1, hasSize(2));
127 FlowRule ruleS1 = rulesS1.stream()
128 .filter(rule -> {
129 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
130 return inPort.port().equals(d1p10.port());
Pier Ventre5c4a0762016-11-21 10:28:13 -0800131 }).findFirst().get();
Pier Ventre766995d2016-10-05 22:15:56 -0700132 assertThat(ruleS1.selector(), is(
133 DefaultTrafficSelector
134 .builder(intent.selector())
135 .matchInPort(d1p10.port())
136 .build()
137 ));
138 assertThat(ruleS1.treatment(), is(
139 DefaultTrafficTreatment
140 .builder()
141 .pushVlan()
142 .setVlanId(VlanId.vlanId(LABEL))
143 .setOutput(d1p0.port())
144 .build()
145 ));
146
147 ruleS1 = rulesS1.stream()
148 .filter(rule -> {
149 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
150 return inPort.port().equals(d1p11.port());
151 })
152 .findFirst()
153 .get();
154 assertThat(ruleS1.selector(), is(
155 DefaultTrafficSelector
156 .builder(intent.selector())
157 .matchInPort(d1p11.port())
158 .build()
159 ));
160 assertThat(ruleS1.treatment(), is(
161 DefaultTrafficTreatment
162 .builder()
163 .pushVlan()
164 .setVlanId(VlanId.vlanId(LABEL))
165 .setOutput(d1p0.port())
166 .build()
167 ));
168
169 Collection<FlowRule> rulesS2 = rules.stream()
170 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
171 .collect(Collectors.toSet());
172 assertThat(rulesS2, hasSize(2));
173 FlowRule ruleS2 = rulesS2.stream()
174 .filter(rule -> {
175 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
176 return inPort.port().equals(d2p10.port());
177 })
178 .findFirst()
179 .get();
180 assertThat(ruleS2.selector(), is(
181 DefaultTrafficSelector
182 .builder(intent.selector())
183 .matchInPort(d2p10.port())
184 .build()
185 ));
186 assertThat(ruleS2.treatment(), is(
187 DefaultTrafficTreatment
188 .builder()
189 .pushVlan()
190 .setVlanId(VlanId.vlanId(LABEL))
191 .setOutput(d2p1.port())
192 .build()
193 ));
194
195 ruleS2 = rulesS2.stream()
196 .filter(rule -> {
197 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
198 return inPort.port().equals(d2p0.port());
199 })
200 .findFirst()
201 .get();
202 assertThat(ruleS2.selector(), is(
203 DefaultTrafficSelector
204 .builder()
205 .matchInPort(d2p0.port())
206 .matchVlanId(VlanId.vlanId(LABEL))
207 .build()
208 ));
209 assertThat(ruleS2.treatment(), is(
210 DefaultTrafficTreatment
211 .builder()
212 .setVlanId(VlanId.vlanId(LABEL))
213 .setOutput(d2p1.port())
214 .build()
215 ));
216
217 Collection<FlowRule> rulesS3 = rules.stream()
218 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
219 .collect(Collectors.toSet());
220 assertThat(rulesS3, hasSize(1));
221 FlowRule ruleS3 = rulesS3.iterator().next();
222 assertThat(ruleS3.selector(), is(
223 DefaultTrafficSelector
224 .builder()
225 .matchInPort(d3p0.port())
226 .matchVlanId(VlanId.vlanId(LABEL))
227 .build()
228 ));
229 assertThat(ruleS3.treatment(), is(
230 DefaultTrafficTreatment
231 .builder()
232 .popVlan()
233 .setOutput(d3p10.port())
234 .build()
235 ));
236
237 sut.deactivate();
238 }
239
240 /**
241 * We test the proper compilation of sp2mp with the MPLS
242 * encapsulation and trivial selector.
243 */
244 @Test
245 public void testMplsEncapsulationForSp() {
246
247 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800248 .appId(APP_ID).selector(selector).treatment(treatment)
249 .constraints(constraintsForMPLS).links(linksForSp2Mp)
Pier Ventre766995d2016-10-05 22:15:56 -0700250 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10)))
251 .filteredEgressPoints(ImmutableSet.of(
252 new FilteredConnectPoint(d1p10),
253 new FilteredConnectPoint(d1p11),
254 new FilteredConnectPoint(d2p10)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800255 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700256
257 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800258
Pier Ventre766995d2016-10-05 22:15:56 -0700259 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
260
261 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
262 assertThat(compiled, hasSize(1));
263
264 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
265 assertThat(rules, hasSize(3));
266
267 Collection<FlowRule> rulesS3 = rules.stream()
268 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
269 .collect(Collectors.toSet());
270 assertThat(rulesS3, hasSize(1));
271 FlowRule ruleS3 = rulesS3.iterator().next();
272 assertThat(ruleS3.selector(), is(
273 DefaultTrafficSelector
274 .builder()
275 .matchInPort(d3p10.port())
276 .build()
277 ));
278 assertThat(ruleS3.treatment(), is(
279 DefaultTrafficTreatment
280 .builder()
281 .pushMpls()
Pier Ventre81c47bf2016-11-04 07:26:22 -0700282 .setMpls(MplsLabel.mplsLabel(LABEL))
Pier Ventre766995d2016-10-05 22:15:56 -0700283 .setOutput(d3p0.port())
284 .build()
285 ));
286
287 Collection<FlowRule> rulesS2 = rules.stream()
288 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
289 .collect(Collectors.toSet());
290 assertThat(rulesS2, hasSize(1));
291 FlowRule ruleS2 = rulesS2.iterator().next();
292 assertThat(ruleS2.selector(), is(
293 DefaultTrafficSelector
294 .builder()
295 .matchInPort(d2p1.port())
296 .matchMplsLabel(MplsLabel.mplsLabel((LABEL)))
297 .matchEthType(Ethernet.MPLS_UNICAST)
298 .build()
299 ));
300 assertThat(ruleS2.treatment(), is(
301 DefaultTrafficTreatment
302 .builder()
303 .setMpls(MplsLabel.mplsLabel(LABEL))
304 .setOutput(d2p0.port())
305 .popMpls(IPV4.ethType())
306 .setOutput(d2p10.port())
307 .build()
308 ));
309
310 Collection<FlowRule> rulesS1 = rules.stream()
311 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
312 .collect(Collectors.toSet());
313 assertThat(rulesS1, hasSize(1));
314 FlowRule ruleS1 = rulesS1.iterator().next();
315 assertThat(ruleS1.selector(), is(
316 DefaultTrafficSelector
317 .builder()
318 .matchInPort(d1p0.port())
319 .matchMplsLabel(MplsLabel.mplsLabel((LABEL)))
320 .matchEthType(Ethernet.MPLS_UNICAST)
321 .build()
322 ));
323 assertThat(ruleS1.treatment(), is(
324 DefaultTrafficTreatment
325 .builder()
326 .popMpls(IPV4.ethType())
327 .setOutput(d1p10.port())
328 .popMpls(IPV4.ethType())
329 .setOutput(d1p11.port())
330 .build()
331 ));
332
333 sut.deactivate();
334
335 }
336
337 /**
338 * We test the proper compilation of mp2sp with the MPLS
339 * encapsulation and filtered selector.
340 */
341 @Test
342 public void testMplsEncapsulationFilteredForMp() {
343
344 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800345 .appId(APP_ID).selector(selector).treatment(treatment)
346 .constraints(constraintsForMPLS).links(linksForMp2Sp)
Pier Ventre766995d2016-10-05 22:15:56 -0700347 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan69Selector)))
348 .filteredIngressPoints(ImmutableSet.of(
349 new FilteredConnectPoint(d1p10, vlan100Selector),
350 new FilteredConnectPoint(d1p11, vlan200Selector),
351 new FilteredConnectPoint(d2p10, vlan300Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800352 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700353
354 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800355
Pier Ventre766995d2016-10-05 22:15:56 -0700356 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
357
358 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
359 assertThat(compiled, hasSize(1));
360
361 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
362 assertThat(rules, hasSize(5));
363
364 Collection<FlowRule> rulesS1 = rules.stream()
365 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
366 .collect(Collectors.toSet());
367 assertThat(rulesS1, hasSize(2));
368 FlowRule ruleS1 = rulesS1.stream()
369 .filter(rule -> {
370 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
371 return inPort.port().equals(d1p10.port());
372 })
373 .findFirst()
374 .get();
375 assertThat(ruleS1.selector(), is(
376 DefaultTrafficSelector
377 .builder(vlan100Selector)
378 .matchInPort(d1p10.port())
379 .build()
380 ));
381 assertThat(ruleS1.treatment(), is(
382 DefaultTrafficTreatment
383 .builder()
384 .popVlan()
385 .pushMpls()
386 .setMpls(MplsLabel.mplsLabel(LABEL))
387 .setOutput(d1p0.port())
388 .build()
389 ));
390
391 ruleS1 = rulesS1.stream()
392 .filter(rule -> {
393 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
394 return inPort.port().equals(d1p11.port());
395 })
396 .findFirst()
397 .get();
398 assertThat(ruleS1.selector(), is(
399 DefaultTrafficSelector
400 .builder(vlan200Selector)
401 .matchInPort(d1p11.port())
402 .build()
403 ));
404 assertThat(ruleS1.treatment(), is(
405 DefaultTrafficTreatment
406 .builder()
407 .popVlan()
408 .pushMpls()
409 .setMpls(MplsLabel.mplsLabel(LABEL))
410 .setOutput(d1p0.port())
411 .build()
412 ));
413
414 Collection<FlowRule> rulesS2 = rules.stream()
415 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
416 .collect(Collectors.toSet());
417 assertThat(rulesS2, hasSize(2));
418 FlowRule ruleS2 = rulesS2.stream()
419 .filter(rule -> {
420 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
421 return inPort.port().equals(d2p10.port());
422 })
423 .findFirst()
424 .get();
425 assertThat(ruleS2.selector(), is(
426 DefaultTrafficSelector
427 .builder(vlan300Selector)
428 .matchInPort(d2p10.port())
429 .build()
430 ));
431 assertThat(ruleS2.treatment(), is(
432 DefaultTrafficTreatment
433 .builder()
434 .popVlan()
435 .pushMpls()
436 .setMpls(MplsLabel.mplsLabel(LABEL))
437 .setOutput(d2p1.port())
438 .build()
439 ));
440
441 ruleS2 = rulesS2.stream()
442 .filter(rule -> {
443 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
444 return inPort.port().equals(d2p0.port());
445 })
446 .findFirst()
447 .get();
448 assertThat(ruleS2.selector(), is(
449 DefaultTrafficSelector
450 .builder()
451 .matchInPort(d2p0.port())
452 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
453 .matchEthType(Ethernet.MPLS_UNICAST)
454 .build()
455 ));
456 assertThat(ruleS2.treatment(), is(
457 DefaultTrafficTreatment
458 .builder()
459 .setMpls(MplsLabel.mplsLabel(LABEL))
460 .setOutput(d2p1.port())
461 .build()
462 ));
463
464 Collection<FlowRule> rulesS3 = rules.stream()
465 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
466 .collect(Collectors.toSet());
467 assertThat(rulesS3, hasSize(1));
468 FlowRule ruleS3 = rulesS3.iterator().next();
469 assertThat(ruleS3.selector(), is(
470 DefaultTrafficSelector
471 .builder()
472 .matchInPort(d3p0.port())
473 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
474 .matchEthType(Ethernet.MPLS_UNICAST)
475 .build()
476 ));
477 assertThat(ruleS3.treatment(), is(
478 DefaultTrafficTreatment
479 .builder()
480 .popMpls(IPV4.ethType())
481 .pushVlan()
482 .setVlanId(((VlanIdCriterion) vlan69Selector.getCriterion(VLAN_VID)).vlanId())
483 .setOutput(d3p10.port())
484 .build()
485 ));
486
487 sut.deactivate();
488
489 }
490
491 /**
492 * We test the proper compilation of sp2mp with the VLAN
493 * encapsulation and filtered selector.
494 */
495 @Test
496 public void testVlanEncapsulationFilteredForSp() {
497
498 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800499 .appId(APP_ID).selector(selector).treatment(treatment)
500 .constraints(constraintsForVlan).links(linksForSp2Mp)
Pier Ventre766995d2016-10-05 22:15:56 -0700501 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls69Selector)))
502 .filteredEgressPoints(ImmutableSet.of(
503 new FilteredConnectPoint(d1p10, mpls100Selector),
504 new FilteredConnectPoint(d1p11, mpls200Selector),
505 new FilteredConnectPoint(d2p10, mpls80Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800506 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700507
508 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800509
Pier Ventre766995d2016-10-05 22:15:56 -0700510 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
511
512 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
513 assertThat(compiled, hasSize(1));
514
515 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
516 assertThat(rules, hasSize(3));
517
518 Collection<FlowRule> rulesS3 = rules.stream()
519 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
520 .collect(Collectors.toSet());
521 assertThat(rulesS3, hasSize(1));
522 FlowRule ruleS3 = rulesS3.iterator().next();
523 assertThat(ruleS3.selector(), is(
524 DefaultTrafficSelector
525 .builder(mpls69Selector)
526 .matchInPort(d3p10.port())
527 .build()
528 ));
529 assertThat(ruleS3.treatment(), is(
530 DefaultTrafficTreatment
531 .builder()
532 .popMpls(IPV4.ethType())
533 .pushVlan()
534 .setVlanId(VlanId.vlanId(LABEL))
535 .setOutput(d3p0.port())
536 .build()
537 ));
538
539 Collection<FlowRule> rulesS2 = rules.stream()
540 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
541 .collect(Collectors.toSet());
542 assertThat(rulesS2, hasSize(1));
543 FlowRule ruleS2 = rulesS2.iterator().next();
544 assertThat(ruleS2.selector(), is(
545 DefaultTrafficSelector
546 .builder()
547 .matchInPort(d2p1.port())
548 .matchVlanId(VlanId.vlanId(LABEL))
549 .build()
550 ));
551 assertThat(ruleS2.treatment(), is(
552 DefaultTrafficTreatment
553 .builder()
554 .setVlanId(VlanId.vlanId(LABEL))
555 .setOutput(d2p0.port())
556 .popVlan()
557 .pushMpls()
558 .setMpls(((MplsCriterion) mpls80Selector.getCriterion(MPLS_LABEL)).label())
559 .setOutput(d2p10.port())
560 .build()
561 ));
562
563 Collection<FlowRule> rulesS1 = rules.stream()
564 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
565 .collect(Collectors.toSet());
566 assertThat(rulesS1, hasSize(1));
567 FlowRule ruleS1 = rulesS1.iterator().next();
568 assertThat(ruleS1.selector(), is(
569 DefaultTrafficSelector
570 .builder()
571 .matchInPort(d1p0.port())
572 .matchVlanId(VlanId.vlanId(LABEL))
573 .build()
574 ));
575 assertThat(ruleS1.treatment(), is(
576 DefaultTrafficTreatment
577 .builder()
578 .popVlan()
579 .pushMpls()
580 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
581 .setOutput(d1p10.port())
582 .popVlan()
583 .pushMpls()
584 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
585 .setOutput(d1p11.port())
586 .build()
587 ));
588
589 sut.deactivate();
590
591 }
592
593 /**
594 * We test the proper compilation of mp2sp with the VLAN
595 * encapsulation, filtered selectors, intent selector and intent treatment.
596 */
597 @Test
598 public void testVlanEncapsulationNonTrivialForMp() {
599
600 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800601 .appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment)
602 .constraints(constraintsForVlan).links(linksForMp2Sp)
Pier Ventre766995d2016-10-05 22:15:56 -0700603 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls69Selector)))
604 .filteredIngressPoints(ImmutableSet.of(
605 new FilteredConnectPoint(d1p10, mpls80Selector),
606 new FilteredConnectPoint(d1p11, mpls100Selector),
607 new FilteredConnectPoint(d2p10, mpls200Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800608 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700609
610 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800611
Pier Ventre766995d2016-10-05 22:15:56 -0700612 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
613
614 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
615 assertThat(compiled, hasSize(1));
616
617 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
618 assertThat(rules, hasSize(5));
619
620 Collection<FlowRule> rulesS1 = rules.stream()
621 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
622 .collect(Collectors.toSet());
623 assertThat(rulesS1, hasSize(2));
624 FlowRule ruleS1 = rulesS1.stream()
625 .filter(rule -> {
626 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
627 return inPort.port().equals(d1p10.port());
628 })
629 .findFirst()
630 .get();
631 assertThat(ruleS1.selector(), is(
632 DefaultTrafficSelector
633 .builder(ipPrefixSelector)
634 .matchInPort(d1p10.port())
635 .matchMplsLabel(((MplsCriterion) mpls80Selector.getCriterion(MPLS_LABEL)).label())
636 .build()
637 ));
638 assertThat(ruleS1.treatment(), is(
639 DefaultTrafficTreatment
640 .builder()
641 .popMpls(IPV4.ethType())
642 .pushVlan()
643 .setVlanId(VlanId.vlanId(LABEL))
644 .setOutput(d1p0.port())
645 .build()
646 ));
647
648 ruleS1 = rulesS1.stream()
649 .filter(rule -> {
650 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
651 return inPort.port().equals(d1p11.port());
652 })
653 .findFirst()
654 .get();
655 assertThat(ruleS1.selector(), is(
656 DefaultTrafficSelector
657 .builder(ipPrefixSelector)
658 .matchInPort(d1p11.port())
659 .matchMplsLabel(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
660 .build()
661 ));
662 assertThat(ruleS1.treatment(), is(
663 DefaultTrafficTreatment
664 .builder()
665 .popMpls(IPV4.ethType())
666 .pushVlan()
667 .setVlanId(VlanId.vlanId(LABEL))
668 .setOutput(d1p0.port())
669 .build()
670 ));
671
672 Collection<FlowRule> rulesS2 = rules.stream()
673 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
674 .collect(Collectors.toSet());
675 assertThat(rulesS2, hasSize(2));
676 FlowRule ruleS2 = rulesS2.stream()
677 .filter(rule -> {
678 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
679 return inPort.port().equals(d2p10.port());
680 })
681 .findFirst()
682 .get();
683 assertThat(ruleS2.selector(), is(
684 DefaultTrafficSelector
685 .builder(ipPrefixSelector)
686 .matchInPort(d2p10.port())
687 .matchMplsLabel(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
688 .build()
689 ));
690 assertThat(ruleS2.treatment(), is(
691 DefaultTrafficTreatment
692 .builder()
693 .popMpls(IPV4.ethType())
694 .pushVlan()
695 .setVlanId(VlanId.vlanId(LABEL))
696 .setOutput(d2p1.port())
697 .build()
698 ));
699
700 ruleS2 = rulesS2.stream()
701 .filter(rule -> {
702 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
703 return inPort.port().equals(d2p0.port());
704 })
705 .findFirst()
706 .get();
707 assertThat(ruleS2.selector(), is(
708 DefaultTrafficSelector
709 .builder()
710 .matchInPort(d2p0.port())
711 .matchVlanId(VlanId.vlanId(LABEL))
712 .build()
713 ));
714 assertThat(ruleS2.treatment(), is(
715 DefaultTrafficTreatment
716 .builder()
717 .setVlanId(VlanId.vlanId(LABEL))
718 .setOutput(d2p1.port())
719 .build()
720 ));
721
722 Collection<FlowRule> rulesS3 = rules.stream()
723 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
724 .collect(Collectors.toSet());
725 assertThat(rulesS3, hasSize(1));
726 FlowRule ruleS3 = rulesS3.iterator().next();
727 assertThat(ruleS3.selector(), is(
728 DefaultTrafficSelector
729 .builder()
730 .matchInPort(d3p0.port())
731 .matchVlanId(VlanId.vlanId(LABEL))
732 .build()
733 ));
734 assertThat(ruleS3.treatment(), is(
735 DefaultTrafficTreatment
736 .builder(ethDstTreatment)
737 .popVlan()
738 .pushMpls()
739 .setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label())
740 .setOutput(d3p10.port())
741 .build()
742 ));
743
744 sut.deactivate();
745
746 }
747
748 /**
749 * We test the proper compilation of sp2mp with the MPLS
750 * encapsulation, filtered selector, intent selector, and
751 * intent treatment.
752 */
753 @Test
754 public void testMplsEncapsulationNonTrivialForSp() {
755
756 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800757 .appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment)
758 .constraints(constraintsForMPLS).links(linksForSp2Mp)
Pier Ventre766995d2016-10-05 22:15:56 -0700759 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan69Selector)))
760 .filteredEgressPoints(ImmutableSet.of(
761 new FilteredConnectPoint(d1p10, vlan100Selector),
762 new FilteredConnectPoint(d1p11, vlan200Selector),
763 new FilteredConnectPoint(d2p10, vlan300Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800764 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700765
766 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800767
Pier Ventre766995d2016-10-05 22:15:56 -0700768 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
769
770 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
771 assertThat(compiled, hasSize(1));
772
773 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
774 assertThat(rules, hasSize(3));
775
776 Collection<FlowRule> rulesS3 = rules.stream()
777 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
778 .collect(Collectors.toSet());
779 assertThat(rulesS3, hasSize(1));
780 FlowRule ruleS3 = rulesS3.iterator().next();
781 assertThat(ruleS3.selector(), is(
782 DefaultTrafficSelector
783 .builder(ipPrefixSelector)
784 .matchInPort(d3p10.port())
785 .matchVlanId(((VlanIdCriterion) vlan69Selector.getCriterion(VLAN_VID)).vlanId())
786 .build()
787 ));
788 assertThat(ruleS3.treatment(), is(
789 DefaultTrafficTreatment
790 .builder()
791 .popVlan()
792 .pushMpls()
793 .setMpls(MplsLabel.mplsLabel(LABEL))
794 .setOutput(d3p0.port())
795 .build()
796 ));
797
798 Collection<FlowRule> rulesS2 = rules.stream()
799 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
800 .collect(Collectors.toSet());
801 assertThat(rulesS2, hasSize(1));
802 FlowRule ruleS2 = rulesS2.iterator().next();
803 assertThat(ruleS2.selector(), is(
804 DefaultTrafficSelector
805 .builder()
806 .matchInPort(d2p1.port())
807 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
808 .matchEthType(Ethernet.MPLS_UNICAST)
809 .build()
810 ));
811 assertThat(ruleS2.treatment(), is(
812 DefaultTrafficTreatment
813 .builder()
814 .setMpls(MplsLabel.mplsLabel(LABEL))
815 .setOutput(d2p0.port())
816 .setEthDst(((ModEtherInstruction) ethDstTreatment
817 .allInstructions()
818 .stream()
819 .filter(instruction -> instruction instanceof ModEtherInstruction)
820 .findFirst().get()).mac())
821 .popMpls(IPV4.ethType())
822 .pushVlan()
823 .setVlanId(((VlanIdCriterion) vlan300Selector.getCriterion(VLAN_VID)).vlanId())
824 .setOutput(d2p10.port())
825 .build()
826 ));
827
828 Collection<FlowRule> rulesS1 = rules.stream()
829 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
830 .collect(Collectors.toSet());
831 assertThat(rulesS1, hasSize(1));
832 FlowRule ruleS1 = rulesS1.iterator().next();
833 assertThat(ruleS1.selector(), is(
834 DefaultTrafficSelector
835 .builder()
836 .matchInPort(d1p0.port())
837 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
838 .matchEthType(Ethernet.MPLS_UNICAST)
839 .build()
840 ));
841 assertThat(ruleS1.treatment(), is(
842 DefaultTrafficTreatment
843 .builder()
844 .setEthDst(((ModEtherInstruction) ethDstTreatment
845 .allInstructions()
846 .stream()
847 .filter(instruction -> instruction instanceof ModEtherInstruction)
848 .findFirst().get()).mac())
849 .popMpls(IPV4.ethType())
850 .pushVlan()
851 .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
852 .setOutput(d1p10.port())
853 .setEthDst(((ModEtherInstruction) ethDstTreatment
854 .allInstructions()
855 .stream()
856 .filter(instruction -> instruction instanceof ModEtherInstruction)
857 .findFirst().get()).mac())
858 .popMpls(IPV4.ethType())
859 .pushVlan()
860 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
861 .setOutput(d1p11.port())
862 .build()
863 ));
864
865 sut.deactivate();
866
867 }
868
869 /**
870 * We test the proper compilation of mp2sp with the MPLS
871 * encapsulation and filtered selectors of different type.
872 */
873 @Test
874 public void testMplsEncapsulationDifferentFilterForMp() {
875
876 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800877 .appId(APP_ID).selector(selector).treatment(treatment)
878 .constraints(constraintsForMPLS).links(linksForMp2Sp)
Pier Ventre766995d2016-10-05 22:15:56 -0700879 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls100Selector)))
880 .filteredIngressPoints(ImmutableSet.of(
881 new FilteredConnectPoint(d1p10, vlan100Selector),
882 new FilteredConnectPoint(d1p11, mpls200Selector),
883 new FilteredConnectPoint(d2p10, vlan200Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800884 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700885
886 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800887
Pier Ventre766995d2016-10-05 22:15:56 -0700888 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
889
890 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
891 assertThat(compiled, hasSize(1));
892
893 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
894 assertThat(rules, hasSize(5));
895
896 Collection<FlowRule> rulesS1 = rules.stream()
897 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
898 .collect(Collectors.toSet());
899 assertThat(rulesS1, hasSize(2));
900 FlowRule ruleS1 = rulesS1.stream()
901 .filter(rule -> {
902 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
903 return inPort.port().equals(d1p10.port());
904 })
905 .findFirst()
906 .get();
907 assertThat(ruleS1.selector(), is(
908 DefaultTrafficSelector
909 .builder(vlan100Selector)
910 .matchInPort(d1p10.port())
911 .build()
912 ));
913 assertThat(ruleS1.treatment(), is(
914 DefaultTrafficTreatment
915 .builder()
916 .popVlan()
917 .pushMpls()
918 .setMpls(MplsLabel.mplsLabel(LABEL))
919 .setOutput(d1p0.port())
920 .build()
921 ));
922
923 ruleS1 = rulesS1.stream()
924 .filter(rule -> {
925 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
926 return inPort.port().equals(d1p11.port());
927 })
928 .findFirst()
929 .get();
930 assertThat(ruleS1.selector(), is(
931 DefaultTrafficSelector
932 .builder(mpls200Selector)
933 .matchInPort(d1p11.port())
934 .build()
935 ));
936 assertThat(ruleS1.treatment(), is(
937 DefaultTrafficTreatment
938 .builder()
939 .setMpls(MplsLabel.mplsLabel(LABEL))
940 .setOutput(d1p0.port())
941 .build()
942 ));
943
944 Collection<FlowRule> rulesS2 = rules.stream()
945 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
946 .collect(Collectors.toSet());
947 assertThat(rulesS2, hasSize(2));
948 FlowRule ruleS2 = rulesS2.stream()
949 .filter(rule -> {
950 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
951 return inPort.port().equals(d2p10.port());
952 })
953 .findFirst()
954 .get();
955 assertThat(ruleS2.selector(), is(
956 DefaultTrafficSelector
957 .builder(vlan200Selector)
958 .matchInPort(d2p10.port())
959 .build()
960 ));
961 assertThat(ruleS2.treatment(), is(
962 DefaultTrafficTreatment
963 .builder()
964 .popVlan()
965 .pushMpls()
966 .setMpls(MplsLabel.mplsLabel(LABEL))
967 .setOutput(d2p1.port())
968 .build()
969 ));
970
971 ruleS2 = rulesS2.stream()
972 .filter(rule -> {
973 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
974 return inPort.port().equals(d2p0.port());
975 })
976 .findFirst()
977 .get();
978 assertThat(ruleS2.selector(), is(
979 DefaultTrafficSelector
980 .builder()
981 .matchInPort(d2p0.port())
982 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
983 .matchEthType(Ethernet.MPLS_UNICAST)
984 .build()
985 ));
986 assertThat(ruleS2.treatment(), is(
987 DefaultTrafficTreatment
988 .builder()
989 .setMpls(MplsLabel.mplsLabel(LABEL))
990 .setOutput(d2p1.port())
991 .build()
992 ));
993
994 Collection<FlowRule> rulesS3 = rules.stream()
995 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
996 .collect(Collectors.toSet());
997 assertThat(rulesS3, hasSize(1));
998 FlowRule ruleS3 = rulesS3.iterator().next();
999 assertThat(ruleS3.selector(), is(
1000 DefaultTrafficSelector
1001 .builder()
1002 .matchInPort(d3p0.port())
1003 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1004 .matchEthType(Ethernet.MPLS_UNICAST)
1005 .build()
1006 ));
1007 assertThat(ruleS3.treatment(), is(
1008 DefaultTrafficTreatment
1009 .builder()
1010 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1011 .setOutput(d3p10.port())
1012 .build()
1013 ));
1014
1015 sut.deactivate();
1016
1017 }
1018
1019 /**
1020 * We test the proper compilation of sp2mp with the VLAN
1021 * encapsulation and filtered selectors of different type.
1022 */
1023 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001024 public void testVlanEncapsulationDifferentFilterForSp() {
Pier Ventre766995d2016-10-05 22:15:56 -07001025
1026 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001027 .appId(APP_ID).selector(selector).treatment(treatment)
1028 .constraints(constraintsForVlan).links(linksForSp2Mp)
Pier Ventre766995d2016-10-05 22:15:56 -07001029 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan200Selector)))
1030 .filteredEgressPoints(ImmutableSet.of(
1031 new FilteredConnectPoint(d1p10, mpls100Selector),
1032 new FilteredConnectPoint(d1p11, vlan100Selector),
1033 new FilteredConnectPoint(d2p10, mpls200Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001034 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -07001035
1036 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001037
Pier Ventre766995d2016-10-05 22:15:56 -07001038 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1039
1040 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1041 assertThat(compiled, hasSize(1));
1042
1043 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1044 assertThat(rules, hasSize(3));
1045
1046 Collection<FlowRule> rulesS3 = rules.stream()
1047 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
1048 .collect(Collectors.toSet());
1049 assertThat(rulesS3, hasSize(1));
1050 FlowRule ruleS3 = rulesS3.iterator().next();
1051 assertThat(ruleS3.selector(), is(
1052 DefaultTrafficSelector
1053 .builder(vlan200Selector)
1054 .matchInPort(d3p10.port())
1055 .build()
1056 ));
1057 assertThat(ruleS3.treatment(), is(
1058 DefaultTrafficTreatment
1059 .builder()
1060 .setVlanId(VlanId.vlanId(LABEL))
1061 .setOutput(d3p0.port())
1062 .build()
1063 ));
1064
1065 Collection<FlowRule> rulesS2 = rules.stream()
1066 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1067 .collect(Collectors.toSet());
1068 assertThat(rulesS2, hasSize(1));
1069 FlowRule ruleS2 = rulesS2.iterator().next();
1070 assertThat(ruleS2.selector(), is(
1071 DefaultTrafficSelector
1072 .builder()
1073 .matchInPort(d2p1.port())
1074 .matchVlanId(VlanId.vlanId(LABEL))
1075 .build()
1076 ));
1077 assertThat(ruleS2.treatment(), is(
1078 DefaultTrafficTreatment
1079 .builder()
1080 .setVlanId(VlanId.vlanId(LABEL))
1081 .setOutput(d2p0.port())
1082 .popVlan()
1083 .pushMpls()
1084 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1085 .setOutput(d2p10.port())
1086 .build()
1087 ));
1088
1089 Collection<FlowRule> rulesS1 = rules.stream()
1090 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1091 .collect(Collectors.toSet());
1092 assertThat(rulesS1, hasSize(1));
1093 FlowRule ruleS1 = rulesS1.iterator().next();
1094 assertThat(ruleS1.selector(), is(
1095 DefaultTrafficSelector
1096 .builder()
1097 .matchInPort(d1p0.port())
1098 .matchVlanId(VlanId.vlanId(LABEL))
1099 .build()
1100 ));
1101 assertThat(ruleS1.treatment(), is(
1102 DefaultTrafficTreatment
1103 .builder()
1104 .popVlan()
1105 .pushMpls()
1106 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1107 .setOutput(d1p10.port())
1108 .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
1109 .setOutput(d1p11.port())
1110 .build()
1111 ));
1112
1113 sut.deactivate();
1114
1115 }
1116
1117 /**
Pier Ventre5c4a0762016-11-21 10:28:13 -08001118 * We test the proper compilation of sp2mp with trivial selector,
1119 * trivial treatment, vlan encapsulation and co-located
1120 * ingress/egress points.
Pier Ventre766995d2016-10-05 22:15:56 -07001121 */
1122 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001123 public void testCoLocatedPointsTrivialForSp() {
Pier Ventre766995d2016-10-05 22:15:56 -07001124
1125 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001126 .appId(APP_ID).selector(selector).treatment(treatment)
1127 .applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc)
Pier Ventre766995d2016-10-05 22:15:56 -07001128 .constraints(constraintsForVlan)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001129 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10)))
1130 .filteredEgressPoints(ImmutableSet.of(
1131 new FilteredConnectPoint(d1p11),
1132 new FilteredConnectPoint(d2p10),
1133 new FilteredConnectPoint(d3p10)
1134 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -07001135
1136 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001137
Pier Ventre766995d2016-10-05 22:15:56 -07001138 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1139
1140 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1141 assertThat(compiled, hasSize(1));
1142
1143 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1144 assertThat(rules, hasSize(3));
1145
1146 Collection<FlowRule> rulesS1 = rules.stream()
1147 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1148 .collect(Collectors.toSet());
1149 assertThat(rulesS1, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001150
Pier Ventre766995d2016-10-05 22:15:56 -07001151 FlowRule ruleS1 = rulesS1.iterator().next();
1152 assertThat(ruleS1.selector(), is(
1153 DefaultTrafficSelector
Pier Ventre5c4a0762016-11-21 10:28:13 -08001154 .builder(selector)
Pier Ventre766995d2016-10-05 22:15:56 -07001155 .matchInPort(d1p10.port())
1156 .build()
1157 ));
1158 assertThat(ruleS1.treatment(), is(
1159 DefaultTrafficTreatment
1160 .builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001161 .pushVlan()
Pier Ventre766995d2016-10-05 22:15:56 -07001162 .setVlanId(VlanId.vlanId(LABEL))
1163 .setOutput(d1p0.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001164 .setOutput(d1p11.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001165 .build()
1166 ));
1167
1168 Collection<FlowRule> rulesS2 = rules.stream()
1169 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1170 .collect(Collectors.toSet());
1171 assertThat(rulesS2, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001172
Pier Ventre766995d2016-10-05 22:15:56 -07001173 FlowRule ruleS2 = rulesS2.iterator().next();
1174 assertThat(ruleS2.selector(), is(
1175 DefaultTrafficSelector
1176 .builder()
1177 .matchInPort(d2p0.port())
1178 .matchVlanId(VlanId.vlanId(LABEL))
1179 .build()
1180 ));
1181 assertThat(ruleS2.treatment(), is(
1182 DefaultTrafficTreatment
1183 .builder()
1184 .setVlanId(VlanId.vlanId(LABEL))
1185 .setOutput(d2p1.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001186 .popVlan()
1187 .setOutput(d2p10.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001188 .build()
1189 ));
1190
1191 Collection<FlowRule> rulesS3 = rules.stream()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001192 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
Pier Ventre766995d2016-10-05 22:15:56 -07001193 .collect(Collectors.toSet());
1194 assertThat(rulesS3, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001195
Pier Ventre766995d2016-10-05 22:15:56 -07001196 FlowRule ruleS3 = rulesS3.iterator().next();
1197 assertThat(ruleS3.selector(), is(
1198 DefaultTrafficSelector
1199 .builder()
1200 .matchInPort(d3p0.port())
1201 .matchVlanId(VlanId.vlanId(LABEL))
1202 .build()
1203 ));
1204 assertThat(ruleS3.treatment(), is(
1205 DefaultTrafficTreatment
1206 .builder()
1207 .popVlan()
Pier Ventre766995d2016-10-05 22:15:56 -07001208 .setOutput(d3p10.port())
1209 .build()
1210 ));
1211
1212 sut.deactivate();
1213
1214 }
1215
1216 /**
Pier Ventre5c4a0762016-11-21 10:28:13 -08001217 * We test the proper compilation of mp2sp with trivial selector,
1218 * trivial treatment, mpls encapsulation and co-located
1219 * ingress/egress points.
Pier Ventre766995d2016-10-05 22:15:56 -07001220 */
1221 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001222 public void testCoLocatedPointsTrivialForMp() {
Pier Ventre766995d2016-10-05 22:15:56 -07001223
1224 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001225 .appId(APP_ID).selector(selector).treatment(treatment)
1226 .links(linksForMp2SpCoLoc).constraints(constraintsForMPLS)
1227 .filteredIngressPoints(ImmutableSet.of(
1228 new FilteredConnectPoint(d1p10),
1229 new FilteredConnectPoint(d2p10)
1230 ))
1231 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11)))
1232 .build();
1233
1234 sut.activate();
1235
1236 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1237
1238 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1239 assertThat(compiled, hasSize(1));
1240
1241 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1242 assertThat(rules, hasSize(3));
1243
1244 Collection<FlowRule> rulesS1 = rules.stream()
1245 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1246 .collect(Collectors.toSet());
1247 assertThat(rulesS1, hasSize(2));
1248
1249 FlowRule ruleS1 = rulesS1.stream()
1250 .filter(rule -> {
1251 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1252 return inPort.port().equals(d1p10.port());
1253 })
1254 .findFirst()
1255 .get();
1256 assertThat(ruleS1.selector(), is(
1257 DefaultTrafficSelector
1258 .builder()
1259 .matchInPort(d1p10.port())
1260 .build()
1261 ));
1262 assertThat(ruleS1.treatment(), is(
1263 DefaultTrafficTreatment
1264 .builder()
1265 .setOutput(d1p11.port())
1266 .build()
1267 ));
1268
1269 ruleS1 = rulesS1.stream()
1270 .filter(rule -> {
1271 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1272 return inPort.port().equals(d1p0.port());
1273 })
1274 .findFirst()
1275 .get();
1276 assertThat(ruleS1.selector(), is(
1277 DefaultTrafficSelector
1278 .builder()
1279 .matchEthType(Ethernet.MPLS_UNICAST)
1280 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1281 .matchInPort(d1p0.port())
1282 .build()
1283 ));
1284 assertThat(ruleS1.treatment(), is(
1285 DefaultTrafficTreatment
1286 .builder()
1287 .popMpls(IPV4.ethType())
1288 .setOutput(d1p11.port())
1289 .build()
1290 ));
1291
1292 Collection<FlowRule> rulesS2 = rules.stream()
1293 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1294 .collect(Collectors.toSet());
1295 assertThat(rulesS2, hasSize(1));
1296
1297 FlowRule ruleS2 = rulesS2.iterator().next();
1298 assertThat(ruleS2.selector(), is(
1299 DefaultTrafficSelector
1300 .builder()
1301 .matchInPort(d2p10.port())
1302 .build()
1303 ));
1304 assertThat(ruleS2.treatment(), is(
1305 DefaultTrafficTreatment
1306 .builder()
1307 .pushMpls()
1308 .setMpls(MplsLabel.mplsLabel(LABEL))
1309 .setOutput(d2p0.port())
1310 .build()
1311 ));
1312
1313 sut.deactivate();
1314
1315 }
1316
1317 /**
1318 * We test the proper compilation of sp2mp with trivial selector,
1319 * trivial treatment, mpls encapsulation and co-located
1320 * filtered ingress/egress points.
1321 */
1322 @Test
1323 public void testCoLocatedFilteredPointsTrivialForSp() {
1324
1325 intent = LinkCollectionIntent.builder()
1326 .appId(APP_ID).selector(selector).treatment(treatment)
1327 .applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc)
Pier Ventre766995d2016-10-05 22:15:56 -07001328 .constraints(constraintsForMPLS)
Pier Ventre766995d2016-10-05 22:15:56 -07001329 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector)))
Pier Ventre5c4a0762016-11-21 10:28:13 -08001330 .filteredEgressPoints(ImmutableSet.of(
1331 new FilteredConnectPoint(d1p11, vlan200Selector),
1332 new FilteredConnectPoint(d2p10, vlan300Selector),
1333 new FilteredConnectPoint(d3p10, vlan69Selector)
1334 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -07001335
1336 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001337
Pier Ventre766995d2016-10-05 22:15:56 -07001338 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1339
1340 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1341 assertThat(compiled, hasSize(1));
1342
1343 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1344 assertThat(rules, hasSize(3));
1345
1346 Collection<FlowRule> rulesS1 = rules.stream()
1347 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1348 .collect(Collectors.toSet());
1349 assertThat(rulesS1, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001350
Pier Ventre766995d2016-10-05 22:15:56 -07001351 FlowRule ruleS1 = rulesS1.iterator().next();
1352 assertThat(ruleS1.selector(), is(
1353 DefaultTrafficSelector
1354 .builder(vlan100Selector)
1355 .matchInPort(d1p10.port())
1356 .build()
1357 ));
1358 assertThat(ruleS1.treatment(), is(
1359 DefaultTrafficTreatment
1360 .builder()
1361 .popVlan()
1362 .pushMpls()
1363 .setMpls(MplsLabel.mplsLabel(LABEL))
1364 .setOutput(d1p0.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001365 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1366 .setOutput(d1p11.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001367 .build()
1368 ));
1369
Pier Ventre5c4a0762016-11-21 10:28:13 -08001370
Pier Ventre766995d2016-10-05 22:15:56 -07001371 Collection<FlowRule> rulesS2 = rules.stream()
1372 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1373 .collect(Collectors.toSet());
1374 assertThat(rulesS2, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001375
Pier Ventre766995d2016-10-05 22:15:56 -07001376 FlowRule ruleS2 = rulesS2.iterator().next();
1377 assertThat(ruleS2.selector(), is(
1378 DefaultTrafficSelector
1379 .builder()
1380 .matchInPort(d2p0.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001381 .matchEthType(Ethernet.MPLS_UNICAST)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001382 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
Pier Ventre766995d2016-10-05 22:15:56 -07001383 .build()
1384 ));
1385 assertThat(ruleS2.treatment(), is(
1386 DefaultTrafficTreatment
1387 .builder()
1388 .setMpls(MplsLabel.mplsLabel(LABEL))
1389 .setOutput(d2p1.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001390 .popMpls(IPV4.ethType())
1391 .pushVlan()
1392 .setVlanId(((VlanIdCriterion) vlan300Selector.getCriterion(VLAN_VID)).vlanId())
1393 .setOutput(d2p10.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001394 .build()
1395 ));
1396
Pier Ventre5c4a0762016-11-21 10:28:13 -08001397
Pier Ventre766995d2016-10-05 22:15:56 -07001398 Collection<FlowRule> rulesS3 = rules.stream()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001399 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
Pier Ventre766995d2016-10-05 22:15:56 -07001400 .collect(Collectors.toSet());
1401 assertThat(rulesS3, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001402
Pier Ventre766995d2016-10-05 22:15:56 -07001403 FlowRule ruleS3 = rulesS3.iterator().next();
1404 assertThat(ruleS3.selector(), is(
1405 DefaultTrafficSelector
1406 .builder()
1407 .matchInPort(d3p0.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001408 .matchEthType(Ethernet.MPLS_UNICAST)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001409 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
Pier Ventre766995d2016-10-05 22:15:56 -07001410 .build()
1411 ));
1412 assertThat(ruleS3.treatment(), is(
1413 DefaultTrafficTreatment
1414 .builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001415 .popMpls(IPV4.ethType())
1416 .pushVlan()
1417 .setVlanId(((VlanIdCriterion) vlan69Selector.getCriterion(VLAN_VID)).vlanId())
Pier Ventre766995d2016-10-05 22:15:56 -07001418 .setOutput(d3p10.port())
1419 .build()
1420 ));
1421
1422 sut.deactivate();
1423
1424 }
1425
Pier Ventreffe88d62016-10-13 14:34:40 -07001426 /**
Pier Ventre5c4a0762016-11-21 10:28:13 -08001427 * We test the proper compilation of mp2sp with trivial selector,
1428 * trivial treatment, vlan encapsulation and co-located
1429 * filtered ingress/egress points.
Pier Ventreffe88d62016-10-13 14:34:40 -07001430 */
1431 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001432 public void testCoLocatedFilteredPointsTrivialForMp() {
Pier Ventreffe88d62016-10-13 14:34:40 -07001433
1434 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001435 .appId(APP_ID).selector(selector).treatment(treatment).links(linksForMp2SpCoLoc)
Pier Ventreffe88d62016-10-13 14:34:40 -07001436 .constraints(constraintsForVlan)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001437 .filteredIngressPoints(ImmutableSet.of(
1438 new FilteredConnectPoint(d1p10, mpls100Selector),
1439 new FilteredConnectPoint(d2p10, mpls200Selector)
1440 ))
1441 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls69Selector)))
Pier Ventreffe88d62016-10-13 14:34:40 -07001442 .build();
1443
1444 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001445
Pier Ventreffe88d62016-10-13 14:34:40 -07001446 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1447
1448 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1449 assertThat(compiled, hasSize(1));
1450
1451 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1452 assertThat(rules, hasSize(3));
1453
1454 Collection<FlowRule> rulesS1 = rules.stream()
1455 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1456 .collect(Collectors.toSet());
Pier Ventre5c4a0762016-11-21 10:28:13 -08001457 assertThat(rulesS1, hasSize(2));
1458
1459 FlowRule ruleS1 = rulesS1.stream()
1460 .filter(rule -> {
1461 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1462 return inPort.port().equals(d1p10.port());
1463 })
1464 .findFirst()
1465 .get();
Pier Ventreffe88d62016-10-13 14:34:40 -07001466 assertThat(ruleS1.selector(), is(
1467 DefaultTrafficSelector
Pier Ventre5c4a0762016-11-21 10:28:13 -08001468 .builder(mpls100Selector)
Pier Ventreffe88d62016-10-13 14:34:40 -07001469 .matchInPort(d1p10.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001470 .build()
1471 ));
1472 assertThat(ruleS1.treatment(), is(
1473 DefaultTrafficTreatment
1474 .builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001475 .setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label())
1476 .setOutput(d1p11.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001477 .build()
1478 ));
1479
Pier Ventre5c4a0762016-11-21 10:28:13 -08001480 ruleS1 = rulesS1.stream()
1481 .filter(rule -> {
1482 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1483 return inPort.port().equals(d1p0.port());
1484 })
1485 .findFirst()
1486 .get();
1487 assertThat(ruleS1.selector(), is(
Pier Ventreffe88d62016-10-13 14:34:40 -07001488 DefaultTrafficSelector
1489 .builder()
Pier Ventreffe88d62016-10-13 14:34:40 -07001490 .matchVlanId(VlanId.vlanId(LABEL))
Pier Ventre5c4a0762016-11-21 10:28:13 -08001491 .matchInPort(d1p0.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001492 .build()
1493 ));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001494 assertThat(ruleS1.treatment(), is(
Pier Ventreffe88d62016-10-13 14:34:40 -07001495 DefaultTrafficTreatment
1496 .builder()
Pier Ventreffe88d62016-10-13 14:34:40 -07001497 .popVlan()
1498 .pushMpls()
1499 .setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001500 .setOutput(d1p11.port())
1501 .build()
1502 ));
1503
1504 Collection<FlowRule> rulesS2 = rules.stream()
1505 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1506 .collect(Collectors.toSet());
1507 assertThat(rulesS2, hasSize(1));
1508 FlowRule ruleS2 = rulesS2.iterator().next();
1509 assertThat(ruleS2.selector(), is(
1510 DefaultTrafficSelector
1511 .builder(mpls200Selector)
1512 .matchInPort(d2p10.port())
1513 .build()
1514 ));
1515 assertThat(ruleS2.treatment(), is(
1516 DefaultTrafficTreatment
1517 .builder()
1518 .popMpls(IPV4.ethType())
1519 .pushVlan()
1520 .setVlanId(VlanId.vlanId(LABEL))
1521 .setOutput(d2p0.port())
1522 .build()
1523 ));
1524
1525 sut.deactivate();
1526
1527 }
1528
1529 /**
1530 * We test the proper compilation of sp2mp with trivial selector,
1531 * trivial treatment, vlan encapsulation and co-located
1532 * different filtered ingress/egress points.
1533 */
1534 @Test
1535 public void testCoLocatedDifferentFilteredPointsTrivialForSp() {
1536
1537 intent = LinkCollectionIntent.builder()
1538 .appId(APP_ID).selector(selector).treatment(treatment)
1539 .applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc)
1540 .constraints(constraintsForVlan)
1541 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector)))
1542 .filteredEgressPoints(ImmutableSet.of(
1543 new FilteredConnectPoint(d1p11, mpls100Selector),
1544 new FilteredConnectPoint(d2p10, vlan200Selector),
1545 new FilteredConnectPoint(d3p10, mpls200Selector)
1546 )).build();
1547
1548 sut.activate();
1549
1550 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1551
1552 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1553 assertThat(compiled, hasSize(1));
1554
1555 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1556 assertThat(rules, hasSize(3));
1557
1558 Collection<FlowRule> rulesS1 = rules.stream()
1559 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1560 .collect(Collectors.toSet());
1561 assertThat(rulesS1, hasSize(1));
1562 FlowRule ruleS1 = rulesS1.iterator().next();
1563 assertThat(ruleS1.selector(), is(
1564 DefaultTrafficSelector
1565 .builder(vlan100Selector)
1566 .matchInPort(d1p10.port())
1567 .build()
1568 ));
1569 assertThat(ruleS1.treatment(), is(
1570 DefaultTrafficTreatment
1571 .builder()
1572 .setVlanId(VlanId.vlanId(LABEL))
1573 .setOutput(d1p0.port())
1574 .popVlan()
1575 .pushMpls()
1576 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1577 .setOutput(d1p11.port())
1578 .build()
1579 ));
1580
1581 Collection<FlowRule> rulesS2 = rules.stream()
1582 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1583 .collect(Collectors.toSet());
1584 assertThat(rulesS2, hasSize(1));
1585 FlowRule ruleS2 = rulesS2.iterator().next();
1586 assertThat(ruleS2.selector(), is(
1587 DefaultTrafficSelector
1588 .builder()
1589 .matchInPort(d2p0.port())
1590 .matchVlanId(VlanId.vlanId(LABEL))
1591 .build()
1592 ));
1593 assertThat(ruleS2.treatment(), is(
1594 DefaultTrafficTreatment
1595 .builder()
1596 .setVlanId(VlanId.vlanId(LABEL))
1597 .setOutput(d2p1.port())
1598 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1599 .setOutput(d2p10.port())
1600 .build()
1601 ));
1602
1603 Collection<FlowRule> rulesS3 = rules.stream()
1604 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
1605 .collect(Collectors.toSet());
1606 assertThat(rulesS3, hasSize(1));
1607 FlowRule ruleS3 = rulesS3.iterator().next();
1608 assertThat(ruleS3.selector(), is(
1609 DefaultTrafficSelector
1610 .builder()
1611 .matchVlanId(VlanId.vlanId(LABEL))
1612 .matchInPort(d3p0.port())
1613 .build()
1614 ));
1615 assertThat(ruleS3.treatment(), is(
1616 DefaultTrafficTreatment
1617 .builder()
1618 .popVlan()
1619 .pushMpls()
1620 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
Pier Ventreffe88d62016-10-13 14:34:40 -07001621 .setOutput(d3p10.port())
1622 .build()
1623 ));
1624
1625 sut.deactivate();
1626
1627 }
1628
1629 /**
Pier Ventre5c4a0762016-11-21 10:28:13 -08001630 * We test the proper compilation of mp2sp with trivial selector,
1631 * trivial treatment, mpls encapsulation and co-located
1632 * filtered ingress/egress points.
Pier Ventreffe88d62016-10-13 14:34:40 -07001633 */
1634 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001635 public void testCoLocatedDifferentFilteredPointsTrivialForMp() {
Pier Ventreffe88d62016-10-13 14:34:40 -07001636
1637 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001638 .appId(APP_ID).selector(selector).treatment(treatment)
1639 .links(linksForMp2SpCoLoc).constraints(constraintsForMPLS)
1640 .filteredIngressPoints(ImmutableSet.of(
1641 new FilteredConnectPoint(d1p10, mpls100Selector),
1642 new FilteredConnectPoint(d2p10, vlan100Selector)
1643 ))
1644 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls200Selector)))
Pier Ventreffe88d62016-10-13 14:34:40 -07001645 .build();
1646
1647 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001648
1649 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1650
1651 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1652 assertThat(compiled, hasSize(1));
1653
1654 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1655 assertThat(rules, hasSize(3));
1656
1657 Collection<FlowRule> rulesS1 = rules.stream()
1658 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1659 .collect(Collectors.toSet());
1660 assertThat(rulesS1, hasSize(2));
1661 FlowRule ruleS1 = rulesS1.stream()
1662 .filter(rule -> {
1663 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1664 return inPort.port().equals(d1p10.port());
1665 })
1666 .findFirst()
1667 .get();
1668 assertThat(ruleS1.selector(), is(
1669 DefaultTrafficSelector
1670 .builder(mpls100Selector)
1671 .matchInPort(d1p10.port())
1672 .build()
1673 ));
1674 assertThat(ruleS1.treatment(), is(
1675 DefaultTrafficTreatment
1676 .builder()
1677 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1678 .setOutput(d1p11.port())
1679 .build()
1680 ));
1681 ruleS1 = rulesS1.stream()
1682 .filter(rule -> {
1683 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1684 return inPort.port().equals(d1p0.port());
1685 })
1686 .findFirst()
1687 .get();
1688 assertThat(ruleS1.selector(), is(
1689 DefaultTrafficSelector
1690 .builder()
1691 .matchEthType(Ethernet.MPLS_UNICAST)
1692 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1693 .matchInPort(d1p0.port())
1694 .build()
1695 ));
1696 assertThat(ruleS1.treatment(), is(
1697 DefaultTrafficTreatment
1698 .builder()
1699 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1700 .setOutput(d1p11.port())
1701 .build()
1702 ));
1703
1704 Collection<FlowRule> rulesS2 = rules.stream()
1705 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1706 .collect(Collectors.toSet());
1707 assertThat(rulesS2, hasSize(1));
1708 FlowRule ruleS2 = rulesS2.iterator().next();
1709 assertThat(ruleS2.selector(), is(
1710 DefaultTrafficSelector
1711 .builder(vlan100Selector)
1712 .matchInPort(d2p10.port())
1713 .build()
1714 ));
1715 assertThat(ruleS2.treatment(), is(
1716 DefaultTrafficTreatment
1717 .builder()
1718 .popVlan()
1719 .pushMpls()
1720 .setMpls(MplsLabel.mplsLabel(LABEL))
1721 .setOutput(d2p0.port())
1722 .build()
1723 ));
1724
1725 sut.deactivate();
1726
1727 }
1728
1729 /**
1730 * We test the proper compilation of sp2mp with selector,
1731 * treatment, mpls encapsulation and co-located
1732 * different filtered ingress/egress points.
1733 */
1734 @Test
1735 public void testCoLocatedDifferentFilteredPointsNonTrivialForSp() {
1736
1737 intent = LinkCollectionIntent.builder()
1738 .appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment)
1739 .applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc)
1740 .constraints(constraintsForMPLS)
1741 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector)))
1742 .filteredEgressPoints(ImmutableSet.of(
1743 new FilteredConnectPoint(d1p11, mpls100Selector),
1744 new FilteredConnectPoint(d2p10, vlan200Selector),
1745 new FilteredConnectPoint(d3p10, mpls200Selector)
1746 )).build();
1747
1748 sut.activate();
1749
Pier Ventreffe88d62016-10-13 14:34:40 -07001750 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1751
1752 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1753 assertThat(compiled, hasSize(1));
1754
1755 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1756 assertThat(rules, hasSize(3));
1757
1758 Collection<FlowRule> rulesS1 = rules.stream()
1759 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1760 .collect(Collectors.toSet());
1761 assertThat(rulesS1, hasSize(1));
1762 FlowRule ruleS1 = rulesS1.iterator().next();
1763 assertThat(ruleS1.selector(), is(
1764 DefaultTrafficSelector
1765 .builder(ipPrefixSelector)
1766 .matchInPort(d1p10.port())
1767 .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
1768 .build()
1769 ));
1770 assertThat(ruleS1.treatment(), is(
1771 DefaultTrafficTreatment
1772 .builder()
1773 .popVlan()
1774 .pushMpls()
1775 .setMpls(MplsLabel.mplsLabel(LABEL))
1776 .setOutput(d1p0.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001777 .setEthDst(((ModEtherInstruction) ethDstTreatment
1778 .allInstructions()
1779 .stream()
1780 .filter(instruction -> instruction instanceof ModEtherInstruction)
1781 .findFirst().get()).mac())
1782 .popVlan()
1783 .pushMpls()
1784 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1785 .setOutput(d1p11.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001786 .build()
1787 ));
1788
1789 Collection<FlowRule> rulesS2 = rules.stream()
1790 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1791 .collect(Collectors.toSet());
1792 assertThat(rulesS2, hasSize(1));
1793 FlowRule ruleS2 = rulesS2.iterator().next();
1794 assertThat(ruleS2.selector(), is(
1795 DefaultTrafficSelector
1796 .builder()
1797 .matchInPort(d2p0.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001798 .matchEthType(Ethernet.MPLS_UNICAST)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001799 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
Pier Ventreffe88d62016-10-13 14:34:40 -07001800 .build()
1801 ));
1802 assertThat(ruleS2.treatment(), is(
1803 DefaultTrafficTreatment
1804 .builder()
1805 .setMpls(MplsLabel.mplsLabel(LABEL))
1806 .setOutput(d2p1.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001807 .setEthDst(((ModEtherInstruction) ethDstTreatment
1808 .allInstructions()
1809 .stream()
1810 .filter(instruction -> instruction instanceof ModEtherInstruction)
1811 .findFirst().get()).mac())
1812 .popMpls(IPV4.ethType())
1813 .pushVlan()
1814 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1815 .setOutput(d2p10.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001816 .build()
1817 ));
1818
1819 Collection<FlowRule> rulesS3 = rules.stream()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001820 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
Pier Ventreffe88d62016-10-13 14:34:40 -07001821 .collect(Collectors.toSet());
1822 assertThat(rulesS3, hasSize(1));
1823 FlowRule ruleS3 = rulesS3.iterator().next();
1824 assertThat(ruleS3.selector(), is(
1825 DefaultTrafficSelector
1826 .builder()
Pier Ventreffe88d62016-10-13 14:34:40 -07001827 .matchEthType(Ethernet.MPLS_UNICAST)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001828 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1829 .matchInPort(d3p0.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001830 .build()
1831 ));
1832 assertThat(ruleS3.treatment(), is(
1833 DefaultTrafficTreatment
1834 .builder()
1835 .setEthDst(((ModEtherInstruction) ethDstTreatment
1836 .allInstructions()
1837 .stream()
1838 .filter(instruction -> instruction instanceof ModEtherInstruction)
1839 .findFirst().get()).mac())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001840 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
Pier Ventreffe88d62016-10-13 14:34:40 -07001841 .setOutput(d3p10.port())
1842 .build()
1843 ));
1844
1845 sut.deactivate();
1846
1847 }
1848
Pier Ventre5c4a0762016-11-21 10:28:13 -08001849 /**
1850 * We test the proper compilation of mp2sp with selector,
1851 * treatment, vlan encapsulation and co-located
1852 * filtered ingress/egress points.
1853 */
1854 @Test
1855 public void testCoLocatedDifferentFilteredPointsNonTrivialForMp() {
1856
1857 intent = LinkCollectionIntent.builder()
1858 .appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment)
1859 .links(linksForMp2SpCoLoc).constraints(constraintsForVlan)
1860 .filteredIngressPoints(ImmutableSet.of(
1861 new FilteredConnectPoint(d1p10, mpls100Selector),
1862 new FilteredConnectPoint(d2p10, vlan100Selector)
1863 ))
1864 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls200Selector)))
1865 .build();
1866
1867 sut.activate();
1868
1869 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1870
1871 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1872 assertThat(compiled, hasSize(1));
1873
1874 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1875 assertThat(rules, hasSize(3));
1876
1877 Collection<FlowRule> rulesS1 = rules.stream()
1878 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1879 .collect(Collectors.toSet());
1880 assertThat(rulesS1, hasSize(2));
1881 FlowRule ruleS1 = rulesS1.stream()
1882 .filter(rule -> {
1883 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1884 return inPort.port().equals(d1p10.port());
1885 })
1886 .findFirst()
1887 .get();
1888 assertThat(ruleS1.selector(), is(
1889 DefaultTrafficSelector
1890 .builder(ipPrefixSelector)
1891 .matchInPort(d1p10.port())
1892 .matchMplsLabel(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1893 .build()
1894 ));
1895 assertThat(ruleS1.treatment(), is(
1896 DefaultTrafficTreatment
1897 .builder()
1898 .setEthDst(((ModEtherInstruction) ethDstTreatment
1899 .allInstructions()
1900 .stream()
1901 .filter(instruction -> instruction instanceof ModEtherInstruction)
1902 .findFirst().get()).mac())
1903 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1904 .setOutput(d1p11.port())
1905 .build()
1906 ));
1907
1908 ruleS1 = rulesS1.stream()
1909 .filter(rule -> {
1910 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1911 return inPort.port().equals(d1p0.port());
1912 })
1913 .findFirst()
1914 .get();
1915 assertThat(ruleS1.selector(), is(
1916 DefaultTrafficSelector
1917 .builder()
1918 .matchVlanId(VlanId.vlanId(LABEL))
1919 .matchInPort(d1p0.port())
1920 .build()
1921 ));
1922 assertThat(ruleS1.treatment(), is(
1923 DefaultTrafficTreatment
1924 .builder()
1925 .setEthDst(((ModEtherInstruction) ethDstTreatment
1926 .allInstructions()
1927 .stream()
1928 .filter(instruction -> instruction instanceof ModEtherInstruction)
1929 .findFirst().get()).mac())
1930 .popVlan()
1931 .pushMpls()
1932 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1933 .setOutput(d1p11.port())
1934 .build()
1935 ));
1936
1937 Collection<FlowRule> rulesS2 = rules.stream()
1938 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1939 .collect(Collectors.toSet());
1940 assertThat(rulesS2, hasSize(1));
1941 FlowRule ruleS2 = rulesS2.iterator().next();
1942 assertThat(ruleS2.selector(), is(
1943 DefaultTrafficSelector
1944 .builder(ipPrefixSelector)
1945 .matchInPort(d2p10.port())
1946 .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
1947 .build()
1948 ));
1949 assertThat(ruleS2.treatment(), is(
1950 DefaultTrafficTreatment
1951 .builder()
1952 .setVlanId(VlanId.vlanId(LABEL))
1953 .setOutput(d2p0.port())
1954 .build()
1955 ));
1956
1957 sut.deactivate();
1958
1959 }
1960
Pier Ventre766995d2016-10-05 22:15:56 -07001961}