Search in sources :

Example 1 with RouteAdminService

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

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

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

the class RouteServiceWebResource method createRoute.

/**
 * Create new unicast route.
 * Creates a new route in the unicast RIB. Source field is kept optional.
 * Without Source field routes are created as STATIC routes. Otherwise as per the mentioned Source
 *
 * @param route unicast route JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid, NO_CONTENT otherwise
 * @onos.rsModel RouteTypePost
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createRoute(InputStream route) {
    RouteAdminService service = get(RouteAdminService.class);
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), route);
        Route r = codec(Route.class).decode(jsonTree, this);
        service.update(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) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 4 with RouteAdminService

use of org.onosproject.routeservice.RouteAdminService 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 5 with RouteAdminService

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

Aggregations

Route (org.onosproject.routeservice.Route)6 RouteAdminService (org.onosproject.routeservice.RouteAdminService)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 IOException (java.io.IOException)4 Consumes (javax.ws.rs.Consumes)4 ResolvedRoute (org.onosproject.routeservice.ResolvedRoute)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 DELETE (javax.ws.rs.DELETE)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 IpAddress (org.onlab.packet.IpAddress)2 IpPrefix (org.onlab.packet.IpPrefix)2