blob: 898b8bb408e754e76d91d02dd17d81e82ab62e74 [file] [log] [blame]
Jonathan Hart9a426f82015-09-03 15:43:13 +02001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Jonathan Hart9a426f82015-09-03 15:43:13 +02003 *
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
Jonathan Hart00cddda2016-02-16 10:30:37 -080019import com.google.common.collect.Lists;
Jonathan Hart9a426f82015-09-03 15:43:13 +020020import 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;
Jonathan Hart365335e2015-12-10 11:09:53 -080032import org.onosproject.core.CoreServiceAdapter;
Jonathan Hart9a426f82015-09-03 15:43:13 +020033import org.onosproject.incubator.net.intf.Interface;
Jonathan Hartb14221c2016-03-07 09:55:50 -080034import org.onosproject.incubator.net.intf.InterfaceEvent;
35import org.onosproject.incubator.net.intf.InterfaceListener;
Jonathan Hart9a426f82015-09-03 15:43:13 +020036import org.onosproject.incubator.net.intf.InterfaceService;
Jonathan Hartb14221c2016-03-07 09:55:50 -080037import org.onosproject.incubator.net.intf.InterfaceServiceAdapter;
Jonathan Hart9a426f82015-09-03 15:43:13 +020038import org.onosproject.net.ConnectPoint;
39import org.onosproject.net.DeviceId;
40import org.onosproject.net.PortNumber;
41import org.onosproject.net.flow.DefaultTrafficSelector;
42import org.onosproject.net.flow.DefaultTrafficTreatment;
43import org.onosproject.net.flow.TrafficSelector;
44import org.onosproject.net.flow.TrafficTreatment;
45import org.onosproject.net.host.InterfaceIpAddress;
46import org.onosproject.net.intent.AbstractIntentTest;
47import org.onosproject.net.intent.Key;
48import org.onosproject.net.intent.MultiPointToSinglePointIntent;
49import org.onosproject.routing.FibEntry;
Jonathan Hart365335e2015-12-10 11:09:53 -080050import org.onosproject.routing.FibListener;
Jonathan Hart9a426f82015-09-03 15:43:13 +020051import org.onosproject.routing.FibUpdate;
52import org.onosproject.routing.IntentSynchronizationService;
Jonathan Hart365335e2015-12-10 11:09:53 -080053import org.onosproject.routing.RoutingServiceAdapter;
Jonathan Hart9a426f82015-09-03 15:43:13 +020054
55import java.util.Collections;
Jonathan Hart9a426f82015-09-03 15:43:13 +020056import java.util.HashSet;
Jonathan Hart00cddda2016-02-16 10:30:37 -080057import java.util.List;
Jonathan Hart9a426f82015-09-03 15:43:13 +020058import java.util.Set;
59
Jonathan Hartb14221c2016-03-07 09:55:50 -080060import static org.easymock.EasyMock.anyObject;
Jonathan Hart9a426f82015-09-03 15:43:13 +020061import static org.easymock.EasyMock.createMock;
62import static org.easymock.EasyMock.expect;
Jonathan Hartb14221c2016-03-07 09:55:50 -080063import static org.easymock.EasyMock.expectLastCall;
Jonathan Hart9a426f82015-09-03 15:43:13 +020064import static org.easymock.EasyMock.replay;
65import static org.easymock.EasyMock.reset;
66import static org.easymock.EasyMock.verify;
Jonathan Hart33b81f22016-02-05 09:25:50 -080067import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId;
Jonathan Hart9a426f82015-09-03 15:43:13 +020068
69/**
70 * Unit tests for SdnIpFib.
71 */
72public class SdnIpFibTest extends AbstractIntentTest {
73
Jonathan Hart9a426f82015-09-03 15:43:13 +020074 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
Jonathan Hartb14221c2016-03-07 09:55:50 -080092 private static final ConnectPoint SW5_ETH1 = new ConnectPoint(
93 DeviceId.deviceId("of:0000000000000005"),
94 PortNumber.portNumber(1));
95
Jonathan Hart9a426f82015-09-03 15:43:13 +020096 private SdnIpFib sdnipFib;
97 private IntentSynchronizationService intentSynchronizer;
98 private final Set<Interface> interfaces = Sets.newHashSet();
99
100 private static final ApplicationId APPID = TestApplicationId.create("SDNIP");
101
Jonathan Hart365335e2015-12-10 11:09:53 -0800102 private FibListener fibListener;
Jonathan Hartb14221c2016-03-07 09:55:50 -0800103 private InterfaceListener interfaceListener;
Jonathan Hart365335e2015-12-10 11:09:53 -0800104
Jonathan Hart9a426f82015-09-03 15:43:13 +0200105 @Before
106 public void setUp() throws Exception {
107 super.setUp();
108
Jonathan Hart9a426f82015-09-03 15:43:13 +0200109 interfaceService = createMock(InterfaceService.class);
Jonathan Hartb14221c2016-03-07 09:55:50 -0800110 interfaceService.addListener(anyObject(InterfaceListener.class));
111 expectLastCall().andDelegateTo(new InterfaceServiceDelegate());
Jonathan Hart9a426f82015-09-03 15:43:13 +0200112
113 // These will set expectations on routingConfig and interfaceService
114 setUpInterfaceService();
Jonathan Hart9a426f82015-09-03 15:43:13 +0200115
Jonathan Hart9a426f82015-09-03 15:43:13 +0200116 replay(interfaceService);
117
118 intentSynchronizer = createMock(IntentSynchronizationService.class);
119
Jonathan Hart365335e2015-12-10 11:09:53 -0800120 sdnipFib = new SdnIpFib();
121 sdnipFib.routingService = new TestRoutingService();
122 sdnipFib.coreService = new TestCoreService();
123 sdnipFib.interfaceService = interfaceService;
124 sdnipFib.intentSynchronizer = intentSynchronizer;
125
126 sdnipFib.activate();
Jonathan Hart9a426f82015-09-03 15:43:13 +0200127 }
128
129 /**
Jonathan Hart9a426f82015-09-03 15:43:13 +0200130 * Sets up InterfaceService.
131 */
132 private void setUpInterfaceService() {
Jonathan Hart00cddda2016-02-16 10:30:37 -0800133 List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList();
Jonathan Hart9a426f82015-09-03 15:43:13 +0200134 interfaceIpAddresses1.add(new InterfaceIpAddress(
135 IpAddress.valueOf("192.168.10.101"),
136 IpPrefix.valueOf("192.168.10.0/24")));
Jonathan Hartb14221c2016-03-07 09:55:50 -0800137 Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1,
Jonathan Hart9a426f82015-09-03 15:43:13 +0200138 interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"),
139 VlanId.NONE);
140 interfaces.add(sw1Eth1);
141
Jonathan Hart00cddda2016-02-16 10:30:37 -0800142 List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList();
Jonathan Hart9a426f82015-09-03 15:43:13 +0200143 interfaceIpAddresses2.add(
144 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"),
145 IpPrefix.valueOf("192.168.20.0/24")));
Jonathan Hartb14221c2016-03-07 09:55:50 -0800146 Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1,
Jonathan Hart9a426f82015-09-03 15:43:13 +0200147 interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"),
148 VlanId.NONE);
149 interfaces.add(sw2Eth1);
150
Jonathan Hart00cddda2016-02-16 10:30:37 -0800151 List<InterfaceIpAddress> interfaceIpAddresses3 = Lists.newArrayList();
Jonathan Hart9a426f82015-09-03 15:43:13 +0200152 interfaceIpAddresses3.add(
153 new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
154 IpPrefix.valueOf("192.168.30.0/24")));
Jonathan Hartb14221c2016-03-07 09:55:50 -0800155 Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1,
Jonathan Hart9a426f82015-09-03 15:43:13 +0200156 interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"),
157 VlanId.NONE);
158 interfaces.add(sw3Eth1);
159
160 InterfaceIpAddress interfaceIpAddress4 =
161 new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"),
162 IpPrefix.valueOf("192.168.40.0/24"));
Jonathan Hartb14221c2016-03-07 09:55:50 -0800163 Interface sw4Eth1 = new Interface("sw4-eth1", SW4_ETH1,
Jonathan Hart00cddda2016-02-16 10:30:37 -0800164 Lists.newArrayList(interfaceIpAddress4),
Jonathan Hart9a426f82015-09-03 15:43:13 +0200165 MacAddress.valueOf("00:00:00:00:00:04"),
166 VlanId.vlanId((short) 1));
167
168 expect(interfaceService.getInterfacesByPort(SW4_ETH1)).andReturn(
169 Collections.singleton(sw4Eth1)).anyTimes();
170 expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.40.1")))
171 .andReturn(sw4Eth1).anyTimes();
172
173 interfaces.add(sw4Eth1);
174
175 expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn(
176 Collections.singleton(sw1Eth1)).anyTimes();
177 expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1")))
178 .andReturn(sw1Eth1).anyTimes();
179 expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn(
180 Collections.singleton(sw2Eth1)).anyTimes();
181 expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1")))
182 .andReturn(sw2Eth1).anyTimes();
183 expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn(
184 Collections.singleton(sw3Eth1)).anyTimes();
185 expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1")))
186 .andReturn(sw3Eth1).anyTimes();
187 expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
188 }
189
190 /**
191 * Tests adding a FIB entry to the IntentSynchronizer.
192 *
193 * We verify that the synchronizer records the correct state and that the
194 * correct intent is submitted to the IntentService.
195 */
196 @Test
197 public void testFibAdd() {
198 IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
199 FibEntry fibEntry = new FibEntry(prefix,
200 Ip4Address.valueOf("192.168.10.1"),
201 MacAddress.valueOf("00:00:00:00:00:01"));
202
203 // Construct a MultiPointToSinglePointIntent intent
204 TrafficSelector.Builder selectorBuilder =
205 DefaultTrafficSelector.builder();
206 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
207 fibEntry.prefix());
208
209 TrafficTreatment.Builder treatmentBuilder =
210 DefaultTrafficTreatment.builder();
211 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
212
213 Set<ConnectPoint> ingressPoints = new HashSet<>();
214 ingressPoints.add(SW2_ETH1);
215 ingressPoints.add(SW3_ETH1);
216 ingressPoints.add(SW4_ETH1);
217
218 MultiPointToSinglePointIntent intent =
219 MultiPointToSinglePointIntent.builder()
220 .appId(APPID)
221 .key(Key.of(prefix.toString(), APPID))
222 .selector(selectorBuilder.build())
223 .treatment(treatmentBuilder.build())
224 .ingressPoints(ingressPoints)
225 .egressPoint(SW1_ETH1)
226 .constraints(SdnIpFib.CONSTRAINTS)
227 .build();
228
229 // Setup the expected intents
230 intentSynchronizer.submit(eqExceptId(intent));
231 replay(intentSynchronizer);
232
233 // Send in the UPDATE FibUpdate
234 FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry);
Jonathan Hart365335e2015-12-10 11:09:53 -0800235 fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList());
Jonathan Hart9a426f82015-09-03 15:43:13 +0200236
237 verify(intentSynchronizer);
238 }
239
240 /**
241 * Tests adding a FIB entry with to a next hop in a VLAN.
242 *
243 * We verify that the synchronizer records the correct state and that the
244 * correct intent is submitted to the IntentService.
245 */
246 @Test
247 public void testFibAddWithVlan() {
248 IpPrefix prefix = Ip4Prefix.valueOf("3.3.3.0/24");
249 FibEntry fibEntry = new FibEntry(prefix,
250 Ip4Address.valueOf("192.168.40.1"),
251 MacAddress.valueOf("00:00:00:00:00:04"));
252
253 // Construct a MultiPointToSinglePointIntent intent
254 TrafficSelector.Builder selectorBuilder =
255 DefaultTrafficSelector.builder();
256 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4)
257 .matchIPDst(fibEntry.prefix())
258 .matchVlanId(VlanId.ANY);
259
260 TrafficTreatment.Builder treatmentBuilder =
261 DefaultTrafficTreatment.builder();
262 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:04"))
263 .setVlanId(VlanId.vlanId((short) 1));
264
265 Set<ConnectPoint> ingressPoints = new HashSet<>();
266 ingressPoints.add(SW1_ETH1);
267 ingressPoints.add(SW2_ETH1);
268 ingressPoints.add(SW3_ETH1);
269
270 MultiPointToSinglePointIntent intent =
271 MultiPointToSinglePointIntent.builder()
272 .appId(APPID)
273 .key(Key.of(prefix.toString(), APPID))
274 .selector(selectorBuilder.build())
275 .treatment(treatmentBuilder.build())
276 .ingressPoints(ingressPoints)
277 .egressPoint(SW4_ETH1)
278 .constraints(SdnIpFib.CONSTRAINTS)
279 .build();
280
281 // Setup the expected intents
282 intentSynchronizer.submit(eqExceptId(intent));
283
284 replay(intentSynchronizer);
285
286 // Send in the UPDATE FibUpdate
287 FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry);
Jonathan Hart365335e2015-12-10 11:09:53 -0800288 fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList());
Jonathan Hart9a426f82015-09-03 15:43:13 +0200289
290 verify(intentSynchronizer);
291 }
292
293 /**
294 * Tests updating a FIB entry.
295 *
296 * We verify that the synchronizer records the correct state and that the
297 * correct intent is submitted to the IntentService.
298 */
299 @Test
300 public void testFibUpdate() {
301 // Firstly add a route
302 testFibAdd();
303
304 IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
305
306 // Start to construct a new route entry and new intent
307 FibEntry fibEntryUpdate = new FibEntry(prefix,
308 Ip4Address.valueOf("192.168.20.1"),
309 MacAddress.valueOf("00:00:00:00:00:02"));
310
311 // Construct a new MultiPointToSinglePointIntent intent
312 TrafficSelector.Builder selectorBuilderNew =
313 DefaultTrafficSelector.builder();
314 selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
315 fibEntryUpdate.prefix());
316
317 TrafficTreatment.Builder treatmentBuilderNew =
318 DefaultTrafficTreatment.builder();
319 treatmentBuilderNew.setEthDst(MacAddress.valueOf("00:00:00:00:00:02"));
320
321 Set<ConnectPoint> ingressPointsNew = new HashSet<>();
322 ingressPointsNew.add(SW1_ETH1);
323 ingressPointsNew.add(SW3_ETH1);
324 ingressPointsNew.add(SW4_ETH1);
325
326 MultiPointToSinglePointIntent intentNew =
327 MultiPointToSinglePointIntent.builder()
328 .appId(APPID)
329 .key(Key.of(prefix.toString(), APPID))
330 .selector(selectorBuilderNew.build())
331 .treatment(treatmentBuilderNew.build())
332 .ingressPoints(ingressPointsNew)
333 .egressPoint(SW2_ETH1)
334 .constraints(SdnIpFib.CONSTRAINTS)
335 .build();
336
337 // Set up test expectation
338 reset(intentSynchronizer);
339
340 // Setup the expected intents
341 intentSynchronizer.submit(eqExceptId(intentNew));
342 replay(intentSynchronizer);
343
344 // Send in the UPDATE FibUpdate
345 FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE,
346 fibEntryUpdate);
Jonathan Hart365335e2015-12-10 11:09:53 -0800347 fibListener.update(Collections.singletonList(fibUpdate),
Jonathan Hart9a426f82015-09-03 15:43:13 +0200348 Collections.emptyList());
349
350 verify(intentSynchronizer);
351 }
352
353 /**
354 * Tests deleting a FIB entry.
355 *
356 * We verify that the synchronizer records the correct state and that the
357 * correct intent is withdrawn from the IntentService.
358 */
359 @Test
360 public void testFibDelete() {
361 // Firstly add a route
362 testFibAdd();
363
364 IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
365
366 // Construct the existing route entry
367 FibEntry fibEntry = new FibEntry(prefix, null, null);
368
369 // Construct the existing MultiPointToSinglePoint intent
370 TrafficSelector.Builder selectorBuilder =
371 DefaultTrafficSelector.builder();
372 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
373 fibEntry.prefix());
374
375 TrafficTreatment.Builder treatmentBuilder =
376 DefaultTrafficTreatment.builder();
377 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
378
379 Set<ConnectPoint> ingressPoints = new HashSet<>();
380 ingressPoints.add(SW2_ETH1);
381 ingressPoints.add(SW3_ETH1);
382 ingressPoints.add(SW4_ETH1);
383
384 MultiPointToSinglePointIntent addedIntent =
385 MultiPointToSinglePointIntent.builder()
386 .appId(APPID)
387 .key(Key.of(prefix.toString(), APPID))
388 .selector(selectorBuilder.build())
389 .treatment(treatmentBuilder.build())
390 .ingressPoints(ingressPoints)
391 .egressPoint(SW1_ETH1)
392 .constraints(SdnIpFib.CONSTRAINTS)
393 .build();
394
395 // Set up expectation
396 reset(intentSynchronizer);
397 // Setup the expected intents
398 intentSynchronizer.withdraw(eqExceptId(addedIntent));
399 replay(intentSynchronizer);
400
401 // Send in the DELETE FibUpdate
402 FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.DELETE, fibEntry);
Jonathan Hart365335e2015-12-10 11:09:53 -0800403 fibListener.update(Collections.emptyList(), Collections.singletonList(fibUpdate));
Jonathan Hart9a426f82015-09-03 15:43:13 +0200404
405 verify(intentSynchronizer);
406 }
Jonathan Hart365335e2015-12-10 11:09:53 -0800407
Jonathan Hartb14221c2016-03-07 09:55:50 -0800408 @Test
409 public void testAddInterface() {
410 testFibAdd();
411
412 IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
413
414 // Construct the existing MultiPointToSinglePoint intent
415 TrafficSelector.Builder selectorBuilder =
416 DefaultTrafficSelector.builder();
417 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(prefix);
418
419 TrafficTreatment.Builder treatmentBuilder =
420 DefaultTrafficTreatment.builder();
421 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
422
423 Set<ConnectPoint> ingressPoints = new HashSet<>();
424 ingressPoints.add(SW2_ETH1);
425 ingressPoints.add(SW3_ETH1);
426 ingressPoints.add(SW4_ETH1);
427 ingressPoints.add(SW5_ETH1);
428
429 MultiPointToSinglePointIntent addedIntent =
430 MultiPointToSinglePointIntent.builder()
431 .appId(APPID)
432 .key(Key.of(prefix.toString(), APPID))
433 .selector(selectorBuilder.build())
434 .treatment(treatmentBuilder.build())
435 .ingressPoints(ingressPoints)
436 .egressPoint(SW1_ETH1)
437 .constraints(SdnIpFib.CONSTRAINTS)
438 .build();
439
440 reset(intentSynchronizer);
441
442 intentSynchronizer.submit(eqExceptId(addedIntent));
443 expectLastCall().once();
444
445 replay(intentSynchronizer);
446
447 Interface intf = new Interface("newintf", SW5_ETH1,
448 Collections.singletonList(InterfaceIpAddress.valueOf("192.168.50.101/24")),
449 MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE);
450 InterfaceEvent intfEvent = new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, intf);
451 interfaceListener.event(intfEvent);
452
453 verify(intentSynchronizer);
454 }
455
456 @Test
457 public void testRemoveInterface() {
458 testFibAdd();
459
460 IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
461
462 // Construct the existing MultiPointToSinglePoint intent
463 TrafficSelector.Builder selectorBuilder =
464 DefaultTrafficSelector.builder();
465 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(prefix);
466
467 TrafficTreatment.Builder treatmentBuilder =
468 DefaultTrafficTreatment.builder();
469 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
470
471 Set<ConnectPoint> ingressPoints = new HashSet<>();
472 ingressPoints.add(SW2_ETH1);
473 ingressPoints.add(SW3_ETH1);
474
475 MultiPointToSinglePointIntent addedIntent =
476 MultiPointToSinglePointIntent.builder()
477 .appId(APPID)
478 .key(Key.of(prefix.toString(), APPID))
479 .selector(selectorBuilder.build())
480 .treatment(treatmentBuilder.build())
481 .ingressPoints(ingressPoints)
482 .egressPoint(SW1_ETH1)
483 .constraints(SdnIpFib.CONSTRAINTS)
484 .build();
485
486 reset(intentSynchronizer);
487
488 intentSynchronizer.submit(eqExceptId(addedIntent));
489 expectLastCall().once();
490
491 replay(intentSynchronizer);
492
493 Interface intf = new Interface("newintf", SW4_ETH1,
494 Collections.singletonList(InterfaceIpAddress.valueOf("192.168.50.101/24")),
495 MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE);
496 InterfaceEvent intfEvent = new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, intf);
497 interfaceListener.event(intfEvent);
498
499 verify(intentSynchronizer);
500 }
501
Jonathan Hart365335e2015-12-10 11:09:53 -0800502 private class TestCoreService extends CoreServiceAdapter {
503 @Override
504 public ApplicationId getAppId(String name) {
505 return APPID;
506 }
507 }
508
509 private class TestRoutingService extends RoutingServiceAdapter {
510
511 @Override
512 public void addFibListener(FibListener fibListener) {
513 SdnIpFibTest.this.fibListener = fibListener;
514 }
515 }
Jonathan Hartb14221c2016-03-07 09:55:50 -0800516
517 private class InterfaceServiceDelegate extends InterfaceServiceAdapter {
518
519 @Override
520 public void addListener(InterfaceListener listener) {
521 SdnIpFibTest.this.interfaceListener = listener;
522 }
523 }
Jonathan Hart9a426f82015-09-03 15:43:13 +0200524}