Implementation of the route service
Change-Id: I4e905cf868ad69c426e4f4155dfd83e1f8b00335
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 857d69b..590b218 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
@@ -70,8 +70,7 @@
*/
public Route(Source source, IpPrefix prefix, IpAddress nextHop) {
checkNotNull(prefix);
- checkNotNull(nextHop);
- checkArgument(prefix.version().equals(nextHop.version()), VERSION_MISMATCH);
+ checkArgument(nextHop == null || prefix.version().equals(nextHop.version()), VERSION_MISMATCH);
this.source = checkNotNull(source);
this.prefix = prefix;
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteAdminService.java b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteAdminService.java
new file mode 100644
index 0000000..da579c5
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteAdminService.java
@@ -0,0 +1,39 @@
+/*
+ * 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 java.util.Collection;
+
+/**
+ * Service allowing mutation of unicast routing state.
+ */
+public interface RouteAdminService extends RouteService {
+
+ /**
+ * Updates the given routes in the route service.
+ *
+ * @param routes collection of routes to update
+ */
+ void update(Collection<Route> routes);
+
+ /**
+ * Withdraws the given routes from the route service.
+ *
+ * @param routes collection of routes to withdraw
+ */
+ void withdraw(Collection<Route> routes);
+}
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 3fd9e69..d4d6892 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
@@ -20,47 +20,28 @@
import org.onosproject.event.ListenerService;
import java.util.Collection;
+import java.util.Map;
/**
- * IP unicast routing service.
+ * Unicast IP route service.
*/
public interface RouteService extends ListenerService<RouteEvent, RouteListener> {
/**
- * Gets all routes.
+ * Returns all routes for all route tables in the system.
*
- * @return collection of all routes
+ * @return map of route table name to routes in that table
*/
- Collection<Route> getRoutes();
+ Map<RouteTableId, Collection<Route>> getAllRoutes();
/**
- * Gets routes learnt from a particular source.
+ * Performs a longest prefix match on the given IP address. The call will
+ * return the route with the most specific prefix that contains the given
+ * IP address.
*
- * @param source route source
- * @return collection of routes
- */
- Collection<Route> getRoutesFromSource(Route.Source source);
-
- /**
- * Gets the longest prefix route that matches the given IP address.
- *
- * @param ip IP addres
+ * @param ip IP address
* @return longest prefix matched route
*/
Route longestPrefixMatch(IpAddress ip);
- //TODO should mutation methods be pushed to a different interface?
- /**
- * Updates the given routes in the route service.
- *
- * @param routes collection of routes to update
- */
- void update(Collection<Route> routes);
-
- /**
- * Withdraws the given routes from the route service.
- *
- * @param routes collection of routes to withdraw
- */
- void withdraw(Collection<Route> routes);
}
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
new file mode 100644
index 0000000..1905d1b
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteStore.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 org.onosproject.store.Store;
+
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * Unicast route store.
+ */
+public interface RouteStore extends Store<RouteEvent, RouteStoreDelegate> {
+
+ /**
+ * Adds or updates the given route in the store.
+ *
+ * @param route route to add or update
+ */
+ void updateRoute(Route route);
+
+ /**
+ * Removes the given route from the store.
+ *
+ * @param route route to remove
+ */
+ void removeRoute(Route route);
+
+ /**
+ * Returns the IDs for all route tables in the store.
+ *
+ * @return route table IDs
+ */
+ Set<RouteTableId> getRouteTables();
+
+ /**
+ * Returns the routes for a particular route table.
+ *
+ * @param table route table
+ * @return collection of route in the table
+ */
+ Collection<Route> getRoutes(RouteTableId table);
+
+ /**
+ * Performs a longest prefix match with the given IP address.
+ *
+ * @param ip IP to look up
+ * @return longest prefix match route
+ */
+ Route longestPrefixMatch(IpAddress ip);
+
+ /**
+ * Updates a next hop IP and MAC in the store.
+ *
+ * @param ip IP address
+ * @param mac MAC address
+ */
+ void updateNextHop(IpAddress ip, MacAddress mac);
+
+ /**
+ * Removes a next hop IP and MAC from the store.
+ *
+ * @param ip IP address
+ * @param mac MAC address
+ */
+ void removeNextHop(IpAddress ip, MacAddress mac);
+
+ /**
+ * Returns the MAC address of the given next hop.
+ *
+ * @param ip next hop IP
+ * @return MAC address
+ */
+ MacAddress getNextHop(IpAddress ip);
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteStoreDelegate.java b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteStoreDelegate.java
new file mode 100644
index 0000000..b79b483
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteStoreDelegate.java
@@ -0,0 +1,25 @@
+/*
+ * 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.onosproject.store.StoreDelegate;
+
+/**
+ * Route store delegate abstraction.
+ */
+public interface RouteStoreDelegate extends StoreDelegate<RouteEvent> {
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteTableId.java b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteTableId.java
new file mode 100644
index 0000000..1a8bccb
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/routing/RouteTableId.java
@@ -0,0 +1,68 @@
+/*
+ * 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 java.util.Objects;
+
+/**
+ * Identifier for a routing table.
+ */
+public class RouteTableId {
+ private final String name;
+
+ /**
+ * Creates a new route table ID.
+ *
+ * @param name unique name for the route table
+ */
+ public RouteTableId(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the name of the route table.
+ *
+ * @return table name
+ */
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof RouteTableId) {
+ RouteTableId that = (RouteTableId) obj;
+
+ return Objects.equals(this.name, that.name);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name);
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+}