/* * 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 android.net.vcn; import static android.net.ipsec.ike.IkeSessionParams.IKE_OPTION_MOBIKE; import static android.net.vcn.Flags.FLAG_SAFE_MODE_CONFIG; import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED; import static com.android.internal.annotations.VisibleForTesting.Visibility; import android.annotation.FlaggedApi; import android.annotation.IntDef; import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SuppressLint; import android.net.Network; import android.net.NetworkCapabilities; import android.net.ipsec.ike.IkeTunnelConnectionParams; import android.net.vcn.persistablebundleutils.TunnelConnectionParamsUtils; import android.os.PersistableBundle; import android.util.ArraySet; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.ArrayUtils; import com.android.internal.util.Preconditions; import com.android.server.vcn.util.PersistableBundleUtils; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.util.concurrent.TimeUnit; /** * This class represents a configuration for a connection to a Virtual Carrier Network gateway. * *
Each VcnGatewayConnectionConfig represents a single logical connection to a carrier gateway, * and may provide one or more telephony services (as represented by network capabilities). Each * gateway is expected to provide mobility for a given session as the device roams across {@link * Network}s. * *
A VCN connection based on this configuration will be brought up dynamically based on device * settings, and filed NetworkRequests. Underlying Networks must provide INTERNET connectivity, and * must be part of the subscription group under which this configuration is registered (see {@link * VcnManager#setVcnConfig}). * *
As an abstraction of a cellular network, services that can be provided by a VCN network are * limited to services provided by cellular networks: * *
If set, the gateway connection will monitor the data stall detection of the VCN network.
* When there is a suspected data stall, the gateway connection will attempt recovery by
* performing a mobility update on the underlying IKE session.
*/
public static final int VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY = 0;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(
prefix = {"VCN_GATEWAY_OPTION_"},
value = {
VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY,
})
public @interface VcnGatewayOption {}
private static final Set Limited to ensure an upper bound on config sizes.
*/
private static final int MAX_RETRY_INTERVAL_COUNT = 10;
/**
* The minimum allowable repeating retry interval
*
* To ensure the device is not constantly being woken up, this retry interval MUST be greater
* than this value.
*
* @see {@link Builder#setRetryIntervalsMillis()}
*/
private static final long MINIMUM_REPEATING_RETRY_INTERVAL_MS = TimeUnit.MINUTES.toMillis(15);
private static final long[] DEFAULT_RETRY_INTERVALS_MS =
new long[] {
TimeUnit.SECONDS.toMillis(1),
TimeUnit.SECONDS.toMillis(2),
TimeUnit.SECONDS.toMillis(5),
TimeUnit.SECONDS.toMillis(30),
TimeUnit.MINUTES.toMillis(1),
TimeUnit.MINUTES.toMillis(5),
TimeUnit.MINUTES.toMillis(15)
};
/** @hide */
@VisibleForTesting(visibility = Visibility.PRIVATE)
public static final List This name is used by the configuring apps to distinguish between
* VcnGatewayConnectionConfigs configured on a single {@link VcnConfig}. This will be used as
* the identifier in VcnStatusCallback invocations.
*
* @see VcnManager.VcnStatusCallback#onGatewayConnectionError
*/
@NonNull
public String getGatewayConnectionName() {
return mGatewayConnectionName;
}
/**
* Returns tunnel connection parameters.
*
* @hide
*/
@NonNull
public IkeTunnelConnectionParams getTunnelConnectionParams() {
return mTunnelConnectionParams;
}
/**
* Returns all exposed capabilities.
*
* The returned integer-value capabilities will not contain duplicates, and will be sorted in
* ascending numerical order.
*
* @see Builder#addExposedCapability(int)
* @see Builder#removeExposedCapability(int)
*/
@NonNull
public int[] getExposedCapabilities() {
// Sorted set guarantees ordering
return ArrayUtils.convertToIntArray(new ArrayList<>(mExposedCapabilities));
}
/**
* Returns all exposed capabilities.
*
* Left to prevent the need to make major changes while changes are actively in flight.
*
* @deprecated use getExposedCapabilities() instead
* @hide
*/
@Deprecated
@NonNull
public Set To select the VCN underlying network, the VCN connection will go through all the
* network candidates and return a network matching the highest priority rule.
*
* If multiple networks match the same rule, the VCN will prefer an already-selected
* network as opposed to a new/unselected network. However, if both are new/unselected
* networks, a network will be chosen arbitrarily amongst the networks matching the highest
* priority rule.
*
* If all networks fail to match the rules provided, a carrier-owned underlying network
* will still be selected (if available, at random if necessary).
*
* @param underlyingNetworkTemplates a list of unique VcnUnderlyingNetworkTemplates that are
* ordered from most to least preferred, or an empty list to use the default
* prioritization. The default network prioritization order is Opportunistic cellular,
* Carrier WiFi and then Macro cellular.
* @return this {@link Builder} instance, for chaining
*/
@NonNull
public Builder setVcnUnderlyingNetworkPriorities(
@NonNull List The last retry interval will be repeated until safe mode is entered, or a connection
* is successfully established, at which point the retry timers will be reset. For power
* reasons, the last (repeated) retry interval MUST be at least 15 minutes.
*
* Retry intervals MAY be subject to system power saving modes. That is to say that if
* the system enters a power saving mode, the retry may not occur until the device leaves
* the specified power saving mode. Intervals are sequential, and intervals will NOT be
* skipped if system power saving results in delaying retries (even if it exceed multiple
* retry intervals).
*
* Each Gateway Connection will retry according to the retry intervals configured, but if
* safe mode is enabled, all Gateway Connection(s) will be disabled.
*
* @param retryIntervalsMs an array of between 1 and 10 millisecond intervals after which
* the VCN will attempt to retry a session initiation. The last (repeating) retry
* interval must be at least 15 minutes. Defaults to: {@code [1s, 2s, 5s, 30s, 1m, 5m,
* 15m]}
* @return this {@link Builder} instance, for chaining
* @see VcnManager for additional discussion on fail-safe mode
*/
@NonNull
public Builder setRetryIntervalsMillis(@NonNull long[] retryIntervalsMs) {
validateRetryInterval(retryIntervalsMs);
mRetryIntervalsMs = retryIntervalsMs;
return this;
}
/**
* Sets the maximum MTU allowed for this VCN Gateway Connection.
*
* This MTU is applied to the VCN Gateway Connection exposed Networks, and represents the
* MTU of the virtualized network.
*
* The system may reduce the MTU below the maximum specified based on signals such as the
* MTU of the underlying networks (and adjusted for Gateway Connection overhead).
*
* @param maxMtu the maximum MTU allowed for this Gateway Connection. Must be greater than
* the IPv6 minimum MTU of 1280. Defaults to 1500.
* @return this {@link Builder} instance, for chaining
*/
@NonNull
public Builder setMaxMtu(@IntRange(from = MIN_MTU_V6) int maxMtu) {
Preconditions.checkArgument(
maxMtu >= MIN_MTU_V6, "maxMtu must be at least IPv6 min MTU (1280)");
mMaxMtu = maxMtu;
return this;
}
/**
* Sets the maximum supported IKEv2/IPsec NATT keepalive timeout.
*
* This is used as a power-optimization hint for other IKEv2/IPsec use cases (e.g. VPNs,
* or IWLAN) to reduce the necessary keepalive frequency, thus conserving power and data.
*
* @param minUdpPort4500NatTimeoutSeconds the maximum keepalive timeout supported by the VCN
* Gateway Connection, generally the minimum duration a NAT mapping is cached on the VCN
* Gateway.
* @return this {@link Builder} instance, for chaining
*/
@NonNull
public Builder setMinUdpPort4500NatTimeoutSeconds(
@IntRange(from = MIN_UDP_PORT_4500_NAT_TIMEOUT_SECONDS)
int minUdpPort4500NatTimeoutSeconds) {
Preconditions.checkArgument(
minUdpPort4500NatTimeoutSeconds >= MIN_UDP_PORT_4500_NAT_TIMEOUT_SECONDS,
"Timeout must be at least 120s");
mMinUdpPort4500NatTimeoutSeconds = minUdpPort4500NatTimeoutSeconds;
return this;
}
/**
* Enables the specified VCN gateway option.
*
* @param option the option to be enabled
* @return this {@link Builder} instance, for chaining
* @throws IllegalArgumentException if the provided option is invalid
*/
@NonNull
public Builder addGatewayOption(@VcnGatewayOption int option) {
validateGatewayOption(option);
mGatewayOptions.add(option);
return this;
}
/**
* Resets (disables) the specified VCN gateway option.
*
* @param option the option to be disabled
* @return this {@link Builder} instance, for chaining
* @throws IllegalArgumentException if the provided option is invalid
*/
@NonNull
public Builder removeGatewayOption(@VcnGatewayOption int option) {
validateGatewayOption(option);
mGatewayOptions.remove(option);
return this;
}
/**
* Enable/disable safe mode
*
* If a VCN fails to provide connectivity within a system-provided timeout, it will enter
* safe mode. In safe mode, the VCN Network will be torn down and the system will restore
* connectivity by allowing underlying cellular or WiFi networks to be used as default. At
* the same time, VCN will continue to retry until it succeeds.
*
* When safe mode is disabled and VCN connection fails to provide connectivity, end users
* might not have connectivity, and may not have access to carrier-owned underlying
* networks.
*
* @param enabled whether safe mode should be enabled. Defaults to {@code true}
*/
@FlaggedApi(FLAG_SAFE_MODE_CONFIG)
@NonNull
public Builder setSafeModeEnabled(boolean enabled) {
mIsSafeModeDisabled = !enabled;
return this;
}
/**
* Builds and validates the VcnGatewayConnectionConfig.
*
* @return an immutable VcnGatewayConnectionConfig instance
*/
@NonNull
public VcnGatewayConnectionConfig build() {
return new VcnGatewayConnectionConfig(
mGatewayConnectionName,
mTunnelConnectionParams,
mExposedCapabilities,
mUnderlyingNetworkTemplates,
mRetryIntervalsMs,
mMaxMtu,
mMinUdpPort4500NatTimeoutSeconds,
mIsSafeModeDisabled,
mGatewayOptions);
}
}
}