use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.
the class IPAddressRangeTest method testToIpAddrString.
public void testToIpAddrString() throws UnknownHostException {
assertEquals("0.0.0.0", InetAddressUtils.toIpAddrString(zero.toOctets()));
assertEquals("0.0.0.1", InetAddressUtils.toIpAddrString(one.toOctets()));
assertEquals("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", InetAddressUtils.toIpAddrString(maxIPv6.toOctets()));
assertEquals("ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffa", InetAddressUtils.toIpAddrString(maxIPv6MinusFive.toOctets()));
assertEquals("0000:0000:0000:0000:0000:0000:0000:0001", InetAddressUtils.toIpAddrString(new IPAddress("::1").toOctets()));
assertEquals("aaaa:0000:0000:0000:0000:0000:0000:0001", InetAddressUtils.toIpAddrString(new IPAddress("AAAA::1").toOctets()));
assertEquals("aaaa:0000:0000:0000:0000:0000:0000:0000", InetAddressUtils.toIpAddrString(new IPAddress("AAAA::").toOctets()));
assertEquals("00aa:0000:0000:0000:0000:0000:0000:0000", InetAddressUtils.toIpAddrString(new IPAddress("AA::").toOctets()));
assertEquals("aaaa:0000:0000:0000:0000:0000:0000:0000%15", InetAddressUtils.toIpAddrString(InetAddressUtils.addr("AAAA::%15")));
assertEquals("aaaa:0000:0000:0000:0000:0000:0000:0000", InetAddressUtils.toIpAddrString(InetAddressUtils.addr("AAAA::%0")));
}
use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.
the class IPAddressRangeTest method testToBigInteger.
public void testToBigInteger() {
IPAddress startAtZero = new IPAddress("0.0.0.0");
assertTrue(startAtZero.isPredecessorOf(one));
assertEquals(0L, startAtZero.toBigInteger().longValue());
startAtZero = startAtZero.incr();
startAtZero = startAtZero.incr();
startAtZero = startAtZero.incr();
startAtZero = startAtZero.incr();
assertEquals(4L, startAtZero.toBigInteger().longValue());
startAtZero = startAtZero.decr();
startAtZero = startAtZero.decr();
assertEquals(2L, startAtZero.toBigInteger().longValue());
assertTrue(startAtZero.isSuccessorOf(one));
assertEquals(1L, one.toBigInteger().longValue());
assertEquals((long) (Math.pow(2, 30) - 1.0), thirtyBitNumber.toBigInteger().longValue());
assertEquals((long) (Math.pow(2, 31) - 1.0), thirtyOneBitNumber.toBigInteger().longValue());
assertEquals((long) (Math.pow(2, 31)), thirtyTwoBit.toBigInteger().longValue());
assertEquals((long) (Math.pow(2, 32) - 1.0), maxIPv4.toBigInteger().longValue());
// assertEquals((long)(Math.pow(2, 16 * 8) - 1.0), maxIPv6.toBigInteger().longValue());
}
use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.
the class Package method hasExcludeRange.
public boolean hasExcludeRange(final String addr) {
final IPAddress ipAddr = new IPAddress(addr);
for (final ExcludeRange rng : getExcludeRanges()) {
final IPAddress begin = rng.getBeginAsAddress();
final IPAddress end = rng.getEndAsAddress();
if (ipAddr.isGreaterThanOrEqualTo(begin) && ipAddr.isLessThanOrEqualTo(end)) {
return true;
}
}
return false;
}
use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.
the class SnmpEventInfoTest method testAddressIncr.
@Test
public void testAddressIncr() {
IPAddress ipA = new IPAddress("::5");
assertEquals("::6", ipA.incr().toString());
IPAddress ipB = new IPAddress("::ffff:ffff");
assertEquals("::1:0:0", ipB.incr().toString());
IPAddress ipC = new IPAddress("::ff00:ffff");
assertEquals("::ff01:0", ipC.incr().toString());
IPAddress ipD = new IPAddress("::ff00:7fff");
assertEquals("::ff00:8000", ipD.incr().toString());
}
use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.
the class SnmpEventInfoTest method testConfigAddressDecr.
@Test
public void testConfigAddressDecr() {
IPAddress a = new IPAddress("::6");
assertEquals("::5", a.decr().toString());
IPAddress b = new IPAddress("::1:0:0");
assertEquals("::ffff:ffff", b.decr().toString());
IPAddress c = new IPAddress("ff::ffff:1:0");
assertEquals("ff::ffff:0:ffff", c.decr().toString());
IPAddress d = new IPAddress("ff::ffff:1:8000");
assertEquals("ff::ffff:1:7fff", d.decr().toString());
}
Aggregations