Search in sources :

Example 1 with LldpLocPortGetter

use of org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter in project opennms by OpenNMS.

the class EnLinkdSnmpIT method test3LldpRemoteTableWalk.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH2_IP, port = 161, resource = "classpath:/linkd/nms17216/switch2-walk.txt") })
public void test3LldpRemoteTableWalk() throws Exception {
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH2_IP));
    final List<LldpLink> links = new ArrayList<LldpLink>();
    LldpRemTableTracker lldpRemTable = new LldpRemTableTracker() {

        public void processLldpRemRow(final LldpRemRow row) {
            links.add(row.getLldpLink());
        }
    };
    try {
        m_client.walk(config, lldpRemTable).withDescription("lldpRemTable").withLocation(null).execute().get();
    } catch (ExecutionException e) {
        // pass
        LOG.error("run: collection failed, exiting", e);
        return;
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    final LldpLocPortGetter lldpLocPort = new LldpLocPortGetter(config, m_client, null);
    for (LldpLink link : links) {
        assertNotNull(link);
        assertNotNull(link.getLldpLocalPortNum());
        assertNull(link.getLldpPortId());
        assertNull(link.getLldpPortIdSubType());
        assertNull(link.getLldpPortDescr());
        LldpLink updated = lldpLocPort.getLldpLink(link);
        assertNotNull(updated.getLldpPortId());
        assertEquals(5, updated.getLldpPortIdSubType().getValue().intValue());
        assertNotNull(updated.getLldpPortDescr());
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) LldpRemTableTracker(org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker) ArrayList(java.util.ArrayList) LldpLocPortGetter(org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter) LldpLink(org.opennms.netmgt.model.LldpLink) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 2 with LldpLocPortGetter

use of org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter in project opennms by OpenNMS.

the class EnLinkdSnmpIT method testLldpLocGetter.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH1_IP, port = 161, resource = "classpath:/linkd/nms17216/switch1-walk.txt") })
public void testLldpLocGetter() throws Exception {
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH1_IP));
    final LldpLocPortGetter lldpLocPort = new LldpLocPortGetter(config, m_client, null);
    LldpLink link = new LldpLink();
    link.setLldpLocalPortNum(9);
    link = lldpLocPort.getLldpLink(link);
    assertEquals(9, link.getLldpLocalPortNum().intValue());
    assertEquals("Gi0/9", link.getLldpPortId());
    assertEquals("GigabitEthernet0/9", link.getLldpPortDescr());
    assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_INTERFACENAME, link.getLldpPortIdSubType());
    link = new LldpLink();
    link.setLldpLocalPortNum(10);
    link = lldpLocPort.getLldpLink(link);
    assertEquals(10, link.getLldpLocalPortNum().intValue());
    assertEquals("Gi0/10", link.getLldpPortId());
    assertEquals("GigabitEthernet0/10", link.getLldpPortDescr());
    assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_INTERFACENAME, link.getLldpPortIdSubType());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) LldpLocPortGetter(org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter) LldpLink(org.opennms.netmgt.model.LldpLink) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 3 with LldpLocPortGetter

use of org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter in project opennms by OpenNMS.

the class EnLinkdSnmpIT method testLldpDragonWaveLldpLocGetter.

