use of org.onosproject.net.topology.TopologyCluster in project onos by opennetworkinglab.
the class VirtualNetworkTopologyManagerTest method testGetClusterUsingNullClusterId.
/**
* Test getCluster() method using a null cluster identifier.
*/
@Test(expected = NullPointerException.class)
public void testGetClusterUsingNullClusterId() {
VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class);
Topology topology = topologyService.currentTopology();
Set<TopologyCluster> clusters = topologyService.getClusters(topology);
TopologyCluster cluster = clusters.stream().findFirst().get();
// test the getCluster() method with a null cluster identifier
TopologyCluster cluster1 = topologyService.getCluster(topology, null);
}
use of org.onosproject.net.topology.TopologyCluster in project onos by opennetworkinglab.
the class VirtualNetworkTopologyManagerTest method testGetCluster.
/**
* Test getCluster() method.
*/
@Test
public void testGetCluster() {
VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class);
Topology topology = topologyService.currentTopology();
Set<TopologyCluster> clusters = topologyService.getClusters(topology);
assertNotNull("The clusters should not be null.", clusters);
assertEquals("The clusters size did not match.", 2, clusters.size());
// test the getCluster() method.
TopologyCluster cluster = clusters.stream().findFirst().get();
assertNotNull("The cluster should not be null.", cluster);
TopologyCluster cluster1 = topologyService.getCluster(topology, cluster.id());
assertNotNull("The cluster should not be null.", cluster1);
assertEquals("The cluster ID did not match.", cluster.id(), cluster1.id());
}
use of org.onosproject.net.topology.TopologyCluster in project onos by opennetworkinglab.
the class ClusterDevicesCommand method doExecute.
@Override
protected void doExecute() {
int cid = Integer.parseInt(id);
init();
TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
if (cluster == null) {
error("No such cluster %s", cid);
} else {
List<DeviceId> ids = Lists.newArrayList(service.getClusterDevices(topology, cluster));
Collections.sort(ids, Comparators.ELEMENT_ID_COMPARATOR);
if (outputJson()) {
print("%s", json(new ObjectMapper(), ids));
} else {
for (DeviceId deviceId : ids) {
print("%s", deviceId);
}
}
}
}
use of org.onosproject.net.topology.TopologyCluster in project onos by opennetworkinglab.
the class DefaultTopology method buildTopologyClusters.
// Builds the topology clusters and returns the id-cluster bindings.
private ImmutableMap<ClusterId, TopologyCluster> buildTopologyClusters() {
ImmutableMap.Builder<ClusterId, TopologyCluster> clusterBuilder = ImmutableMap.builder();
SccResult<TopologyVertex, TopologyEdge> results = clusterResults.get();
// Extract both vertexes and edges from the results; the lists form
// pairs along the same index.
List<Set<TopologyVertex>> clusterVertexes = results.clusterVertexes();
List<Set<TopologyEdge>> clusterEdges = results.clusterEdges();
// Scan over the lists and create a cluster from the results.
for (int i = 0, n = results.clusterCount(); i < n; i++) {
Set<TopologyVertex> vertexSet = clusterVertexes.get(i);
Set<TopologyEdge> edgeSet = clusterEdges.get(i);
ClusterId cid = ClusterId.clusterId(i);
DefaultTopologyCluster cluster = new DefaultTopologyCluster(cid, vertexSet.size(), edgeSet.size(), findRoot(vertexSet));
clusterBuilder.put(cid, cluster);
}
return clusterBuilder.build();
}
use of org.onosproject.net.topology.TopologyCluster in project onos by opennetworkinglab.
the class DefaultTopologyTest method clusterRelated.
@Test
public void clusterRelated() {
Set<TopologyCluster> clusters = dt.getClusters();
assertEquals("incorrect cluster count", 2, clusters.size());
TopologyCluster c = dt.getCluster(D1);
Set<DeviceId> devs = dt.getClusterDevices(c);
assertEquals("incorrect cluster device count", 4, devs.size());
assertTrue("cluster should contain D2", devs.contains(D2));
assertFalse("cluster should not contain D5", devs.contains(D5));
}
Aggregations