Search in sources :

Example 6 with Route

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

the class RouteServiceWebResource method deleteRoute.

/**
 * Remove a unicast route.
 * Removes a route from the unicast RIB.
 *
 * @param route unicast route JSON
 * @return 204 NO CONTENT
 * @onos.rsModel RoutePost
 */
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
public Response deleteRoute(InputStream route) {
    RouteAdminService service = get(RouteAdminService.class);
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), route);
        Route r = codec(Route.class).decode(jsonTree, this);
        service.withdraw(Collections.singletonList(r));
    } 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) IOException(java.io.IOException) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Example 7 with Route

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

Example 8 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 9 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 10 with Route

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

the class RouteManagerTest method testRouteDelete.

/**
 * Tests deleting routes from the route manager.
 */
@Test
public void testRouteDelete() {
    Route route = new Route(Route.Source.STATIC, V4_PREFIX1, V4_NEXT_HOP1);
    ResolvedRoute removedResolvedRoute = new ResolvedRoute(route, MAC1);
    verifyDelete(route, removedResolvedRoute);
    route = new Route(Route.Source.STATIC, V6_PREFIX1, V6_NEXT_HOP1);
    removedResolvedRoute = new ResolvedRoute(route, MAC3);
    verifyDelete(route, removedResolvedRoute);
}
Also used : ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

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