blob: 31e1cdec36e3cd267876c143628952344aff6abd [file] [log] [blame]
Luca Pretee4a5e1a2016-09-07 17:01:22 -07001/*
2 * Copyright 2015-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.sdnip;
18
19import com.google.common.collect.Lists;
20import com.google.common.collect.Sets;
21import org.junit.Before;
22import org.junit.Test;
23import org.onlab.packet.Ethernet;
24import org.onlab.packet.Ip4Address;
25import org.onlab.packet.Ip4Prefix;
26import org.onlab.packet.IpAddress;
27import org.onlab.packet.IpPrefix;
28import org.onlab.packet.MacAddress;
29import org.onlab.packet.VlanId;
30import org.onosproject.TestApplicationId;
31import org.onosproject.core.ApplicationId;
32import org.onosproject.core.CoreServiceAdapter;
33import org.onosproject.incubator.net.intf.Interface;
34import org.onosproject.incubator.net.intf.InterfaceEvent;
35import org.onosproject.incubator.net.intf.InterfaceListener;
36import org.onosproject.incubator.net.intf.InterfaceService;
37import org.onosproject.incubator.net.intf.InterfaceServiceAdapter;
38import org.onosproject.incubator.net.routing.ResolvedRoute;
39import org.onosproject.incubator.net.routing.RouteEvent;
40import org.onosproject.incubator.net.routing.RouteListener;
41import org.onosproject.incubator.net.routing.RouteServiceAdapter;
42import org.onosproject.net.ConnectPoint;
43import org.onosproject.net.DeviceId;
44import org.onosproject.net.FilteredConnectPoint;
45import org.onosproject.net.PortNumber;
46import org.onosproject.net.flow.DefaultTrafficSelector;
47import org.onosproject.net.flow.DefaultTrafficTreatment;
48import org.onosproject.net.flow.TrafficSelector;
49import org.onosproject.net.flow.TrafficTreatment;
50import org.onosproject.net.host.InterfaceIpAddress;
51import org.onosproject.net.intent.AbstractIntentTest;
52import org.onosproject.net.intent.Key;
53import org.onosproject.net.intent.MultiPointToSinglePointIntent;
54import org.onosproject.routing.IntentSynchronizationService;
55
56import java.util.Collections;
57import java.util.List;
58import java.util.Set;
59
60import static org.easymock.EasyMock.anyObject;
61import static org.easymock.EasyMock.createMock;
62import static org.easymock.EasyMock.expect;
63import static org.easymock.EasyMock.expectLastCall;
64import static org.easymock.EasyMock.replay;
65import static org.easymock.EasyMock.reset;
66import static org.easymock.EasyMock.verify;
67import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId;
68
69/**
70 * Unit tests for SdnIpFib.
71 */
72public class SdnIpFibTest extends AbstractIntentTest {
73
74 private InterfaceService interfaceService;
75
76 private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
77 DeviceId.deviceId("of:0000000000000001"),
78 PortNumber.portNumber(1));
79
80 private static final ConnectPoint SW2_ETH1 = new ConnectPoint(
81 DeviceId.deviceId("of:0000000000000002"),
82 PortNumber.portNumber(1));
83
84 private static final ConnectPoint SW3_ETH1 = new ConnectPoint(
85 DeviceId.deviceId("of:0000000000000003"),
86 PortNumber.portNumber(1));
87
88 private static final ConnectPoint SW4_ETH1 = new ConnectPoint(
89 DeviceId.deviceId("of:0000000000000004"),
90 PortNumber.portNumber(1));
91
92 private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01");
93 private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02");
94 private static final MacAddress MAC3 = MacAddress.valueOf("00:00:00:00:00:03");
95 private static final MacAddress MAC4 = MacAddress.valueOf("00:00:00:00:00:04");
96
97 private static final VlanId NO_VLAN = VlanId.NONE;
98 private static final VlanId VLAN10 = VlanId.vlanId(Short.valueOf("10"));
99 private static final VlanId VLAN20 = VlanId.vlanId(Short.valueOf("20"));
100
101 private static final InterfaceIpAddress IIP1 =
102 InterfaceIpAddress.valueOf("192.168.10.101/24");
103 private static final InterfaceIpAddress IIP2 =
104 InterfaceIpAddress.valueOf("192.168.20.101/24");
105 private static final InterfaceIpAddress IIP3 =
106 InterfaceIpAddress.valueOf("192.168.30.101/24");
107 private static final InterfaceIpAddress IIP4 =
108 InterfaceIpAddress.valueOf("192.168.40.101/24");
109
110 private static final IpAddress IP1 = Ip4Address.valueOf("192.168.10.1");
111 private static final IpAddress IP2 = Ip4Address.valueOf("192.168.20.1");
112 private static final IpAddress IP3 = Ip4Address.valueOf("192.168.30.1");
113
114 private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24");
115 private static final IpPrefix PREFIX2 = Ip4Prefix.valueOf("1.1.2.0/24");
116
117 private SdnIpFib sdnipFib;
118 private IntentSynchronizationService intentSynchronizer;
119 private final Set<Interface> interfaces = Sets.newHashSet();
120
121 private static final ApplicationId APPID = TestApplicationId.create("SDNIP");
122
123 private RouteListener routeListener;
124 private InterfaceListener interfaceListener;
125
126 @Before
127 public void setUp() throws Exception {
128 super.setUp();
129
130 interfaceService = createMock(InterfaceService.class);
131
132 interfaceService.addListener(anyObject(InterfaceListener.class));
133 expectLastCall().andDelegateTo(new InterfaceServiceDelegate());
134
135 // These will set expectations on routingConfig and interfaceService
136 setUpInterfaceService();
137
138 replay(interfaceService);
139
140 intentSynchronizer = createMock(IntentSynchronizationService.class);
141
142 sdnipFib = new SdnIpFib();
143 sdnipFib.routeService = new TestRouteService();
144 sdnipFib.coreService = new TestCoreService();
145 sdnipFib.interfaceService = interfaceService;
146 sdnipFib.intentSynchronizer = intentSynchronizer;
147
148 sdnipFib.activate();
149 }
150
151 /**
152 * Sets up the interface service.
153 */
154 private void setUpInterfaceService() {
155 List<InterfaceIpAddress> iIps1 = Lists.newArrayList();
156 iIps1.add(IIP1);
157 Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, iIps1, MAC1, VLAN10);
158 interfaces.add(sw1Eth1);
159
160 List<InterfaceIpAddress> iIps2 = Lists.newArrayList();
161 iIps2.add(IIP2);
162 Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, iIps2, MAC2, VLAN20);
163 interfaces.add(sw2Eth1);
164
165 List<InterfaceIpAddress> iIps3 = Lists.newArrayList();
166 iIps3.add(IIP3);
167 Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, iIps3, MAC3, NO_VLAN);
168 interfaces.add(sw3Eth1);
169
170 expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn(
171 Collections.singleton(sw1Eth1)).anyTimes();
172 expect(interfaceService.getMatchingInterface(IP1))
173 .andReturn(sw1Eth1).anyTimes();
174 expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn(
175 Collections.singleton(sw2Eth1)).anyTimes();
176 expect(interfaceService.getMatchingInterface(IP2))
177 .andReturn(sw2Eth1).anyTimes();
178 expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn(
179 Collections.singleton(sw3Eth1)).anyTimes();
180 expect(interfaceService.getMatchingInterface(IP3))
181 .andReturn(sw3Eth1).anyTimes();
182 expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
183 }
184
185 /**
186 * Tests adding a route. The egress interface has no VLAN configured.
187 *
188 * We verify that the synchronizer records the correct state and that the
189 * correct intent is submitted to the IntentService.
190 */
191 @Test
192 public void testRouteAddToNoVlan() {
193 // Build the expected route
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700194 ResolvedRoute route = new ResolvedRoute(PREFIX1, IP3, MAC3, SW3_ETH1);
Luca Pretee4a5e1a2016-09-07 17:01:22 -0700195
196 MultiPointToSinglePointIntent intent =
197 createIntentToThreeSrcOneTwo(PREFIX1);
198
199 // Setup the expected intents
200 intentSynchronizer.submit(eqExceptId(intent));
201 replay(intentSynchronizer);
202
203 // Send in the added event
204 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
205
206 verify(intentSynchronizer);
207 }
208
209 /**
210 * Tests adding a route. The egress interface has a VLAN configured.
211 *
212 * We verify that the synchronizer records the correct state and that the
213 * correct intent is submitted to the IntentService.
214 */
215 @Test
216 public void testRouteAddToVlan() {
217 // Build the expected route
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700218 ResolvedRoute route = new ResolvedRoute(PREFIX2, IP1, MAC1, SW1_ETH1);
Luca Pretee4a5e1a2016-09-07 17:01:22 -0700219
220 MultiPointToSinglePointIntent intent = createIntentToOne(PREFIX2);
221
222 // Setup the expected intents
223 intentSynchronizer.submit(eqExceptId(intent));
224 replay(intentSynchronizer);
225
226 // Send in the added event
227 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
228
229 verify(intentSynchronizer);
230 }
231
232 /**
233 * Tests updating a route.
234 *
235 * We first add a route from a next-hop with no vlan. We then announce the
236 * same route from another next-hop with a vlan.
237 *
238 * We verify that the synchronizer records the correct state and that the
239 * correct intent is submitted to the IntentService.
240 */
241 @Test
242 public void testRouteUpdatesToVlan() {
243 // Add a route first to a destination with no VLAN
244 testRouteAddToNoVlan();
245
246 // Build the new route entries for prefix1 and prefix2
Charles Chane4d13102016-11-08 15:38:44 -0800247 ResolvedRoute oldRoutePrefixOne = new ResolvedRoute(PREFIX1, IP3, MAC3, SW3_ETH1);
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700248 ResolvedRoute routePrefixOne = new ResolvedRoute(PREFIX1, IP1, MAC1, SW1_ETH1);
Luca Pretee4a5e1a2016-09-07 17:01:22 -0700249
250 // Create the new expected intents
251 MultiPointToSinglePointIntent newPrefixOneIntent = createIntentToOne(PREFIX1);
252
253 // Set up test expectation
254 reset(intentSynchronizer);
255
256 // Setup the expected intents
257 intentSynchronizer.submit(eqExceptId(newPrefixOneIntent));
258 replay(intentSynchronizer);
259
260 // Send in the update events
261 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED,
Charles Chane4d13102016-11-08 15:38:44 -0800262 routePrefixOne, oldRoutePrefixOne));
Luca Pretee4a5e1a2016-09-07 17:01:22 -0700263
264 verify(intentSynchronizer);
265 }
266
267 /**
268 * Tests updating a route.
269 *
270 * We first add a route from a next-hop with a vlan. We then announce the
271 * same route from another next-hop with no vlan.
272 *
273 * We verify that the synchronizer records the correct state and that the
274 * correct intent is submitted to the IntentService.
275 */
276 @Test
277 public void testRouteUpdatesToNoVlan() {
278 // Add a route first to a destination with no VLAN
279 testRouteAddToVlan();
280
281 // Build the new route entries for prefix1 and prefix2
Charles Chane4d13102016-11-08 15:38:44 -0800282 ResolvedRoute oldRoutePrefix = new ResolvedRoute(PREFIX2, IP1, MAC1, SW1_ETH1);
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700283 ResolvedRoute routePrefix = new ResolvedRoute(PREFIX2, IP3, MAC3, SW3_ETH1);
Luca Pretee4a5e1a2016-09-07 17:01:22 -0700284
285 // Create the new expected intents
286 MultiPointToSinglePointIntent newPrefixIntent =
287 createIntentToThreeSrcOneTwo(PREFIX2);
288
289 // Set up test expectation
290 reset(intentSynchronizer);
291
292 // Setup the expected intents
293 intentSynchronizer.submit(eqExceptId(newPrefixIntent));
294 replay(intentSynchronizer);
295
296 // Send in the update events
297 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED,
Charles Chane4d13102016-11-08 15:38:44 -0800298 routePrefix, oldRoutePrefix));
Luca Pretee4a5e1a2016-09-07 17:01:22 -0700299
300 verify(intentSynchronizer);
301 }
302
303 /**
304 * Tests deleting a route.
305 *
306 * We verify that the synchronizer records the correct state and that the
307 * correct intent is withdrawn from the IntentService.
308 */
309 @Test
310 public void testRouteDelete() {
311 // Add a route first
312 testRouteAddToNoVlan();
313
314 // Construct the existing route entry
Charles Chane4d13102016-11-08 15:38:44 -0800315 ResolvedRoute route = new ResolvedRoute(PREFIX1, IP3, MAC3, SW3_ETH1);
Luca Pretee4a5e1a2016-09-07 17:01:22 -0700316
317 // Create existing intent
318 MultiPointToSinglePointIntent removedIntent =
319 createIntentToThreeSrcOneTwo(PREFIX1);
320
321 // Set up expectation
322 reset(intentSynchronizer);
323 // Setup the expected intents
324 intentSynchronizer.withdraw(eqExceptId(removedIntent));
325 replay(intentSynchronizer);
326
327 // Send in the removed event
328 routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route));
329
330 verify(intentSynchronizer);
331 }
332
333 /**
334 * Tests adding a new interface.
335 *
336 * We verify that the synchronizer records the correct state and that the
337 * correct intent is withdrawn from the IntentService.
338 */
339 @Test
340 public void testAddInterface() {
341 // Add a route first
342 testRouteAddToNoVlan();
343
344 // Create the new expected intent
345 MultiPointToSinglePointIntent addedIntent =
346 createIntentToThreeSrcOneTwoFour(PREFIX1);
347
348 reset(intentSynchronizer);
349
350 intentSynchronizer.submit(eqExceptId(addedIntent));
351 expectLastCall().once();
352
353 replay(intentSynchronizer);
354
355 // Create the new interface and add notify it
356 Interface intf = new Interface("sw4-eth1", SW4_ETH1,
357 Collections.singletonList(IIP4),
358 MAC4, NO_VLAN);
359 InterfaceEvent intfEvent =
360 new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, intf);
361
362 interfaceListener.event(intfEvent);
363
364 verify(intentSynchronizer);
365 }
366
367 /**
368 * Tests removing an existing interface.
369 *
370 * We first push an intent with destination sw3 and source sw1 and sw2. We
371 * then remove the ingress interface on sw1.
372 *
373 * We verify that the synchronizer records the correct state and that the
374 * correct intent is withdrawn from the IntentService.
375 */
376 @Test
377 public void testRemoveIngressInterface() {
378 // Add a route first
379 testRouteAddToNoVlan();
380
381 // Create the new expected intent
382 MultiPointToSinglePointIntent remainingIntent =
383 createIntentToThreeSrcTwo(PREFIX1);
384
385 reset(intentSynchronizer);
386
387 intentSynchronizer.submit(eqExceptId(remainingIntent));
388 expectLastCall().once();
389
390 replay(intentSynchronizer);
391
392 // Define the existing ingress interface and remove it
393 Interface intf = new Interface("sw1-eth1", SW1_ETH1,
394 Collections.singletonList(IIP1),
395 MAC1, VLAN10);
396 InterfaceEvent intfEvent =
397 new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, intf);
398 interfaceListener.event(intfEvent);
399
400 verify(intentSynchronizer);
401 }
402
403 /**
404 * Tests removing an existing egress interface.
405 *
406 * We first push an intent with destination sw3 and source sw1 and sw2. We
407 * then remove the egress interface on sw3.
408 *
409 * We verify that the synchronizer records the correct state and that the
410 * correct intent is withdrawn from the IntentService.
411 */
412 @Test
413 public void testRemoveEgressInterface() {
414 // Add a route first
415 testRouteAddToNoVlan();
416
417 // Create existing intent
418 MultiPointToSinglePointIntent removedIntent =
419 createIntentToThreeSrcOneTwo(PREFIX1);
420
421 // Set up expectation
422 reset(intentSynchronizer);
423 // Setup the expected intents
424 intentSynchronizer.withdraw(eqExceptId(removedIntent));
425 replay(intentSynchronizer);
426
427 // Define the existing egress interface and remove it
428 Interface intf = new Interface("sw3-eth1", SW3_ETH1,
429 Collections.singletonList(IIP3),
430 MAC3, VlanId.NONE);
431 InterfaceEvent intfEvent =
432 new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, intf);
433 interfaceListener.event(intfEvent);
434
435 verify(intentSynchronizer);
436 }
437
438 /*
439 * Builds a MultiPointToSinglePointIntent with dest sw1 (VLAN Id) and src
440 * sw2, sw3.
441 */
442 private MultiPointToSinglePointIntent createIntentToOne(IpPrefix ipPrefix) {
443 // Build the expected treatment
444 TrafficTreatment.Builder treatmentBuilder =
445 DefaultTrafficTreatment.builder();
446 treatmentBuilder.setEthDst(MAC1);
447
448 // Build the expected egress FilteredConnectPoint
449 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
450 selector.matchVlanId(VLAN10);
451 FilteredConnectPoint egressFilteredCP =
452 new FilteredConnectPoint(SW1_ETH1, selector.build());
453
454 // Build the expected selectors
455 Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet();
456
457 // Build the expected ingress FilteredConnectPoint for sw2
458 selector = DefaultTrafficSelector.builder();
459 selector.matchVlanId(VLAN20);
460 selector.matchEthType(Ethernet.TYPE_IPV4);
461 selector.matchIPDst(ipPrefix);
462 FilteredConnectPoint ingressFilteredCP =
463 new FilteredConnectPoint(SW2_ETH1, selector.build());
464 ingressFilteredCPs.add(ingressFilteredCP);
465
466 // Build the expected ingress FilteredConnectPoint for sw3
467 selector = DefaultTrafficSelector.builder();
468 selector.matchEthType(Ethernet.TYPE_IPV4);
469 selector.matchIPDst(ipPrefix);
470 ingressFilteredCP = new FilteredConnectPoint(SW3_ETH1, selector.build());
471 ingressFilteredCPs.add(ingressFilteredCP);
472
473 // Build the expected intent
474 MultiPointToSinglePointIntent intent =
475 MultiPointToSinglePointIntent.builder()
476 .appId(APPID)
477 .key(Key.of(ipPrefix.toString(), APPID))
478 .filteredIngressPoints(ingressFilteredCPs)
479 .filteredEgressPoint(egressFilteredCP)
480 .treatment(treatmentBuilder.build())
481 .constraints(SdnIpFib.CONSTRAINTS)
482 .build();
483
484 return intent;
485 }
486
487 /*
488 * Builds a MultiPointToSinglePointIntent with dest sw3 (no VLAN Id) and src
489 * sw1, sw2.
490 */
491 private MultiPointToSinglePointIntent createIntentToThreeSrcOneTwo(IpPrefix ipPrefix) {
492 // Build the expected treatment
493 TrafficTreatment.Builder treatmentBuilder =
494 DefaultTrafficTreatment.builder();
495 treatmentBuilder.setEthDst(MAC3);
496
497 // Build the expected egress FilteredConnectPoint
498 FilteredConnectPoint egressFilteredCP = new FilteredConnectPoint(SW3_ETH1);
499
500 // Build the expected selectors
501 Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet();
502
503 // Build the expected ingress FilteredConnectPoint for sw1
504 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
505 selector.matchVlanId(VLAN10);
506 selector.matchEthType(Ethernet.TYPE_IPV4);
507 selector.matchIPDst(ipPrefix);
508 FilteredConnectPoint ingressFilteredCP =
509 new FilteredConnectPoint(SW1_ETH1, selector.build());
510 ingressFilteredCPs.add(ingressFilteredCP);
511
512 // Build the expected ingress FilteredConnectPoint for sw2
513 selector = DefaultTrafficSelector.builder();
514 selector.matchVlanId(VLAN20);
515 selector.matchEthType(Ethernet.TYPE_IPV4);
516 selector.matchIPDst(ipPrefix);
517 ingressFilteredCP = new FilteredConnectPoint(SW2_ETH1, selector.build());
518 ingressFilteredCPs.add(ingressFilteredCP);
519
520 // Build the expected intent
521 MultiPointToSinglePointIntent intent =
522 MultiPointToSinglePointIntent.builder()
523 .appId(APPID)
524 .key(Key.of(ipPrefix.toString(), APPID))
525 .filteredIngressPoints(ingressFilteredCPs)
526 .filteredEgressPoint(egressFilteredCP)
527 .treatment(treatmentBuilder.build())
528 .constraints(SdnIpFib.CONSTRAINTS)
529 .build();
530
531 return intent;
532 }
533
534 /*
535 * Builds a MultiPointToSinglePointIntent with dest sw3 (no VLAN Id) and src
536 * sw2.
537 */
538 private MultiPointToSinglePointIntent createIntentToThreeSrcTwo(IpPrefix ipPrefix) {
539 // Build the expected treatment
540 TrafficTreatment.Builder treatmentBuilder =
541 DefaultTrafficTreatment.builder();
542 treatmentBuilder.setEthDst(MAC3);
543
544 // Build the expected egress FilteredConnectPoint
545 FilteredConnectPoint egressFilteredCP = new FilteredConnectPoint(SW3_ETH1);
546
547 // Build the expected ingress FilteredConnectPoint for sw2
548 Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet();
549 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
550 selector.matchVlanId(VLAN20);
551 selector.matchEthType(Ethernet.TYPE_IPV4);
552 selector.matchIPDst(ipPrefix);
553 FilteredConnectPoint ingressFilteredCP =
554 new FilteredConnectPoint(SW2_ETH1, selector.build());
555 ingressFilteredCPs.add(ingressFilteredCP);
556
557 // Build the expected intent
558 MultiPointToSinglePointIntent intent =
559 MultiPointToSinglePointIntent.builder()
560 .appId(APPID)
561 .key(Key.of(ipPrefix.toString(), APPID))
562 .filteredIngressPoints(ingressFilteredCPs)
563 .filteredEgressPoint(egressFilteredCP)
564 .treatment(treatmentBuilder.build())
565 .constraints(SdnIpFib.CONSTRAINTS)
566 .build();
567
568 return intent;
569 }
570
571 /*
572 * Builds a MultiPointToSinglePointIntent with dest sw3 (no VLAN Id) and src
573 * sw1, sw2, sw4.
574 */
575 private MultiPointToSinglePointIntent createIntentToThreeSrcOneTwoFour(IpPrefix ipPrefix) {
576 // Build the expected treatment
577 TrafficTreatment.Builder treatmentBuilder =
578 DefaultTrafficTreatment.builder();
579 treatmentBuilder.setEthDst(MAC3);
580
581 // Build the expected egress FilteredConnectPoint
582 FilteredConnectPoint egressFilteredCP = new FilteredConnectPoint(SW3_ETH1);
583
584 // Build the expected selectors
585 Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet();
586
587 // Build the expected ingress FilteredConnectPoint for sw1
588 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
589 selector.matchVlanId(VLAN10);
590 selector.matchEthType(Ethernet.TYPE_IPV4);
591 selector.matchIPDst(ipPrefix);
592 FilteredConnectPoint ingressFilteredCP =
593 new FilteredConnectPoint(SW1_ETH1, selector.build());
594 ingressFilteredCPs.add(ingressFilteredCP);
595
596 // Build the expected ingress FilteredConnectPoint for sw2
597 selector = DefaultTrafficSelector.builder();
598 selector.matchVlanId(VLAN20);
599 selector.matchEthType(Ethernet.TYPE_IPV4);
600 selector.matchIPDst(ipPrefix);
601 ingressFilteredCP = new FilteredConnectPoint(SW2_ETH1, selector.build());
602 ingressFilteredCPs.add(ingressFilteredCP);
603
604 // Build the expected ingress FilteredConnectPoint for sw4
605 selector = DefaultTrafficSelector.builder();
606 selector.matchEthType(Ethernet.TYPE_IPV4);
607 selector.matchIPDst(ipPrefix);
608 ingressFilteredCP = new FilteredConnectPoint(SW4_ETH1, selector.build());
609 ingressFilteredCPs.add(ingressFilteredCP);
610
611 // Build the expected intent
612 MultiPointToSinglePointIntent intent =
613 MultiPointToSinglePointIntent.builder()
614 .appId(APPID)
615 .key(Key.of(ipPrefix.toString(), APPID))
616 .filteredIngressPoints(ingressFilteredCPs)
617 .filteredEgressPoint(egressFilteredCP)
618 .treatment(treatmentBuilder.build())
619 .constraints(SdnIpFib.CONSTRAINTS)
620 .build();
621
622 return intent;
623 }
624
625 private class TestCoreService extends CoreServiceAdapter {
626 @Override
627 public ApplicationId getAppId(String name) {
628 return APPID;
629 }
630 }
631
632 private class TestRouteService extends RouteServiceAdapter {
633 @Override
634 public void addListener(RouteListener routeListener) {
635 SdnIpFibTest.this.routeListener = routeListener;
636 }
637 }
638
639 private class InterfaceServiceDelegate extends InterfaceServiceAdapter {
640 @Override
641 public void addListener(InterfaceListener listener) {
642 SdnIpFibTest.this.interfaceListener = listener;
643 }
644 }
645}