Aaron Kruglikov
Committed by Gerrit Code Review

Changed ProxyArpManager to make use of EdgeManager.

Change-Id: I05193146490aba6736c1815bf0d9022df8628973
...@@ -174,6 +174,8 @@ public class EdgeManager implements EdgePortService { ...@@ -174,6 +174,8 @@ public class EdgeManager implements EdgePortService {
174 } 174 }
175 }); 175 });
176 } else { 176 } else {
177 + //FIXME special case of preexisting edgeport & no triggerless events could cause this to never hit and
178 + //never discover an edgeport that should have been discovered.
177 loadAllEdgePorts(); 179 loadAllEdgePorts();
178 } 180 }
179 } 181 }
...@@ -198,6 +200,7 @@ public class EdgeManager implements EdgePortService { ...@@ -198,6 +200,7 @@ public class EdgeManager implements EdgePortService {
198 200
199 // Processes a device event by adding or removing its end-points in our cache. 201 // Processes a device event by adding or removing its end-points in our cache.
200 private void processDeviceEvent(DeviceEvent event) { 202 private void processDeviceEvent(DeviceEvent event) {
203 + //FIXME handle the case where a device is suspended, this may or may not come up
201 DeviceEvent.Type type = event.type(); 204 DeviceEvent.Type type = event.type();
202 DeviceId id = event.subject().id(); 205 DeviceId id = event.subject().id();
203 206
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.net.proxyarp.impl; 16 package org.onosproject.net.proxyarp.impl;
17 17
18 +import com.google.common.collect.Lists;
18 import com.google.common.collect.Sets; 19 import com.google.common.collect.Sets;
19 import org.junit.Before; 20 import org.junit.Before;
20 import org.junit.Test; 21 import org.junit.Test;
...@@ -36,6 +37,7 @@ import org.onosproject.net.Port; ...@@ -36,6 +37,7 @@ import org.onosproject.net.Port;
36 import org.onosproject.net.PortNumber; 37 import org.onosproject.net.PortNumber;
37 import org.onosproject.net.device.DeviceListener; 38 import org.onosproject.net.device.DeviceListener;
38 import org.onosproject.net.device.DeviceService; 39 import org.onosproject.net.device.DeviceService;
40 +import org.onosproject.net.edgeservice.impl.EdgeManager;
39 import org.onosproject.net.flow.instructions.Instruction; 41 import org.onosproject.net.flow.instructions.Instruction;
40 import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; 42 import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
41 import org.onosproject.net.host.HostService; 43 import org.onosproject.net.host.HostService;
...@@ -53,8 +55,14 @@ import java.util.Comparator; ...@@ -53,8 +55,14 @@ import java.util.Comparator;
53 import java.util.List; 55 import java.util.List;
54 import java.util.Set; 56 import java.util.Set;
55 57
56 -import static org.easymock.EasyMock.*; 58 +import static org.easymock.EasyMock.anyObject;
57 -import static org.junit.Assert.*; 59 +import static org.easymock.EasyMock.createMock;
60 +import static org.easymock.EasyMock.expect;
61 +import static org.easymock.EasyMock.replay;
62 +import static org.junit.Assert.assertArrayEquals;
63 +import static org.junit.Assert.assertEquals;
64 +import static org.junit.Assert.assertFalse;
65 +import static org.junit.Assert.assertTrue;
58 66
59 /** 67 /**
60 * Tests for the {@link ProxyArpManager} class. 68 * Tests for the {@link ProxyArpManager} class.
...@@ -85,6 +93,11 @@ public class ProxyArpManagerTest { ...@@ -85,6 +93,11 @@ public class ProxyArpManagerTest {
85 private static final HostLocation LOC2 = new HostLocation(DID2, P1, 123L); 93 private static final HostLocation LOC2 = new HostLocation(DID2, P1, 123L);
86 private static final byte[] ZERO_MAC_ADDRESS = MacAddress.ZERO.toBytes(); 94 private static final byte[] ZERO_MAC_ADDRESS = MacAddress.ZERO.toBytes();
87 95
96 + //Return values used for various functions of the TestPacketService inner class.
97 + private boolean isEdgePointReturn;
98 + private List<ConnectPoint> getEdgePointsNoArg;
99 +
100 +
88 private ProxyArpManager proxyArp; 101 private ProxyArpManager proxyArp;
89 102
90 private TestPacketService packetService; 103 private TestPacketService packetService;
...@@ -98,6 +111,8 @@ public class ProxyArpManagerTest { ...@@ -98,6 +111,8 @@ public class ProxyArpManagerTest {
98 packetService = new TestPacketService(); 111 packetService = new TestPacketService();
99 proxyArp.packetService = packetService; 112 proxyArp.packetService = packetService;
100 113
114 + proxyArp.edgeService = new TestEdgePortService();
115 +
101 // Create a host service mock here. Must be replayed by tests once the 116 // Create a host service mock here. Must be replayed by tests once the
102 // expectations have been set up 117 // expectations have been set up
103 hostService = createMock(HostService.class); 118 hostService = createMock(HostService.class);
...@@ -112,7 +127,7 @@ public class ProxyArpManagerTest { ...@@ -112,7 +127,7 @@ public class ProxyArpManagerTest {
112 127
113 /** 128 /**
114 * Creates a fake topology to feed into the ARP module. 129 * Creates a fake topology to feed into the ARP module.
115 - * <p/> 130 + * <p>
116 * The default topology is a unidirectional ring topology. Each switch has 131 * The default topology is a unidirectional ring topology. Each switch has
117 * 3 ports. Ports 2 and 3 have the links to neighbor switches, and port 1 132 * 3 ports. Ports 2 and 3 have the links to neighbor switches, and port 1
118 * is free (edge port). 133 * is free (edge port).
...@@ -205,12 +220,12 @@ public class ProxyArpManagerTest { ...@@ -205,12 +220,12 @@ public class ProxyArpManagerTest {
205 InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2); 220 InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2);
206 PortAddresses pa1 = 221 PortAddresses pa1 =
207 new PortAddresses(cp, Sets.newHashSet(ia1), 222 new PortAddresses(cp, Sets.newHashSet(ia1),
208 - MacAddress.valueOf(2 * i - 1), 223 + MacAddress.valueOf(2 * i - 1),
209 - VlanId.vlanId((short) 1)); 224 + VlanId.vlanId((short) 1));
210 PortAddresses pa2 = 225 PortAddresses pa2 =
211 new PortAddresses(cp, Sets.newHashSet(ia2), 226 new PortAddresses(cp, Sets.newHashSet(ia2),
212 - MacAddress.valueOf(2 * i), 227 + MacAddress.valueOf(2 * i),
213 - VlanId.NONE); 228 + VlanId.NONE);
214 229
215 addresses.add(pa1); 230 addresses.add(pa1);
216 addresses.add(pa2); 231 addresses.add(pa2);
...@@ -223,7 +238,7 @@ public class ProxyArpManagerTest { ...@@ -223,7 +238,7 @@ public class ProxyArpManagerTest {
223 238
224 for (int i = 1; i <= NUM_FLOOD_PORTS; i++) { 239 for (int i = 1; i <= NUM_FLOOD_PORTS; i++) {
225 ConnectPoint cp = new ConnectPoint(getDeviceId(i + NUM_ADDRESS_PORTS), 240 ConnectPoint cp = new ConnectPoint(getDeviceId(i + NUM_ADDRESS_PORTS),
226 - P1); 241 + P1);
227 expect(hostService.getAddressBindingsForPort(cp)) 242 expect(hostService.getAddressBindingsForPort(cp))
228 .andReturn(Collections.<PortAddresses>emptySet()).anyTimes(); 243 .andReturn(Collections.<PortAddresses>emptySet()).anyTimes();
229 } 244 }
...@@ -266,11 +281,14 @@ public class ProxyArpManagerTest { ...@@ -266,11 +281,14 @@ public class ProxyArpManagerTest {
266 */ 281 */
267 @Test 282 @Test
268 public void testReplyKnown() { 283 public void testReplyKnown() {
284 + //Set the return value of isEdgePoint from the edgemanager.
285 + isEdgePointReturn = true;
286 +
269 Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(4), 287 Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(4),
270 - Collections.singleton(IP1)); 288 + Collections.singleton(IP1));
271 289
272 Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), 290 Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5),
273 - Collections.singleton(IP2)); 291 + Collections.singleton(IP2));
274 292
275 expect(hostService.getHostsByIp(IP1)) 293 expect(hostService.getHostsByIp(IP1))
276 .andReturn(Collections.singleton(replyer)); 294 .andReturn(Collections.singleton(replyer));
...@@ -294,17 +312,25 @@ public class ProxyArpManagerTest { ...@@ -294,17 +312,25 @@ public class ProxyArpManagerTest {
294 */ 312 */
295 @Test 313 @Test
296 public void testReplyUnknown() { 314 public void testReplyUnknown() {
315 + isEdgePointReturn = true;
316 +
297 Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), 317 Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5),
298 - Collections.singleton(IP2)); 318 + Collections.singleton(IP2));
299 319
300 expect(hostService.getHostsByIp(IP1)) 320 expect(hostService.getHostsByIp(IP1))
301 .andReturn(Collections.<Host>emptySet()); 321 .andReturn(Collections.<Host>emptySet());
302 expect(hostService.getHost(HID2)).andReturn(requestor); 322 expect(hostService.getHost(HID2)).andReturn(requestor);
303 323
324 +
304 replay(hostService); 325 replay(hostService);
305 326
306 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); 327 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1);
307 328
329 + //Setup the set of edge ports to be used in the reply method
330 + getEdgePointsNoArg = Lists.newLinkedList();
331 + getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1)));
332 + getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1)));
333 +
308 proxyArp.reply(arpRequest, getLocation(6)); 334 proxyArp.reply(arpRequest, getLocation(6));
309 335
310 verifyFlood(arpRequest); 336 verifyFlood(arpRequest);
...@@ -318,11 +344,12 @@ public class ProxyArpManagerTest { ...@@ -318,11 +344,12 @@ public class ProxyArpManagerTest {
318 */ 344 */
319 @Test 345 @Test
320 public void testReplyDifferentVlan() { 346 public void testReplyDifferentVlan() {
347 +
321 Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN2, getLocation(4), 348 Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN2, getLocation(4),
322 - Collections.singleton(IP1)); 349 + Collections.singleton(IP1));
323 350
324 Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), 351 Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5),
325 - Collections.singleton(IP2)); 352 + Collections.singleton(IP2));
326 353
327 expect(hostService.getHostsByIp(IP1)) 354 expect(hostService.getHostsByIp(IP1))
328 .andReturn(Collections.singleton(replyer)); 355 .andReturn(Collections.singleton(replyer));
...@@ -332,6 +359,10 @@ public class ProxyArpManagerTest { ...@@ -332,6 +359,10 @@ public class ProxyArpManagerTest {
332 359
333 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); 360 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1);
334 361
362 + //Setup for flood test
363 + getEdgePointsNoArg = Lists.newLinkedList();
364 + getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1)));
365 + getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1)));
335 proxyArp.reply(arpRequest, getLocation(6)); 366 proxyArp.reply(arpRequest, getLocation(6));
336 367
337 verifyFlood(arpRequest); 368 verifyFlood(arpRequest);
...@@ -346,13 +377,13 @@ public class ProxyArpManagerTest { ...@@ -346,13 +377,13 @@ public class ProxyArpManagerTest {
346 MacAddress secondMac = MacAddress.valueOf(2L); 377 MacAddress secondMac = MacAddress.valueOf(2L);
347 378
348 Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC1, 379 Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC1,
349 - Collections.singleton(theirIp)); 380 + Collections.singleton(theirIp));
350 381
351 expect(hostService.getHost(HID2)).andReturn(requestor); 382 expect(hostService.getHost(HID2)).andReturn(requestor);
352 replay(hostService); 383 replay(hostService);
353 384
354 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, theirIp, ourFirstIp); 385 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, theirIp, ourFirstIp);
355 - 386 + isEdgePointReturn = true;
356 proxyArp.reply(arpRequest, LOC1); 387 proxyArp.reply(arpRequest, LOC1);
357 388
358 assertEquals(1, packetService.packets.size()); 389 assertEquals(1, packetService.packets.size());
...@@ -378,7 +409,7 @@ public class ProxyArpManagerTest { ...@@ -378,7 +409,7 @@ public class ProxyArpManagerTest {
378 409
379 // Request for a valid external IP address but coming in the wrong port 410 // Request for a valid external IP address but coming in the wrong port
380 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC1, null, theirIp, 411 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC1, null, theirIp,
381 - Ip4Address.valueOf("10.0.3.1")); 412 + Ip4Address.valueOf("10.0.3.1"));
382 proxyArp.reply(arpRequest, LOC1); 413 proxyArp.reply(arpRequest, LOC1);
383 assertEquals(0, packetService.packets.size()); 414 assertEquals(0, packetService.packets.size());
384 415
...@@ -402,8 +433,10 @@ public class ProxyArpManagerTest { ...@@ -402,8 +433,10 @@ public class ProxyArpManagerTest {
402 // This is a request from something inside our network (like a BGP 433 // This is a request from something inside our network (like a BGP
403 // daemon) to an external host. 434 // daemon) to an external host.
404 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, ourMac, null, ourIp, theirIp); 435 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, ourMac, null, ourIp, theirIp);
405 - proxyArp.reply(arpRequest, getLocation(5)); 436 + //Ensure the packet is allowed through (it is not to an internal port)
437 + isEdgePointReturn = true;
406 438
439 + proxyArp.reply(arpRequest, getLocation(5));
407 assertEquals(1, packetService.packets.size()); 440 assertEquals(1, packetService.packets.size());
408 verifyPacketOut(arpRequest, getLocation(1), packetService.packets.get(0)); 441 verifyPacketOut(arpRequest, getLocation(1), packetService.packets.get(0));
409 442
...@@ -421,7 +454,7 @@ public class ProxyArpManagerTest { ...@@ -421,7 +454,7 @@ public class ProxyArpManagerTest {
421 @Test 454 @Test
422 public void testForwardToHost() { 455 public void testForwardToHost() {
423 Host host1 = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, 456 Host host1 = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1,
424 - Collections.singleton(IP1)); 457 + Collections.singleton(IP1));
425 458
426 expect(hostService.getHost(HID1)).andReturn(host1); 459 expect(hostService.getHost(HID1)).andReturn(host1);
427 replay(hostService); 460 replay(hostService);
...@@ -448,6 +481,13 @@ public class ProxyArpManagerTest { ...@@ -448,6 +481,13 @@ public class ProxyArpManagerTest {
448 481
449 Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1); 482 Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1);
450 483
484 + //populate the list of edges when so that when forward hits flood in the manager it contains the values
485 + //that should continue on
486 + getEdgePointsNoArg = Lists.newLinkedList();
487 + getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("3"), PortNumber.portNumber(1)));
488 + getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1)));
489 + getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1)));
490 +
451 proxyArp.forward(arpRequest, getLocation(6)); 491 proxyArp.forward(arpRequest, getLocation(6));
452 492
453 verifyFlood(arpRequest); 493 verifyFlood(arpRequest);
...@@ -464,17 +504,17 @@ public class ProxyArpManagerTest { ...@@ -464,17 +504,17 @@ public class ProxyArpManagerTest {
464 assertEquals(NUM_FLOOD_PORTS - 1, packetService.packets.size()); 504 assertEquals(NUM_FLOOD_PORTS - 1, packetService.packets.size());
465 505
466 Collections.sort(packetService.packets, 506 Collections.sort(packetService.packets,
467 - new Comparator<OutboundPacket>() { 507 + new Comparator<OutboundPacket>() {
468 - @Override 508 + @Override
469 - public int compare(OutboundPacket o1, OutboundPacket o2) { 509 + public int compare(OutboundPacket o1, OutboundPacket o2) {
470 - return o1.sendThrough().uri().compareTo(o2.sendThrough().uri()); 510 + return o1.sendThrough().uri().compareTo(o2.sendThrough().uri());
471 - } 511 + }
472 - }); 512 + });
473 513
474 514
475 for (int i = 0; i < NUM_FLOOD_PORTS - 1; i++) { 515 for (int i = 0; i < NUM_FLOOD_PORTS - 1; i++) {
476 ConnectPoint cp = new ConnectPoint(getDeviceId(NUM_ADDRESS_PORTS + i + 1), 516 ConnectPoint cp = new ConnectPoint(getDeviceId(NUM_ADDRESS_PORTS + i + 1),
477 - PortNumber.portNumber(1)); 517 + PortNumber.portNumber(1));
478 518
479 OutboundPacket outboundPacket = packetService.packets.get(i); 519 OutboundPacket outboundPacket = packetService.packets.get(i);
480 verifyPacketOut(packet, cp, outboundPacket); 520 verifyPacketOut(packet, cp, outboundPacket);
...@@ -572,4 +612,17 @@ public class ProxyArpManagerTest { ...@@ -572,4 +612,17 @@ public class ProxyArpManagerTest {
572 } 612 }
573 613
574 } 614 }
615 +
616 + class TestEdgePortService extends EdgeManager {
617 +
618 + @Override
619 + public boolean isEdgePoint(ConnectPoint connectPoint) {
620 + return isEdgePointReturn;
621 + }
622 +
623 + @Override
624 + public Iterable<ConnectPoint> getEdgePoints() {
625 + return getEdgePointsNoArg;
626 + }
627 + }
575 } 628 }
......