Test the encap/timeout for the VCN

Bug: 269715746
Test: VpnTest
Change-Id: I8e5e7a7eb09ee4d2e0a88193c5a6b1f0580d5eb8
This commit is contained in:
Chalard Jean
2023-04-21 14:37:13 +09:00
parent d8321ef84f
commit 12740c9ff0

View File

@@ -142,6 +142,7 @@ import android.net.ipsec.ike.exceptions.IkeNetworkLostException;
import android.net.ipsec.ike.exceptions.IkeNonProtocolException; import android.net.ipsec.ike.exceptions.IkeNonProtocolException;
import android.net.ipsec.ike.exceptions.IkeProtocolException; import android.net.ipsec.ike.exceptions.IkeProtocolException;
import android.net.ipsec.ike.exceptions.IkeTimeoutException; import android.net.ipsec.ike.exceptions.IkeTimeoutException;
import android.net.vcn.VcnTransportInfo;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
import android.os.Build.VERSION_CODES; import android.os.Build.VERSION_CODES;
import android.os.Bundle; import android.os.Bundle;
@@ -1563,6 +1564,11 @@ public class VpnTest extends VpnTestBase {
} }
private NetworkCallback triggerOnAvailableAndGetCallback() throws Exception { private NetworkCallback triggerOnAvailableAndGetCallback() throws Exception {
return triggerOnAvailableAndGetCallback(new NetworkCapabilities.Builder().build());
}
private NetworkCallback triggerOnAvailableAndGetCallback(
@NonNull final NetworkCapabilities caps) throws Exception {
final ArgumentCaptor<NetworkCallback> networkCallbackCaptor = final ArgumentCaptor<NetworkCallback> networkCallbackCaptor =
ArgumentCaptor.forClass(NetworkCallback.class); ArgumentCaptor.forClass(NetworkCallback.class);
verify(mConnectivityManager, timeout(TEST_TIMEOUT_MS)) verify(mConnectivityManager, timeout(TEST_TIMEOUT_MS))
@@ -1579,7 +1585,7 @@ public class VpnTest extends VpnTestBase {
// if NetworkCapabilities and LinkProperties of underlying network will be sent/cleared or // if NetworkCapabilities and LinkProperties of underlying network will be sent/cleared or
// not. // not.
// See verifyVpnManagerEvent(). // See verifyVpnManagerEvent().
cb.onCapabilitiesChanged(TEST_NETWORK, new NetworkCapabilities()); cb.onCapabilitiesChanged(TEST_NETWORK, caps);
cb.onLinkPropertiesChanged(TEST_NETWORK, new LinkProperties()); cb.onLinkPropertiesChanged(TEST_NETWORK, new LinkProperties());
return cb; return cb;
} }
@@ -1903,12 +1909,15 @@ public class VpnTest extends VpnTestBase {
private PlatformVpnSnapshot verifySetupPlatformVpn(VpnProfile vpnProfile, private PlatformVpnSnapshot verifySetupPlatformVpn(VpnProfile vpnProfile,
IkeSessionConfiguration ikeConfig, boolean mtuSupportsIpv6) throws Exception { IkeSessionConfiguration ikeConfig, boolean mtuSupportsIpv6) throws Exception {
return verifySetupPlatformVpn(vpnProfile, ikeConfig, mtuSupportsIpv6, return verifySetupPlatformVpn(vpnProfile, ikeConfig,
false /* areLongLivedTcpConnectionsExpensive */); new NetworkCapabilities.Builder().build() /* underlying network caps */,
mtuSupportsIpv6, false /* areLongLivedTcpConnectionsExpensive */);
} }
private PlatformVpnSnapshot verifySetupPlatformVpn(VpnProfile vpnProfile, private PlatformVpnSnapshot verifySetupPlatformVpn(VpnProfile vpnProfile,
IkeSessionConfiguration ikeConfig, boolean mtuSupportsIpv6, IkeSessionConfiguration ikeConfig,
@NonNull final NetworkCapabilities underlyingNetworkCaps,
boolean mtuSupportsIpv6,
boolean areLongLivedTcpConnectionsExpensive) throws Exception { boolean areLongLivedTcpConnectionsExpensive) throws Exception {
if (!mtuSupportsIpv6) { if (!mtuSupportsIpv6) {
doReturn(IPV6_MIN_MTU - 1).when(mTestDeps).calculateVpnMtu(any(), anyInt(), anyInt(), doReturn(IPV6_MIN_MTU - 1).when(mTestDeps).calculateVpnMtu(any(), anyInt(), anyInt(),
@@ -1925,7 +1934,7 @@ public class VpnTest extends VpnTestBase {
.thenReturn(vpnProfile.encode()); .thenReturn(vpnProfile.encode());
vpn.startVpnProfile(TEST_VPN_PKG); vpn.startVpnProfile(TEST_VPN_PKG);
final NetworkCallback nwCb = triggerOnAvailableAndGetCallback(); final NetworkCallback nwCb = triggerOnAvailableAndGetCallback(underlyingNetworkCaps);
verify(mExecutor, atLeastOnce()).schedule(any(Runnable.class), anyLong(), any()); verify(mExecutor, atLeastOnce()).schedule(any(Runnable.class), anyLong(), any());
reset(mExecutor); reset(mExecutor);
@@ -2079,15 +2088,16 @@ public class VpnTest extends VpnTestBase {
doTestMigrateIkeSession(ikeProfile.toVpnProfile(), doTestMigrateIkeSession(ikeProfile.toVpnProfile(),
expectedKeepalive, expectedKeepalive,
ESP_IP_VERSION_AUTO /* expectedIpVersion */, ESP_IP_VERSION_AUTO /* expectedIpVersion */,
ESP_ENCAP_TYPE_AUTO /* expectedEncapType */); ESP_ENCAP_TYPE_AUTO /* expectedEncapType */,
new NetworkCapabilities.Builder().build());
} }
private void doTestMigrateIkeSession_FromIkeTunnConnParams( private Ikev2VpnProfile makeIkeV2VpnProfile(
boolean isAutomaticIpVersionSelectionEnabled, boolean isAutomaticIpVersionSelectionEnabled,
boolean isAutomaticNattKeepaliveTimerEnabled, boolean isAutomaticNattKeepaliveTimerEnabled,
int keepaliveInProfile, int keepaliveInProfile,
int ipVersionInProfile, int ipVersionInProfile,
int encapTypeInProfile) throws Exception { int encapTypeInProfile) {
// TODO: Update helper function in IkeSessionTestUtils to support building IkeSessionParams // TODO: Update helper function in IkeSessionTestUtils to support building IkeSessionParams
// with IP version and encap type when mainline-prod branch support these two APIs. // with IP version and encap type when mainline-prod branch support these two APIs.
final IkeSessionParams params = getTestIkeSessionParams(true /* testIpv6 */, final IkeSessionParams params = getTestIkeSessionParams(true /* testIpv6 */,
@@ -2099,12 +2109,40 @@ public class VpnTest extends VpnTestBase {
final IkeTunnelConnectionParams tunnelParams = final IkeTunnelConnectionParams tunnelParams =
new IkeTunnelConnectionParams(ikeSessionParams, CHILD_PARAMS); new IkeTunnelConnectionParams(ikeSessionParams, CHILD_PARAMS);
final Ikev2VpnProfile ikeProfile = new Ikev2VpnProfile.Builder(tunnelParams) return new Ikev2VpnProfile.Builder(tunnelParams)
.setBypassable(true) .setBypassable(true)
.setAutomaticNattKeepaliveTimerEnabled(isAutomaticNattKeepaliveTimerEnabled) .setAutomaticNattKeepaliveTimerEnabled(isAutomaticNattKeepaliveTimerEnabled)
.setAutomaticIpVersionSelectionEnabled(isAutomaticIpVersionSelectionEnabled) .setAutomaticIpVersionSelectionEnabled(isAutomaticIpVersionSelectionEnabled)
.build(); .build();
}
private void doTestMigrateIkeSession_FromIkeTunnConnParams(
boolean isAutomaticIpVersionSelectionEnabled,
boolean isAutomaticNattKeepaliveTimerEnabled,
int keepaliveInProfile,
int ipVersionInProfile,
int encapTypeInProfile) throws Exception {
doTestMigrateIkeSession_FromIkeTunnConnParams(isAutomaticIpVersionSelectionEnabled,
isAutomaticNattKeepaliveTimerEnabled, keepaliveInProfile, ipVersionInProfile,
encapTypeInProfile, new NetworkCapabilities.Builder().build());
}
private void doTestMigrateIkeSession_FromIkeTunnConnParams(
boolean isAutomaticIpVersionSelectionEnabled,
boolean isAutomaticNattKeepaliveTimerEnabled,
int keepaliveInProfile,
int ipVersionInProfile,
int encapTypeInProfile,
@NonNull final NetworkCapabilities nc) throws Exception {
final Ikev2VpnProfile ikeProfile = makeIkeV2VpnProfile(
isAutomaticIpVersionSelectionEnabled,
isAutomaticNattKeepaliveTimerEnabled,
keepaliveInProfile,
ipVersionInProfile,
encapTypeInProfile);
final IkeSessionParams ikeSessionParams =
ikeProfile.getIkeTunnelConnectionParams().getIkeSessionParams();
final int expectedKeepalive = isAutomaticNattKeepaliveTimerEnabled final int expectedKeepalive = isAutomaticNattKeepaliveTimerEnabled
? AUTOMATIC_KEEPALIVE_DELAY_SECONDS ? AUTOMATIC_KEEPALIVE_DELAY_SECONDS
: ikeSessionParams.getNattKeepAliveDelaySeconds(); : ikeSessionParams.getNattKeepAliveDelaySeconds();
@@ -2115,22 +2153,48 @@ public class VpnTest extends VpnTestBase {
? ESP_ENCAP_TYPE_AUTO ? ESP_ENCAP_TYPE_AUTO
: ikeSessionParams.getEncapType(); : ikeSessionParams.getEncapType();
doTestMigrateIkeSession(ikeProfile.toVpnProfile(), expectedKeepalive, doTestMigrateIkeSession(ikeProfile.toVpnProfile(), expectedKeepalive,
expectedIpVersion, expectedEncapType); expectedIpVersion, expectedEncapType, nc);
} }
private void doTestMigrateIkeSession(VpnProfile profile, @Test
int expectedKeepalive, int expectedIpVersion, int expectedEncapType) throws Exception { public void doTestMigrateIkeSession_Vcn() throws Exception {
final int expectedKeepalive = 2097; // Any unlikely number will do
final NetworkCapabilities vcnNc = new NetworkCapabilities.Builder()
.addTransportType(TRANSPORT_CELLULAR)
.setTransportInfo(new VcnTransportInfo(TEST_SUB_ID, expectedKeepalive))
.build();
final Ikev2VpnProfile ikev2VpnProfile = makeIkeV2VpnProfile(
true /* isAutomaticIpVersionSelectionEnabled */,
true /* isAutomaticNattKeepaliveTimerEnabled */,
234 /* keepaliveInProfile */, // Should be ignored, any value will do
ESP_IP_VERSION_IPV4, // Should be ignored
ESP_ENCAP_TYPE_UDP // Should be ignored
);
doTestMigrateIkeSession(
ikev2VpnProfile.toVpnProfile(),
expectedKeepalive,
ESP_IP_VERSION_AUTO /* expectedIpVersion */,
ESP_ENCAP_TYPE_AUTO /* expectedEncapType */,
vcnNc);
}
private void doTestMigrateIkeSession(
@NonNull final VpnProfile profile,
final int expectedKeepalive,
final int expectedIpVersion,
final int expectedEncapType,
@NonNull final NetworkCapabilities caps) throws Exception {
final PlatformVpnSnapshot vpnSnapShot = final PlatformVpnSnapshot vpnSnapShot =
verifySetupPlatformVpn(profile, verifySetupPlatformVpn(profile,
createIkeConfig(createIkeConnectInfo(), true /* isMobikeEnabled */), createIkeConfig(createIkeConnectInfo(), true /* isMobikeEnabled */),
caps /* underlying network capabilities */,
false /* mtuSupportsIpv6 */, false /* mtuSupportsIpv6 */,
expectedKeepalive < DEFAULT_LONG_LIVED_TCP_CONNS_EXPENSIVE_TIMEOUT_SEC); expectedKeepalive < DEFAULT_LONG_LIVED_TCP_CONNS_EXPENSIVE_TIMEOUT_SEC);
// Simulate a new network coming up // Simulate a new network coming up
vpnSnapShot.nwCb.onAvailable(TEST_NETWORK_2); vpnSnapShot.nwCb.onAvailable(TEST_NETWORK_2);
verify(mIkeSessionWrapper, never()).setNetwork(any(), anyInt(), anyInt(), anyInt()); verify(mIkeSessionWrapper, never()).setNetwork(any(), anyInt(), anyInt(), anyInt());
vpnSnapShot.nwCb.onCapabilitiesChanged( vpnSnapShot.nwCb.onCapabilitiesChanged(TEST_NETWORK_2, caps);
TEST_NETWORK_2, new NetworkCapabilities.Builder().build());
// Verify MOBIKE is triggered // Verify MOBIKE is triggered
verify(mIkeSessionWrapper, timeout(TEST_TIMEOUT_MS)).setNetwork(TEST_NETWORK_2, verify(mIkeSessionWrapper, timeout(TEST_TIMEOUT_MS)).setNetwork(TEST_NETWORK_2,
expectedIpVersion, expectedEncapType, expectedKeepalive); expectedIpVersion, expectedEncapType, expectedKeepalive);
@@ -2156,6 +2220,7 @@ public class VpnTest extends VpnTestBase {
final PlatformVpnSnapshot vpnSnapShot = final PlatformVpnSnapshot vpnSnapShot =
verifySetupPlatformVpn(ikeProfile.toVpnProfile(), verifySetupPlatformVpn(ikeProfile.toVpnProfile(),
createIkeConfig(createIkeConnectInfo(), true /* isMobikeEnabled */), createIkeConfig(createIkeConnectInfo(), true /* isMobikeEnabled */),
new NetworkCapabilities.Builder().build() /* underlying network caps */,
hasV6 /* mtuSupportsIpv6 */, hasV6 /* mtuSupportsIpv6 */,
false /* areLongLivedTcpConnectionsExpensive */); false /* areLongLivedTcpConnectionsExpensive */);
reset(mExecutor); reset(mExecutor);
@@ -2343,6 +2408,7 @@ public class VpnTest extends VpnTestBase {
final PlatformVpnSnapshot vpnSnapShot = final PlatformVpnSnapshot vpnSnapShot =
verifySetupPlatformVpn(ikeProfile.toVpnProfile(), verifySetupPlatformVpn(ikeProfile.toVpnProfile(),
createIkeConfig(createIkeConnectInfo(), true /* isMobikeEnabled */), createIkeConfig(createIkeConnectInfo(), true /* isMobikeEnabled */),
new NetworkCapabilities.Builder().build() /* underlying network caps */,
false /* mtuSupportsIpv6 */, false /* mtuSupportsIpv6 */,
true /* areLongLivedTcpConnectionsExpensive */); true /* areLongLivedTcpConnectionsExpensive */);