Search in sources :

Example 11 with Route

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

the class RouteServiceWebResource method deleteRoutes.

/**
 * Removes unicast routes.
 * Removes multiple routes from the unicast RIB.
 *
 * @param routesStream unicast routes array JSON
 * @return 204 NO CONTENT
 */
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("/bulk")
public Response deleteRoutes(InputStream routesStream) {
    RouteAdminService service = get(RouteAdminService.class);
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), routesStream);
        ArrayNode routesArray = nullIsIllegal((ArrayNode) jsonTree.get(ROUTES), ROUTES_KEY_ERROR);
        List<Route> routes = codec(Route.class).decode(routesArray, this);
        service.withdraw(routes);
    } catch (IOException ex) {
        throw new IllegalArgumentException(ex);
    }
    return Response.noContent().build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RouteAdminService(org.onosproject.routeservice.RouteAdminService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Example 12 with Route

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

use of org.onosproject.routeservice.Route 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 14 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 15 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)

Aggregations

Route (org.onosproject.routeservice.Route)35 IpAddress (org.onlab.packet.IpAddress)17 ResolvedRoute (org.onosproject.routeservice.ResolvedRoute)14 IpPrefix (org.onlab.packet.IpPrefix)13 Host (org.onosproject.net.Host)12 MacAddress (org.onlab.packet.MacAddress)10 VlanId (org.onlab.packet.VlanId)9 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)9 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 Test (org.junit.Test)6 DHCP6 (org.onlab.packet.DHCP6)6 HostLocation (org.onosproject.net.HostLocation)6 HostEvent (org.onosproject.net.host.HostEvent)6 RouteAdminService (org.onosproject.routeservice.RouteAdminService)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 ArrayList (java.util.ArrayList)4