Search in sources :

Example 6 with McastRoute

use of org.onosproject.mcast.api.McastRoute in project onos by opennetworkinglab.

the class McastRouteWebResource method addSources.

/**
 * Adds sources for a given existing multicast route.
 *
 * @param group  group IP address
 * @param srcIp  source IP address
 * @param stream host sinks JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel McastSourcesAdd
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("sources/{group}/{srcIp}")
public Response addSources(@PathParam("group") String group, @PathParam("srcIp") String srcIp, InputStream stream) {
    MulticastRouteService service = get(MulticastRouteService.class);
    Optional<McastRoute> route = getMcastRoute(group, srcIp);
    if (route.isPresent()) {
        ArrayNode jsonTree;
        try {
            jsonTree = (ArrayNode) mapper().readTree(stream).get(SOURCES);
            Set<HostId> sources = new HashSet<>();
            jsonTree.elements().forEachRemaining(src -> {
                sources.add(HostId.hostId(src.asText()));
            });
            if (!sources.isEmpty()) {
                sources.forEach(src -> {
                    service.addSource(route.get(), src);
                });
            }
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }
        return Response.ok().build();
    }
    return Response.noContent().build();
}
Also used : MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) McastRoute(org.onosproject.mcast.api.McastRoute) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) HostId(org.onosproject.net.HostId) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 7 with McastRoute

use of org.onosproject.mcast.api.McastRoute in project onos by opennetworkinglab.

the class McastRouteWebResource method deleteRoutes.

/**
 * Removes all the given multicast routes.
 *
 * @param stream the set of multicast routes
 * @return 204 NO CONTENT
 */
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("bulk/")
public Response deleteRoutes(InputStream stream) {
    MulticastRouteService service = get(MulticastRouteService.class);
    try {
        ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
        ArrayNode routesArray = nullIsIllegal((ArrayNode) jsonTree.get(ROUTES), ROUTES_KEY_ERROR);
        List<McastRoute> routes = codec(McastRoute.class).decode(routesArray, this);
        routes.forEach(service::remove);
    } catch (IOException ex) {
        throw new IllegalArgumentException(ex);
    }
    return Response.noContent().build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) McastRoute(org.onosproject.mcast.api.McastRoute) IOException(java.io.IOException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Example 8 with McastRoute

use of org.onosproject.mcast.api.McastRoute in project onos by opennetworkinglab.

the class McastRouteWebResource method getHostSources.

/**
 * Get all source connect points for a given sink host in a multicast route.
 *
 * @param group  group IP address
 * @param srcIp  source IP address
 * @param hostId host Id
 * @return 200 OK with array of all sources for multicast route
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("sources/{group}/{srcIp}/{hostId}")
public Response getHostSources(@PathParam("group") String group, @PathParam("srcIp") String srcIp, @PathParam("hostId") String hostId) {
    Optional<McastRoute> route = getMcastRoute(group, srcIp);
    if (route.isPresent()) {
        ArrayNode node = this.mapper().createArrayNode();
        get(MulticastRouteService.class).sources(route.get(), HostId.hostId(hostId)).forEach(source -> {
            node.add(source.toString());
        });
        ObjectNode root = this.mapper().createObjectNode().putPOJO(SOURCES, node);
        return ok(root).build();
    }
    return Response.noContent().build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) McastRoute(org.onosproject.mcast.api.McastRoute) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with McastRoute

use of org.onosproject.mcast.api.McastRoute in project onos by opennetworkinglab.

the class McastRouteWebResource method createRoute.

/**
 * Create new multicast route.
 *
 * @param stream multicast route JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel McastRoute
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response createRoute(InputStream stream) {
    MulticastRouteService service = get(MulticastRouteService.class);
    try {
        ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
        McastRoute route = codec(McastRoute.class).decode(jsonTree, this);
        service.add(route);
        Set<HostId> sources = new HashSet<>();
        jsonTree.path(SOURCES).elements().forEachRemaining(src -> {
            sources.add(HostId.hostId(src.asText()));
        });
        Set<HostId> sinks = new HashSet<>();
        jsonTree.path(SINKS).elements().forEachRemaining(sink -> {
            sinks.add(HostId.hostId(sink.asText()));
        });
        if (!sources.isEmpty()) {
            sources.forEach(source -> {
                service.addSource(route, source);
            });
        }
        if (!sinks.isEmpty()) {
            sinks.forEach(sink -> {
                service.addSink(route, sink);
            });
        }
    } catch (IOException ex) {
        throw new IllegalArgumentException(ex);
    }
    return Response.created(URI.create("")).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) McastRoute(org.onosproject.mcast.api.McastRoute) IOException(java.io.IOException) HostId(org.onosproject.net.HostId) HashSet(java.util.HashSet) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 10 with McastRoute

use of org.onosproject.mcast.api.McastRoute in project onos by opennetworkinglab.

the class McastShowHostCommand method doExecute.

@Override
protected void doExecute() {
    // Get the service
    MulticastRouteService mcastService = get(MulticastRouteService.class);
    // Get the routes
    Set<McastRoute> routes = mcastService.getRoutes();
    // Verify mcast group
    if (!isNullOrEmpty(gAddr)) {
        // Let's find the group
        IpAddress mcastGroup = IpAddress.valueOf(gAddr);
        McastRoute mcastRoute = routes.stream().filter(route -> route.group().equals(mcastGroup)).findAny().orElse(null);
        // If it exists
        if (mcastRoute != null) {
            prepareResult(mcastService, mcastRoute);
        }
    } else {
        routes.stream().filter(mcastRoute -> mcastRoute.group().isIp4()).sorted(Comparator.comparing(McastRoute::group)).forEach(route -> {
            prepareResult(mcastService, route);
        });
        routes.stream().filter(mcastRoute -> mcastRoute.group().isIp6()).sorted(Comparator.comparing(McastRoute::group)).forEach(route -> {
            prepareResult(mcastService, route);
        });
    }
    if (outputJson()) {
        print("%s", routesNode);
    } else {
        print("%s", routesBuilder.toString());
    }
}
Also used : MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) IpAddress(org.onlab.packet.IpAddress) McastRoute(org.onosproject.mcast.api.McastRoute)

Aggregations

McastRoute (org.onosproject.mcast.api.McastRoute)18 MulticastRouteService (org.onosproject.mcast.api.MulticastRouteService)15 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 IOException (java.io.IOException)7 Consumes (javax.ws.rs.Consumes)7 HashSet (java.util.HashSet)6 POST (javax.ws.rs.POST)6 IpAddress (org.onlab.packet.IpAddress)6 GET (javax.ws.rs.GET)5 HostId (org.onosproject.net.HostId)5 ConnectPoint (org.onosproject.net.ConnectPoint)3 Comparator (java.util.Comparator)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 DELETE (javax.ws.rs.DELETE)1 Command (org.apache.karaf.shell.api.action.Command)1