Refactored HostArpRequester to be a private inner class of ProxyArpManager and removed the clumsy sendArpReply method in the IProxyArpService interface which was needed to support the old arrangement
diff --git a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ArpCache.java b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ArpCache.java
index 8b9c65a..4af4b05 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ArpCache.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ArpCache.java
@@ -14,7 +14,6 @@
* Mappings time out after a short period of time (currently 1 min). We don't
* try and refresh the mapping before the entry times out because as a controller
* we don't know if the mapping is still needed.
- *
*/
/* TODO clean out old ARP entries out of the cache periodically. We currently
diff --git a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/HostArpRequester.java b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/HostArpRequester.java
deleted file mode 100644
index fd30574..0000000
--- a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/HostArpRequester.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package net.onrc.onos.ofcontroller.proxyarp;
-
-import java.net.InetAddress;
-
-import net.floodlightcontroller.packet.ARP;
-import net.floodlightcontroller.util.MACAddress;
-
-public class HostArpRequester implements IArpRequester {
-
- private IProxyArpService arpService;
- private ARP arpRequest;
- private long dpid;
- private short port;
-
- public HostArpRequester(IProxyArpService arpService, ARP arpRequest,
- long dpid, short port) {
-
- this.arpService = arpService;
- this.arpRequest = arpRequest;
- this.dpid = dpid;
- this.port = port;
- }
-
- @Override
- public void arpResponse(InetAddress ipAddress, MACAddress macAddress) {
- arpService.sendArpReply(arpRequest, dpid, port, macAddress);
- }
-
-}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/IProxyArpService.java b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/IProxyArpService.java
index 7dde89b..2c5dd72 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/IProxyArpService.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/IProxyArpService.java
@@ -2,25 +2,11 @@
import java.net.InetAddress;
-import net.floodlightcontroller.packet.ARP;
import net.floodlightcontroller.util.MACAddress;
public interface IProxyArpService {
-
- public final int ARP_REQUEST_TIMEOUT = 2000; //ms
-
/**
- * Tell the IProxyArpService to send an ARP reply with the targetMac to
- * the host on the specified switchport.
- * @param arpRequest
- * @param dpid
- * @param port
- * @param targetMac
- */
- public void sendArpReply(ARP arpRequest, long dpid, short port, MACAddress targetMac);
-
- /**
- * Returns the mac address if there is a valid entry in the cache.
+ * Returns the MAC address if there is a valid entry in the cache.
* Otherwise returns null.
* @param ipAddress
* @return
@@ -33,7 +19,6 @@
* @param ipAddress
* @param requester
* @param retry Whether to keep sending requests until the MAC is learnt
- * @return
*/
public void sendArpRequest(InetAddress ipAddress, IArpRequester requester,
boolean retry);
diff --git a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ProxyArpManager.java b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ProxyArpManager.java
index fe16144..10aa87a 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ProxyArpManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ProxyArpManager.java
@@ -44,6 +44,8 @@
private final static Logger log = LoggerFactory.getLogger(ProxyArpManager.class);
private final long ARP_TIMER_PERIOD = 60000; //ms (== 1 min)
+
+ private static final int ARP_REQUEST_TIMEOUT = 2000; //ms
private final IFloodlightProviderService floodlightProvider;
private final ITopologyService topology;
@@ -71,8 +73,7 @@
}
public boolean isExpired() {
- return (System.currentTimeMillis() - requestTime)
- > IProxyArpService.ARP_REQUEST_TIMEOUT;
+ return (System.currentTimeMillis() - requestTime) > ARP_REQUEST_TIMEOUT;
}
public boolean shouldRetry() {
@@ -84,6 +85,23 @@
}
}
+ private class HostArpRequester implements IArpRequester {
+ private final ARP arpRequest;
+ private final long dpid;
+ private final short port;
+
+ public HostArpRequester(ARP arpRequest, long dpid, short port) {
+ this.arpRequest = arpRequest;
+ this.dpid = dpid;
+ this.port = port;
+ }
+
+ @Override
+ public void arpResponse(InetAddress ipAddress, MACAddress macAddress) {
+ ProxyArpManager.this.sendArpReply(arpRequest, dpid, port, macAddress);
+ }
+ }
+
public ProxyArpManager(IFloodlightProviderService floodlightProvider,
ITopologyService topology, ILayer3InfoService layer3){
this.floodlightProvider = floodlightProvider;
@@ -236,7 +254,7 @@
//Record where the request came from so we know where to send the reply
arpRequests.put(target, new ArpRequest(
- new HostArpRequester(this, arp, sw.getId(), pi.getInPort()), false));
+ new HostArpRequester(arp, sw.getId(), pi.getInPort()), false));
//Flood the request out edge ports
sendArpRequestToSwitches(target, pi.getPacketData(), sw.getId(), pi.getInPort());
@@ -450,21 +468,7 @@
}
}
- private String inetAddressToString(byte[] bytes) {
- try {
- return InetAddress.getByAddress(bytes).getHostAddress();
- } catch (UnknownHostException e) {
- log.debug("Invalid IP address", e);
- return "";
- }
- }
-
- /*
- * IProxyArpService methods
- */
-
- @Override
- public void sendArpReply(ARP arpRequest, long dpid, short port, MACAddress targetMac) {
+ private void sendArpReply(ARP arpRequest, long dpid, short port, MACAddress targetMac) {
if (log.isTraceEnabled()) {
log.trace("Sending reply {} => {} to {}", new Object[] {
inetAddressToString(arpRequest.getTargetProtocolAddress()),
@@ -519,6 +523,19 @@
log.error("Failure writing packet out to switch", e);
}
}
+
+ private String inetAddressToString(byte[] bytes) {
+ try {
+ return InetAddress.getByAddress(bytes).getHostAddress();
+ } catch (UnknownHostException e) {
+ log.debug("Invalid IP address", e);
+ return "";
+ }
+ }
+
+ /*
+ * IProxyArpService methods
+ */
@Override
public MACAddress getMacAddress(InetAddress ipAddress) {