blob: f15d50f526f4dd4943e73a3b966597a864c833c8 [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;
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -080052import org.onlab.onos.net.intent.Intent;
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;
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -080057import org.onlab.onos.sdnip.IntentSynchronizer.IntentKey;
Pingping3855f312014-10-22 12:50:37 -070058import org.onlab.onos.sdnip.config.BgpPeer;
59import org.onlab.onos.sdnip.config.Interface;
60import org.onlab.onos.sdnip.config.SdnIpConfigService;
61import org.onlab.packet.Ethernet;
62import org.onlab.packet.IpAddress;
Pavlin Radoslavov6b570732014-11-06 13:16:45 -080063import org.onlab.packet.Ip4Address;
Pingping3855f312014-10-22 12:50:37 -070064import org.onlab.packet.IpPrefix;
Pavlin Radoslavov6b570732014-11-06 13:16:45 -080065import org.onlab.packet.Ip4Prefix;
Pingping3855f312014-10-22 12:50:37 -070066import org.onlab.packet.MacAddress;
67import org.onlab.packet.VlanId;
Pingping3855f312014-10-22 12:50:37 -070068
69import com.google.common.collect.Sets;
70
71/**
72 * This class tests adding a route, updating a route, deleting a route,
73 * and adding a route whose next hop is the local BGP speaker.
Pingpingfc584672014-10-23 10:51:19 -070074 * <p/>
75 * ARP module answers the MAC address synchronously.
Pingping3855f312014-10-22 12:50:37 -070076 */
Brian O'Connor520c0522014-11-23 23:50:47 -080077public class RouterTest extends AbstractIntentTest {
Pingping3855f312014-10-22 12:50:37 -070078
79 private SdnIpConfigService sdnIpConfigService;
80 private InterfaceService interfaceService;
81 private IntentService intentService;
82 private HostService hostService;
83
Jonathan Hart31582d12014-10-22 13:52:41 -070084 private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
85 DeviceId.deviceId("of:0000000000000001"),
86 PortNumber.portNumber(1));
87
88 private static final ConnectPoint SW2_ETH1 = new ConnectPoint(
89 DeviceId.deviceId("of:0000000000000002"),
90 PortNumber.portNumber(1));
91
92 private static final ConnectPoint SW3_ETH1 = new ConnectPoint(
93 DeviceId.deviceId("of:0000000000000003"),
94 PortNumber.portNumber(1));
Pingping3855f312014-10-22 12:50:37 -070095
96 private static final ApplicationId APPID = new ApplicationId() {
97 @Override
98 public short id() {
99 return 1;
100 }
101
102 @Override
103 public String name() {
104 return "SDNIP";
105 }
106 };
107
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800108 private IntentSynchronizer intentSynchronizer;
Pingping3855f312014-10-22 12:50:37 -0700109 private Router router;
110
111 @Before
112 public void setUp() throws Exception {
Brian O'Connor520c0522014-11-23 23:50:47 -0800113 super.setUp();
114
Jonathan Hart31582d12014-10-22 13:52:41 -0700115 setUpBgpPeers();
Pingping3855f312014-10-22 12:50:37 -0700116
Jonathan Hart31582d12014-10-22 13:52:41 -0700117 setUpInterfaceService();
118 setUpHostService();
Pingping3855f312014-10-22 12:50:37 -0700119
120 intentService = createMock(IntentService.class);
Pingping3855f312014-10-22 12:50:37 -0700121
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800122 intentSynchronizer = new IntentSynchronizer(APPID, intentService);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800123 router = new Router(APPID, intentSynchronizer, sdnIpConfigService,
124 interfaceService, hostService);
Pingping3855f312014-10-22 12:50:37 -0700125 }
126
127 /**
128 * Sets up BGP peers in external networks.
Pingping3855f312014-10-22 12:50:37 -0700129 */
Jonathan Hart31582d12014-10-22 13:52:41 -0700130 private void setUpBgpPeers() {
Pingping3855f312014-10-22 12:50:37 -0700131
Jonathan Hart31582d12014-10-22 13:52:41 -0700132 Map<IpAddress, BgpPeer> peers = new HashMap<>();
Pingping3855f312014-10-22 12:50:37 -0700133
134 String peerSw1Eth1 = "192.168.10.1";
Jonathan Hart31582d12014-10-22 13:52:41 -0700135 peers.put(IpAddress.valueOf(peerSw1Eth1),
Pingping3855f312014-10-22 12:50:37 -0700136 new BgpPeer("00:00:00:00:00:00:00:01", 1, peerSw1Eth1));
137
138 // Two BGP peers are connected to switch 2 port 1.
139 String peer1Sw2Eth1 = "192.168.20.1";
Jonathan Hart31582d12014-10-22 13:52:41 -0700140 peers.put(IpAddress.valueOf(peer1Sw2Eth1),
Pingping3855f312014-10-22 12:50:37 -0700141 new BgpPeer("00:00:00:00:00:00:00:02", 1, peer1Sw2Eth1));
142
143 String peer2Sw2Eth1 = "192.168.20.2";
Jonathan Hart31582d12014-10-22 13:52:41 -0700144 peers.put(IpAddress.valueOf(peer2Sw2Eth1),
Pingping3855f312014-10-22 12:50:37 -0700145 new BgpPeer("00:00:00:00:00:00:00:02", 1, peer2Sw2Eth1));
146
Jonathan Hart31582d12014-10-22 13:52:41 -0700147 sdnIpConfigService = createMock(SdnIpConfigService.class);
148 expect(sdnIpConfigService.getBgpPeers()).andReturn(peers).anyTimes();
149 replay(sdnIpConfigService);
150
Pingping3855f312014-10-22 12:50:37 -0700151 }
152
153 /**
154 * Sets up logical interfaces, which emulate the configured interfaces
155 * in SDN-IP application.
Pingping3855f312014-10-22 12:50:37 -0700156 */
Jonathan Hart31582d12014-10-22 13:52:41 -0700157 private void setUpInterfaceService() {
158 interfaceService = createMock(InterfaceService.class);
Pingping3855f312014-10-22 12:50:37 -0700159
Jonathan Hart31582d12014-10-22 13:52:41 -0700160 Set<Interface> interfaces = Sets.newHashSet();
Pingping3855f312014-10-22 12:50:37 -0700161
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700162 InterfaceIpAddress ia1 =
163 new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"),
164 IpPrefix.valueOf("192.168.10.0/24"));
Jonathan Hart31582d12014-10-22 13:52:41 -0700165 Interface sw1Eth1 = new Interface(SW1_ETH1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700166 Sets.newHashSet(ia1),
Jonathan Hart31582d12014-10-22 13:52:41 -0700167 MacAddress.valueOf("00:00:00:00:00:01"));
Pingping3855f312014-10-22 12:50:37 -0700168
Jonathan Hart31582d12014-10-22 13:52:41 -0700169 expect(interfaceService.getInterface(SW1_ETH1)).andReturn(sw1Eth1).anyTimes();
170 interfaces.add(sw1Eth1);
Pingping3855f312014-10-22 12:50:37 -0700171
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700172 InterfaceIpAddress ia2 =
173 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"),
174 IpPrefix.valueOf("192.168.20.0/24"));
Jonathan Hart31582d12014-10-22 13:52:41 -0700175 Interface sw2Eth1 = new Interface(SW2_ETH1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700176 Sets.newHashSet(ia2),
Jonathan Hart31582d12014-10-22 13:52:41 -0700177 MacAddress.valueOf("00:00:00:00:00:02"));
Pingping3855f312014-10-22 12:50:37 -0700178
Jonathan Hart31582d12014-10-22 13:52:41 -0700179 expect(interfaceService.getInterface(SW2_ETH1)).andReturn(sw2Eth1).anyTimes();
180 interfaces.add(sw2Eth1);
181
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700182 InterfaceIpAddress ia3 =
183 new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
184 IpPrefix.valueOf("192.168.30.0/24"));
Jonathan Hart31582d12014-10-22 13:52:41 -0700185 Interface sw3Eth1 = new Interface(SW3_ETH1,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -0700186 Sets.newHashSet(ia3),
Jonathan Hart31582d12014-10-22 13:52:41 -0700187 MacAddress.valueOf("00:00:00:00:00:03"));
188
189 expect(interfaceService.getInterface(SW3_ETH1)).andReturn(sw3Eth1).anyTimes();
190 interfaces.add(sw3Eth1);
191
192 expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
193
194 replay(interfaceService);
195 }
196
197 /**
198 * Sets up the host service with details of some hosts.
199 */
200 private void setUpHostService() {
201 hostService = createMock(HostService.class);
202
203 hostService.addListener(anyObject(HostListener.class));
204 expectLastCall().anyTimes();
205
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700206 IpAddress host1Address = IpAddress.valueOf("192.168.10.1");
Jonathan Hart31582d12014-10-22 13:52:41 -0700207 Host host1 = new DefaultHost(ProviderId.NONE, HostId.NONE,
208 MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE,
209 new HostLocation(SW1_ETH1, 1),
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700210 Sets.newHashSet(host1Address));
Jonathan Hart31582d12014-10-22 13:52:41 -0700211
212 expect(hostService.getHostsByIp(host1Address))
213 .andReturn(Sets.newHashSet(host1)).anyTimes();
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700214 hostService.startMonitoringIp(host1Address);
Jonathan Hart31582d12014-10-22 13:52:41 -0700215 expectLastCall().anyTimes();
216
217
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700218 IpAddress host2Address = IpAddress.valueOf("192.168.20.1");
Jonathan Hart31582d12014-10-22 13:52:41 -0700219 Host host2 = new DefaultHost(ProviderId.NONE, HostId.NONE,
220 MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE,
221 new HostLocation(SW2_ETH1, 1),
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700222 Sets.newHashSet(host2Address));
Jonathan Hart31582d12014-10-22 13:52:41 -0700223
224 expect(hostService.getHostsByIp(host2Address))
225 .andReturn(Sets.newHashSet(host2)).anyTimes();
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700226 hostService.startMonitoringIp(host2Address);
Jonathan Hart31582d12014-10-22 13:52:41 -0700227 expectLastCall().anyTimes();
228
229
230 replay(hostService);
Pingping3855f312014-10-22 12:50:37 -0700231 }
232
233 /**
234 * This method tests adding a route entry.
235 */
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -0800236 @Test
Pingping3855f312014-10-22 12:50:37 -0700237 public void testProcessRouteAdd() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700238 // Construct a route entry
239 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800240 Ip4Prefix.valueOf("1.1.1.0/24"),
241 Ip4Address.valueOf("192.168.10.1"));
Pingping3855f312014-10-22 12:50:37 -0700242
243 // Construct a MultiPointToSinglePointIntent intent
244 TrafficSelector.Builder selectorBuilder =
245 DefaultTrafficSelector.builder();
246 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
247 routeEntry.prefix());
248
249 TrafficTreatment.Builder treatmentBuilder =
250 DefaultTrafficTreatment.builder();
251 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
252
253 Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700254 ingressPoints.add(SW2_ETH1);
255 ingressPoints.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700256
257 MultiPointToSinglePointIntent intent =
258 new MultiPointToSinglePointIntent(APPID,
259 selectorBuilder.build(), treatmentBuilder.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700260 ingressPoints, SW1_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700261
262 // Set up test expectation
263 reset(intentService);
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -0800264 intentService.submit(TestIntentServiceHelper.eqExceptId(intent));
Pingping3855f312014-10-22 12:50:37 -0700265 replay(intentService);
266
267 // Call the processRouteAdd() method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800268 intentSynchronizer.leaderChanged(true);
269 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pingping3855f312014-10-22 12:50:37 -0700270 router.processRouteAdd(routeEntry);
271
272 // Verify
273 assertEquals(router.getRoutes().size(), 1);
274 assertTrue(router.getRoutes().contains(routeEntry));
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800275 assertEquals(intentSynchronizer.getRouteIntents().size(), 1);
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -0800276 Intent firstIntent =
277 intentSynchronizer.getRouteIntents().iterator().next();
278 IntentKey firstIntentKey = new IntentKey(firstIntent);
279 IntentKey intentKey = new IntentKey(intent);
280 assertTrue(firstIntentKey.equals(intentKey));
Pingping3855f312014-10-22 12:50:37 -0700281 verify(intentService);
282 }
283
284 /**
285 * This method tests updating a route entry.
286 *
287 * @throws TestUtilsException
288 */
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -0800289 @Test
Pingping3855f312014-10-22 12:50:37 -0700290 public void testRouteUpdate() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700291 // Firstly add a route
292 testProcessRouteAdd();
293
294 // Construct the existing route entry
295 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800296 Ip4Prefix.valueOf("1.1.1.0/24"),
297 Ip4Address.valueOf("192.168.10.1"));
Pingping3855f312014-10-22 12:50:37 -0700298
299 // Construct the existing MultiPointToSinglePointIntent intent
300 TrafficSelector.Builder selectorBuilder =
301 DefaultTrafficSelector.builder();
302 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
303 routeEntry.prefix());
304
305 TrafficTreatment.Builder treatmentBuilder =
306 DefaultTrafficTreatment.builder();
307 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
308
Pingping3855f312014-10-22 12:50:37 -0700309 Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700310 ingressPoints.add(SW2_ETH1);
311 ingressPoints.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700312
313 MultiPointToSinglePointIntent intent =
314 new MultiPointToSinglePointIntent(APPID,
315 selectorBuilder.build(), treatmentBuilder.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700316 ingressPoints, SW1_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700317
318 // Start to construct a new route entry and new intent
319 RouteEntry routeEntryUpdate = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800320 Ip4Prefix.valueOf("1.1.1.0/24"),
321 Ip4Address.valueOf("192.168.20.1"));
Pingping3855f312014-10-22 12:50:37 -0700322
323 // Construct a new MultiPointToSinglePointIntent intent
324 TrafficSelector.Builder selectorBuilderNew =
325 DefaultTrafficSelector.builder();
326 selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
327 routeEntryUpdate.prefix());
328
329 TrafficTreatment.Builder treatmentBuilderNew =
330 DefaultTrafficTreatment.builder();
331 treatmentBuilderNew.setEthDst(MacAddress.valueOf("00:00:00:00:00:02"));
332
Pingping3855f312014-10-22 12:50:37 -0700333
334 Set<ConnectPoint> ingressPointsNew = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700335 ingressPointsNew.add(SW1_ETH1);
336 ingressPointsNew.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700337
338 MultiPointToSinglePointIntent intentNew =
339 new MultiPointToSinglePointIntent(APPID,
340 selectorBuilderNew.build(),
341 treatmentBuilderNew.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700342 ingressPointsNew, SW2_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700343
344 // Set up test expectation
345 reset(intentService);
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -0800346 intentService.withdraw(TestIntentServiceHelper.eqExceptId(intent));
347 intentService.submit(TestIntentServiceHelper.eqExceptId(intentNew));
Pingping3855f312014-10-22 12:50:37 -0700348 replay(intentService);
349
350 // Call the processRouteAdd() method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800351 intentSynchronizer.leaderChanged(true);
352 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pingping3855f312014-10-22 12:50:37 -0700353 router.processRouteAdd(routeEntryUpdate);
354
355 // Verify
356 assertEquals(router.getRoutes().size(), 1);
357 assertTrue(router.getRoutes().contains(routeEntryUpdate));
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800358 assertEquals(intentSynchronizer.getRouteIntents().size(), 1);
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -0800359 Intent firstIntent =
360 intentSynchronizer.getRouteIntents().iterator().next();
361 IntentKey firstIntentKey = new IntentKey(firstIntent);
362 IntentKey intentNewKey = new IntentKey(intentNew);
363 assertTrue(firstIntentKey.equals(intentNewKey));
Pingping3855f312014-10-22 12:50:37 -0700364 verify(intentService);
365 }
366
367 /**
368 * This method tests deleting a route entry.
369 */
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -0800370 @Test
Pingping3855f312014-10-22 12:50:37 -0700371 public void testProcessRouteDelete() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700372 // Firstly add a route
373 testProcessRouteAdd();
374
375 // Construct the existing route entry
376 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800377 Ip4Prefix.valueOf("1.1.1.0/24"),
378 Ip4Address.valueOf("192.168.10.1"));
Pingping3855f312014-10-22 12:50:37 -0700379
380 // Construct the existing MultiPointToSinglePointIntent intent
381 TrafficSelector.Builder selectorBuilder =
382 DefaultTrafficSelector.builder();
383 selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
384 routeEntry.prefix());
385
386 TrafficTreatment.Builder treatmentBuilder =
387 DefaultTrafficTreatment.builder();
388 treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
389
Pingping3855f312014-10-22 12:50:37 -0700390 Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>();
Jonathan Hart31582d12014-10-22 13:52:41 -0700391 ingressPoints.add(SW2_ETH1);
392 ingressPoints.add(SW3_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700393
394 MultiPointToSinglePointIntent intent =
395 new MultiPointToSinglePointIntent(APPID,
396 selectorBuilder.build(), treatmentBuilder.build(),
Jonathan Hart31582d12014-10-22 13:52:41 -0700397 ingressPoints, SW1_ETH1);
Pingping3855f312014-10-22 12:50:37 -0700398
399 // Set up expectation
400 reset(intentService);
Pavlin Radoslavov97e8a8b2014-11-24 17:51:28 -0800401 intentService.withdraw(TestIntentServiceHelper.eqExceptId(intent));
Pingping3855f312014-10-22 12:50:37 -0700402 replay(intentService);
403
404 // Call route deleting method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800405 intentSynchronizer.leaderChanged(true);
406 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pingping3855f312014-10-22 12:50:37 -0700407 router.processRouteDelete(routeEntry);
408
409 // Verify
410 assertEquals(router.getRoutes().size(), 0);
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800411 assertEquals(intentSynchronizer.getRouteIntents().size(), 0);
Pingping3855f312014-10-22 12:50:37 -0700412 verify(intentService);
413 }
414
415 /**
416 * This method tests when the next hop of a route is the local BGP speaker.
417 *
418 * @throws TestUtilsException
419 */
420 @Test
421 public void testLocalRouteAdd() throws TestUtilsException {
Pingping3855f312014-10-22 12:50:37 -0700422 // Construct a route entry, the next hop is the local BGP speaker
423 RouteEntry routeEntry = new RouteEntry(
Pavlin Radoslavov6b570732014-11-06 13:16:45 -0800424 Ip4Prefix.valueOf("1.1.1.0/24"),
425 Ip4Address.valueOf("0.0.0.0"));
Pingping3855f312014-10-22 12:50:37 -0700426
427 // Reset intentService to check whether the submit method is called
428 reset(intentService);
429 replay(intentService);
430
431 // Call the processRouteAdd() method in Router class
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -0800432 intentSynchronizer.leaderChanged(true);
433 TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
Pingping3855f312014-10-22 12:50:37 -0700434 router.processRouteAdd(routeEntry);
435
436 // Verify
437 assertEquals(router.getRoutes().size(), 1);
438 assertTrue(router.getRoutes().contains(routeEntry));
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -0800439 assertEquals(intentSynchronizer.getRouteIntents().size(), 0);
Pingping3855f312014-10-22 12:50:37 -0700440 verify(intentService);
441 }
442}