Search in sources :

Example 1 with TopologyCluster

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);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) Topology(org.onosproject.net.topology.Topology) TopologyCluster(org.onosproject.net.topology.TopologyCluster) TopologyService(org.onosproject.net.topology.TopologyService) Test(org.junit.Test)

Example 2 with TopologyCluster

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());
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) Topology(org.onosproject.net.topology.Topology) TopologyCluster(org.onosproject.net.topology.TopologyCluster) TopologyService(org.onosproject.net.topology.TopologyService) Test(org.junit.Test)

Example 3 with TopologyCluster

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);
            }
        }
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) TopologyCluster(org.onosproject.net.topology.TopologyCluster) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with TopologyCluster

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();
}
Also used : DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) TopologyVertex(org.onosproject.net.topology.TopologyVertex) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ClusterId(org.onosproject.net.topology.ClusterId) TopologyCluster(org.onosproject.net.topology.TopologyCluster) DefaultTopologyCluster(org.onosproject.net.topology.DefaultTopologyCluster) TopologyEdge(org.onosproject.net.topology.TopologyEdge) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultTopologyCluster(org.onosproject.net.topology.DefaultTopologyCluster)

Example 5 with TopologyCluster

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));
}
Also used : DeviceId(org.onosproject.net.DeviceId) TopologyCluster(org.onosproject.net.topology.TopologyCluster) Test(org.junit.Test)

Aggregations

TopologyCluster (org.onosproject.net.topology.TopologyCluster)19 Topology (org.onosproject.net.topology.Topology)11 TopologyService (org.onosproject.net.topology.TopologyService)10 Test (org.junit.Test)7 DeviceId (org.onosproject.net.DeviceId)6 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)5 Link (org.onosproject.net.Link)5 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 ConnectPoint (org.onosproject.net.ConnectPoint)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 DefaultTopologyCluster (org.onosproject.net.topology.DefaultTopologyCluster)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 VirtualLink (org.onosproject.incubator.net.virtual.VirtualLink)2 DefaultTopologyVertex (org.onosproject.net.topology.DefaultTopologyVertex)2 TopologyEdge (org.onosproject.net.topology.TopologyEdge)2 TopologyVertex (org.onosproject.net.topology.TopologyVertex)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1