Search in sources :

Example 51 with JUnitSnmpAgents

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

the class Nms8000EnIT method testCdpLinks.

/* 
     * nmmr1 GigabitEthernet0/0                 ---> nmmr3   GigabitEthernet0/1
     * nmmr1 GigabitEthernet0/1                 ---> nmmsw1  FastEthernet0/1
     * nmmr1 GigabitEthernet0/2                 ---> nmmsw2  FastEthernet0/2
     * 
     * nmmr2 GigabitEthernet0/0                 ---> nmmr3   GigabitEthernet0/2
     * nmmr2 GigabitEthernet0/1                 ---> nmmsw2  FastEthernet0/1
     * nmmr2 GigabitEthernet0/2                 ---> nmmsw1  FastEthernet0/2
     * 
     * nmmr3 GigabitEthernet0/0                 ---> netlabSW03   GigabitEthernet2/0/18
     * nmmr3 GigabitEthernet0/1                 ---> nmmr1  GigabitEthernet0/0
     * nmmr3 GigabitEthernet0/2                 ---> nmmr2  GigabitEthernet0/0
     * 
     * nmmsw1  FastEthernet0/1                  ---> nmmr1 GigabitEthernet0/1
     * nmmsw1  FastEthernet0/2                  ---> nmmr2 GigabitEthernet0/2
     * 
     * nmmsw2  FastEthernet0/1                  ---> nmmr2 GigabitEthernet0/1
     * nmmsw2  FastEthernet0/2                  ---> nmmr1 GigabitEthernet0/2
     */
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = NMMR1_IP, port = 161, resource = NMMR1_SNMP_RESOURCE), @JUnitSnmpAgent(host = NMMR2_IP, port = 161, resource = NMMR2_SNMP_RESOURCE), @JUnitSnmpAgent(host = NMMR3_IP, port = 161, resource = NMMR3_SNMP_RESOURCE), @JUnitSnmpAgent(host = NMMSW1_IP, port = 161, resource = NMMSW1_SNMP_RESOURCE), @JUnitSnmpAgent(host = NMMSW2_IP, port = 161, resource = NMMSW2_SNMP_RESOURCE) })
public void testCdpLinks() throws Exception {
    m_nodeDao.save(builder.getNMMR1());
    m_nodeDao.save(builder.getNMMR2());
    m_nodeDao.save(builder.getNMMR3());
    m_nodeDao.save(builder.getNMMSW1());
    m_nodeDao.save(builder.getNMMSW2());
    m_nodeDao.flush();
    m_linkdConfig.getConfiguration().setUseBridgeDiscovery(false);
    m_linkdConfig.getConfiguration().setUseCdpDiscovery(true);
    m_linkdConfig.getConfiguration().setUseOspfDiscovery(false);
    m_linkdConfig.getConfiguration().setUseLldpDiscovery(false);
    m_linkdConfig.getConfiguration().setUseIsisDiscovery(false);
    assertTrue(!m_linkdConfig.useLldpDiscovery());
    assertTrue(m_linkdConfig.useCdpDiscovery());
    assertTrue(!m_linkdConfig.useOspfDiscovery());
    assertTrue(!m_linkdConfig.useBridgeDiscovery());
    assertTrue(!m_linkdConfig.useIsisDiscovery());
    final OnmsNode nmmr1 = m_nodeDao.findByForeignId("linkd", NMMR1_NAME);
    final OnmsNode nmmr2 = m_nodeDao.findByForeignId("linkd", NMMR2_NAME);
    final OnmsNode nmmr3 = m_nodeDao.findByForeignId("linkd", NMMR3_NAME);
    final OnmsNode nmmsw1 = m_nodeDao.findByForeignId("linkd", NMMSW1_NAME);
    final OnmsNode nmmsw2 = m_nodeDao.findByForeignId("linkd", NMMSW2_NAME);
    assertTrue(m_linkd.scheduleNodeCollection(nmmr1.getId()));
    assertTrue(m_linkd.scheduleNodeCollection(nmmr2.getId()));
    assertTrue(m_linkd.scheduleNodeCollection(nmmr3.getId()));
    assertTrue(m_linkd.scheduleNodeCollection(nmmsw1.getId()));
    assertTrue(m_linkd.scheduleNodeCollection(nmmsw2.getId()));
    assertTrue(m_linkd.runSingleSnmpCollection(nmmr1.getId()));
    assertEquals(3, m_cdpLinkDao.countAll());
    assertTrue(m_linkd.runSingleSnmpCollection(nmmr2.getId()));
    assertEquals(6, m_cdpLinkDao.countAll());
    assertTrue(m_linkd.runSingleSnmpCollection(nmmr3.getId()));
    assertEquals(9, m_cdpLinkDao.countAll());
    assertTrue(m_linkd.runSingleSnmpCollection(nmmsw1.getId()));
    assertEquals(11, m_cdpLinkDao.countAll());
    assertTrue(m_linkd.runSingleSnmpCollection(nmmsw2.getId()));
    assertEquals(13, m_cdpLinkDao.countAll());
    for (final OnmsNode node : m_nodeDao.findAll()) {
        assertNotNull(node.getCdpElement());
        printCdpElement(node.getCdpElement());
    }
    for (CdpLink link : m_cdpLinkDao.findAll()) {
        printCdpLink(link);
        assertEquals(CiscoNetworkProtocolType.ip, link.getCdpCacheAddressType());
    }
    assertEquals(6, m_cdpLinkDao.findLinksForTopology().size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) CdpLink(org.opennms.netmgt.model.CdpLink) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 52 with JUnitSnmpAgents

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

the class Nms7563EnIT method testSwitch02Links.

/*
     * The SNMP walk reported by the HP ProcurceSwitch for CDP
     * seems to be wrong, there is a double reported link
     * that with the Cisco2900.
     * In any case we decide to save the data as it is walked 
     * and put all the necessarly login to manage
     * links in other classes.
     */
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH02_IP, port = 161, resource = SWITCH02_SNMP_RESOURCE) })
public void testSwitch02Links() throws Exception {
    m_nodeDao.save(builder.getSwitch02());
    m_nodeDao.flush();
    m_linkdConfig.getConfiguration().setUseBridgeDiscovery(false);
    m_linkdConfig.getConfiguration().setUseOspfDiscovery(false);
    m_linkdConfig.getConfiguration().setUseIsisDiscovery(false);
    m_linkdConfig.getConfiguration().setUseLldpDiscovery(false);
    assertTrue(!m_linkdConfig.useIsisDiscovery());
    assertTrue(!m_linkdConfig.useBridgeDiscovery());
    assertTrue(!m_linkdConfig.useOspfDiscovery());
    assertTrue(!m_linkdConfig.useLldpDiscovery());
    assertTrue(m_linkdConfig.useCdpDiscovery());
    final OnmsNode switch02 = m_nodeDao.findByForeignId("linkd", SWITCH02_NAME);
    assertTrue(m_linkd.scheduleNodeCollection(switch02.getId()));
    assertTrue(m_linkd.runSingleSnmpCollection(switch02.getId()));
    for (final OnmsNode node : m_nodeDao.findAll()) {
        assertNotNull(node.getCdpElement());
        printCdpElement(node.getCdpElement());
        assertEquals(TruthValue.TRUE, node.getCdpElement().getCdpGlobalRun());
        assertEquals(SWITCH02_CDP_GLOBAL_DEVICE_ID, node.getCdpElement().getCdpGlobalDeviceId());
    }
    assertEquals(3, m_cdpLinkDao.countAll());
    assertEquals(0, m_cdpLinkDao.findLinksForTopology().size());
    for (CdpLink link : m_cdpLinkDao.findAll()) {
        printCdpLink(link);
        if (link.getCdpCacheIfIndex().intValue() == 7 && link.getCdpCacheDeviceIndex().intValue() == 1) {
            assertNull(link.getCdpInterfaceName());
            assertEquals(CiscoNetworkProtocolType.ip, link.getCdpCacheAddressType());
            // here the ip address is associated to wlan0 but the mac is associated to eth0
            // clearly the link is with eth0.
            assertEquals("192.168.87.16", link.getCdpCacheAddress());
            assertEquals(HOMESERVER_CDP_GLOBAL_DEVICE_ID, link.getCdpCacheDeviceId());
            assertEquals("Debian GNU/Linux 7 (wheezy) Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u2 x86_64", link.getCdpCacheVersion());
            assertEquals("Debian GNU/Linux 7 (wheezy) Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u2 x86_64", link.getCdpCacheDevicePlatform());
            assertEquals(HOMESERVER_IF_MAC_MAP.get(2), link.getCdpCacheDevicePort());
        } else if (link.getCdpCacheIfIndex().intValue() == 24 && link.getCdpCacheDeviceIndex().intValue() == 1) {
            // This is a link to cisco01 port fastethernet0/8
            assertNull(link.getCdpInterfaceName());
            assertEquals(CiscoNetworkProtocolType.ip, link.getCdpCacheAddressType());
            assertEquals("192.168.88.240", link.getCdpCacheAddress());
            assertEquals(CISCO01_CDP_GLOBAL_DEVICE_ID, link.getCdpCacheDeviceId());
            assertEquals("Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE4, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyrighcisco WS-C2960-8TC-L", link.getCdpCacheVersion());
            assertEquals("Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE4, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyrighcisco WS-C2960-8TC-L", link.getCdpCacheDevicePlatform());
            assertEquals(CISCO01_IF_IFDESCR_MAP.get(10008), link.getCdpCacheDevicePort());
        } else if (link.getCdpCacheIfIndex().intValue() == 24 && link.getCdpCacheDeviceIndex().intValue() == 2) {
            // This is a link to cisco01 port fastethernet0/8 with different data also
            // the cdpcacheversion is always different from the cdpcacheplatform.
            assertNull(link.getCdpInterfaceName());
            assertEquals(CiscoNetworkProtocolType.ip, link.getCdpCacheAddressType());
            assertEquals("192.168.88.240", link.getCdpCacheAddress());
            assertEquals(CISCO01_LLDP_CHASSID_ID, link.getCdpCacheDeviceId());
            assertEquals("Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE4, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2013 by Cisco Systems, Inc.  Compiled Wed 26-Jun-13 02:49 by prod_rel_team", link.getCdpCacheVersion());
            assertEquals("Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE4, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2013 by Cisco Systems, Inc.  Compiled Wed 26-Jun-13 02:49 by prod_rel_team", link.getCdpCacheDevicePlatform());
            assertEquals(CISCO01_IF_IFNAME_MAP.get(10008), link.getCdpCacheDevicePort());
        } else {
            assertTrue(false);
        }
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) CdpLink(org.opennms.netmgt.model.CdpLink) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 53 with JUnitSnmpAgents

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

the class Nms7563EnIT method testHomeServerLinks.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = HOMESERVER_IP, port = 161, resource = HOMESERVER_SNMP_RESOURCE) })
public void testHomeServerLinks() throws Exception {
    m_nodeDao.save(builder.getHomeServer());
    m_nodeDao.flush();
    m_linkdConfig.getConfiguration().setUseBridgeDiscovery(false);
    m_linkdConfig.getConfiguration().setUseOspfDiscovery(false);
    m_linkdConfig.getConfiguration().setUseIsisDiscovery(false);
    m_linkdConfig.getConfiguration().setUseCdpDiscovery(false);
    assertTrue(!m_linkdConfig.useIsisDiscovery());
    assertTrue(!m_linkdConfig.useBridgeDiscovery());
    assertTrue(!m_linkdConfig.useOspfDiscovery());
    assertTrue(m_linkdConfig.useLldpDiscovery());
    assertTrue(!m_linkdConfig.useCdpDiscovery());
    final OnmsNode homeserver = m_nodeDao.findByForeignId("linkd", HOMESERVER_NAME);
    assertTrue(m_linkd.scheduleNodeCollection(homeserver.getId()));
    assertTrue(m_linkd.runSingleSnmpCollection(homeserver.getId()));
    for (final OnmsNode node : m_nodeDao.findAll()) {
        assertNotNull(node.getLldpElement());
        printLldpElement(node.getLldpElement());
        assertEquals(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS, node.getLldpElement().getLldpChassisIdSubType());
        assertEquals(HOMESERVER_LLDP_CHASSID_ID, node.getLldpElement().getLldpChassisId());
        assertEquals(HOMESERVER_LLDP_SYSNAME, node.getLldpElement().getLldpSysname());
    }
    assertEquals(1, m_lldpLinkDao.countAll());
    for (LldpLink link : m_lldpLinkDao.findAll()) {
        assertNotNull(link);
        printLldpLink(link);
        assertEquals(2, link.getLldpLocalPortNum().intValue());
        assertNull(link.getLldpPortIfindex());
        assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_MACADDRESS, link.getLldpPortIdSubType());
        assertEquals(HOMESERVER_IF_MAC_MAP.get(2), link.getLldpPortId());
        assertEquals("eth0", link.getLldpPortDescr());
        assertEquals(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS, link.getLldpRemChassisIdSubType());
        assertEquals(SWITCH02_LLDP_CHASSID_ID, link.getLldpRemChassisId());
        assertEquals(SWITCH02_LLDP_SYSNAME, link.getLldpRemSysname());
        assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, link.getLldpRemPortIdSubType());
        assertEquals("7", link.getLldpRemPortId());
        assertEquals("7", link.getLldpRemPortDescr());
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) LldpLink(org.opennms.netmgt.model.LldpLink) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 54 with JUnitSnmpAgents

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

the class EnLinkdSnmpIT method testOspfNbrTableWalk.

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

        public void processOspfNbrRow(final OspfNbrRow row) {
            OspfLink link = row.getOspfLink();
            try {
                assertEquals(InetAddress.getByName("192.168.100.249"), link.getOspfRemRouterId());
                assertEquals(InetAddress.getByName("192.168.100.245"), link.getOspfRemIpAddr());
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
            assertEquals(0, link.getOspfRemAddressLessIndex().intValue());
        }
    };
    try {
        m_client.walk(config, ospfNbrTableTracker).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) UnknownHostException(java.net.UnknownHostException) OspfNbrTableTracker(org.opennms.netmgt.enlinkd.snmp.OspfNbrTableTracker) OspfLink(org.opennms.netmgt.model.OspfLink) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 55 with JUnitSnmpAgents

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

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