Search in sources :

Example 1 with MulticastRouteService

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

the class McastRouteWebResource method addSinks.

/**
 * Adds sinks 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 McastSinksAdd
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("sinks/{group}/{srcIp}")
public Response addSinks(@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(SINKS);
            Set<HostId> sinks = new HashSet<>();
            jsonTree.elements().forEachRemaining(sink -> {
                sinks.add(HostId.hostId(sink.asText()));
            });
            if (!sinks.isEmpty()) {
                sinks.forEach(sink -> {
                    service.addSink(route.get(), sink);
                });
            }
        } 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 2 with MulticastRouteService

use of org.onosproject.mcast.api.MulticastRouteService 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 3 with MulticastRouteService

use of org.onosproject.mcast.api.MulticastRouteService 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 4 with MulticastRouteService

use of org.onosproject.mcast.api.MulticastRouteService 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 5 with MulticastRouteService

use of org.onosproject.mcast.api.MulticastRouteService 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

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