/* * 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 com.android.internal.annotations.VisibleForTesting.Visibility; 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.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: * *
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)
};
private static final String GATEWAY_CONNECTION_NAME_KEY = "mGatewayConnectionName";
@NonNull private final String mGatewayConnectionName;
private static final String TUNNEL_CONNECTION_PARAMS_KEY = "mTunnelConnectionParams";
@NonNull private IkeTunnelConnectionParams mTunnelConnectionParams;
private static final String EXPOSED_CAPABILITIES_KEY = "mExposedCapabilities";
@NonNull private final SortedSet 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 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;
}
/**
* Builds and validates the VcnGatewayConnectionConfig.
*
* @return an immutable VcnGatewayConnectionConfig instance
*/
@NonNull
public VcnGatewayConnectionConfig build() {
return new VcnGatewayConnectionConfig(
mGatewayConnectionName,
mTunnelConnectionParams,
mExposedCapabilities,
mRetryIntervalsMs,
mMaxMtu);
}
}
}