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

Commit 4ca906c3 authored by Xiao Ma's avatar Xiao Ma
Browse files

Follow-up CL to the change at aosp/1523097.

Add test to verify the customized options which will be put in the
parameter request list only.

Add test to verify if the option is sent correctly in DHCPREQUEST.

Bug: 169128961
Test: atest NetworkStackIntegrationTest NetworkStackTests
Change-Id: I64840dbcbeae95e3c4f3fd64cd7f7bdf2836b76c
parent 60175d2d
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -239,7 +239,7 @@ public class ProvisioningConfiguration {
         *
         *
         * @param: options customized DHCP option stable parcelable list.
         * @param: options customized DHCP option stable parcelable list.
         */
         */
        public Builder withDhcpOptions(List<DhcpOption> options) {
        public Builder withDhcpOptions(@Nullable List<DhcpOption> options) {
            mConfig.mDhcpOptions = options;
            mConfig.mDhcpOptions = options;
            return this;
            return this;
        }
        }
+2 −2
Original line number Original line Diff line number Diff line
@@ -403,7 +403,7 @@ public abstract class DhcpPacket {


    // Set in unit tests, to ensure that the test does not break when run on different devices and
    // Set in unit tests, to ensure that the test does not break when run on different devices and
    // on different releases.
    // on different releases.
    static String testOverrideVendorId = null;
    static String sTestOverrideVendorId = null;


    protected DhcpPacket(int transId, short secs, Inet4Address clientIp, Inet4Address yourIp,
    protected DhcpPacket(int transId, short secs, Inet4Address clientIp, Inet4Address yourIp,
                         Inet4Address nextIp, Inet4Address relayIp,
                         Inet4Address nextIp, Inet4Address relayIp,
@@ -779,7 +779,7 @@ public abstract class DhcpPacket {
     * with the customized option value if any.
     * with the customized option value if any.
     */
     */
    private static String getVendorId(@Nullable List<DhcpOption> customizedClientOptions) {
    private static String getVendorId(@Nullable List<DhcpOption> customizedClientOptions) {
        if (testOverrideVendorId != null) return testOverrideVendorId;
        if (sTestOverrideVendorId != null) return sTestOverrideVendorId;


        String vendorId = "android-dhcp-" + Build.VERSION.RELEASE;
        String vendorId = "android-dhcp-" + Build.VERSION.RELEASE;
        if (customizedClientOptions != null) {
        if (customizedClientOptions != null) {
+12 −0
Original line number Original line Diff line number Diff line
@@ -17,10 +17,14 @@
package android.net.ip
package android.net.ip


import android.net.ipmemorystore.NetworkAttributes
import android.net.ipmemorystore.NetworkAttributes
import android.net.ipmemorystore.OnNetworkAttributesRetrievedListener
import android.net.ipmemorystore.Status
import android.net.ipmemorystore.Status.SUCCESS
import android.util.ArrayMap
import android.util.ArrayMap
import java.net.Inet6Address
import java.net.Inet6Address
import kotlin.test.assertEquals
import kotlin.test.assertEquals
import org.mockito.Mockito.any
import org.mockito.Mockito.any
import org.mockito.Mockito.doAnswer
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentCaptor
import org.mockito.Mockito.eq
import org.mockito.Mockito.eq
import org.mockito.Mockito.never
import org.mockito.Mockito.never
@@ -69,4 +73,12 @@ class IpClientIntegrationTest : IpClientIntegrationTestCommon() {
    override fun assertNeverNotifyNeighborLost() {
    override fun assertNeverNotifyNeighborLost() {
        verify(mCallback, never()).notifyLost(any(), any())
        verify(mCallback, never()).notifyLost(any(), any())
    }
    }

    override fun storeNetworkAttributes(l2Key: String, na: NetworkAttributes) {
        doAnswer { inv ->
            val listener = inv.getArgument<OnNetworkAttributesRetrievedListener>(1)
            listener.onNetworkAttributesRetrieved(Status(SUCCESS), l2Key, na)
            true
        }.`when`(mIpMemoryStore).retrieveNetworkAttributes(eq(l2Key), any())
    }
}
}
+193 −30
Original line number Original line Diff line number Diff line
@@ -508,6 +508,8 @@ public abstract class IpClientIntegrationTestCommon {


    protected abstract NetworkAttributes getStoredNetworkAttributes(String l2Key, long timeout);
    protected abstract NetworkAttributes getStoredNetworkAttributes(String l2Key, long timeout);


    protected abstract void storeNetworkAttributes(String l2Key, NetworkAttributes na);

    protected abstract void assertIpMemoryNeverStoreNetworkAttributes(String l2Key, long timeout);
    protected abstract void assertIpMemoryNeverStoreNetworkAttributes(String l2Key, long timeout);


    protected abstract void assertNotifyNeighborLost(Inet6Address targetIp);
    protected abstract void assertNotifyNeighborLost(Inet6Address targetIp);
@@ -2673,20 +2675,20 @@ public abstract class IpClientIntegrationTestCommon {
        verifyDhcpPacketRequestsIPv6OnlyPreferredOption(DhcpRequestPacket.class);
        verifyDhcpPacketRequestsIPv6OnlyPreferredOption(DhcpRequestPacket.class);
    }
    }


    private void startFromInitRebootStateWithIPv6OnlyPreferredOption(final Integer ipv6OnlyWaitTime,
    private void setUpRetrievedNetworkAttributesForInitRebootState() {
            final long expectedWaitSecs) throws Exception {
        final NetworkAttributes na = new NetworkAttributes.Builder()
        doAnswer(invocation -> {
            ((OnNetworkAttributesRetrievedListener) invocation.getArgument(1))
                    .onNetworkAttributesRetrieved(new Status(SUCCESS), TEST_L2KEY,
                            new NetworkAttributes.Builder()
                .setAssignedV4Address(CLIENT_ADDR)
                .setAssignedV4Address(CLIENT_ADDR)
                .setAssignedV4AddressExpiry(Long.MAX_VALUE) // lease is always valid
                .setAssignedV4AddressExpiry(Long.MAX_VALUE) // lease is always valid
                .setMtu(new Integer(TEST_DEFAULT_MTU))
                .setMtu(new Integer(TEST_DEFAULT_MTU))
                .setCluster(TEST_CLUSTER)
                .setCluster(TEST_CLUSTER)
                .setDnsAddresses(Collections.singletonList(SERVER_ADDR))
                .setDnsAddresses(Collections.singletonList(SERVER_ADDR))
                                .build());
                .build();
            return null;
        storeNetworkAttributes(TEST_L2KEY, na);
        }).when(mIpMemoryStore).retrieveNetworkAttributes(eq(TEST_L2KEY), any());
    }

    private void startFromInitRebootStateWithIPv6OnlyPreferredOption(final Integer ipv6OnlyWaitTime,
            final long expectedWaitSecs) throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();


        final ProvisioningConfiguration config = new ProvisioningConfiguration.Builder()
        final ProvisioningConfiguration config = new ProvisioningConfiguration.Builder()
                .withoutIpReachabilityMonitor()
                .withoutIpReachabilityMonitor()
@@ -2813,7 +2815,7 @@ public abstract class IpClientIntegrationTestCommon {
    );
    );


    private DhcpPacket doCustomizedDhcpOptionsTest(final List<DhcpOption> options,
    private DhcpPacket doCustomizedDhcpOptionsTest(final List<DhcpOption> options,
             final ScanResultInfo info) throws Exception {
             final ScanResultInfo info, boolean isDhcpLeaseCacheEnabled) throws Exception {
        ProvisioningConfiguration.Builder prov = new ProvisioningConfiguration.Builder()
        ProvisioningConfiguration.Builder prov = new ProvisioningConfiguration.Builder()
                .withoutIpReachabilityMonitor()
                .withoutIpReachabilityMonitor()
                .withLayer2Information(new Layer2Information(TEST_L2KEY, TEST_CLUSTER,
                .withLayer2Information(new Layer2Information(TEST_L2KEY, TEST_CLUSTER,
@@ -2822,7 +2824,7 @@ public abstract class IpClientIntegrationTestCommon {
                .withDhcpOptions(options)
                .withDhcpOptions(options)
                .withoutIPv6();
                .withoutIPv6();


        setDhcpFeatures(false /* isDhcpLeaseCacheEnabled */, false /* isRapidCommitEnabled */,
        setDhcpFeatures(isDhcpLeaseCacheEnabled, false /* isRapidCommitEnabled */,
                false /* isDhcpIpConflictDetectEnabled */, false /* isIPv6OnlyPreferredEnabled */);
                false /* isDhcpIpConflictDetectEnabled */, false /* isIPv6OnlyPreferredEnabled */);


        startIpClientProvisioning(prov.build());
        startIpClientProvisioning(prov.build());
@@ -2833,10 +2835,11 @@ public abstract class IpClientIntegrationTestCommon {
    }
    }


    @Test
    @Test
    public void testCustomizedDhcpOptions() throws Exception {
    public void testDiscoverCustomizedDhcpOptions() throws Exception {
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                false /* isDhcpLeaseCacheEnabled */);


        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
@@ -2844,10 +2847,11 @@ public abstract class IpClientIntegrationTestCommon {
    }
    }


    @Test
    @Test
    public void testCustomizedDhcpOptions_nullDhcpOptions() throws Exception {
    public void testDiscoverCustomizedDhcpOptions_nullDhcpOptions() throws Exception {
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(null /* options */, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(null /* options */, info,
                false /* isDhcpLeaseCacheEnabled */);


        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
@@ -2855,9 +2859,9 @@ public abstract class IpClientIntegrationTestCommon {
    }
    }


    @Test
    @Test
    public void testCustomizedDhcpOptions_nullScanResultInfo() throws Exception {
    public void testDiscoverCustomizedDhcpOptions_nullScanResultInfo() throws Exception {
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS,
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS,
                null /* scanResultInfo */);
                null /* scanResultInfo */, false /* isDhcpLeaseCacheEnabled */);


        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
@@ -2865,10 +2869,11 @@ public abstract class IpClientIntegrationTestCommon {
    }
    }


    @Test
    @Test
    public void testCustomizedDhcpOptions_disallowedOui() throws Exception {
    public void testDiscoverCustomizedDhcpOptions_disallowedOui() throws Exception {
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */,
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */,
                new byte[]{ 0x00, 0x11, 0x22} /* oui */, (byte) 0x17 /* vendor-specific IE type */);
                new byte[]{ 0x00, 0x11, 0x22} /* oui */, (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                false /* isDhcpLeaseCacheEnabled */);


        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
@@ -2876,10 +2881,11 @@ public abstract class IpClientIntegrationTestCommon {
    }
    }


    @Test
    @Test
    public void testCustomizedDhcpOptions_invalidIeId() throws Exception {
    public void testDiscoverCustomizedDhcpOptions_invalidIeId() throws Exception {
        final ScanResultInfo info = makeScanResultInfo(0xde /* vendor-specificIE */, TEST_OEM_OUI,
        final ScanResultInfo info = makeScanResultInfo(0xde /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                false /* isDhcpLeaseCacheEnabled */);


        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
@@ -2887,10 +2893,11 @@ public abstract class IpClientIntegrationTestCommon {
    }
    }


    @Test
    @Test
    public void testCustomizedDhcpOptions_invalidVendorSpecificType() throws Exception {
    public void testDiscoverCustomizedDhcpOptions_invalidVendorSpecificType() throws Exception {
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x10 /* vendor-specific IE type */);
                (byte) 0x10 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                false /* isDhcpLeaseCacheEnabled */);


        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
@@ -2898,7 +2905,7 @@ public abstract class IpClientIntegrationTestCommon {
    }
    }


    @Test
    @Test
    public void testCustomizedDhcpOptions_disallowedOption() throws Exception {
    public void testDisoverCustomizedDhcpOptions_disallowedOption() throws Exception {
        final List<DhcpOption> options = Arrays.asList(
        final List<DhcpOption> options = Arrays.asList(
                makeDhcpOption((byte) 60, TEST_OEM_VENDOR_ID.getBytes()),
                makeDhcpOption((byte) 60, TEST_OEM_VENDOR_ID.getBytes()),
                makeDhcpOption((byte) 77, TEST_OEM_USER_CLASS_INFO),
                makeDhcpOption((byte) 77, TEST_OEM_USER_CLASS_INFO),
@@ -2906,7 +2913,8 @@ public abstract class IpClientIntegrationTestCommon {
                makeDhcpOption((byte) 26, HexDump.toByteArray(TEST_DEFAULT_MTU)));
                makeDhcpOption((byte) 26, HexDump.toByteArray(TEST_DEFAULT_MTU)));
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info,
                false /* isDhcpLeaseCacheEnabled */);


        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
@@ -2915,7 +2923,7 @@ public abstract class IpClientIntegrationTestCommon {
    }
    }


    @Test
    @Test
    public void testCustomizedDhcpOptions_disallowedParamRequestOption() throws Exception {
    public void testDiscoverCustomizedDhcpOptions_disallowedParamRequestOption() throws Exception {
        final List<DhcpOption> options = Arrays.asList(
        final List<DhcpOption> options = Arrays.asList(
                makeDhcpOption((byte) 60, TEST_OEM_VENDOR_ID.getBytes()),
                makeDhcpOption((byte) 60, TEST_OEM_VENDOR_ID.getBytes()),
                makeDhcpOption((byte) 77, TEST_OEM_USER_CLASS_INFO),
                makeDhcpOption((byte) 77, TEST_OEM_USER_CLASS_INFO),
@@ -2923,14 +2931,169 @@ public abstract class IpClientIntegrationTestCommon {
                makeDhcpOption((byte) 42, null));
                makeDhcpOption((byte) 42, null));
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info,
                false /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
        assertArrayEquals(packet.mUserClass, TEST_OEM_USER_CLASS_INFO);
        assertFalse(packet.hasRequestedParam((byte) 42 /* NTP_SERVER */));
    }

    @Test
    public void testDiscoverCustomizedDhcpOptions_ParameterRequestListOnly() throws Exception {
        final List<DhcpOption> options = Arrays.asList(
                // DHCP_USER_CLASS
                makeDhcpOption((byte) 77, null));
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info,
                false /* isDhcpLeaseCacheEnabled */);


        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertTrue(packet instanceof DhcpDiscoverPacket);
        assertTrue(packet.hasRequestedParam((byte) 77 /* DHCP_USER_CLASS */));
        assertNull(packet.mUserClass);
    }

    @Test
    public void testRequestCustomizedDhcpOptions() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
        assertArrayEquals(packet.mUserClass, TEST_OEM_USER_CLASS_INFO);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_nullDhcpOptions() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(null /* options */, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertNull(packet.mUserClass);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_nullScanResultInfo() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS,
                null /* scanResultInfo */, true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertNull(packet.mUserClass);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_disallowedOui() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */,
                new byte[]{ 0x00, 0x11, 0x22} /* oui */, (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertNull(packet.mUserClass);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_invalidIeId() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final ScanResultInfo info = makeScanResultInfo(0xde /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertNull(packet.mUserClass);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_invalidVendorSpecificType() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x10 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(TEST_OEM_DHCP_OPTIONS, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, new String("android-dhcp-" + Build.VERSION.RELEASE));
        assertNull(packet.mUserClass);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_disallowedOption() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final List<DhcpOption> options = Arrays.asList(
                makeDhcpOption((byte) 60, TEST_OEM_VENDOR_ID.getBytes()),
                makeDhcpOption((byte) 77, TEST_OEM_USER_CLASS_INFO),
                // Option 26: MTU
                makeDhcpOption((byte) 26, HexDump.toByteArray(TEST_DEFAULT_MTU)));
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
        assertArrayEquals(packet.mUserClass, TEST_OEM_USER_CLASS_INFO);
        assertNull(packet.mMtu);
    }

    @Test
    public void testRequestCustomizedDhcpOptions_disallowedParamRequestOption() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final List<DhcpOption> options = Arrays.asList(
                makeDhcpOption((byte) 60, TEST_OEM_VENDOR_ID.getBytes()),
                makeDhcpOption((byte) 77, TEST_OEM_USER_CLASS_INFO),
                // NTP_SERVER
                makeDhcpOption((byte) 42, null));
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
        assertEquals(packet.mVendorId, TEST_OEM_VENDOR_ID);
        assertArrayEquals(packet.mUserClass, TEST_OEM_USER_CLASS_INFO);
        assertArrayEquals(packet.mUserClass, TEST_OEM_USER_CLASS_INFO);
        assertFalse(packet.hasRequestedParam((byte) 42 /* NTP_SERVER */));
        assertFalse(packet.hasRequestedParam((byte) 42 /* NTP_SERVER */));
    }
    }


    @Test
    public void testRequestCustomizedDhcpOptions_ParameterRequestListOnly() throws Exception {
        setUpRetrievedNetworkAttributesForInitRebootState();

        final List<DhcpOption> options = Arrays.asList(
                // DHCP_USER_CLASS
                makeDhcpOption((byte) 77, null));
        final ScanResultInfo info = makeScanResultInfo(0xdd /* vendor-specificIE */, TEST_OEM_OUI,
                (byte) 0x17 /* vendor-specific IE type */);
        final DhcpPacket packet = doCustomizedDhcpOptionsTest(options, info,
                true /* isDhcpLeaseCacheEnabled */);

        assertTrue(packet instanceof DhcpRequestPacket);
        assertTrue(packet.hasRequestedParam((byte) 77 /* DHCP_USER_CLASS */));
        assertNull(packet.mUserClass);
    }

    private void assertGratuitousNa(final NeighborAdvertisement na) throws Exception {
    private void assertGratuitousNa(final NeighborAdvertisement na) throws Exception {
        final MacAddress etherMulticast =
        final MacAddress etherMulticast =
                NetworkStackUtils.ipv6MulticastToEthernetMulticast(IPV6_ADDR_ALL_ROUTERS_MULTICAST);
                NetworkStackUtils.ipv6MulticastToEthernetMulticast(IPV6_ADDR_ALL_ROUTERS_MULTICAST);
+4 −0
Original line number Original line Diff line number Diff line
@@ -271,4 +271,8 @@ class IpClientRootTest : IpClientIntegrationTestCommon() {
    override fun assertNeverNotifyNeighborLost() {
    override fun assertNeverNotifyNeighborLost() {
        verify(mCb, never()).onReachabilityLost(anyString())
        verify(mCb, never()).onReachabilityLost(anyString())
    }
    }

    override fun storeNetworkAttributes(l2Key: String, na: NetworkAttributes) {
        mStore.storeNetworkAttributes(l2Key, na, null /* listener */)
    }
}
}
Loading