Search in sources :

Example 36 with IpPrefix

use of android.net.IpPrefix in project android_frameworks_base by crdroidandroid.

the class IpPrefixTest method testConstructor.

@SmallTest
public void testConstructor() {
    IpPrefix p;
    try {
        p = new IpPrefix((byte[]) null, 9);
        fail("Expected NullPointerException: null byte array");
    } catch (RuntimeException expected) {
    }
    try {
        p = new IpPrefix((InetAddress) null, 10);
        fail("Expected NullPointerException: null InetAddress");
    } catch (RuntimeException expected) {
    }
    try {
        p = new IpPrefix((String) null);
        fail("Expected NullPointerException: null String");
    } catch (RuntimeException expected) {
    }
    try {
        byte[] b2 = { 1, 2, 3, 4, 5 };
        p = new IpPrefix(b2, 29);
        fail("Expected IllegalArgumentException: invalid array length");
    } catch (IllegalArgumentException expected) {
    }
    try {
        p = new IpPrefix("1.2.3.4");
        fail("Expected IllegalArgumentException: no prefix length");
    } catch (IllegalArgumentException expected) {
    }
    try {
        p = new IpPrefix("1.2.3.4/");
        fail("Expected IllegalArgumentException: empty prefix length");
    } catch (IllegalArgumentException expected) {
    }
    try {
        p = new IpPrefix("foo/32");
        fail("Expected IllegalArgumentException: invalid address");
    } catch (IllegalArgumentException expected) {
    }
    try {
        p = new IpPrefix("1/32");
        fail("Expected IllegalArgumentException: deprecated IPv4 format");
    } catch (IllegalArgumentException expected) {
    }
    try {
        p = new IpPrefix("1.2.3.256/32");
        fail("Expected IllegalArgumentException: invalid IPv4 address");
    } catch (IllegalArgumentException expected) {
    }
    try {
        p = new IpPrefix("foo/32");
        fail("Expected IllegalArgumentException: non-address");
    } catch (IllegalArgumentException expected) {
    }
    try {
        p = new IpPrefix("f00:::/32");
        fail("Expected IllegalArgumentException: invalid IPv6 address");
    } catch (IllegalArgumentException expected) {
    }
}
Also used : IpPrefix(android.net.IpPrefix) InetAddress(java.net.InetAddress) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 37 with IpPrefix

use of android.net.IpPrefix in project android_frameworks_base by crdroidandroid.

the class IpPrefixTest method testParceling.

public void testParceling() {
    IpPrefix p;
    p = new IpPrefix("2001:4860:db8::/64");
    assertParcelingIsLossless(p);
    p = new IpPrefix("192.0.2.0/25");
    assertParcelingIsLossless(p);
}
Also used : IpPrefix(android.net.IpPrefix)

Example 38 with IpPrefix

use of android.net.IpPrefix in project android_frameworks_base by crdroidandroid.

the class IpPrefixTest method testMappedAddressesAreBroken.

@SmallTest
public void testMappedAddressesAreBroken() {
    // 192.0.2.0/24 != ::ffff:c000:0204/120, but because we use InetAddress,
    // we are unable to comprehend that.
    byte[] ipv6bytes = { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0xff, (byte) 0xff, (byte) 192, (byte) 0, (byte) 2, (byte) 0 };
    IpPrefix p = new IpPrefix(ipv6bytes, 120);
    // Fine.
    assertEquals(16, p.getRawAddress().length);
    // Fine.
    assertArrayEquals(ipv6bytes, p.getRawAddress());
    // Broken.
    assertEquals("192.0.2.0/120", p.toString());
    assertEquals(InetAddress.parseNumericAddress("192.0.2.0"), p.getAddress());
}
Also used : IpPrefix(android.net.IpPrefix) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 39 with IpPrefix

use of android.net.IpPrefix in project android_frameworks_base by crdroidandroid.

the class IpPrefixTest method testContains.

@SmallTest
public void testContains() {
    IpPrefix p = new IpPrefix("2001:db8:f00::ace:d00d/127");
    assertTrue(p.contains(Address("2001:db8:f00::ace:d00c")));
    assertTrue(p.contains(Address("2001:db8:f00::ace:d00d")));
    assertFalse(p.contains(Address("2001:db8:f00::ace:d00e")));
    assertFalse(p.contains(Address("2001:db8:f00::bad:d00d")));
    assertFalse(p.contains(Address("2001:4868:4860::8888")));
    assertFalse(p.contains(null));
    assertFalse(p.contains(Address("8.8.8.8")));
    p = new IpPrefix("192.0.2.0/23");
    assertTrue(p.contains(Address("192.0.2.43")));
    assertTrue(p.contains(Address("192.0.3.21")));
    assertFalse(p.contains(Address("192.0.0.21")));
    assertFalse(p.contains(Address("8.8.8.8")));
    assertFalse(p.contains(Address("2001:4868:4860::8888")));
    IpPrefix ipv6Default = new IpPrefix("::/0");
    assertTrue(ipv6Default.contains(Address("2001:db8::f00")));
    assertFalse(ipv6Default.contains(Address("192.0.2.1")));
    IpPrefix ipv4Default = new IpPrefix("0.0.0.0/0");
    assertTrue(ipv4Default.contains(Address("255.255.255.255")));
    assertTrue(ipv4Default.contains(Address("192.0.2.1")));
    assertFalse(ipv4Default.contains(Address("2001:db8::f00")));
}
Also used : IpPrefix(android.net.IpPrefix) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 40 with IpPrefix

use of android.net.IpPrefix in project android_frameworks_base by crdroidandroid.

the class IpPrefixTest method assertParcelingIsLossless.

public void assertParcelingIsLossless(IpPrefix p) {
    IpPrefix p2 = passThroughParcel(p);
    assertEquals(p, p2);
}
Also used : IpPrefix(android.net.IpPrefix)

Aggregations

IpPrefix (android.net.IpPrefix)89 SmallTest (android.test.suitebuilder.annotation.SmallTest)40 RouteInfo (android.net.RouteInfo)35 InetAddress (java.net.InetAddress)25 LinkAddress (android.net.LinkAddress)20 Inet6Address (java.net.Inet6Address)19 LinkProperties (android.net.LinkProperties)15 StaticIpConfiguration (android.net.StaticIpConfiguration)5 RaParams (android.net.ip.RouterAdvertisementDaemon.RaParams)5 Parcel (android.os.Parcel)5 Suppress (android.test.suitebuilder.annotation.Suppress)5 Inet4Address (java.net.Inet4Address)5 Random (java.util.Random)5 BufferOverflowException (java.nio.BufferOverflowException)4 ByteBuffer (java.nio.ByteBuffer)4