Search in sources :

Example 1 with McastRoute

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

the class McastHostRouteCodec method decode.

@Override
public McastRoute decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    String source = json.path(SOURCE).asText();
    IpAddress sourceIp = null;
    if (!source.equals("*")) {
        sourceIp = IpAddress.valueOf(source);
    }
    IpAddress group = IpAddress.valueOf(json.path(GROUP).asText());
    McastRoute route = new McastRoute(sourceIp, group, McastRoute.Type.STATIC);
    return route;
}
Also used : IpAddress(org.onlab.packet.IpAddress) McastRoute(org.onosproject.mcast.api.McastRoute)

Example 2 with McastRoute

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

the class McastRouteWebResource method getSources.

/**
 * Get all sources connect points for a multicast route.
 *
 * @param group group IP address
 * @param srcIp source IP address
 * @return 200 OK with array of all sources for multicast route
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("sources/{group}/{srcIp}")
public Response getSources(@PathParam("group") String group, @PathParam("srcIp") String srcIp) {
    Optional<McastRoute> route = getMcastRoute(group, srcIp);
    if (route.isPresent()) {
        ObjectNode sources = this.mapper().createObjectNode();
        get(MulticastRouteService.class).routeData(route.get()).sources().forEach((k, v) -> {
            ArrayNode node = this.mapper().createArrayNode();
            v.forEach(source -> {
                node.add(source.toString());
            });
            sources.putPOJO(k.toString(), node);
        });
        ObjectNode root = this.mapper().createObjectNode().putPOJO(SOURCES, sources);
        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 3 with McastRoute

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

the class McastRouteWebResource method getRoutes.

/**
 * Get all multicast routes.
 * Returns array of all known multicast routes.
 *
 * @return 200 OK with array of all known multicast routes
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getRoutes() {
    Set<McastRoute> routes = get(MulticastRouteService.class).getRoutes();
    ObjectNode root = encodeArray(McastRoute.class, ROUTES, routes);
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) McastRoute(org.onosproject.mcast.api.McastRoute) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with McastRoute

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

the class McastRouteWebResource method getHostSinks.

/**
 * Get all sink 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 sinks for multicast route
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("sinks/{group}/{srcIp}/{hostId}")
public Response getHostSinks(@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).sinks(route.get(), HostId.hostId(hostId)).forEach(source -> {
            node.add(source.toString());
        });
        ObjectNode root = this.mapper().createObjectNode().putPOJO(SINKS, 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 5 with McastRoute

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

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