Search in sources :

Example 1 with McastRoute

use of org.onosproject.net.mcast.McastRoute in project onos by opennetworkinglab.

the class McastDeleteCommand method doExecute.

@Override
protected void doExecute() {
    MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
    if ("*".equals(sAddr) && "*".equals(gAddr)) {
        // Clear all routes
        mcastRouteManager.getRoutes().forEach(mcastRouteManager::remove);
        return;
    }
    McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr), IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
    if (egressList == null) {
        mcastRouteManager.remove(mRoute);
        print(D_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source());
    } else {
        // check list for validity before we begin to delete.
        for (String egress : egressList) {
            ConnectPoint eCp = ConnectPoint.deviceConnectPoint(egress);
            mcastRouteManager.removeSink(mRoute, eCp);
        }
        print(U_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source());
    }
}
Also used : MulticastRouteService(org.onosproject.net.mcast.MulticastRouteService) McastRoute(org.onosproject.net.mcast.McastRoute) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 2 with McastRoute

use of org.onosproject.net.mcast.McastRoute in project onos by opennetworkinglab.

the class McastJoinCommand method doExecute.

@Override
protected void doExecute() {
    MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
    McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr), IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
    mcastRouteManager.add(mRoute);
    if (ingressPort != null) {
        ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressPort);
        mcastRouteManager.addSource(mRoute, ingress);
    }
    if (ports != null) {
        for (String egCP : ports) {
            ConnectPoint egress = ConnectPoint.deviceConnectPoint(egCP);
            mcastRouteManager.addSink(mRoute, egress);
        }
    }
    printMcastRoute(mRoute);
}
Also used : MulticastRouteService(org.onosproject.net.mcast.MulticastRouteService) McastRoute(org.onosproject.net.mcast.McastRoute) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 3 with McastRoute

use of org.onosproject.net.mcast.McastRoute in project onos by opennetworkinglab.

the class PimInterfaceManager method getSourceInterface.

private PimInterface getSourceInterface(McastRoute route) {
    Route unicastRoute = unicastRouteService.longestPrefixMatch(route.source());
    if (unicastRoute == null) {
        log.warn("No route to source {}", route.source());
        return null;
    }
    Interface intf = interfaceService.getMatchingInterface(unicastRoute.nextHop());
    if (intf == null) {
        log.warn("No interface with route to next hop {}", unicastRoute.nextHop());
        return null;
    }
    PimInterface pimInterface = pimInterfaces.get(intf.connectPoint());
    if (pimInterface == null) {
        log.warn("PIM is not enabled on interface {}", intf);
        return null;
    }
    Set<Host> hosts = hostService.getHostsByIp(unicastRoute.nextHop());
    Host host = null;
    for (Host h : hosts) {
        if (h.vlan().equals(intf.vlan())) {
            host = h;
        }
    }
    if (host == null) {
        log.warn("Next hop host entry not found: {}", unicastRoute.nextHop());
        return null;
    }
    pimInterface.addRoute(route, unicastRoute.nextHop(), host.mac());
    return pimInterface;
}
Also used : Host(org.onosproject.net.Host) Route(org.onosproject.routeservice.Route) McastRoute(org.onosproject.net.mcast.McastRoute) Interface(org.onosproject.net.intf.Interface)

Example 4 with McastRoute

use of org.onosproject.net.mcast.McastRoute in project onos by opennetworkinglab.

the class MulticastRouteWebResource method addSinks.

/**
 * Create a sink for a multicast route.
 * Creates a new sink for an existing multicast route.
 *
 * @onos.rsModel McastSinkPost
 * @param group group IP address
 * @param source source IP address
 * @param stream sink JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("sinks/{group}/{source}")
public Response addSinks(@PathParam("group") String group, @PathParam("source") String source, InputStream stream) {
    MulticastRouteService service = get(MulticastRouteService.class);
    try {
        McastRoute route = new McastRoute(IpAddress.valueOf(source), IpAddress.valueOf(group), McastRoute.Type.STATIC);
        ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
        jsonTree.path("sinks").forEach(node -> {
            ConnectPoint sink = ConnectPoint.deviceConnectPoint(node.asText());
            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.net.mcast.MulticastRouteService) McastRoute(org.onosproject.net.mcast.McastRoute) IOException(java.io.IOException) ConnectPoint(org.onosproject.net.ConnectPoint) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 5 with McastRoute

use of org.onosproject.net.mcast.McastRoute in project onos by opennetworkinglab.

the class MulticastRouteResourceTest method testMcastRoutePopulatedArray.

/**
 * Tests the results of the REST API GET when there are active mcastroutes.
 */
@Test
public void testMcastRoutePopulatedArray() {
    initMcastRouteMocks();
    final Set<McastRoute> mcastRoutes = ImmutableSet.of(route1, route2, route3);
    expect(mockMulticastRouteService.getRoutes()).andReturn(mcastRoutes).anyTimes();
    replay(mockMulticastRouteService);
    final WebTarget wt = target();
    final String response = wt.path("mcast").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());
    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("routes"));
    final JsonArray jsonMcastRoutes = result.get("routes").asArray();
    assertThat(jsonMcastRoutes, notNullValue());
    assertThat(jsonMcastRoutes, hasMcastRoute(route1));
    assertThat(jsonMcastRoutes, hasMcastRoute(route2));
    assertThat(jsonMcastRoutes, hasMcastRoute(route3));
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) McastRoute(org.onosproject.net.mcast.McastRoute) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Aggregations

McastRoute (org.onosproject.net.mcast.McastRoute)12 MulticastRouteService (org.onosproject.net.mcast.MulticastRouteService)8 ConnectPoint (org.onosproject.net.ConnectPoint)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 IOException (java.io.IOException)3 Consumes (javax.ws.rs.Consumes)3 Produces (javax.ws.rs.Produces)3 IpAddress (org.onlab.packet.IpAddress)3 Comparator (java.util.Comparator)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 POST (javax.ws.rs.POST)2 Command (org.apache.karaf.shell.api.action.Command)2 Service (org.apache.karaf.shell.api.action.lifecycle.Service)2 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)2 JsonArray (com.eclipsesource.json.JsonArray)1 JsonObject (com.eclipsesource.json.JsonObject)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1