proxy arp application
Change-Id: Ic2136537a4104e75b64ae4731e1bae4f3a4c1661
diff --git a/apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java b/apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java
index 5857438..1accddb 100644
--- a/apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java
+++ b/apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java
@@ -26,9 +26,7 @@
import org.onlab.onos.net.packet.PacketContext;
import org.onlab.onos.net.packet.PacketProcessor;
import org.onlab.onos.net.packet.PacketService;
-import org.onlab.onos.net.proxyarp.ProxyArpService;
import org.onlab.onos.net.topology.TopologyService;
-import org.onlab.packet.ARP;
import org.onlab.packet.Ethernet;
import org.slf4j.Logger;
@@ -55,9 +53,6 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected FlowRuleService flowRuleService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected ProxyArpService proxyArpService;
-
private ReactivePacketProcessor processor = new ReactivePacketProcessor();
private ApplicationId appId;
@@ -65,7 +60,7 @@
@Activate
public void activate() {
appId = ApplicationId.getAppId();
- packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1);
+ packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2);
log.info("Started with Application ID {}", appId.id());
}
@@ -93,16 +88,6 @@
InboundPacket pkt = context.inPacket();
Ethernet ethPkt = pkt.parsed();
- if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) {
- ARP arp = (ARP) ethPkt.getPayload();
- if (arp.getOpCode() == ARP.OP_REPLY) {
- proxyArpService.forward(ethPkt);
- } else if (arp.getOpCode() == ARP.OP_REQUEST) {
- proxyArpService.reply(ethPkt);
- }
- context.block();
- return;
- }
HostId id = HostId.hostId(ethPkt.getDestinationMAC());
@@ -181,24 +166,24 @@
// We don't yet support bufferids in the flowservice so packet out first.
packetOut(context, portNumber);
- if (context.inPacket().parsed().getEtherType() == Ethernet.TYPE_IPV4) {
- // Install the flow rule to handle this type of message from now on.
- Ethernet inPkt = context.inPacket().parsed();
- TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
- builder.matchEthType(inPkt.getEtherType())
- .matchEthSrc(inPkt.getSourceMAC())
- .matchEthDst(inPkt.getDestinationMAC())
- .matchInport(context.inPacket().receivedFrom().port());
- TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
- treat.setOutput(portNumber);
+ // Install the flow rule to handle this type of message from now on.
+ Ethernet inPkt = context.inPacket().parsed();
+ TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
+ builder.matchEthType(inPkt.getEtherType())
+ .matchEthSrc(inPkt.getSourceMAC())
+ .matchEthDst(inPkt.getDestinationMAC())
+ .matchInport(context.inPacket().receivedFrom().port());
- FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(),
- builder.build(), treat.build(), PRIORITY, appId, TIMEOUT);
+ TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
+ treat.setOutput(portNumber);
- flowRuleService.applyFlowRules(f);
- }
+ FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(),
+ builder.build(), treat.build(), PRIORITY, appId, TIMEOUT);
+
+ flowRuleService.applyFlowRules(f);
+
}
}
diff --git a/apps/pom.xml b/apps/pom.xml
index 010c531..27a1f2f 100644
--- a/apps/pom.xml
+++ b/apps/pom.xml
@@ -21,6 +21,7 @@
<module>fwd</module>
<module>foo</module>
<module>mobility</module>
+ <module>proxyarp</module>
<module>config</module>
</modules>
diff --git a/apps/proxyarp/pom.xml b/apps/proxyarp/pom.xml
new file mode 100644
index 0000000..4051d19
--- /dev/null
+++ b/apps/proxyarp/pom.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-apps</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-app-proxyarp</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>ONOS simple proxy arp module</description>
+
+</project>
diff --git a/apps/proxyarp/src/main/java/org/onlab/onos/proxyarp/ProxyArp.java b/apps/proxyarp/src/main/java/org/onlab/onos/proxyarp/ProxyArp.java
new file mode 100644
index 0000000..a06470f
--- /dev/null
+++ b/apps/proxyarp/src/main/java/org/onlab/onos/proxyarp/ProxyArp.java
@@ -0,0 +1,70 @@
+package org.onlab.onos.proxyarp;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.net.packet.PacketContext;
+import org.onlab.onos.net.packet.PacketProcessor;
+import org.onlab.onos.net.packet.PacketService;
+import org.onlab.onos.net.proxyarp.ProxyArpService;
+import org.slf4j.Logger;
+
+/**
+ * Sample reactive proxy arp application.
+ */
+@Component(immediate = true)
+public class ProxyArp {
+
+
+ private final Logger log = getLogger(getClass());
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected PacketService packetService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ProxyArpService proxyArpService;
+
+ private ProxyArpProcessor processor = new ProxyArpProcessor();
+
+ private ApplicationId appId;
+
+ @Activate
+ public void activate() {
+ appId = ApplicationId.getAppId();
+ packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1);
+ log.info("Started with Application ID {}", appId.id());
+ }
+
+ @Deactivate
+ public void deactivate() {
+ packetService.removeProcessor(processor);
+ processor = null;
+ log.info("Stopped");
+ }
+
+
+ /**
+ * Packet processor responsible for forwarding packets along their paths.
+ */
+ private class ProxyArpProcessor implements PacketProcessor {
+
+ @Override
+ public void process(PacketContext context) {
+ // Stop processing if the packet has been handled, since we
+ // can't do any more to it.
+ if (context.isHandled()) {
+ return;
+ }
+
+ //handle the arp packet.
+ proxyArpService.handleArp(context);
+ }
+ }
+}
+
+
diff --git a/apps/proxyarp/src/main/java/org/onlab/onos/proxyarp/package-info.java b/apps/proxyarp/src/main/java/org/onlab/onos/proxyarp/package-info.java
new file mode 100644
index 0000000..3f7da98
--- /dev/null
+++ b/apps/proxyarp/src/main/java/org/onlab/onos/proxyarp/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Proxy Arp application that handles arp resolution for you.
+ */
+package org.onlab.onos.proxyarp;
diff --git a/core/api/src/main/java/org/onlab/onos/net/proxyarp/ProxyArpService.java b/core/api/src/main/java/org/onlab/onos/net/proxyarp/ProxyArpService.java
index 4ee43c7..77d1208 100644
--- a/core/api/src/main/java/org/onlab/onos/net/proxyarp/ProxyArpService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/proxyarp/ProxyArpService.java
@@ -1,5 +1,6 @@
package org.onlab.onos.net.proxyarp;
+import org.onlab.onos.net.packet.PacketContext;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IpPrefix;
@@ -33,4 +34,12 @@
*/
void forward(Ethernet eth);
+ /**
+ * Handles a arp packet.
+ * Replies to arp requests and forwards request to the right place.
+ * @param context the packet context to handle
+ * @return true if handled, false otherwise.
+ */
+ boolean handleArp(PacketContext context);
+
}
diff --git a/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java b/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
index ae6a81d..182e210 100644
--- a/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
@@ -158,7 +158,7 @@
checkValidity();
FlowRule stored = store.getFlowRule(flowRule);
if (stored == null) {
- log.debug("Rule already evicted from store: {}", flowRule);
+ log.info("Rule already evicted from store: {}", flowRule);
return;
}
Device device = deviceService.getDevice(flowRule.deviceId());
@@ -247,8 +247,12 @@
idleTime.put(swRule, currentTime);
return true;
}
- return (currentTime - idleTime.get(swRule)) <= timeout;
+ if ((currentTime - idleTime.get(swRule)) <= timeout) {
+ idleTime.put(swRule, currentTime);
+ return true;
+ }
+ return false;
}
// Posts the specified event to the local event dispatcher.
diff --git a/core/net/src/main/java/org/onlab/onos/net/proxyarp/impl/ProxyArpManager.java b/core/net/src/main/java/org/onlab/onos/net/proxyarp/impl/ProxyArpManager.java
index 3570948..0da2733 100644
--- a/core/net/src/main/java/org/onlab/onos/net/proxyarp/impl/ProxyArpManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/proxyarp/impl/ProxyArpManager.java
@@ -31,6 +31,8 @@
import org.onlab.onos.net.link.LinkListener;
import org.onlab.onos.net.link.LinkService;
import org.onlab.onos.net.packet.DefaultOutboundPacket;
+import org.onlab.onos.net.packet.InboundPacket;
+import org.onlab.onos.net.packet.PacketContext;
import org.onlab.onos.net.packet.PacketService;
import org.onlab.onos.net.proxyarp.ProxyArpService;
import org.onlab.packet.ARP;
@@ -155,6 +157,23 @@
}
+ @Override
+ public boolean handleArp(PacketContext context) {
+ InboundPacket pkt = context.inPacket();
+ Ethernet ethPkt = pkt.parsed();
+ if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) {
+ ARP arp = (ARP) ethPkt.getPayload();
+ if (arp.getOpCode() == ARP.OP_REPLY) {
+ forward(ethPkt);
+ } else if (arp.getOpCode() == ARP.OP_REQUEST) {
+ reply(ethPkt);
+ }
+ context.block();
+ return true;
+ }
+ return false;
+ }
+
/**
* Flood the arp request at all edges in the network.
* @param request the arp request.
@@ -321,7 +340,6 @@
}
-}
-
+ }
}
diff --git a/features/features.xml b/features/features.xml
index 68fa8c3..0afafec 100644
--- a/features/features.xml
+++ b/features/features.xml
@@ -121,11 +121,17 @@
</feature>
<feature name="onos-app-mobility" version="1.0.0"
- description="ONOS sample forwarding application">
+ description="ONOS sample mobility application">
<feature>onos-api</feature>
<bundle>mvn:org.onlab.onos/onos-app-mobility/1.0.0-SNAPSHOT</bundle>
</feature>
+ <feature name="onos-app-proxyarp" version="1.0.0"
+ description="ONOS sample proxyarp application">
+ <feature>onos-api</feature>
+ <bundle>mvn:org.onlab.onos/onos-app-proxyarp/1.0.0-SNAPSHOT</bundle>
+ </feature>
+
<feature name="onos-app-foo" version="1.0.0"
diff --git a/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowRuleBuilder.java b/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowRuleBuilder.java
index 70727d3..028e857 100644
--- a/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowRuleBuilder.java
+++ b/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowRuleBuilder.java
@@ -82,10 +82,9 @@
// TODO: revisit potentially.
return new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
buildSelector(), null, removed.getPriority(),
- FlowRuleState.REMOVED, stat.getDurationSec(),
+ FlowRuleState.REMOVED, removed.getDurationSec(),
removed.getPacketCount().getValue(), removed.getByteCount().getValue(),
- removed.getCookie().getValue(),
- stat.getIdleTimeout());
+ removed.getCookie().getValue(), removed.getIdleTimeout());
}
}