Modify proxy arp for mwc demo

Change-Id: I613f82a2e829ae24441875270880a06386b2d8a7
diff --git a/apps/proxyarp/src/main/java/org/onosproject/proxyarp/DefaultProxyArp.java b/apps/proxyarp/src/main/java/org/onosproject/proxyarp/DefaultProxyArp.java
index d8095bb..4f02787 100644
--- a/apps/proxyarp/src/main/java/org/onosproject/proxyarp/DefaultProxyArp.java
+++ b/apps/proxyarp/src/main/java/org/onosproject/proxyarp/DefaultProxyArp.java
@@ -23,6 +23,7 @@
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
+import org.onosproject.net.intf.InterfaceService;
 import org.onosproject.net.neighbour.DefaultNeighbourMessageHandler;
 import org.onosproject.net.neighbour.NeighbourResolutionService;
 import org.onosproject.net.ConnectPoint;
@@ -52,10 +53,14 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected CoreService coreService;
 
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected InterfaceService interfaceService;
+
     private ApplicationId appId;
 
     private InternalEdgeListener edgeListener = new InternalEdgeListener();
-    private DefaultNeighbourMessageHandler defaultHandler = new DefaultNeighbourMessageHandler();
+    private DefaultNeighbourMessageHandler defaultHandler =
+            new DefaultNeighbourMessageHandler(interfaceService);
 
     @Activate
     protected void activate() {
diff --git a/core/api/src/main/java/org/onosproject/net/neighbour/DefaultNeighbourMessageHandler.java b/core/api/src/main/java/org/onosproject/net/neighbour/DefaultNeighbourMessageHandler.java
index 5f34e9f..dd2f1b2 100644
--- a/core/api/src/main/java/org/onosproject/net/neighbour/DefaultNeighbourMessageHandler.java
+++ b/core/api/src/main/java/org/onosproject/net/neighbour/DefaultNeighbourMessageHandler.java
@@ -16,9 +16,15 @@
 
 package org.onosproject.net.neighbour;
 
+import org.onlab.packet.IpAddress;
+import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.Host;
 import org.onosproject.net.host.HostService;
+import org.onosproject.net.host.InterfaceIpAddress;
+import org.onosproject.net.intf.Interface;
+import org.onosproject.net.intf.InterfaceService;
 
+import java.util.List;
 import java.util.Set;
 
 import static org.onlab.packet.VlanId.vlanId;
@@ -29,6 +35,13 @@
  * L2 network (i.e. ProxyArp behaviour).
  */
 public class DefaultNeighbourMessageHandler implements NeighbourMessageHandler {
+
+    InterfaceService interfaceService;
+
+    public DefaultNeighbourMessageHandler(InterfaceService interfaceService) {
+        this.interfaceService = interfaceService;
+    }
+
     @Override
     public void handleMessage(NeighbourMessageContext context, HostService hostService) {
         switch (context.type()) {
@@ -64,7 +77,19 @@
 
             // The request couldn't be resolved.
             // Flood the request on all ports except the incoming port.
-            context.flood();
+
+            ConnectPoint inPort = context.inPort();
+            Set<Interface> interfaces = interfaceService.getInterfacesByPort(inPort);
+            IpAddress ipAddress = context.target();
+
+            interfaces.stream()
+                    .filter(iface -> {
+                        List<InterfaceIpAddress> ips = iface.ipAddressesList();
+                        return ips.stream().anyMatch(iip -> iip.subnetAddress().contains(ipAddress));
+                    })
+                    .filter(iface -> !iface.connectPoint().equals(inPort))
+                    .forEach(context::forward);
+//            context.flood();
             break;
         default:
             break;