Search in sources :

Example 1 with OnmsAccessPoint

use of org.opennms.netmgt.model.OnmsAccessPoint in project opennms by OpenNMS.

the class AccessPointDaoTest method testFindByPhysAddr.

@Test
@Transactional
public void testFindByPhysAddr() {
    addNewAccessPoint("ap1", AP1_MAC, "default-package");
    addNewAccessPoint("ap2", AP2_MAC, "not-default-package");
    OnmsAccessPoint ap1 = m_accessPointDao.get(AP1_MAC);
    assertEquals("default-package", ap1.getPollingPackage());
    OnmsAccessPoint ap2 = m_accessPointDao.get(AP2_MAC);
    assertEquals("not-default-package", ap2.getPollingPackage());
}
Also used : OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with OnmsAccessPoint

use of org.opennms.netmgt.model.OnmsAccessPoint in project opennms by OpenNMS.

the class AccessPointDaoTest method addNewAccessPoint.

private void addNewAccessPoint(String name, String mac, String pkg) {
    NetworkBuilder nb = new NetworkBuilder();
    nb.addNode(name).setForeignSource("apmd").setForeignId(name);
    nb.addInterface("169.254.0.1");
    m_nodeDao.save(nb.getCurrentNode());
    final OnmsAccessPoint ap1 = new OnmsAccessPoint(mac, nb.getCurrentNode().getId(), pkg);
    ap1.setStatus(AccessPointStatus.UNKNOWN);
    m_accessPointDao.save(ap1);
    m_nodeDao.flush();
    m_accessPointDao.flush();
}
Also used : NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint)

Example 3 with OnmsAccessPoint

use of org.opennms.netmgt.model.OnmsAccessPoint in project opennms by OpenNMS.

the class InstanceStrategyIntegrationTest method testReloadDaemon.

/*
     * Test the behaviour when the configuration is modified and the daemon is
     * reloaded. Verify: That the proper events are sent by the daemon. The AP
     * state in the database after the poll.
     */
@Test
@JUnitSnmpAgent(host = "10.1.0.2", resource = SNMP_DATA_PATH + "10.1.0.2-walk.txt")
public void testReloadDaemon() throws Exception {
    // Add AP1 and AP2 to the default package
    addNewAccessPoint("ap1", AP1_MAC, "default");
    addNewAccessPoint("ap2", AP2_MAC, "default");
    // Add AP3 to a separate package
    addNewAccessPoint("ap3", AP3_MAC, "not-default");
    // Add a controller to the default package
    addNewController("amc1", "10.1.0.2", "default");
    // Set AP1 as UP
    setOidValueForAccessPoint("10.1.0.2", AP1_MAC, 1);
    // Initialize and start the daemon
    initApmdWithConfig(getEmptyConfig());
    m_apm.start();
    // Sleep for a polling cycle
    sleep(POLLING_INTERVAL_DELTA);
    // Verify the state of the APs in the database
    OnmsAccessPoint ap1 = m_accessPointDao.get(AP1_MAC);
    LOG.debug(ap1.getStatus().getLabel());
    assertTrue(ap1.getStatus() == AccessPointStatus.UNKNOWN);
    OnmsAccessPoint ap2 = m_accessPointDao.get(AP2_MAC);
    assertTrue(ap2.getStatus() == AccessPointStatus.UNKNOWN);
    OnmsAccessPoint ap3 = m_accessPointDao.get(AP3_MAC);
    assertTrue(ap3.getStatus() == AccessPointStatus.UNKNOWN);
    // Anticipate the events
    anticipateApStatusEvent(AP1_MAC, "UP");
    anticipateApStatusEvent(AP2_MAC, "DOWN");
    // Update the configuration and send a reload event to the daemon
    updateConfigAndReloadDaemon(getStandardConfig(), true);
    // Verify the events
    verifyAnticipated(POLLING_INTERVAL_DELTA);
    // Verify the state of the APs in the database
    ap1 = m_accessPointDao.get(AP1_MAC);
    assertTrue(ap1.getStatus() == AccessPointStatus.ONLINE);
    ap2 = m_accessPointDao.get(AP2_MAC);
    assertTrue(ap2.getStatus() == AccessPointStatus.OFFLINE);
    ap3 = m_accessPointDao.get(AP3_MAC);
    assertTrue(ap3.getStatus() == AccessPointStatus.UNKNOWN);
}
Also used : OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 4 with OnmsAccessPoint

use of org.opennms.netmgt.model.OnmsAccessPoint in project opennms by OpenNMS.

the class InstanceStrategyIntegrationTest method testApUpDown.

/*
     * Run a series of tests with a single controller and 3 access points.
     * Verify: That the proper events are sent by the daemon. The AP state in
     * the database after the poll.
     */
