Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 872b2369 authored by Xiao Ma's avatar Xiao Ma
Browse files

Refactor out the IPv4-only provisioning result verification.

So far the provisioning verification is included inside handleDhcpPacket
and follows DHCP handshake, which works for IPv4-only provisioning, but
when IPv6 stack is also enabled in some tests, then IPv6 link-local
address will be configured automatically when interface is up. Refactor
out the IPv4 provisioning function, then it's flexible to verify something
else we are interested in (e.g. IPv6 link-local, privacy addresses).

Bug: 131781810
Test: atest NetworkStackIntegrationTests NetworkStackNextIntegrationTests
Change-Id: I7f5aba2d19de9bdbd0962bc3268d51c19112d9d2
parent 48bd1067
Loading
Loading
Loading
Loading
+27 −18
Original line number Diff line number Diff line
@@ -690,13 +690,12 @@ public class IpClientIntegrationTest {
                false /* isPreconnectionEnabled */, isDhcpIpConflictDetectEnabled,
                isHostnameConfigurationEnabled, hostname, displayName, scanResultInfo);
        return handleDhcpPackets(isSuccessLease, leaseTimeSec, shouldReplyRapidCommitAck, mtu,
                isDhcpIpConflictDetectEnabled, captivePortalApiUrl);
                captivePortalApiUrl);
    }

    private List<DhcpPacket> handleDhcpPackets(final boolean isSuccessLease,
            final Integer leaseTimeSec, final boolean shouldReplyRapidCommitAck, final int mtu,
            final boolean isDhcpIpConflictDetectEnabled, final String captivePortalApiUrl)
            throws Exception {
            final String captivePortalApiUrl) throws Exception {
        final List<DhcpPacket> packetList = new ArrayList<>();
        DhcpPacket packet;
        while ((packet = getNextDhcpPacket()) != null) {
@@ -721,15 +720,6 @@ public class IpClientIntegrationTest {

            // wait for reply to DHCPOFFER packet if disabling rapid commit option
            if (shouldReplyRapidCommitAck || !(packet instanceof DhcpDiscoverPacket)) {
                if (!isDhcpIpConflictDetectEnabled && isSuccessLease) {
                    // verify IPv4-only provisioning success before exiting loop.
                    // 1. if it's a failure lease, onProvisioningSuccess() won't be called;
                    // 2. if duplicated IPv4 address detection is enabled, verify TIMEOUT
                    //    will affect ARP packet capture running in other test cases.
                    ArgumentCaptor<LinkProperties> captor =
                            ArgumentCaptor.forClass(LinkProperties.class);
                    verifyProvisioningSuccess(captor, Collections.singletonList(CLIENT_ADDR));
                }
                return packetList;
            }
        }
@@ -791,8 +781,15 @@ public class IpClientIntegrationTest {
        verify(mCb, timeout(TEST_TIMEOUT_MS)).onLinkPropertiesChange(emptyLp);
    }

    private void verifyProvisioningSuccess(ArgumentCaptor<LinkProperties> captor,
            final Collection<InetAddress> addresses) throws Exception {
    // Verify IPv4-only provisioning success. No need to verify IPv4 provisioning when below cases
    // happen:
    // 1. if there's a failure lease, onProvisioningSuccess() won't be called;
    // 2. if duplicated IPv4 address detection is enabled, verify TIMEOUT will affect ARP packets
    //    capture running in other test cases.
    // 3. if IPv6 is enabled, e.g. withoutIPv6() isn't called when starting provisioning.
    private void verifyIPv4OnlyProvisioningSuccess(final Collection<InetAddress> addresses)
            throws Exception {
        final ArgumentCaptor<LinkProperties> captor = ArgumentCaptor.forClass(LinkProperties.class);
        verify(mCb, timeout(TEST_TIMEOUT_MS)).onProvisioningSuccess(captor.capture());
        LinkProperties lp = captor.getValue();
        assertNotNull(lp);
@@ -810,6 +807,7 @@ public class IpClientIntegrationTest {
        performDhcpHandshake(true /* isSuccessLease */, TEST_LEASE_DURATION_S,
                true /* isDhcpLeaseCacheEnabled */, false /* shouldReplyRapidCommitAck */,
                mtu, false /* isDhcpIpConflictDetectEnabled */);
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
        assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, mtu);

        if (shouldChangeMtu) {
@@ -998,8 +996,7 @@ public class IpClientIntegrationTest {
            assertArpProbe(packetList.get(0));
            assertArpAnnounce(packetList.get(3));

            ArgumentCaptor<LinkProperties> captor = ArgumentCaptor.forClass(LinkProperties.class);
            verifyProvisioningSuccess(captor, Collections.singletonList(CLIENT_ADDR));
            verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
            assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime,
                    TEST_DEFAULT_MTU);
        }
@@ -1038,6 +1035,7 @@ public class IpClientIntegrationTest {
        performDhcpHandshake(true /* isSuccessLease */, TEST_LEASE_DURATION_S,
                true /* isDhcpLeaseCacheEnabled */, false /* shouldReplyRapidCommitAck */,
                TEST_DEFAULT_MTU, false /* isDhcpIpConflictDetectEnabled */);
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
        assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, TEST_DEFAULT_MTU);
    }

@@ -1057,6 +1055,7 @@ public class IpClientIntegrationTest {
        performDhcpHandshake(true /* isSuccessLease */, INFINITE_LEASE,
                true /* isDhcpLeaseCacheEnabled */, false /* shouldReplyRapidCommitAck */,
                TEST_DEFAULT_MTU, false /* isDhcpIpConflictDetectEnabled */);
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
        assertIpMemoryStoreNetworkAttributes(INFINITE_LEASE, currentTime, TEST_DEFAULT_MTU);
    }

@@ -1066,6 +1065,7 @@ public class IpClientIntegrationTest {
        performDhcpHandshake(true /* isSuccessLease */, null /* no lease time */,
                true /* isDhcpLeaseCacheEnabled */, false /* shouldReplyRapidCommitAck */,
                TEST_DEFAULT_MTU, false /* isDhcpIpConflictDetectEnabled */);
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
        assertIpMemoryStoreNetworkAttributes(null, currentTime, TEST_DEFAULT_MTU);
    }

@@ -1074,6 +1074,7 @@ public class IpClientIntegrationTest {
        performDhcpHandshake(true /* isSuccessLease */, TEST_LEASE_DURATION_S,
                false /* isDhcpLeaseCacheEnabled */, false /* shouldReplyRapidCommitAck */,
                TEST_DEFAULT_MTU, false /* isDhcpIpConflictDetectEnabled */);
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
        assertIpMemoryNeverStoreNetworkAttributes();
    }

@@ -1083,6 +1084,7 @@ public class IpClientIntegrationTest {
        performDhcpHandshake(true /* isSuccessLease */, TEST_LEASE_DURATION_S,
                true /* isDhcpLeaseCacheEnabled */, true /* shouldReplyRapidCommitAck */,
                TEST_DEFAULT_MTU, false /* isDhcpIpConflictDetectEnabled */);
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
        assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, TEST_DEFAULT_MTU);
    }

@@ -1206,6 +1208,7 @@ public class IpClientIntegrationTest {
        performDhcpHandshake(true /* isSuccessLease */, TEST_LEASE_DURATION_S,
                true /* isDhcpLeaseCacheEnabled */, false /* shouldReplyRapidCommitAck */,
                TEST_MIN_MTU, false /* isDhcpIpConflictDetectEnabled */);
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
        assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, TEST_MIN_MTU);

        // Pretend that ConnectivityService set the MTU.
@@ -1222,6 +1225,7 @@ public class IpClientIntegrationTest {
        performDhcpHandshake(true /* isSuccessLease */, TEST_LEASE_DURATION_S,
                true /* isDhcpLeaseCacheEnabled */, false /* shouldReplyRapidCommitAck */,
                0 /* mtu */, false /* isDhcpIpConflictDetectEnabled */);
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
        assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, 0 /* mtu */);
        assertEquals(NetworkInterface.getByName(mIfaceName).getMTU(), TEST_DEFAULT_MTU);
    }
@@ -1655,6 +1659,7 @@ public class IpClientIntegrationTest {
        performDhcpHandshake(true /* isSuccessLease */, TEST_LEASE_DURATION_S,
                true /* isDhcpLeaseCacheEnabled */, false /* shouldReplyRapidCommitAck */,
                TEST_DEFAULT_MTU, false /* isDhcpIpConflictDetectEnabled */);
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
        assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, TEST_DEFAULT_MTU);

        // Stop IpClient and expect a final LinkProperties callback with an empty LP.
@@ -1867,6 +1872,7 @@ public class IpClientIntegrationTest {
                true /* isHostnameConfigurationEnabled */, TEST_HOST_NAME /* hostname */,
                null /* captivePortalApiUrl */, null /* displayName */, null /* scanResultInfo */);
        assertEquals(2, sentPackets.size());
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
        assertHostname(true, TEST_HOST_NAME, TEST_HOST_NAME_TRANSLITERATION, sentPackets);
        assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, TEST_DEFAULT_MTU);
    }
