Search in sources :

Example 26 with JUnitSnmpAgents

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgents in project opennms by OpenNMS.

the class EnLinkdSnmpIT method testIpNetToMediaTableWalk.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = MIKROTIK_IP, port = 161, resource = MIKROTIK_SNMP_RESOURCE) })
public void testIpNetToMediaTableWalk() throws Exception {
    final List<IpNetToMedia> rows = new ArrayList<>();
    String trackerName = "ipNetToMediaTable";
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(MIKROTIK_IP));
    IpNetToMediaTableTracker tracker = new IpNetToMediaTableTracker() {

        public void processIpNetToMediaRow(final IpNetToMediaRow row) {
            rows.add(row.getIpNetToMedia());
        }
    };
    try {
        m_client.walk(config, tracker).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    assertEquals(6, rows.size());
    for (final IpNetToMedia row : rows) {
        assertEquals(IpNetToMediaType.IPNETTOMEDIA_TYPE_DYNAMIC, row.getIpNetToMediaType());
        if (row.getPhysAddress().equals("00901a4222f8")) {
            assertEquals(InetAddressUtils.addr("10.129.16.1"), row.getNetAddress());
            assertEquals(1, row.getSourceIfIndex().intValue());
        } else if (row.getPhysAddress().equals("0013c8f1d242")) {
            assertEquals(InetAddressUtils.addr("10.129.16.164"), row.getNetAddress());
            assertEquals(1, row.getSourceIfIndex().intValue());
        } else if (row.getPhysAddress().equals("f0728c99994d")) {
            assertEquals(InetAddressUtils.addr("192.168.0.13"), row.getNetAddress());
            assertEquals(2, row.getSourceIfIndex().intValue());
        } else if (row.getPhysAddress().equals("0015999f07ef")) {
            assertEquals(InetAddressUtils.addr("192.168.0.14"), row.getNetAddress());
            assertEquals(2, row.getSourceIfIndex().intValue());
        } else if (row.getPhysAddress().equals("60334b0817a8")) {
            assertEquals(InetAddressUtils.addr("192.168.0.16"), row.getNetAddress());
            assertEquals(2, row.getSourceIfIndex().intValue());
        } else if (row.getPhysAddress().equals("001b63cda9fd")) {
            assertEquals(InetAddressUtils.addr("192.168.0.17"), row.getNetAddress());
            assertEquals(2, row.getSourceIfIndex().intValue());
        } else {
            assertEquals(false, true);
        }
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) IpNetToMedia(org.opennms.netmgt.model.IpNetToMedia) ArrayList(java.util.ArrayList) IpNetToMediaTableTracker(org.opennms.netmgt.enlinkd.snmp.IpNetToMediaTableTracker) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 27 with JUnitSnmpAgents

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgents in project opennms by OpenNMS.

the class EnLinkdSnmpIT method testOspfIfTableWalk.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH1_IP, port = 161, resource = "classpath:/linkd/nms17216/switch1-walk.txt") })
public void testOspfIfTableWalk() throws Exception {
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH1_IP));
    String trackerName = "ospfIfTable";
    final List<OspfLink> links = new ArrayList<>();
    OspfIfTableTracker ospfIfTableTracker = new OspfIfTableTracker() {

        public void processOspfIfRow(final OspfIfRow row) {
            links.add(row.getOspfLink());
        }
    };
    try {
        m_client.walk(config, ospfIfTableTracker).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    final OspfIpAddrTableGetter ipAddrTableGetter = new OspfIpAddrTableGetter(config, m_client, null, 0);
    for (OspfLink link : links) {
        link = ipAddrTableGetter.get(link);
        assertEquals(0, link.getOspfAddressLessIndex().intValue());
        if (link.getOspfIpAddr().equals(InetAddress.getByName("192.168.100.246"))) {
            assertEquals(10101, link.getOspfIfIndex().intValue());
            assertEquals(InetAddress.getByName("255.255.255.252"), link.getOspfIpMask());
        } else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.10.1"))) {
            assertEquals(10, link.getOspfIfIndex().intValue());
            assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
        } else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.20.1"))) {
            assertEquals(20, link.getOspfIfIndex().intValue());
            assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
        } else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.30.1"))) {
            assertEquals(30, link.getOspfIfIndex().intValue());
            assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
        } else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.40.1"))) {
            assertEquals(40, link.getOspfIfIndex().intValue());
            assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
        } else {
            assertEquals(false, true);
        }
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OspfIfTableTracker(org.opennms.netmgt.enlinkd.snmp.OspfIfTableTracker) ArrayList(java.util.ArrayList) OspfLink(org.opennms.netmgt.model.OspfLink) OspfIpAddrTableGetter(org.opennms.netmgt.enlinkd.snmp.OspfIpAddrTableGetter) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 28 with JUnitSnmpAgents

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgents 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<>();
    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, 0);
    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 29 with JUnitSnmpAgents

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgents 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 30 with JUnitSnmpAgents

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgents in project opennms by OpenNMS.