/**
     * 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 testLldpDragonWaveLldpLocGetter() throws Exception {
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(DW_IP));
    final LldpLocPortGetter lldpLocPort = new LldpLocPortGetter(config, m_client, null);
    LldpLink link = new LldpLink();
    link.setLldpLocalPortNum(1);
    link = lldpLocPort.getLldpLink(link);
    assertEquals(1, link.getLldpLocalPortNum().intValue());
    assertEquals("cf", link.getLldpPortId());
    assertEquals("NuDesign", link.getLldpPortDescr());
    assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_INTERFACEALIAS, link.getLldpPortIdSubType());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) LldpLocPortGetter(org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter) LldpLink(org.opennms.netmgt.model.LldpLink) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 4 with LldpLocPortGetter

use of org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter in project opennms by OpenNMS.

the class NodeDiscoveryLldp method runCollection.

protected void runCollection() {
    final Date now = new Date();
    final LldpLocalGroupTracker lldpLocalGroup = new LldpLocalGroupTracker();
    SnmpAgentConfig peer = m_linkd.getSnmpAgentConfig(getPrimaryIpAddress(), getLocation());
    try {
        m_linkd.getLocationAwareSnmpClient().walk(peer, lldpLocalGroup).withDescription("lldpLocalGroup").withLocation(getLocation()).execute().get();
    } catch (ExecutionException e) {
        LOG.info("run: Agent error while scanning the lldpLocalGroup table", e);
        return;
    } catch (final InterruptedException e) {
        LOG.info("run: Lldp Linkd lldpLocalGroup table collection interrupted", e);
        return;
    }
    if (lldpLocalGroup.getLldpLocChassisid() == null) {
        LOG.info("run: node[{}]: address {}. LLDP_MIB not supported", getNodeId(), getPrimaryIpAddressString());
        return;
    } else {
        LOG.info("run: node[{}]: address {}. lldp identifier : {}", getNodeId(), getPrimaryIpAddressString(), lldpLocalGroup.getLldpElement());
    }
    m_linkd.getQueryManager().store(getNodeId(), lldpLocalGroup.getLldpElement());
    if (getSysoid() == null || getSysoid().equals(DW_SYSOID)) {
        if (lldpLocalGroup.getLldpLocChassisid().toHexString().equals(DW_NULL_CHASSIS_ID) && lldpLocalGroup.getLldpLocChassisidSubType() == LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_CHASSISCOMPONENT.getValue()) {
            LOG.info("run: node[{}]: address {}. lldp identifier : {}. lldp not active for Dragon Wave Device.", getNodeId(), getPrimaryIpAddressString(), lldpLocalGroup.getLldpElement());
            return;
        }
        if (lldpLocalGroup.getLldpLocSysname().equals(DW_NULL_SYSOID_ID)) {
            LOG.info("run: node[{}]: address {}. lldp identifier : {}. lldp not active for Dragon Wave Device.", getNodeId(), getPrimaryIpAddressString(), lldpLocalGroup.getLldpElement());
            return;
        }
    }
    List<LldpLink> links = new ArrayList<LldpLink>();
    LldpRemTableTracker lldpRemTable = new LldpRemTableTracker() {

        public void processLldpRemRow(final LldpRemRow row) {
            links.add(row.getLldpLink());
        }
    };
    try {
        m_linkd.getLocationAwareSnmpClient().walk(peer, lldpRemTable).withDescription("lldpRemTable").withLocation(getLocation()).execute().get();
    } catch (ExecutionException e) {
        LOG.error("run: collection execution failed, exiting", e);
        return;
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    final LldpLocPortGetter lldpLocPort = new LldpLocPortGetter(peer, m_linkd.getLocationAwareSnmpClient(), getLocation());
    for (LldpLink link : links) m_linkd.getQueryManager().store(getNodeId(), lldpLocPort.getLldpLink(link));
    m_linkd.getQueryManager().reconcileLldp(getNodeId(), now);
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) LldpRemTableTracker(org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker) LldpLocalGroupTracker(org.opennms.netmgt.enlinkd.snmp.LldpLocalGroupTracker) ArrayList(java.util.ArrayList) LldpLocPortGetter(org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter) LldpLink(org.opennms.netmgt.model.LldpLink) ExecutionException(java.util.concurrent.ExecutionException) Date(java.util.Date)

Example 5 with LldpLocPortGetter

use of org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter in project opennms by OpenNMS.

the class EnLinkdSnmpIT method test2LldpLocGetter.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH2_IP, port = 161, resource = "classpath:/linkd/nms17216/switch2-walk.txt") })
public void test2LldpLocGetter() throws Exception {
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH2_IP));
    final LldpLocPortGetter lldpLocPort = new LldpLocPortGetter(config, m_client, null);
    LldpLink link = new LldpLink();
    link.setLldpLocalPortNum(1);
    link = lldpLocPort.getLldpLink(link);
    assertEquals(1, link.getLldpLocalPortNum().intValue());
    assertEquals("Gi0/1", link.getLldpPortId());
    assertEquals("GigabitEthernet0/1", link.getLldpPortDescr());
    assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_INTERFACENAME, link.getLldpPortIdSubType());
    link = new LldpLink();
    link.setLldpLocalPortNum(2);
    link = lldpLocPort.getLldpLink(link);
    assertEquals(2, link.getLldpLocalPortNum().intValue());
    assertEquals("Gi0/2", link.getLldpPortId());
    assertEquals("GigabitEthernet0/2", link.getLldpPortDescr());
    assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_INTERFACENAME, link.getLldpPortIdSubType());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) LldpLocPortGetter(org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter) LldpLink(org.opennms.netmgt.model.LldpLink) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Aggregations

LldpLocPortGetter (org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter)5 LldpLink (org.opennms.netmgt.model.LldpLink)5 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)5 Test (org.junit.Test)4 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)4 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 LldpRemTableTracker (org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker)2 Date (java.util.Date)1 LldpLocalGroupTracker (org.opennms.netmgt.enlinkd.snmp.LldpLocalGroupTracker)1