Search in sources :

Example 91 with RouteInfo

use of android.net.RouteInfo in project android_frameworks_base by ParanoidAndroid.

the class RouteInfoTest method testParceling.

public void testParceling() {
    RouteInfo r;
    r = new RouteInfo(Prefix("::/0"), Address("2001:db8::"), null);
    assertParcelingIsLossless(r);
    r = new RouteInfo(Prefix("192.0.2.0/24"), null, "wlan0");
    assertParcelingIsLossless(r);
}
Also used : RouteInfo(android.net.RouteInfo)

Example 92 with RouteInfo

use of android.net.RouteInfo in project android_frameworks_base by ParanoidAndroid.

the class RouteInfoTest method testEquals.

public void testEquals() {
    // IPv4
    RouteInfo r1 = new RouteInfo(Prefix("2001:db8:ace::/48"), Address("2001:db8::1"), "wlan0");
    RouteInfo r2 = new RouteInfo(Prefix("2001:db8:ace::/48"), Address("2001:db8::1"), "wlan0");
    assertAreEqual(r1, r2);
    RouteInfo r3 = new RouteInfo(Prefix("2001:db8:ace::/49"), Address("2001:db8::1"), "wlan0");
    RouteInfo r4 = new RouteInfo(Prefix("2001:db8:ace::/48"), Address("2001:db8::2"), "wlan0");
    RouteInfo r5 = new RouteInfo(Prefix("2001:db8:ace::/48"), Address("2001:db8::1"), "rmnet0");
    assertAreNotEqual(r1, r3);
    assertAreNotEqual(r1, r4);
    assertAreNotEqual(r1, r5);
    // IPv6
    r1 = new RouteInfo(Prefix("192.0.2.0/25"), Address("192.0.2.1"), "wlan0");
    r2 = new RouteInfo(Prefix("192.0.2.0/25"), Address("192.0.2.1"), "wlan0");
    assertAreEqual(r1, r2);
    r3 = new RouteInfo(Prefix("192.0.2.0/24"), Address("192.0.2.1"), "wlan0");
    r4 = new RouteInfo(Prefix("192.0.2.0/25"), Address("192.0.2.2"), "wlan0");
    r5 = new RouteInfo(Prefix("192.0.2.0/25"), Address("192.0.2.1"), "rmnet0");
    assertAreNotEqual(r1, r3);
    assertAreNotEqual(r1, r4);
    assertAreNotEqual(r1, r5);
    // Interfaces (but not destinations or gateways) can be null.
    r1 = new RouteInfo(Prefix("192.0.2.0/25"), Address("192.0.2.1"), null);
    r2 = new RouteInfo(Prefix("192.0.2.0/25"), Address("192.0.2.1"), null);
    r3 = new RouteInfo(Prefix("192.0.2.0/24"), Address("192.0.2.1"), "wlan0");
    assertAreEqual(r1, r2);
    assertAreNotEqual(r1, r3);
}
Also used : RouteInfo(android.net.RouteInfo)

Example 93 with RouteInfo

use of android.net.RouteInfo in project android_frameworks_base by ParanoidAndroid.

the class RouteInfoTest method passThroughParcel.

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

Example 94 with RouteInfo

use of android.net.RouteInfo in project platform_frameworks_base by android.

the class LinkPropertiesTest method testRouteInterfaces.

@SmallTest
public void testRouteInterfaces() {
    LinkAddress prefix = new LinkAddress(NetworkUtils.numericToInetAddress("2001:db8::"), 32);
    InetAddress address = ADDRV6;
    // Add a route with no interface to a LinkProperties with no interface. No errors.
    LinkProperties lp = new LinkProperties();
    RouteInfo r = new RouteInfo(prefix, address, null);
    assertTrue(lp.addRoute(r));
    assertEquals(1, lp.getRoutes().size());
    assertAllRoutesHaveInterface(null, lp);
    // Adding the same route twice has no effect.
    assertFalse(lp.addRoute(r));
    assertEquals(1, lp.getRoutes().size());
    // Add a route with an interface. Expect an exception.
    r = new RouteInfo(prefix, address, "wlan0");
    try {
        lp.addRoute(r);
        fail("Adding wlan0 route to LP with no interface, expect exception");
    } catch (IllegalArgumentException expected) {
    }
    // Change the interface name. All the routes should change their interface name too.
    lp.setInterfaceName("rmnet0");
    assertAllRoutesHaveInterface("rmnet0", lp);
    // Now add a route with the wrong interface. This causes an exception too.
    try {
        lp.addRoute(r);
        fail("Adding wlan0 route to rmnet0 LP, expect exception");
    } catch (IllegalArgumentException expected) {
    }
    // If the interface name matches, the route is added.
    r = new RouteInfo(prefix, null, "wlan0");
    lp.setInterfaceName("wlan0");
    lp.addRoute(r);
    assertEquals(2, lp.getRoutes().size());
    assertAllRoutesHaveInterface("wlan0", lp);
    // Routes with null interfaces are converted to wlan0.
    r = RouteInfo.makeHostRoute(ADDRV6, null);
    lp.addRoute(r);
    assertEquals(3, lp.getRoutes().size());
    assertAllRoutesHaveInterface("wlan0", lp);
    // Check comparisons work.
    LinkProperties lp2 = new LinkProperties(lp);
    assertAllRoutesHaveInterface("wlan0", lp);
    assertEquals(0, lp.compareAllRoutes(lp2).added.size());
    assertEquals(0, lp.compareAllRoutes(lp2).removed.size());
    lp2.setInterfaceName("p2p0");
    assertAllRoutesHaveInterface("p2p0", lp2);
    assertEquals(3, lp.compareAllRoutes(lp2).added.size());
    assertEquals(3, lp.compareAllRoutes(lp2).removed.size());
}
Also used : LinkAddress(android.net.LinkAddress) RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress) LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 95 with RouteInfo

use of android.net.RouteInfo in project platform_frameworks_base by android.

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));
}
Also used : IpPrefix(android.net.IpPrefix) LinkAddress(android.net.LinkAddress) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress) SmallTest(android.test.suitebuilder.annotation.SmallTest) Suppress(android.test.suitebuilder.annotation.Suppress)

Aggregations

RouteInfo (android.net.RouteInfo)160 LinkProperties (android.net.LinkProperties)72 InetAddress (java.net.InetAddress)56 LinkAddress (android.net.LinkAddress)52 SmallTest (android.test.suitebuilder.annotation.SmallTest)45 IpPrefix (android.net.IpPrefix)35 Inet6Address (java.net.Inet6Address)14 Inet4Address (java.net.Inet4Address)12 IOException (java.io.IOException)11 StaticIpConfiguration (android.net.StaticIpConfiguration)10 EOFException (java.io.EOFException)8 DataInputStream (java.io.DataInputStream)7 HashMap (java.util.HashMap)7 Parcel (android.os.Parcel)6 BufferedInputStream (java.io.BufferedInputStream)6 FileInputStream (java.io.FileInputStream)6 UnknownHostException (java.net.UnknownHostException)6 ArrayList (java.util.ArrayList)6 UserInfo (android.content.pm.UserInfo)5 IpConfiguration (android.net.IpConfiguration)5