Implementation of the NeighbourResolutionService.
Change-Id: I41fc48578df3027ec71ee7369171c8988ee7a85e
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/DefaultNeighbourMessageHandler.java b/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/DefaultNeighbourMessageHandler.java
index 3686c47..86fb848 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/DefaultNeighbourMessageHandler.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/neighbour/DefaultNeighbourMessageHandler.java
@@ -21,36 +21,54 @@
import java.util.Set;
+import static org.onlab.packet.VlanId.vlanId;
import static org.onosproject.net.HostId.hostId;
/**
- * Default neighbour message handler which implements basic proxying on a flat
+ * Default neighbour message handler which implements basic proxying on an
* L2 network (i.e. ProxyArp behaviour).
*/
public class DefaultNeighbourMessageHandler implements NeighbourMessageHandler {
@Override
public void handleMessage(NeighbourMessageContext context, HostService hostService) {
- // See if we have the target host in the host store
- Set<Host> hosts = hostService.getHostsByIp(context.target());
+ switch (context.type()) {
+ case REPLY:
+ Host h = hostService.getHost(hostId(context.packet().getDestinationMAC(),
+ vlanId(context.packet().getVlanID())));
- Host dst = null;
- Host src = hostService.getHost(hostId(context.srcMac(), context.vlan()));
-
- for (Host host : hosts) {
- if (host.vlan().equals(context.vlan())) {
- dst = host;
- break;
+ if (h == null) {
+ context.flood();
+ } else {
+ context.proxy(h.location());
}
+ break;
+ case REQUEST:
+ // See if we have the target host in the host store
+ Set<Host> hosts = hostService.getHostsByIp(context.target());
+
+ Host dst = null;
+ Host src = hostService.getHost(hostId(context.srcMac(), context.vlan()));
+
+ for (Host host : hosts) {
+ if (host.vlan().equals(context.vlan())) {
+ dst = host;
+ break;
+ }
+ }
+
+ if (src != null && dst != null) {
+ // We know the target host so we can respond
+ context.reply(dst.mac());
+ return;
+ }
+
+ // The request couldn't be resolved.
+ // Flood the request on all ports except the incoming port.
+ context.flood();
+ break;
+ default:
+ break;
}
- if (src != null && dst != null) {
- // We know the target host so we can respond
- context.reply(dst.mac());
- return;
- }
-
- // The request couldn't be resolved.
- // Flood the request on all ports except the incoming port.
- context.flood();
}
}
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 307a783..f498f17 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
@@ -24,8 +24,6 @@
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.net.ConnectPoint;
-import static com.google.common.base.Preconditions.checkState;
-
/**
* Context of an incoming neighbor message (e.g. ARP, NDP).
*
@@ -34,156 +32,91 @@
* response to the incoming message.</p>
*/
@Beta
-public class NeighbourMessageContext {
-
- private final NeighbourProtocol protocol;
- private final NeighbourMessageType type;
-
- private final IpAddress target;
- private final IpAddress sender;
-
- private final Ethernet eth;
- private final ConnectPoint inPort;
-
- private final NeighbourMessageActions actions;
-
- /**
- * Creates a new neighbour message context.
- *
- * @param actions actions
- * @param eth ethernet frame
- * @param inPort incoming port
- * @param protocol message protocol
- * @param type message type
- * @param target target IP address
- * @param sender sender IP address
- */
- public NeighbourMessageContext(NeighbourMessageActions actions,
- Ethernet eth, ConnectPoint inPort,
- NeighbourProtocol protocol, NeighbourMessageType type,
- IpAddress target, IpAddress sender) {
- this.actions = actions;
- this.eth = eth;
- this.inPort = inPort;
- this.protocol = protocol;
- this.type = type;
- this.target = target;
- this.sender = sender;
- }
-
+public interface NeighbourMessageContext {
/**
* Gets the port where the packet came in to the network.
*
* @return connect point
*/
- public ConnectPoint inPort() {
- return inPort;
- }
+ ConnectPoint inPort();
/**
* Gets the full parsed representation of the packet.
*
* @return ethernet header
*/
- public Ethernet packet() {
- return eth;
- }
+ Ethernet packet();
/**
* Gets the protocol of the packet.
*
* @return protocol
*/
- public NeighbourProtocol protocol() {
- return protocol;
- }
+ NeighbourProtocol protocol();
/**
* Gets the message type of the packet.
*
* @return message type
*/
- public NeighbourMessageType type() {
- return type;
- }
+ NeighbourMessageType type();
/**
* Gets the vlan of the packet, if any.
*
* @return vlan
*/
- public VlanId vlan() {
- return VlanId.vlanId(eth.getVlanID());
- }
+ VlanId vlan();
/**
* Gets the source MAC address of the message.
*
* @return source MAC address
*/
- public MacAddress srcMac() {
- return MacAddress.valueOf(eth.getSourceMACAddress());
- }
+ MacAddress srcMac();
/**
* Gets the target IP address of the message.
*
* @return target IP address
*/
- public IpAddress target() {
- return target;
- }
+ IpAddress target();
/**
* Gets the source IP address of the message.
*
* @return source IP address
*/
- public IpAddress sender() {
- return sender;
- }
+ IpAddress sender();
/**
* Proxies the message to a given output port.
*
* @param outPort output port
*/
- public void proxy(ConnectPoint outPort) {
- actions.proxy(this, outPort);
- }
+ void proxy(ConnectPoint outPort);
/**
* Proxies the message to a given interface.
*
* @param outIntf output interface
*/
- public void proxy(Interface outIntf) {
- actions.proxy(this, outIntf);
- }
+ void proxy(Interface outIntf);
/**
* Replies to the request message with a given MAC address.
*
* @param targetMac target MAC address
*/
- public void reply(MacAddress targetMac) {
- checkState(type == NeighbourMessageType.REQUEST, "can only reply to requests");
-
- actions.reply(this, targetMac);
- }
+ void reply(MacAddress targetMac);
/**
* Floods the incoming message out all ports except the input port.
*/
- public void flood() {
- actions.flood(this);
- }
+ void flood();
/**
* Drops the incoming message.
*/
- public void drop() {
- actions.drop(this);
- }
-
+ void drop();
}
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 f7adb04..94401cc 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
@@ -45,4 +45,20 @@
*/
void registerNeighbourHandler(Interface intf, NeighbourMessageHandler handler);
+ /**
+ * Unregisters a neighbour message handler that was assigned to a connect
+ * point.
+ *
+ * @param connectPoint connect point
+ * @param handler neighbour message handler
+ */
+ void unregisterNeighbourHandler(ConnectPoint connectPoint, NeighbourMessageHandler handler);
+
+ /**
+ * Unregisters a neighbour message handler that was assigned to an interface.
+ *
+ * @param intf interface
+ * @param handler neighbour message handler
+ */
+ void unregisterNeighbourHandler(Interface intf, NeighbourMessageHandler handler);
}