Search in sources :

Example 16 with JUnitSnmpAgents

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

the class Nms4930EnIT method testNms4930Network.

/*
     * The main fact is that this devices have only the Bridge MIb walk
     * dlink_DES has STP disabled
     * dlink_DGS has STP enabled but root is itself
     * 
     */
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = DLINK1_IP, port = 161, resource = DLINK1_SNMP_RESOURCE), @JUnitSnmpAgent(host = DLINK2_IP, port = 161, resource = DLINK2_SNMP_RESOURCE) })
public void testNms4930Network() throws Exception {
    final OnmsNode dlink1 = m_nodeDao.findByForeignId("linkd", DLINK1_NAME);
    final OnmsNode dlink2 = m_nodeDao.findByForeignId("linkd", DLINK2_NAME);
    final OnmsNode nodebetweendlink1dlink2 = m_nodeDao.findByForeignId("linkd", "10.100.1.7");
    final OnmsNode nodeonlink1dport6 = m_nodeDao.findByForeignId("linkd", "10.100.2.6");
    assertNotNull(nodebetweendlink1dlink2);
    assertNotNull(nodeonlink1dport6);
    m_linkdConfig.getConfiguration().setUseBridgeDiscovery(true);
    m_linkdConfig.getConfiguration().setUseCdpDiscovery(false);
    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());
    assertTrue(m_linkd.scheduleNodeCollection(dlink1.getId()));
    assertTrue(m_linkd.scheduleNodeCollection(dlink2.getId()));
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(0, m_bridgeMacLinkDao.countAll());
    assertTrue(m_linkd.runSingleSnmpCollection(dlink1.getId()));
    assertTrue(m_linkd.runTopologyDiscovery(dlink1.getId()));
    checkTopologyDlink1(dlink1);
    assertTrue(m_linkd.runSingleSnmpCollection(dlink2.getId()));
    assertTrue(m_linkd.runTopologyDiscovery(dlink2.getId()));
    checkTopology(dlink1, dlink2, nodeonlink1dport6, nodebetweendlink1dlink2);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 17 with JUnitSnmpAgents

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

