use of org.opennms.netmgt.model.topology.SharedSegment in project opennms by OpenNMS.
the class EnLinkdIT method testLoadTopology.
@Test
public void testLoadTopology() {
final OnmsMonitoringLocation location = new OnmsMonitoringLocation(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID);
ABCTopology topology = new ABCTopology();
OnmsNode lnodeA = topology.nodeA;
lnodeA.setForeignSource("linkd");
lnodeA.setForeignId("nodeA");
lnodeA.setLabel("nodeA");
lnodeA.setLocation(location);
OnmsNode lnodeB = topology.nodeB;
lnodeB.setForeignSource("linkd");
lnodeB.setForeignId("nodeB");
lnodeB.setLabel("nodeB");
lnodeB.setLocation(location);
OnmsNode lnodeC = topology.nodeC;
lnodeC.setForeignSource("linkd");
lnodeC.setForeignId("nodeC");
lnodeC.setLabel("nodeC");
lnodeC.setLocation(location);
m_nodeDao.save(lnodeA);
m_nodeDao.save(lnodeB);
m_nodeDao.save(lnodeC);
OnmsNode nodeA = m_nodeDao.findByForeignId("linkd", "nodeA");
OnmsNode nodeB = m_nodeDao.findByForeignId("linkd", "nodeB");
OnmsNode nodeC = m_nodeDao.findByForeignId("linkd", "nodeC");
topology.nodeAId = nodeA.getId();
topology.nodeBId = nodeB.getId();
topology.nodeCId = nodeC.getId();
topology.nodeA = nodeA;
topology.nodeB = nodeB;
topology.nodeC = nodeC;
BridgeBridgeLink ablink = new BridgeBridgeLink();
ablink.setNode(nodeA);
ablink.setBridgePort(topology.portAB);
ablink.setDesignatedNode(nodeB);
ablink.setDesignatedPort(topology.portBA);
ablink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(ablink);
BridgeBridgeLink bclink = new BridgeBridgeLink();
bclink.setNode(nodeC);
bclink.setBridgePort(topology.portCB);
bclink.setDesignatedNode(nodeB);
bclink.setDesignatedPort(topology.portBC);
bclink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(bclink);
BridgeMacLink mac1 = new BridgeMacLink();
mac1.setNode(nodeA);
mac1.setBridgePort(topology.portA);
mac1.setMacAddress(topology.mac1);
mac1.setBridgeMacLinkLastPollTime(mac1.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(mac1);
BridgeMacLink mac2 = new BridgeMacLink();
mac2.setNode(nodeB);
mac2.setBridgePort(topology.portB);
mac2.setMacAddress(topology.mac2);
mac2.setBridgeMacLinkLastPollTime(mac2.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(mac2);
BridgeMacLink mac3 = new BridgeMacLink();
mac3.setNode(nodeC);
mac3.setBridgePort(topology.portC);
mac3.setMacAddress(topology.mac3);
mac3.setBridgeMacLinkLastPollTime(mac3.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(mac3);
m_bridgeMacLinkDao.flush();
m_bridgeBridgeLinkDao.flush();
assertEquals(3, m_bridgeMacLinkDao.countAll());
assertEquals(2, m_bridgeBridgeLinkDao.countAll());
assertNotNull(m_bridgeTopologyDao);
m_linkd.getQueryManager().loadBridgeTopology();
assertEquals(1, m_bridgeTopologyDao.getAll().size());
BroadcastDomain nodeAbd = m_linkd.getQueryManager().getBroadcastDomain(nodeA.getId().intValue());
assertNotNull(nodeAbd);
BroadcastDomain nodeBbd = m_linkd.getQueryManager().getBroadcastDomain(nodeB.getId().intValue());
BroadcastDomain nodeCbd = m_linkd.getQueryManager().getBroadcastDomain(nodeC.getId().intValue());
assertEquals(nodeAbd, nodeBbd);
assertEquals(nodeAbd, nodeCbd);
nodeAbd.hierarchySetUp(nodeAbd.getBridge(nodeA.getId()));
topology.check(nodeAbd);
List<SharedSegment> nodeASegments = m_bridgeTopologyDao.getBridgeNodeSharedSegments(m_bridgeBridgeLinkDao, m_bridgeMacLinkDao, nodeA.getId());
assertEquals(2, nodeASegments.size());
for (SharedSegment segment : nodeASegments) {
System.err.println(segment.printTopology());
}
}
use of org.opennms.netmgt.model.topology.SharedSegment in project opennms by OpenNMS.
the class BroadcastDomainTest method testCleanTopology.
@Test
public void testCleanTopology() {
TwoBridgeWithBackbonePortsTopology topology = new TwoBridgeWithBackbonePortsTopology();
BroadcastDomain domain = new BroadcastDomain();
domain.addBridge(new Bridge(topology.nodeAId));
domain.addBridge(new Bridge(topology.nodeBId));
domain.setBridgeElements(topology.elemlist);
NodeDiscoveryBridgeTopology ndbt = new NodeDiscoveryBridgeTopology(linkd, new Node(topology.nodeAId, null, null, null, location));
ndbt.setDomain(domain);
ndbt.addUpdatedBFT(domain.getBridge(topology.nodeAId), topology.bftA);
ndbt.addUpdatedBFT(domain.getBridge(topology.nodeBId), topology.bftB);
ndbt.calculate();
domain.clearTopologyForBridge(topology.nodeBId);
assertEquals(topology.nodeAId.intValue(), domain.getRootBridge().getId().intValue());
assertEquals(2, domain.getTopology().size());
assertEquals(5, domain.getMacsOnDomain().size());
for (SharedSegment segment : domain.getTopology()) {
assertEquals(0, segment.getBridgeBridgeLinks().size());
assertEquals(1, segment.getBridgeIdsOnSegment().size());
assertEquals(topology.nodeAId.intValue(), segment.getBridgeIdsOnSegment().iterator().next().intValue());
if (segment.containsMac(topology.macA11) && segment.containsMac(topology.macA12)) {
assertEquals(2, segment.getMacsOnSegment().size());
assertEquals(2, segment.getBridgeMacLinks().size());
for (BridgeMacLink link : segment.getBridgeMacLinks()) {
assertEquals(topology.portA1.intValue(), link.getBridgePort().intValue());
}
} else if (segment.containsMac(topology.macB21) && segment.containsMac(topology.macB22) && segment.containsMac(topology.macAB)) {
assertEquals(3, segment.getMacsOnSegment().size());
assertEquals(3, segment.getBridgeMacLinks().size());
for (BridgeMacLink link : segment.getBridgeMacLinks()) {
assertEquals(topology.portAB.intValue(), link.getBridgePort().intValue());
}
} else {
assertEquals(true, false);
}
}
}
use of org.opennms.netmgt.model.topology.SharedSegment in project opennms by OpenNMS.
the class BroadcastDomainTest method testTwoBridgeTwoCalculation.
@Test
public void testTwoBridgeTwoCalculation() {
TwoNodeTopology topology = new TwoNodeTopology();
BroadcastDomain domain = new BroadcastDomain();
domain.addBridge(new Bridge(topology.nodeBId));
domain.setBridgeElements(topology.elemlist);
NodeDiscoveryBridgeTopology ndbt = new NodeDiscoveryBridgeTopology(linkd, new Node(topology.nodeAId, null, null, null, location));
ndbt.setDomain(domain);
ndbt.addUpdatedBFT(domain.getBridge(topology.nodeBId), topology.bftB);
ndbt.calculate();
printBridgeTopology(ndbt.getDomain());
List<SharedSegment> shsegs = ndbt.getDomain().getTopology();
assertEquals(3, shsegs.size());
domain.addBridge(new Bridge(topology.nodeAId));
domain.setBridgeElements(topology.elemlist);
ndbt.addUpdatedBFT(domain.getBridge(topology.nodeAId), topology.bftA);
ndbt.calculate();
topology.check2nodeTopology(ndbt.getDomain(), true);
assertEquals(topology.nodeBId, domain.getRootBridgeId());
}
use of org.opennms.netmgt.model.topology.SharedSegment in project opennms by OpenNMS.
the class EnLinkdElementFactory method getBridgeLinks.
@Override
public Collection<BridgeLinkNode> getBridgeLinks(int nodeId) {
List<BridgeLinkNode> bridgelinks = new ArrayList<BridgeLinkNode>();
for (SharedSegment segment : m_bridgetopologyDao.getBridgeNodeSharedSegments(m_bridgeBridgeLinkDao, m_bridgeMacLinkDao, nodeId)) {
bridgelinks.add(convertFromModel(nodeId, segment));
}
Collections.sort(bridgelinks);
return bridgelinks;
}
use of org.opennms.netmgt.model.topology.SharedSegment in project opennms by OpenNMS.
the class EnLinkdElementFactory method getNodeLinks.
@Override
public Collection<NodeLinkBridge> getNodeLinks(int nodeId) {
Map<String, Set<InetAddress>> mactoIpMap = new HashMap<String, Set<InetAddress>>();
for (OnmsIpInterface ip : m_ipInterfaceDao.findByNodeId(nodeId)) {
for (IpNetToMedia ipnetomedia : m_ipNetToMediaDao.findByNetAddress(ip.getIpAddress())) {
if (!mactoIpMap.containsKey(ipnetomedia.getPhysAddress()))
mactoIpMap.put(ipnetomedia.getPhysAddress(), new HashSet<InetAddress>());
mactoIpMap.get(ipnetomedia.getPhysAddress()).add(ip.getIpAddress());
}
}
List<NodeLinkBridge> nodelinks = new ArrayList<NodeLinkBridge>();
for (String mac : mactoIpMap.keySet()) {
SharedSegment segment = m_bridgetopologyDao.getHostNodeSharedSegment(m_bridgeBridgeLinkDao, m_bridgeMacLinkDao, mac);
if (segment.isEmpty())
continue;
if (!segment.containsMac(mac))
continue;
nodelinks.add(convertFromModel(mac, segment, getNodePortString(mactoIpMap.get(mac), mac)));
}
Collections.sort(nodelinks);
return nodelinks;
}
Aggregations