Search in sources :

Example 11 with McastRoute

use of org.onosproject.mcast.api.McastRoute 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);
}
Also used : MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) IpAddress(org.onlab.packet.IpAddress) McastRoute(org.onosproject.mcast.api.McastRoute) HostId(org.onosproject.net.HostId)

Example 12 with McastRoute

use of org.onosproject.mcast.api.McastRoute 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);
}
Also used : MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) IpAddress(org.onlab.packet.IpAddress) McastRoute(org.onosproject.mcast.api.McastRoute)

Example 13 with McastRoute

use of org.onosproject.mcast.api.McastRoute 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);
}
Also used : MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) IpAddress(org.onlab.packet.IpAddress) McastRoute(org.onosproject.mcast.api.McastRoute)

Example 14 with McastRoute

use of org.onosproject.mcast.api.McastRoute 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("");
}
Also used : McastRoute(org.onosproject.mcast.api.McastRoute) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) Set(java.util.Set) MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) Comparator(java.util.Comparator) Collectors(java.util.stream.Collectors) Command(org.apache.karaf.shell.api.action.Command) IpAddress(org.onlab.packet.IpAddress) ConnectPoint(org.onosproject.net.ConnectPoint) MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) IpAddress(org.onlab.packet.IpAddress) McastRoute(org.onosproject.mcast.api.McastRoute) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 15 with McastRoute

use of org.onosproject.mcast.api.McastRoute 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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) McastRoute(org.onosproject.mcast.api.McastRoute) 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)

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