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;
}
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();
}
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();
}
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();
}
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();
}
Aggregations