Search in sources :

Example 1 with CdpElement

use of org.opennms.netmgt.model.CdpElement in project opennms by OpenNMS.

the class EnhancedLinkdServiceImpl method reconcileCdp.

@Override
public void reconcileCdp(int nodeId, Date now) {
    CdpElement element = m_cdpElementDao.findByNodeId(nodeId);
    if (element != null && element.getCdpNodeLastPollTime().getTime() < now.getTime()) {
        m_cdpElementDao.delete(element);
        m_cdpElementDao.flush();
    }
    m_cdpLinkDao.deleteByNodeIdOlderThen(nodeId, now);
    m_cdpLinkDao.flush();
}
Also used : CdpElement(org.opennms.netmgt.model.CdpElement)

Example 2 with CdpElement

use of org.opennms.netmgt.model.CdpElement in project opennms by OpenNMS.

the class EnhancedLinkdServiceImpl method store.

@Override
@Transactional
public void store(int nodeId, CdpElement element) {
    if (element == null)
        return;
    final OnmsNode node = m_nodeDao.get(nodeId);
    if (node == null)
        return;
    CdpElement dbelement = node.getCdpElement();
    if (dbelement != null) {
        dbelement.merge(element);
        node.setCdpElement(dbelement);
    } else {
        element.setNode(node);
        element.setCdpNodeLastPollTime(element.getCdpNodeCreateTime());
        node.setCdpElement(element);
    }
    m_nodeDao.saveOrUpdate(node);
    m_nodeDao.flush();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) CdpElement(org.opennms.netmgt.model.CdpElement) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with CdpElement

use of org.opennms.netmgt.model.CdpElement in project opennms by OpenNMS.

the class EnhancedLinkdTopologyProvider method getCdpLinks.

