blob: 267d19ea61623c80f074e645ff1f07342f903959 [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;
Pier Ventre766995d2016-10-05 22:15:56 -070020import org.junit.Before;
21import org.junit.Test;
22import org.onlab.packet.Ethernet;
23import org.onlab.packet.MplsLabel;
24import org.onlab.packet.VlanId;
25import org.onosproject.cfg.ComponentConfigAdapter;
26import org.onosproject.core.CoreService;
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020027import org.onosproject.net.DeviceId;
Pier Ventre766995d2016-10-05 22:15:56 -070028import org.onosproject.net.FilteredConnectPoint;
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020029import org.onosproject.net.domain.DomainService;
Pier Ventre766995d2016-10-05 22:15:56 -070030import org.onosproject.net.flow.DefaultTrafficSelector;
31import org.onosproject.net.flow.DefaultTrafficTreatment;
32import org.onosproject.net.flow.FlowRule;
33import org.onosproject.net.flow.criteria.MplsCriterion;
34import org.onosproject.net.flow.criteria.PortCriterion;
35import org.onosproject.net.flow.criteria.VlanIdCriterion;
36import org.onosproject.net.intent.FlowRuleIntent;
37import org.onosproject.net.intent.Intent;
38import org.onosproject.net.intent.IntentExtensionService;
39import org.onosproject.net.intent.LinkCollectionIntent;
40import org.onosproject.net.resource.MockResourceService;
41
42import java.util.Collection;
43import java.util.Collections;
44import java.util.List;
45import java.util.stream.Collectors;
46
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070047import static org.easymock.EasyMock.*;
Pier Ventre766995d2016-10-05 22:15:56 -070048import static org.hamcrest.MatcherAssert.assertThat;
49import static org.hamcrest.Matchers.hasSize;
50import static org.hamcrest.core.Is.is;
51import static org.onlab.packet.EthType.EtherType.IPV4;
Pier Ventre5c4a0762016-11-21 10:28:13 -080052import static org.onosproject.net.NetTestTools.APP_ID;
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020053import static org.onosproject.net.domain.DomainId.LOCAL;
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070054import static org.onosproject.net.flow.criteria.Criterion.Type.*;
Pier Ventre766995d2016-10-05 22:15:56 -070055import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
56
57/**
58 * This set of tests are meant to test the encapsulation
59 * in the LinkCollectionIntent.
60 */
61public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectionTest {
62
63 @Before
64 public void setUp() {
65 sut = new LinkCollectionIntentCompiler();
66 coreService = createMock(CoreService.class);
Pier Ventre5c4a0762016-11-21 10:28:13 -080067 expect(coreService.registerApplication("org.onosproject.net.intent")).andReturn(appId);
Pier Ventre766995d2016-10-05 22:15:56 -070068 sut.coreService = coreService;
69
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020070 domainService = createMock(DomainService.class);
71 expect(domainService.getDomain(anyObject(DeviceId.class))).andReturn(LOCAL).anyTimes();
72 sut.domainService = domainService;
73
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070074 super.setUp();
Pier Ventre766995d2016-10-05 22:15:56 -070075
76 intentExtensionService = createMock(IntentExtensionService.class);
77 intentExtensionService.registerCompiler(LinkCollectionIntent.class, sut);
78 intentExtensionService.unregisterCompiler(LinkCollectionIntent.class);
79
80 registrator = new IntentConfigurableRegistrator();
81 registrator.extensionService = intentExtensionService;
82 registrator.cfgService = new ComponentConfigAdapter();
83 registrator.activate();
84
85 sut.registrator = registrator;
86 sut.resourceService = new MockResourceService();
87
Yi Tseng84c5a3d2017-04-14 16:42:59 -070088 LinkCollectionCompiler.optimizeInstructions = false;
Pier Ventre81c47bf2016-11-04 07:26:22 -070089 LinkCollectionCompiler.copyTtl = false;
90
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020091 replay(coreService, domainService, intentExtensionService);
Pier Ventre766995d2016-10-05 22:15:56 -070092 }
93
Pier Ventre766995d2016-10-05 22:15:56 -070094 /**
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())
Pier Ventre766995d2016-10-05 22:15:56 -0700329 .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())
Pier Ventre766995d2016-10-05 22:15:56 -0700582 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
583 .setOutput(d1p11.port())
584 .build()
585 ));
586
587 sut.deactivate();
588
589 }
590
591 /**
592 * We test the proper compilation of mp2sp with the VLAN
593 * encapsulation, filtered selectors, intent selector and intent treatment.
594 */
595 @Test
596 public void testVlanEncapsulationNonTrivialForMp() {
597
598 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800599 .appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment)
600 .constraints(constraintsForVlan).links(linksForMp2Sp)
Pier Ventre766995d2016-10-05 22:15:56 -0700601 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls69Selector)))
602 .filteredIngressPoints(ImmutableSet.of(
603 new FilteredConnectPoint(d1p10, mpls80Selector),
604 new FilteredConnectPoint(d1p11, mpls100Selector),
605 new FilteredConnectPoint(d2p10, mpls200Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800606 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700607
608 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800609
Pier Ventre766995d2016-10-05 22:15:56 -0700610 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
611
612 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
613 assertThat(compiled, hasSize(1));
614
615 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
616 assertThat(rules, hasSize(5));
617
618 Collection<FlowRule> rulesS1 = rules.stream()
619 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
620 .collect(Collectors.toSet());
621 assertThat(rulesS1, hasSize(2));
622 FlowRule ruleS1 = rulesS1.stream()
623 .filter(rule -> {
624 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
625 return inPort.port().equals(d1p10.port());
626 })
627 .findFirst()
628 .get();
629 assertThat(ruleS1.selector(), is(
630 DefaultTrafficSelector
631 .builder(ipPrefixSelector)
632 .matchInPort(d1p10.port())
633 .matchMplsLabel(((MplsCriterion) mpls80Selector.getCriterion(MPLS_LABEL)).label())
634 .build()
635 ));
636 assertThat(ruleS1.treatment(), is(
637 DefaultTrafficTreatment
638 .builder()
639 .popMpls(IPV4.ethType())
640 .pushVlan()
641 .setVlanId(VlanId.vlanId(LABEL))
642 .setOutput(d1p0.port())
643 .build()
644 ));
645
646 ruleS1 = rulesS1.stream()
647 .filter(rule -> {
648 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
649 return inPort.port().equals(d1p11.port());
650 })
651 .findFirst()
652 .get();
653 assertThat(ruleS1.selector(), is(
654 DefaultTrafficSelector
655 .builder(ipPrefixSelector)
656 .matchInPort(d1p11.port())
657 .matchMplsLabel(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
658 .build()
659 ));
660 assertThat(ruleS1.treatment(), is(
661 DefaultTrafficTreatment
662 .builder()
663 .popMpls(IPV4.ethType())
664 .pushVlan()
665 .setVlanId(VlanId.vlanId(LABEL))
666 .setOutput(d1p0.port())
667 .build()
668 ));
669
670 Collection<FlowRule> rulesS2 = rules.stream()
671 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
672 .collect(Collectors.toSet());
673 assertThat(rulesS2, hasSize(2));
674 FlowRule ruleS2 = rulesS2.stream()
675 .filter(rule -> {
676 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
677 return inPort.port().equals(d2p10.port());
678 })
679 .findFirst()
680 .get();
681 assertThat(ruleS2.selector(), is(
682 DefaultTrafficSelector
683 .builder(ipPrefixSelector)
684 .matchInPort(d2p10.port())
685 .matchMplsLabel(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
686 .build()
687 ));
688 assertThat(ruleS2.treatment(), is(
689 DefaultTrafficTreatment
690 .builder()
691 .popMpls(IPV4.ethType())
692 .pushVlan()
693 .setVlanId(VlanId.vlanId(LABEL))
694 .setOutput(d2p1.port())
695 .build()
696 ));
697
698 ruleS2 = rulesS2.stream()
699 .filter(rule -> {
700 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
701 return inPort.port().equals(d2p0.port());
702 })
703 .findFirst()
704 .get();
705 assertThat(ruleS2.selector(), is(
706 DefaultTrafficSelector
707 .builder()
708 .matchInPort(d2p0.port())
709 .matchVlanId(VlanId.vlanId(LABEL))
710 .build()
711 ));
712 assertThat(ruleS2.treatment(), is(
713 DefaultTrafficTreatment
714 .builder()
715 .setVlanId(VlanId.vlanId(LABEL))
716 .setOutput(d2p1.port())
717 .build()
718 ));
719
720 Collection<FlowRule> rulesS3 = rules.stream()
721 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
722 .collect(Collectors.toSet());
723 assertThat(rulesS3, hasSize(1));
724 FlowRule ruleS3 = rulesS3.iterator().next();
725 assertThat(ruleS3.selector(), is(
726 DefaultTrafficSelector
727 .builder()
728 .matchInPort(d3p0.port())
729 .matchVlanId(VlanId.vlanId(LABEL))
730 .build()
731 ));
732 assertThat(ruleS3.treatment(), is(
733 DefaultTrafficTreatment
734 .builder(ethDstTreatment)
735 .popVlan()
736 .pushMpls()
737 .setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label())
738 .setOutput(d3p10.port())
739 .build()
740 ));
741
742 sut.deactivate();
743
744 }
745
746 /**
747 * We test the proper compilation of sp2mp with the MPLS
748 * encapsulation, filtered selector, intent selector, and
749 * intent treatment.
750 */
751 @Test
752 public void testMplsEncapsulationNonTrivialForSp() {
753
754 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800755 .appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment)
756 .constraints(constraintsForMPLS).links(linksForSp2Mp)
Pier Ventre766995d2016-10-05 22:15:56 -0700757 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan69Selector)))
758 .filteredEgressPoints(ImmutableSet.of(
759 new FilteredConnectPoint(d1p10, vlan100Selector),
760 new FilteredConnectPoint(d1p11, vlan200Selector),
761 new FilteredConnectPoint(d2p10, vlan300Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800762 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700763
764 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800765
Pier Ventre766995d2016-10-05 22:15:56 -0700766 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
767
768 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
769 assertThat(compiled, hasSize(1));
770
771 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
772 assertThat(rules, hasSize(3));
773
774 Collection<FlowRule> rulesS3 = rules.stream()
775 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
776 .collect(Collectors.toSet());
777 assertThat(rulesS3, hasSize(1));
778 FlowRule ruleS3 = rulesS3.iterator().next();
779 assertThat(ruleS3.selector(), is(
780 DefaultTrafficSelector
781 .builder(ipPrefixSelector)
782 .matchInPort(d3p10.port())
783 .matchVlanId(((VlanIdCriterion) vlan69Selector.getCriterion(VLAN_VID)).vlanId())
784 .build()
785 ));
786 assertThat(ruleS3.treatment(), is(
787 DefaultTrafficTreatment
788 .builder()
789 .popVlan()
790 .pushMpls()
791 .setMpls(MplsLabel.mplsLabel(LABEL))
792 .setOutput(d3p0.port())
793 .build()
794 ));
795
796 Collection<FlowRule> rulesS2 = rules.stream()
797 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
798 .collect(Collectors.toSet());
799 assertThat(rulesS2, hasSize(1));
800 FlowRule ruleS2 = rulesS2.iterator().next();
801 assertThat(ruleS2.selector(), is(
802 DefaultTrafficSelector
803 .builder()
804 .matchInPort(d2p1.port())
805 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
806 .matchEthType(Ethernet.MPLS_UNICAST)
807 .build()
808 ));
809 assertThat(ruleS2.treatment(), is(
810 DefaultTrafficTreatment
811 .builder()
812 .setMpls(MplsLabel.mplsLabel(LABEL))
813 .setOutput(d2p0.port())
814 .setEthDst(((ModEtherInstruction) ethDstTreatment
815 .allInstructions()
816 .stream()
817 .filter(instruction -> instruction instanceof ModEtherInstruction)
818 .findFirst().get()).mac())
819 .popMpls(IPV4.ethType())
820 .pushVlan()
821 .setVlanId(((VlanIdCriterion) vlan300Selector.getCriterion(VLAN_VID)).vlanId())
822 .setOutput(d2p10.port())
823 .build()
824 ));
825
826 Collection<FlowRule> rulesS1 = rules.stream()
827 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
828 .collect(Collectors.toSet());
829 assertThat(rulesS1, hasSize(1));
830 FlowRule ruleS1 = rulesS1.iterator().next();
831 assertThat(ruleS1.selector(), is(
832 DefaultTrafficSelector
833 .builder()
834 .matchInPort(d1p0.port())
835 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
836 .matchEthType(Ethernet.MPLS_UNICAST)
837 .build()
838 ));
839 assertThat(ruleS1.treatment(), is(
840 DefaultTrafficTreatment
841 .builder()
842 .setEthDst(((ModEtherInstruction) ethDstTreatment
843 .allInstructions()
844 .stream()
845 .filter(instruction -> instruction instanceof ModEtherInstruction)
846 .findFirst().get()).mac())
847 .popMpls(IPV4.ethType())
848 .pushVlan()
849 .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
850 .setOutput(d1p10.port())
851 .setEthDst(((ModEtherInstruction) ethDstTreatment
852 .allInstructions()
853 .stream()
854 .filter(instruction -> instruction instanceof ModEtherInstruction)
855 .findFirst().get()).mac())
Pier Ventre766995d2016-10-05 22:15:56 -0700856 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
857 .setOutput(d1p11.port())
858 .build()
859 ));
860
861 sut.deactivate();
862
863 }
864
865 /**
866 * We test the proper compilation of mp2sp with the MPLS
867 * encapsulation and filtered selectors of different type.
868 */
869 @Test
870 public void testMplsEncapsulationDifferentFilterForMp() {
871
872 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -0800873 .appId(APP_ID).selector(selector).treatment(treatment)
874 .constraints(constraintsForMPLS).links(linksForMp2Sp)
Pier Ventre766995d2016-10-05 22:15:56 -0700875 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls100Selector)))
876 .filteredIngressPoints(ImmutableSet.of(
877 new FilteredConnectPoint(d1p10, vlan100Selector),
878 new FilteredConnectPoint(d1p11, mpls200Selector),
879 new FilteredConnectPoint(d2p10, vlan200Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -0800880 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -0700881
882 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -0800883
Pier Ventre766995d2016-10-05 22:15:56 -0700884 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
885
886 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
887 assertThat(compiled, hasSize(1));
888
889 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
890 assertThat(rules, hasSize(5));
891
892 Collection<FlowRule> rulesS1 = rules.stream()
893 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
894 .collect(Collectors.toSet());
895 assertThat(rulesS1, hasSize(2));
896 FlowRule ruleS1 = rulesS1.stream()
897 .filter(rule -> {
898 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
899 return inPort.port().equals(d1p10.port());
900 })
901 .findFirst()
902 .get();
903 assertThat(ruleS1.selector(), is(
904 DefaultTrafficSelector
905 .builder(vlan100Selector)
906 .matchInPort(d1p10.port())
907 .build()
908 ));
909 assertThat(ruleS1.treatment(), is(
910 DefaultTrafficTreatment
911 .builder()
912 .popVlan()
913 .pushMpls()
914 .setMpls(MplsLabel.mplsLabel(LABEL))
915 .setOutput(d1p0.port())
916 .build()
917 ));
918
919 ruleS1 = rulesS1.stream()
920 .filter(rule -> {
921 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
922 return inPort.port().equals(d1p11.port());
923 })
924 .findFirst()
925 .get();
926 assertThat(ruleS1.selector(), is(
927 DefaultTrafficSelector
928 .builder(mpls200Selector)
929 .matchInPort(d1p11.port())
930 .build()
931 ));
932 assertThat(ruleS1.treatment(), is(
933 DefaultTrafficTreatment
934 .builder()
935 .setMpls(MplsLabel.mplsLabel(LABEL))
936 .setOutput(d1p0.port())
937 .build()
938 ));
939
940 Collection<FlowRule> rulesS2 = rules.stream()
941 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
942 .collect(Collectors.toSet());
943 assertThat(rulesS2, hasSize(2));
944 FlowRule ruleS2 = rulesS2.stream()
945 .filter(rule -> {
946 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
947 return inPort.port().equals(d2p10.port());
948 })
949 .findFirst()
950 .get();
951 assertThat(ruleS2.selector(), is(
952 DefaultTrafficSelector
953 .builder(vlan200Selector)
954 .matchInPort(d2p10.port())
955 .build()
956 ));
957 assertThat(ruleS2.treatment(), is(
958 DefaultTrafficTreatment
959 .builder()
960 .popVlan()
961 .pushMpls()
962 .setMpls(MplsLabel.mplsLabel(LABEL))
963 .setOutput(d2p1.port())
964 .build()
965 ));
966
967 ruleS2 = rulesS2.stream()
968 .filter(rule -> {
969 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
970 return inPort.port().equals(d2p0.port());
971 })
972 .findFirst()
973 .get();
974 assertThat(ruleS2.selector(), is(
975 DefaultTrafficSelector
976 .builder()
977 .matchInPort(d2p0.port())
978 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
979 .matchEthType(Ethernet.MPLS_UNICAST)
980 .build()
981 ));
982 assertThat(ruleS2.treatment(), is(
983 DefaultTrafficTreatment
984 .builder()
985 .setMpls(MplsLabel.mplsLabel(LABEL))
986 .setOutput(d2p1.port())
987 .build()
988 ));
989
990 Collection<FlowRule> rulesS3 = rules.stream()
991 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
992 .collect(Collectors.toSet());
993 assertThat(rulesS3, hasSize(1));
994 FlowRule ruleS3 = rulesS3.iterator().next();
995 assertThat(ruleS3.selector(), is(
996 DefaultTrafficSelector
997 .builder()
998 .matchInPort(d3p0.port())
999 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1000 .matchEthType(Ethernet.MPLS_UNICAST)
1001 .build()
1002 ));
1003 assertThat(ruleS3.treatment(), is(
1004 DefaultTrafficTreatment
1005 .builder()
1006 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1007 .setOutput(d3p10.port())
1008 .build()
1009 ));
1010
1011 sut.deactivate();
1012
1013 }
1014
1015 /**
1016 * We test the proper compilation of sp2mp with the VLAN
1017 * encapsulation and filtered selectors of different type.
1018 */
1019 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001020 public void testVlanEncapsulationDifferentFilterForSp() {
Pier Ventre766995d2016-10-05 22:15:56 -07001021
1022 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001023 .appId(APP_ID).selector(selector).treatment(treatment)
1024 .constraints(constraintsForVlan).links(linksForSp2Mp)
Pier Ventre766995d2016-10-05 22:15:56 -07001025 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan200Selector)))
1026 .filteredEgressPoints(ImmutableSet.of(
1027 new FilteredConnectPoint(d1p10, mpls100Selector),
1028 new FilteredConnectPoint(d1p11, vlan100Selector),
1029 new FilteredConnectPoint(d2p10, mpls200Selector)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001030 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -07001031
1032 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001033
Pier Ventre766995d2016-10-05 22:15:56 -07001034 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1035
1036 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1037 assertThat(compiled, hasSize(1));
1038
1039 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1040 assertThat(rules, hasSize(3));
1041
1042 Collection<FlowRule> rulesS3 = rules.stream()
1043 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
1044 .collect(Collectors.toSet());
1045 assertThat(rulesS3, hasSize(1));
1046 FlowRule ruleS3 = rulesS3.iterator().next();
1047 assertThat(ruleS3.selector(), is(
1048 DefaultTrafficSelector
1049 .builder(vlan200Selector)
1050 .matchInPort(d3p10.port())
1051 .build()
1052 ));
1053 assertThat(ruleS3.treatment(), is(
1054 DefaultTrafficTreatment
1055 .builder()
1056 .setVlanId(VlanId.vlanId(LABEL))
1057 .setOutput(d3p0.port())
1058 .build()
1059 ));
1060
1061 Collection<FlowRule> rulesS2 = rules.stream()
1062 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1063 .collect(Collectors.toSet());
1064 assertThat(rulesS2, hasSize(1));
1065 FlowRule ruleS2 = rulesS2.iterator().next();
1066 assertThat(ruleS2.selector(), is(
1067 DefaultTrafficSelector
1068 .builder()
1069 .matchInPort(d2p1.port())
1070 .matchVlanId(VlanId.vlanId(LABEL))
1071 .build()
1072 ));
1073 assertThat(ruleS2.treatment(), is(
1074 DefaultTrafficTreatment
1075 .builder()
1076 .setVlanId(VlanId.vlanId(LABEL))
1077 .setOutput(d2p0.port())
1078 .popVlan()
1079 .pushMpls()
1080 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1081 .setOutput(d2p10.port())
1082 .build()
1083 ));
1084
1085 Collection<FlowRule> rulesS1 = rules.stream()
1086 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1087 .collect(Collectors.toSet());
1088 assertThat(rulesS1, hasSize(1));
1089 FlowRule ruleS1 = rulesS1.iterator().next();
1090 assertThat(ruleS1.selector(), is(
1091 DefaultTrafficSelector
1092 .builder()
1093 .matchInPort(d1p0.port())
1094 .matchVlanId(VlanId.vlanId(LABEL))
1095 .build()
1096 ));
1097 assertThat(ruleS1.treatment(), is(
1098 DefaultTrafficTreatment
1099 .builder()
Yi Tseng84c5a3d2017-04-14 16:42:59 -07001100 .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
1101 .setOutput(d1p11.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001102 .popVlan()
1103 .pushMpls()
1104 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1105 .setOutput(d1p10.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001106 .build()
1107 ));
1108
1109 sut.deactivate();
1110
1111 }
1112
1113 /**
Pier Ventre5c4a0762016-11-21 10:28:13 -08001114 * We test the proper compilation of sp2mp with trivial selector,
1115 * trivial treatment, vlan encapsulation and co-located
1116 * ingress/egress points.
Pier Ventre766995d2016-10-05 22:15:56 -07001117 */
1118 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001119 public void testCoLocatedPointsTrivialForSp() {
Pier Ventre766995d2016-10-05 22:15:56 -07001120
1121 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001122 .appId(APP_ID).selector(selector).treatment(treatment)
1123 .applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc)
Pier Ventre766995d2016-10-05 22:15:56 -07001124 .constraints(constraintsForVlan)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001125 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10)))
1126 .filteredEgressPoints(ImmutableSet.of(
1127 new FilteredConnectPoint(d1p11),
1128 new FilteredConnectPoint(d2p10),
1129 new FilteredConnectPoint(d3p10)
1130 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -07001131
1132 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001133
Pier Ventre766995d2016-10-05 22:15:56 -07001134 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1135
1136 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1137 assertThat(compiled, hasSize(1));
1138
1139 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1140 assertThat(rules, hasSize(3));
1141
1142 Collection<FlowRule> rulesS1 = rules.stream()
1143 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1144 .collect(Collectors.toSet());
1145 assertThat(rulesS1, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001146
Pier Ventre766995d2016-10-05 22:15:56 -07001147 FlowRule ruleS1 = rulesS1.iterator().next();
1148 assertThat(ruleS1.selector(), is(
1149 DefaultTrafficSelector
Pier Ventre5c4a0762016-11-21 10:28:13 -08001150 .builder(selector)
Pier Ventre766995d2016-10-05 22:15:56 -07001151 .matchInPort(d1p10.port())
1152 .build()
1153 ));
1154 assertThat(ruleS1.treatment(), is(
1155 DefaultTrafficTreatment
1156 .builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001157 .pushVlan()
Pier Ventre766995d2016-10-05 22:15:56 -07001158 .setVlanId(VlanId.vlanId(LABEL))
1159 .setOutput(d1p0.port())
Yi Tseng84c5a3d2017-04-14 16:42:59 -07001160 .popVlan()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001161 .setOutput(d1p11.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001162 .build()
1163 ));
1164
1165 Collection<FlowRule> rulesS2 = rules.stream()
1166 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1167 .collect(Collectors.toSet());
1168 assertThat(rulesS2, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001169
Pier Ventre766995d2016-10-05 22:15:56 -07001170 FlowRule ruleS2 = rulesS2.iterator().next();
1171 assertThat(ruleS2.selector(), is(
1172 DefaultTrafficSelector
1173 .builder()
1174 .matchInPort(d2p0.port())
1175 .matchVlanId(VlanId.vlanId(LABEL))
1176 .build()
1177 ));
1178 assertThat(ruleS2.treatment(), is(
1179 DefaultTrafficTreatment
1180 .builder()
1181 .setVlanId(VlanId.vlanId(LABEL))
1182 .setOutput(d2p1.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001183 .popVlan()
1184 .setOutput(d2p10.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001185 .build()
1186 ));
1187
1188 Collection<FlowRule> rulesS3 = rules.stream()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001189 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
Pier Ventre766995d2016-10-05 22:15:56 -07001190 .collect(Collectors.toSet());
1191 assertThat(rulesS3, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001192
Pier Ventre766995d2016-10-05 22:15:56 -07001193 FlowRule ruleS3 = rulesS3.iterator().next();
1194 assertThat(ruleS3.selector(), is(
1195 DefaultTrafficSelector
1196 .builder()
1197 .matchInPort(d3p0.port())
1198 .matchVlanId(VlanId.vlanId(LABEL))
1199 .build()
1200 ));
1201 assertThat(ruleS3.treatment(), is(
1202 DefaultTrafficTreatment
1203 .builder()
1204 .popVlan()
Pier Ventre766995d2016-10-05 22:15:56 -07001205 .setOutput(d3p10.port())
1206 .build()
1207 ));
1208
1209 sut.deactivate();
1210
1211 }
1212
1213 /**
Pier Ventre5c4a0762016-11-21 10:28:13 -08001214 * We test the proper compilation of mp2sp with trivial selector,
1215 * trivial treatment, mpls encapsulation and co-located
1216 * ingress/egress points.
Pier Ventre766995d2016-10-05 22:15:56 -07001217 */
1218 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001219 public void testCoLocatedPointsTrivialForMp() {
Pier Ventre766995d2016-10-05 22:15:56 -07001220
1221 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001222 .appId(APP_ID).selector(selector).treatment(treatment)
1223 .links(linksForMp2SpCoLoc).constraints(constraintsForMPLS)
1224 .filteredIngressPoints(ImmutableSet.of(
1225 new FilteredConnectPoint(d1p10),
1226 new FilteredConnectPoint(d2p10)
1227 ))
1228 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11)))
1229 .build();
1230
1231 sut.activate();
1232
1233 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1234
1235 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1236 assertThat(compiled, hasSize(1));
1237
1238 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1239 assertThat(rules, hasSize(3));
1240
1241 Collection<FlowRule> rulesS1 = rules.stream()
1242 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1243 .collect(Collectors.toSet());
1244 assertThat(rulesS1, hasSize(2));
1245
1246 FlowRule ruleS1 = rulesS1.stream()
1247 .filter(rule -> {
1248 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1249 return inPort.port().equals(d1p10.port());
1250 })
1251 .findFirst()
1252 .get();
1253 assertThat(ruleS1.selector(), is(
1254 DefaultTrafficSelector
1255 .builder()
1256 .matchInPort(d1p10.port())
1257 .build()
1258 ));
1259 assertThat(ruleS1.treatment(), is(
1260 DefaultTrafficTreatment
1261 .builder()
1262 .setOutput(d1p11.port())
1263 .build()
1264 ));
1265
1266 ruleS1 = rulesS1.stream()
1267 .filter(rule -> {
1268 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1269 return inPort.port().equals(d1p0.port());
1270 })
1271 .findFirst()
1272 .get();
1273 assertThat(ruleS1.selector(), is(
1274 DefaultTrafficSelector
1275 .builder()
1276 .matchEthType(Ethernet.MPLS_UNICAST)
1277 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1278 .matchInPort(d1p0.port())
1279 .build()
1280 ));
1281 assertThat(ruleS1.treatment(), is(
1282 DefaultTrafficTreatment
1283 .builder()
1284 .popMpls(IPV4.ethType())
1285 .setOutput(d1p11.port())
1286 .build()
1287 ));
1288
1289 Collection<FlowRule> rulesS2 = rules.stream()
1290 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1291 .collect(Collectors.toSet());
1292 assertThat(rulesS2, hasSize(1));
1293
1294 FlowRule ruleS2 = rulesS2.iterator().next();
1295 assertThat(ruleS2.selector(), is(
1296 DefaultTrafficSelector
1297 .builder()
1298 .matchInPort(d2p10.port())
1299 .build()
1300 ));
1301 assertThat(ruleS2.treatment(), is(
1302 DefaultTrafficTreatment
1303 .builder()
1304 .pushMpls()
1305 .setMpls(MplsLabel.mplsLabel(LABEL))
1306 .setOutput(d2p0.port())
1307 .build()
1308 ));
1309
1310 sut.deactivate();
1311
1312 }
1313
1314 /**
1315 * We test the proper compilation of sp2mp with trivial selector,
1316 * trivial treatment, mpls encapsulation and co-located
1317 * filtered ingress/egress points.
1318 */
1319 @Test
1320 public void testCoLocatedFilteredPointsTrivialForSp() {
1321
1322 intent = LinkCollectionIntent.builder()
1323 .appId(APP_ID).selector(selector).treatment(treatment)
1324 .applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc)
Pier Ventre766995d2016-10-05 22:15:56 -07001325 .constraints(constraintsForMPLS)
Pier Ventre766995d2016-10-05 22:15:56 -07001326 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector)))
Pier Ventre5c4a0762016-11-21 10:28:13 -08001327 .filteredEgressPoints(ImmutableSet.of(
1328 new FilteredConnectPoint(d1p11, vlan200Selector),
1329 new FilteredConnectPoint(d2p10, vlan300Selector),
1330 new FilteredConnectPoint(d3p10, vlan69Selector)
1331 )).build();
Pier Ventre766995d2016-10-05 22:15:56 -07001332
1333 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001334
Pier Ventre766995d2016-10-05 22:15:56 -07001335 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1336
1337 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1338 assertThat(compiled, hasSize(1));
1339
1340 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1341 assertThat(rules, hasSize(3));
1342
1343 Collection<FlowRule> rulesS1 = rules.stream()
1344 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1345 .collect(Collectors.toSet());
1346 assertThat(rulesS1, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001347
Pier Ventre766995d2016-10-05 22:15:56 -07001348 FlowRule ruleS1 = rulesS1.iterator().next();
1349 assertThat(ruleS1.selector(), is(
1350 DefaultTrafficSelector
1351 .builder(vlan100Selector)
1352 .matchInPort(d1p10.port())
1353 .build()
1354 ));
1355 assertThat(ruleS1.treatment(), is(
1356 DefaultTrafficTreatment
1357 .builder()
1358 .popVlan()
1359 .pushMpls()
1360 .setMpls(MplsLabel.mplsLabel(LABEL))
1361 .setOutput(d1p0.port())
Yi Tseng84c5a3d2017-04-14 16:42:59 -07001362 .popMpls(IPV4.ethType())
1363 .pushVlan()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001364 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1365 .setOutput(d1p11.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001366 .build()
1367 ));
1368
Pier Ventre5c4a0762016-11-21 10:28:13 -08001369
Pier Ventre766995d2016-10-05 22:15:56 -07001370 Collection<FlowRule> rulesS2 = rules.stream()
1371 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1372 .collect(Collectors.toSet());
1373 assertThat(rulesS2, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001374
Pier Ventre766995d2016-10-05 22:15:56 -07001375 FlowRule ruleS2 = rulesS2.iterator().next();
1376 assertThat(ruleS2.selector(), is(
1377 DefaultTrafficSelector
1378 .builder()
1379 .matchInPort(d2p0.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001380 .matchEthType(Ethernet.MPLS_UNICAST)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001381 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
Pier Ventre766995d2016-10-05 22:15:56 -07001382 .build()
1383 ));
1384 assertThat(ruleS2.treatment(), is(
1385 DefaultTrafficTreatment
1386 .builder()
1387 .setMpls(MplsLabel.mplsLabel(LABEL))
1388 .setOutput(d2p1.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001389 .popMpls(IPV4.ethType())
1390 .pushVlan()
1391 .setVlanId(((VlanIdCriterion) vlan300Selector.getCriterion(VLAN_VID)).vlanId())
1392 .setOutput(d2p10.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001393 .build()
1394 ));
1395
Pier Ventre5c4a0762016-11-21 10:28:13 -08001396
Pier Ventre766995d2016-10-05 22:15:56 -07001397 Collection<FlowRule> rulesS3 = rules.stream()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001398 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
Pier Ventre766995d2016-10-05 22:15:56 -07001399 .collect(Collectors.toSet());
1400 assertThat(rulesS3, hasSize(1));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001401
Pier Ventre766995d2016-10-05 22:15:56 -07001402 FlowRule ruleS3 = rulesS3.iterator().next();
1403 assertThat(ruleS3.selector(), is(
1404 DefaultTrafficSelector
1405 .builder()
1406 .matchInPort(d3p0.port())
Pier Ventre766995d2016-10-05 22:15:56 -07001407 .matchEthType(Ethernet.MPLS_UNICAST)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001408 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
Pier Ventre766995d2016-10-05 22:15:56 -07001409 .build()
1410 ));
1411 assertThat(ruleS3.treatment(), is(
1412 DefaultTrafficTreatment
1413 .builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001414 .popMpls(IPV4.ethType())
1415 .pushVlan()
1416 .setVlanId(((VlanIdCriterion) vlan69Selector.getCriterion(VLAN_VID)).vlanId())
Pier Ventre766995d2016-10-05 22:15:56 -07001417 .setOutput(d3p10.port())
1418 .build()
1419 ));
1420
1421 sut.deactivate();
1422
1423 }
1424
Pier Ventreffe88d62016-10-13 14:34:40 -07001425 /**
Pier Ventre5c4a0762016-11-21 10:28:13 -08001426 * We test the proper compilation of mp2sp with trivial selector,
1427 * trivial treatment, vlan encapsulation and co-located
1428 * filtered ingress/egress points.
Pier Ventreffe88d62016-10-13 14:34:40 -07001429 */
1430 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001431 public void testCoLocatedFilteredPointsTrivialForMp() {
Pier Ventreffe88d62016-10-13 14:34:40 -07001432
1433 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001434 .appId(APP_ID).selector(selector).treatment(treatment).links(linksForMp2SpCoLoc)
Pier Ventreffe88d62016-10-13 14:34:40 -07001435 .constraints(constraintsForVlan)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001436 .filteredIngressPoints(ImmutableSet.of(
1437 new FilteredConnectPoint(d1p10, mpls100Selector),
1438 new FilteredConnectPoint(d2p10, mpls200Selector)
1439 ))
1440 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls69Selector)))
Pier Ventreffe88d62016-10-13 14:34:40 -07001441 .build();
1442
1443 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001444
Pier Ventreffe88d62016-10-13 14:34:40 -07001445 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1446
1447 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1448 assertThat(compiled, hasSize(1));
1449
1450 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1451 assertThat(rules, hasSize(3));
1452
1453 Collection<FlowRule> rulesS1 = rules.stream()
1454 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1455 .collect(Collectors.toSet());
Pier Ventre5c4a0762016-11-21 10:28:13 -08001456 assertThat(rulesS1, hasSize(2));
1457
1458 FlowRule ruleS1 = rulesS1.stream()
1459 .filter(rule -> {
1460 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1461 return inPort.port().equals(d1p10.port());
1462 })
1463 .findFirst()
1464 .get();
Pier Ventreffe88d62016-10-13 14:34:40 -07001465 assertThat(ruleS1.selector(), is(
1466 DefaultTrafficSelector
Pier Ventre5c4a0762016-11-21 10:28:13 -08001467 .builder(mpls100Selector)
Pier Ventreffe88d62016-10-13 14:34:40 -07001468 .matchInPort(d1p10.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001469 .build()
1470 ));
1471 assertThat(ruleS1.treatment(), is(
1472 DefaultTrafficTreatment
1473 .builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001474 .setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label())
1475 .setOutput(d1p11.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001476 .build()
1477 ));
1478
Pier Ventre5c4a0762016-11-21 10:28:13 -08001479 ruleS1 = rulesS1.stream()
1480 .filter(rule -> {
1481 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1482 return inPort.port().equals(d1p0.port());
1483 })
1484 .findFirst()
1485 .get();
1486 assertThat(ruleS1.selector(), is(
Pier Ventreffe88d62016-10-13 14:34:40 -07001487 DefaultTrafficSelector
1488 .builder()
Pier Ventreffe88d62016-10-13 14:34:40 -07001489 .matchVlanId(VlanId.vlanId(LABEL))
Pier Ventre5c4a0762016-11-21 10:28:13 -08001490 .matchInPort(d1p0.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001491 .build()
1492 ));
Pier Ventre5c4a0762016-11-21 10:28:13 -08001493 assertThat(ruleS1.treatment(), is(
Pier Ventreffe88d62016-10-13 14:34:40 -07001494 DefaultTrafficTreatment
1495 .builder()
Pier Ventreffe88d62016-10-13 14:34:40 -07001496 .popVlan()
1497 .pushMpls()
1498 .setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001499 .setOutput(d1p11.port())
1500 .build()
1501 ));
1502
1503 Collection<FlowRule> rulesS2 = rules.stream()
1504 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1505 .collect(Collectors.toSet());
1506 assertThat(rulesS2, hasSize(1));
1507 FlowRule ruleS2 = rulesS2.iterator().next();
1508 assertThat(ruleS2.selector(), is(
1509 DefaultTrafficSelector
1510 .builder(mpls200Selector)
1511 .matchInPort(d2p10.port())
1512 .build()
1513 ));
1514 assertThat(ruleS2.treatment(), is(
1515 DefaultTrafficTreatment
1516 .builder()
1517 .popMpls(IPV4.ethType())
1518 .pushVlan()
1519 .setVlanId(VlanId.vlanId(LABEL))
1520 .setOutput(d2p0.port())
1521 .build()
1522 ));
1523
1524 sut.deactivate();
1525
1526 }
1527
1528 /**
1529 * We test the proper compilation of sp2mp with trivial selector,
1530 * trivial treatment, vlan encapsulation and co-located
1531 * different filtered ingress/egress points.
1532 */
1533 @Test
1534 public void testCoLocatedDifferentFilteredPointsTrivialForSp() {
1535
1536 intent = LinkCollectionIntent.builder()
1537 .appId(APP_ID).selector(selector).treatment(treatment)
1538 .applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc)
1539 .constraints(constraintsForVlan)
1540 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector)))
1541 .filteredEgressPoints(ImmutableSet.of(
1542 new FilteredConnectPoint(d1p11, mpls100Selector),
1543 new FilteredConnectPoint(d2p10, vlan200Selector),
1544 new FilteredConnectPoint(d3p10, mpls200Selector)
1545 )).build();
1546
1547 sut.activate();
1548
1549 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1550
1551 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1552 assertThat(compiled, hasSize(1));
1553
1554 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1555 assertThat(rules, hasSize(3));
1556
1557 Collection<FlowRule> rulesS1 = rules.stream()
1558 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1559 .collect(Collectors.toSet());
1560 assertThat(rulesS1, hasSize(1));
1561 FlowRule ruleS1 = rulesS1.iterator().next();
1562 assertThat(ruleS1.selector(), is(
1563 DefaultTrafficSelector
1564 .builder(vlan100Selector)
1565 .matchInPort(d1p10.port())
1566 .build()
1567 ));
1568 assertThat(ruleS1.treatment(), is(
1569 DefaultTrafficTreatment
1570 .builder()
1571 .setVlanId(VlanId.vlanId(LABEL))
1572 .setOutput(d1p0.port())
1573 .popVlan()
1574 .pushMpls()
1575 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1576 .setOutput(d1p11.port())
1577 .build()
1578 ));
1579
1580 Collection<FlowRule> rulesS2 = rules.stream()
1581 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1582 .collect(Collectors.toSet());
1583 assertThat(rulesS2, hasSize(1));
1584 FlowRule ruleS2 = rulesS2.iterator().next();
1585 assertThat(ruleS2.selector(), is(
1586 DefaultTrafficSelector
1587 .builder()
1588 .matchInPort(d2p0.port())
1589 .matchVlanId(VlanId.vlanId(LABEL))
1590 .build()
1591 ));
1592 assertThat(ruleS2.treatment(), is(
1593 DefaultTrafficTreatment
1594 .builder()
1595 .setVlanId(VlanId.vlanId(LABEL))
1596 .setOutput(d2p1.port())
1597 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1598 .setOutput(d2p10.port())
1599 .build()
1600 ));
1601
1602 Collection<FlowRule> rulesS3 = rules.stream()
1603 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
1604 .collect(Collectors.toSet());
1605 assertThat(rulesS3, hasSize(1));
1606 FlowRule ruleS3 = rulesS3.iterator().next();
1607 assertThat(ruleS3.selector(), is(
1608 DefaultTrafficSelector
1609 .builder()
1610 .matchVlanId(VlanId.vlanId(LABEL))
1611 .matchInPort(d3p0.port())
1612 .build()
1613 ));
1614 assertThat(ruleS3.treatment(), is(
1615 DefaultTrafficTreatment
1616 .builder()
1617 .popVlan()
1618 .pushMpls()
1619 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
Pier Ventreffe88d62016-10-13 14:34:40 -07001620 .setOutput(d3p10.port())
1621 .build()
1622 ));
1623
1624 sut.deactivate();
1625
1626 }
1627
1628 /**
Pier Ventre5c4a0762016-11-21 10:28:13 -08001629 * We test the proper compilation of mp2sp with trivial selector,
1630 * trivial treatment, mpls encapsulation and co-located
1631 * filtered ingress/egress points.
Pier Ventreffe88d62016-10-13 14:34:40 -07001632 */
1633 @Test
Pier Ventre5c4a0762016-11-21 10:28:13 -08001634 public void testCoLocatedDifferentFilteredPointsTrivialForMp() {
Pier Ventreffe88d62016-10-13 14:34:40 -07001635
1636 intent = LinkCollectionIntent.builder()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001637 .appId(APP_ID).selector(selector).treatment(treatment)
1638 .links(linksForMp2SpCoLoc).constraints(constraintsForMPLS)
1639 .filteredIngressPoints(ImmutableSet.of(
1640 new FilteredConnectPoint(d1p10, mpls100Selector),
1641 new FilteredConnectPoint(d2p10, vlan100Selector)
1642 ))
1643 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls200Selector)))
Pier Ventreffe88d62016-10-13 14:34:40 -07001644 .build();
1645
1646 sut.activate();
Pier Ventre5c4a0762016-11-21 10:28:13 -08001647
1648 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1649
1650 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1651 assertThat(compiled, hasSize(1));
1652
1653 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1654 assertThat(rules, hasSize(3));
1655
1656 Collection<FlowRule> rulesS1 = rules.stream()
1657 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1658 .collect(Collectors.toSet());
1659 assertThat(rulesS1, hasSize(2));
1660 FlowRule ruleS1 = rulesS1.stream()
1661 .filter(rule -> {
1662 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1663 return inPort.port().equals(d1p10.port());
1664 })
1665 .findFirst()
1666 .get();
1667 assertThat(ruleS1.selector(), is(
1668 DefaultTrafficSelector
1669 .builder(mpls100Selector)
1670 .matchInPort(d1p10.port())
1671 .build()
1672 ));
1673 assertThat(ruleS1.treatment(), is(
1674 DefaultTrafficTreatment
1675 .builder()
1676 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1677 .setOutput(d1p11.port())
1678 .build()
1679 ));
1680 ruleS1 = rulesS1.stream()
1681 .filter(rule -> {
1682 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1683 return inPort.port().equals(d1p0.port());
1684 })
1685 .findFirst()
1686 .get();
1687 assertThat(ruleS1.selector(), is(
1688 DefaultTrafficSelector
1689 .builder()
1690 .matchEthType(Ethernet.MPLS_UNICAST)
1691 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1692 .matchInPort(d1p0.port())
1693 .build()
1694 ));
1695 assertThat(ruleS1.treatment(), is(
1696 DefaultTrafficTreatment
1697 .builder()
1698 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1699 .setOutput(d1p11.port())
1700 .build()
1701 ));
1702
1703 Collection<FlowRule> rulesS2 = rules.stream()
1704 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1705 .collect(Collectors.toSet());
1706 assertThat(rulesS2, hasSize(1));
1707 FlowRule ruleS2 = rulesS2.iterator().next();
1708 assertThat(ruleS2.selector(), is(
1709 DefaultTrafficSelector
1710 .builder(vlan100Selector)
1711 .matchInPort(d2p10.port())
1712 .build()
1713 ));
1714 assertThat(ruleS2.treatment(), is(
1715 DefaultTrafficTreatment
1716 .builder()
1717 .popVlan()
1718 .pushMpls()
1719 .setMpls(MplsLabel.mplsLabel(LABEL))
1720 .setOutput(d2p0.port())
1721 .build()
1722 ));
1723
1724 sut.deactivate();
1725
1726 }
1727
1728 /**
1729 * We test the proper compilation of sp2mp with selector,
1730 * treatment, mpls encapsulation and co-located
1731 * different filtered ingress/egress points.
1732 */
1733 @Test
1734 public void testCoLocatedDifferentFilteredPointsNonTrivialForSp() {
1735
1736 intent = LinkCollectionIntent.builder()
1737 .appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment)
1738 .applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc)
1739 .constraints(constraintsForMPLS)
1740 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector)))
1741 .filteredEgressPoints(ImmutableSet.of(
1742 new FilteredConnectPoint(d1p11, mpls100Selector),
1743 new FilteredConnectPoint(d2p10, vlan200Selector),
1744 new FilteredConnectPoint(d3p10, mpls200Selector)
1745 )).build();
1746
1747 sut.activate();
1748
Pier Ventreffe88d62016-10-13 14:34:40 -07001749 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1750
1751 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1752 assertThat(compiled, hasSize(1));
1753
1754 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1755 assertThat(rules, hasSize(3));
1756
1757 Collection<FlowRule> rulesS1 = rules.stream()
1758 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1759 .collect(Collectors.toSet());
1760 assertThat(rulesS1, hasSize(1));
1761 FlowRule ruleS1 = rulesS1.iterator().next();
1762 assertThat(ruleS1.selector(), is(
1763 DefaultTrafficSelector
1764 .builder(ipPrefixSelector)
1765 .matchInPort(d1p10.port())
1766 .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
1767 .build()
1768 ));
1769 assertThat(ruleS1.treatment(), is(
1770 DefaultTrafficTreatment
1771 .builder()
1772 .popVlan()
1773 .pushMpls()
1774 .setMpls(MplsLabel.mplsLabel(LABEL))
1775 .setOutput(d1p0.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001776 .setEthDst(((ModEtherInstruction) ethDstTreatment
1777 .allInstructions()
1778 .stream()
1779 .filter(instruction -> instruction instanceof ModEtherInstruction)
1780 .findFirst().get()).mac())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001781 .setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1782 .setOutput(d1p11.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001783 .build()
1784 ));
1785
1786 Collection<FlowRule> rulesS2 = rules.stream()
1787 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1788 .collect(Collectors.toSet());
1789 assertThat(rulesS2, hasSize(1));
1790 FlowRule ruleS2 = rulesS2.iterator().next();
1791 assertThat(ruleS2.selector(), is(
1792 DefaultTrafficSelector
1793 .builder()
1794 .matchInPort(d2p0.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001795 .matchEthType(Ethernet.MPLS_UNICAST)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001796 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
Pier Ventreffe88d62016-10-13 14:34:40 -07001797 .build()
1798 ));
1799 assertThat(ruleS2.treatment(), is(
1800 DefaultTrafficTreatment
1801 .builder()
1802 .setMpls(MplsLabel.mplsLabel(LABEL))
1803 .setOutput(d2p1.port())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001804 .setEthDst(((ModEtherInstruction) ethDstTreatment
1805 .allInstructions()
1806 .stream()
1807 .filter(instruction -> instruction instanceof ModEtherInstruction)
1808 .findFirst().get()).mac())
1809 .popMpls(IPV4.ethType())
1810 .pushVlan()
1811 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1812 .setOutput(d2p10.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001813 .build()
1814 ));
1815
1816 Collection<FlowRule> rulesS3 = rules.stream()
Pier Ventre5c4a0762016-11-21 10:28:13 -08001817 .filter(rule -> rule.deviceId().equals(d3p1.deviceId()))
Pier Ventreffe88d62016-10-13 14:34:40 -07001818 .collect(Collectors.toSet());
1819 assertThat(rulesS3, hasSize(1));
1820 FlowRule ruleS3 = rulesS3.iterator().next();
1821 assertThat(ruleS3.selector(), is(
1822 DefaultTrafficSelector
1823 .builder()
Pier Ventreffe88d62016-10-13 14:34:40 -07001824 .matchEthType(Ethernet.MPLS_UNICAST)
Pier Ventre5c4a0762016-11-21 10:28:13 -08001825 .matchMplsLabel(MplsLabel.mplsLabel(LABEL))
1826 .matchInPort(d3p0.port())
Pier Ventreffe88d62016-10-13 14:34:40 -07001827 .build()
1828 ));
1829 assertThat(ruleS3.treatment(), is(
1830 DefaultTrafficTreatment
1831 .builder()
1832 .setEthDst(((ModEtherInstruction) ethDstTreatment
1833 .allInstructions()
1834 .stream()
1835 .filter(instruction -> instruction instanceof ModEtherInstruction)
1836 .findFirst().get()).mac())
Pier Ventre5c4a0762016-11-21 10:28:13 -08001837 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
Pier Ventreffe88d62016-10-13 14:34:40 -07001838 .setOutput(d3p10.port())
1839 .build()
1840 ));
1841
1842 sut.deactivate();
1843
1844 }
1845
Pier Ventre5c4a0762016-11-21 10:28:13 -08001846 /**
1847 * We test the proper compilation of mp2sp with selector,
1848 * treatment, vlan encapsulation and co-located
1849 * filtered ingress/egress points.
1850 */
1851 @Test
1852 public void testCoLocatedDifferentFilteredPointsNonTrivialForMp() {
1853
1854 intent = LinkCollectionIntent.builder()
1855 .appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment)
1856 .links(linksForMp2SpCoLoc).constraints(constraintsForVlan)
1857 .filteredIngressPoints(ImmutableSet.of(
1858 new FilteredConnectPoint(d1p10, mpls100Selector),
1859 new FilteredConnectPoint(d2p10, vlan100Selector)
1860 ))
1861 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls200Selector)))
1862 .build();
1863
1864 sut.activate();
1865
1866 LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
1867
1868 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1869 assertThat(compiled, hasSize(1));
1870
1871 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1872 assertThat(rules, hasSize(3));
1873
1874 Collection<FlowRule> rulesS1 = rules.stream()
1875 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1876 .collect(Collectors.toSet());
1877 assertThat(rulesS1, hasSize(2));
1878 FlowRule ruleS1 = rulesS1.stream()
1879 .filter(rule -> {
1880 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1881 return inPort.port().equals(d1p10.port());
1882 })
1883 .findFirst()
1884 .get();
1885 assertThat(ruleS1.selector(), is(
1886 DefaultTrafficSelector
1887 .builder(ipPrefixSelector)
1888 .matchInPort(d1p10.port())
1889 .matchMplsLabel(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
1890 .build()
1891 ));
1892 assertThat(ruleS1.treatment(), is(
1893 DefaultTrafficTreatment
1894 .builder()
1895 .setEthDst(((ModEtherInstruction) ethDstTreatment
1896 .allInstructions()
1897 .stream()
1898 .filter(instruction -> instruction instanceof ModEtherInstruction)
1899 .findFirst().get()).mac())
1900 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1901 .setOutput(d1p11.port())
1902 .build()
1903 ));
1904
1905 ruleS1 = rulesS1.stream()
1906 .filter(rule -> {
1907 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1908 return inPort.port().equals(d1p0.port());
1909 })
1910 .findFirst()
1911 .get();
1912 assertThat(ruleS1.selector(), is(
1913 DefaultTrafficSelector
1914 .builder()
1915 .matchVlanId(VlanId.vlanId(LABEL))
1916 .matchInPort(d1p0.port())
1917 .build()
1918 ));
1919 assertThat(ruleS1.treatment(), is(
1920 DefaultTrafficTreatment
1921 .builder()
1922 .setEthDst(((ModEtherInstruction) ethDstTreatment
1923 .allInstructions()
1924 .stream()
1925 .filter(instruction -> instruction instanceof ModEtherInstruction)
1926 .findFirst().get()).mac())
1927 .popVlan()
1928 .pushMpls()
1929 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1930 .setOutput(d1p11.port())
1931 .build()
1932 ));
1933
1934 Collection<FlowRule> rulesS2 = rules.stream()
1935 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
1936 .collect(Collectors.toSet());
1937 assertThat(rulesS2, hasSize(1));
1938 FlowRule ruleS2 = rulesS2.iterator().next();
1939 assertThat(ruleS2.selector(), is(
1940 DefaultTrafficSelector
1941 .builder(ipPrefixSelector)
1942 .matchInPort(d2p10.port())
1943 .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
1944 .build()
1945 ));
1946 assertThat(ruleS2.treatment(), is(
1947 DefaultTrafficTreatment
1948 .builder()
1949 .setVlanId(VlanId.vlanId(LABEL))
1950 .setOutput(d2p0.port())
1951 .build()
1952 ));
1953
1954 sut.deactivate();
1955
1956 }
1957
Pier Ventre766995d2016-10-05 22:15:56 -07001958}