use of org.onosproject.routeservice.RouteInfo 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.RouteInfo in project onos by opennetworkinglab.
the class RouteServiceWebResource method getRoutesCount.
/**
* Get count of all unicast routes.
* Returns count of all known unicast routes.
*
* @return 200 OK with count of all known unicast routes
* @onos.rsModel RoutesGetCount
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/routes/count")
public Response getRoutesCount() {
RouteService service = get(RouteService.class);
ObjectNode root = mapper().createObjectNode();
service.getRouteTables().forEach(table -> {
Collection<RouteInfo> routes = service.getRoutes(table);
root.put(table.name() + "PrefixCount", routes.stream().count());
});
return ok(root).build();
}
use of org.onosproject.routeservice.RouteInfo in project onos by opennetworkinglab.
the class RoutesListCommand method json.
/**
* Produces a JSON array of routes.
*
* @param routes the routes with the data
* @return JSON array with the routes
*/
private JsonNode json(Collection<RouteInfo> routes) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
routes.stream().flatMap(ri -> ri.allRoutes().stream()).forEach(r -> {
// use RouteCodec to encode the Route object inside ResolvedRoute
ObjectNode routeNode = jsonForEntity(r.route(), Route.class);
if (r.nextHopMac() != null) {
routeNode.put("nextHopMac", r.nextHopMac().toString());
}
if (r.nextHopVlan() != null) {
routeNode.put("nextHopVlan", r.nextHopVlan().toString());
}
result.add(routeNode);
});
return result;
}
Aggregations