@Test
@JUnitSnmpAgent(host = "10.1.0.2", resource = SNMP_DATA_PATH + "10.1.0.2-walk.txt")
public void testApUpDown() throws Exception {
    // Add AP1 and AP2 to the default package
    addNewAccessPoint("ap1", AP1_MAC, "default");
    addNewAccessPoint("ap2", AP2_MAC, "default");
    // Add AP3 to a separate package
    addNewAccessPoint("ap3", AP3_MAC, "not-default");
    // Add a controller to the default package
    addNewController("amc1", "10.1.0.2", "default");
    // Set AP1 as UP and AP2 as DOWN
    setOidValueForAccessPoint("10.1.0.2", AP1_MAC, 1);
    setOidValueForAccessPoint("10.1.0.2", AP2_MAC, 0);
    // Anticipate the events
    anticipateApStatusEvent(AP1_MAC, "UP");
    anticipateApStatusEvent(AP2_MAC, "DOWN");
    // Initialize and start the daemon
    initApmdWithConfig(getStandardConfig());
    m_apm.start();
    // Verify the events
    verifyAnticipated(POLLING_INTERVAL_DELTA);
    // Verify the state of the APs in the database
    OnmsAccessPoint ap1 = m_accessPointDao.get(AP1_MAC);
    assertTrue(ap1.getStatus() == AccessPointStatus.ONLINE);
    OnmsAccessPoint ap2 = m_accessPointDao.get(AP2_MAC);
    assertTrue(ap2.getStatus() == AccessPointStatus.OFFLINE);
    OnmsAccessPoint ap3 = m_accessPointDao.get(AP3_MAC);
    assertTrue(ap3.getStatus() == AccessPointStatus.UNKNOWN);
    // Change AP3's package, the next poll should send an additional DOWN
    // event
    anticipateApStatusEvent(AP1_MAC, "UP");
    anticipateApStatusEvent(AP2_MAC, "DOWN");
    anticipateApStatusEvent(AP3_MAC, "DOWN");
    ap3.setPollingPackage("default");
    m_accessPointDao.update(ap3);
    m_accessPointDao.flush();
    // Verify the events
    verifyAnticipated(POLLING_INTERVAL_DELTA);
    // Update the data in the SNMP agent to show AP1 as DOWN
    anticipateApStatusEvent(AP1_MAC, "DOWN");
    anticipateApStatusEvent(AP2_MAC, "DOWN");
    anticipateApStatusEvent(AP3_MAC, "DOWN");
    setOidValueForAccessPoint("10.1.0.2", AP1_MAC, 2);
    // Verify the events
    verifyAnticipated(POLLING_INTERVAL_DELTA);
    // Verify the DB again, all APs should be DOWN now
    ap1 = m_accessPointDao.get(AP1_MAC);
    assertTrue(ap1.getStatus() == AccessPointStatus.OFFLINE);
    ap2 = m_accessPointDao.get(AP2_MAC);
    assertTrue(ap2.getStatus() == AccessPointStatus.OFFLINE);
    ap3 = m_accessPointDao.get(AP3_MAC);
    assertTrue(ap3.getStatus() == AccessPointStatus.OFFLINE);
    // Bring AP1 back UP
    anticipateApStatusEvent(AP1_MAC, "UP");
    anticipateApStatusEvent(AP2_MAC, "DOWN");
    anticipateApStatusEvent(AP3_MAC, "DOWN");
    setOidValueForAccessPoint("10.1.0.2", AP1_MAC, 1);
    // Verify the events
    verifyAnticipated(POLLING_INTERVAL_DELTA);
}
Also used : OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 5 with OnmsAccessPoint

use of org.opennms.netmgt.model.OnmsAccessPoint in project opennms by OpenNMS.

the class AccessPointMonitordTest method addNewAccessPoint.

@Transactional(propagation = Propagation.MANDATORY)
public void addNewAccessPoint(String name, String mac, String pkg) {
    NetworkBuilder nb = new NetworkBuilder();
    nb.addNode(name).setForeignSource("apmd").setForeignId(name);
    nb.addInterface("169.254.0.1");
    m_nodeDao.save(nb.getCurrentNode());
    final OnmsAccessPoint ap1 = new OnmsAccessPoint(mac, nb.getCurrentNode().getId(), pkg);
    ap1.setStatus(AccessPointStatus.UNKNOWN);
    m_accessPointDao.save(ap1);
    m_nodeDao.flush();
    m_accessPointDao.flush();
}
Also used : NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsAccessPoint (org.opennms.netmgt.model.OnmsAccessPoint)14 Test (org.junit.Test)7 JUnitSnmpAgent (org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)4 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)3 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 Map (java.util.Map)2 ParameterMap (org.opennms.core.utils.ParameterMap)2 OnmsAccessPointCollection (org.opennms.netmgt.model.OnmsAccessPointCollection)2 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)2 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)2 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)2 Transactional (org.springframework.transaction.annotation.Transactional)2 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)1 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 Event (org.opennms.netmgt.xml.event.Event)1