Search in sources :

Example 76 with RouteInfo

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

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)

Example 77 with RouteInfo

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

the class LinkPropertiesTest method testIsProvisioned.

@SmallTest
public void testIsProvisioned() {
    LinkProperties lp4 = new LinkProperties();
    assertFalse("v4only:empty", lp4.isProvisioned());
    lp4.addLinkAddress(LINKADDRV4);
    assertFalse("v4only:addr-only", lp4.isProvisioned());
    lp4.addDnsServer(DNS1);
    assertFalse("v4only:addr+dns", lp4.isProvisioned());
    lp4.addRoute(new RouteInfo(GATEWAY1));
    assertTrue("v4only:addr+dns+route", lp4.isProvisioned());
    assertTrue("v4only:addr+dns+route", lp4.isIPv4Provisioned());
    assertFalse("v4only:addr+dns+route", lp4.isIPv6Provisioned());
    LinkProperties lp6 = new LinkProperties();
    assertFalse("v6only:empty", lp6.isProvisioned());
    lp6.addLinkAddress(LINKADDRV6LINKLOCAL);
    assertFalse("v6only:fe80-only", lp6.isProvisioned());
    lp6.addDnsServer(DNS6);
    assertFalse("v6only:fe80+dns", lp6.isProvisioned());
    lp6.addRoute(new RouteInfo(GATEWAY61));
    assertFalse("v6only:fe80+dns+route", lp6.isProvisioned());
    lp6.addLinkAddress(LINKADDRV6);
    assertTrue("v6only:fe80+global+dns+route", lp6.isIPv6Provisioned());
    assertTrue("v6only:fe80+global+dns+route", lp6.isProvisioned());
    lp6.removeLinkAddress(LINKADDRV6LINKLOCAL);
    assertFalse("v6only:global+dns+route", lp6.isIPv4Provisioned());
    assertTrue("v6only:global+dns+route", lp6.isIPv6Provisioned());
    assertTrue("v6only:global+dns+route", lp6.isProvisioned());
    LinkProperties lp46 = new LinkProperties();
    lp46.addLinkAddress(LINKADDRV4);
    lp46.addLinkAddress(LINKADDRV6);
    lp46.addDnsServer(DNS1);
    lp46.addDnsServer(DNS6);
    assertFalse("dualstack:missing-routes", lp46.isProvisioned());
    lp46.addRoute(new RouteInfo(GATEWAY1));
    assertTrue("dualstack:v4-provisioned", lp46.isIPv4Provisioned());
    assertFalse("dualstack:v4-provisioned", lp46.isIPv6Provisioned());
    assertTrue("dualstack:v4-provisioned", lp46.isProvisioned());
    lp46.addRoute(new RouteInfo(GATEWAY61));
    assertTrue("dualstack:both-provisioned", lp46.isIPv4Provisioned());
    assertTrue("dualstack:both-provisioned", lp46.isIPv6Provisioned());
    assertTrue("dualstack:both-provisioned", lp46.isProvisioned());
    // A link with an IPv6 address and default route, but IPv4 DNS server.
    LinkProperties mixed = new LinkProperties();
    mixed.addLinkAddress(LINKADDRV6);
    mixed.addDnsServer(DNS1);
    mixed.addRoute(new RouteInfo(GATEWAY61));
    assertFalse("mixed:addr6+route6+dns4", mixed.isIPv4Provisioned());
    assertFalse("mixed:addr6+route6+dns4", mixed.isIPv6Provisioned());
    assertFalse("mixed:addr6+route6+dns4", mixed.isProvisioned());
}
Also used : RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 78 with RouteInfo

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

the class RouteInfoTest method assertParcelingIsLossless.

public void assertParcelingIsLossless(RouteInfo r) {
    RouteInfo r2 = passThroughParcel(r);
    assertEquals(r, r2);
}
Also used : RouteInfo(android.net.RouteInfo)

Example 79 with RouteInfo

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

the class RouteInfoTest method testMulticastRoute.

// Make sure that creating routes to multicast addresses doesn't throw an exception. Even though
// there's nothing we can do with them, we don't want to crash if, e.g., someone calls
// requestRouteToHostAddress("230.0.0.0", MOBILE_HIPRI);
public void testMulticastRoute() {
    RouteInfo r;
    r = new RouteInfo(Prefix("230.0.0.0/32"), Address("192.0.2.1"), "wlan0");
    r = new RouteInfo(Prefix("ff02::1/128"), Address("2001:db8::1"), "wlan0");
// No exceptions? Good.
}
Also used : RouteInfo(android.net.RouteInfo)

Example 80 with RouteInfo

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

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

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