use of org.opennms.netmgt.model.LldpLink in project opennms by OpenNMS.
the class Nms8000EnIT method reverseLldpLink.
private LldpLink reverseLldpLink(OnmsNode sourcenode, LldpElement element, LldpLink link) {
LldpLink reverseLink = new LldpLink();
reverseLink.setId(-link.getId());
reverseLink.setNode(sourcenode);
reverseLink.setLldpLocalPortNum(0);
reverseLink.setLldpPortId(link.getLldpRemPortId());
reverseLink.setLldpPortIdSubType(link.getLldpRemPortIdSubType());
reverseLink.setLldpPortDescr(link.getLldpRemPortDescr());
if (link.getLldpRemPortIdSubType() == LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL) {
try {
reverseLink.setLldpPortIfindex(Integer.getInteger(link.getLldpRemPortId()));
} catch (Exception e) {
}
}
reverseLink.setLldpRemChassisId(element.getLldpChassisId());
reverseLink.setLldpRemChassisIdSubType(element.getLldpChassisIdSubType());
reverseLink.setLldpRemSysname(element.getLldpSysname());
reverseLink.setLldpRemPortId(link.getLldpPortId());
reverseLink.setLldpRemPortIdSubType(link.getLldpPortIdSubType());
reverseLink.setLldpRemPortDescr(link.getLldpPortDescr());
reverseLink.setLldpLinkCreateTime(link.getLldpLinkCreateTime());
reverseLink.setLldpLinkLastPollTime(link.getLldpLinkLastPollTime());
return reverseLink;
}
use of org.opennms.netmgt.model.LldpLink in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProvider method getLldpLinks.
private void getLldpLinks(Map<Integer, OnmsNode> nodemap, Map<Integer, List<OnmsSnmpInterface>> nodesnmpmap, Map<Integer, OnmsIpInterface> ipprimarymap) {
// Index the nodes by sysName
final Map<String, OnmsNode> nodesbysysname = new HashMap<>();
for (OnmsNode node : nodemap.values()) {
if (node.getSysName() != null) {
nodesbysysname.putIfAbsent(node.getSysName(), node);
}
}
// Index the LLDP elements by node id
Map<Integer, LldpElement> lldpelementmap = new HashMap<Integer, LldpElement>();
for (LldpElement lldpelement : m_lldpElementDao.findAll()) {
lldpelementmap.put(lldpelement.getNode().getId(), lldpelement);
}
// Pull all of the LLDP links and index them by remote chassis id
List<LldpLink> allLinks = m_lldpLinkDao.findAll();
Map<String, List<LldpLink>> linksByRemoteChassisId = new HashMap<>();
for (LldpLink link : allLinks) {
final String remoteChassisId = link.getLldpRemChassisId();
List<LldpLink> linksWithRemoteChassisId = linksByRemoteChassisId.get(remoteChassisId);
if (linksWithRemoteChassisId == null) {
linksWithRemoteChassisId = new ArrayList<>();
linksByRemoteChassisId.put(remoteChassisId, linksWithRemoteChassisId);
}
linksWithRemoteChassisId.add(link);
}
Set<LldpLinkDetail> combinedLinkDetails = new HashSet<LldpLinkDetail>();
Set<Integer> parsed = new HashSet<Integer>();
for (LldpLink sourceLink : allLinks) {
if (parsed.contains(sourceLink.getId())) {
continue;
}
LOG.debug("loadtopology: lldp link with id '{}' link '{}' ", sourceLink.getId(), sourceLink);
LldpElement sourceLldpElement = lldpelementmap.get(sourceLink.getNode().getId());
LldpLink targetLink = null;
// Limit the candidate links by only choosing those have a remote chassis id matching the chassis id of the source link
for (LldpLink link : linksByRemoteChassisId.getOrDefault(sourceLldpElement.getLldpChassisId(), Collections.emptyList())) {
if (parsed.contains(link.getId())) {
continue;
}
if (sourceLink.getId().intValue() == link.getId().intValue()) {
continue;
}
LOG.debug("loadtopology: checking lldp link with id '{}' link '{}' ", link.getId(), link);
LldpElement element = lldpelementmap.get(link.getNode().getId());
// Compare the chassis id on the other end of the link
if (!sourceLink.getLldpRemChassisId().equals(element.getLldpChassisId())) {
continue;
}
boolean bool1 = sourceLink.getLldpRemPortId().equals(link.getLldpPortId()) && link.getLldpRemPortId().equals(sourceLink.getLldpPortId());
boolean bool3 = sourceLink.getLldpRemPortIdSubType() == link.getLldpPortIdSubType() && link.getLldpRemPortIdSubType() == sourceLink.getLldpPortIdSubType();
if (bool1 && bool3) {
targetLink = link;
LOG.info("loadtopology: found lldp mutual link: '{}' and '{}' ", sourceLink, targetLink);
break;
}
}
if (targetLink == null && sourceLink.getLldpRemSysname() != null) {
final OnmsNode node = nodesbysysname.get(sourceLink.getLldpRemSysname());
if (node != null) {
targetLink = reverseLldpLink(node, sourceLldpElement, sourceLink);
LOG.info("loadtopology: found lldp link using lldp rem sysname: '{}' and '{}'", sourceLink, targetLink);
}
}
if (targetLink == null) {
LOG.info("loadtopology: cannot found target node for link: '{}'", sourceLink);
continue;
}
parsed.add(sourceLink.getId());
parsed.add(targetLink.getId());
Vertex source = getOrCreateVertex(nodemap.get(sourceLink.getNode().getId()), ipprimarymap.get(sourceLink.getNode().getId()));
Vertex target = getOrCreateVertex(nodemap.get(targetLink.getNode().getId()), ipprimarymap.get(targetLink.getNode().getId()));
combinedLinkDetails.add(new LldpLinkDetail(Math.min(sourceLink.getId(), targetLink.getId()) + "|" + Math.max(sourceLink.getId(), targetLink.getId()), source, sourceLink, target, targetLink));
}
for (LldpLinkDetail linkDetail : combinedLinkDetails) {
LinkdEdge edge = connectVertices(linkDetail, LLDP_EDGE_NAMESPACE);
edge.setTooltipText(getEdgeTooltipText(linkDetail, nodesnmpmap));
}
}
use of org.opennms.netmgt.model.LldpLink in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProviderTest method testDataCorrectness.
@Test
public void testDataCorrectness() {
LldpLinkDao lldpLinkDao = m_databasePopulator.getLldpLinkDao();
List<LldpLink> links = lldpLinkDao.findAll();
assertEquals(16, links.size());
OspfLinkDao ospfLinkDao = m_databasePopulator.getOspfLinkDao();
List<OspfLink> ospfLinks = ospfLinkDao.findAll();
assertEquals(2, ospfLinks.size());
}
Aggregations