Search in sources :

Example 1 with LldpElement

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

the class EnLinkdSnmpIT method testLldpDragonWaveLocalGroupWalk.

/**
     * This test is designed to test the issues in bug NMS-6921.
     * 
     * @see http://issues.opennms.org/browse/NMS-6912

     * 
     * @throws Exception
     */
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = DW_IP, port = 161, resource = DW_SNMP_RESOURCE) })
public void testLldpDragonWaveLocalGroupWalk() throws Exception {
    String trackerName = "lldpLocalGroup";
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(DW_IP));
    LldpLocalGroupTracker lldpLocalGroup = new LldpLocalGroupTracker();
    try {
        m_client.walk(config, lldpLocalGroup).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    LldpElement eiA = lldpLocalGroup.getLldpElement();
    System.err.println("local chassis type: " + LldpChassisIdSubType.getTypeString(eiA.getLldpChassisIdSubType().getValue()));
    System.err.println("local chassis id: " + eiA.getLldpChassisId());
    System.err.println("local sysname: " + eiA.getLldpSysname());
    assertEquals("cf", eiA.getLldpChassisId());
    assertEquals(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_CHASSISCOMPONENT, eiA.getLldpChassisIdSubType());
    assertEquals("NuDesign", eiA.getLldpSysname());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) LldpLocalGroupTracker(org.opennms.netmgt.enlinkd.snmp.LldpLocalGroupTracker) LldpElement(org.opennms.netmgt.model.LldpElement) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 2 with LldpElement

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

the class NodeDaoIT method testLldpSaveAndUpdate.

@Test
@Transactional
public void testLldpSaveAndUpdate() throws InterruptedException {
    OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "MyFirstLldpNode");
    getNodeDao().save(node);
    getNodeDao().flush();
    Collection<OnmsNode> nodes = getNodeDao().findAll();
    assertEquals(7, nodes.size());
    Integer nodeid = null;
    for (OnmsNode retrieved : nodes) {
        if (retrieved.getLabel().equals("MyFirstLldpNode")) {
            nodeid = retrieved.getId();
            System.out.println("nodeid: " + nodeid);
        }
    }
    OnmsNode dbnode1 = getNodeDao().get(nodeid);
    assertNotNull(dbnode1);
    if (dbnode1.getLldpElement() == null) {
        LldpElement lldpElement = new LldpElement();
        lldpElement.setLldpChassisId("abc123456");
        lldpElement.setLldpChassisIdSubType(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS);
        lldpElement.setLldpSysname("prova");
        lldpElement.setNode(node);
        lldpElement.setLldpNodeLastPollTime(lldpElement.getLldpNodeCreateTime());
        dbnode1.setLldpElement(lldpElement);
    }
    getNodeDao().save(dbnode1);
    getNodeDao().flush();
    OnmsNode dbnode2 = getNodeDao().get(nodeid);
    assertNotNull(dbnode2);
    assertNotNull(dbnode2.getLldpElement());
    System.out.println("lldp element id: " + dbnode2.getLldpElement().getId());
    System.out.println("lldp element create time: " + dbnode2.getLldpElement().getLldpNodeCreateTime());
    System.out.println("lldp element last poll time: " + dbnode2.getLldpElement().getLldpNodeLastPollTime());
    assertEquals("abc123456", dbnode2.getLldpElement().getLldpChassisId());
    assertEquals(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS, dbnode2.getLldpElement().getLldpChassisIdSubType());
    assertEquals("prova", dbnode2.getLldpElement().getLldpSysname());
    assertNotNull(dbnode2.getLldpElement().getLldpNodeCreateTime());
    assertNotNull(dbnode2.getLldpElement().getLldpNodeLastPollTime());
    System.out.println("---------");
    Thread.sleep(1000);
    System.out.println("---------");
    LldpElement lldpUpdateElement = new LldpElement();
    lldpUpdateElement.setLldpChassisId("abc012345");
    lldpUpdateElement.setLldpChassisIdSubType(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS);
    lldpUpdateElement.setLldpSysname("prova");
    LldpElement dbLldpElement = dbnode2.getLldpElement();
    dbLldpElement.merge(lldpUpdateElement);
    dbnode2.setLldpElement(dbLldpElement);
    getNodeDao().save(dbnode2);
    getNodeDao().flush();
    OnmsNode dbnode3 = getNodeDao().get(nodeid);
    assertNotNull(dbnode3);
    assertNotNull(dbnode3.getLldpElement());
    System.out.println("lldp element id: " + dbnode3.getLldpElement().getId());
    System.out.println("lldp element create time: " + dbnode3.getLldpElement().getLldpNodeCreateTime());
    System.out.println("lldp element last poll time: " + dbnode3.getLldpElement().getLldpNodeLastPollTime());
    assertEquals("abc012345", dbnode3.getLldpElement().getLldpChassisId());
    assertEquals(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS, dbnode3.getLldpElement().getLldpChassisIdSubType());
    assertEquals("prova", dbnode3.getLldpElement().getLldpSysname());
    assertNotNull(dbnode3.getLldpElement().getLldpNodeCreateTime());
    assertNotNull(dbnode3.getLldpElement().getLldpNodeLastPollTime());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) LldpElement(org.opennms.netmgt.model.LldpElement) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with LldpElement

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