the class Nms7918EnIT method testNms7918.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = ASW01_IP, port = 161, resource = ASW01_SNMP_RESOURCE), @JUnitSnmpAgent(host = SAMASW01_IP, port = 161, resource = SAMASW01_SNMP_RESOURCE), @JUnitSnmpAgent(host = STCASW01_IP, port = 161, resource = STCASW01_SNMP_RESOURCE) })
public void testNms7918() throws Exception {
    final OnmsNode stcasw01 = m_nodeDao.findByForeignId("linkd", STCASW01_NAME);
    final OnmsNode samasw01 = m_nodeDao.findByForeignId("linkd", SAMASW01_NAME);
    final OnmsNode asw01 = m_nodeDao.findByForeignId("linkd", ASW01_NAME);
    m_linkdConfig.getConfiguration().setUseBridgeDiscovery(true);
    m_linkdConfig.getConfiguration().setUseCdpDiscovery(false);
    m_linkdConfig.getConfiguration().setUseOspfDiscovery(false);
    m_linkdConfig.getConfiguration().setUseLldpDiscovery(false);
    m_linkdConfig.getConfiguration().setUseIsisDiscovery(false);
    m_linkdConfig.getConfiguration().setMaxBft(3);
    assertTrue(!m_linkdConfig.useLldpDiscovery());
    assertTrue(!m_linkdConfig.useCdpDiscovery());
    assertTrue(!m_linkdConfig.useOspfDiscovery());
    assertTrue(m_linkdConfig.useBridgeDiscovery());
    assertTrue(!m_linkdConfig.useIsisDiscovery());
    assertTrue(m_linkd.scheduleNodeCollection(asw01.getId()));
    assertTrue(m_linkd.scheduleNodeCollection(samasw01.getId()));
    assertTrue(m_linkd.scheduleNodeCollection(stcasw01.getId()));
    assertEquals(0, m_bridgeElementDao.countAll());
    assertEquals(0, m_bridgeStpLinkDao.countAll());
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(0, m_bridgeMacLinkDao.countAll());
    assertTrue(m_linkd.runSingleSnmpCollection(asw01.getId()));
    assertTrue(m_linkd.runSingleSnmpCollection(samasw01.getId()));
    assertTrue(m_linkd.runSingleSnmpCollection(stcasw01.getId()));
    assertEquals(3, m_bridgeElementDao.countAll());
    assertEquals(0, m_bridgeStpLinkDao.countAll());
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(0, m_bridgeMacLinkDao.countAll());
    assertTrue(m_linkd.runTopologyDiscovery(asw01.getId()));
    assertTrue(m_linkd.runTopologyDiscovery(samasw01.getId()));
    assertTrue(m_linkd.runTopologyDiscovery(stcasw01.getId()));
    checkTopology(asw01, stcasw01, samasw01);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 18 with JUnitSnmpAgents

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

the class Nms7918EnIT method testNms7918SAMASW01Bft.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SAMASW01_IP, port = 161, resource = SAMASW01_SNMP_RESOURCE) })
public void testNms7918SAMASW01Bft() throws Exception {
    final OnmsNode samasw01 = m_nodeDao.findByForeignId("linkd", SAMASW01_NAME);
    m_linkdConfig.getConfiguration().setUseBridgeDiscovery(true);
    m_linkdConfig.getConfiguration().setUseCdpDiscovery(false);
    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());
    assertTrue(m_linkd.scheduleNodeCollection(samasw01.getId()));
    assertTrue(!m_linkd.scheduleNodeCollection(samasw01.getId()));
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(0, m_bridgeMacLinkDao.countAll());
    assertTrue(m_linkd.runSingleSnmpCollection(samasw01.getId()));
    assertEquals(1, m_bridgeElementDao.countAll());
    assertEquals(0, m_bridgeStpLinkDao.countAll());
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(0, m_bridgeMacLinkDao.countAll());
    assertTrue(m_linkd.runTopologyDiscovery(samasw01.getId()));
    assertNull(m_linkd.getQueryManager().useBridgeTopologyUpdateBFT(samasw01.getId()));
    assertEquals(1, m_bridgeElementDao.countAll());
    assertEquals(0, m_bridgeStpLinkDao.countAll());
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(31, m_bridgeMacLinkDao.countAll());
    for (BridgeMacLink link : m_bridgeMacLinkDao.findAll()) {
        System.err.println(link.printTopology());
    }
    assertTrue(m_linkd.runSingleSnmpCollection(samasw01.getId()));
    assertEquals(1, m_bridgeElementDao.countAll());
    assertEquals(0, m_bridgeStpLinkDao.countAll());
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(31, m_bridgeMacLinkDao.countAll());
    Thread.sleep(5000);
    assertTrue(m_linkd.runTopologyDiscovery(samasw01.getId()));
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(31, m_bridgeMacLinkDao.countAll());
    for (BridgeMacLink link : m_bridgeMacLinkDao.findAll()) {
        System.err.println(link.printTopology());
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 19 with JUnitSnmpAgents

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

the class Nms7918EnIT method testNms7918ASW01Bft.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = ASW01_IP, port = 161, resource = ASW01_SNMP_RESOURCE) })
public void testNms7918ASW01Bft() throws Exception {
    final OnmsNode asw01 = m_nodeDao.findByForeignId("linkd", ASW01_NAME);
    m_linkdConfig.getConfiguration().setUseBridgeDiscovery(true);
    m_linkdConfig.getConfiguration().setUseCdpDiscovery(false);
    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());
    assertTrue(m_linkd.scheduleNodeCollection(asw01.getId()));
    assertTrue(!m_linkd.scheduleNodeCollection(asw01.getId()));
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(0, m_bridgeMacLinkDao.countAll());
    assertTrue(m_linkd.runSingleSnmpCollection(asw01.getId()));
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(0, m_bridgeMacLinkDao.countAll());
    assertTrue(m_linkd.runTopologyDiscovery(asw01.getId()));
    assertNull(m_linkd.getQueryManager().useBridgeTopologyUpdateBFT(asw01.getId()));
    assertEquals(1, m_bridgeElementDao.countAll());
    assertEquals(0, m_bridgeStpLinkDao.countAll());
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(40, m_bridgeMacLinkDao.countAll());
    for (BridgeMacLink link : m_bridgeMacLinkDao.findAll()) {
        System.err.println(link.printTopology());
    }
    assertTrue(m_linkd.runSingleSnmpCollection(asw01.getId()));
    assertEquals(1, m_bridgeElementDao.countAll());
    assertEquals(0, m_bridgeStpLinkDao.countAll());
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(40, m_bridgeMacLinkDao.countAll());
    Thread.sleep(5000);
    assertTrue(m_linkd.runTopologyDiscovery(asw01.getId()));
    assertEquals(1, m_bridgeElementDao.countAll());
    assertEquals(0, m_bridgeStpLinkDao.countAll());
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(40, m_bridgeMacLinkDao.countAll());
    for (BridgeMacLink link : m_bridgeMacLinkDao.findAll()) {
        System.err.println(link.printTopology());
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 20 with JUnitSnmpAgents

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

the class JUnitSnmpAgentExecutionListener method beforeTestMethod.

@Override
public void beforeTestMethod(final TestContext testContext) throws Exception {
    super.beforeTestClass(testContext);
    final JUnitSnmpAgents agents = findAgentListAnnotation(testContext);
    final JUnitSnmpAgent agent = findAgentAnnotation(testContext);
    // save the existing strategy property
    String strategy = System.getProperty(STRATEGY_CLASS_PROPERTY);
    testContext.setAttribute(STRATEGY_CLASS_KEY, strategy);
    // if no annotations exists then do nothing
    if (agents == null && agent == null) {
        // no annotations found
        return;
    }
    // determine if we should use the mock strategry
    boolean useMockSnmpStrategy = shouldUseMockStrategy(agents, agent);
    // override the configured strategy to use the mock strategy if necessary
    if (useMockSnmpStrategy) {
        strategy = MockSnmpStrategy.class.getName();
        System.setProperty(STRATEGY_CLASS_PROPERTY, MockSnmpStrategy.class.getName());
        LOG.info("Forcing JUnit SNMP Agent to use mock strategy");
    }
    LOG.debug("Initializing JUnit SNMP Agent with strategy: {}", strategy == null ? "default" : strategy);
    final MockSnmpDataProvider provider = useMockSnmpStrategy ? new MockSnmpStrategyDataProvider() : new MockSnmpAgentDataProvider();
    testContext.setAttribute(PROVIDER_KEY, provider);
    if (agents != null) {
        for (final JUnitSnmpAgent a : agents.value()) {
            handleSnmpAgent(testContext, a, useMockSnmpStrategy, provider);
        }
    }
    handleSnmpAgent(testContext, agent, useMockSnmpStrategy, provider);
    if (testContext.getTestInstance() instanceof MockSnmpDataProviderAware) {
        LOG.debug("injecting data provider into MockSnmpDataProviderAware test: {}", testContext.getTestInstance());
        ((MockSnmpDataProviderAware) testContext.getTestInstance()).setMockSnmpDataProvider(provider);
    }
}
Also used : MockSnmpStrategy(org.opennms.netmgt.snmp.mock.MockSnmpStrategy) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

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