Jonathan Hart
Committed by Gerrit Code Review

ProxyArpManager: Factor out common logic for handling ARP and NDP packets.

Change-Id: I0709f9cda2506f01dbc912b8c3e12443ec217fed
......@@ -82,7 +82,7 @@ public class ProxyArp {
packetService.addProcessor(processor, PacketProcessor.director(1));
readComponentConfiguration(context);
requestPackests();
requestPackets();
log.info("Started with Application ID {}", appId.id());
}
......@@ -99,13 +99,13 @@ public class ProxyArp {
@Modified
public void modified(ComponentContext context) {
readComponentConfiguration(context);
requestPackests();
requestPackets();
}
/**
* Request packet in via PacketService.
*/
private void requestPackests() {
private void requestPackets() {
TrafficSelector.Builder selectorBuilder =
DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(TYPE_ARP);
......
......@@ -21,7 +21,7 @@ import org.onosproject.net.ConnectPoint;
import org.onosproject.net.packet.PacketContext;
/**
* Service for processing arp requests on behalf of applications.
* Service for processing ARP or NDP requests on behalf of applications.
*/
// TODO: move to the peer host package
public interface ProxyArpService {
......
......@@ -33,8 +33,6 @@ import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Host;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.host.HostProvider;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.packet.DefaultOutboundPacket;
......@@ -43,9 +41,7 @@ import org.onosproject.net.packet.PacketService;
import org.onosproject.net.provider.ProviderId;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
......@@ -149,7 +145,7 @@ public class HostMonitor implements TimerTask {
Set<Host> hosts = hostManager.getHostsByIp(ip);
if (hosts.isEmpty()) {
sendArpNdpRequest(ip);
sendRequest(ip);
} else {
for (Host host : hosts) {
HostProvider provider = hostProviders.get(host.providerId());
......@@ -166,12 +162,11 @@ public class HostMonitor implements TimerTask {
}
/**
* Sends an ARP or Neighbor Discovery Protocol request for the given IP
* address.
* Sends an ARP or NDP request for the given IP address.
*
* @param targetIp IP address to send the request for
*/
private void sendArpNdpRequest(IpAddress targetIp) {
private void sendRequest(IpAddress targetIp) {
Interface intf = interfaceService.getMatchingInterface(targetIp);
if (intf == null) {
......@@ -180,13 +175,13 @@ public class HostMonitor implements TimerTask {
for (InterfaceIpAddress ia : intf.ipAddresses()) {
if (ia.subnetAddress().contains(targetIp)) {
sendArpNdpProbe(intf.connectPoint(), targetIp, ia.ipAddress(),
sendProbe(intf.connectPoint(), targetIp, ia.ipAddress(),
intf.mac(), intf.vlan());
}
}
}
private void sendArpNdpProbe(ConnectPoint connectPoint,
private void sendProbe(ConnectPoint connectPoint,
IpAddress targetIp,
IpAddress sourceIp, MacAddress sourceMac,
VlanId vlan) {
......@@ -194,17 +189,12 @@ public class HostMonitor implements TimerTask {
if (targetIp.isIp4()) {
// IPv4: Use ARP
probePacket = buildArpRequest(targetIp, sourceIp, sourceMac,
vlan);
probePacket = buildArpRequest(targetIp, sourceIp, sourceMac, vlan);
} else {
// IPv6: Use Neighbor Discovery
probePacket = buildNdpRequest(targetIp, sourceIp, sourceMac,
vlan);
probePacket = buildNdpRequest(targetIp, sourceIp, sourceMac, vlan);
}
List<Instruction> instructions = new ArrayList<>();
instructions.add(Instructions.createOutput(connectPoint.port()));
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.setOutput(connectPoint.port())
.build();
......@@ -273,7 +263,7 @@ public class HostMonitor implements TimerTask {
icmp6.setIcmpType(ICMP6.NEIGHBOR_SOLICITATION);
icmp6.setIcmpCode((byte) 0);
// Create the Neighbor Solication packet
// Create the Neighbor Solicitation packet
NeighborSolicitation ns = new NeighborSolicitation();
ns.setTargetAddress(targetIp.toOctets());
ns.addOption(NeighborDiscoveryOptions.TYPE_SOURCE_LL_ADDRESS,
......