use of org.onosproject.mcast.api.MulticastRouteService in project onos by opennetworkinglab.
the class McastSinkDeleteCommand method doExecute.
@Override
protected void doExecute() {
MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
// Clear all routes
if ("*".equals(sAddr) && "*".equals(gAddr)) {
mcastRouteManager.getRoutes().forEach(mcastRouteManager::remove);
return;
}
// Removing/updating a specific entry
IpAddress sAddrIp = null;
// If the source Ip is * we want ASM so we leave it as null and the route will have it as an optional.empty()
if (!sAddr.equals("*")) {
sAddrIp = IpAddress.valueOf(sAddr);
}
McastRoute mRoute = new McastRoute(sAddrIp, IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
// If the user provides only sAddr and gAddr, we have to remove the route
if (host == null || host.isEmpty()) {
mcastRouteManager.remove(mRoute);
printMcastRoute(D_FORMAT_MAPPING, mRoute);
return;
}
// Otherwise we need to remove a specific sink
HostId hostId = HostId.hostId(host);
if (!mcastRouteManager.getRoutes().contains(mRoute)) {
print("Route is not present, store it first");
return;
}
// Remove the entire host id
mcastRouteManager.removeSink(mRoute, hostId);
// We have done
printMcastRoute(U_FORMAT_MAPPING, mRoute);
}
use of org.onosproject.mcast.api.MulticastRouteService in project onos by opennetworkinglab.
the class McastSourceDeleteCommand method doExecute.
@Override
protected void doExecute() {
MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
// Clear all routes
if ("*".equals(sAddr) && "*".equals(gAddr)) {
mcastRouteManager.getRoutes().forEach(mcastRouteManager::remove);
return;
}
// Removing/updating a specific entry
IpAddress sAddrIp = null;
// If the source Ip is * we want ASM so we leave it as null and the route will have it as an optional.empty()
if (!sAddr.equals("*")) {
sAddrIp = IpAddress.valueOf(sAddr);
}
McastRoute mRoute = new McastRoute(sAddrIp, IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
// No specific connect points, we have to remove everything
if (sourceList == null) {
mcastRouteManager.remove(mRoute);
printMcastRoute(D_FORMAT_MAPPING, mRoute);
return;
}
// Otherwise we need to remove specific connect points
if (!mcastRouteManager.getRoutes().contains(mRoute)) {
print("Route is not present, store it first");
return;
}
for (String hostId : sourceList) {
mcastRouteManager.removeSource(mRoute, HostId.hostId(hostId));
}
printMcastRoute(U_FORMAT_MAPPING, mRoute);
}
use of org.onosproject.mcast.api.MulticastRouteService in project onos by opennetworkinglab.
the class McastHostJoinCommand method doExecute.
@Override
protected void doExecute() {
MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
IpAddress sAddrIp = null;
// If the source Ip is * we want ASM so we leave it as null and the route will have it as an optional.empty()
if (!sAddr.equals("*")) {
sAddrIp = IpAddress.valueOf(sAddr);
}
McastRoute mRoute = new McastRoute(sAddrIp, IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
mcastRouteManager.add(mRoute);
if (sources != null) {
for (String hostId : sources) {
mcastRouteManager.addSource(mRoute, HostId.hostId(hostId));
}
}
if (sinks != null) {
for (String hostId : sinks) {
mcastRouteManager.addSink(mRoute, HostId.hostId(hostId));
}
}
printMcastRoute(mRoute);
}
use of org.onosproject.mcast.api.MulticastRouteService in project onos by opennetworkinglab.
the class McastRoutesListCommand method doExecute.
@Override
protected void doExecute() {
// Get the service
MulticastRouteService mcastService = get(MulticastRouteService.class);
// Get the routes
Set<McastRoute> routes = mcastService.getRoutes();
// Filter ipv4
Set<McastRoute> ipv4Routes = routes.stream().filter(mcastRoute -> mcastRoute.group().isIp4()).collect(Collectors.toSet());
// Filter ipv6
Set<McastRoute> ipv6Routes = routes.stream().filter(mcastRoute -> mcastRoute.group().isIp6()).collect(Collectors.toSet());
// Print header
print(FORMAT_TABLE, "ipv4");
print(FORMAT_ROUTE, "", GROUP, SOURCE, ORIGIN, SOURCES, SINKS);
// Print ipv4 mcast routing entries
ipv4Routes.stream().sorted(Comparator.comparing(McastRoute::group)).forEach(route -> {
// Get sinks and sources
Set<ConnectPoint> sources = mcastService.sources(route);
Set<ConnectPoint> sinks = mcastService.sinks(route);
Optional<IpAddress> sourceIp = route.source();
String src = "* ";
if (sourceIp.isPresent()) {
src = sourceIp.get().toString();
}
print(FORMAT_ROUTE, "", route.group(), src, route.type(), sources.size(), " " + sinks.size());
});
print(FORMAT_TOTAL, ipv4Routes.size());
print("");
// Print header
print(FORMAT_TABLE, "ipv6");
print(FORMAT_ROUTE6, "", GROUP, SOURCE, ORIGIN, SOURCES, SINKS);
// Print ipv6 mcast routing entries
ipv6Routes.stream().sorted(Comparator.comparing(McastRoute::group)).forEach(route -> {
// Get sinks and sources
Set<ConnectPoint> sources = mcastService.sources(route);
Set<ConnectPoint> sinks = mcastService.sinks(route);
Optional<IpAddress> sourceIp = route.source();
String src = "* ";
if (sourceIp.isPresent()) {
src = sourceIp.get().toString();
}
print(FORMAT_ROUTE6, "", route.group(), src, route.type(), sources.size(), " " + sinks.size());
});
print(FORMAT_TOTAL, ipv6Routes.size());
print("");
}
use of org.onosproject.mcast.api.MulticastRouteService in project onos by opennetworkinglab.
the class McastRouteWebResource method createRoutes.
/**
* Creates a set of new multicast routes.
*
* @param stream multicast routes JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel McastRouteBulk
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("bulk/")
public Response createRoutes(InputStream stream) {
MulticastRouteService service = get(MulticastRouteService.class);
try {
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
ArrayNode routesArray = nullIsIllegal((ArrayNode) jsonTree.get(ROUTES), ROUTES_KEY_ERROR);
routesArray.forEach(routeJson -> {
McastRoute route = codec(McastRoute.class).decode((ObjectNode) routeJson, this);
service.add(route);
Set<HostId> sources = new HashSet<>();
routeJson.path(SOURCES).elements().forEachRemaining(src -> {
sources.add(HostId.hostId(src.asText()));
});
Set<HostId> sinks = new HashSet<>();
routeJson.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();
}
Aggregations