use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.
the class RangeChunkerTest method testCoalesceConsecutiveSpecifics.
@Test
public void testCoalesceConsecutiveSpecifics() {
DiscoveryConfiguration config = new DiscoveryConfiguration();
for (int i = 0; i < 5; i++) {
Specific specific = new Specific();
specific.setAddress("10.0.0." + i);
specific.setForeignSource("ABC");
specific.setLocation("123");
specific.setRetries(1);
specific.setTimeout(1000l);
config.addSpecific(specific);
}
Map<String, List<DiscoveryJob>> jobs = new RangeChunker(ipAddressFilter).chunk(config);
printJobs(jobs);
// The specifics have been combined into one range
assertEquals(1, jobs.size());
assertEquals(1, jobs.get("123").get(0).getRanges().size());
IPPollRange range = jobs.get("123").get(0).getRanges().iterator().next();
assertEquals("10.0.0.0", new IPAddress(range.getAddressRange().getBegin()).toString());
assertEquals("10.0.0.4", new IPAddress(range.getAddressRange().getEnd()).toString());
}
use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.
the class AgentResponseCollectionTest method data.
@Parameters
public static Collection<Object[]> data() throws ParseException, UnknownHostException {
final Map<String, String> parameters = new HashMap<String, String>();
parameters.put("options", "value");
final String ipAddr = "127.0.0.1";
// Instantiate the InetAddress like the InetAddressXmlAdapter does
final InetAddress inetAddr = new IPAddress(ipAddr).toInetAddress();
final AgentResponse response = new AgentResponse(inetAddr, 161, "SNMP", parameters);
final AgentResponseCollection responses = new AgentResponseCollection(Arrays.asList(response));
return Arrays.asList(new Object[][] { { responses, "<agents count=\"1\" totalCount=\"1\" offset=\"0\">" + "<agent>" + " <address>" + ipAddr + "</address>" + " <port>161</port>" + " <serviceName>SNMP</serviceName>" + " <parameters>" + " <entry>" + " <key>options</key>" + " <value>value</value>" + " </entry>" + " </parameters>" + "</agent>" + "</agents>", null } });
}
use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.
the class JdbcFilterDaoIT method verifyPerformance.
// Verifies that if a bunch of interfaces exists, checking if an ip address is valid should be faster
// than retrieving all interfaces.
// See HZN-1161 for more details.
@Test
public void verifyPerformance() {
// Create a bunch of interfaces
final OnmsNode node1 = m_populator.getNode1();
final IPAddressRange ipAddresses = new IPAddressRange("10.10.0.0", "10.10.255.255");
final Iterator<IPAddress> iterator = ipAddresses.iterator();
while (iterator.hasNext()) {
IPAddress address = iterator.next();
OnmsIpInterface ipInterface = new OnmsIpInterface();
ipInterface.setNode(node1);
ipInterface.setIpAddress(address.toInetAddress());
m_interfaceDao.save(ipInterface);
}
final int numberOfInterfaces = m_interfaceDao.countAll();
assertThat(numberOfInterfaces, greaterThan(255 * 255));
// verify
assertThat(m_dao.getActiveIPAddressList("IPADDR != '0.0.0.0'"), Matchers.hasSize(numberOfInterfaces));
assertThat(m_dao.isValid("10.10.0.1", "IPADDR != '0.0.0.0'"), is(true));
}
use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.
the class SnmpPoller method reloadSnmpConfig.
/**
* <p>reloadSnmpConfig</p>
*
* @param event a {@link org.opennms.netmgt.xml.event.Event} object.
*/
@EventHandler(uei = EventConstants.CONFIGURE_SNMP_EVENT_UEI)
public void reloadSnmpConfig(Event event) {
LOG.debug("reloadSnmpConfig: managing event: {}", event.getUei());
try {
Thread.sleep(5000);
} catch (final InterruptedException e) {
LOG.debug("interrupted while waiting for reload", e);
Thread.currentThread().interrupt();
}
SnmpEventInfo info = null;
try {
info = new SnmpEventInfo(event);
if (StringUtils.isBlank(info.getFirstIPAddress())) {
LOG.error("configureSNMPHandler: event contained invalid firstIpAddress. {}", event);
return;
}
} catch (final Throwable e) {
LOG.error("reloadSnmpConfig: ", e);
return;
}
final IPAddressRange range = new IPAddressRange(info.getFirstIPAddress(), info.getLastIPAddress());
for (final IPAddress ipaddr : range) {
LOG.debug("reloadSnmpConfig: found ipaddr: {}", ipaddr);
if (getNetwork().hasPollableInterface(ipaddr.toDbString())) {
LOG.debug("reloadSnmpConfig: recreating the Interface to poll: {}", ipaddr);
getNetwork().delete(ipaddr.toDbString());
scheduleNewSnmpInterface(ipaddr.toDbString());
} else {
LOG.debug("reloadSnmpConfig: no Interface found for ipaddr: {}", ipaddr);
}
}
}
use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.
the class IPAddressRangeTest method testIterator.
public void testIterator() {
assertEquals(new BigInteger("3"), small.size());
Iterator<IPAddress> it = small.iterator();
assertTrue(it.hasNext());
assertEquals(addr2, it.next());
assertTrue(it.hasNext());
assertEquals(addr2.incr(), it.next());
assertTrue(it.hasNext());
assertEquals(addr3, it.next());
assertFalse(it.hasNext());
}
Aggregations