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