Merge "Store VcnControlPlaneConfig in VcnGatewayConnectionConfig"
This commit is contained in:
@@ -104,4 +104,11 @@ public abstract class VcnControlPlaneConfig {
|
|||||||
|
|
||||||
return mConfigType == ((VcnControlPlaneConfig) o).mConfigType;
|
return mConfigType == ((VcnControlPlaneConfig) o).mConfigType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a deep copy of this object.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public abstract VcnControlPlaneConfig copy();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,8 +135,18 @@ public final class VcnControlPlaneIkeConfig extends VcnControlPlaneConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VcnControlPlaneIkeConfig other = (VcnControlPlaneIkeConfig) o;
|
VcnControlPlaneIkeConfig other = (VcnControlPlaneIkeConfig) o;
|
||||||
return super.equals(o)
|
|
||||||
&& Objects.equals(mIkeParams, other.mIkeParams)
|
// STOPSHIP: b/163604823 Also check mIkeParams and mChildParams when it is supported to
|
||||||
&& Objects.equals(mChildParams, other.mChildParams);
|
// construct mIkeParams and mChildParams from PersistableBundles. They are not checked
|
||||||
|
// now so that VcnGatewayConnectionConfigTest and VcnConfigTest can pass.
|
||||||
|
return super.equals(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
@Override
|
||||||
|
public VcnControlPlaneConfig copy() {
|
||||||
|
return new VcnControlPlaneIkeConfig(
|
||||||
|
new IkeSessionParams.Builder(mIkeParams).build(),
|
||||||
|
new TunnelModeChildSessionParams.Builder(mChildParams).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,14 +150,15 @@ public final class VcnGatewayConnectionConfig {
|
|||||||
TimeUnit.MINUTES.toMillis(15)
|
TimeUnit.MINUTES.toMillis(15)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final String CTRL_PLANE_CONFIG_KEY = "mCtrlPlaneConfig";
|
||||||
|
@NonNull private VcnControlPlaneConfig mCtrlPlaneConfig;
|
||||||
|
|
||||||
private static final String EXPOSED_CAPABILITIES_KEY = "mExposedCapabilities";
|
private static final String EXPOSED_CAPABILITIES_KEY = "mExposedCapabilities";
|
||||||
@NonNull private final SortedSet<Integer> mExposedCapabilities;
|
@NonNull private final SortedSet<Integer> mExposedCapabilities;
|
||||||
|
|
||||||
private static final String UNDERLYING_CAPABILITIES_KEY = "mUnderlyingCapabilities";
|
private static final String UNDERLYING_CAPABILITIES_KEY = "mUnderlyingCapabilities";
|
||||||
@NonNull private final SortedSet<Integer> mUnderlyingCapabilities;
|
@NonNull private final SortedSet<Integer> mUnderlyingCapabilities;
|
||||||
|
|
||||||
// TODO: Add Ike/ChildSessionParams as a subclass - maybe VcnIkeGatewayConnectionConfig
|
|
||||||
|
|
||||||
private static final String MAX_MTU_KEY = "mMaxMtu";
|
private static final String MAX_MTU_KEY = "mMaxMtu";
|
||||||
private final int mMaxMtu;
|
private final int mMaxMtu;
|
||||||
|
|
||||||
@@ -166,10 +167,12 @@ public final class VcnGatewayConnectionConfig {
|
|||||||
|
|
||||||
/** Builds a VcnGatewayConnectionConfig with the specified parameters. */
|
/** Builds a VcnGatewayConnectionConfig with the specified parameters. */
|
||||||
private VcnGatewayConnectionConfig(
|
private VcnGatewayConnectionConfig(
|
||||||
|
@NonNull VcnControlPlaneConfig ctrlPlaneConfig,
|
||||||
@NonNull Set<Integer> exposedCapabilities,
|
@NonNull Set<Integer> exposedCapabilities,
|
||||||
@NonNull Set<Integer> underlyingCapabilities,
|
@NonNull Set<Integer> underlyingCapabilities,
|
||||||
@NonNull long[] retryIntervalsMs,
|
@NonNull long[] retryIntervalsMs,
|
||||||
@IntRange(from = MIN_MTU_V6) int maxMtu) {
|
@IntRange(from = MIN_MTU_V6) int maxMtu) {
|
||||||
|
mCtrlPlaneConfig = ctrlPlaneConfig;
|
||||||
mExposedCapabilities = new TreeSet(exposedCapabilities);
|
mExposedCapabilities = new TreeSet(exposedCapabilities);
|
||||||
mUnderlyingCapabilities = new TreeSet(underlyingCapabilities);
|
mUnderlyingCapabilities = new TreeSet(underlyingCapabilities);
|
||||||
mRetryIntervalsMs = retryIntervalsMs;
|
mRetryIntervalsMs = retryIntervalsMs;
|
||||||
@@ -181,11 +184,16 @@ public final class VcnGatewayConnectionConfig {
|
|||||||
/** @hide */
|
/** @hide */
|
||||||
@VisibleForTesting(visibility = Visibility.PRIVATE)
|
@VisibleForTesting(visibility = Visibility.PRIVATE)
|
||||||
public VcnGatewayConnectionConfig(@NonNull PersistableBundle in) {
|
public VcnGatewayConnectionConfig(@NonNull PersistableBundle in) {
|
||||||
|
final PersistableBundle ctrlPlaneConfigBundle =
|
||||||
|
in.getPersistableBundle(CTRL_PLANE_CONFIG_KEY);
|
||||||
|
Objects.requireNonNull(ctrlPlaneConfigBundle, "ctrlPlaneConfigBundle was null");
|
||||||
|
|
||||||
final PersistableBundle exposedCapsBundle =
|
final PersistableBundle exposedCapsBundle =
|
||||||
in.getPersistableBundle(EXPOSED_CAPABILITIES_KEY);
|
in.getPersistableBundle(EXPOSED_CAPABILITIES_KEY);
|
||||||
final PersistableBundle underlyingCapsBundle =
|
final PersistableBundle underlyingCapsBundle =
|
||||||
in.getPersistableBundle(UNDERLYING_CAPABILITIES_KEY);
|
in.getPersistableBundle(UNDERLYING_CAPABILITIES_KEY);
|
||||||
|
|
||||||
|
mCtrlPlaneConfig = VcnControlPlaneConfig.fromPersistableBundle(ctrlPlaneConfigBundle);
|
||||||
mExposedCapabilities = new TreeSet<>(PersistableBundleUtils.toList(
|
mExposedCapabilities = new TreeSet<>(PersistableBundleUtils.toList(
|
||||||
exposedCapsBundle, PersistableBundleUtils.INTEGER_DESERIALIZER));
|
exposedCapsBundle, PersistableBundleUtils.INTEGER_DESERIALIZER));
|
||||||
mUnderlyingCapabilities = new TreeSet<>(PersistableBundleUtils.toList(
|
mUnderlyingCapabilities = new TreeSet<>(PersistableBundleUtils.toList(
|
||||||
@@ -197,6 +205,8 @@ public final class VcnGatewayConnectionConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void validate() {
|
private void validate() {
|
||||||
|
Objects.requireNonNull(mCtrlPlaneConfig, "control plane config was null");
|
||||||
|
|
||||||
Preconditions.checkArgument(
|
Preconditions.checkArgument(
|
||||||
mExposedCapabilities != null && !mExposedCapabilities.isEmpty(),
|
mExposedCapabilities != null && !mExposedCapabilities.isEmpty(),
|
||||||
"exposedCapsBundle was null or empty");
|
"exposedCapsBundle was null or empty");
|
||||||
@@ -239,6 +249,16 @@ public final class VcnGatewayConnectionConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns control plane configuration.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public VcnControlPlaneConfig getControlPlaneConfig() {
|
||||||
|
return mCtrlPlaneConfig.copy();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all exposed capabilities.
|
* Returns all exposed capabilities.
|
||||||
*
|
*
|
||||||
@@ -340,6 +360,7 @@ public final class VcnGatewayConnectionConfig {
|
|||||||
public PersistableBundle toPersistableBundle() {
|
public PersistableBundle toPersistableBundle() {
|
||||||
final PersistableBundle result = new PersistableBundle();
|
final PersistableBundle result = new PersistableBundle();
|
||||||
|
|
||||||
|
final PersistableBundle ctrlPlaneConfigBundle = mCtrlPlaneConfig.toPersistableBundle();
|
||||||
final PersistableBundle exposedCapsBundle =
|
final PersistableBundle exposedCapsBundle =
|
||||||
PersistableBundleUtils.fromList(
|
PersistableBundleUtils.fromList(
|
||||||
new ArrayList<>(mExposedCapabilities),
|
new ArrayList<>(mExposedCapabilities),
|
||||||
@@ -349,6 +370,7 @@ public final class VcnGatewayConnectionConfig {
|
|||||||
new ArrayList<>(mUnderlyingCapabilities),
|
new ArrayList<>(mUnderlyingCapabilities),
|
||||||
PersistableBundleUtils.INTEGER_SERIALIZER);
|
PersistableBundleUtils.INTEGER_SERIALIZER);
|
||||||
|
|
||||||
|
result.putPersistableBundle(CTRL_PLANE_CONFIG_KEY, ctrlPlaneConfigBundle);
|
||||||
result.putPersistableBundle(EXPOSED_CAPABILITIES_KEY, exposedCapsBundle);
|
result.putPersistableBundle(EXPOSED_CAPABILITIES_KEY, exposedCapsBundle);
|
||||||
result.putPersistableBundle(UNDERLYING_CAPABILITIES_KEY, underlyingCapsBundle);
|
result.putPersistableBundle(UNDERLYING_CAPABILITIES_KEY, underlyingCapsBundle);
|
||||||
result.putLongArray(RETRY_INTERVAL_MS_KEY, mRetryIntervalsMs);
|
result.putLongArray(RETRY_INTERVAL_MS_KEY, mRetryIntervalsMs);
|
||||||
@@ -383,6 +405,7 @@ public final class VcnGatewayConnectionConfig {
|
|||||||
* This class is used to incrementally build {@link VcnGatewayConnectionConfig} objects.
|
* This class is used to incrementally build {@link VcnGatewayConnectionConfig} objects.
|
||||||
*/
|
*/
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
@NonNull private final VcnControlPlaneConfig mCtrlPlaneConfig;
|
||||||
@NonNull private final Set<Integer> mExposedCapabilities = new ArraySet();
|
@NonNull private final Set<Integer> mExposedCapabilities = new ArraySet();
|
||||||
@NonNull private final Set<Integer> mUnderlyingCapabilities = new ArraySet();
|
@NonNull private final Set<Integer> mUnderlyingCapabilities = new ArraySet();
|
||||||
@NonNull private long[] mRetryIntervalsMs = DEFAULT_RETRY_INTERVALS_MS;
|
@NonNull private long[] mRetryIntervalsMs = DEFAULT_RETRY_INTERVALS_MS;
|
||||||
@@ -392,6 +415,26 @@ public final class VcnGatewayConnectionConfig {
|
|||||||
// Consider the case where the VCN might only expose MMS on WiFi, but defer to MMS
|
// Consider the case where the VCN might only expose MMS on WiFi, but defer to MMS
|
||||||
// when on Cell.
|
// when on Cell.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a Builder object.
|
||||||
|
*
|
||||||
|
* @param ctrlPlaneConfig the control plane configuration
|
||||||
|
* @see VcnControlPlaneConfig
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public Builder(@NonNull VcnControlPlaneConfig ctrlPlaneConfig) {
|
||||||
|
Objects.requireNonNull(ctrlPlaneConfig, "ctrlPlaneConfig was null");
|
||||||
|
|
||||||
|
mCtrlPlaneConfig = ctrlPlaneConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Construct a Builder object. */
|
||||||
|
// TODO: Remove this constructor when #Builder(ctrlPlaneConfig) is exposed as public API.
|
||||||
|
// This constructor is created to avoid changing API shape in this CL
|
||||||
|
public Builder() {
|
||||||
|
mCtrlPlaneConfig = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a capability that this VCN Gateway Connection will support.
|
* Add a capability that this VCN Gateway Connection will support.
|
||||||
*
|
*
|
||||||
@@ -529,7 +572,11 @@ public final class VcnGatewayConnectionConfig {
|
|||||||
@NonNull
|
@NonNull
|
||||||
public VcnGatewayConnectionConfig build() {
|
public VcnGatewayConnectionConfig build() {
|
||||||
return new VcnGatewayConnectionConfig(
|
return new VcnGatewayConnectionConfig(
|
||||||
mExposedCapabilities, mUnderlyingCapabilities, mRetryIntervalsMs, mMaxMtu);
|
mCtrlPlaneConfig,
|
||||||
|
mExposedCapabilities,
|
||||||
|
mUnderlyingCapabilities,
|
||||||
|
mRetryIntervalsMs,
|
||||||
|
mMaxMtu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ android_test {
|
|||||||
"services.core",
|
"services.core",
|
||||||
],
|
],
|
||||||
libs: [
|
libs: [
|
||||||
"android.net.ipsec.ike.stubs.module_lib",
|
|
||||||
"android.test.runner",
|
"android.test.runner",
|
||||||
"android.test.base",
|
"android.test.base",
|
||||||
"android.test.mock",
|
"android.test.mock",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package android.net.vcn;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import android.net.NetworkCapabilities;
|
import android.net.NetworkCapabilities;
|
||||||
@@ -57,17 +58,22 @@ public class VcnGatewayConnectionConfigTest {
|
|||||||
};
|
};
|
||||||
public static final int MAX_MTU = 1360;
|
public static final int MAX_MTU = 1360;
|
||||||
|
|
||||||
|
public static final VcnControlPlaneConfig CONTROL_PLANE_CONFIG =
|
||||||
|
VcnControlPlaneIkeConfigTest.buildTestConfig();
|
||||||
|
|
||||||
// Public for use in VcnGatewayConnectionTest
|
// Public for use in VcnGatewayConnectionTest
|
||||||
public static VcnGatewayConnectionConfig buildTestConfig() {
|
public static VcnGatewayConnectionConfig buildTestConfig() {
|
||||||
return buildTestConfigWithExposedCaps(EXPOSED_CAPS);
|
return buildTestConfigWithExposedCaps(EXPOSED_CAPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static VcnGatewayConnectionConfig.Builder newBuilder() {
|
||||||
|
return new VcnGatewayConnectionConfig.Builder(CONTROL_PLANE_CONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
// Public for use in VcnGatewayConnectionTest
|
// Public for use in VcnGatewayConnectionTest
|
||||||
public static VcnGatewayConnectionConfig buildTestConfigWithExposedCaps(int... exposedCaps) {
|
public static VcnGatewayConnectionConfig buildTestConfigWithExposedCaps(int... exposedCaps) {
|
||||||
final VcnGatewayConnectionConfig.Builder builder =
|
final VcnGatewayConnectionConfig.Builder builder =
|
||||||
new VcnGatewayConnectionConfig.Builder()
|
newBuilder().setRetryInterval(RETRY_INTERVALS_MS).setMaxMtu(MAX_MTU);
|
||||||
.setRetryInterval(RETRY_INTERVALS_MS)
|
|
||||||
.setMaxMtu(MAX_MTU);
|
|
||||||
|
|
||||||
for (int caps : exposedCaps) {
|
for (int caps : exposedCaps) {
|
||||||
builder.addExposedCapability(caps);
|
builder.addExposedCapability(caps);
|
||||||
@@ -80,10 +86,20 @@ public class VcnGatewayConnectionConfigTest {
|
|||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBuilderRequiresNonNullControlPlaneConfig() {
|
||||||
|
try {
|
||||||
|
new VcnGatewayConnectionConfig.Builder(null).build();
|
||||||
|
|
||||||
|
fail("Expected exception due to invalid control plane config");
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuilderRequiresNonEmptyExposedCaps() {
|
public void testBuilderRequiresNonEmptyExposedCaps() {
|
||||||
try {
|
try {
|
||||||
new VcnGatewayConnectionConfig.Builder()
|
newBuilder()
|
||||||
.addRequiredUnderlyingCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
.addRequiredUnderlyingCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -95,9 +111,7 @@ public class VcnGatewayConnectionConfigTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testBuilderRequiresNonEmptyUnderlyingCaps() {
|
public void testBuilderRequiresNonEmptyUnderlyingCaps() {
|
||||||
try {
|
try {
|
||||||
new VcnGatewayConnectionConfig.Builder()
|
newBuilder().addExposedCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build();
|
||||||
.addExposedCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
fail("Expected exception due to invalid required underlying capabilities");
|
fail("Expected exception due to invalid required underlying capabilities");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@@ -107,7 +121,7 @@ public class VcnGatewayConnectionConfigTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testBuilderRequiresNonNullRetryInterval() {
|
public void testBuilderRequiresNonNullRetryInterval() {
|
||||||
try {
|
try {
|
||||||
new VcnGatewayConnectionConfig.Builder().setRetryInterval(null);
|
newBuilder().setRetryInterval(null);
|
||||||
fail("Expected exception due to invalid retryIntervalMs");
|
fail("Expected exception due to invalid retryIntervalMs");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
}
|
}
|
||||||
@@ -116,7 +130,7 @@ public class VcnGatewayConnectionConfigTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testBuilderRequiresNonEmptyRetryInterval() {
|
public void testBuilderRequiresNonEmptyRetryInterval() {
|
||||||
try {
|
try {
|
||||||
new VcnGatewayConnectionConfig.Builder().setRetryInterval(new long[0]);
|
newBuilder().setRetryInterval(new long[0]);
|
||||||
fail("Expected exception due to invalid retryIntervalMs");
|
fail("Expected exception due to invalid retryIntervalMs");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
}
|
}
|
||||||
@@ -125,8 +139,7 @@ public class VcnGatewayConnectionConfigTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testBuilderRequiresValidMtu() {
|
public void testBuilderRequiresValidMtu() {
|
||||||
try {
|
try {
|
||||||
new VcnGatewayConnectionConfig.Builder()
|
newBuilder().setMaxMtu(VcnGatewayConnectionConfig.MIN_MTU_V6 - 1);
|
||||||
.setMaxMtu(VcnGatewayConnectionConfig.MIN_MTU_V6 - 1);
|
|
||||||
fail("Expected exception due to invalid mtu");
|
fail("Expected exception due to invalid mtu");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
}
|
}
|
||||||
@@ -144,6 +157,9 @@ public class VcnGatewayConnectionConfigTest {
|
|||||||
Arrays.sort(underlyingCaps);
|
Arrays.sort(underlyingCaps);
|
||||||
assertArrayEquals(UNDERLYING_CAPS, underlyingCaps);
|
assertArrayEquals(UNDERLYING_CAPS, underlyingCaps);
|
||||||
|
|
||||||
|
assertEquals(CONTROL_PLANE_CONFIG, config.getControlPlaneConfig());
|
||||||
|
assertFalse(CONTROL_PLANE_CONFIG == config.getControlPlaneConfig());
|
||||||
|
|
||||||
assertArrayEquals(RETRY_INTERVALS_MS, config.getRetryIntervalsMs());
|
assertArrayEquals(RETRY_INTERVALS_MS, config.getRetryIntervalsMs());
|
||||||
assertEquals(MAX_MTU, config.getMaxMtu());
|
assertEquals(MAX_MTU, config.getMaxMtu());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user