@@ -1881,6 +1887,7 @@ public class IpClientIntegrationTest {
                false /* isHostnameConfigurationEnabled */, TEST_HOST_NAME,
                null /* captivePortalApiUrl */, null /* displayName */, null /* scanResultInfo */);
        assertEquals(2, sentPackets.size());
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
        assertHostname(false, TEST_HOST_NAME, TEST_HOST_NAME_TRANSLITERATION, sentPackets);
        assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, TEST_DEFAULT_MTU);
    }
@@ -1895,6 +1902,7 @@ public class IpClientIntegrationTest {
                true /* isHostnameConfigurationEnabled */, null /* hostname */,
                null /* captivePortalApiUrl */, null /* displayName */, null /* scanResultInfo */);
        assertEquals(2, sentPackets.size());
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
        assertHostname(true, null /* hostname */, null /* hostnameAfterTransliteration */,
                sentPackets);
        assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, TEST_DEFAULT_MTU);
@@ -1915,8 +1923,7 @@ public class IpClientIntegrationTest {
                (short) TEST_DEFAULT_MTU, serverSentUrl));
        final int testMtu = 1345;
        handleDhcpPackets(true /* isSuccessLease */, TEST_LEASE_DURATION_S,
                false /* isDhcpRapidCommitEnabled */, testMtu,
                false /* isDhcpIpConflictDetectEnabled */, serverSentUrl);
                false /* shouldReplyRapidCommitAck */, testMtu, serverSentUrl);

        final Uri expectedUrl = featureEnabled && serverSendsOption
                ? Uri.parse(TEST_CAPTIVE_PORTAL_URL) : null;
@@ -1985,6 +1992,7 @@ public class IpClientIntegrationTest {
                false /* isHostnameConfigurationEnabled */, null /* hostname */,
                null /* captivePortalApiUrl */, displayName, info /* scanResultInfo */);
        assertEquals(2, sentPackets.size());
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));

        ArgumentCaptor<DhcpResultsParcelable> captor =
                ArgumentCaptor.forClass(DhcpResultsParcelable.class);
@@ -2079,6 +2087,7 @@ public class IpClientIntegrationTest {
                TEST_DEFAULT_MTU, false /* isDhcpIpConflictDetectEnabled */,
                true /* isHostnameConfigurationEnabled */, null /* hostname */,
                null /* captivePortalApiUrl */, displayName, scanResultInfo);
        verifyIPv4OnlyProvisioningSuccess(Collections.singletonList(CLIENT_ADDR));
        assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, TEST_DEFAULT_MTU);

        // simulate the roaming by updating bssid.