the class EnLinkdSnmpIT method testDot1dTpFdbTableWalk.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = DLINK1_IP, port = 161, resource = DLINK1_SNMP_RESOURCE) })
public void testDot1dTpFdbTableWalk() throws Exception {
    String trackerName = "dot1dTpFdbTable";
    final List<BridgeMacLink> links = new ArrayList<>();
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(DLINK1_IP));
    Dot1dTpFdbTableTracker tracker = new Dot1dTpFdbTableTracker() {

        @Override
        public void processDot1dTpFdbRow(final Dot1dTpFdbRow row) {
            links.add(row.getLink());
        }
    };
    try {
        m_client.walk(config, tracker).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    assertEquals(17, links.size());
    for (BridgeMacLink link : links) {
        assertEquals(BridgeDot1qTpFdbStatus.DOT1D_TP_FDB_STATUS_LEARNED, link.getBridgeDot1qTpFdbStatus());
        System.out.println(link.getMacAddress());
        if (link.getMacAddress().equals("000c29dcc076")) {
            assertEquals(24, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("000ffeb10d1e")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("000ffeb10e26")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("001a4b802790")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("001d6004acbc")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("001e58865d0f")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("0021913b5108")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("002401ad3416")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("00248c4c8bd0")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("0024d608693e")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("000ffeb10d1e")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("1caff737cc33")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("1caff7443339")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("1cbdb9b56160")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("5cd998667abb")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("e0cb4e3e7fc0")) {
            assertEquals(6, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("f07d68711f89")) {
            assertEquals(24, link.getBridgePort().intValue());
        } else if (link.getMacAddress().equals("f07d6876c565")) {
            assertEquals(24, link.getBridgePort().intValue());
        } else {
            assertEquals(false, true);
        }
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) ArrayList(java.util.ArrayList) Dot1dTpFdbTableTracker(org.opennms.netmgt.enlinkd.snmp.Dot1dTpFdbTableTracker) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Aggregations

JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)66 Test (org.junit.Test)64 OnmsNode (org.opennms.netmgt.model.OnmsNode)38 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)23 LldpLink (org.opennms.netmgt.model.LldpLink)14 ArrayList (java.util.ArrayList)8 BridgeMacLink (org.opennms.netmgt.model.BridgeMacLink)8 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)6 EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)4 LldpLocPortGetter (org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter)4 CdpLink (org.opennms.netmgt.model.CdpLink)4 IsIsLink (org.opennms.netmgt.model.IsIsLink)4 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 LldpElement (org.opennms.netmgt.model.LldpElement)3 OspfLink (org.opennms.netmgt.model.OspfLink)3 InetAddress (java.net.InetAddress)2 CdpGlobalGroupTracker (org.opennms.netmgt.enlinkd.snmp.CdpGlobalGroupTracker)2 LldpLocalGroupTracker (org.opennms.netmgt.enlinkd.snmp.LldpLocalGroupTracker)2 LldpRemTableTracker (org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker)2