Search in sources :

Example 71 with RouteInfo

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

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 72 with RouteInfo

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

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)

Example 73 with RouteInfo

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

the class LinkPropertiesTest method testCompareProvisioning.

@SmallTest
public void testCompareProvisioning() {
    LinkProperties v4lp = new LinkProperties();
    v4lp.addLinkAddress(LINKADDRV4);
    v4lp.addRoute(new RouteInfo(GATEWAY1));
    v4lp.addDnsServer(DNS1);
    assertTrue(v4lp.isProvisioned());
    LinkProperties v4r = new LinkProperties(v4lp);
    v4r.removeDnsServer(DNS1);
    assertFalse(v4r.isProvisioned());
    assertEquals(ProvisioningChange.STILL_NOT_PROVISIONED, LinkProperties.compareProvisioning(v4r, v4r));
    assertEquals(ProvisioningChange.LOST_PROVISIONING, LinkProperties.compareProvisioning(v4lp, v4r));
    assertEquals(ProvisioningChange.GAINED_PROVISIONING, LinkProperties.compareProvisioning(v4r, v4lp));
    assertEquals(ProvisioningChange.STILL_PROVISIONED, LinkProperties.compareProvisioning(v4lp, v4lp));
    // Check that losing IPv4 provisioning on a dualstack network is
    // seen as a total loss of provisioning.
    LinkProperties v6lp = new LinkProperties();
    v6lp.addLinkAddress(LINKADDRV6);
    v6lp.addRoute(new RouteInfo(GATEWAY61));
    v6lp.addDnsServer(DNS6);
    assertFalse(v6lp.isIPv4Provisioned());
    assertTrue(v6lp.isIPv6Provisioned());
    assertTrue(v6lp.isProvisioned());
    LinkProperties v46lp = new LinkProperties(v6lp);
    v46lp.addLinkAddress(LINKADDRV4);
    v46lp.addRoute(new RouteInfo(GATEWAY1));
    v46lp.addDnsServer(DNS1);
    assertTrue(v46lp.isIPv4Provisioned());
    assertTrue(v46lp.isIPv6Provisioned());
    assertTrue(v46lp.isProvisioned());
    assertEquals(ProvisioningChange.STILL_PROVISIONED, LinkProperties.compareProvisioning(v4lp, v46lp));
    assertEquals(ProvisioningChange.STILL_PROVISIONED, LinkProperties.compareProvisioning(v6lp, v46lp));
    assertEquals(ProvisioningChange.LOST_PROVISIONING, LinkProperties.compareProvisioning(v46lp, v6lp));
    assertEquals(ProvisioningChange.LOST_PROVISIONING, LinkProperties.compareProvisioning(v46lp, v4lp));
    // Check that losing and gaining a secondary router does not change
    // the provisioning status.
    LinkProperties v6lp2 = new LinkProperties(v6lp);
    v6lp2.addRoute(new RouteInfo(GATEWAY62));
    assertTrue(v6lp2.isProvisioned());
    assertEquals(ProvisioningChange.STILL_PROVISIONED, LinkProperties.compareProvisioning(v6lp2, v6lp));
    assertEquals(ProvisioningChange.STILL_PROVISIONED, LinkProperties.compareProvisioning(v6lp, v6lp2));
}
Also used : RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 74 with RouteInfo

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

the class LinkPropertiesTest method testEqualsDifferentOrder.

@SmallTest
public void testEqualsDifferentOrder() {
    try {
        LinkProperties source = new LinkProperties();
        source.setInterfaceName(NAME);
        // set 2 link addresses
        source.addLinkAddress(LINKADDRV4);
        source.addLinkAddress(LINKADDRV6);
        // set 2 dnses
        source.addDnsServer(DNS1);
        source.addDnsServer(DNS2);
        // set 2 gateways
        source.addRoute(new RouteInfo(GATEWAY1));
        source.addRoute(new RouteInfo(GATEWAY2));
        source.setMtu(MTU);
        LinkProperties target = new LinkProperties();
        // Exchange order
        target.setInterfaceName(NAME);
        target.addLinkAddress(LINKADDRV6);
        target.addLinkAddress(LINKADDRV4);
        target.addDnsServer(DNS2);
        target.addDnsServer(DNS1);
        target.addRoute(new RouteInfo(GATEWAY2));
        target.addRoute(new RouteInfo(GATEWAY1));
        target.setMtu(MTU);
        assertLinkPropertiesEqual(source, target);
    } catch (Exception e) {
        fail();
    }
}
Also used : RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 75 with RouteInfo

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

the class RouteInfoTest method testTruncation.

public void testTruncation() {
    LinkAddress l;
    RouteInfo r;
    l = new LinkAddress("192.0.2.5/30");
    r = new RouteInfo(l, Address("192.0.2.1"), "wlan0");
    assertEquals("192.0.2.4", r.getDestination().getAddress().getHostAddress());
    l = new LinkAddress("2001:db8:1:f::5/63");
    r = new RouteInfo(l, Address("2001:db8:5::1"), "wlan0");
    assertEquals("2001:db8:1:e::", r.getDestination().getAddress().getHostAddress());
}
Also used : RouteInfo(android.net.RouteInfo)

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