Search in sources :

Example 86 with IpPrefix

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

the class RouteInfoTest method testConstructor.

@SmallTest
public void testConstructor() {
    RouteInfo r;
    // Invalid input.
    try {
        r = new RouteInfo((IpPrefix) null, null, "rmnet0");
        fail("Expected RuntimeException:  destination and gateway null");
    } catch (RuntimeException e) {
    }
    // Null destination is default route.
    r = new RouteInfo((IpPrefix) null, Address("2001:db8::1"), null);
    assertEquals(Prefix("::/0"), r.getDestination());
    assertEquals(Address("2001:db8::1"), r.getGateway());
    assertNull(r.getInterface());
    r = new RouteInfo((IpPrefix) null, Address("192.0.2.1"), "wlan0");
    assertEquals(Prefix("0.0.0.0/0"), r.getDestination());
    assertEquals(Address("192.0.2.1"), r.getGateway());
    assertEquals("wlan0", r.getInterface());
    // Null gateway sets gateway to unspecified address (why?).
    r = new RouteInfo(Prefix("2001:db8:beef:cafe::/48"), null, "lo");
    assertEquals(Prefix("2001:db8:beef::/48"), r.getDestination());
    assertEquals(Address("::"), r.getGateway());
    assertEquals("lo", r.getInterface());
    r = new RouteInfo(Prefix("192.0.2.5/24"), null);
    assertEquals(Prefix("192.0.2.0/24"), r.getDestination());
    assertEquals(Address("0.0.0.0"), r.getGateway());
    assertNull(r.getInterface());
}
Also used : IpPrefix(android.net.IpPrefix) RouteInfo(android.net.RouteInfo) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 87 with IpPrefix

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

the class IpPrefixTest method testTruncation.

public void testTruncation() {
    IpPrefix p;
    p = new IpPrefix(IPV4_BYTES, 32);
    assertEquals("192.0.2.4/32", p.toString());
    p = new IpPrefix(IPV4_BYTES, 29);
    assertEquals("192.0.2.0/29", p.toString());
    p = new IpPrefix(IPV4_BYTES, 8);
    assertEquals("192.0.0.0/8", p.toString());
    p = new IpPrefix(IPV4_BYTES, 0);
    assertEquals("0.0.0.0/0", p.toString());
    try {
        p = new IpPrefix(IPV4_BYTES, 33);
        fail("Expected IllegalArgumentException: invalid prefix length");
    } catch (RuntimeException expected) {
    }
    try {
        p = new IpPrefix(IPV4_BYTES, 128);
        fail("Expected IllegalArgumentException: invalid prefix length");
    } catch (RuntimeException expected) {
    }
    try {
        p = new IpPrefix(IPV4_BYTES, -1);
        fail("Expected IllegalArgumentException: negative prefix length");
    } catch (RuntimeException expected) {
    }
    p = new IpPrefix(IPV6_BYTES, 128);
    assertEquals("2001:db8:dead:beef:f00::a0/128", p.toString());
    p = new IpPrefix(IPV6_BYTES, 122);
    assertEquals("2001:db8:dead:beef:f00::80/122", p.toString());
    p = new IpPrefix(IPV6_BYTES, 64);
    assertEquals("2001:db8:dead:beef::/64", p.toString());
    p = new IpPrefix(IPV6_BYTES, 3);
    assertEquals("2000::/3", p.toString());
    p = new IpPrefix(IPV6_BYTES, 0);
    assertEquals("::/0", p.toString());
    try {
        p = new IpPrefix(IPV6_BYTES, -1);
        fail("Expected IllegalArgumentException: negative prefix length");
    } catch (RuntimeException expected) {
    }
    try {
        p = new IpPrefix(IPV6_BYTES, 129);
        fail("Expected IllegalArgumentException: negative prefix length");
    } catch (RuntimeException expected) {
    }
}
Also used : IpPrefix(android.net.IpPrefix)

Example 88 with IpPrefix

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

the class IpPrefixTest method testHashCode.

@SmallTest
public void testHashCode() {
    IpPrefix p;
    int oldCode = -1;
    Random random = new Random();
    for (int i = 0; i < 100; i++) {
        if (random.nextBoolean()) {
            // IPv4.
            byte[] b = new byte[4];
            random.nextBytes(b);
            p = new IpPrefix(b, random.nextInt(33));
            assertNotEqual(oldCode, p.hashCode());
            oldCode = p.hashCode();
        } else {
            // IPv6.
            byte[] b = new byte[16];
            random.nextBytes(b);
            p = new IpPrefix(b, random.nextInt(129));
            assertNotEqual(oldCode, p.hashCode());
            oldCode = p.hashCode();
        }
    }
}
Also used : IpPrefix(android.net.IpPrefix) Random(java.util.Random) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 89 with IpPrefix

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

the class IpPrefixTest method passThroughParcel.

public IpPrefix passThroughParcel(IpPrefix p) {
    Parcel parcel = Parcel.obtain();
    IpPrefix p2 = null;
    try {
        p.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);
        p2 = IpPrefix.CREATOR.createFromParcel(parcel);
    } finally {
        parcel.recycle();
    }
    assertNotNull(p2);
    return p2;
}
Also used : IpPrefix(android.net.IpPrefix) Parcel(android.os.Parcel)

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