use of org.onosproject.mcast.api.McastRoute in project onos by opennetworkinglab.
the class McastRouteWebResource method addSources.
/**
* Adds sources 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 McastSourcesAdd
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("sources/{group}/{srcIp}")
public Response addSources(@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(SOURCES);
Set<HostId> sources = new HashSet<>();
jsonTree.elements().forEachRemaining(src -> {
sources.add(HostId.hostId(src.asText()));
});
if (!sources.isEmpty()) {
sources.forEach(src -> {
service.addSource(route.get(), src);
});
}
} 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 deleteRoutes.
/**
* Removes all the given multicast routes.
*
* @param stream the set of multicast routes
* @return 204 NO CONTENT
*/
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("bulk/")
public Response deleteRoutes(InputStream stream) {
MulticastRouteService service = get(MulticastRouteService.class);
try {
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
ArrayNode routesArray = nullIsIllegal((ArrayNode) jsonTree.get(ROUTES), ROUTES_KEY_ERROR);
List<McastRoute> routes = codec(McastRoute.class).decode(routesArray, this);
routes.forEach(service::remove);
} catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
return Response.noContent().build();
}
use of org.onosproject.mcast.api.McastRoute in project onos by opennetworkinglab.
the class McastRouteWebResource method getHostSources.
/**
* Get all source 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 sources for multicast route
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("sources/{group}/{srcIp}/{hostId}")
public Response getHostSources(@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).sources(route.get(), HostId.hostId(hostId)).forEach(source -> {
node.add(source.toString());
});
ObjectNode root = this.mapper().createObjectNode().putPOJO(SOURCES, 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 createRoute.
/**
* Create new multicast route.
*
* @param stream multicast route JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel McastRoute
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response createRoute(InputStream stream) {
MulticastRouteService service = get(MulticastRouteService.class);
try {
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
McastRoute route = codec(McastRoute.class).decode(jsonTree, this);
service.add(route);
Set<HostId> sources = new HashSet<>();
jsonTree.path(SOURCES).elements().forEachRemaining(src -> {
sources.add(HostId.hostId(src.asText()));
});
Set<HostId> sinks = new HashSet<>();
jsonTree.path(SINKS).elements().forEachRemaining(sink -> {
sinks.add(HostId.hostId(sink.asText()));
});
if (!sources.isEmpty()) {
sources.forEach(source -> {
service.addSource(route, source);
});
}
if (!sinks.isEmpty()) {
sinks.forEach(sink -> {
service.addSink(route, sink);
});
}
} catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
return Response.created(URI.create("")).build();
}
use of org.onosproject.mcast.api.McastRoute in project onos by opennetworkinglab.
the class McastShowHostCommand method doExecute.
@Override
protected void doExecute() {
// Get the service
MulticastRouteService mcastService = get(MulticastRouteService.class);
// Get the routes
Set<McastRoute> routes = mcastService.getRoutes();
// Verify mcast group
if (!isNullOrEmpty(gAddr)) {
// Let's find the group
IpAddress mcastGroup = IpAddress.valueOf(gAddr);
McastRoute mcastRoute = routes.stream().filter(route -> route.group().equals(mcastGroup)).findAny().orElse(null);
// If it exists
if (mcastRoute != null) {
prepareResult(mcastService, mcastRoute);
}
} else {
routes.stream().filter(mcastRoute -> mcastRoute.group().isIp4()).sorted(Comparator.comparing(McastRoute::group)).forEach(route -> {
prepareResult(mcastService, route);
});
routes.stream().filter(mcastRoute -> mcastRoute.group().isIp6()).sorted(Comparator.comparing(McastRoute::group)).forEach(route -> {
prepareResult(mcastService, route);
});
}
if (outputJson()) {
print("%s", routesNode);
} else {
print("%s", routesBuilder.toString());
}
}
Aggregations