Search in sources :

Example 21 with LldpLink

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;
}
Also used : LldpLink(org.opennms.netmgt.model.LldpLink)

Example 22 with LldpLink

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));
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) OnmsNode(org.opennms.netmgt.model.OnmsNode) HashMap(java.util.HashMap) LldpElement(org.opennms.netmgt.model.LldpElement) LldpLink(org.opennms.netmgt.model.LldpLink) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 23 with LldpLink

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());
}
Also used : OspfLinkDao(org.opennms.netmgt.dao.api.OspfLinkDao) LldpLinkDao(org.opennms.netmgt.dao.api.LldpLinkDao) LldpLink(org.opennms.netmgt.model.LldpLink) OspfLink(org.opennms.netmgt.model.OspfLink) Test(org.junit.Test)

Aggregations

LldpLink (org.opennms.netmgt.model.LldpLink)23 Test (org.junit.Test)16 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)14 OnmsNode (org.opennms.netmgt.model.OnmsNode)12 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)7 ArrayList (java.util.ArrayList)5 LldpLocPortGetter (org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter)5 LldpRemTableTracker (org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker)4 LldpElement (org.opennms.netmgt.model.LldpElement)3 OspfLink (org.opennms.netmgt.model.OspfLink)3 HashSet (java.util.HashSet)2 ExecutionException (java.util.concurrent.ExecutionException)2 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)2 Vertex (org.opennms.features.topology.api.topo.Vertex)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Before (org.junit.Before)1 EqRestriction (org.opennms.core.criteria.restrictions.EqRestriction)1 JUnitSnmpAgent (org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)1