use of org.opennms.core.network.IPAddressRange in project opennms by OpenNMS.
the class SnmpEventInfoTest method testRemove.
@Test
public void testRemove() {
IPAddressRange r = new IPAddressRange("192.168.1.10", "192.168.1.20");
assertArrayEquals(new IPAddressRange[0], r.remove(r));
assertArrayEquals(new IPAddressRange[0], r.remove(new IPAddressRange("192.168.1.5", "192.168.1.27")));
assertArrayEquals(new IPAddressRange[] { r }, r.remove(new IPAddressRange("192.168.1.5", "192.168.1.7")));
assertArrayEquals(new IPAddressRange[] { r }, r.remove(new IPAddressRange("192.168.1.22", "192.168.1.27")));
assertArrayEquals(new IPAddressRange[] { new IPAddressRange("192.168.1.15", "192.168.1.20") }, r.remove(new IPAddressRange("192.168.1.5", "192.168.1.14")));
assertArrayEquals(new IPAddressRange[] { new IPAddressRange("192.168.1.10", "192.168.1.14") }, r.remove(new IPAddressRange("192.168.1.15", "192.168.1.24")));
assertArrayEquals(new IPAddressRange[] { new IPAddressRange("192.168.1.10", "192.168.1.14"), new IPAddressRange("192.168.1.16", "192.168.1.20") }, r.remove(new IPAddressRange("192.168.1.15", "192.168.1.15")));
}
use of org.opennms.core.network.IPAddressRange in project opennms by OpenNMS.
the class SnmpEventInfoTest method testContainsRange.
@Test
public void testContainsRange() {
IPAddressRange r = new IPAddressRange("192.168.1.1", "192.168.1.10");
assertTrue(r.contains(new IPAddressRange("192.168.1.1", "192.168.1.1")));
assertTrue(r.contains(new IPAddressRange("192.168.1.10", "192.168.1.10")));
assertTrue(r.contains(new IPAddressRange("192.168.1.2", "192.168.1.7")));
assertFalse(r.contains(new IPAddressRange("192.168.1.0", "192.168.1.1")));
assertFalse(r.contains(new IPAddressRange("192.168.1.2", "192.168.1.11")));
assertFalse(r.contains(new IPAddressRange("192.168.1.0", "192.168.1.11")));
}
use of org.opennms.core.network.IPAddressRange in project opennms by OpenNMS.
the class MergeableDefinition method mergeMatchingAttributeDef.
/**
* This method is called when a definition is found in the config and
* that has the same attributes as the params in the configureSNMP event and
* the IP specific/range needs to be merged into the definition.
*
* @param eventDefefinition a {@link org.opennms.netmgt.config.MergeableDefinition} object.
*/
protected void mergeMatchingAttributeDef(MergeableDefinition eventDefinition) {
m_configRanges.addAll(eventDefinition.getAddressRanges());
getConfigDef().setRanges(new ArrayList<Range>());
getConfigDef().setSpecifics(new ArrayList<String>());
for (IPAddressRange range : m_configRanges) {
if (range.isSingleton()) {
getConfigDef().addSpecific(range.getBegin().toUserString());
} else {
Range xmlRange = new Range();
xmlRange.setBegin(range.getBegin().toUserString());
xmlRange.setEnd(range.getEnd().toUserString());
getConfigDef().addRange(xmlRange);
}
}
}
use of org.opennms.core.network.IPAddressRange in project opennms by OpenNMS.
the class SnmpEventInfoTest method testListRemove.
@Test
public void testListRemove() {
// {[1..100]}
IPAddressRange r = new IPAddressRange("192.168.1.1", "192.168.1.100");
IPAddressRangeSet ranges = new IPAddressRangeSet();
ranges.add(r);
IPAddressRange s = new IPAddressRange("192.168.1.30", "192.168.1.40");
// {[1..29],[41..100]}
ranges.remove(s);
assertArrayEquals(new IPAddressRange[] { new IPAddressRange("192.168.1.1", "192.168.1.29"), new IPAddressRange("192.168.1.41", "192.168.1.100") }, ranges.toArray());
IPAddressRange t = new IPAddressRange("192.168.1.20", "192.168.1.35");
// {[1..19],[41..100]}
ranges.remove(t);
assertArrayEquals(new IPAddressRange[] { new IPAddressRange("192.168.1.1", "192.168.1.19"), new IPAddressRange("192.168.1.41", "192.168.1.100") }, ranges.toArray());
IPAddressRange u = new IPAddressRange("192.168.1.35", "192.168.1.50");
// {[1..19],[51..100]}
ranges.remove(u);
assertArrayEquals(new IPAddressRange[] { new IPAddressRange("192.168.1.1", "192.168.1.19"), new IPAddressRange("192.168.1.51", "192.168.1.100") }, ranges.toArray());
// {1..19],[51..59],[71..100]}
ranges.remove(new IPAddressRange("192.168.1.60", "192.168.1.70"));
assertArrayEquals(new IPAddressRange[] { new IPAddressRange("192.168.1.1", "192.168.1.19"), new IPAddressRange("192.168.1.51", "192.168.1.59"), new IPAddressRange("192.168.1.71", "192.168.1.100") }, ranges.toArray());
// {1..9],[81..100}
ranges.remove(new IPAddressRange("192.168.1.10", "192.168.1.80"));
assertArrayEquals(new IPAddressRange[] { new IPAddressRange("192.168.1.1", "192.168.1.9"), new IPAddressRange("192.168.1.81", "192.168.1.100") }, ranges.toArray());
}
use of org.opennms.core.network.IPAddressRange 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));
}
Aggregations