Search in sources :

Example 11 with MulticastRouteService

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

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

Example 13 with MulticastRouteService

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

the class McastRouteWebResource method deleteRoutes.

/**
 * Removes all the multicast routes.
 *
 * @return 204 NO CONTENT
 */
@DELETE
public Response deleteRoutes() {
    MulticastRouteService service = get(MulticastRouteService.class);
    service.getRoutes().forEach(service::remove);
    return Response.noContent().build();
}
Also used : MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) DELETE(javax.ws.rs.DELETE)

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