Search in sources :

Example 1 with RouteInfo

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("");
        });
    }
}
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 RouteInfo

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();
}
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 3 with RouteInfo

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;
}
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) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

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