Search in sources :

Example 1 with RouteService

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("");
        });
    }
}
Also used : Route(org.onosproject.routeservice.Route) RouteService(org.onosproject.routeservice.RouteService) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Objects(java.util.Objects) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Service(org.apache.karaf.shell.api.action.lifecycle.Service) RouteInfo(org.onosproject.routeservice.RouteInfo) Optional(java.util.Optional) JsonNode(com.fasterxml.jackson.databind.JsonNode) RouteTableId(org.onosproject.routeservice.RouteTableId) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Comparator(java.util.Comparator) RouteTableId(org.onosproject.routeservice.RouteTableId) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RouteService(org.onosproject.routeservice.RouteService) RouteInfo(org.onosproject.routeservice.RouteInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with RouteService

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) RouteService(org.onosproject.routeservice.RouteService) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with RouteService

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RouteService(org.onosproject.routeservice.RouteService) RouteInfo(org.onosproject.routeservice.RouteInfo) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with RouteService

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RouteService(org.onosproject.routeservice.RouteService) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 RouteService (org.onosproject.routeservice.RouteService)4 GET (javax.ws.rs.GET)3 Produces (javax.ws.rs.Produces)3 ResolvedRoute (org.onosproject.routeservice.ResolvedRoute)3 Route (org.onosproject.routeservice.Route)3 Path (javax.ws.rs.Path)2 RouteInfo (org.onosproject.routeservice.RouteInfo)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Command (org.apache.karaf.shell.api.action.Command)1 Service (org.apache.karaf.shell.api.action.lifecycle.Service)1 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)1 RouteTableId (org.onosproject.routeservice.RouteTableId)1