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