Search in sources :

Example 1 with LldpRemTableTracker

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

the class EnLinkdSnmpIT method testLldpDragonWaveRemTableWalk.

@Test
@JUnitSnmpAgent(host = DW_IP, port = 161, resource = DW_SNMP_RESOURCE)
public void testLldpDragonWaveRemTableWalk() throws Exception {
    final SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(DW_IP));
    LldpRemTableTracker lldpRemTable = new LldpRemTableTracker() {

        public void processLldpRemRow(final LldpRemRow row) {
            System.err.println("----------lldp rem----------------");
            System.err.println("columns number in the row: " + row.getColumnCount());
            assertEquals(6, row.getColumnCount());
            LldpLink link = row.getLldpLink();
            assertEquals(1, row.getLldpRemLocalPortNum().intValue());
            System.err.println("local port number: " + row.getLldpRemLocalPortNum());
            assertEquals(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_CHASSISCOMPONENT, link.getLldpRemChassisIdSubType());
            System.err.println("remote chassis type: " + LldpChassisIdSubType.getTypeString(link.getLldpRemChassisIdSubType().getValue()));
            assertEquals("cf", link.getLldpRemChassisId());
            System.err.println("remote chassis: " + link.getLldpRemChassisId());
            assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_INTERFACEALIAS, link.getLldpRemPortIdSubType());
            System.err.println("remote port type: " + LldpPortIdSubType.getTypeString(link.getLldpRemPortIdSubType().getValue()));
            assertEquals("cf", link.getLldpRemPortId());
            System.err.println("remote port id: " + link.getLldpRemPortId());
            assertEquals("NuDesign", link.getLldpRemPortDescr());
            System.err.println("remote port descr: " + link.getLldpRemPortDescr());
            assertEquals("NuDesign", link.getLldpRemSysname());
            System.err.println("remote sysname: " + link.getLldpRemSysname());
        }
    };
    String trackerName = "lldpRemTable";
    try {
        m_client.walk(config, lldpRemTable).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        assertEquals(false, true);
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) LldpRemTableTracker(org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker) LldpLink(org.opennms.netmgt.model.LldpLink) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 2 with LldpRemTableTracker

use of org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker 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 3 with LldpRemTableTracker

use of org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker 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 4 with LldpRemTableTracker

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

the class EnLinkdSnmpIT method testLldpRemTableWalk.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH1_IP, port = 161, resource = "classpath:/linkd/nms17216/switch1-walk.txt") })
public void testLldpRemTableWalk() throws Exception {
    final SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH1_IP));
    LldpRemTableTracker lldpRemTable = new LldpRemTableTracker() {

        public void processLldpRemRow(final LldpRemRow row) {
            System.err.println("----------lldp rem----------------");
            System.err.println("columns number in the row: " + row.getColumnCount());
            assertEquals(6, row.getColumnCount());
            LldpLink link = row.getLldpLink();
            System.err.println("local port number: " + row.getLldpRemLocalPortNum());
            System.err.println("remote chassis: " + link.getLldpRemChassisId());
            System.err.println("remote chassis type: " + LldpChassisIdSubType.getTypeString(link.getLldpRemChassisIdSubType().getValue()));
            assertEquals(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS, link.getLldpRemChassisIdSubType());
            System.err.println("remote port id: " + link.getLldpRemPortId());
            System.err.println("remote port type: " + LldpPortIdSubType.getTypeString(link.getLldpRemPortIdSubType().getValue()));
            assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_INTERFACENAME, link.getLldpRemPortIdSubType());
        }
    };
    try {
        m_client.walk(config, lldpRemTable).withDescription("lldpRemTable").withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        assertEquals(false, true);
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) LldpRemTableTracker(org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker) LldpLink(org.opennms.netmgt.model.LldpLink) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Aggregations

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