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;