private void getCdpLinks(Map<Integer, OnmsNode> nodemap, Map<Integer, List<OnmsSnmpInterface>> nodesnmpmap, Map<Integer, OnmsIpInterface> ipprimarymap, Map<InetAddress, OnmsIpInterface> ipmap) {
    Map<Integer, CdpElement> cdpelementmap = new HashMap<Integer, CdpElement>();
    for (CdpElement cdpelement : m_cdpElementDao.findAll()) {
        cdpelementmap.put(cdpelement.getNode().getId(), cdpelement);
    }
    List<CdpLink> allLinks = m_cdpLinkDao.findAll();
    Set<CdpLinkDetail> combinedLinkDetails = new HashSet<CdpLinkDetail>();
    Set<Integer> parsed = new HashSet<Integer>();
    for (CdpLink sourceLink : allLinks) {
        if (parsed.contains(sourceLink.getId()))
            continue;
        LOG.debug("loadtopology: cdp link with id '{}' link '{}' ", sourceLink.getId(), sourceLink);
        CdpElement sourceCdpElement = cdpelementmap.get(sourceLink.getNode().getId());
        CdpLink targetLink = null;
        for (CdpLink link : allLinks) {
            if (sourceLink.getId().intValue() == link.getId().intValue() || parsed.contains(link.getId()))
                continue;
            LOG.debug("loadtopology: checking cdp link with id '{}' link '{}' ", link.getId(), link);
            CdpElement element = cdpelementmap.get(link.getNode().getId());
            // Compare the remote data to the targetNode element data
            if (!sourceLink.getCdpCacheDeviceId().equals(element.getCdpGlobalDeviceId()) || !link.getCdpCacheDeviceId().equals(sourceCdpElement.getCdpGlobalDeviceId()))
                continue;
            if (sourceLink.getCdpInterfaceName().equals(link.getCdpCacheDevicePort()) && link.getCdpInterfaceName().equals(sourceLink.getCdpCacheDevicePort())) {
                targetLink = link;
                LOG.info("loadtopology: found cdp mutual link: '{}' and '{}' ", sourceLink, targetLink);
                break;
            }
        }
        if (targetLink == null) {
            if (sourceLink.getCdpCacheAddressType() == CiscoNetworkProtocolType.ip) {
                try {
                    InetAddress targetAddress = InetAddressUtils.addr(sourceLink.getCdpCacheAddress());
                    if (ipmap.containsKey(targetAddress)) {
                        targetLink = reverseCdpLink(ipmap.get(targetAddress), sourceCdpElement, sourceLink);
                        LOG.info("loadtopology: found cdp link using cdp cache address: '{}' and '{}'", sourceLink, targetLink);
                    }
                } catch (Exception e) {
                    LOG.warn("loadtopology: cannot convert ip address: {}", sourceLink.getCdpCacheAddress(), e);
                }
            }
        }
        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 CdpLinkDetail(Math.min(sourceLink.getId(), targetLink.getId()) + "|" + Math.max(sourceLink.getId(), targetLink.getId()), source, sourceLink, target, targetLink));
    }
    for (CdpLinkDetail linkDetail : combinedLinkDetails) {
        LinkdEdge edge = connectVertices(linkDetail, CDP_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) HashMap(java.util.HashMap) CdpLink(org.opennms.netmgt.model.CdpLink) InetAddress(java.net.InetAddress) CdpElement(org.opennms.netmgt.model.CdpElement) HashSet(java.util.HashSet)

Example 4 with CdpElement

use of org.opennms.netmgt.model.CdpElement in project opennms by OpenNMS.

the class CdpGlobalGroupTracker method getCdpElement.

public CdpElement getCdpElement() {
    CdpElement cdpElement = new CdpElement();
    cdpElement.setCdpGlobalRun(TruthValue.get(getCdpGlobalRun()));
    cdpElement.setCdpGlobalDeviceId(getCdpDeviceId());
    if (getCdpGlobalDeviceFormat() != null) {
        try {
            cdpElement.setCdpGlobalDeviceIdFormat(CdpGlobalDeviceIdFormat.get(getCdpGlobalDeviceFormat()));
        } catch (IllegalArgumentException e) {
            LOG.info("setCdpGlobalDeviceIdFormat not supported: ", e.getLocalizedMessage());
        }
    }
    return cdpElement;
}
Also used : CdpElement(org.opennms.netmgt.model.CdpElement)

Example 5 with CdpElement

use of org.opennms.netmgt.model.CdpElement in project opennms by OpenNMS.

the class EnLinkdElementFactory method convertFromModel.

@Transactional
@SuppressWarnings("deprecation")
private CdpLinkNode convertFromModel(int nodeid, CdpLink link) {
    CdpLinkNode linknode = new CdpLinkNode();
    linknode.setCdpLocalPort(getPortString(link.getCdpCacheIfIndex(), link.getCdpInterfaceName(), null));
    if (link.getCdpCacheIfIndex() != null)
        linknode.setCdpLocalPortUrl(getSnmpInterfaceUrl(nodeid, link.getCdpCacheIfIndex()));
    linknode.setCdpCacheAddressType(CiscoNetworkProtocolType.getTypeString(link.getCdpCacheAddressType().getValue()));
    linknode.setCdpCacheAddress(link.getCdpCacheAddress());
    linknode.setCdpCacheDeviceId(link.getCdpCacheDeviceId());
    linknode.setCdpCacheDevicePlatform(link.getCdpCacheDevicePlatform());
    linknode.setCdpCacheVersion(link.getCdpCacheVersion());
    linknode.setCdpCacheDevicePort(link.getCdpCacheDevicePort());
    CdpElement cdpCacheElement = m_cdpElementDao.findByGlobalDeviceId(link.getCdpCacheDeviceId());
    if (cdpCacheElement != null) {
        linknode.setCdpCacheDeviceUrl(getNodeUrl(cdpCacheElement.getNode().getId()));
        OnmsSnmpInterface cdpcachesnmp = getFromCdpCacheDevicePort(cdpCacheElement.getNode().getId(), link.getCdpCacheDevicePort());
        if (cdpcachesnmp != null) {
            linknode.setCdpCacheDevicePort(getPortString(cdpcachesnmp.getIfIndex(), link.getCdpCacheDevicePort(), cdpcachesnmp.getIfAlias()));
            linknode.setCdpCacheDevicePortUrl(getSnmpInterfaceUrl(cdpCacheElement.getNode().getId(), cdpcachesnmp.getIfIndex()));
        }
    }
    linknode.setCdpCreateTime(Util.formatDateToUIString(link.getCdpLinkCreateTime()));
    linknode.setCdpLastPollTime(Util.formatDateToUIString(link.getCdpLinkLastPollTime()));
    return linknode;
}
Also used : OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) CdpElement(org.opennms.netmgt.model.CdpElement) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CdpElement (org.opennms.netmgt.model.CdpElement)6 CdpLink (org.opennms.netmgt.model.CdpLink)2 Transactional (org.springframework.transaction.annotation.Transactional)2 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)1 Vertex (org.opennms.features.topology.api.topo.Vertex)1 CdpCacheTableTracker (org.opennms.netmgt.enlinkd.snmp.CdpCacheTableTracker)1 CdpGlobalGroupTracker (org.opennms.netmgt.enlinkd.snmp.CdpGlobalGroupTracker)1 CdpInterfacePortNameGetter (org.opennms.netmgt.enlinkd.snmp.CdpInterfacePortNameGetter)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)1 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)1