Search in sources :

Example 1 with IPAddressRangeSet

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

Example 2 with IPAddressRangeSet

use of org.opennms.core.network.IPAddressRangeSet in project opennms by OpenNMS.

the class SnmpEventInfoTest method testListAdd.

@Test
public void testListAdd() {
    IPAddressRange r = new IPAddressRange("192.168.1.10", "192.168.1.20");
    IPAddressRangeSet ranges = new IPAddressRangeSet();
    ranges.add(r);
    assertArrayEquals(new IPAddressRange[] { r }, ranges.toArray());
    IPAddressRange s = new IPAddressRange("192.168.1.30", "192.168.1.40");
    ranges.add(s);
    assertArrayEquals(new IPAddressRange[] { r, s }, ranges.toArray());
    IPAddressRange t = new IPAddressRange("192.168.1.2", "192.168.1.8");
    ranges.add(t);
    assertArrayEquals(new IPAddressRange[] { t, r, s }, ranges.toArray());
    IPAddressRange u = new IPAddressRange("192.168.1.22", "192.168.1.28");
    ranges.add(u);
    assertArrayEquals(new IPAddressRange[] { t, r, u, s }, ranges.toArray());
    ranges.add(new IPAddressRange("192.168.1.18", "192.168.1.24"));
    assertArrayEquals(new IPAddressRange[] { t, new IPAddressRange("192.168.1.10", "192.168.1.28"), s }, ranges.toArray());
    ranges.add(new IPAddressRange("192.168.1.9", "192.168.1.9"));
    assertArrayEquals(new IPAddressRange[] { new IPAddressRange("192.168.1.2", "192.168.1.28"), s }, ranges.toArray());
}
Also used : IPAddressRangeSet(org.opennms.core.network.IPAddressRangeSet) IPAddressRange(org.opennms.core.network.IPAddressRange) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 IPAddressRange (org.opennms.core.network.IPAddressRange)2 IPAddressRangeSet (org.opennms.core.network.IPAddressRangeSet)2