use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class RouteServiceWebResource method deleteRoute.
/**
* Remove a unicast route.
* Removes a route from the unicast RIB.
*
* @param route unicast route JSON
* @return 204 NO CONTENT
* @onos.rsModel RoutePost
*/
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
public Response deleteRoute(InputStream route) {
RouteAdminService service = get(RouteAdminService.class);
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), route);
Route r = codec(Route.class).decode(jsonTree, this);
service.withdraw(Collections.singletonList(r));
} catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
return Response.noContent().build();
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class RouteServiceWebResource method getRoutes.
/**
* Get all unicast routes.
* Returns array of all known unicast routes.
*
* @return 200 OK with array of all known unicast routes
* @onos.rsModel RoutesGet
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getRoutes() {
RouteService service = get(RouteService.class);
ObjectNode root = mapper().createObjectNode();
service.getRouteTables().forEach(table -> {
List<Route> routes = service.getRoutes(table).stream().flatMap(ri -> ri.allRoutes().stream()).map(ResolvedRoute::route).collect(Collectors.toList());
root.put(table.name(), codec(Route.class).encode(routes, this));
});
return ok(root).build();
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class RoutesListCommand method doExecute.
@Override
protected void doExecute() {
RouteService service = AbstractShellCommand.get(RouteService.class);
if (outputJson()) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode result = mapper.createObjectNode();
result.set("routes4", json(service.getRoutes(new RouteTableId("ipv4"))));
result.set("routes6", json(service.getRoutes(new RouteTableId("ipv6"))));
print("%s", result);
} else {
print("B: Best route, R: Resolved route\n");
service.getRouteTables().forEach(id -> {
Collection<RouteInfo> tableRoutes = service.getRoutes(id);
String format = tableRoutes.stream().anyMatch(route -> route.prefix().isIp6()) ? FORMAT_ROUTE6 : FORMAT_ROUTE;
// Print header
print(FORMAT_TABLE, id);
print(format, "B", "R", NETWORK, NEXTHOP, SOURCE, NODE);
// Print routing entries
tableRoutes.stream().sorted(Comparator.comparing(r -> r.prefix().address())).forEach(route -> this.print(format, route));
print(FORMAT_TOTAL, tableRoutes.size());
print("");
});
}
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class LocalRouteStore method computeRouteTablesFromRoutes.
private Map<RouteTableId, Set<Route>> computeRouteTablesFromRoutes(Collection<Route> routes) {
Map<RouteTableId, Set<Route>> computedTables = new HashMap<>();
routes.forEach(route -> {
RouteTableId routeTableId = (route.prefix().address().isIp4()) ? IPV4 : IPV6;
Set<Route> tempRoutes = computedTables.computeIfAbsent(routeTableId, k -> Sets.newHashSet());
tempRoutes.add(route);
});
return computedTables;
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class RouteManagerTest method testRouteDelete.
/**
* Tests deleting routes from the route manager.
*/
@Test
public void testRouteDelete() {
Route route = new Route(Route.Source.STATIC, V4_PREFIX1, V4_NEXT_HOP1);
ResolvedRoute removedResolvedRoute = new ResolvedRoute(route, MAC1);
verifyDelete(route, removedResolvedRoute);
route = new Route(Route.Source.STATIC, V6_PREFIX1, V6_NEXT_HOP1);
removedResolvedRoute = new ResolvedRoute(route, MAC3);
verifyDelete(route, removedResolvedRoute);
}
Aggregations