blob: 6ef4a2002633e7ace2704b26281405b78cb5be67 [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.sdnip;
Pingping3855f312014-10-22 12:50:37 -070017
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
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -080028import java.util.Collections;
Pingping3855f312014-10-22 12:50:37 -070029import java.util.HashMap;
30import java.util.HashSet;
31import java.util.Map;
32import java.util.Set;
33
34import org.junit.Before;
35import org.junit.Test;
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -070036import org.onlab.junit.TestUtils;
37import org.onlab.junit.TestUtils.TestUtilsException;
Jonathan Hart51372182014-12-03 21:32:34 -080038import org.onlab.packet.Ethernet;
39import org.onlab.packet.Ip4Address;
40import org.onlab.packet.Ip4Prefix;
41import org.onlab.packet.IpAddress;
42import org.onlab.packet.IpPrefix;
43import org.onlab.packet.MacAddress;
44import org.onlab.packet.VlanId;
Brian O'Connorabafb502014-12-02 22:26:20 -080045import org.onosproject.core.ApplicationId;
46import org.onosproject.net.ConnectPoint;
47import org.onosproject.net.DefaultHost;
48import org.onosproject.net.DeviceId;
49import org.onosproject.net.Host;
50import org.onosproject.net.HostId;
51import org.onosproject.net.HostLocation;
52import org.onosproject.net.PortNumber;
53import org.onosproject.net.flow.DefaultTrafficSelector;
54import org.onosproject.net.flow.DefaultTrafficTreatment;
55import org.onosproject.net.flow.TrafficSelector;
56import org.onosproject.net.flow.TrafficTreatment;
57import org.onosproject.net.host.HostListener;
58import org.onosproject.net.host.HostService;
59import org.onosproject.net.host.InterfaceIpAddress;
Jonathan Hart51372182014-12-03 21:32:34 -080060import org.onosproject.net.intent.AbstractIntentTest;
Brian O'Connorabafb502014-12-02 22:26:20 -080061import org.onosproject.net.intent.Intent;
62import org.onosproject.net.intent.IntentOperations;
63import org.onosproject.net.intent.IntentService;
64import org.onosproject.net.intent.MultiPointToSinglePointIntent;
Brian O'Connorabafb502014-12-02 22:26:20 -080065import org.onosproject.net.provider.ProviderId;
66import org.onosproject.sdnip.IntentSynchronizer.IntentKey;
67import org.onosproject.sdnip.config.BgpPeer;
68import org.onosproject.sdnip.config.Interface;
69import org.onosproject.sdnip.config.SdnIpConfigurationService;
Pingping3855f312014-10-22 12:50:37 -070070
71import com.google.common.collect.Sets;
72
73/**
74 * This class tests adding a route, updating a route, deleting a route,
75 * and adding a route whose next hop is the local BGP speaker.
Pingpingfc584672014-10-23 10:51:19 -070076 * <p/>
77 * ARP module answers the MAC address synchronously.
Pingping3855f312014-10-22 12:50:37 -070078 */
Brian O'Connor520c0522014-11-23 23:50:47 -080079public class RouterTest extends AbstractIntentTest {
Pingping3855f312014-10-22 12:50:37 -070080
Jonathan Hart9965d772014-12-02 10:28:34 -080081 private SdnIpConfigurationService sdnIpConfigService;
Pingping3855f312014-10-22 12:50:37 -070082 private InterfaceService interfaceService;
83 private IntentService intentService;
84 private HostService hostService;
85
Jonathan Hart31582d12014-10-22 13:52:41 -070086 private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
87 DeviceId.deviceId("of:0000000000000001"),
88 PortNumber.portNumber(1));
89
90 private static final ConnectPoint SW2_ETH1 = new ConnectPoint(
91 DeviceId.deviceId("of:0000000000000002"),
92 PortNumber.portNumber(1));
93
94 private static final ConnectPoint SW3_ETH1 = new ConnectPoint(
95 DeviceId.deviceId("of:0000000000000003"),
96 PortNumber.portNumber(1));
Pingping3855f312014-10-22 12:50:37 -070097
98 private static final ApplicationId APPID = new ApplicationId() {
99 @Override
100 public short id() {
101 return 1;
102 }
103
104 @Override
105 public String name() {
106 return "SDNIP";
107 }
108 };
109
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800110 private IntentSynchronizer intentSynchronizer;
Pingping3855f312014-10-22 12:50:37 -0700111 private Router router;
112
113 @Before
114 public void setUp() throws Exception {
Brian O'Connor520c0522014-11-23 23:50:47 -0800115 super.setUp();
116
Jonathan Hart31582d12014-10-22 13:52:41 -0700117 setUpBgpPeers();
Pingping3855f312014-10-22 12:50:37 -0700118
Jonathan Hart31582d12014-10-22 13:52:41 -0700119 setUpInterfaceService();
120 setUpHostService();
Pingping3855f312014-10-22 12:50:37 -0700121
122 intentService = createMock(IntentService.class);
Pingping3855f312014-10-22 12:50:37 -0700123
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800124 intentSynchronizer = new IntentSynchronizer(APPID, intentService);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800125 router = new Router(APPID, intentSynchronizer, sdnIpConfigService,
126 interfaceService, hostService);
Pingping3855f312014-10-22 12:50:37 -0700127 }
128
129 /**
130 * Sets up BGP peers in external networks.
Pingping3855f312014-10-22 12:50:37 -0700131 */
Jonathan Hart31582d12014-10-22 13:52:41 -0700132 private void setUpBgpPeers() {
Pingping3855f312014-10-22 12:50:37 -0700133
Jonathan Hart31582d12014-10-22 13:52:41 -0700134 Map<IpAddress, BgpPeer> peers = new HashMap<>();
Pingping3855f312014-10-22 12:50:37 -0700135
136 String peerSw1Eth1 = "192.168.10.1";
Jonathan Hart31582d12014-10-22 13:52:41 -0700137 peers.put(IpAddress.valueOf(peerSw1Eth1),
Pingping3855f312014-10-22 12:50:37 -0700138 new BgpPeer("00:00:00:00:00:00:00:01", 1, peerSw1Eth1));
139
140 // Two BGP peers are connected to switch 2 port 1.
141 String peer1Sw2Eth1 = "192.168.20.1";
Jonathan Hart31582d12014-10-22 13:52:41 -0700142 peers.put(IpAddress.valueOf(peer1Sw2Eth1),
Pingping3855f312014-10-22 12:50:37 -0700143 new BgpPeer("00:00:00:00:00:00:00:02", 1, peer1Sw2Eth1));
144
145 String peer2Sw2Eth1 = "192.168.20.2";
Jonathan Hart31582d12014-10-22 13:52:41 -0700146 peers.put(IpAddress.valueOf(peer2Sw2Eth1),
Pingping3855f312014-10-22 12:50:37 -0700147 new BgpPeer("00:00:00:00:00:00:00:02", 1, peer2Sw2Eth1));
148
Jonathan Hart9965d772014-12-02 10:28:34 -0800149 sdnIpConfigService = createMock(SdnIpConfigurationService.class);
Jonathan Hart31582d12014-10-22 13:52:41 -0700150 expect(sdnIpConfigService.getBgpPeers()).andReturn(peers).anyTimes();
151 replay(sdnIpConfigService);
152
Pingping3855f312014-10-22 12:50:37 -0700153 }
154
155 /**
156 * Sets up logical interfaces, which emulate the configured interfaces
157 * in SDN-IP application.
Pingping3855f312014-10-22 12:50:37 -0700158 */
Jonathan Hart31582d12014-10-22 13:52:41 -0700159 private void setUpInterfaceService() {
160 interfaceService = createMock(InterfaceService.class);
Pingping3855f312014-10-22 12:50:37 -0700161
Jonathan Hart31582d12014-10-22 13:52:41 -0700162 Set<Interface> interfaces = Sets.newHashSet();
Pingping3855f312014-10-22 12:50:37 -0700163
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700164 InterfaceIpAddress ia1 =
165 new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"),
166 IpPrefix.valueOf("192.168.10.0/24"));
Jonathan Hart31582d12014-10-22 13:52:41 -0700167 Interface sw1Eth1 = new Interface(SW1_ETH1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700168 Sets.newHashSet(ia1),
Jonathan Hart31582d12014-10-22 13:52:41 -0700169 MacAddress.valueOf("00:00:00:00:00:01"));
Pingping3855f312014-10-22 12:50:37 -0700170
Jonathan Hart31582d12014-10-22 13:52:41 -0700171 expect(interfaceService.getInterface(SW1_ETH1)).andReturn(sw1Eth1).anyTimes();
172 interfaces.add(sw1Eth1);
Pingping3855f312014-10-22 12:50:37 -0700173
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700174 InterfaceIpAddress ia2 =
175 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"),
176 IpPrefix.valueOf("192.168.20.0/24"));
Jonathan Hart31582d12014-10-22 13:52:41 -0700177 Interface sw2Eth1 = new Interface(SW2_ETH1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700178 Sets.newHashSet(ia2),
Jonathan Hart31582d12014-10-22 13:52:41 -0700179 MacAddress.valueOf("00:00:00:00:00:02"));
Pingping3855f312014-10-22 12:50:37 -0700180
Jonathan Hart31582d12014-10-22 13:52:41 -0700181 expect(interfaceService.getInterface(SW2_ETH1)).andReturn(sw2Eth1).anyTimes();
182 interfaces.add(sw2Eth1);
183
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700184 InterfaceIpAddress ia3 =
185 new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
186 IpPrefix.valueOf("192.168.30.0/24"));
Jonathan Hart31582d12014-10-22 13:52:41 -0700187 Interface sw3Eth1 = new Interface(SW3_ETH1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700188 Sets.newHashSet(ia3),
Jonathan Hart31582d12014-10-22 13:52:41 -0700189 MacAddress.valueOf("00:00:00:00:00:03"));
190
191 expect(interfaceService.getInterface(SW3_ETH1)).andReturn(sw3Eth1).anyTimes();
192 interfaces.add(sw3Eth1);
193
194 expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
195
196 replay(interfaceService);
197 }
198
199 /**
200 * Sets up the host service with details of some hosts.
201 */
202 private void setUpHostService() {
203 hostService = createMock(HostService.class);
204
205 hostService.addListener(anyObject(HostListener.class));
206 expectLastCall().anyTimes();
207
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700208 IpAddress host1Address = IpAddress.valueOf("192.168.10.1");
Jonathan Hart31582d12014-10-22 13:52:41 -0700209 Host host1 = new DefaultHost(ProviderId.NONE, HostId.NONE,
210 MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE,
211 new HostLocation(SW1_ETH1, 1),
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700212 Sets.newHashSet(host1Address));
Jonathan Hart31582d12014-10-22 13:52:41 -0700213
214 expect(hostService.getHostsByIp(host1Address))
215 .andReturn(Sets.newHashSet(host1)).anyTimes();
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700216 hostService.startMonitoringIp(host1Address);
Jonathan Hart31582d12014-10-22 13:52:41 -0700217 expectLastCall().anyTimes();
218
219
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700220 IpAddress host2Address = IpAddress.valueOf("192.168.20.1");
Jonathan Hart31582d12014-10-22 13:52:41 -0700221 Host host2 = new DefaultHost(ProviderId.NONE, HostId.NONE,
222 MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE,
223 new HostLocation(SW2_ETH1, 1),
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700224 Sets.newHashSet(host2Address));
Jonathan Hart31582d12014-10-22 13:52:41 -0700225
226 expect(hostService.getHostsByIp(host2Address))
227 .andReturn(Sets.newHashSet(host2)).anyTimes();
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700228 hostService.startMonitoringIp(host2Address);
Jonathan Hart31582d12014-10-22 13:52:41 -0700229 expectLastCall().anyTimes();
230
231
232 replay(hostService);
Pingping3855f312014-10-22 12:50:37 -0700233 }
234
235 /**
236 * This method tests adding a route entry.
237 */
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -0800238 @Test
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800239 public void testRouteAdd() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700240 // Construct a route entry
241 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800242 Ip4Prefix.valueOf("1.1.1.0/24"),
243 Ip4Address.valueOf("192.168.10.1"));
Pingping3855f312014-10-22 12:50:37 -0700244
245 // Construct a MultiPointToSinglePointIntent intent
246 TrafficSelector.Builder selectorBuilder =
247 DefaultTrafficSelector.builder();
248 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
249 routeEntry.prefix());
250
251 TrafficTreatment.Builder treatmentBuilder =
252 DefaultTrafficTreatment.builder();
253 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
254
255 Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700256 ingressPoints.add(SW2_ETH1);
257 ingressPoints.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700258
259 MultiPointToSinglePointIntent intent =
260 new MultiPointToSinglePointIntent(APPID,
261 selectorBuilder.build(), treatmentBuilder.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700262 ingressPoints, SW1_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700263
264 // Set up test expectation
265 reset(intentService);
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800266 // Setup the expected intents
267 IntentOperations.Builder builder = IntentOperations.builder(APPID);
268 builder.addSubmitOperation(intent);
269 intentService.execute(TestIntentServiceHelper.eqExceptId(
270 builder.build()));
Pingping3855f312014-10-22 12:50:37 -0700271 replay(intentService);
272
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800273 // Call the processRouteUpdates() method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800274 intentSynchronizer.leaderChanged(true);
275 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800276 RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.UPDATE,
277 routeEntry);
278 router.processRouteUpdates(Collections.<RouteUpdate>singletonList(routeUpdate));
Pingping3855f312014-10-22 12:50:37 -0700279
280 // Verify
281 assertEquals(router.getRoutes().size(), 1);
282 assertTrue(router.getRoutes().contains(routeEntry));
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800283 assertEquals(intentSynchronizer.getRouteIntents().size(), 1);
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -0800284 Intent firstIntent =
285 intentSynchronizer.getRouteIntents().iterator().next();
286 IntentKey firstIntentKey = new IntentKey(firstIntent);
287 IntentKey intentKey = new IntentKey(intent);
288 assertTrue(firstIntentKey.equals(intentKey));
Pingping3855f312014-10-22 12:50:37 -0700289 verify(intentService);
290 }
291
292 /**
293 * This method tests updating a route entry.
294 *
295 * @throws TestUtilsException
296 */
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -0800297 @Test
Pingping3855f312014-10-22 12:50:37 -0700298 public void testRouteUpdate() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700299 // Firstly add a route
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800300 testRouteAdd();
301
302 Intent addedIntent =
303 intentSynchronizer.getRouteIntents().iterator().next();
Pingping3855f312014-10-22 12:50:37 -0700304
Pingping3855f312014-10-22 12:50:37 -0700305 // Start to construct a new route entry and new intent
306 RouteEntry routeEntryUpdate = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800307 Ip4Prefix.valueOf("1.1.1.0/24"),
308 Ip4Address.valueOf("192.168.20.1"));
Pingping3855f312014-10-22 12:50:37 -0700309
310 // Construct a new MultiPointToSinglePointIntent intent
311 TrafficSelector.Builder selectorBuilderNew =
312 DefaultTrafficSelector.builder();
313 selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
314 routeEntryUpdate.prefix());
315
316 TrafficTreatment.Builder treatmentBuilderNew =
317 DefaultTrafficTreatment.builder();
318 treatmentBuilderNew.setEthDst(MacAddress.valueOf("00:00:00:00:00:02"));
319
Pingping3855f312014-10-22 12:50:37 -0700320
321 Set<ConnectPoint> ingressPointsNew = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700322 ingressPointsNew.add(SW1_ETH1);
323 ingressPointsNew.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700324
325 MultiPointToSinglePointIntent intentNew =
326 new MultiPointToSinglePointIntent(APPID,
327 selectorBuilderNew.build(),
328 treatmentBuilderNew.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700329 ingressPointsNew, SW2_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700330
331 // Set up test expectation
332 reset(intentService);
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800333 // Setup the expected intents
334 IntentOperations.Builder builder = IntentOperations.builder(APPID);
335 builder.addWithdrawOperation(addedIntent.id());
336 intentService.execute(TestIntentServiceHelper.eqExceptId(
337 builder.build()));
338 builder = IntentOperations.builder(APPID);
339 builder.addSubmitOperation(intentNew);
340 intentService.execute(TestIntentServiceHelper.eqExceptId(
341 builder.build()));
Pingping3855f312014-10-22 12:50:37 -0700342 replay(intentService);
343
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800344 // Call the processRouteUpdates() method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800345 intentSynchronizer.leaderChanged(true);
346 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800347 RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.UPDATE,
348 routeEntryUpdate);
349 router.processRouteUpdates(Collections.<RouteUpdate>singletonList(routeUpdate));
Pingping3855f312014-10-22 12:50:37 -0700350
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);
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -0800355 Intent firstIntent =
356 intentSynchronizer.getRouteIntents().iterator().next();
357 IntentKey firstIntentKey = new IntentKey(firstIntent);
358 IntentKey intentNewKey = new IntentKey(intentNew);
359 assertTrue(firstIntentKey.equals(intentNewKey));
Pingping3855f312014-10-22 12:50:37 -0700360 verify(intentService);
361 }
362
363 /**
364 * This method tests deleting a route entry.
365 */
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -0800366 @Test
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800367 public void testRouteDelete() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700368 // Firstly add a route
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800369 testRouteAdd();
370
371 Intent addedIntent =
372 intentSynchronizer.getRouteIntents().iterator().next();
Pingping3855f312014-10-22 12:50:37 -0700373
374 // Construct the existing route entry
375 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800376 Ip4Prefix.valueOf("1.1.1.0/24"),
377 Ip4Address.valueOf("192.168.10.1"));
Pingping3855f312014-10-22 12:50:37 -0700378
Pingping3855f312014-10-22 12:50:37 -0700379 // Set up expectation
380 reset(intentService);
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800381 // Setup the expected intents
382 IntentOperations.Builder builder = IntentOperations.builder(APPID);
383 builder.addWithdrawOperation(addedIntent.id());
384 intentService.execute(TestIntentServiceHelper.eqExceptId(
385 builder.build()));
Pingping3855f312014-10-22 12:50:37 -0700386 replay(intentService);
387
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800388 // Call the processRouteUpdates() method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800389 intentSynchronizer.leaderChanged(true);
390 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800391 RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.DELETE,
392 routeEntry);
393 router.processRouteUpdates(Collections.<RouteUpdate>singletonList(routeUpdate));
Pingping3855f312014-10-22 12:50:37 -0700394
395 // Verify
396 assertEquals(router.getRoutes().size(), 0);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800397 assertEquals(intentSynchronizer.getRouteIntents().size(), 0);
Pingping3855f312014-10-22 12:50:37 -0700398 verify(intentService);
399 }
400
401 /**
402 * This method tests when the next hop of a route is the local BGP speaker.
403 *
404 * @throws TestUtilsException
405 */
406 @Test
407 public void testLocalRouteAdd() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700408 // Construct a route entry, the next hop is the local BGP speaker
409 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800410 Ip4Prefix.valueOf("1.1.1.0/24"),
411 Ip4Address.valueOf("0.0.0.0"));
Pingping3855f312014-10-22 12:50:37 -0700412
413 // Reset intentService to check whether the submit method is called
414 reset(intentService);
415 replay(intentService);
416
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800417 // Call the processRouteUpdates() method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800418 intentSynchronizer.leaderChanged(true);
419 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pavlin Radoslavov248c2ae2014-12-02 09:51:25 -0800420 RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.UPDATE,
421 routeEntry);
422 router.processRouteUpdates(Collections.<RouteUpdate>singletonList(routeUpdate));
Pingping3855f312014-10-22 12:50:37 -0700423
424 // Verify
425 assertEquals(router.getRoutes().size(), 1);
426 assertTrue(router.getRoutes().contains(routeEntry));
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800427 assertEquals(intentSynchronizer.getRouteIntents().size(), 0);
Pingping3855f312014-10-22 12:50:37 -0700428 verify(intentService);
429 }
430}