blob: b5beb4ac4526bea1fd57d6d351235e10869283ce [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
Pingping3855f312014-10-22 12:50:37 -070016package org.onlab.onos.sdnip;
17
Jonathan Hart31582d12014-10-22 13:52:41 -070018import static org.easymock.EasyMock.anyObject;
Pingping3855f312014-10-22 12:50:37 -070019import static org.easymock.EasyMock.createMock;
20import static org.easymock.EasyMock.expect;
Jonathan Hart31582d12014-10-22 13:52:41 -070021import static org.easymock.EasyMock.expectLastCall;
Pingping3855f312014-10-22 12:50:37 -070022import static org.easymock.EasyMock.replay;
23import static org.easymock.EasyMock.reset;
24import static org.easymock.EasyMock.verify;
25import static org.junit.Assert.assertEquals;
26import static org.junit.Assert.assertTrue;
27
28import java.util.HashMap;
29import java.util.HashSet;
30import java.util.Map;
31import java.util.Set;
32
33import org.junit.Before;
34import org.junit.Test;
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -070035import org.onlab.junit.TestUtils;
36import org.onlab.junit.TestUtils.TestUtilsException;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070037import org.onlab.onos.core.ApplicationId;
Pingping3855f312014-10-22 12:50:37 -070038import org.onlab.onos.net.ConnectPoint;
39import org.onlab.onos.net.DefaultHost;
40import org.onlab.onos.net.DeviceId;
41import org.onlab.onos.net.Host;
42import org.onlab.onos.net.HostId;
43import org.onlab.onos.net.HostLocation;
44import org.onlab.onos.net.PortNumber;
45import org.onlab.onos.net.flow.DefaultTrafficSelector;
46import org.onlab.onos.net.flow.DefaultTrafficTreatment;
47import org.onlab.onos.net.flow.TrafficSelector;
48import org.onlab.onos.net.flow.TrafficTreatment;
Jonathan Hart31582d12014-10-22 13:52:41 -070049import org.onlab.onos.net.host.HostListener;
Pingping3855f312014-10-22 12:50:37 -070050import org.onlab.onos.net.host.HostService;
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070051import org.onlab.onos.net.host.InterfaceIpAddress;
Pingping3855f312014-10-22 12:50:37 -070052import org.onlab.onos.net.intent.IntentService;
53import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
54import org.onlab.onos.net.provider.ProviderId;
55import org.onlab.onos.sdnip.config.BgpPeer;
56import org.onlab.onos.sdnip.config.Interface;
57import org.onlab.onos.sdnip.config.SdnIpConfigService;
58import org.onlab.packet.Ethernet;
59import org.onlab.packet.IpAddress;
Pavlin Radoslavov6b570732014-11-06 13:16:45 -080060import org.onlab.packet.Ip4Address;
Pingping3855f312014-10-22 12:50:37 -070061import org.onlab.packet.IpPrefix;
Pavlin Radoslavov6b570732014-11-06 13:16:45 -080062import org.onlab.packet.Ip4Prefix;
Pingping3855f312014-10-22 12:50:37 -070063import org.onlab.packet.MacAddress;
64import org.onlab.packet.VlanId;
Pingping3855f312014-10-22 12:50:37 -070065
66import com.google.common.collect.Sets;
67
68/**
69 * This class tests adding a route, updating a route, deleting a route,
70 * and adding a route whose next hop is the local BGP speaker.
Pingpingfc584672014-10-23 10:51:19 -070071 * <p/>
72 * ARP module answers the MAC address synchronously.
Pingping3855f312014-10-22 12:50:37 -070073 */
74public class RouterTest {
75
76 private SdnIpConfigService sdnIpConfigService;
77 private InterfaceService interfaceService;
78 private IntentService intentService;
79 private HostService hostService;
80
Jonathan Hart31582d12014-10-22 13:52:41 -070081 private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
82 DeviceId.deviceId("of:0000000000000001"),
83 PortNumber.portNumber(1));
84
85 private static final ConnectPoint SW2_ETH1 = new ConnectPoint(
86 DeviceId.deviceId("of:0000000000000002"),
87 PortNumber.portNumber(1));
88
89 private static final ConnectPoint SW3_ETH1 = new ConnectPoint(
90 DeviceId.deviceId("of:0000000000000003"),
91 PortNumber.portNumber(1));
Pingping3855f312014-10-22 12:50:37 -070092
93 private static final ApplicationId APPID = new ApplicationId() {
94 @Override
95 public short id() {
96 return 1;
97 }
98
99 @Override
100 public String name() {
101 return "SDNIP";
102 }
103 };
104
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800105 private IntentSynchronizer intentSynchronizer;
Pingping3855f312014-10-22 12:50:37 -0700106 private Router router;
107
108 @Before
109 public void setUp() throws Exception {
Jonathan Hart31582d12014-10-22 13:52:41 -0700110 setUpBgpPeers();
Pingping3855f312014-10-22 12:50:37 -0700111
Jonathan Hart31582d12014-10-22 13:52:41 -0700112 setUpInterfaceService();
113 setUpHostService();
Pingping3855f312014-10-22 12:50:37 -0700114
115 intentService = createMock(IntentService.class);
Pingping3855f312014-10-22 12:50:37 -0700116
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800117 intentSynchronizer = new IntentSynchronizer(APPID, intentService);
118 router = new Router(APPID, intentSynchronizer,
Pingping3855f312014-10-22 12:50:37 -0700119 hostService, sdnIpConfigService, interfaceService);
120 }
121
122 /**
123 * Sets up BGP peers in external networks.
Pingping3855f312014-10-22 12:50:37 -0700124 */
Jonathan Hart31582d12014-10-22 13:52:41 -0700125 private void setUpBgpPeers() {
Pingping3855f312014-10-22 12:50:37 -0700126
Jonathan Hart31582d12014-10-22 13:52:41 -0700127 Map<IpAddress, BgpPeer> peers = new HashMap<>();
Pingping3855f312014-10-22 12:50:37 -0700128
129 String peerSw1Eth1 = "192.168.10.1";
Jonathan Hart31582d12014-10-22 13:52:41 -0700130 peers.put(IpAddress.valueOf(peerSw1Eth1),
Pingping3855f312014-10-22 12:50:37 -0700131 new BgpPeer("00:00:00:00:00:00:00:01", 1, peerSw1Eth1));
132
133 // Two BGP peers are connected to switch 2 port 1.
134 String peer1Sw2Eth1 = "192.168.20.1";
Jonathan Hart31582d12014-10-22 13:52:41 -0700135 peers.put(IpAddress.valueOf(peer1Sw2Eth1),
Pingping3855f312014-10-22 12:50:37 -0700136 new BgpPeer("00:00:00:00:00:00:00:02", 1, peer1Sw2Eth1));
137
138 String peer2Sw2Eth1 = "192.168.20.2";
Jonathan Hart31582d12014-10-22 13:52:41 -0700139 peers.put(IpAddress.valueOf(peer2Sw2Eth1),
Pingping3855f312014-10-22 12:50:37 -0700140 new BgpPeer("00:00:00:00:00:00:00:02", 1, peer2Sw2Eth1));
141
Jonathan Hart31582d12014-10-22 13:52:41 -0700142 sdnIpConfigService = createMock(SdnIpConfigService.class);
143 expect(sdnIpConfigService.getBgpPeers()).andReturn(peers).anyTimes();
144 replay(sdnIpConfigService);
145
Pingping3855f312014-10-22 12:50:37 -0700146 }
147
148 /**
149 * Sets up logical interfaces, which emulate the configured interfaces
150 * in SDN-IP application.
Pingping3855f312014-10-22 12:50:37 -0700151 */
Jonathan Hart31582d12014-10-22 13:52:41 -0700152 private void setUpInterfaceService() {
153 interfaceService = createMock(InterfaceService.class);
Pingping3855f312014-10-22 12:50:37 -0700154
Jonathan Hart31582d12014-10-22 13:52:41 -0700155 Set<Interface> interfaces = Sets.newHashSet();
Pingping3855f312014-10-22 12:50:37 -0700156
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700157 InterfaceIpAddress ia1 =
158 new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"),
159 IpPrefix.valueOf("192.168.10.0/24"));
Jonathan Hart31582d12014-10-22 13:52:41 -0700160 Interface sw1Eth1 = new Interface(SW1_ETH1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700161 Sets.newHashSet(ia1),
Jonathan Hart31582d12014-10-22 13:52:41 -0700162 MacAddress.valueOf("00:00:00:00:00:01"));
Pingping3855f312014-10-22 12:50:37 -0700163
Jonathan Hart31582d12014-10-22 13:52:41 -0700164 expect(interfaceService.getInterface(SW1_ETH1)).andReturn(sw1Eth1).anyTimes();
165 interfaces.add(sw1Eth1);
Pingping3855f312014-10-22 12:50:37 -0700166
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700167 InterfaceIpAddress ia2 =
168 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"),
169 IpPrefix.valueOf("192.168.20.0/24"));
Jonathan Hart31582d12014-10-22 13:52:41 -0700170 Interface sw2Eth1 = new Interface(SW2_ETH1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700171 Sets.newHashSet(ia2),
Jonathan Hart31582d12014-10-22 13:52:41 -0700172 MacAddress.valueOf("00:00:00:00:00:02"));
Pingping3855f312014-10-22 12:50:37 -0700173
Jonathan Hart31582d12014-10-22 13:52:41 -0700174 expect(interfaceService.getInterface(SW2_ETH1)).andReturn(sw2Eth1).anyTimes();
175 interfaces.add(sw2Eth1);
176
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700177 InterfaceIpAddress ia3 =
178 new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
179 IpPrefix.valueOf("192.168.30.0/24"));
Jonathan Hart31582d12014-10-22 13:52:41 -0700180 Interface sw3Eth1 = new Interface(SW3_ETH1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700181 Sets.newHashSet(ia3),
Jonathan Hart31582d12014-10-22 13:52:41 -0700182 MacAddress.valueOf("00:00:00:00:00:03"));
183
184 expect(interfaceService.getInterface(SW3_ETH1)).andReturn(sw3Eth1).anyTimes();
185 interfaces.add(sw3Eth1);
186
187 expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
188
189 replay(interfaceService);
190 }
191
192 /**
193 * Sets up the host service with details of some hosts.
194 */
195 private void setUpHostService() {
196 hostService = createMock(HostService.class);
197
198 hostService.addListener(anyObject(HostListener.class));
199 expectLastCall().anyTimes();
200
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700201 IpAddress host1Address = IpAddress.valueOf("192.168.10.1");
Jonathan Hart31582d12014-10-22 13:52:41 -0700202 Host host1 = new DefaultHost(ProviderId.NONE, HostId.NONE,
203 MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE,
204 new HostLocation(SW1_ETH1, 1),
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700205 Sets.newHashSet(host1Address));
Jonathan Hart31582d12014-10-22 13:52:41 -0700206
207 expect(hostService.getHostsByIp(host1Address))
208 .andReturn(Sets.newHashSet(host1)).anyTimes();
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700209 hostService.startMonitoringIp(host1Address);
Jonathan Hart31582d12014-10-22 13:52:41 -0700210 expectLastCall().anyTimes();
211
212
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700213 IpAddress host2Address = IpAddress.valueOf("192.168.20.1");
Jonathan Hart31582d12014-10-22 13:52:41 -0700214 Host host2 = new DefaultHost(ProviderId.NONE, HostId.NONE,
215 MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE,
216 new HostLocation(SW2_ETH1, 1),
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700217 Sets.newHashSet(host2Address));
Jonathan Hart31582d12014-10-22 13:52:41 -0700218
219 expect(hostService.getHostsByIp(host2Address))
220 .andReturn(Sets.newHashSet(host2)).anyTimes();
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700221 hostService.startMonitoringIp(host2Address);
Jonathan Hart31582d12014-10-22 13:52:41 -0700222 expectLastCall().anyTimes();
223
224
225 replay(hostService);
Pingping3855f312014-10-22 12:50:37 -0700226 }
227
228 /**
229 * This method tests adding a route entry.
230 */
231 @Test
232 public void testProcessRouteAdd() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700233 // Construct a route entry
234 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800235 Ip4Prefix.valueOf("1.1.1.0/24"),
236 Ip4Address.valueOf("192.168.10.1"));
Pingping3855f312014-10-22 12:50:37 -0700237
238 // Construct a MultiPointToSinglePointIntent intent
239 TrafficSelector.Builder selectorBuilder =
240 DefaultTrafficSelector.builder();
241 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
242 routeEntry.prefix());
243
244 TrafficTreatment.Builder treatmentBuilder =
245 DefaultTrafficTreatment.builder();
246 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
247
248 Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700249 ingressPoints.add(SW2_ETH1);
250 ingressPoints.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700251
252 MultiPointToSinglePointIntent intent =
253 new MultiPointToSinglePointIntent(APPID,
254 selectorBuilder.build(), treatmentBuilder.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700255 ingressPoints, SW1_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700256
257 // Set up test expectation
258 reset(intentService);
259 intentService.submit(intent);
260 replay(intentService);
261
262 // Call the processRouteAdd() method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800263 intentSynchronizer.leaderChanged(true);
264 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pingping3855f312014-10-22 12:50:37 -0700265 router.processRouteAdd(routeEntry);
266
267 // Verify
268 assertEquals(router.getRoutes().size(), 1);
269 assertTrue(router.getRoutes().contains(routeEntry));
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800270 assertEquals(intentSynchronizer.getPushedRouteIntents().size(), 1);
271 assertEquals(intentSynchronizer.getPushedRouteIntents().iterator().next(),
Pingping3855f312014-10-22 12:50:37 -0700272 intent);
273 verify(intentService);
274 }
275
276 /**
277 * This method tests updating a route entry.
278 *
279 * @throws TestUtilsException
280 */
281 @Test
282 public void testRouteUpdate() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700283 // Firstly add a route
284 testProcessRouteAdd();
285
286 // Construct the existing route entry
287 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800288 Ip4Prefix.valueOf("1.1.1.0/24"),
289 Ip4Address.valueOf("192.168.10.1"));
Pingping3855f312014-10-22 12:50:37 -0700290
291 // Construct the existing MultiPointToSinglePointIntent intent
292 TrafficSelector.Builder selectorBuilder =
293 DefaultTrafficSelector.builder();
294 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
295 routeEntry.prefix());
296
297 TrafficTreatment.Builder treatmentBuilder =
298 DefaultTrafficTreatment.builder();
299 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
300
Pingping3855f312014-10-22 12:50:37 -0700301 Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700302 ingressPoints.add(SW2_ETH1);
303 ingressPoints.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700304
305 MultiPointToSinglePointIntent intent =
306 new MultiPointToSinglePointIntent(APPID,
307 selectorBuilder.build(), treatmentBuilder.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700308 ingressPoints, SW1_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700309
310 // Start to construct a new route entry and new intent
311 RouteEntry routeEntryUpdate = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800312 Ip4Prefix.valueOf("1.1.1.0/24"),
313 Ip4Address.valueOf("192.168.20.1"));
Pingping3855f312014-10-22 12:50:37 -0700314
315 // Construct a new MultiPointToSinglePointIntent intent
316 TrafficSelector.Builder selectorBuilderNew =
317 DefaultTrafficSelector.builder();
318 selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
319 routeEntryUpdate.prefix());
320
321 TrafficTreatment.Builder treatmentBuilderNew =
322 DefaultTrafficTreatment.builder();
323 treatmentBuilderNew.setEthDst(MacAddress.valueOf("00:00:00:00:00:02"));
324
Pingping3855f312014-10-22 12:50:37 -0700325
326 Set<ConnectPoint> ingressPointsNew = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700327 ingressPointsNew.add(SW1_ETH1);
328 ingressPointsNew.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700329
330 MultiPointToSinglePointIntent intentNew =
331 new MultiPointToSinglePointIntent(APPID,
332 selectorBuilderNew.build(),
333 treatmentBuilderNew.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700334 ingressPointsNew, SW2_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700335
336 // Set up test expectation
337 reset(intentService);
338 intentService.withdraw(intent);
339 intentService.submit(intentNew);
340 replay(intentService);
341
342 // Call the processRouteAdd() method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800343 intentSynchronizer.leaderChanged(true);
344 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pingping3855f312014-10-22 12:50:37 -0700345 router.processRouteAdd(routeEntryUpdate);
346
347 // Verify
348 assertEquals(router.getRoutes().size(), 1);
349 assertTrue(router.getRoutes().contains(routeEntryUpdate));
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800350 assertEquals(intentSynchronizer.getPushedRouteIntents().size(), 1);
351 assertEquals(intentSynchronizer.getPushedRouteIntents().iterator().next(),
Pingping3855f312014-10-22 12:50:37 -0700352 intentNew);
353 verify(intentService);
354 }
355
356 /**
357 * This method tests deleting a route entry.
358 */
359 @Test
360 public void testProcessRouteDelete() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700361 // Firstly add a route
362 testProcessRouteAdd();
363
364 // Construct the existing route entry
365 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800366 Ip4Prefix.valueOf("1.1.1.0/24"),
367 Ip4Address.valueOf("192.168.10.1"));
Pingping3855f312014-10-22 12:50:37 -0700368
369 // Construct the existing MultiPointToSinglePointIntent intent
370 TrafficSelector.Builder selectorBuilder =
371 DefaultTrafficSelector.builder();
372 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
373 routeEntry.prefix());
374
375 TrafficTreatment.Builder treatmentBuilder =
376 DefaultTrafficTreatment.builder();
377 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
378
Pingping3855f312014-10-22 12:50:37 -0700379 Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700380 ingressPoints.add(SW2_ETH1);
381 ingressPoints.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700382
383 MultiPointToSinglePointIntent intent =
384 new MultiPointToSinglePointIntent(APPID,
385 selectorBuilder.build(), treatmentBuilder.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700386 ingressPoints, SW1_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700387
388 // Set up expectation
389 reset(intentService);
390 intentService.withdraw(intent);
391 replay(intentService);
392
393 // Call route deleting method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800394 intentSynchronizer.leaderChanged(true);
395 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pingping3855f312014-10-22 12:50:37 -0700396 router.processRouteDelete(routeEntry);
397
398 // Verify
399 assertEquals(router.getRoutes().size(), 0);
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800400 assertEquals(intentSynchronizer.getPushedRouteIntents().size(), 0);
Pingping3855f312014-10-22 12:50:37 -0700401 verify(intentService);
402 }
403
404 /**
405 * This method tests when the next hop of a route is the local BGP speaker.
406 *
407 * @throws TestUtilsException
408 */
409 @Test
410 public void testLocalRouteAdd() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700411 // Construct a route entry, the next hop is the local BGP speaker
412 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800413 Ip4Prefix.valueOf("1.1.1.0/24"),
414 Ip4Address.valueOf("0.0.0.0"));
Pingping3855f312014-10-22 12:50:37 -0700415
416 // Reset intentService to check whether the submit method is called
417 reset(intentService);
418 replay(intentService);
419
420 // Call the processRouteAdd() method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800421 intentSynchronizer.leaderChanged(true);
422 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pingping3855f312014-10-22 12:50:37 -0700423 router.processRouteAdd(routeEntry);
424
425 // Verify
426 assertEquals(router.getRoutes().size(), 1);
427 assertTrue(router.getRoutes().contains(routeEntry));
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800428 assertEquals(intentSynchronizer.getPushedRouteIntents().size(), 0);
Pingping3855f312014-10-22 12:50:37 -0700429 verify(intentService);
430 }
431}