Search in sources :

Example 46 with RouteInfo

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

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

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

the class RouteInfoTest method testConstructor.

@SmallTest
public void testConstructor() {
    RouteInfo r;
    // Invalid input.
    try {
        r = new RouteInfo((IpPrefix) null, null, "rmnet0");
        fail("Expected RuntimeException:  destination and gateway null");
    } catch (RuntimeException e) {
    }
    // Null destination is default route.
    r = new RouteInfo((IpPrefix) null, Address("2001:db8::1"), null);
    assertEquals(Prefix("::/0"), r.getDestination());
    assertEquals(Address("2001:db8::1"), r.getGateway());
    assertNull(r.getInterface());
    r = new RouteInfo((IpPrefix) null, Address("192.0.2.1"), "wlan0");
    assertEquals(Prefix("0.0.0.0/0"), r.getDestination());
    assertEquals(Address("192.0.2.1"), r.getGateway());
    assertEquals("wlan0", r.getInterface());
    // Null gateway sets gateway to unspecified address (why?).
    r = new RouteInfo(Prefix("2001:db8:beef:cafe::/48"), null, "lo");
    assertEquals(Prefix("2001:db8:beef::/48"), r.getDestination());
    assertEquals(Address("::"), r.getGateway());
    assertEquals("lo", r.getInterface());
    r = new RouteInfo(Prefix("192.0.2.5/24"), null);
    assertEquals(Prefix("192.0.2.0/24"), r.getDestination());
    assertEquals(Address("0.0.0.0"), r.getGateway());
    assertNull(r.getInterface());
}
Also used : IpPrefix(android.net.IpPrefix) RouteInfo(android.net.RouteInfo) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 48 with RouteInfo

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

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

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

the class RouteInfoTest method assertParcelingIsLossless.

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

Example 50 with RouteInfo

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

the class StaticIpConfigurationTest method testToLinkProperties.

@SmallTest
public void testToLinkProperties() {
    LinkProperties expected = new LinkProperties();
    expected.setInterfaceName(IFACE);
    StaticIpConfiguration s = new StaticIpConfiguration();
    assertEquals(expected, s.toLinkProperties(IFACE));
    final RouteInfo connectedRoute = new RouteInfo(new IpPrefix(ADDRSTR), null, IFACE);
    s.ipAddress = ADDR;
    expected.addLinkAddress(ADDR);
    expected.addRoute(connectedRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.gateway = GATEWAY;
    RouteInfo defaultRoute = new RouteInfo(new IpPrefix("0.0.0.0/0"), GATEWAY, IFACE);
    expected.addRoute(defaultRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.gateway = OFFLINKGATEWAY;
    expected.removeRoute(defaultRoute);
    defaultRoute = new RouteInfo(new IpPrefix("0.0.0.0/0"), OFFLINKGATEWAY, IFACE);
    expected.addRoute(defaultRoute);
    RouteInfo gatewayRoute = new RouteInfo(new IpPrefix("192.0.2.129/32"), null, IFACE);
    expected.addRoute(gatewayRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.dnsServers.add(DNS1);
    expected.addDnsServer(DNS1);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.dnsServers.add(DNS2);
    s.dnsServers.add(DNS3);
    expected.addDnsServer(DNS2);
    expected.addDnsServer(DNS3);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.domains = "google.com";
    expected.setDomains("google.com");
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.gateway = null;
    expected.removeRoute(defaultRoute);
    expected.removeRoute(gatewayRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
    // Without knowing the IP address, we don't have a directly-connected route, so we can't
    // tell if the gateway is off-link or not and we don't add a host route. This isn't a real
    // configuration, but we should at least not crash.
    s.gateway = OFFLINKGATEWAY;
    s.ipAddress = null;
    expected.removeLinkAddress(ADDR);
    expected.removeRoute(connectedRoute);
    expected.addRoute(defaultRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
}
Also used : IpPrefix(android.net.IpPrefix) StaticIpConfiguration(android.net.StaticIpConfiguration) RouteInfo(android.net.RouteInfo) SmallTest(android.test.suitebuilder.annotation.SmallTest)

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