use of org.opennms.features.topology.api.topo.SimpleLeafVertex in project opennms by OpenNMS.
the class AbstractLinkdTopologyProvider method getVertex.
protected AbstractVertex getVertex(Integer nodeId, String ip, String sysobjectId, String nodeLabel, String tooltipText) {
AbstractVertex vertex = new SimpleLeafVertex(TOPOLOGY_NAMESPACE_LINKD, nodeId.toString(), 0, 0);
vertex.setIconKey(getIconName(sysobjectId));
vertex.setLabel(nodeLabel);
vertex.setIpAddress(ip);
vertex.setNodeID(nodeId);
vertex.setTooltipText(tooltipText);
return vertex;
}
use of org.opennms.features.topology.api.topo.SimpleLeafVertex in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProviderTest method testConnectVertices.
@Test
public void testConnectVertices() {
m_topologyProvider.resetContainer();
Vertex vertexId = m_topologyProvider.addVertex(0, 0);
assertEquals(1, m_topologyProvider.getVertices().size());
Vertex vertex0 = m_topologyProvider.getVertices().iterator().next();
assertEquals("v0", vertex0.getId());
Vertex vertex1 = m_topologyProvider.addVertex(0, 0);
assertEquals(2, m_topologyProvider.getVertices().size());
Edge edgeId = m_topologyProvider.connectVertices(vertex0, vertex1);
assertEquals(1, m_topologyProvider.getEdges().size());
SimpleLeafVertex sourceLeafVert = (SimpleLeafVertex) edgeId.getSource().getVertex();
SimpleLeafVertex targetLeafVert = (SimpleLeafVertex) edgeId.getTarget().getVertex();
assertEquals("v0", sourceLeafVert.getId());
assertEquals("v1", targetLeafVert.getId());
EdgeRef[] edgeIds = m_topologyProvider.getEdgeIdsForVertex(vertexId);
assertEquals(1, edgeIds.length);
assertEquals(edgeId, edgeIds[0]);
}
use of org.opennms.features.topology.api.topo.SimpleLeafVertex in project opennms by OpenNMS.
the class SFreeTopologyProvider method createERRandomTopology.
private void createERRandomTopology(int numberOfNodes, double averageNumberofNeighboors) {
Map<Integer, SimpleLeafVertex> nodes = new HashMap<Integer, SimpleLeafVertex>();
List<AbstractEdge> edges = new ArrayList<>();
for (Integer i = 0; i < numberOfNodes; i++) {
SimpleLeafVertex vertex = new SimpleLeafVertex(TOPOLOGY_NAMESPACE_SFREE, Integer.toString(i), 0, 0);
vertex.setIconKey("sfree.system");
vertex.setLabel("ErdosReniyNode" + i);
nodes.put(i, vertex);
}
Double z = 0.5 * (numberOfNodes - 1);
// Double p = averageNumberofNeighboors/z;
Random r = new Random((new Date()).getTime());
for (Integer start = 0; start < numberOfNodes; start++) {
for (Integer end = start + 1; end < numberOfNodes; end++) {
if (z * r.nextDouble() < averageNumberofNeighboors) {
String edgeId = "link:" + start + "-" + end;
SimpleConnector source = new SimpleConnector(TOPOLOGY_NAMESPACE_SFREE, nodes.get(start).getId() + "-" + edgeId + "-connector", nodes.get(start));
SimpleConnector target = new SimpleConnector(TOPOLOGY_NAMESPACE_SFREE, nodes.get(end).getId() + "-" + edgeId + "-connector", nodes.get(end));
edges.add(new AbstractEdge(TOPOLOGY_NAMESPACE_SFREE, edgeId, source, target));
}
}
}
addVertices(nodes.values().toArray(new Vertex[] {}));
addEdges(edges.toArray(new Edge[] {}));
}
use of org.opennms.features.topology.api.topo.SimpleLeafVertex in project opennms by OpenNMS.
the class SFreeTopologyProvider method createBARandomTopology.
private void createBARandomTopology(int numberOfNodes, double averageNumberofNeighboors) {
Map<Integer, SimpleLeafVertex> nodes = new HashMap<Integer, SimpleLeafVertex>();
List<AbstractEdge> edges = new ArrayList<>();
for (int i = 0; i < 2 * averageNumberofNeighboors; i++) {
LOG.debug("Creating First Cluster from: {}", i);
int j = (i + 1) % ((int) Math.round(2 * averageNumberofNeighboors));
SimpleLeafVertex vertexi = new SimpleLeafVertex(TOPOLOGY_NAMESPACE_SFREE, Integer.toString(i), 0, 0);
vertexi.setIconKey("sfree.system");
vertexi.setLabel("BarabasiAlbertNode" + i);
if (!nodes.containsKey(i)) {
nodes.put(i, vertexi);
LOG.debug("Added Node: {}", vertexi.getId());
}
SimpleLeafVertex vertexj = new SimpleLeafVertex(TOPOLOGY_NAMESPACE_SFREE, Integer.toString(j), 0, 0);
vertexj.setIconKey("sfree.system");
vertexj.setLabel("BarabasiAlbertNode" + j);
if (!nodes.containsKey(j)) {
nodes.put(j, vertexj);
LOG.debug("Added Node: {}", vertexj.getId());
}
String edgeId = "link:" + i + "-" + j;
SimpleConnector source = new SimpleConnector(TOPOLOGY_NAMESPACE_SFREE, nodes.get(i).getId() + "-" + edgeId + "-connector", nodes.get(i));
SimpleConnector target = new SimpleConnector(TOPOLOGY_NAMESPACE_SFREE, nodes.get(j).getId() + "-" + edgeId + "-connector", nodes.get(j));
edges.add(new AbstractEdge(TOPOLOGY_NAMESPACE_SFREE, edgeId, source, target));
LOG.debug("Added Link: {}", edgeId);
}
Random r = new Random((new Date()).getTime());
for (int i = ((int) Math.floor(2 * averageNumberofNeighboors)); i < numberOfNodes; i++) {
SimpleLeafVertex vertexi = new SimpleLeafVertex(TOPOLOGY_NAMESPACE_SFREE, Integer.toString(i), 0, 0);
vertexi.setIconKey("sfree.system");
vertexi.setLabel("BarabasiAlbertNode" + i);
nodes.put(i, vertexi);
LOG.debug("Adding Node: {}", i);
for (int times = 0; times < averageNumberofNeighboors; times++) {
AbstractEdge edge;
// choose node to attach to
double d = r.nextDouble() * nodes.size();
LOG.debug("Generated random position: {}", d);
Long j = (long) d;
LOG.debug("Try Adding edge: {}--->{}", j, i);
String edgeId = "link:" + i + "-" + j.intValue();
SimpleConnector source = new SimpleConnector(TOPOLOGY_NAMESPACE_SFREE, nodes.get(i).getId() + "-" + edgeId + "-connector", nodes.get(i));
SimpleConnector target = new SimpleConnector(TOPOLOGY_NAMESPACE_SFREE, nodes.get(j.intValue()).getId() + "-" + edgeId + "-connector", nodes.get(j.intValue()));
edge = new AbstractEdge(TOPOLOGY_NAMESPACE_SFREE, edgeId, source, target);
if (i == j.intValue())
continue;
edges.add(edge);
}
// m links added
}
addVertices(nodes.values().toArray(new Vertex[] {}));
addEdges(edges.toArray(new Edge[] {}));
}
Aggregations