Search in sources :

Example 1 with Route

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

the class RouteRemoveCommand method doExecute.

@Override
protected void doExecute() {
    RouteAdminService service = AbstractShellCommand.get(RouteAdminService.class);
    IpPrefix prefix = IpPrefix.valueOf(prefixString);
    IpAddress nextHop = IpAddress.valueOf(nextHopString);
    // Routes through cli without mentioning source then it is created as STATIC,
    // otherwise routes are created with corresponding source.
    Route route = source == null ? new Route(Route.Source.STATIC, prefix, nextHop) : new Route(Route.Source.valueOf(source), prefix, nextHop);
    service.withdraw(Collections.singleton(route));
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) RouteAdminService(org.onosproject.routeservice.RouteAdminService) IpAddress(org.onlab.packet.IpAddress) Route(org.onosproject.routeservice.Route)

Example 2 with Route

use of org.onosproject.routeservice.Route 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 3 with Route

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

the class RouteAddCommand method doExecute.

@Override
protected void doExecute() {
    RouteAdminService service = AbstractShellCommand.get(RouteAdminService.class);
    IpPrefix prefix = IpPrefix.valueOf(prefixString);
    IpAddress nextHop = IpAddress.valueOf(nextHopString);
    service.update(Collections.singleton(new Route(Route.Source.STATIC, prefix, nextHop)));
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) RouteAdminService(org.onosproject.routeservice.RouteAdminService) IpAddress(org.onlab.packet.IpAddress) Route(org.onosproject.routeservice.Route)

Example 4 with Route

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

the class RouteManager method activate.

@Activate
protected void activate() {
    routeMonitor = new RouteMonitor(this, clusterService, storageService);
    routeResolver = new RouteResolver(this, hostService);
    threadFactory = groupedThreads("onos/route", "listener-%d", log);
    hostEventExecutors = new PredictableExecutor(DEFAULT_BUCKETS, groupedThreads("onos/route-manager", "event-host-%d", log));
    resolvedRouteStore = new DefaultResolvedRouteStore();
    routeStore.setDelegate(delegate);
    hostService.addListener(hostListener);
    routeStore.getRouteTables().stream().flatMap(id -> routeStore.getRoutes(id).stream()).forEach(routeSet -> routeResolver.resolve(routeSet));
}
Also used : Route(org.onosproject.routeservice.Route) Host(org.onosproject.net.Host) RouteStore(org.onosproject.routeservice.RouteStore) PredictableExecutor(org.onlab.util.PredictableExecutor) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) RouteEvent(org.onosproject.routeservice.RouteEvent) HostListener(org.onosproject.net.host.HostListener) HostService(org.onosproject.net.host.HostService) RouteStoreDelegate(org.onosproject.routeservice.RouteStoreDelegate) Component(org.osgi.service.component.annotations.Component) StorageService(org.onosproject.store.service.StorageService) ImmutableList(com.google.common.collect.ImmutableList) RouteAdminService(org.onosproject.routeservice.RouteAdminService) Map(java.util.Map) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) RouteService(org.onosproject.routeservice.RouteService) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) RouteListener(org.onosproject.routeservice.RouteListener) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) InternalRouteEvent(org.onosproject.routeservice.InternalRouteEvent) RouteInfo(org.onosproject.routeservice.RouteInfo) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) RouteTableId(org.onosproject.routeservice.RouteTableId) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Reference(org.osgi.service.component.annotations.Reference) IpPrefix(org.onlab.packet.IpPrefix) PredictableExecutor(org.onlab.util.PredictableExecutor) Activate(org.osgi.service.component.annotations.Activate)

Example 5 with Route

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

the class RouteCodec method decode.

@Override
public Route decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    IpPrefix prefix = IpPrefix.valueOf(json.path(PREFIX).asText());
    IpAddress nextHop = IpAddress.valueOf(json.path(NEXT_HOP).asText());
    String source = json.path(SOURCE).asText();
    // Routes through the REST API without mentioning source in the json are created as STATIC,
    // otherwise routes are created with corresponding source.
    Route route = source.isEmpty() ? new Route(Route.Source.STATIC, prefix, nextHop) : new Route(Route.Source.valueOf(source), prefix, nextHop);
    return route;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IpAddress(org.onlab.packet.IpAddress) Route(org.onosproject.routeservice.Route)

Aggregations

Route (org.onosproject.routeservice.Route)34 IpAddress (org.onlab.packet.IpAddress)16 ResolvedRoute (org.onosproject.routeservice.ResolvedRoute)13 IpPrefix (org.onlab.packet.IpPrefix)12 Host (org.onosproject.net.Host)11 MacAddress (org.onlab.packet.MacAddress)9 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)9 VlanId (org.onlab.packet.VlanId)8 HostId (org.onosproject.net.HostId)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Collection (java.util.Collection)6 Optional (java.util.Optional)6 Set (java.util.Set)6 DHCP6 (org.onlab.packet.DHCP6)6 HostLocation (org.onosproject.net.HostLocation)6 RouteAdminService (org.onosproject.routeservice.RouteAdminService)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 ArrayList (java.util.ArrayList)4 Dhcp6ClientIdOption (org.onlab.packet.dhcp.Dhcp6ClientIdOption)4 DefaultHostDescription (org.onosproject.net.host.DefaultHostDescription)4