blob: 12fc6cbf41be76944257ed5a2546408ef37e8139 [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;
Brian O'Connor520c0522014-11-23 23:50:47 -080034import org.junit.Ignore;
Pingping3855f312014-10-22 12:50:37 -070035import org.junit.Test;
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -070036import org.onlab.junit.TestUtils;
37import org.onlab.junit.TestUtils.TestUtilsException;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070038import org.onlab.onos.core.ApplicationId;
Pingping3855f312014-10-22 12:50:37 -070039import org.onlab.onos.net.ConnectPoint;
40import org.onlab.onos.net.DefaultHost;
41import org.onlab.onos.net.DeviceId;
42import org.onlab.onos.net.Host;
43import org.onlab.onos.net.HostId;
44import org.onlab.onos.net.HostLocation;
45import org.onlab.onos.net.PortNumber;
46import org.onlab.onos.net.flow.DefaultTrafficSelector;
47import org.onlab.onos.net.flow.DefaultTrafficTreatment;
48import org.onlab.onos.net.flow.TrafficSelector;
49import org.onlab.onos.net.flow.TrafficTreatment;
Jonathan Hart31582d12014-10-22 13:52:41 -070050import org.onlab.onos.net.host.HostListener;
Pingping3855f312014-10-22 12:50:37 -070051import org.onlab.onos.net.host.HostService;
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070052import org.onlab.onos.net.host.InterfaceIpAddress;
Pingping3855f312014-10-22 12:50:37 -070053import org.onlab.onos.net.intent.IntentService;
54import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
Brian O'Connor520c0522014-11-23 23:50:47 -080055import org.onlab.onos.net.intent.AbstractIntentTest;
Pingping3855f312014-10-22 12:50:37 -070056import org.onlab.onos.net.provider.ProviderId;
57import org.onlab.onos.sdnip.config.BgpPeer;
58import org.onlab.onos.sdnip.config.Interface;
59import org.onlab.onos.sdnip.config.SdnIpConfigService;
60import org.onlab.packet.Ethernet;
61import org.onlab.packet.IpAddress;
Pavlin Radoslavov6b570732014-11-06 13:16:45 -080062import org.onlab.packet.Ip4Address;
Pingping3855f312014-10-22 12:50:37 -070063import org.onlab.packet.IpPrefix;
Pavlin Radoslavov6b570732014-11-06 13:16:45 -080064import org.onlab.packet.Ip4Prefix;
Pingping3855f312014-10-22 12:50:37 -070065import org.onlab.packet.MacAddress;
66import org.onlab.packet.VlanId;
Pingping3855f312014-10-22 12:50:37 -070067
68import com.google.common.collect.Sets;
69
70/**
71 * This class tests adding a route, updating a route, deleting a route,
72 * and adding a route whose next hop is the local BGP speaker.
Pingpingfc584672014-10-23 10:51:19 -070073 * <p/>
74 * ARP module answers the MAC address synchronously.
Pingping3855f312014-10-22 12:50:37 -070075 */
Brian O'Connor520c0522014-11-23 23:50:47 -080076public class RouterTest extends AbstractIntentTest {
Pingping3855f312014-10-22 12:50:37 -070077
78 private SdnIpConfigService sdnIpConfigService;
79 private InterfaceService interfaceService;
80 private IntentService intentService;
81 private HostService hostService;
82
Jonathan Hart31582d12014-10-22 13:52:41 -070083 private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
84 DeviceId.deviceId("of:0000000000000001"),
85 PortNumber.portNumber(1));
86
87 private static final ConnectPoint SW2_ETH1 = new ConnectPoint(
88 DeviceId.deviceId("of:0000000000000002"),
89 PortNumber.portNumber(1));
90
91 private static final ConnectPoint SW3_ETH1 = new ConnectPoint(
92 DeviceId.deviceId("of:0000000000000003"),
93 PortNumber.portNumber(1));
Pingping3855f312014-10-22 12:50:37 -070094
95 private static final ApplicationId APPID = new ApplicationId() {
96 @Override
97 public short id() {
98 return 1;
99 }
100
101 @Override
102 public String name() {
103 return "SDNIP";
104 }
105 };
106
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800107 private IntentSynchronizer intentSynchronizer;
Pingping3855f312014-10-22 12:50:37 -0700108 private Router router;
109
110 @Before
111 public void setUp() throws Exception {
Brian O'Connor520c0522014-11-23 23:50:47 -0800112 super.setUp();
113
Jonathan Hart31582d12014-10-22 13:52:41 -0700114 setUpBgpPeers();
Pingping3855f312014-10-22 12:50:37 -0700115
Jonathan Hart31582d12014-10-22 13:52:41 -0700116 setUpInterfaceService();
117 setUpHostService();
Pingping3855f312014-10-22 12:50:37 -0700118
119 intentService = createMock(IntentService.class);
Pingping3855f312014-10-22 12:50:37 -0700120
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800121 intentSynchronizer = new IntentSynchronizer(APPID, intentService);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800122 router = new Router(APPID, intentSynchronizer, sdnIpConfigService,
123 interfaceService, hostService);
Pingping3855f312014-10-22 12:50:37 -0700124 }
125
126 /**
127 * Sets up BGP peers in external networks.
Pingping3855f312014-10-22 12:50:37 -0700128 */
Jonathan Hart31582d12014-10-22 13:52:41 -0700129 private void setUpBgpPeers() {
Pingping3855f312014-10-22 12:50:37 -0700130
Jonathan Hart31582d12014-10-22 13:52:41 -0700131 Map<IpAddress, BgpPeer> peers = new HashMap<>();
Pingping3855f312014-10-22 12:50:37 -0700132
133 String peerSw1Eth1 = "192.168.10.1";
Jonathan Hart31582d12014-10-22 13:52:41 -0700134 peers.put(IpAddress.valueOf(peerSw1Eth1),
Pingping3855f312014-10-22 12:50:37 -0700135 new BgpPeer("00:00:00:00:00:00:00:01", 1, peerSw1Eth1));
136
137 // Two BGP peers are connected to switch 2 port 1.
138 String peer1Sw2Eth1 = "192.168.20.1";
Jonathan Hart31582d12014-10-22 13:52:41 -0700139 peers.put(IpAddress.valueOf(peer1Sw2Eth1),
Pingping3855f312014-10-22 12:50:37 -0700140 new BgpPeer("00:00:00:00:00:00:00:02", 1, peer1Sw2Eth1));
141
142 String peer2Sw2Eth1 = "192.168.20.2";
Jonathan Hart31582d12014-10-22 13:52:41 -0700143 peers.put(IpAddress.valueOf(peer2Sw2Eth1),
Pingping3855f312014-10-22 12:50:37 -0700144 new BgpPeer("00:00:00:00:00:00:00:02", 1, peer2Sw2Eth1));
145
Jonathan Hart31582d12014-10-22 13:52:41 -0700146 sdnIpConfigService = createMock(SdnIpConfigService.class);
147 expect(sdnIpConfigService.getBgpPeers()).andReturn(peers).anyTimes();
148 replay(sdnIpConfigService);
149
Pingping3855f312014-10-22 12:50:37 -0700150 }
151
152 /**
153 * Sets up logical interfaces, which emulate the configured interfaces
154 * in SDN-IP application.
Pingping3855f312014-10-22 12:50:37 -0700155 */
Jonathan Hart31582d12014-10-22 13:52:41 -0700156 private void setUpInterfaceService() {
157 interfaceService = createMock(InterfaceService.class);
Pingping3855f312014-10-22 12:50:37 -0700158
Jonathan Hart31582d12014-10-22 13:52:41 -0700159 Set<Interface> interfaces = Sets.newHashSet();
Pingping3855f312014-10-22 12:50:37 -0700160
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700161 InterfaceIpAddress ia1 =
162 new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"),
163 IpPrefix.valueOf("192.168.10.0/24"));
Jonathan Hart31582d12014-10-22 13:52:41 -0700164 Interface sw1Eth1 = new Interface(SW1_ETH1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700165 Sets.newHashSet(ia1),
Jonathan Hart31582d12014-10-22 13:52:41 -0700166 MacAddress.valueOf("00:00:00:00:00:01"));
Pingping3855f312014-10-22 12:50:37 -0700167
Jonathan Hart31582d12014-10-22 13:52:41 -0700168 expect(interfaceService.getInterface(SW1_ETH1)).andReturn(sw1Eth1).anyTimes();
169 interfaces.add(sw1Eth1);
Pingping3855f312014-10-22 12:50:37 -0700170
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700171 InterfaceIpAddress ia2 =
172 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"),
173 IpPrefix.valueOf("192.168.20.0/24"));
Jonathan Hart31582d12014-10-22 13:52:41 -0700174 Interface sw2Eth1 = new Interface(SW2_ETH1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700175 Sets.newHashSet(ia2),
Jonathan Hart31582d12014-10-22 13:52:41 -0700176 MacAddress.valueOf("00:00:00:00:00:02"));
Pingping3855f312014-10-22 12:50:37 -0700177
Jonathan Hart31582d12014-10-22 13:52:41 -0700178 expect(interfaceService.getInterface(SW2_ETH1)).andReturn(sw2Eth1).anyTimes();
179 interfaces.add(sw2Eth1);
180
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700181 InterfaceIpAddress ia3 =
182 new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
183 IpPrefix.valueOf("192.168.30.0/24"));
Jonathan Hart31582d12014-10-22 13:52:41 -0700184 Interface sw3Eth1 = new Interface(SW3_ETH1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700185 Sets.newHashSet(ia3),
Jonathan Hart31582d12014-10-22 13:52:41 -0700186 MacAddress.valueOf("00:00:00:00:00:03"));
187
188 expect(interfaceService.getInterface(SW3_ETH1)).andReturn(sw3Eth1).anyTimes();
189 interfaces.add(sw3Eth1);
190
191 expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
192
193 replay(interfaceService);
194 }
195
196 /**
197 * Sets up the host service with details of some hosts.
198 */
199 private void setUpHostService() {
200 hostService = createMock(HostService.class);
201
202 hostService.addListener(anyObject(HostListener.class));
203 expectLastCall().anyTimes();
204
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700205 IpAddress host1Address = IpAddress.valueOf("192.168.10.1");
Jonathan Hart31582d12014-10-22 13:52:41 -0700206 Host host1 = new DefaultHost(ProviderId.NONE, HostId.NONE,
207 MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE,
208 new HostLocation(SW1_ETH1, 1),
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700209 Sets.newHashSet(host1Address));
Jonathan Hart31582d12014-10-22 13:52:41 -0700210
211 expect(hostService.getHostsByIp(host1Address))
212 .andReturn(Sets.newHashSet(host1)).anyTimes();
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700213 hostService.startMonitoringIp(host1Address);
Jonathan Hart31582d12014-10-22 13:52:41 -0700214 expectLastCall().anyTimes();
215
216
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700217 IpAddress host2Address = IpAddress.valueOf("192.168.20.1");
Jonathan Hart31582d12014-10-22 13:52:41 -0700218 Host host2 = new DefaultHost(ProviderId.NONE, HostId.NONE,
219 MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE,
220 new HostLocation(SW2_ETH1, 1),
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700221 Sets.newHashSet(host2Address));
Jonathan Hart31582d12014-10-22 13:52:41 -0700222
223 expect(hostService.getHostsByIp(host2Address))
224 .andReturn(Sets.newHashSet(host2)).anyTimes();
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700225 hostService.startMonitoringIp(host2Address);
Jonathan Hart31582d12014-10-22 13:52:41 -0700226 expectLastCall().anyTimes();
227
228
229 replay(hostService);
Pingping3855f312014-10-22 12:50:37 -0700230 }
231
232 /**
233 * This method tests adding a route entry.
234 */
Brian O'Connor520c0522014-11-23 23:50:47 -0800235 @Test @Ignore("needs fix from intents")
Pingping3855f312014-10-22 12:50:37 -0700236 public void testProcessRouteAdd() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700237 // Construct a route entry
238 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800239 Ip4Prefix.valueOf("1.1.1.0/24"),
240 Ip4Address.valueOf("192.168.10.1"));
Pingping3855f312014-10-22 12:50:37 -0700241
242 // Construct a MultiPointToSinglePointIntent intent
243 TrafficSelector.Builder selectorBuilder =
244 DefaultTrafficSelector.builder();
245 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
246 routeEntry.prefix());
247
248 TrafficTreatment.Builder treatmentBuilder =
249 DefaultTrafficTreatment.builder();
250 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
251
252 Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700253 ingressPoints.add(SW2_ETH1);
254 ingressPoints.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700255
256 MultiPointToSinglePointIntent intent =
257 new MultiPointToSinglePointIntent(APPID,
258 selectorBuilder.build(), treatmentBuilder.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700259 ingressPoints, SW1_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700260
261 // Set up test expectation
262 reset(intentService);
263 intentService.submit(intent);
264 replay(intentService);
265
266 // Call the processRouteAdd() method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800267 intentSynchronizer.leaderChanged(true);
268 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pingping3855f312014-10-22 12:50:37 -0700269 router.processRouteAdd(routeEntry);
270
271 // Verify
272 assertEquals(router.getRoutes().size(), 1);
273 assertTrue(router.getRoutes().contains(routeEntry));
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800274 assertEquals(intentSynchronizer.getRouteIntents().size(), 1);
275 assertEquals(intentSynchronizer.getRouteIntents().iterator().next(),
Pingping3855f312014-10-22 12:50:37 -0700276 intent);
277 verify(intentService);
278 }
279
280 /**
281 * This method tests updating a route entry.
282 *
283 * @throws TestUtilsException
284 */
Brian O'Connor520c0522014-11-23 23:50:47 -0800285 @Test @Ignore("needs fix from intents")
Pingping3855f312014-10-22 12:50:37 -0700286 public void testRouteUpdate() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700287 // Firstly add a route
288 testProcessRouteAdd();
289
290 // Construct the existing route entry
291 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800292 Ip4Prefix.valueOf("1.1.1.0/24"),
293 Ip4Address.valueOf("192.168.10.1"));
Pingping3855f312014-10-22 12:50:37 -0700294
295 // Construct the existing MultiPointToSinglePointIntent intent
296 TrafficSelector.Builder selectorBuilder =
297 DefaultTrafficSelector.builder();
298 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
299 routeEntry.prefix());
300
301 TrafficTreatment.Builder treatmentBuilder =
302 DefaultTrafficTreatment.builder();
303 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
304
Pingping3855f312014-10-22 12:50:37 -0700305 Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700306 ingressPoints.add(SW2_ETH1);
307 ingressPoints.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700308
309 MultiPointToSinglePointIntent intent =
310 new MultiPointToSinglePointIntent(APPID,
311 selectorBuilder.build(), treatmentBuilder.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700312 ingressPoints, SW1_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700313
314 // Start to construct a new route entry and new intent
315 RouteEntry routeEntryUpdate = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800316 Ip4Prefix.valueOf("1.1.1.0/24"),
317 Ip4Address.valueOf("192.168.20.1"));
Pingping3855f312014-10-22 12:50:37 -0700318
319 // Construct a new MultiPointToSinglePointIntent intent
320 TrafficSelector.Builder selectorBuilderNew =
321 DefaultTrafficSelector.builder();
322 selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
323 routeEntryUpdate.prefix());
324
325 TrafficTreatment.Builder treatmentBuilderNew =
326 DefaultTrafficTreatment.builder();
327 treatmentBuilderNew.setEthDst(MacAddress.valueOf("00:00:00:00:00:02"));
328
Pingping3855f312014-10-22 12:50:37 -0700329
330 Set<ConnectPoint> ingressPointsNew = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700331 ingressPointsNew.add(SW1_ETH1);
332 ingressPointsNew.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700333
334 MultiPointToSinglePointIntent intentNew =
335 new MultiPointToSinglePointIntent(APPID,
336 selectorBuilderNew.build(),
337 treatmentBuilderNew.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700338 ingressPointsNew, SW2_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700339
340 // Set up test expectation
341 reset(intentService);
342 intentService.withdraw(intent);
343 intentService.submit(intentNew);
344 replay(intentService);
345
346 // Call the processRouteAdd() method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800347 intentSynchronizer.leaderChanged(true);
348 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pingping3855f312014-10-22 12:50:37 -0700349 router.processRouteAdd(routeEntryUpdate);
350
351 // Verify
352 assertEquals(router.getRoutes().size(), 1);
353 assertTrue(router.getRoutes().contains(routeEntryUpdate));
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800354 assertEquals(intentSynchronizer.getRouteIntents().size(), 1);
355 assertEquals(intentSynchronizer.getRouteIntents().iterator().next(),
Pingping3855f312014-10-22 12:50:37 -0700356 intentNew);
357 verify(intentService);
358 }
359
360 /**
361 * This method tests deleting a route entry.
362 */
Brian O'Connor520c0522014-11-23 23:50:47 -0800363 @Test @Ignore("needs fix from intents")
Pingping3855f312014-10-22 12:50:37 -0700364 public void testProcessRouteDelete() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700365 // Firstly add a route
366 testProcessRouteAdd();
367
368 // Construct the existing route entry
369 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800370 Ip4Prefix.valueOf("1.1.1.0/24"),
371 Ip4Address.valueOf("192.168.10.1"));
Pingping3855f312014-10-22 12:50:37 -0700372
373 // Construct the existing MultiPointToSinglePointIntent intent
374 TrafficSelector.Builder selectorBuilder =
375 DefaultTrafficSelector.builder();
376 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
377 routeEntry.prefix());
378
379 TrafficTreatment.Builder treatmentBuilder =
380 DefaultTrafficTreatment.builder();
381 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
382
Pingping3855f312014-10-22 12:50:37 -0700383 Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700384 ingressPoints.add(SW2_ETH1);
385 ingressPoints.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700386
387 MultiPointToSinglePointIntent intent =
388 new MultiPointToSinglePointIntent(APPID,
389 selectorBuilder.build(), treatmentBuilder.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700390 ingressPoints, SW1_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700391
392 // Set up expectation
393 reset(intentService);
394 intentService.withdraw(intent);
395 replay(intentService);
396
397 // Call route deleting method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800398 intentSynchronizer.leaderChanged(true);
399 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pingping3855f312014-10-22 12:50:37 -0700400 router.processRouteDelete(routeEntry);
401
402 // Verify
403 assertEquals(router.getRoutes().size(), 0);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800404 assertEquals(intentSynchronizer.getRouteIntents().size(), 0);
Pingping3855f312014-10-22 12:50:37 -0700405 verify(intentService);
406 }
407
408 /**
409 * This method tests when the next hop of a route is the local BGP speaker.
410 *
411 * @throws TestUtilsException
412 */
413 @Test
414 public void testLocalRouteAdd() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700415 // Construct a route entry, the next hop is the local BGP speaker
416 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800417 Ip4Prefix.valueOf("1.1.1.0/24"),
418 Ip4Address.valueOf("0.0.0.0"));
Pingping3855f312014-10-22 12:50:37 -0700419
420 // Reset intentService to check whether the submit method is called
421 reset(intentService);
422 replay(intentService);
423
424 // Call the processRouteAdd() method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800425 intentSynchronizer.leaderChanged(true);
426 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pingping3855f312014-10-22 12:50:37 -0700427 router.processRouteAdd(routeEntry);
428
429 // Verify
430 assertEquals(router.getRoutes().size(), 1);
431 assertTrue(router.getRoutes().contains(routeEntry));
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800432 assertEquals(intentSynchronizer.getRouteIntents().size(), 0);
Pingping3855f312014-10-22 12:50:37 -0700433 verify(intentService);
434 }
435}