Search in sources :

Example 6 with RouteInfo

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

the class RouteInfoTest method testMatches.

public void testMatches() {
    class PatchedRouteInfo extends RouteInfo {

        public PatchedRouteInfo(LinkAddress destination, InetAddress gateway, String iface) {
            super(destination, gateway, iface);
        }

        public boolean matches(InetAddress destination) {
            return super.matches(destination);
        }
    }
    RouteInfo 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")));
    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")));
    RouteInfo ipv6Default = new PatchedRouteInfo(Prefix("::/0"), null, "rmnet0");
    assertTrue(ipv6Default.matches(Address("2001:db8::f00")));
    assertFalse(ipv6Default.matches(Address("192.0.2.1")));
    RouteInfo 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 : LinkAddress(android.net.LinkAddress) RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress)

Example 7 with RouteInfo

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

the class RouteInfoTest method testHostRoute.

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

Example 8 with RouteInfo

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

the class RouteInfoTest method assertParcelingIsLossless.

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

Example 9 with RouteInfo

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

the class RouteInfoTest method testConstructor.

@SmallTest
public void testConstructor() {
    RouteInfo r;
    // Invalid input.
    try {
        r = new RouteInfo(null, null, "rmnet0");
        fail("Expected RuntimeException:  destination and gateway null");
    } catch (RuntimeException e) {
    }
    // Null destination is default route.
    r = new RouteInfo(null, Address("2001:db8::1"), null);
    assertEquals(Prefix("::/0"), r.getDestination());
    assertEquals(Address("2001:db8::1"), r.getGateway());
    assertNull(r.getInterface());
    r = new RouteInfo(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 : RouteInfo(android.net.RouteInfo) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 10 with RouteInfo

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

the class LinkPropertiesTest method testRouteInterfaces.

@SmallTest
public void testRouteInterfaces() {
    LinkAddress prefix = new LinkAddress(NetworkUtils.numericToInetAddress("2001:db8::"), 32);
    InetAddress address = NetworkUtils.numericToInetAddress(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);
    lp.addRoute(r);
    assertEquals(1, lp.getRoutes().size());
    assertAllRoutesHaveInterface(null, lp);
    // Add a route with an interface. Except 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.
    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(NetworkUtils.numericToInetAddress(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.compareRoutes(lp2).added.size());
    assertEquals(0, lp.compareRoutes(lp2).removed.size());
    lp2.setInterfaceName("p2p0");
    assertAllRoutesHaveInterface("p2p0", lp2);
    assertEquals(3, lp.compareRoutes(lp2).added.size());
    assertEquals(3, lp.compareRoutes(lp2).removed.size());
}
Also used : RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress) LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

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