Search in sources :

Example 16 with McastRoute

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

the class McastRouteWebResource method addHostSinks.

/**
 * Adds a new sink for an existing host in a given multicast route.
 *
 * @param group  group IP address
 * @param srcIp  source IP address
 * @param hostId the host Id
 * @param stream sink connect points JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel McastHostSinksAdd
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("sinks/{group}/{srcIp}/{hostId}")
public Response addHostSinks(@PathParam("group") String group, @PathParam("srcIp") String srcIp, @PathParam("hostId") String hostId, 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<ConnectPoint> sinks = new HashSet<>();
            jsonTree.elements().forEachRemaining(src -> {
                sinks.add(ConnectPoint.deviceConnectPoint(src.asText()));
            });
            if (!sinks.isEmpty()) {
                service.addSinks(route.get(), HostId.hostId(hostId), sinks);
            }
        } 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) ConnectPoint(org.onosproject.net.ConnectPoint) 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 17 with McastRoute

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

the class McastRouteWebResource method getSinks.

/**
 * Get all HostId sinks and their connect points for a multicast route.
 *
 * @param group group IP address
 * @param srcIp source IP address
 * @return 200 OK with array of all sinks for multicast route
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("sinks/{group}/{srcIp}")
public Response getSinks(@PathParam("group") String group, @PathParam("srcIp") String srcIp) {
    Optional<McastRoute> route = getMcastRoute(group, srcIp);
    if (route.isPresent()) {
        ObjectNode sinks = this.mapper().createObjectNode();
        get(MulticastRouteService.class).routeData(route.get()).sinks().forEach((k, v) -> {
            ArrayNode node = this.mapper().createArrayNode();
            v.forEach(sink -> {
                node.add(sink.toString());
            });
            sinks.putPOJO(k.toString(), node);
        });
        ObjectNode root = this.mapper().createObjectNode().putPOJO(SINKS, sinks);
        return ok(root).build();
    }
    return Response.noContent().build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) 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 18 with McastRoute

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

the class McastRouteWebResource method addHostSource.

/**
 * Adds a new set of connect points for an existing host source in a given multicast route.
 *
 * @param group  group IP address
 * @param srcIp  source IP address
 * @param hostId the host Id
 * @param stream source connect points JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel McastHostSourcesAdd
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("source/{group}/{srcIp}/{hostId}")
public Response addHostSource(@PathParam("group") String group, @PathParam("srcIp") String srcIp, @PathParam("hostId") String hostId, 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<ConnectPoint> sources = new HashSet<>();
            jsonTree.elements().forEachRemaining(src -> {
                sources.add(ConnectPoint.deviceConnectPoint(src.asText()));
            });
            if (!sources.isEmpty()) {
                service.addSources(route.get(), HostId.hostId(hostId), sources);
            }
        } 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) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

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