Route CLI improvements and bug fixes
Change-Id: I4b4547f578cc053dc150066dadb68b6b2cbb82ee
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/routing/NextHop.java b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/NextHop.java
new file mode 100644
index 0000000..418b02f
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/NextHop.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2016 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.routing;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Describes a routing next hop.
+ */
+public class NextHop {
+
+ private final IpAddress ip;
+ private final MacAddress mac;
+
+ /**
+ * Creates a new next hop.
+ *
+ * @param ip IP address
+ * @param mac MAC address
+ */
+ public NextHop(IpAddress ip, MacAddress mac) {
+ this.ip = ip;
+ this.mac = mac;
+ }
+
+ /**
+ * Returns the IP address of the next hop.
+ *
+ * @return IP address
+ */
+ public IpAddress ip() {
+ return ip;
+ }
+
+ /**
+ * Returns the MAC address of the next hop.
+ *
+ * @return MAC address
+ */
+ public MacAddress mac() {
+ return mac;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(ip, mac);
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+
+ if (!(other instanceof NextHop)) {
+ return false;
+ }
+
+ NextHop that = (NextHop) other;
+
+ return Objects.equals(this.ip, that.mac) &&
+ Objects.equals(this.ip, that.mac);
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("ip", ip)
+ .add("mac", mac)
+ .toString();
+ }
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/routing/ResolvedRoute.java b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/ResolvedRoute.java
index e473530..7a47ead 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/routing/ResolvedRoute.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/ResolvedRoute.java
@@ -20,6 +20,8 @@
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
+import static com.google.common.base.MoreObjects.toStringHelper;
+
/**
* Represents a route with the next hop MAC address resolved.
*/
@@ -80,4 +82,13 @@
public MacAddress nextHopMac() {
return nextHopMac;
}
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("prefix", prefix)
+ .add("nextHop", nextHop)
+ .add("nextHopMac", nextHopMac)
+ .toString();
+ }
}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/routing/Route.java b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/Route.java
index c1cccc3..0ae4952 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/routing/Route.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/Route.java
@@ -21,6 +21,7 @@
import java.util.Objects;
+import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -70,7 +71,8 @@
*/
public Route(Source source, IpPrefix prefix, IpAddress nextHop) {
checkNotNull(prefix);
- checkArgument(nextHop == null || prefix.version().equals(nextHop.version()), VERSION_MISMATCH);
+ checkNotNull(nextHop);
+ checkArgument(prefix.version().equals(nextHop.version()), VERSION_MISMATCH);
this.source = checkNotNull(source);
this.prefix = prefix;
@@ -124,4 +126,12 @@
return Objects.equals(this.prefix, that.prefix) &&
Objects.equals(this.nextHop, that.nextHop);
}
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("prefix", prefix)
+ .add("nextHop", nextHop)
+ .toString();
+ }
}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteService.java b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteService.java
index bab595a..4fd99d4 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteService.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteService.java
@@ -21,6 +21,7 @@
import java.util.Collection;
import java.util.Map;
+import java.util.Set;
/**
* Unicast IP route service.
@@ -44,4 +45,19 @@
*/
Route longestPrefixMatch(IpAddress ip);
+ /**
+ * Returns the routes for the given next hop.
+ *
+ * @param nextHop next hop IP address
+ * @return routes for this next hop
+ */
+ Collection<Route> getRoutesForNextHop(IpAddress nextHop);
+
+ /**
+ * Returns all next hops in the route store.
+ *
+ * @return set of next hops
+ */
+ Set<NextHop> getNextHops();
+
}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteStore.java b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteStore.java
index 132afd4..9b75099 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteStore.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteStore.java
@@ -21,6 +21,7 @@
import org.onosproject.store.Store;
import java.util.Collection;
+import java.util.Map;
import java.util.Set;
/**
@@ -66,6 +67,14 @@
Route longestPrefixMatch(IpAddress ip);
/**
+ * Returns the routes that point to the given next hop IP address.
+ *
+ * @param ip IP address of the next hop
+ * @return routes for the given next hop
+ */
+ Collection<Route> getRoutesForNextHop(IpAddress ip);
+
+ /**
* Updates a next hop IP and MAC in the store.
*
* @param ip IP address
@@ -88,4 +97,11 @@
* @return MAC address
*/
MacAddress getNextHop(IpAddress ip);
+
+ /**
+ * Returns all next hops in the route store.
+ *
+ * @return next hops
+ */
+ Map<IpAddress, MacAddress> getNextHops();
}