the class EnLinkdElementFactory method convertFromModel.

@Transactional
@SuppressWarnings("deprecation")
private LldpLinkNode convertFromModel(int nodeid, LldpLink link) {
    LldpLinkNode linknode = new LldpLinkNode();
    linknode.setLldpPortString(getPortString(link.getLldpPortId(), link.getLldpPortIdSubType()));
    linknode.setLldpPortDescr(link.getLldpPortDescr());
    linknode.setLldpPortUrl(getSnmpInterfaceUrl(Integer.valueOf(nodeid), link.getLldpPortIfindex()));
    linknode.setLldpRemSysName(link.getLldpRemSysname());
    linknode.setLldpRemPortString(getPortString(link.getLldpRemPortId(), link.getLldpRemPortIdSubType()));
    linknode.setLldpRemPortDescr(link.getLldpRemPortDescr());
    linknode.setLldpCreateTime(Util.formatDateToUIString(link.getLldpLinkCreateTime()));
    linknode.setLldpLastPollTime(Util.formatDateToUIString(link.getLldpLinkLastPollTime()));
    OnmsNode remNode = null;
    List<LldpElement> lldpremelements = m_lldpElementDao.findByChassisId(link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType());
    if (lldpremelements.size() == 1) {
        remNode = lldpremelements.get(0).getNode();
    } else if (lldpremelements.size() > 1) {
        linknode.setLldpRemChassisIdString(getChassisIdString("Found " + lldpremelements.size() + " nodes for", link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
        return linknode;
    } else {
        final Criteria criteria = new Criteria(OnmsNode.class).addRestriction(new EqRestriction("sysName", link.getLldpRemSysname()));
        List<OnmsNode> nodes = m_nodeDao.findMatching(criteria);
        if (nodes.size() == 1)
            remNode = nodes.get(0);
    }
    if (remNode != null) {
        linknode.setLldpRemChassisIdString(getChassisIdString(remNode.getLabel(), link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
        linknode.setLldpRemChassisIdUrl(getNodeUrl(remNode.getId()));
        if (link.getLldpRemPortIdSubType() == LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL) {
            try {
                Integer remIfIndex = Integer.getInteger(link.getLldpRemPortId());
                linknode.setLldpRemPortUrl(getSnmpInterfaceUrl(Integer.valueOf(remNode.getId()), remIfIndex));
            } catch (Exception e) {
            }
        }
    } else {
        linknode.setLldpRemChassisIdString(getChassisIdString(link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
    }
    return linknode;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) List(java.util.List) ArrayList(java.util.ArrayList) LldpElement(org.opennms.netmgt.model.LldpElement) Criteria(org.opennms.core.criteria.Criteria) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with LldpElement

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

the class EnhancedLinkdServiceImpl method reconcileLldp.

@Override
public void reconcileLldp(int nodeId, Date now) {
    LldpElement element = m_lldpElementDao.findByNodeId(nodeId);
    if (element != null && element.getLldpNodeLastPollTime().getTime() < now.getTime()) {
        m_lldpElementDao.delete(element);
        m_lldpElementDao.flush();
    }
    m_lldpLinkDao.deleteByNodeIdOlderThen(nodeId, now);
    m_lldpLinkDao.flush();
}
Also used : LldpElement(org.opennms.netmgt.model.LldpElement)

Example 5 with LldpElement

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

the class EnhancedLinkdServiceImpl method store.

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

Aggregations

LldpElement (org.opennms.netmgt.model.LldpElement)10 OnmsNode (org.opennms.netmgt.model.OnmsNode)6 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)3 LldpLink (org.opennms.netmgt.model.LldpLink)3 Transactional (org.springframework.transaction.annotation.Transactional)3 HashSet (java.util.HashSet)2 List (java.util.List)2 EqRestriction (org.opennms.core.criteria.restrictions.EqRestriction)2 LldpLocalGroupTracker (org.opennms.netmgt.enlinkd.snmp.LldpLocalGroupTracker)2 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)2 HashMap (java.util.HashMap)1 Criteria (org.opennms.core.criteria.Criteria)1 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)1 Vertex (org.opennms.features.topology.api.topo.Vertex)1 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)1 OspfLink (org.opennms.netmgt.model.OspfLink)1