Search in sources :

Example 1 with IPAddress

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")));
}
Also used : IPAddress(org.opennms.core.network.IPAddress)

Example 2 with IPAddress

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());
}
Also used : IPAddress(org.opennms.core.network.IPAddress)

Example 3 with IPAddress

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;
}
Also used : IPAddress(org.opennms.core.network.IPAddress)

Example 4 with IPAddress

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());
}
Also used : IPAddress(org.opennms.core.network.IPAddress) Test(org.junit.Test)

Example 5 with IPAddress

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());
}
Also used : IPAddress(org.opennms.core.network.IPAddress) Test(org.junit.Test)

Aggregations

IPAddress (org.opennms.core.network.IPAddress)12 Test (org.junit.Test)4 IPAddressRange (org.opennms.core.network.IPAddressRange)2 BigInteger (java.math.BigInteger)1 InetAddress (java.net.InetAddress)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ParseException (org.json.simple.parser.ParseException)1 Parameters (org.junit.runners.Parameterized.Parameters)1 SnmpEventInfo (org.opennms.netmgt.config.SnmpEventInfo)1 DiscoveryConfiguration (org.opennms.netmgt.config.discovery.DiscoveryConfiguration)1 Specific (org.opennms.netmgt.config.discovery.Specific)1 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)1 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 IPPollRange (org.opennms.netmgt.model.discovery.IPPollRange)1