use of org.onosproject.routeservice.RouteService 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.RouteService in project onos by opennetworkinglab.
the class RouteServiceWebResource method getRoutesCountByType.
/**
* Get count of all types routes .
* Returns count of all known route types.
*
* @return 200 OK with count of all route types
* @onos.rsModel RoutesGetTypeCount
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/routes/types/count")
public Response getRoutesCountByType() {
RouteService service = get(RouteService.class);
ObjectNode root = mapper().createObjectNode();
service.getRouteTables().forEach(table -> {
List<Route> staticRoutes = new ArrayList<>();
List<Route> fpmRoutes = new ArrayList<>();
List<Route> ripRoutes = new ArrayList<>();
List<Route> dhcpRoutes = new ArrayList<>();
List<Route> dhcpLQRoutes = new ArrayList<>();
List<Route> bgpRoutes = new ArrayList<>();
List<Route> routes = service.getRoutes(table).stream().flatMap(ri -> ri.allRoutes().stream()).map(ResolvedRoute::route).collect(Collectors.toList());
routes.forEach(route -> {
if (route.source() == Route.Source.STATIC) {
staticRoutes.add(route);
}
if (route.source() == Route.Source.FPM) {
fpmRoutes.add(route);
}
if (route.source() == Route.Source.RIP) {
ripRoutes.add(route);
}
if (route.source() == Route.Source.DHCP) {
dhcpRoutes.add(route);
}
if (route.source() == Route.Source.DHCPLQ) {
dhcpLQRoutes.add(route);
}
if (route.source() == Route.Source.BGP) {
bgpRoutes.add(route);
}
});
root.put(table.name() + "StaticRouteCount", staticRoutes.size());
root.put(table.name() + "FpmRouteCount", fpmRoutes.size());
root.put(table.name() + "RipRouteCount", ripRoutes.size());
root.put(table.name() + "DhcpRouteCount", dhcpRoutes.size());
root.put(table.name() + "DhcpLQRouteCount", dhcpLQRoutes.size());
root.put(table.name() + "BgpRouteCount", bgpRoutes.size());
root.put(table.name() + "TotalRouteCount", routes.stream().count());
});
return ok(root).build();
}
use of org.onosproject.routeservice.RouteService 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.RouteService 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();
}
Aggregations