Search in sources :

Example 41 with RouteInfo

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

the class VpnConfig method addLegacyRoutes.

public void addLegacyRoutes(String routesStr) {
    if (routesStr.trim().equals("")) {
        return;
    }
    String[] routes = routesStr.trim().split(" ");
    for (String route : routes) {
        //each route is ip/prefix
        RouteInfo info = new RouteInfo(new IpPrefix(route), null);
        this.routes.add(info);
        updateAllowedFamilies(info.getDestination().getAddress());
    }
}
Also used : IpPrefix(android.net.IpPrefix) RouteInfo(android.net.RouteInfo)

Example 42 with RouteInfo

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

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

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

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

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

the class LinkPropertiesTest method testEqualsSameOrder.

@SmallTest
public void testEqualsSameOrder() {
    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();
        // All fields are same
        target.setInterfaceName(NAME);
        target.addLinkAddress(LINKADDRV4);
        target.addLinkAddress(LINKADDRV6);
        target.addDnsServer(DNS1);
        target.addDnsServer(DNS2);
        target.addRoute(new RouteInfo(GATEWAY1));
        target.addRoute(new RouteInfo(GATEWAY2));
        target.setMtu(MTU);
        assertLinkPropertiesEqual(source, target);
        target.clear();
        // change Interface Name
        target.setInterfaceName("qmi1");
        target.addLinkAddress(LINKADDRV4);
        target.addLinkAddress(LINKADDRV6);
        target.addDnsServer(DNS1);
        target.addDnsServer(DNS2);
        target.addRoute(new RouteInfo(GATEWAY1));
        target.addRoute(new RouteInfo(GATEWAY2));
        target.setMtu(MTU);
        assertFalse(source.equals(target));
        target.clear();
        target.setInterfaceName(NAME);
        // change link addresses
        target.addLinkAddress(new LinkAddress(NetworkUtils.numericToInetAddress("75.208.6.2"), 32));
        target.addLinkAddress(LINKADDRV6);
        target.addDnsServer(DNS1);
        target.addDnsServer(DNS2);
        target.addRoute(new RouteInfo(GATEWAY1));
        target.addRoute(new RouteInfo(GATEWAY2));
        target.setMtu(MTU);
        assertFalse(source.equals(target));
        target.clear();
        target.setInterfaceName(NAME);
        target.addLinkAddress(LINKADDRV4);
        target.addLinkAddress(LINKADDRV6);
        // change dnses
        target.addDnsServer(NetworkUtils.numericToInetAddress("75.208.7.2"));
        target.addDnsServer(DNS2);
        target.addRoute(new RouteInfo(GATEWAY1));
        target.addRoute(new RouteInfo(GATEWAY2));
        target.setMtu(MTU);
        assertFalse(source.equals(target));
        target.clear();
        target.setInterfaceName(NAME);
        target.addLinkAddress(LINKADDRV4);
        target.addLinkAddress(LINKADDRV6);
        target.addDnsServer(DNS1);
        target.addDnsServer(DNS2);
        // change gateway
        target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress("75.208.8.2")));
        target.addRoute(new RouteInfo(GATEWAY2));
        target.setMtu(MTU);
        assertFalse(source.equals(target));
        target.clear();
        target.setInterfaceName(NAME);
        target.addLinkAddress(LINKADDRV4);
        target.addLinkAddress(LINKADDRV6);
        target.addDnsServer(DNS1);
        target.addDnsServer(DNS2);
        target.addRoute(new RouteInfo(GATEWAY1));
        target.addRoute(new RouteInfo(GATEWAY2));
        // change mtu
        target.setMtu(1440);
        assertFalse(source.equals(target));
    } catch (Exception e) {
        throw new RuntimeException(e.toString());
    //fail();
    }
}
Also used : LinkAddress(android.net.LinkAddress) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 45 with RouteInfo

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

the class RouteInfoTest method testHostAndDefaultRoutes.

