Carry original route in ResolvedRoute object.
The original route may have information of interest to consumers, such
as the route source or VRF information.
Change-Id: I32df752c92e235423694b13d4ff239a38bae5a50
diff --git a/apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/FibInstaller.java b/apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/FibInstaller.java
index d279ffc..bbf2c36 100644
--- a/apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/FibInstaller.java
+++ b/apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/FibInstaller.java
@@ -40,6 +40,7 @@
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.incubator.net.routing.ResolvedRoute;
+import org.onosproject.incubator.net.routing.Route;
import org.onosproject.incubator.net.routing.RouteEvent;
import org.onosproject.incubator.net.routing.RouteListener;
import org.onosproject.incubator.net.routing.RouteService;
@@ -65,11 +66,11 @@
import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.flowobjective.NextObjective;
import org.onosproject.net.flowobjective.ObjectiveContext;
+import org.onosproject.routing.InterfaceProvisionRequest;
import org.onosproject.routing.NextHop;
import org.onosproject.routing.NextHopGroupKey;
-import org.onosproject.routing.RouterInfo;
-import org.onosproject.routing.InterfaceProvisionRequest;
import org.onosproject.routing.Router;
+import org.onosproject.routing.RouterInfo;
import org.onosproject.routing.RoutingService;
import org.onosproject.routing.config.RouterConfigHelper;
import org.onosproject.routing.config.RoutersConfig;
@@ -233,9 +234,9 @@
routeService.removeListener(routeListener);
//clean up the routes.
- for (Map.Entry<IpPrefix, IpAddress> routes: prefixToNextHop.entrySet()) {
- deleteRoute(new ResolvedRoute(routes.getKey(), null, null, null));
- }
+ prefixToNextHop.entrySet().stream()
+ .map(e -> new Route(Route.Source.UNDEFINED, e.getKey(), e.getValue()))
+ .forEach(this::deleteRoute);
if (interfaceManager != null) {
interfaceManager.cleanup();
@@ -266,6 +267,10 @@
}
private synchronized void deleteRoute(ResolvedRoute route) {
+ deleteRoute(new Route(Route.Source.UNDEFINED, route.prefix(), route.nextHop()));
+ }
+
+ private void deleteRoute(Route route) {
//Integer nextId = nextHops.get(route.nextHop());
/* Group group = deleteNextHop(route.prefix());
diff --git a/apps/routing/fibinstaller/src/test/java/org/onosproject/routing/fibinstaller/FibInstallerTest.java b/apps/routing/fibinstaller/src/test/java/org/onosproject/routing/fibinstaller/FibInstallerTest.java
index fabc94b..e00a029 100644
--- a/apps/routing/fibinstaller/src/test/java/org/onosproject/routing/fibinstaller/FibInstallerTest.java
+++ b/apps/routing/fibinstaller/src/test/java/org/onosproject/routing/fibinstaller/FibInstallerTest.java
@@ -36,6 +36,7 @@
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.incubator.net.intf.InterfaceServiceAdapter;
import org.onosproject.incubator.net.routing.ResolvedRoute;
+import org.onosproject.incubator.net.routing.Route;
import org.onosproject.incubator.net.routing.RouteEvent;
import org.onosproject.incubator.net.routing.RouteListener;
import org.onosproject.incubator.net.routing.RouteServiceAdapter;
@@ -283,7 +284,7 @@
*/
@Test
public void testRouteAdd() {
- ResolvedRoute resolvedRoute = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
+ ResolvedRoute resolvedRoute = createRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
// Create the next objective
NextObjective nextObjective = createNextObjective(MAC1, MAC1, SW1_ETH1.port(), VlanId.NONE, true);
@@ -309,7 +310,7 @@
*/
@Test
public void testRouteAddWithVlan() {
- ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2, SW1_ETH2);
+ ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP2, MAC2, SW1_ETH2);
// Create the next objective
NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
@@ -339,8 +340,8 @@
testRouteAdd();
reset(flowObjectiveService);
- ResolvedRoute oldRoute = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
- ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2, SW1_ETH2);
+ ResolvedRoute oldRoute = createRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
+ ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP2, MAC2, SW1_ETH2);
// Create the next objective
NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
@@ -370,7 +371,7 @@
testRouteAdd();
// Construct the existing route
- ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
+ ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP1, MAC1, SW1_ETH1);
// Create the flow objective
reset(flowObjectiveService);
@@ -384,6 +385,12 @@
verify(flowObjectiveService);
}
+ private static ResolvedRoute createRoute(IpPrefix prefix, IpAddress nextHop,
+ MacAddress nextHopMac, ConnectPoint location) {
+ return new ResolvedRoute(
+ new Route(Route.Source.UNDEFINED, prefix, nextHop), nextHopMac, location);
+ }
+
private class TestInterfaceService extends InterfaceServiceAdapter {
@Override
public void addListener(InterfaceListener listener) {
diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/SdnIpFibTest.java b/apps/sdnip/src/test/java/org/onosproject/sdnip/SdnIpFibTest.java
index 0d45475..4d04b82 100644
--- a/apps/sdnip/src/test/java/org/onosproject/sdnip/SdnIpFibTest.java
+++ b/apps/sdnip/src/test/java/org/onosproject/sdnip/SdnIpFibTest.java
@@ -38,6 +38,7 @@
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.incubator.net.intf.InterfaceServiceAdapter;
import org.onosproject.incubator.net.routing.ResolvedRoute;
+import org.onosproject.incubator.net.routing.Route;
import org.onosproject.incubator.net.routing.RouteEvent;
import org.onosproject.incubator.net.routing.RouteListener;
import org.onosproject.incubator.net.routing.RouteServiceAdapter;
@@ -192,7 +193,7 @@
@Test
public void testRouteAddToNoVlan() {
// Build the expected route
- ResolvedRoute route = new ResolvedRoute(PREFIX1, IP3, MAC3, SW3_ETH1);
+ ResolvedRoute route = createRoute(PREFIX1, IP3, MAC3, SW3_ETH1);
MultiPointToSinglePointIntent intent =
createIntentToThreeSrcOneTwo(PREFIX1);
@@ -216,7 +217,7 @@
@Test
public void testRouteAddToVlan() {
// Build the expected route
- ResolvedRoute route = new ResolvedRoute(PREFIX2, IP1, MAC1, SW1_ETH1);
+ ResolvedRoute route = createRoute(PREFIX2, IP1, MAC1, SW1_ETH1);
MultiPointToSinglePointIntent intent = createIntentToOne(PREFIX2);
@@ -245,8 +246,8 @@
testRouteAddToNoVlan();
// Build the new route entries for prefix1 and prefix2
- ResolvedRoute oldRoutePrefixOne = new ResolvedRoute(PREFIX1, IP3, MAC3, SW3_ETH1);
- ResolvedRoute routePrefixOne = new ResolvedRoute(PREFIX1, IP1, MAC1, SW1_ETH1);
+ ResolvedRoute oldRoutePrefixOne = createRoute(PREFIX1, IP3, MAC3, SW3_ETH1);
+ ResolvedRoute routePrefixOne = createRoute(PREFIX1, IP1, MAC1, SW1_ETH1);
// Create the new expected intents
MultiPointToSinglePointIntent newPrefixOneIntent = createIntentToOne(PREFIX1);
@@ -280,8 +281,8 @@
testRouteAddToVlan();
// Build the new route entries for prefix1 and prefix2
- ResolvedRoute oldRoutePrefix = new ResolvedRoute(PREFIX2, IP1, MAC1, SW1_ETH1);
- ResolvedRoute routePrefix = new ResolvedRoute(PREFIX2, IP3, MAC3, SW3_ETH1);
+ ResolvedRoute oldRoutePrefix = createRoute(PREFIX2, IP1, MAC1, SW1_ETH1);
+ ResolvedRoute routePrefix = createRoute(PREFIX2, IP3, MAC3, SW3_ETH1);
// Create the new expected intents
MultiPointToSinglePointIntent newPrefixIntent =
@@ -313,7 +314,7 @@
testRouteAddToNoVlan();
// Construct the existing route entry
- ResolvedRoute route = new ResolvedRoute(PREFIX1, IP3, MAC3, SW3_ETH1);
+ ResolvedRoute route = createRoute(PREFIX1, IP3, MAC3, SW3_ETH1);
// Create existing intent
MultiPointToSinglePointIntent removedIntent =
@@ -623,6 +624,12 @@
return intent;
}
+ private static ResolvedRoute createRoute(IpPrefix prefix, IpAddress nextHop,
+ MacAddress nextHopMac, ConnectPoint location) {
+ return new ResolvedRoute(
+ new Route(Route.Source.UNDEFINED, prefix, nextHop), nextHopMac, location);
+ }
+
private class TestCoreService extends CoreServiceAdapter {
@Override
public ApplicationId getAppId(String name) {
diff --git a/cli/src/main/java/org/onosproject/cli/net/RoutesListCommand.java b/cli/src/main/java/org/onosproject/cli/net/RoutesListCommand.java
index f32ecd5..31b7555 100644
--- a/cli/src/main/java/org/onosproject/cli/net/RoutesListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/RoutesListCommand.java
@@ -22,7 +22,6 @@
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.incubator.net.routing.ResolvedRoute;
-import org.onosproject.incubator.net.routing.Route;
import org.onosproject.incubator.net.routing.RouteInfo;
import org.onosproject.incubator.net.routing.RouteService;
import org.onosproject.incubator.net.routing.RouteTableId;
@@ -84,7 +83,7 @@
private void print(String format, RouteInfo routeInfo) {
routeInfo.allRoutes()
.forEach(r -> print(format, isBestRoute(routeInfo.bestRoute(), r) ? ">" : "",
- r.prefix(), r.nextHop(), Route.Source.UNDEFINED));
+ r.prefix(), r.nextHop(), r.route().source()));
}
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 02d4e95..394e764 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
@@ -31,8 +31,7 @@
*/
public class ResolvedRoute {
- private final IpPrefix prefix;
- private final IpAddress nextHop;
+ private final Route route;
private final MacAddress nextHopMac;
private final VlanId nextHopVlan;
private final ConnectPoint location;
@@ -51,19 +50,6 @@
/**
* Creates a new resolved route.
*
- * @param prefix route prefix
- * @param nextHop route next hop IP address
- * @param nextHopMac next hop MAC address
- * @param location connect point where the next hop connects to
- */
- public ResolvedRoute(IpPrefix prefix, IpAddress nextHop, MacAddress nextHopMac,
- ConnectPoint location) {
- this(prefix, nextHop, nextHopMac, VlanId.NONE, location);
- }
-
- /**
- * Creates a new resolved route.
- *
* @param route input route
* @param nextHopMac next hop MAC address
* @param nextHopVlan next hop VLAN ID
@@ -71,29 +57,19 @@
*/
public ResolvedRoute(Route route, MacAddress nextHopMac, VlanId nextHopVlan,
ConnectPoint location) {
- this.prefix = route.prefix();
- this.nextHop = route.nextHop();
+ this.route = route;
this.nextHopMac = nextHopMac;
this.nextHopVlan = nextHopVlan;
this.location = location;
}
/**
- * Creates a new resolved route.
+ * Returns the original route.
*
- * @param prefix route prefix
- * @param nextHop route next hop IP address
- * @param nextHopMac next hop MAC address
- * @param nextHopVlan next hop VLAN address
- * @param location connect point where the next hop connects to
+ * @return route
*/
- public ResolvedRoute(IpPrefix prefix, IpAddress nextHop, MacAddress nextHopMac,
- VlanId nextHopVlan, ConnectPoint location) {
- this.prefix = prefix;
- this.nextHop = nextHop;
- this.nextHopMac = nextHopMac;
- this.nextHopVlan = nextHopVlan;
- this.location = location;
+ public Route route() {
+ return route;
}
/**
@@ -102,7 +78,7 @@
* @return IP prefix
*/
public IpPrefix prefix() {
- return prefix;
+ return route.prefix();
}
/**
@@ -111,7 +87,7 @@
* @return IP address
*/
public IpAddress nextHop() {
- return nextHop;
+ return route.nextHop();
}
/**
@@ -143,7 +119,7 @@
@Override
public int hashCode() {
- return Objects.hash(prefix, nextHop, nextHopMac, nextHopVlan, location);
+ return Objects.hash(route, nextHopMac, nextHopVlan, location);
}
@Override
@@ -158,8 +134,7 @@
ResolvedRoute that = (ResolvedRoute) other;
- return Objects.equals(this.prefix, that.prefix) &&
- Objects.equals(this.nextHop, that.nextHop) &&
+ return Objects.equals(this.route, that.route) &&
Objects.equals(this.nextHopMac, that.nextHopMac) &&
Objects.equals(this.nextHopVlan, that.nextHopVlan) &&
Objects.equals(this.location, that.location);
@@ -168,8 +143,7 @@
@Override
public String toString() {
return toStringHelper(this)
- .add("prefix", prefix)
- .add("nextHop", nextHop)
+ .add("route", route)
.add("nextHopMac", nextHopMac)
.add("nextHopVlan", nextHopVlan)
.add("location", location)