use of android.net.IpPrefix in project android_frameworks_base by AOSPA.
the class LinkPropertiesTest method testIsReachable.
@SmallTest
// Failing.
@Suppress
public void testIsReachable() {
final LinkProperties v4lp = new LinkProperties();
assertFalse(v4lp.isReachable(DNS1));
assertFalse(v4lp.isReachable(DNS2));
// Add an on-link route, making the on-link DNS server reachable,
// but there is still no IPv4 address.
assertTrue(v4lp.addRoute(new RouteInfo(new IpPrefix(NetworkUtils.numericToInetAddress("75.208.0.0"), 16))));
assertFalse(v4lp.isReachable(DNS1));
assertFalse(v4lp.isReachable(DNS2));
// Adding an IPv4 address (right now, any IPv4 address) means we use
// the routes to compute likely reachability.
assertTrue(v4lp.addLinkAddress(new LinkAddress(ADDRV4, 16)));
assertTrue(v4lp.isReachable(DNS1));
assertFalse(v4lp.isReachable(DNS2));
// Adding a default route makes the off-link DNS server reachable.
assertTrue(v4lp.addRoute(new RouteInfo(GATEWAY1)));
assertTrue(v4lp.isReachable(DNS1));
assertTrue(v4lp.isReachable(DNS2));
final LinkProperties v6lp = new LinkProperties();
final InetAddress kLinkLocalDns = NetworkUtils.numericToInetAddress("fe80::6:1");
final InetAddress kLinkLocalDnsWithScope = NetworkUtils.numericToInetAddress("fe80::6:2%43");
final InetAddress kOnLinkDns = NetworkUtils.numericToInetAddress("2001:db8:85a3::53");
assertFalse(v6lp.isReachable(kLinkLocalDns));
assertFalse(v6lp.isReachable(kLinkLocalDnsWithScope));
assertFalse(v6lp.isReachable(kOnLinkDns));
assertFalse(v6lp.isReachable(DNS6));
// Add a link-local route, making the link-local DNS servers reachable. Because
// we assume the presence of an IPv6 link-local address, link-local DNS servers
// are considered reachable, but only those with a non-zero scope identifier.
assertTrue(v6lp.addRoute(new RouteInfo(new IpPrefix(NetworkUtils.numericToInetAddress("fe80::"), 64))));
assertFalse(v6lp.isReachable(kLinkLocalDns));
assertTrue(v6lp.isReachable(kLinkLocalDnsWithScope));
assertFalse(v6lp.isReachable(kOnLinkDns));
assertFalse(v6lp.isReachable(DNS6));
// Add a link-local address--nothing changes.
assertTrue(v6lp.addLinkAddress(LINKADDRV6LINKLOCAL));
assertFalse(v6lp.isReachable(kLinkLocalDns));
assertTrue(v6lp.isReachable(kLinkLocalDnsWithScope));
assertFalse(v6lp.isReachable(kOnLinkDns));
assertFalse(v6lp.isReachable(DNS6));
// Add a global route on link, but no global address yet. DNS servers reachable
// via a route that doesn't require a gateway: give them the benefit of the
// doubt and hope the link-local source address suffices for communication.
assertTrue(v6lp.addRoute(new RouteInfo(new IpPrefix(NetworkUtils.numericToInetAddress("2001:db8:85a3::"), 64))));
assertFalse(v6lp.isReachable(kLinkLocalDns));
assertTrue(v6lp.isReachable(kLinkLocalDnsWithScope));
assertTrue(v6lp.isReachable(kOnLinkDns));
assertFalse(v6lp.isReachable(DNS6));
// Add a global address; the on-link global address DNS server is (still)
// presumed reachable.
assertTrue(v6lp.addLinkAddress(new LinkAddress(ADDRV6, 64)));
assertFalse(v6lp.isReachable(kLinkLocalDns));
assertTrue(v6lp.isReachable(kLinkLocalDnsWithScope));
assertTrue(v6lp.isReachable(kOnLinkDns));
assertFalse(v6lp.isReachable(DNS6));
// Adding a default route makes the off-link DNS server reachable.
assertTrue(v6lp.addRoute(new RouteInfo(GATEWAY62)));
assertFalse(v6lp.isReachable(kLinkLocalDns));
assertTrue(v6lp.isReachable(kLinkLocalDnsWithScope));
assertTrue(v6lp.isReachable(kOnLinkDns));
assertTrue(v6lp.isReachable(DNS6));
// Check isReachable on stacked links. This requires that the source IP address be assigned
// on the interface returned by the route lookup.
LinkProperties stacked = new LinkProperties();
// Can't add a stacked link without an interface name.
stacked.setInterfaceName("v4-test0");
v6lp.addStackedLink(stacked);
InetAddress stackedAddress = Address("192.0.0.4");
LinkAddress stackedLinkAddress = new LinkAddress(stackedAddress, 32);
assertFalse(v6lp.isReachable(stackedAddress));
stacked.addLinkAddress(stackedLinkAddress);
assertFalse(v6lp.isReachable(stackedAddress));
stacked.addRoute(new RouteInfo(stackedLinkAddress));
assertTrue(stacked.isReachable(stackedAddress));
assertTrue(v6lp.isReachable(stackedAddress));
assertFalse(v6lp.isReachable(DNS1));
stacked.addRoute(new RouteInfo((IpPrefix) null, stackedAddress));
assertTrue(v6lp.isReachable(DNS1));
}
use of android.net.IpPrefix in project android_frameworks_base by AOSPA.
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) {
}
}
use of android.net.IpPrefix in project android_frameworks_base by AOSPA.
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) {
}
}
use of android.net.IpPrefix in project android_frameworks_base by AOSPA.
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;
}
use of android.net.IpPrefix in project android_frameworks_base by AOSPA.
the class IpPrefixTest method assertParcelingIsLossless.
public void assertParcelingIsLossless(IpPrefix p) {
IpPrefix p2 = passThroughParcel(p);
assertEquals(p, p2);
}
Aggregations