Committed by
Gerrit Code Review
Changed ProxyArpManager to make use of EdgeManager.
Change-Id: I05193146490aba6736c1815bf0d9022df8628973
Showing
3 changed files
with
105 additions
and
192 deletions
... | @@ -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,9 +15,6 @@ | ... | @@ -15,9 +15,6 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.proxyarp.impl; | 16 | package org.onosproject.net.proxyarp.impl; |
17 | 17 | ||
18 | -import com.google.common.collect.HashMultimap; | ||
19 | -import com.google.common.collect.Lists; | ||
20 | -import com.google.common.collect.Multimap; | ||
21 | import org.apache.felix.scr.annotations.Activate; | 18 | import org.apache.felix.scr.annotations.Activate; |
22 | import org.apache.felix.scr.annotations.Component; | 19 | import org.apache.felix.scr.annotations.Component; |
23 | import org.apache.felix.scr.annotations.Deactivate; | 20 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -38,22 +35,15 @@ import org.onlab.packet.ndp.NeighborDiscoveryOptions; | ... | @@ -38,22 +35,15 @@ import org.onlab.packet.ndp.NeighborDiscoveryOptions; |
38 | import org.onlab.packet.ndp.NeighborSolicitation; | 35 | import org.onlab.packet.ndp.NeighborSolicitation; |
39 | import org.onosproject.core.Permission; | 36 | import org.onosproject.core.Permission; |
40 | import org.onosproject.net.ConnectPoint; | 37 | import org.onosproject.net.ConnectPoint; |
41 | -import org.onosproject.net.Device; | ||
42 | import org.onosproject.net.Host; | 38 | import org.onosproject.net.Host; |
43 | import org.onosproject.net.HostId; | 39 | import org.onosproject.net.HostId; |
44 | -import org.onosproject.net.Link; | ||
45 | -import org.onosproject.net.Port; | ||
46 | -import org.onosproject.net.PortNumber; | ||
47 | -import org.onosproject.net.device.DeviceEvent; | ||
48 | -import org.onosproject.net.device.DeviceListener; | ||
49 | import org.onosproject.net.device.DeviceService; | 40 | import org.onosproject.net.device.DeviceService; |
41 | +import org.onosproject.net.edge.EdgePortService; | ||
50 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 42 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
51 | import org.onosproject.net.flow.TrafficTreatment; | 43 | import org.onosproject.net.flow.TrafficTreatment; |
52 | import org.onosproject.net.host.HostService; | 44 | import org.onosproject.net.host.HostService; |
53 | import org.onosproject.net.host.InterfaceIpAddress; | 45 | import org.onosproject.net.host.InterfaceIpAddress; |
54 | import org.onosproject.net.host.PortAddresses; | 46 | import org.onosproject.net.host.PortAddresses; |
55 | -import org.onosproject.net.link.LinkEvent; | ||
56 | -import org.onosproject.net.link.LinkListener; | ||
57 | import org.onosproject.net.link.LinkService; | 47 | import org.onosproject.net.link.LinkService; |
58 | import org.onosproject.net.packet.DefaultOutboundPacket; | 48 | import org.onosproject.net.packet.DefaultOutboundPacket; |
59 | import org.onosproject.net.packet.InboundPacket; | 49 | import org.onosproject.net.packet.InboundPacket; |
... | @@ -64,14 +54,13 @@ import org.slf4j.Logger; | ... | @@ -64,14 +54,13 @@ import org.slf4j.Logger; |
64 | 54 | ||
65 | import java.nio.ByteBuffer; | 55 | import java.nio.ByteBuffer; |
66 | import java.util.HashSet; | 56 | import java.util.HashSet; |
67 | -import java.util.List; | ||
68 | -import java.util.Map.Entry; | ||
69 | import java.util.Set; | 57 | import java.util.Set; |
58 | +import java.util.stream.Collectors; | ||
70 | 59 | ||
71 | import static com.google.common.base.Preconditions.checkArgument; | 60 | import static com.google.common.base.Preconditions.checkArgument; |
72 | import static com.google.common.base.Preconditions.checkNotNull; | 61 | import static com.google.common.base.Preconditions.checkNotNull; |
73 | -import static org.slf4j.LoggerFactory.getLogger; | ||
74 | import static org.onosproject.security.AppGuard.checkPermission; | 62 | import static org.onosproject.security.AppGuard.checkPermission; |
63 | +import static org.slf4j.LoggerFactory.getLogger; | ||
75 | 64 | ||
76 | 65 | ||
77 | @Component(immediate = true) | 66 | @Component(immediate = true) |
... | @@ -87,6 +76,9 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -87,6 +76,9 @@ public class ProxyArpManager implements ProxyArpService { |
87 | private static final String NOT_ARP_REPLY = "ARP is not a reply."; | 76 | private static final String NOT_ARP_REPLY = "ARP is not a reply."; |
88 | 77 | ||
89 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 78 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
79 | + protected EdgePortService edgeService; | ||
80 | + | ||
81 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
90 | protected HostService hostService; | 82 | protected HostService hostService; |
91 | 83 | ||
92 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 84 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
... | @@ -98,29 +90,18 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -98,29 +90,18 @@ public class ProxyArpManager implements ProxyArpService { |
98 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 90 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
99 | protected DeviceService deviceService; | 91 | protected DeviceService deviceService; |
100 | 92 | ||
101 | - private final Multimap<Device, PortNumber> internalPorts = HashMultimap.create(); | ||
102 | - private final Multimap<Device, PortNumber> externalPorts = HashMultimap.create(); | ||
103 | - | ||
104 | - private final DeviceListener deviceListener = new InternalDeviceListener(); | ||
105 | - private final InternalLinkListener linkListener = new InternalLinkListener(); | ||
106 | - | ||
107 | /** | 93 | /** |
108 | * Listens to both device service and link service to determine | 94 | * Listens to both device service and link service to determine |
109 | * whether a port is internal or external. | 95 | * whether a port is internal or external. |
110 | */ | 96 | */ |
111 | @Activate | 97 | @Activate |
112 | public void activate() { | 98 | public void activate() { |
113 | - deviceService.addListener(deviceListener); | ||
114 | - linkService.addListener(linkListener); | ||
115 | - determinePortLocations(); | ||
116 | log.info("Started"); | 99 | log.info("Started"); |
117 | } | 100 | } |
118 | 101 | ||
119 | 102 | ||
120 | @Deactivate | 103 | @Deactivate |
121 | public void deactivate() { | 104 | public void deactivate() { |
122 | - deviceService.removeListener(deviceListener); | ||
123 | - linkService.removeListener(linkListener); | ||
124 | log.info("Stopped"); | 105 | log.info("Stopped"); |
125 | } | 106 | } |
126 | 107 | ||
... | @@ -243,7 +224,7 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -243,7 +224,7 @@ public class ProxyArpManager implements ProxyArpService { |
243 | for (InterfaceIpAddress ia : addresses.ipAddresses()) { | 224 | for (InterfaceIpAddress ia : addresses.ipAddresses()) { |
244 | if (ia.ipAddress().equals(targetAddress)) { | 225 | if (ia.ipAddress().equals(targetAddress)) { |
245 | Ethernet ndpReply = | 226 | Ethernet ndpReply = |
246 | - buildNdpReply(targetAddress, addresses.mac(), eth); | 227 | + buildNdpReply(targetAddress, addresses.mac(), eth); |
247 | sendTo(ndpReply, inPort); | 228 | sendTo(ndpReply, inPort); |
248 | } | 229 | } |
249 | } | 230 | } |
... | @@ -303,16 +284,16 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -303,16 +284,16 @@ public class ProxyArpManager implements ProxyArpService { |
303 | Ethernet ndpReply = buildNdpReply(targetAddress, dst.mac(), eth); | 284 | Ethernet ndpReply = buildNdpReply(targetAddress, dst.mac(), eth); |
304 | sendTo(ndpReply, inPort); | 285 | sendTo(ndpReply, inPort); |
305 | } | 286 | } |
287 | + //TODO checkpoint | ||
306 | 288 | ||
307 | /** | 289 | /** |
308 | * Outputs the given packet out the given port. | 290 | * Outputs the given packet out the given port. |
309 | * | 291 | * |
310 | - * @param packet the packet to send | 292 | + * @param packet the packet to send |
311 | * @param outPort the port to send it out | 293 | * @param outPort the port to send it out |
312 | */ | 294 | */ |
313 | private void sendTo(Ethernet packet, ConnectPoint outPort) { | 295 | private void sendTo(Ethernet packet, ConnectPoint outPort) { |
314 | - if (internalPorts.containsEntry( | 296 | + if (!edgeService.isEdgePoint(outPort)) { |
315 | - deviceService.getDevice(outPort.deviceId()), outPort.port())) { | ||
316 | // Sanity check to make sure we don't send the packet out an | 297 | // Sanity check to make sure we don't send the packet out an |
317 | // internal port and create a loop (could happen due to | 298 | // internal port and create a loop (could happen due to |
318 | // misconfiguration). | 299 | // misconfiguration). |
... | @@ -332,13 +313,10 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -332,13 +313,10 @@ public class ProxyArpManager implements ProxyArpService { |
332 | * @return a set of PortAddresses describing ports in the subnet | 313 | * @return a set of PortAddresses describing ports in the subnet |
333 | */ | 314 | */ |
334 | private Set<PortAddresses> findPortsInSubnet(IpAddress target) { | 315 | private Set<PortAddresses> findPortsInSubnet(IpAddress target) { |
335 | - Set<PortAddresses> result = new HashSet<PortAddresses>(); | 316 | + Set<PortAddresses> result = new HashSet<>(); |
336 | for (PortAddresses addresses : hostService.getAddressBindings()) { | 317 | for (PortAddresses addresses : hostService.getAddressBindings()) { |
337 | - for (InterfaceIpAddress ia : addresses.ipAddresses()) { | 318 | + result.addAll(addresses.ipAddresses().stream().filter(ia -> ia.subnetAddress().contains(target)). |
338 | - if (ia.subnetAddress().contains(target)) { | 319 | + map(ia -> addresses).collect(Collectors.toList())); |
339 | - result.add(addresses); | ||
340 | - } | ||
341 | - } | ||
342 | } | 320 | } |
343 | return result; | 321 | return result; |
344 | } | 322 | } |
... | @@ -432,71 +410,30 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -432,71 +410,30 @@ public class ProxyArpManager implements ProxyArpService { |
432 | * Flood the arp request at all edges in the network. | 410 | * Flood the arp request at all edges in the network. |
433 | * | 411 | * |
434 | * @param request the arp request | 412 | * @param request the arp request |
435 | - * @param inPort the connect point the arp request was received on | 413 | + * @param inPort the connect point the arp request was received on |
436 | */ | 414 | */ |
437 | private void flood(Ethernet request, ConnectPoint inPort) { | 415 | private void flood(Ethernet request, ConnectPoint inPort) { |
438 | TrafficTreatment.Builder builder = null; | 416 | TrafficTreatment.Builder builder = null; |
439 | ByteBuffer buf = ByteBuffer.wrap(request.serialize()); | 417 | ByteBuffer buf = ByteBuffer.wrap(request.serialize()); |
440 | 418 | ||
441 | - synchronized (externalPorts) { | 419 | + for (ConnectPoint connectPoint : edgeService.getEdgePoints()) { |
442 | - for (Entry<Device, PortNumber> entry : externalPorts.entries()) { | 420 | + if (isOutsidePort(connectPoint) || connectPoint.equals(inPort)) { |
443 | - ConnectPoint cp = new ConnectPoint(entry.getKey().id(), entry.getValue()); | 421 | + continue; |
444 | - if (isOutsidePort(cp) || cp.equals(inPort)) { | ||
445 | - continue; | ||
446 | - } | ||
447 | - | ||
448 | - builder = DefaultTrafficTreatment.builder(); | ||
449 | - builder.setOutput(entry.getValue()); | ||
450 | - packetService.emit(new DefaultOutboundPacket(entry.getKey().id(), | ||
451 | - builder.build(), buf)); | ||
452 | } | 422 | } |
453 | - } | ||
454 | - } | ||
455 | 423 | ||
456 | - /** | 424 | + builder = DefaultTrafficTreatment.builder(); |
457 | - * Determines the location of all known ports in the system. | 425 | + builder.setOutput(connectPoint.port()); |
458 | - */ | 426 | + packetService.emit(new DefaultOutboundPacket(connectPoint.deviceId(), |
459 | - private void determinePortLocations() { | 427 | + builder.build(), buf)); |
460 | - Iterable<Device> devices = deviceService.getDevices(); | ||
461 | - Iterable<Link> links = null; | ||
462 | - List<PortNumber> ports = null; | ||
463 | - for (Device d : devices) { | ||
464 | - ports = buildPortNumberList(deviceService.getPorts(d.id())); | ||
465 | - links = linkService.getLinks(); | ||
466 | - for (Link l : links) { | ||
467 | - // for each link, mark the concerned ports as internal | ||
468 | - // and the remaining ports are therefore external. | ||
469 | - if (l.src().deviceId().equals(d.id()) | ||
470 | - && ports.contains(l.src().port())) { | ||
471 | - ports.remove(l.src().port()); | ||
472 | - internalPorts.put(d, l.src().port()); | ||
473 | - } | ||
474 | - if (l.dst().deviceId().equals(d.id()) | ||
475 | - && ports.contains(l.dst().port())) { | ||
476 | - ports.remove(l.dst().port()); | ||
477 | - internalPorts.put(d, l.dst().port()); | ||
478 | - } | ||
479 | - } | ||
480 | - synchronized (externalPorts) { | ||
481 | - externalPorts.putAll(d, ports); | ||
482 | - } | ||
483 | } | 428 | } |
484 | 429 | ||
485 | } | 430 | } |
486 | 431 | ||
487 | - private List<PortNumber> buildPortNumberList(List<Port> ports) { | ||
488 | - List<PortNumber> portNumbers = Lists.newLinkedList(); | ||
489 | - for (Port p : ports) { | ||
490 | - portNumbers.add(p.number()); | ||
491 | - } | ||
492 | - return portNumbers; | ||
493 | - } | ||
494 | - | ||
495 | /** | 432 | /** |
496 | * Builds an Neighbor Discovery reply based on a request. | 433 | * Builds an Neighbor Discovery reply based on a request. |
497 | * | 434 | * |
498 | - * @param srcIp the IP address to use as the reply source | 435 | + * @param srcIp the IP address to use as the reply source |
499 | - * @param srcMac the MAC address to use as the reply source | 436 | + * @param srcMac the MAC address to use as the reply source |
500 | * @param request the Neighbor Solicitation request we got | 437 | * @param request the Neighbor Solicitation request we got |
501 | * @return an Ethernet frame containing the Neighbor Advertisement reply | 438 | * @return an Ethernet frame containing the Neighbor Advertisement reply |
502 | */ | 439 | */ |
... | @@ -524,91 +461,11 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -524,91 +461,11 @@ public class ProxyArpManager implements ProxyArpService { |
524 | nadv.setSolicitedFlag((byte) 1); | 461 | nadv.setSolicitedFlag((byte) 1); |
525 | nadv.setOverrideFlag((byte) 1); | 462 | nadv.setOverrideFlag((byte) 1); |
526 | nadv.addOption(NeighborDiscoveryOptions.TYPE_TARGET_LL_ADDRESS, | 463 | nadv.addOption(NeighborDiscoveryOptions.TYPE_TARGET_LL_ADDRESS, |
527 | - srcMac.toBytes()); | 464 | + srcMac.toBytes()); |
528 | 465 | ||
529 | icmp6.setPayload(nadv); | 466 | icmp6.setPayload(nadv); |
530 | ipv6.setPayload(icmp6); | 467 | ipv6.setPayload(icmp6); |
531 | eth.setPayload(ipv6); | 468 | eth.setPayload(ipv6); |
532 | return eth; | 469 | return eth; |
533 | } | 470 | } |
534 | - | ||
535 | - public class InternalLinkListener implements LinkListener { | ||
536 | - | ||
537 | - @Override | ||
538 | - public void event(LinkEvent event) { | ||
539 | - Link link = event.subject(); | ||
540 | - Device src = deviceService.getDevice(link.src().deviceId()); | ||
541 | - Device dst = deviceService.getDevice(link.dst().deviceId()); | ||
542 | - switch (event.type()) { | ||
543 | - case LINK_ADDED: | ||
544 | - synchronized (externalPorts) { | ||
545 | - externalPorts.remove(src, link.src().port()); | ||
546 | - externalPorts.remove(dst, link.dst().port()); | ||
547 | - internalPorts.put(src, link.src().port()); | ||
548 | - internalPorts.put(dst, link.dst().port()); | ||
549 | - } | ||
550 | - | ||
551 | - break; | ||
552 | - case LINK_REMOVED: | ||
553 | - synchronized (externalPorts) { | ||
554 | - externalPorts.put(src, link.src().port()); | ||
555 | - externalPorts.put(dst, link.dst().port()); | ||
556 | - internalPorts.remove(src, link.src().port()); | ||
557 | - internalPorts.remove(dst, link.dst().port()); | ||
558 | - } | ||
559 | - | ||
560 | - break; | ||
561 | - case LINK_UPDATED: | ||
562 | - // don't care about links being updated. | ||
563 | - break; | ||
564 | - default: | ||
565 | - break; | ||
566 | - } | ||
567 | - | ||
568 | - } | ||
569 | - | ||
570 | - } | ||
571 | - | ||
572 | - public class InternalDeviceListener implements DeviceListener { | ||
573 | - | ||
574 | - @Override | ||
575 | - public void event(DeviceEvent event) { | ||
576 | - Device device = event.subject(); | ||
577 | - switch (event.type()) { | ||
578 | - case DEVICE_ADDED: | ||
579 | - case DEVICE_AVAILABILITY_CHANGED: | ||
580 | - case DEVICE_SUSPENDED: | ||
581 | - case DEVICE_UPDATED: | ||
582 | - // nothing to do in these cases; handled when links get reported | ||
583 | - break; | ||
584 | - case DEVICE_REMOVED: | ||
585 | - synchronized (externalPorts) { | ||
586 | - externalPorts.removeAll(device); | ||
587 | - internalPorts.removeAll(device); | ||
588 | - } | ||
589 | - break; | ||
590 | - case PORT_ADDED: | ||
591 | - case PORT_UPDATED: | ||
592 | - synchronized (externalPorts) { | ||
593 | - if (event.port().isEnabled()) { | ||
594 | - externalPorts.put(device, event.port().number()); | ||
595 | - internalPorts.remove(device, event.port().number()); | ||
596 | - } | ||
597 | - } | ||
598 | - break; | ||
599 | - case PORT_REMOVED: | ||
600 | - synchronized (externalPorts) { | ||
601 | - externalPorts.remove(device, event.port().number()); | ||
602 | - internalPorts.remove(device, event.port().number()); | ||
603 | - } | ||
604 | - break; | ||
605 | - default: | ||
606 | - break; | ||
607 | - | ||
608 | - } | ||
609 | - | ||
610 | - } | ||
611 | - | ||
612 | - } | ||
613 | - | ||
614 | } | 471 | } | ... | ... |
... | @@ -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 | } | ... | ... |
-
Please register or login to post a comment