Search in sources :

Example 1 with RouteTableId

use of org.onosproject.routeservice.RouteTableId 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 RouteTableId

use of org.onosproject.routeservice.RouteTableId in project onos by opennetworkinglab.

the class DistributedRouteStore method activate.

/**
 * Sets up distributed route store.
 */
public void activate() {
    routeTables = new ConcurrentHashMap<>();
    executor = Executors.newSingleThreadExecutor(groupedThreads("onos/route", "store", log));
    KryoNamespace masterRouteTableSerializer = KryoNamespace.newBuilder().register(RouteTableId.class).build();
    masterRouteTable = storageService.<RouteTableId>setBuilder().withName("onos-master-route-table").withSerializer(Serializer.using(masterRouteTableSerializer)).build().asDistributedSet();
    masterRouteTable.addListener(masterRouteTableListener);
    // Add default tables (add is idempotent)
    masterRouteTable.add(IPV4);
    masterRouteTable.add(IPV6);
    masterRouteTable.forEach(this::createRouteTable);
    log.info("Started");
}
Also used : RouteTableId(org.onosproject.routeservice.RouteTableId) KryoNamespace(org.onlab.util.KryoNamespace)

Example 3 with RouteTableId

use of org.onosproject.routeservice.RouteTableId in project onos by opennetworkinglab.

the class LocalRouteStore method computeRouteTablesFromIps.

private Map<RouteTableId, Set<IpAddress>> computeRouteTablesFromIps(Collection<IpAddress> ipAddresses) {
    Map<RouteTableId, Set<IpAddress>> computedTables = new HashMap<>();
    ipAddresses.forEach(ipAddress -> {
        RouteTableId routeTableId = (ipAddress.isIp4()) ? IPV4 : IPV6;
        Set<IpAddress> tempIpAddresses = computedTables.computeIfAbsent(routeTableId, k -> Sets.newHashSet());
        tempIpAddresses.add(ipAddress);
    });
    return computedTables;
}
Also used : RouteTableId(org.onosproject.routeservice.RouteTableId) RouteSet(org.onosproject.routeservice.RouteSet) Set(java.util.Set) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IpAddress(org.onlab.packet.IpAddress)

Example 4 with RouteTableId

use of org.onosproject.routeservice.RouteTableId 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;
}
Also used : RouteTableId(org.onosproject.routeservice.RouteTableId) RouteSet(org.onosproject.routeservice.RouteSet) Set(java.util.Set) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Route(org.onosproject.routeservice.Route)

Example 5 with RouteTableId

use of org.onosproject.routeservice.RouteTableId in project onos by opennetworkinglab.

the class DistributedRouteStore 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;
}
Also used : RouteTableId(org.onosproject.routeservice.RouteTableId) RouteSet(org.onosproject.routeservice.RouteSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) DistributedSet(org.onosproject.store.service.DistributedSet) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Route(org.onosproject.routeservice.Route)

Aggregations

RouteTableId (org.onosproject.routeservice.RouteTableId)6 HashMap (java.util.HashMap)4 Set (java.util.Set)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 RouteSet (org.onosproject.routeservice.RouteSet)4 Route (org.onosproject.routeservice.Route)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 IpAddress (org.onlab.packet.IpAddress)2 DistributedSet (org.onosproject.store.service.DistributedSet)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)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 KryoNamespace (org.onlab.util.KryoNamespace)1