From eb290f96b3962e8aeb2fb4ea26905ad51db668e1 Mon Sep 17 00:00:00 2001 From: Joel Scherpelz Date: Thu, 13 Apr 2017 12:52:42 +0900 Subject: [PATCH 1/2] Add CTS to verify RIO min/max prefix length Add two new test cases to ConnectivityManagerTest: testAcceptRaRtInfoMinPlen() testAcceptRaRtInfoMaxPlen() Bug: 33333670 Test: ConnectivityManagerTest CTS test passes with WIFI on/off Change-Id: I3c0a6823b6fa75f55f9bb99b59557abeb5b9ac62 --- .../net/cts/ConnectivityManagerTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index 22dfd1babc..2b10ac274f 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -45,12 +45,15 @@ import android.util.Log; import com.android.internal.telephony.PhoneConstants; +import java.io.File; +import java.io.FileNotFoundException; import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; import java.net.Socket; import java.net.InetSocketAddress; import java.util.HashMap; +import java.util.Scanner; import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; @@ -74,6 +77,13 @@ public class ConnectivityManagerTest extends AndroidTestCase { "Host: " + TEST_HOST + "\r\n" + "Connection: keep-alive\r\n\r\n"; + // Base path for IPv6 sysctls + private static final String IPV6_SYSCTL_DIR = "/proc/sys/net/ipv6/conf"; + + // Expected values for MIN|MAX_PLEN. + private static final int IPV6_WIFI_ACCEPT_RA_RT_INFO_MIN_PLEN = 48; + private static final int IPV6_WIFI_ACCEPT_RA_RT_INFO_MAX_PLEN = 64; + // Action sent to ConnectivityActionReceiver when a network callback is sent via PendingIntent. private static final String NETWORK_CALLBACK_ACTION = "ConnectivityManagerTest.NetworkCallbackAction"; @@ -765,4 +775,23 @@ public class ConnectivityManagerTest extends AndroidTestCase { fail("No exception thrown when restricted network requested."); } catch (SecurityException expected) {} } + + private Scanner makeWifiSysctlScanner(String key) throws FileNotFoundException { + Network network = ensureWifiConnected(); + String iface = mCm.getLinkProperties(network).getInterfaceName(); + String path = IPV6_SYSCTL_DIR + "/" + iface + "/" + key; + return new Scanner(new File(path)); + } + + /** Verify that accept_ra_rt_info_min_plen exists and is set to the expected value */ + public void testAcceptRaRtInfoMinPlen() throws Exception { + Scanner s = makeWifiSysctlScanner("accept_ra_rt_info_min_plen"); + assertEquals(IPV6_WIFI_ACCEPT_RA_RT_INFO_MIN_PLEN, s.nextInt()); + } + + /** Verify that accept_ra_rt_info_max_plen exists and is set to the expected value */ + public void testAcceptRaRtInfoMaxPlen() throws Exception { + Scanner s = makeWifiSysctlScanner("accept_ra_rt_info_max_plen"); + assertEquals(IPV6_WIFI_ACCEPT_RA_RT_INFO_MAX_PLEN, s.nextInt()); + } } From c805581fc0a7934aacdce1c14582ff6d841593d4 Mon Sep 17 00:00:00 2001 From: Joel Scherpelz Date: Thu, 13 Apr 2017 12:56:19 +0900 Subject: [PATCH 2/2] Add CTS test to verify router solicitation backoff Add two new test cases to ConnectivityManagerTest: testRouterSolicitations() testRouterSolicitationMaxInterval() Bug: 33620395 Test: ConnectivityManagerTest CTS test passes with WIFI on/off Change-Id: Iac8979dfab29ae75343a355d02acfb0f39b491f9 --- .../net/cts/ConnectivityManagerTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index 2b10ac274f..83f087b9e5 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -84,6 +84,10 @@ public class ConnectivityManagerTest extends AndroidTestCase { private static final int IPV6_WIFI_ACCEPT_RA_RT_INFO_MIN_PLEN = 48; private static final int IPV6_WIFI_ACCEPT_RA_RT_INFO_MAX_PLEN = 64; + // Expected values for RFC 7559 router soliciations. + // Maximum number of router solicitations to send. -1 means no limit. + private static final int IPV6_WIFI_ROUTER_SOLICITATIONS = -1; + // Action sent to ConnectivityActionReceiver when a network callback is sent via PendingIntent. private static final String NETWORK_CALLBACK_ACTION = "ConnectivityManagerTest.NetworkCallbackAction"; @@ -794,4 +798,23 @@ public class ConnectivityManagerTest extends AndroidTestCase { Scanner s = makeWifiSysctlScanner("accept_ra_rt_info_max_plen"); assertEquals(IPV6_WIFI_ACCEPT_RA_RT_INFO_MAX_PLEN, s.nextInt()); } + + /** Verify that router_solicitations exists and is set to the expected value */ + public void testRouterSolicitations() throws Exception { + Scanner s = makeWifiSysctlScanner("router_solicitations"); + assertEquals(IPV6_WIFI_ROUTER_SOLICITATIONS, s.nextInt()); + } + + /** Verify that router_solicitation_max_interval exists and is in an acceptable interval */ + public void testRouterSolicitationMaxInterval() throws Exception { + Scanner s = makeWifiSysctlScanner("router_solicitation_max_interval"); + int interval = s.nextInt(); + // Verify we're in the interval [15 minutes, 60 minutes]. Lower values may adversely + // impact battery life and higher values can decrease the probability of detecting + // network changes. + final int lowerBoundSec = 15 * 60; + final int upperBoundSec = 60 * 60; + assertTrue(lowerBoundSec <= interval); + assertTrue(interval <= upperBoundSec); + } }