public void testHostAndDefaultRoutes() {
    RouteInfo r;
    r = new RouteInfo(Prefix("0.0.0.0/0"), Address("0.0.0.0"), "wlan0");
    assertFalse(r.isHostRoute());
    assertTrue(r.isDefaultRoute());
    assertTrue(r.isIPv4Default());
    assertFalse(r.isIPv6Default());
    r = new RouteInfo(Prefix("::/0"), Address("::"), "wlan0");
    assertFalse(r.isHostRoute());
    assertTrue(r.isDefaultRoute());
    assertFalse(r.isIPv4Default());
    assertTrue(r.isIPv6Default());
    r = new RouteInfo(Prefix("192.0.2.0/24"), null, "wlan0");
    assertFalse(r.isHostRoute());
    assertFalse(r.isDefaultRoute());
    assertFalse(r.isIPv4Default());
    assertFalse(r.isIPv6Default());
    r = new RouteInfo(Prefix("2001:db8::/48"), null, "wlan0");
    assertFalse(r.isHostRoute());
    assertFalse(r.isDefaultRoute());
    assertFalse(r.isIPv4Default());
    assertFalse(r.isIPv6Default());
    r = new RouteInfo(Prefix("192.0.2.0/32"), Address("0.0.0.0"), "wlan0");
    assertTrue(r.isHostRoute());
    assertFalse(r.isDefaultRoute());
    assertFalse(r.isIPv4Default());
    assertFalse(r.isIPv6Default());
    r = new RouteInfo(Prefix("2001:db8::/128"), Address("::"), "wlan0");
    assertTrue(r.isHostRoute());
    assertFalse(r.isDefaultRoute());
    assertFalse(r.isIPv4Default());
    assertFalse(r.isIPv6Default());
    r = new RouteInfo(Prefix("192.0.2.0/32"), null, "wlan0");
    assertTrue(r.isHostRoute());
    assertFalse(r.isDefaultRoute());
    assertFalse(r.isIPv4Default());
    assertFalse(r.isIPv6Default());
    r = new RouteInfo(Prefix("2001:db8::/128"), null, "wlan0");
    assertTrue(r.isHostRoute());
    assertFalse(r.isDefaultRoute());
    assertFalse(r.isIPv4Default());
    assertFalse(r.isIPv6Default());
    r = new RouteInfo(Prefix("::/128"), Address("fe80::"), "wlan0");
    assertTrue(r.isHostRoute());
    assertFalse(r.isDefaultRoute());
    assertFalse(r.isIPv4Default());
    assertFalse(r.isIPv6Default());
    r = new RouteInfo(Prefix("0.0.0.0/32"), Address("192.0.2.1"), "wlan0");
    assertTrue(r.isHostRoute());
    assertFalse(r.isDefaultRoute());
    assertFalse(r.isIPv4Default());
    assertFalse(r.isIPv6Default());
}
Also used : RouteInfo(android.net.RouteInfo)

Aggregations

RouteInfo (android.net.RouteInfo)168 LinkProperties (android.net.LinkProperties)73 LinkAddress (android.net.LinkAddress)60 InetAddress (java.net.InetAddress)57 SmallTest (android.test.suitebuilder.annotation.SmallTest)45 IpPrefix (android.net.IpPrefix)35 Inet6Address (java.net.Inet6Address)21 Inet4Address (java.net.Inet4Address)20 IOException (java.io.IOException)11 StaticIpConfiguration (android.net.StaticIpConfiguration)10 EOFException (java.io.EOFException)8 DataInputStream (java.io.DataInputStream)7 UnknownHostException (java.net.UnknownHostException)7 HashMap (java.util.HashMap)7 StringJoiner (java.util.StringJoiner)7 Parcel (android.os.Parcel)6 BufferedInputStream (java.io.BufferedInputStream)6 FileInputStream (java.io.FileInputStream)6 ArrayList (java.util.ArrayList)6 UserInfo (android.content.pm.UserInfo)5