blob: 87103aa74ce8ce8bbf89f8aec893300944b1fdba [file] [log] [blame]
Sho SHIMIZUee2aa652015-02-25 18:56:43 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Sho SHIMIZUee2aa652015-02-25 18:56:43 -08003 *
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 */
16package org.onosproject.net.intent.impl.compiler;
17
18import com.google.common.collect.ImmutableSet;
Pier Ventre766995d2016-10-05 22:15:56 -070019import org.hamcrest.core.Is;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080020import org.junit.After;
21import org.junit.Before;
22import org.junit.Test;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070023import org.onlab.packet.MacAddress;
Pier Ventre647138f2016-08-26 17:32:44 -070024import org.onlab.packet.VlanId;
Thomas Vachuskabdbdd242016-03-01 01:55:55 -080025import org.onosproject.cfg.ComponentConfigAdapter;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080026import org.onosproject.core.CoreService;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080027import org.onosproject.net.ConnectPoint;
28import org.onosproject.net.DefaultLink;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070029import org.onosproject.net.FilteredConnectPoint;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080030import org.onosproject.net.Link;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070031import org.onosproject.net.PortNumber;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080032import org.onosproject.net.flow.DefaultTrafficSelector;
33import org.onosproject.net.flow.DefaultTrafficTreatment;
34import org.onosproject.net.flow.FlowRule;
35import org.onosproject.net.flow.TrafficSelector;
36import org.onosproject.net.flow.TrafficTreatment;
Pier Ventre766995d2016-10-05 22:15:56 -070037import org.onosproject.net.flow.criteria.MplsCriterion;
38import org.onosproject.net.flow.criteria.PortCriterion;
39import org.onosproject.net.flow.criteria.VlanIdCriterion;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080040import org.onosproject.net.intent.FlowRuleIntent;
41import org.onosproject.net.intent.Intent;
42import org.onosproject.net.intent.IntentExtensionService;
43import org.onosproject.net.intent.LinkCollectionIntent;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080044
45import java.util.Collection;
46import java.util.Collections;
47import java.util.List;
48import java.util.Set;
Pier Ventre647138f2016-08-26 17:32:44 -070049import java.util.stream.Collectors;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080050
51import static org.easymock.EasyMock.createMock;
52import static org.easymock.EasyMock.expect;
53import static org.easymock.EasyMock.replay;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070054import static org.hamcrest.CoreMatchers.instanceOf;
55import static org.hamcrest.CoreMatchers.notNullValue;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080056import static org.hamcrest.MatcherAssert.assertThat;
57import static org.hamcrest.Matchers.hasSize;
58import static org.hamcrest.Matchers.is;
Pier Ventre766995d2016-10-05 22:15:56 -070059import static org.onlab.packet.EthType.EtherType.IPV4;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080060import static org.onosproject.net.Link.Type.DIRECT;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070061import static org.onosproject.net.NetTestTools.*;
Pier Ventre766995d2016-10-05 22:15:56 -070062import static org.onosproject.net.flow.criteria.Criterion.Type.IN_PORT;
63import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL;
64import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID;
65import static org.onosproject.net.flow.instructions.L2ModificationInstruction.*;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080066
Pier Ventre766995d2016-10-05 22:15:56 -070067public class LinkCollectionIntentCompilerTest extends AbstractLinkCollectionTest {
Yi Tseng2a81c9d2016-09-14 10:14:24 -070068
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080069 @Before
Brian O'Connor81134662015-06-25 17:23:33 -040070 public void setUp() {
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080071 sut = new LinkCollectionIntentCompiler();
72 coreService = createMock(CoreService.class);
73 expect(coreService.registerApplication("org.onosproject.net.intent"))
74 .andReturn(appId);
75 sut.coreService = coreService;
76
77 Intent.bindIdGenerator(idGenerator);
78
79 intent = LinkCollectionIntent.builder()
80 .appId(APP_ID)
81 .selector(selector)
82 .treatment(treatment)
83 .links(links)
84 .ingressPoints(ImmutableSet.of(d1p1))
85 .egressPoints(ImmutableSet.of(d3p1))
86 .build();
Pier Ventre647138f2016-08-26 17:32:44 -070087
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080088 intentExtensionService = createMock(IntentExtensionService.class);
89 intentExtensionService.registerCompiler(LinkCollectionIntent.class, sut);
90 intentExtensionService.unregisterCompiler(LinkCollectionIntent.class);
Thomas Vachuskabdbdd242016-03-01 01:55:55 -080091
92 registrator = new IntentConfigurableRegistrator();
93 registrator.extensionService = intentExtensionService;
94 registrator.cfgService = new ComponentConfigAdapter();
95 registrator.activate();
96
97 sut.registrator = registrator;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080098
99 replay(coreService, intentExtensionService);
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700100
101
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800102 }
103
104 @After
105 public void tearDown() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700106
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800107 Intent.unbindIdGenerator(idGenerator);
108 }
109
110 @Test
111 public void testCompile() {
112 sut.activate();
113
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800114 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800115 assertThat(compiled, hasSize(1));
116
117 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
118 assertThat(rules, hasSize(links.size()));
119
120 // if not found, get() raises an exception
121 FlowRule rule1 = rules.stream()
Pier Ventre766995d2016-10-05 22:15:56 -0700122 .filter(rule -> rule.deviceId().equals(d1p10.deviceId()))
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800123 .findFirst()
124 .get();
125 assertThat(rule1.selector(), is(
126 DefaultTrafficSelector.builder(intent.selector()).matchInPort(d1p1.port()).build()
127 ));
128 assertThat(rule1.treatment(), is(
129 DefaultTrafficTreatment.builder(intent.treatment()).setOutput(d1p1.port()).build()
130 ));
Brian O'Connor81134662015-06-25 17:23:33 -0400131 assertThat(rule1.priority(), is(intent.priority()));
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800132
133 FlowRule rule2 = rules.stream()
134 .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
135 .findFirst()
136 .get();
137 assertThat(rule2.selector(), is(
138 DefaultTrafficSelector.builder(intent.selector()).matchInPort(d2p0.port()).build()
139 ));
140 assertThat(rule2.treatment(), is(
141 DefaultTrafficTreatment.builder().setOutput(d2p1.port()).build()
142 ));
Brian O'Connor81134662015-06-25 17:23:33 -0400143 assertThat(rule2.priority(), is(intent.priority()));
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800144
145 FlowRule rule3 = rules.stream()
146 .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
147 .findFirst()
148 .get();
149 assertThat(rule3.selector(), is(
150 DefaultTrafficSelector.builder(intent.selector()).matchInPort(d3p1.port()).build()
151 ));
152 assertThat(rule3.treatment(), is(
153 DefaultTrafficTreatment.builder().setOutput(d3p1.port()).build()
154 ));
Brian O'Connor81134662015-06-25 17:23:33 -0400155 assertThat(rule3.priority(), is(intent.priority()));
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800156
157 sut.deactivate();
158 }
Pier Ventre647138f2016-08-26 17:32:44 -0700159
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700160 /**
161 * Single point to multi point case.
162 * -1 of1 2-1 of2 2--1 of3 2-
163 * 3
164 * `-1 of4 2-
165 */
166 @Test
Pier Ventre766995d2016-10-05 22:15:56 -0700167 public void testFilteredConnectPointForSp() {
Pier Ventre647138f2016-08-26 17:32:44 -0700168 sut.activate();
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700169 Set<Link> testLinks = ImmutableSet.of(
170 DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(),
171 DefaultLink.builder().providerId(PID).src(of2p2).dst(of3p1).type(DIRECT).build(),
172 DefaultLink.builder().providerId(PID).src(of2p3).dst(of4p1).type(DIRECT).build()
173 );
Pier Ventre647138f2016-08-26 17:32:44 -0700174
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700175 TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(vlan100Selector)
176 .matchInPort(PortNumber.portNumber(1))
177 .build();
178
179 TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder()
180 .setOutput(PortNumber.portNumber(2))
181 .build();
182
183 TrafficSelector expectOf2Selector = DefaultTrafficSelector.builder(vlan100Selector)
184 .matchInPort(PortNumber.portNumber(1))
185 .build();
186
187 TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder()
188 .setOutput(PortNumber.portNumber(2))
189 .setOutput(PortNumber.portNumber(3))
190 .build();
191
192 TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(vlan100Selector)
193 .matchInPort(PortNumber.portNumber(1))
194 .build();
195
196 TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder()
197 .setOutput(PortNumber.portNumber(2))
198 .build();
199
200 TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(vlan100Selector)
201 .matchInPort(PortNumber.portNumber(1))
202 .build();
203
204 TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder()
205 .setVlanId(VlanId.vlanId("200"))
206 .setOutput(PortNumber.portNumber(2))
207 .build();
Pier Ventre647138f2016-08-26 17:32:44 -0700208
209
Pier Ventre647138f2016-08-26 17:32:44 -0700210
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700211 Set<FilteredConnectPoint> ingress = ImmutableSet.of(
212 new FilteredConnectPoint(of1p1, vlan100Selector)
213 );
Pier Ventre647138f2016-08-26 17:32:44 -0700214
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700215 Set<FilteredConnectPoint> egress = ImmutableSet.of(
216 new FilteredConnectPoint(of3p2, vlan100Selector),
217 new FilteredConnectPoint(of4p2, vlan200Selector)
218 );
Pier Ventre647138f2016-08-26 17:32:44 -0700219
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700220 intent = LinkCollectionIntent.builder()
221 .appId(APP_ID)
222 .filteredIngressPoints(ingress)
223 .filteredEgressPoints(egress)
224 .treatment(treatment)
225 .applyTreatmentOnEgress(true)
226 .links(testLinks)
227 .build();
Pier Ventre647138f2016-08-26 17:32:44 -0700228
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700229 assertThat(sut, is(notNullValue()));
Pier Ventre647138f2016-08-26 17:32:44 -0700230
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700231 List<Intent> result = sut.compile(intent, Collections.emptyList());
232
233 assertThat(result, is(notNullValue()));
234 assertThat(result, hasSize(1));
235
236 Intent resultIntent = result.get(0);
237 assertThat(resultIntent, instanceOf(FlowRuleIntent.class));
238
239 if (resultIntent instanceof FlowRuleIntent) {
240 FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent;
241
242 assertThat(frIntent.flowRules(), hasSize(4));
243
244 List<FlowRule> deviceFlowRules;
245 FlowRule flowRule;
246
247 // Of1
248 deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules());
249 assertThat(deviceFlowRules, hasSize(1));
250 flowRule = deviceFlowRules.get(0);
251 assertThat(flowRule.selector(), is(expectOf1Selector));
252 assertThat(flowRule.treatment(), is(expectOf1Treatment));
253
254 // Of2
255 deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules());
256 assertThat(deviceFlowRules, hasSize(1));
257 flowRule = deviceFlowRules.get(0);
258 assertThat(flowRule.selector(), is(expectOf2Selector));
259 assertThat(flowRule.treatment(), is(expectOf2Treatment));
260
261 // Of3
262 deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules());
263 assertThat(deviceFlowRules, hasSize(1));
264 flowRule = deviceFlowRules.get(0);
265 assertThat(flowRule.selector(), is(expectOf3Selector));
266 assertThat(flowRule.treatment(), is(expectOf3Treatment));
267
268 // Of4
269 deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules());
270 assertThat(deviceFlowRules, hasSize(1));
271 flowRule = deviceFlowRules.get(0);
272 assertThat(flowRule.selector(), is(expectOf4Selector));
273 assertThat(flowRule.treatment(), is(expectOf4Treatment));
274
275 }
276 sut.deactivate();
277 }
278
279 /**
280 * Multi point to single point intent with filtered connect point.
281 *
282 * -1 of1 2-1 of2 2-1 of4 2-
283 * 3
284 * -1 of3 2---/
285 */
286 @Test
Pier Ventre766995d2016-10-05 22:15:56 -0700287 public void testFilteredConnectPointForMp() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700288 sut.activate();
289 Set<Link> testlinks = ImmutableSet.of(
290 DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(),
291 DefaultLink.builder().providerId(PID).src(of3p2).dst(of2p3).type(DIRECT).build(),
292 DefaultLink.builder().providerId(PID).src(of2p2).dst(of4p1).type(DIRECT).build()
293 );
294
295 Set<FilteredConnectPoint> ingress = ImmutableSet.of(
296 new FilteredConnectPoint(of1p1, vlan100Selector),
297 new FilteredConnectPoint(of3p1, vlan100Selector)
298 );
299
300 Set<FilteredConnectPoint> egress = ImmutableSet.of(
301 new FilteredConnectPoint(of4p2, vlan200Selector)
302 );
303
304 TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(vlan100Selector)
305 .matchInPort(PortNumber.portNumber(1))
306 .build();
307
308 TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder()
309 .setVlanId(VlanId.vlanId("200"))
310 .setOutput(PortNumber.portNumber(2))
311 .build();
312
313 TrafficSelector expectOf2Selector1 = DefaultTrafficSelector.builder(vlan200Selector)
314 .matchInPort(PortNumber.portNumber(1))
315 .build();
316
317 TrafficSelector expectOf2Selector2 = DefaultTrafficSelector.builder(vlan200Selector)
318 .matchInPort(PortNumber.portNumber(3))
319 .build();
320
321 TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder()
322 .setOutput(PortNumber.portNumber(2))
323 .build();
324
325 TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(vlan100Selector)
326 .matchInPort(PortNumber.portNumber(1))
327 .build();
328
329 TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder()
330 .setVlanId(VlanId.vlanId("200"))
331 .setOutput(PortNumber.portNumber(2))
332 .build();
333
334 TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(vlan100Selector)
335 .matchInPort(PortNumber.portNumber(1))
336 .matchVlanId(VlanId.vlanId("200"))
337 .build();
338
339 TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder()
340 .setOutput(PortNumber.portNumber(2))
341 .build();
342
343 intent = LinkCollectionIntent.builder()
344 .appId(APP_ID)
345 .filteredIngressPoints(ingress)
346 .filteredEgressPoints(egress)
347 .treatment(treatment)
348 .links(testlinks)
349 .build();
350
351 List<Intent> result = sut.compile(intent, Collections.emptyList());
352
353 assertThat(result, is(notNullValue()));
354 assertThat(result, hasSize(1));
355
356 Intent resultIntent = result.get(0);
357 assertThat(resultIntent, instanceOf(FlowRuleIntent.class));
358
359 if (resultIntent instanceof FlowRuleIntent) {
360 FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent;
361 assertThat(frIntent.flowRules(), hasSize(5));
362
363 List<FlowRule> deviceFlowRules;
364 FlowRule flowRule;
365
366 // Of1
367 deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules());
368 assertThat(deviceFlowRules, hasSize(1));
369 flowRule = deviceFlowRules.get(0);
370 assertThat(flowRule.selector(), is(expectOf1Selector));
371 assertThat(flowRule.treatment(), is(expectOf1Treatment));
372
373 // Of2 (has 2 flows)
374 deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules());
375 assertThat(deviceFlowRules, hasSize(2));
376 flowRule = deviceFlowRules.get(0);
377 assertThat(flowRule.selector(), is(expectOf2Selector1));
378 assertThat(flowRule.treatment(), is(expectOf2Treatment));
379 flowRule = deviceFlowRules.get(1);
380 assertThat(flowRule.selector(), is(expectOf2Selector2));
381 assertThat(flowRule.treatment(), is(expectOf2Treatment));
382
383 // Of3
384 deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules());
385 assertThat(deviceFlowRules, hasSize(1));
386 flowRule = deviceFlowRules.get(0);
387 assertThat(flowRule.selector(), is(expectOf3Selector));
388 assertThat(flowRule.treatment(), is(expectOf3Treatment));
389
390 // Of4
391 deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules());
392 assertThat(deviceFlowRules, hasSize(1));
393 flowRule = deviceFlowRules.get(0);
394 assertThat(flowRule.selector(), is(expectOf4Selector));
395 assertThat(flowRule.treatment(), is(expectOf4Treatment));
396 }
Pier Ventre647138f2016-08-26 17:32:44 -0700397
398 sut.deactivate();
399 }
400
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700401 /**
402 * Single point to multi point without filtered connect point case.
403 * -1 of1 2-1 of2 2--1 of3 2-
404 * 3
405 * `-1 of4 2-
406 */
Pier Ventre27d42572016-08-29 17:37:08 -0700407 @Test
Pier Ventre766995d2016-10-05 22:15:56 -0700408 public void nonTrivialTranslationForSp() {
Pier Ventre27d42572016-08-29 17:37:08 -0700409 sut.activate();
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700410 Set<Link> testLinks = ImmutableSet.of(
411 DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(),
412 DefaultLink.builder().providerId(PID).src(of2p2).dst(of3p1).type(DIRECT).build(),
413 DefaultLink.builder().providerId(PID).src(of2p3).dst(of4p1).type(DIRECT).build()
414 );
Pier Ventre27d42572016-08-29 17:37:08 -0700415
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700416 TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
417 .matchInPort(PortNumber.portNumber(1))
418 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700419
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700420 TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder()
421 .setOutput(PortNumber.portNumber(2))
422 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700423
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700424 TrafficSelector expectOf2Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
425 .matchInPort(PortNumber.portNumber(1))
426 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700427
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700428 TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder()
429 .setOutput(PortNumber.portNumber(2))
430 .setOutput(PortNumber.portNumber(3))
431 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700432
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700433 TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
434 .matchInPort(PortNumber.portNumber(1))
435 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700436
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700437 TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder(ethDstTreatment)
438 .setOutput(PortNumber.portNumber(2))
439 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700440
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700441 TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
442 .matchInPort(PortNumber.portNumber(1))
443 .build();
444
445 TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder(ethDstTreatment)
446 .setOutput(PortNumber.portNumber(2))
447 .build();
448
449
450
451 Set<ConnectPoint> ingress = ImmutableSet.of(
452 of1p1
453 );
454
455 Set<ConnectPoint> egress = ImmutableSet.of(
456 of3p2,
457 of4p2
458 );
459
460 intent = LinkCollectionIntent.builder()
461 .appId(APP_ID)
462 .selector(ipPrefixSelector)
463 .treatment(ethDstTreatment)
464 .ingressPoints(ingress)
465 .egressPoints(egress)
466 .applyTreatmentOnEgress(true)
467 .links(testLinks)
468 .build();
469
470 assertThat(sut, is(notNullValue()));
471
472 List<Intent> result = sut.compile(intent, Collections.emptyList());
473
474 assertThat(result, is(notNullValue()));
475 assertThat(result, hasSize(1));
476
477 Intent resultIntent = result.get(0);
478 assertThat(resultIntent, instanceOf(FlowRuleIntent.class));
479
480 if (resultIntent instanceof FlowRuleIntent) {
481 FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent;
482
483 assertThat(frIntent.flowRules(), hasSize(4));
484
485 List<FlowRule> deviceFlowRules;
486 FlowRule flowRule;
487
488 // Of1
489 deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules());
490 assertThat(deviceFlowRules, hasSize(1));
491 flowRule = deviceFlowRules.get(0);
492 assertThat(flowRule.selector(), is(expectOf1Selector));
493 assertThat(flowRule.treatment(), is(expectOf1Treatment));
494
495 // Of2
496 deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules());
497 assertThat(deviceFlowRules, hasSize(1));
498 flowRule = deviceFlowRules.get(0);
499 assertThat(flowRule.selector(), is(expectOf2Selector));
500 assertThat(flowRule.treatment(), is(expectOf2Treatment));
501
502 // Of3
503 deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules());
504 assertThat(deviceFlowRules, hasSize(1));
505 flowRule = deviceFlowRules.get(0);
506 assertThat(flowRule.selector(), is(expectOf3Selector));
507 assertThat(flowRule.treatment(), is(expectOf3Treatment));
508
509 // Of4
510 deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules());
511 assertThat(deviceFlowRules, hasSize(1));
512 flowRule = deviceFlowRules.get(0);
513 assertThat(flowRule.selector(), is(expectOf4Selector));
514 assertThat(flowRule.treatment(), is(expectOf4Treatment));
515
516 }
517 sut.deactivate();
Pier Ventre27d42572016-08-29 17:37:08 -0700518 }
519
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700520 /**
521 * Multi point to single point intent without filtered connect point.
522 *
523 * -1 of1 2-1 of2 2-1 of4 2-
524 * 3
525 * -1 of3 2---/
526 */
Pier Ventre27d42572016-08-29 17:37:08 -0700527 @Test
Pier Ventre766995d2016-10-05 22:15:56 -0700528 public void nonTrivialTranslationForMp() {
Pier Ventre27d42572016-08-29 17:37:08 -0700529 sut.activate();
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700530 Set<Link> testlinks = ImmutableSet.of(
531 DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(),
532 DefaultLink.builder().providerId(PID).src(of3p2).dst(of2p3).type(DIRECT).build(),
533 DefaultLink.builder().providerId(PID).src(of2p2).dst(of4p1).type(DIRECT).build()
534 );
Pier Ventre27d42572016-08-29 17:37:08 -0700535
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700536 Set<ConnectPoint> ingress = ImmutableSet.of(
537 of1p1,
538 of3p1
539 );
Pier Ventre27d42572016-08-29 17:37:08 -0700540
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700541 Set<ConnectPoint> egress = ImmutableSet.of(
542 of4p2
543 );
Pier Ventre27d42572016-08-29 17:37:08 -0700544
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700545 TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
546 .matchInPort(PortNumber.portNumber(1))
547 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700548
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700549 TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder(ethDstTreatment)
550 .setOutput(PortNumber.portNumber(2))
551 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700552
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700553 TrafficSelector expectOf2Selector1 = DefaultTrafficSelector.builder(ipPrefixSelector)
554 .matchInPort(PortNumber.portNumber(1))
555 .matchEthDst(MacAddress.valueOf("C0:FF:EE:C0:FF:EE"))
556 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700557
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700558 TrafficSelector expectOf2Selector2 = DefaultTrafficSelector.builder(ipPrefixSelector)
559 .matchEthDst(MacAddress.valueOf("C0:FF:EE:C0:FF:EE"))
560 .matchInPort(PortNumber.portNumber(3))
561 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700562
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700563 TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder()
564 .setOutput(PortNumber.portNumber(2))
565 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700566
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700567 TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
568 .matchInPort(PortNumber.portNumber(1))
569 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700570
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700571 TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder(ethDstTreatment)
572 .setOutput(PortNumber.portNumber(2))
573 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700574
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700575 TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
576 .matchEthDst(MacAddress.valueOf("C0:FF:EE:C0:FF:EE"))
577 .matchInPort(PortNumber.portNumber(1))
578 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700579
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700580 TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder()
581 .setOutput(PortNumber.portNumber(2))
582 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700583
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700584 intent = LinkCollectionIntent.builder()
585 .appId(APP_ID)
586 .selector(ipPrefixSelector)
587 .ingressPoints(ingress)
588 .egressPoints(egress)
589 .treatment(ethDstTreatment)
590 .links(testlinks)
591 .build();
Pier Ventre27d42572016-08-29 17:37:08 -0700592
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700593 List<Intent> result = sut.compile(intent, Collections.emptyList());
Pier Ventre27d42572016-08-29 17:37:08 -0700594
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700595 assertThat(result, is(notNullValue()));
596 assertThat(result, hasSize(1));
597
598 Intent resultIntent = result.get(0);
599 assertThat(resultIntent, instanceOf(FlowRuleIntent.class));
600
601 if (resultIntent instanceof FlowRuleIntent) {
602 FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent;
603 assertThat(frIntent.flowRules(), hasSize(5));
604
605 List<FlowRule> deviceFlowRules;
606 FlowRule flowRule;
607
608 // Of1
609 deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules());
610 assertThat(deviceFlowRules, hasSize(1));
611 flowRule = deviceFlowRules.get(0);
612 assertThat(flowRule.selector(), is(expectOf1Selector));
613 assertThat(flowRule.treatment(), is(expectOf1Treatment));
614
615 // Of2 (has 2 flows)
616 deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules());
617 assertThat(deviceFlowRules, hasSize(2));
618 flowRule = deviceFlowRules.get(0);
619 assertThat(flowRule.selector(), is(expectOf2Selector1));
620 assertThat(flowRule.treatment(), is(expectOf2Treatment));
621 flowRule = deviceFlowRules.get(1);
622 assertThat(flowRule.selector(), is(expectOf2Selector2));
623 assertThat(flowRule.treatment(), is(expectOf2Treatment));
624
625 // Of3
626 deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules());
627 assertThat(deviceFlowRules, hasSize(1));
628 flowRule = deviceFlowRules.get(0);
629 assertThat(flowRule.selector(), is(expectOf3Selector));
630 assertThat(flowRule.treatment(), is(expectOf3Treatment));
631
632 // Of4
633 deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules());
634 assertThat(deviceFlowRules, hasSize(1));
635 flowRule = deviceFlowRules.get(0);
636 assertThat(flowRule.selector(), is(expectOf4Selector));
637 assertThat(flowRule.treatment(), is(expectOf4Treatment));
638 }
639
640 sut.deactivate();
Pier Ventre27d42572016-08-29 17:37:08 -0700641 }
Pier Ventre766995d2016-10-05 22:15:56 -0700642
643 /**
644 * We test the proper compilation of mp2sp with
645 * trivial selector, trivial treatment and 1 hop.
646 */
647 @Test
648 public void singleHopTestForMp() {
649
650 intent = LinkCollectionIntent.builder()
651 .appId(APP_ID)
652 .selector(selector)
653 .treatment(treatment)
654 .links(ImmutableSet.of())
655 .filteredIngressPoints(ImmutableSet.of(
656 new FilteredConnectPoint(d1p10),
657 new FilteredConnectPoint(d1p11)
658 ))
659 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0)))
660 .build();
661
662 sut.activate();
663
664 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
665 assertThat(compiled, hasSize(1));
666
667 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
668 assertThat(rules, hasSize(2));
669
670 Collection<FlowRule> rulesS1 = rules.stream()
671 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
672 .collect(Collectors.toSet());
673 assertThat(rulesS1, hasSize(2));
674 FlowRule ruleS1 = rulesS1.stream()
675 .filter(rule -> {
676 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
677 return inPort.port().equals(d1p10.port());
678 })
679 .findFirst()
680 .get();
681 assertThat(ruleS1.selector(), Is.is(
682 DefaultTrafficSelector
683 .builder()
684 .matchInPort(d1p10.port())
685 .build()
686 ));
687 assertThat(ruleS1.treatment(), Is.is(
688 DefaultTrafficTreatment
689 .builder()
690 .setOutput(d1p0.port())
691 .build()
692 ));
693
694 ruleS1 = rulesS1.stream()
695 .filter(rule -> {
696 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
697 return inPort.port().equals(d1p11.port());
698 })
699 .findFirst()
700 .get();
701 assertThat(ruleS1.selector(), Is.is(
702 DefaultTrafficSelector
703 .builder()
704 .matchInPort(d1p11.port())
705 .build()
706 ));
707 assertThat(ruleS1.treatment(), Is.is(
708 DefaultTrafficTreatment
709 .builder()
710 .setOutput(d1p0.port())
711 .build()
712 ));
713
714 sut.deactivate();
715
716 }
717
718 /**
719 * We test the proper compilation of sp2mp with
720 * trivial selector, trivial treatment and 1 hop.
721 */
722 @Test
723 public void singleHopTestForSp() {
724
725 intent = LinkCollectionIntent.builder()
726 .appId(APP_ID)
727 .selector(selector)
728 .treatment(treatment)
729 .applyTreatmentOnEgress(true)
730 .links(ImmutableSet.of())
731 .filteredEgressPoints(ImmutableSet.of(
732 new FilteredConnectPoint(d1p10),
733 new FilteredConnectPoint(d1p11)
734 ))
735 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0)))
736 .build();
737
738 sut.activate();
739
740 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
741 assertThat(compiled, hasSize(1));
742
743 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
744 assertThat(rules, hasSize(1));
745
746 Collection<FlowRule> rulesS1 = rules.stream()
747 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
748 .collect(Collectors.toSet());
749 assertThat(rulesS1, hasSize(1));
750 FlowRule ruleS1 = rulesS1.stream()
751 .filter(rule -> {
752 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
753 return inPort.port().equals(d1p0.port());
754 })
755 .findFirst()
756 .get();
757 assertThat(ruleS1.selector(), Is.is(
758 DefaultTrafficSelector
759 .builder()
760 .matchInPort(d1p0.port())
761 .build()
762 ));
763 assertThat(ruleS1.treatment(), Is.is(
764 DefaultTrafficTreatment
765 .builder()
766 .setOutput(d1p10.port())
767 .setOutput(d1p11.port())
768 .build()
769 ));
770
771 sut.deactivate();
772
773 }
774
775 /**
776 * We test the proper compilation of mp2sp with
777 * trivial selector, trivial treatment, filtered
778 * points and 1 hop.
779 */
780 @Test
781 public void singleHopTestFilteredForMp() {
782
783 intent = LinkCollectionIntent.builder()
784 .appId(APP_ID)
785 .selector(selector)
786 .treatment(treatment)
787 .links(ImmutableSet.of())
788 .filteredIngressPoints(ImmutableSet.of(
789 new FilteredConnectPoint(d1p10, vlan100Selector),
790 new FilteredConnectPoint(d1p11, mpls69Selector)
791 ))
792 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0, vlan200Selector)))
793 .build();
794
795 sut.activate();
796
797 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
798 assertThat(compiled, hasSize(1));
799
800 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
801 assertThat(rules, hasSize(2));
802
803 Collection<FlowRule> rulesS1 = rules.stream()
804 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
805 .collect(Collectors.toSet());
806 assertThat(rulesS1, hasSize(2));
807 FlowRule ruleS1 = rulesS1.stream()
808 .filter(rule -> {
809 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
810 return inPort.port().equals(d1p10.port());
811 })
812 .findFirst()
813 .get();
814 assertThat(ruleS1.selector(), Is.is(
815 DefaultTrafficSelector
816 .builder(vlan100Selector)
817 .matchInPort(d1p10.port())
818 .build()
819 ));
820 assertThat(ruleS1.treatment(), Is.is(
821 DefaultTrafficTreatment
822 .builder()
823 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
824 .setOutput(d1p0.port())
825 .build()
826 ));
827
828 ruleS1 = rulesS1.stream()
829 .filter(rule -> {
830 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
831 return inPort.port().equals(d1p11.port());
832 })
833 .findFirst()
834 .get();
835 assertThat(ruleS1.selector(), Is.is(
836 DefaultTrafficSelector
837 .builder(mpls69Selector)
838 .matchInPort(d1p11.port())
839 .build()
840 ));
841 assertThat(ruleS1.treatment(), Is.is(
842 DefaultTrafficTreatment
843 .builder()
844 .popMpls(IPV4.ethType())
845 .pushVlan()
846 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
847 .setOutput(d1p0.port())
848 .build()
849 ));
850
851 sut.deactivate();
852
853 }
854
855 /**
856 * We test the proper compilation of sp2mp with
857 * trivial selector, trivial treatment and 1 hop.
858 */
859 @Test
860 public void singleHopTestFilteredForSp() {
861
862 intent = LinkCollectionIntent.builder()
863 .appId(APP_ID)
864 .selector(selector)
865 .treatment(treatment)
866 .applyTreatmentOnEgress(true)
867 .links(ImmutableSet.of())
868 .filteredEgressPoints(ImmutableSet.of(
869 new FilteredConnectPoint(d1p10, vlan100Selector),
870 new FilteredConnectPoint(d1p11, mpls80Selector)
871 ))
872 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0, vlan200Selector)))
873 .build();
874
875 sut.activate();
876
877 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
878 assertThat(compiled, hasSize(1));
879
880 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
881 assertThat(rules, hasSize(1));
882
883 Collection<FlowRule> rulesS1 = rules.stream()
884 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
885 .collect(Collectors.toSet());
886 assertThat(rulesS1, hasSize(1));
887 FlowRule ruleS1 = rulesS1.stream()
888 .filter(rule -> {
889 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
890 return inPort.port().equals(d1p0.port());
891 })
892 .findFirst()
893 .get();
894 assertThat(ruleS1.selector(), Is.is(
895 DefaultTrafficSelector
896 .builder(vlan200Selector)
897 .matchInPort(d1p0.port())
898 .build()
899 ));
900 assertThat(ruleS1.treatment(), Is.is(
901 DefaultTrafficTreatment
902 .builder()
903 .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
904 .setOutput(d1p10.port())
905 .popVlan()
906 .pushMpls()
907 .setMpls(((MplsCriterion) mpls80Selector.getCriterion(MPLS_LABEL)).label())
908 .setOutput(d1p11.port())
909 .build()
910 ));
911
912 sut.deactivate();
913
914 }
915
916 /**
917 * We test the proper compilation of mp2sp with
918 * selector, treatment, filtered
919 * points and 1 hop.
920 */
921 @Test
922 public void singleHopNonTrivialForMp() {
923
924 intent = LinkCollectionIntent.builder()
925 .appId(APP_ID)
926 .selector(ipPrefixSelector)
927 .treatment(ethDstTreatment)
928 .links(ImmutableSet.of())
929 .filteredIngressPoints(ImmutableSet.of(
930 new FilteredConnectPoint(d1p10, vlan100Selector),
931 new FilteredConnectPoint(d1p11, mpls100Selector)
932 ))
933 .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0, vlan200Selector)))
934 .build();
935
936 sut.activate();
937
938 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
939 assertThat(compiled, hasSize(1));
940
941 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
942 assertThat(rules, hasSize(2));
943
944 Collection<FlowRule> rulesS1 = rules.stream()
945 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
946 .collect(Collectors.toSet());
947 assertThat(rulesS1, hasSize(2));
948 FlowRule ruleS1 = rulesS1.stream()
949 .filter(rule -> {
950 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
951 return inPort.port().equals(d1p10.port());
952 })
953 .findFirst()
954 .get();
955 assertThat(ruleS1.selector(), Is.is(
956 DefaultTrafficSelector
957 .builder(ipPrefixSelector)
958 .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
959 .matchInPort(d1p10.port())
960 .build()
961 ));
962 assertThat(ruleS1.treatment(), Is.is(
963 DefaultTrafficTreatment
964 .builder()
965 .setEthDst(((ModEtherInstruction) ethDstTreatment
966 .allInstructions()
967 .stream()
968 .filter(instruction -> instruction instanceof ModEtherInstruction)
969 .findFirst().get()).mac())
970 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
971 .setOutput(d1p0.port())
972 .build()
973 ));
974
975 ruleS1 = rulesS1.stream()
976 .filter(rule -> {
977 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
978 return inPort.port().equals(d1p11.port());
979 })
980 .findFirst()
981 .get();
982 assertThat(ruleS1.selector(), Is.is(
983 DefaultTrafficSelector
984 .builder(ipPrefixSelector)
985 .matchMplsLabel(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label())
986 .matchInPort(d1p11.port())
987 .build()
988 ));
989 assertThat(ruleS1.treatment(), Is.is(
990 DefaultTrafficTreatment
991 .builder()
992 .setEthDst(((ModEtherInstruction) ethDstTreatment
993 .allInstructions()
994 .stream()
995 .filter(instruction -> instruction instanceof ModEtherInstruction)
996 .findFirst().get()).mac())
997 .popMpls(IPV4.ethType())
998 .pushVlan()
999 .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1000 .setOutput(d1p0.port())
1001 .build()
1002 ));
1003
1004 sut.deactivate();
1005
1006 }
1007
1008 /**
1009 * We test the proper compilation of sp2mp with
1010 * selector, treatment and 1 hop.
1011 */
1012 @Test
1013 public void singleHopNonTrivialForSp() {
1014
1015 intent = LinkCollectionIntent.builder()
1016 .appId(APP_ID)
1017 .selector(ipPrefixSelector)
1018 .treatment(ethDstTreatment)
1019 .applyTreatmentOnEgress(true)
1020 .links(ImmutableSet.of())
1021 .filteredEgressPoints(ImmutableSet.of(
1022 new FilteredConnectPoint(d1p10, vlan100Selector),
1023 new FilteredConnectPoint(d1p11, mpls200Selector)
1024 ))
1025 .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0, vlan200Selector)))
1026 .build();
1027
1028 sut.activate();
1029
1030 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
1031 assertThat(compiled, hasSize(1));
1032
1033 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
1034 assertThat(rules, hasSize(1));
1035
1036 Collection<FlowRule> rulesS1 = rules.stream()
1037 .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
1038 .collect(Collectors.toSet());
1039 assertThat(rulesS1, hasSize(1));
1040 FlowRule ruleS1 = rulesS1.stream()
1041 .filter(rule -> {
1042 PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
1043 return inPort.port().equals(d1p0.port());
1044 })
1045 .findFirst()
1046 .get();
1047 assertThat(ruleS1.selector(), Is.is(
1048 DefaultTrafficSelector
1049 .builder(ipPrefixSelector)
1050 .matchVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId())
1051 .matchInPort(d1p0.port())
1052 .build()
1053 ));
1054 assertThat(ruleS1.treatment(), Is.is(
1055 DefaultTrafficTreatment
1056 .builder()
1057 .setEthDst(((ModEtherInstruction) ethDstTreatment
1058 .allInstructions()
1059 .stream()
1060 .filter(instruction -> instruction instanceof ModEtherInstruction)
1061 .findFirst().get()).mac())
1062 .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
1063 .setOutput(d1p10.port())
1064 .setEthDst(((ModEtherInstruction) ethDstTreatment
1065 .allInstructions()
1066 .stream()
1067 .filter(instruction -> instruction instanceof ModEtherInstruction)
1068 .findFirst().get()).mac())
1069 .popVlan()
1070 .pushMpls()
1071 .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
1072 .setOutput(d1p11.port())
1073 .build()
1074 ));
1075
1076 sut.deactivate();
1077
1078 }
1079
Sho SHIMIZUee2aa652015-02-25 18:56:43 -08001080}