Reimplemented the ProxyArp app on top of the NeighbourResolutionService.

Also some small API changes to track app ID of handler registrations, and
improved interface matching in NeighbourPacketManager.

Added CLI to view handler registrations.

Change-Id: I8cd0b91a16d9ec60287b65f9d8fc5e3cd87560e8
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/NeighbourHandlerRegistration.java b/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/NeighbourHandlerRegistration.java
new file mode 100644
index 0000000..cc800a3
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/NeighbourHandlerRegistration.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.incubator.net.neighbour;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.incubator.net.intf.Interface;
+
+/**
+ * Information about the registration of a neighbour message handler.
+ */
+public interface NeighbourHandlerRegistration {
+
+    /**
+     * Gets the interface of the registration.
+     *
+     * @return interface
+     */
+    Interface intf();
+
+    /**
+     * Gets the neighbour message handler.
+     *
+     * @return message handler
+     */
+    NeighbourMessageHandler handler();
+
+    /**
+     * Gets the ID of the application that registered the handler.
+     *
+     * @return application ID
+     */
+    ApplicationId appId();
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/NeighbourMessageContext.java b/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/NeighbourMessageContext.java
index f498f17..0c609ae 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/NeighbourMessageContext.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/NeighbourMessageContext.java
@@ -76,6 +76,16 @@
     MacAddress srcMac();
 
     /**
+     * Gets the destination MAC address of the message.
+     * <p>
+     * Only valid for reply packets, will be null for request packets.
+     * </p>
+     *
+     * @return target MAC address
+     */
+    MacAddress dstMac();
+
+    /**
      * Gets the target IP address of the message.
      *
      * @return target IP address
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/NeighbourResolutionService.java b/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/NeighbourResolutionService.java
index 94401cc..4e4adb9 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/NeighbourResolutionService.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/NeighbourResolutionService.java
@@ -17,9 +17,13 @@
 package org.onosproject.incubator.net.neighbour;
 
 import com.google.common.annotations.Beta;
+import org.onosproject.core.ApplicationId;
 import org.onosproject.incubator.net.intf.Interface;
 import org.onosproject.net.ConnectPoint;
 
+import java.util.Collection;
+import java.util.Map;
+
 /**
  * Provides a means of registering logic for handling neighbour messages.
  */
@@ -32,8 +36,10 @@
      *
      * @param connectPoint connect point
      * @param handler neighbour message handler
+     * @param appId application ID
      */
-    void registerNeighbourHandler(ConnectPoint connectPoint, NeighbourMessageHandler handler);
+    void registerNeighbourHandler(ConnectPoint connectPoint, NeighbourMessageHandler handler,
+                                  ApplicationId appId);
 
     /**
      * Registers a neighbour message handler for all neighbour messages incoming
@@ -42,8 +48,10 @@
      *
      * @param intf interface
      * @param handler neighbour message handler
+     * @param appId application ID
      */
-    void registerNeighbourHandler(Interface intf, NeighbourMessageHandler handler);
+    void registerNeighbourHandler(Interface intf, NeighbourMessageHandler handler,
+                                  ApplicationId appId);
 
     /**
      * Unregisters a neighbour message handler that was assigned to a connect
@@ -51,14 +59,34 @@
      *
      * @param connectPoint connect point
      * @param handler neighbour message handler
+     * @param appId application ID
      */
-    void unregisterNeighbourHandler(ConnectPoint connectPoint, NeighbourMessageHandler handler);
+    void unregisterNeighbourHandler(ConnectPoint connectPoint, NeighbourMessageHandler handler,
+                                    ApplicationId appId);
 
     /**
      * Unregisters a neighbour message handler that was assigned to an interface.
      *
      * @param intf interface
      * @param handler neighbour message handler
+     * @param appId application ID
      */
-    void unregisterNeighbourHandler(Interface intf, NeighbourMessageHandler handler);
+    void unregisterNeighbourHandler(Interface intf, NeighbourMessageHandler handler,
+                                    ApplicationId appId);
+
+    /**
+     * Unregisters all neighbour handlers that were registered by the given
+     * application.
+     *
+     * @param appId application ID
+     */
+    void unregisterNeighbourHandlers(ApplicationId appId);
+
+    /**
+     * Gets the neighbour message handlers that have been registered with the
+     * service.
+     *
+     * @return neighbour message handlers indexed by connect point
+     */
+    Map<ConnectPoint, Collection<NeighbourHandlerRegistration>> getHandlerRegistrations();
 }