use of android.net.IpPrefix in project platform_frameworks_base by android.
the class IpPrefixTest method testEquals.
@SmallTest
public void testEquals() {
IpPrefix p1, p2;
p1 = new IpPrefix("192.0.2.251/23");
p2 = new IpPrefix(new byte[] { (byte) 192, (byte) 0, (byte) 2, (byte) 251 }, 23);
assertAreEqual(p1, p2);
p1 = new IpPrefix("192.0.2.5/23");
assertAreEqual(p1, p2);
p1 = new IpPrefix("192.0.2.5/24");
assertAreNotEqual(p1, p2);
p1 = new IpPrefix("192.0.4.5/23");
assertAreNotEqual(p1, p2);
p1 = new IpPrefix("2001:db8:dead:beef:f00::80/122");
p2 = new IpPrefix(IPV6_BYTES, 122);
assertEquals("2001:db8:dead:beef:f00::80/122", p2.toString());
assertAreEqual(p1, p2);
p1 = new IpPrefix("2001:db8:dead:beef:f00::bf/122");
assertAreEqual(p1, p2);
p1 = new IpPrefix("2001:db8:dead:beef:f00::8:0/123");
assertAreNotEqual(p1, p2);
p1 = new IpPrefix("2001:db8:dead:beef::/122");
assertAreNotEqual(p1, p2);
// 192.0.2.4/32 != c000:0204::/32.
byte[] ipv6bytes = new byte[16];
System.arraycopy(IPV4_BYTES, 0, ipv6bytes, 0, IPV4_BYTES.length);
p1 = new IpPrefix(ipv6bytes, 32);
assertAreEqual(p1, new IpPrefix("c000:0204::/32"));
p2 = new IpPrefix(IPV4_BYTES, 32);
assertAreNotEqual(p1, p2);
}
use of android.net.IpPrefix in project platform_frameworks_base by android.
the class IpPrefixTest method testParceling.
public void testParceling() {
IpPrefix p;
p = new IpPrefix("2001:4860:db8::/64");
assertParcelingIsLossless(p);
p = new IpPrefix("192.0.2.0/25");
assertParcelingIsLossless(p);
}
use of android.net.IpPrefix in project platform_frameworks_base by android.
the class IpPrefixTest method testMappedAddressesAreBroken.
@SmallTest
public void testMappedAddressesAreBroken() {
// 192.0.2.0/24 != ::ffff:c000:0204/120, but because we use InetAddress,
// we are unable to comprehend that.
byte[] ipv6bytes = { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0xff, (byte) 0xff, (byte) 192, (byte) 0, (byte) 2, (byte) 0 };
IpPrefix p = new IpPrefix(ipv6bytes, 120);
// Fine.
assertEquals(16, p.getRawAddress().length);
// Fine.
assertArrayEquals(ipv6bytes, p.getRawAddress());
// Broken.
assertEquals("192.0.2.0/120", p.toString());
assertEquals(InetAddress.parseNumericAddress("192.0.2.0"), p.getAddress());
}
use of android.net.IpPrefix in project platform_frameworks_base by android.
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));
}
use of android.net.IpPrefix in project platform_frameworks_base by android.
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());
}
Aggregations