Dynamically set MTU based on proposed algorithms
This change adds the relevant utilities and plumbing to ensure that MTUs are set dynamically based on the underlying network's MTU. Bug: 184697651 Test: atest FrameworksVcnTests Change-Id: I77e34a92eb4e81e83d20fe6019b38ea5f1af4765
This commit is contained in:
@@ -47,15 +47,19 @@ import android.net.LinkAddress;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.NetworkAgent;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.ipsec.ike.ChildSaProposal;
|
||||
import android.net.ipsec.ike.exceptions.AuthenticationFailedException;
|
||||
import android.net.ipsec.ike.exceptions.IkeException;
|
||||
import android.net.ipsec.ike.exceptions.IkeInternalException;
|
||||
import android.net.ipsec.ike.exceptions.TemporaryFailureException;
|
||||
import android.net.vcn.VcnControlPlaneIkeConfig;
|
||||
import android.net.vcn.VcnManager.VcnErrorCode;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.server.vcn.util.MtuUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -153,7 +157,9 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMigratedTransformsAreApplied() throws Exception {
|
||||
public void testMigration() throws Exception {
|
||||
triggerChildOpened();
|
||||
|
||||
getChildSessionCallback()
|
||||
.onIpSecTransformsMigrated(makeDummyIpSecTransform(), makeDummyIpSecTransform());
|
||||
mTestLooper.dispatchAll();
|
||||
@@ -171,6 +177,17 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
|
||||
}
|
||||
|
||||
assertEquals(mGatewayConnection.mConnectedState, mGatewayConnection.getCurrentState());
|
||||
|
||||
final List<ChildSaProposal> saProposals =
|
||||
((VcnControlPlaneIkeConfig) mConfig.getControlPlaneConfig())
|
||||
.getChildSessionParams()
|
||||
.getSaProposals();
|
||||
final int expectedMtu =
|
||||
MtuUtils.getMtu(
|
||||
saProposals,
|
||||
mConfig.getMaxMtu(),
|
||||
TEST_UNDERLYING_NETWORK_RECORD_1.linkProperties.getMtu());
|
||||
verify(mNetworkAgent).sendLinkProperties(argThat(lp -> expectedMtu == lp.getMtu()));
|
||||
}
|
||||
|
||||
private void triggerChildOpened() {
|
||||
|
||||
@@ -90,12 +90,18 @@ public class VcnGatewayConnectionTestBase {
|
||||
protected static final int TEST_SUB_ID = 5;
|
||||
protected static final long ELAPSED_REAL_TIME = 123456789L;
|
||||
protected static final String TEST_IPSEC_TUNNEL_IFACE = "IPSEC_IFACE";
|
||||
|
||||
protected static final UnderlyingNetworkRecord TEST_UNDERLYING_NETWORK_RECORD_1 =
|
||||
new UnderlyingNetworkRecord(
|
||||
new Network(0),
|
||||
new NetworkCapabilities(),
|
||||
new LinkProperties(),
|
||||
false /* blocked */);
|
||||
|
||||
static {
|
||||
TEST_UNDERLYING_NETWORK_RECORD_1.linkProperties.setMtu(1500);
|
||||
}
|
||||
|
||||
protected static final UnderlyingNetworkRecord TEST_UNDERLYING_NETWORK_RECORD_2 =
|
||||
new UnderlyingNetworkRecord(
|
||||
new Network(1),
|
||||
@@ -103,6 +109,10 @@ public class VcnGatewayConnectionTestBase {
|
||||
new LinkProperties(),
|
||||
false /* blocked */);
|
||||
|
||||
static {
|
||||
TEST_UNDERLYING_NETWORK_RECORD_2.linkProperties.setMtu(1460);
|
||||
}
|
||||
|
||||
protected static final TelephonySubscriptionSnapshot TEST_SUBSCRIPTION_SNAPSHOT =
|
||||
new TelephonySubscriptionSnapshot(
|
||||
Collections.singletonMap(TEST_SUB_ID, TEST_SUB_GRP), Collections.EMPTY_MAP);
|
||||
|
||||
92
tests/vcn/java/com/android/server/vcn/util/MtuUtilsTest.java
Normal file
92
tests/vcn/java/com/android/server/vcn/util/MtuUtilsTest.java
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.vcn.util;
|
||||
|
||||
import static android.net.ipsec.ike.SaProposal.ENCRYPTION_ALGORITHM_AES_CBC;
|
||||
import static android.net.ipsec.ike.SaProposal.ENCRYPTION_ALGORITHM_AES_GCM_12;
|
||||
import static android.net.ipsec.ike.SaProposal.ENCRYPTION_ALGORITHM_AES_GCM_16;
|
||||
import static android.net.ipsec.ike.SaProposal.ENCRYPTION_ALGORITHM_AES_GCM_8;
|
||||
import static android.net.ipsec.ike.SaProposal.INTEGRITY_ALGORITHM_HMAC_SHA2_256_128;
|
||||
import static android.net.ipsec.ike.SaProposal.KEY_LEN_AES_256;
|
||||
|
||||
import static com.android.net.module.util.NetworkStackConstants.ETHER_MTU;
|
||||
import static com.android.net.module.util.NetworkStackConstants.IPV6_MIN_MTU;
|
||||
import static com.android.server.vcn.util.MtuUtils.getMtu;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
import android.net.ipsec.ike.ChildSaProposal;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class MtuUtilsTest {
|
||||
@Test
|
||||
public void testUnderlyingMtuZero() {
|
||||
assertEquals(
|
||||
IPV6_MIN_MTU, getMtu(emptyList(), ETHER_MTU /* maxMtu */, 0 /* underlyingMtu */));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClampsToMaxMtu() {
|
||||
assertEquals(0, getMtu(emptyList(), 0 /* maxMtu */, IPV6_MIN_MTU /* underlyingMtu */));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalModeAlgorithmLessThanUnderlyingMtu() {
|
||||
final List<ChildSaProposal> saProposals =
|
||||
Arrays.asList(
|
||||
new ChildSaProposal.Builder()
|
||||
.addEncryptionAlgorithm(
|
||||
ENCRYPTION_ALGORITHM_AES_CBC, KEY_LEN_AES_256)
|
||||
.addIntegrityAlgorithm(INTEGRITY_ALGORITHM_HMAC_SHA2_256_128)
|
||||
.build());
|
||||
|
||||
final int actualMtu =
|
||||
getMtu(saProposals, ETHER_MTU /* maxMtu */, ETHER_MTU /* underlyingMtu */);
|
||||
assertTrue(ETHER_MTU > actualMtu);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedModeAlgorithmLessThanUnderlyingMtu() {
|
||||
final List<ChildSaProposal> saProposals =
|
||||
Arrays.asList(
|
||||
new ChildSaProposal.Builder()
|
||||
.addEncryptionAlgorithm(
|
||||
ENCRYPTION_ALGORITHM_AES_GCM_16, KEY_LEN_AES_256)
|
||||
.addEncryptionAlgorithm(
|
||||
ENCRYPTION_ALGORITHM_AES_GCM_12, KEY_LEN_AES_256)
|
||||
.addEncryptionAlgorithm(
|
||||
ENCRYPTION_ALGORITHM_AES_GCM_8, KEY_LEN_AES_256)
|
||||
.build());
|
||||
|
||||
final int actualMtu =
|
||||
getMtu(saProposals, ETHER_MTU /* maxMtu */, ETHER_MTU /* underlyingMtu */);
|
||||
assertTrue(ETHER_MTU > actualMtu);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user