Search in sources :

Example 1 with IpPrefix

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

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 2 with IpPrefix

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

the class IpPrefixTest method assertParcelingIsLossless.

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

Example 3 with IpPrefix

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

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 4 with IpPrefix

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

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)

Example 5 with IpPrefix

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

the class RouteInfoTest method testMatches.

public void testMatches() {
    class PatchedRouteInfo {

        private final RouteInfo mRouteInfo;

        public PatchedRouteInfo(IpPrefix destination, InetAddress gateway, String iface) {
            mRouteInfo = new RouteInfo(destination, gateway, iface);
        }

        public boolean matches(InetAddress destination) {
            return mRouteInfo.matches(destination);
        }
    }
    PatchedRouteInfo r;
    r = new PatchedRouteInfo(Prefix("2001:db8:f00::ace:d00d/127"), null, "rmnet0");
    assertTrue(r.matches(Address("2001:db8:f00::ace:d00c")));
    assertTrue(r.matches(Address("2001:db8:f00::ace:d00d")));
    assertFalse(r.matches(Address("2001:db8:f00::ace:d00e")));
    assertFalse(r.matches(Address("2001:db8:f00::bad:d00d")));
    assertFalse(r.matches(Address("2001:4868:4860::8888")));
    assertFalse(r.matches(Address("8.8.8.8")));
    r = new PatchedRouteInfo(Prefix("192.0.2.0/23"), null, "wlan0");
    assertTrue(r.matches(Address("192.0.2.43")));
    assertTrue(r.matches(Address("192.0.3.21")));
    assertFalse(r.matches(Address("192.0.0.21")));
    assertFalse(r.matches(Address("8.8.8.8")));
    PatchedRouteInfo ipv6Default = new PatchedRouteInfo(Prefix("::/0"), null, "rmnet0");
    assertTrue(ipv6Default.matches(Address("2001:db8::f00")));
    assertFalse(ipv6Default.matches(Address("192.0.2.1")));
    PatchedRouteInfo ipv4Default = new PatchedRouteInfo(Prefix("0.0.0.0/0"), null, "rmnet0");
    assertTrue(ipv4Default.matches(Address("255.255.255.255")));
    assertTrue(ipv4Default.matches(Address("192.0.2.1")));
    assertFalse(ipv4Default.matches(Address("2001:db8::f00")));
}
Also used : IpPrefix(android.net.IpPrefix) RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress)

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