Search in sources :

Example 6 with RouteAdminService

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

the class RouteServiceWebResource method createRoutes.

/**
 * Creates new unicast routes.
 * 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 routesStream unicast routes JSON array
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid, NO_CONTENT otherwise
 * @onos.rsModel RoutesTypePost
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/bulk")
public Response createRoutes(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.update(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) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

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