Move the DscpPolicy status constants and IntDef to NetworkAgent.
As requested by API council. Also fix lint errors in the test. Fix: 217366078 Test: existing tests modified in this CL Change-Id: I8f7cd0e78bf29aeb52ec6a08a5d635d25fa2205d
This commit is contained in:
@@ -104,12 +104,6 @@ package android.net {
|
|||||||
field @NonNull public static final android.os.Parcelable.Creator<android.net.DscpPolicy> CREATOR;
|
field @NonNull public static final android.os.Parcelable.Creator<android.net.DscpPolicy> CREATOR;
|
||||||
field public static final int PROTOCOL_ANY = -1; // 0xffffffff
|
field public static final int PROTOCOL_ANY = -1; // 0xffffffff
|
||||||
field public static final int SOURCE_PORT_ANY = -1; // 0xffffffff
|
field public static final int SOURCE_PORT_ANY = -1; // 0xffffffff
|
||||||
field public static final int STATUS_DELETED = 4; // 0x4
|
|
||||||
field public static final int STATUS_INSUFFICIENT_PROCESSING_RESOURCES = 3; // 0x3
|
|
||||||
field public static final int STATUS_POLICY_NOT_FOUND = 5; // 0x5
|
|
||||||
field public static final int STATUS_REQUESTED_CLASSIFIER_NOT_SUPPORTED = 2; // 0x2
|
|
||||||
field public static final int STATUS_REQUEST_DECLINED = 1; // 0x1
|
|
||||||
field public static final int STATUS_SUCCESS = 0; // 0x0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class DscpPolicy.Builder {
|
public static final class DscpPolicy.Builder {
|
||||||
@@ -271,6 +265,12 @@ package android.net {
|
|||||||
method public final void setUnderlyingNetworks(@Nullable java.util.List<android.net.Network>);
|
method public final void setUnderlyingNetworks(@Nullable java.util.List<android.net.Network>);
|
||||||
method public void unregister();
|
method public void unregister();
|
||||||
method public void unregisterAfterReplacement(@IntRange(from=0, to=0x1388) int);
|
method public void unregisterAfterReplacement(@IntRange(from=0, to=0x1388) int);
|
||||||
|
field public static final int DSCP_POLICY_STATUS_DELETED = 4; // 0x4
|
||||||
|
field public static final int DSCP_POLICY_STATUS_INSUFFICIENT_PROCESSING_RESOURCES = 3; // 0x3
|
||||||
|
field public static final int DSCP_POLICY_STATUS_POLICY_NOT_FOUND = 5; // 0x5
|
||||||
|
field public static final int DSCP_POLICY_STATUS_REQUESTED_CLASSIFIER_NOT_SUPPORTED = 2; // 0x2
|
||||||
|
field public static final int DSCP_POLICY_STATUS_REQUEST_DECLINED = 1; // 0x1
|
||||||
|
field public static final int DSCP_POLICY_STATUS_SUCCESS = 0; // 0x0
|
||||||
field public static final int VALIDATION_STATUS_NOT_VALID = 2; // 0x2
|
field public static final int VALIDATION_STATUS_NOT_VALID = 2; // 0x2
|
||||||
field public static final int VALIDATION_STATUS_VALID = 1; // 0x1
|
field public static final int VALIDATION_STATUS_VALID = 1; // 0x1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
import android.annotation.IntDef;
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.annotation.SystemApi;
|
import android.annotation.SystemApi;
|
||||||
@@ -26,8 +25,6 @@ import android.util.Range;
|
|||||||
|
|
||||||
import com.android.net.module.util.InetAddressUtils;
|
import com.android.net.module.util.InetAddressUtils;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -49,36 +46,6 @@ public final class DscpPolicy implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public static final int SOURCE_PORT_ANY = -1;
|
public static final int SOURCE_PORT_ANY = -1;
|
||||||
|
|
||||||
/**
|
|
||||||
* Policy was successfully added.
|
|
||||||
*/
|
|
||||||
public static final int STATUS_SUCCESS = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Policy was rejected for any reason besides invalid classifier or insufficient resources.
|
|
||||||
*/
|
|
||||||
public static final int STATUS_REQUEST_DECLINED = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Requested policy contained a classifier which is not supported.
|
|
||||||
*/
|
|
||||||
public static final int STATUS_REQUESTED_CLASSIFIER_NOT_SUPPORTED = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: should this error case be supported?
|
|
||||||
*/
|
|
||||||
public static final int STATUS_INSUFFICIENT_PROCESSING_RESOURCES = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Policy was deleted.
|
|
||||||
*/
|
|
||||||
public static final int STATUS_DELETED = 4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Policy was not found during deletion.
|
|
||||||
*/
|
|
||||||
public static final int STATUS_POLICY_NOT_FOUND = 5;
|
|
||||||
|
|
||||||
/** The unique policy ID. Each requesting network is responsible for maintaining policy IDs
|
/** The unique policy ID. Each requesting network is responsible for maintaining policy IDs
|
||||||
* unique within that network. In the case where a policy with an existing ID is created, the
|
* unique within that network. In the case where a policy with an existing ID is created, the
|
||||||
* new policy will update the existing policy with the same ID.
|
* new policy will update the existing policy with the same ID.
|
||||||
@@ -112,17 +79,6 @@ public final class DscpPolicy implements Parcelable {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
@IntDef(prefix = "STATUS_", value = {
|
|
||||||
STATUS_SUCCESS,
|
|
||||||
STATUS_REQUEST_DECLINED,
|
|
||||||
STATUS_REQUESTED_CLASSIFIER_NOT_SUPPORTED,
|
|
||||||
STATUS_INSUFFICIENT_PROCESSING_RESOURCES,
|
|
||||||
STATUS_DELETED
|
|
||||||
})
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
|
||||||
public @interface DscpPolicyStatus {}
|
|
||||||
|
|
||||||
/* package */ DscpPolicy(
|
/* package */ DscpPolicy(
|
||||||
int policyId,
|
int policyId,
|
||||||
int dscp,
|
int dscp,
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import android.annotation.SystemApi;
|
|||||||
import android.annotation.TestApi;
|
import android.annotation.TestApi;
|
||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.DscpPolicy.DscpPolicyStatus;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.ConditionVariable;
|
import android.os.ConditionVariable;
|
||||||
@@ -434,6 +433,48 @@ public abstract class NetworkAgent {
|
|||||||
*/
|
*/
|
||||||
public static final int CMD_DSCP_POLICY_STATUS = BASE + 28;
|
public static final int CMD_DSCP_POLICY_STATUS = BASE + 28;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DSCP policy was successfully added.
|
||||||
|
*/
|
||||||
|
public static final int DSCP_POLICY_STATUS_SUCCESS = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DSCP policy was rejected for any reason besides invalid classifier or insufficient resources.
|
||||||
|
*/
|
||||||
|
public static final int DSCP_POLICY_STATUS_REQUEST_DECLINED = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requested DSCP policy contained a classifier which is not supported.
|
||||||
|
*/
|
||||||
|
public static final int DSCP_POLICY_STATUS_REQUESTED_CLASSIFIER_NOT_SUPPORTED = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requested DSCP policy was not added due to insufficient processing resources.
|
||||||
|
*/
|
||||||
|
// TODO: should this error case be supported?
|
||||||
|
public static final int DSCP_POLICY_STATUS_INSUFFICIENT_PROCESSING_RESOURCES = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DSCP policy was deleted.
|
||||||
|
*/
|
||||||
|
public static final int DSCP_POLICY_STATUS_DELETED = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DSCP policy was not found during deletion.
|
||||||
|
*/
|
||||||
|
public static final int DSCP_POLICY_STATUS_POLICY_NOT_FOUND = 5;
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
@IntDef(prefix = "DSCP_POLICY_STATUS_", value = {
|
||||||
|
DSCP_POLICY_STATUS_SUCCESS,
|
||||||
|
DSCP_POLICY_STATUS_REQUEST_DECLINED,
|
||||||
|
DSCP_POLICY_STATUS_REQUESTED_CLASSIFIER_NOT_SUPPORTED,
|
||||||
|
DSCP_POLICY_STATUS_INSUFFICIENT_PROCESSING_RESOURCES,
|
||||||
|
DSCP_POLICY_STATUS_DELETED
|
||||||
|
})
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
public @interface DscpPolicyStatus {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sent by the NetworkAgent to ConnectivityService to notify that this network is expected to be
|
* Sent by the NetworkAgent to ConnectivityService to notify that this network is expected to be
|
||||||
* replaced within the specified time by a similar network.
|
* replaced within the specified time by a similar network.
|
||||||
|
|||||||
@@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
package com.android.server.connectivity;
|
package com.android.server.connectivity;
|
||||||
|
|
||||||
import static android.net.DscpPolicy.STATUS_DELETED;
|
import static android.net.NetworkAgent.DSCP_POLICY_STATUS_DELETED;
|
||||||
import static android.net.DscpPolicy.STATUS_INSUFFICIENT_PROCESSING_RESOURCES;
|
import static android.net.NetworkAgent.DSCP_POLICY_STATUS_INSUFFICIENT_PROCESSING_RESOURCES;
|
||||||
import static android.net.DscpPolicy.STATUS_POLICY_NOT_FOUND;
|
import static android.net.NetworkAgent.DSCP_POLICY_STATUS_POLICY_NOT_FOUND;
|
||||||
import static android.net.DscpPolicy.STATUS_SUCCESS;
|
import static android.net.NetworkAgent.DSCP_POLICY_STATUS_SUCCESS;
|
||||||
import static android.system.OsConstants.ETH_P_ALL;
|
import static android.system.OsConstants.ETH_P_ALL;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
@@ -112,12 +112,12 @@ public class DscpPolicyTracker {
|
|||||||
// the maximum number of policies then return INSUFFICIENT_PROCESSING_RESOURCES.
|
// the maximum number of policies then return INSUFFICIENT_PROCESSING_RESOURCES.
|
||||||
final int existingIndex = mPolicyIdToBpfMapIndex.get(policy.getPolicyId(), -1);
|
final int existingIndex = mPolicyIdToBpfMapIndex.get(policy.getPolicyId(), -1);
|
||||||
if (existingIndex == -1 && mPolicyIdToBpfMapIndex.size() >= MAX_POLICIES) {
|
if (existingIndex == -1 && mPolicyIdToBpfMapIndex.size() >= MAX_POLICIES) {
|
||||||
return STATUS_INSUFFICIENT_PROCESSING_RESOURCES;
|
return DSCP_POLICY_STATUS_INSUFFICIENT_PROCESSING_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently all classifiers are supported, if any are removed return
|
// Currently all classifiers are supported, if any are removed return
|
||||||
// STATUS_REQUESTED_CLASSIFIER_NOT_SUPPORTED,
|
// DSCP_POLICY_STATUS_REQUESTED_CLASSIFIER_NOT_SUPPORTED,
|
||||||
// and for any other generic error STATUS_REQUEST_DECLINED
|
// and for any other generic error DSCP_POLICY_STATUS_REQUEST_DECLINED
|
||||||
|
|
||||||
int addIndex = 0;
|
int addIndex = 0;
|
||||||
// If a policy with a matching ID exists, replace it, otherwise use the next free
|
// If a policy with a matching ID exists, replace it, otherwise use the next free
|
||||||
@@ -154,24 +154,25 @@ public class DscpPolicyTracker {
|
|||||||
}
|
}
|
||||||
} catch (ErrnoException e) {
|
} catch (ErrnoException e) {
|
||||||
Log.e(TAG, "Failed to insert policy into map: ", e);
|
Log.e(TAG, "Failed to insert policy into map: ", e);
|
||||||
return STATUS_INSUFFICIENT_PROCESSING_RESOURCES;
|
return DSCP_POLICY_STATUS_INSUFFICIENT_PROCESSING_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return DSCP_POLICY_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the provided DSCP policy to the bpf map. Attach bpf program dscp_policy to iface
|
* Add the provided DSCP policy to the bpf map. Attach bpf program dscp_policy to iface
|
||||||
* if not already attached. Response will be sent back to nai with status.
|
* if not already attached. Response will be sent back to nai with status.
|
||||||
*
|
*
|
||||||
* STATUS_SUCCESS - if policy was added successfully
|
* DSCP_POLICY_STATUS_SUCCESS - if policy was added successfully
|
||||||
* STATUS_INSUFFICIENT_PROCESSING_RESOURCES - if max policies were already set
|
* DSCP_POLICY_STATUS_INSUFFICIENT_PROCESSING_RESOURCES - if max policies were already set
|
||||||
*/
|
*/
|
||||||
public void addDscpPolicy(NetworkAgentInfo nai, DscpPolicy policy) {
|
public void addDscpPolicy(NetworkAgentInfo nai, DscpPolicy policy) {
|
||||||
if (!mAttachedIfaces.contains(nai.linkProperties.getInterfaceName())) {
|
if (!mAttachedIfaces.contains(nai.linkProperties.getInterfaceName())) {
|
||||||
if (!attachProgram(nai.linkProperties.getInterfaceName())) {
|
if (!attachProgram(nai.linkProperties.getInterfaceName())) {
|
||||||
Log.e(TAG, "Unable to attach program");
|
Log.e(TAG, "Unable to attach program");
|
||||||
sendStatus(nai, policy.getPolicyId(), STATUS_INSUFFICIENT_PROCESSING_RESOURCES);
|
sendStatus(nai, policy.getPolicyId(),
|
||||||
|
DSCP_POLICY_STATUS_INSUFFICIENT_PROCESSING_RESOURCES);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,11 +182,11 @@ public class DscpPolicyTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void removePolicyFromMap(NetworkAgentInfo nai, int policyId, int index) {
|
private void removePolicyFromMap(NetworkAgentInfo nai, int policyId, int index) {
|
||||||
int status = STATUS_POLICY_NOT_FOUND;
|
int status = DSCP_POLICY_STATUS_POLICY_NOT_FOUND;
|
||||||
try {
|
try {
|
||||||
mBpfDscpIpv4Policies.replaceEntry(new Struct.U32(index), DscpPolicyValue.NONE);
|
mBpfDscpIpv4Policies.replaceEntry(new Struct.U32(index), DscpPolicyValue.NONE);
|
||||||
mBpfDscpIpv6Policies.replaceEntry(new Struct.U32(index), DscpPolicyValue.NONE);
|
mBpfDscpIpv6Policies.replaceEntry(new Struct.U32(index), DscpPolicyValue.NONE);
|
||||||
status = STATUS_DELETED;
|
status = DSCP_POLICY_STATUS_DELETED;
|
||||||
} catch (ErrnoException e) {
|
} catch (ErrnoException e) {
|
||||||
Log.e(TAG, "Failed to delete policy from map: ", e);
|
Log.e(TAG, "Failed to delete policy from map: ", e);
|
||||||
}
|
}
|
||||||
@@ -199,7 +200,7 @@ public class DscpPolicyTracker {
|
|||||||
public void removeDscpPolicy(NetworkAgentInfo nai, int policyId) {
|
public void removeDscpPolicy(NetworkAgentInfo nai, int policyId) {
|
||||||
if (!mAttachedIfaces.contains(nai.linkProperties.getInterfaceName())) {
|
if (!mAttachedIfaces.contains(nai.linkProperties.getInterfaceName())) {
|
||||||
// Nothing to remove since program is not attached. Send update back for policy id.
|
// Nothing to remove since program is not attached. Send update back for policy id.
|
||||||
sendStatus(nai, policyId, STATUS_POLICY_NOT_FOUND);
|
sendStatus(nai, policyId, DSCP_POLICY_STATUS_POLICY_NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +223,7 @@ public class DscpPolicyTracker {
|
|||||||
if (!mAttachedIfaces.contains(nai.linkProperties.getInterfaceName())) {
|
if (!mAttachedIfaces.contains(nai.linkProperties.getInterfaceName())) {
|
||||||
// Nothing to remove since program is not attached. Send update for policy
|
// Nothing to remove since program is not attached. Send update for policy
|
||||||
// id 0. The status update must contain a policy ID, and 0 is an invalid id.
|
// id 0. The status update must contain a policy ID, and 0 is an invalid id.
|
||||||
sendStatus(nai, 0, STATUS_SUCCESS);
|
sendStatus(nai, 0, DSCP_POLICY_STATUS_SUCCESS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,15 +22,14 @@ import android.app.Instrumentation
|
|||||||
import android.Manifest.permission.MANAGE_TEST_NETWORKS
|
import android.Manifest.permission.MANAGE_TEST_NETWORKS
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.cts.util.CtsNetUtils
|
|
||||||
import android.net.DscpPolicy
|
import android.net.DscpPolicy
|
||||||
import android.net.DscpPolicy.STATUS_DELETED
|
|
||||||
import android.net.DscpPolicy.STATUS_SUCCESS
|
|
||||||
import android.net.InetAddresses
|
import android.net.InetAddresses
|
||||||
import android.net.IpPrefix
|
import android.net.IpPrefix
|
||||||
import android.net.LinkAddress
|
import android.net.LinkAddress
|
||||||
import android.net.LinkProperties
|
import android.net.LinkProperties
|
||||||
import android.net.NetworkAgent
|
import android.net.NetworkAgent
|
||||||
|
import android.net.NetworkAgent.DSCP_POLICY_STATUS_DELETED
|
||||||
|
import android.net.NetworkAgent.DSCP_POLICY_STATUS_SUCCESS
|
||||||
import android.net.NetworkAgentConfig
|
import android.net.NetworkAgentConfig
|
||||||
import android.net.NetworkCapabilities
|
import android.net.NetworkCapabilities
|
||||||
import android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET
|
import android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET
|
||||||
@@ -45,26 +44,18 @@ import android.net.NetworkRequest
|
|||||||
import android.net.TestNetworkInterface
|
import android.net.TestNetworkInterface
|
||||||
import android.net.TestNetworkManager
|
import android.net.TestNetworkManager
|
||||||
import android.net.RouteInfo
|
import android.net.RouteInfo
|
||||||
import android.net.util.SocketUtils
|
|
||||||
import android.os.Build
|
|
||||||
import android.os.HandlerThread
|
import android.os.HandlerThread
|
||||||
import android.os.Looper
|
|
||||||
import android.platform.test.annotations.AppModeFull
|
import android.platform.test.annotations.AppModeFull
|
||||||
import android.system.Os
|
import android.system.Os
|
||||||
import android.system.OsConstants
|
|
||||||
import android.system.OsConstants.AF_INET
|
import android.system.OsConstants.AF_INET
|
||||||
import android.system.OsConstants.IPPROTO_IP
|
|
||||||
import android.system.OsConstants.IPPROTO_UDP
|
import android.system.OsConstants.IPPROTO_UDP
|
||||||
import android.system.OsConstants.SOCK_DGRAM
|
import android.system.OsConstants.SOCK_DGRAM
|
||||||
import android.system.OsConstants.SOCK_NONBLOCK
|
import android.system.OsConstants.SOCK_NONBLOCK
|
||||||
import android.util.Log
|
|
||||||
import android.util.Range
|
import android.util.Range
|
||||||
import androidx.test.InstrumentationRegistry
|
import androidx.test.InstrumentationRegistry
|
||||||
import androidx.test.runner.AndroidJUnit4
|
import androidx.test.runner.AndroidJUnit4
|
||||||
import com.android.modules.utils.build.SdkLevel
|
|
||||||
import com.android.testutils.CompatUtil
|
import com.android.testutils.CompatUtil
|
||||||
import com.android.testutils.DevSdkIgnoreRule
|
import com.android.testutils.DevSdkIgnoreRule
|
||||||
import com.android.testutils.OffsetFilter
|
|
||||||
import com.android.testutils.assertParcelingIsLossless
|
import com.android.testutils.assertParcelingIsLossless
|
||||||
import com.android.testutils.runAsShell
|
import com.android.testutils.runAsShell
|
||||||
import com.android.testutils.SC_V2
|
import com.android.testutils.SC_V2
|
||||||
@@ -74,26 +65,18 @@ import com.android.testutils.TestableNetworkAgent.CallbackEntry.OnNetworkCreated
|
|||||||
import com.android.testutils.TestableNetworkAgent.CallbackEntry.OnDscpPolicyStatusUpdated
|
import com.android.testutils.TestableNetworkAgent.CallbackEntry.OnDscpPolicyStatusUpdated
|
||||||
import com.android.testutils.TestableNetworkCallback
|
import com.android.testutils.TestableNetworkCallback
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.AfterClass
|
|
||||||
import org.junit.Assume.assumeTrue
|
import org.junit.Assume.assumeTrue
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.BeforeClass
|
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import java.net.Inet4Address
|
import java.net.Inet4Address
|
||||||
import java.net.Inet6Address
|
|
||||||
import java.net.InetAddress
|
|
||||||
import java.net.InetSocketAddress
|
|
||||||
import java.net.ServerSocket
|
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
import java.nio.ByteOrder
|
import java.nio.ByteOrder
|
||||||
import java.util.UUID
|
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNotNull
|
import kotlin.test.assertNotNull
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
import kotlin.concurrent.thread
|
|
||||||
import kotlin.test.fail
|
import kotlin.test.fail
|
||||||
|
|
||||||
private const val MAX_PACKET_LENGTH = 1500
|
private const val MAX_PACKET_LENGTH = 1500
|
||||||
@@ -191,7 +174,7 @@ class DscpPolicyTest {
|
|||||||
|
|
||||||
private fun createConnectedNetworkAgent(
|
private fun createConnectedNetworkAgent(
|
||||||
context: Context = realContext,
|
context: Context = realContext,
|
||||||
specifier: String? = iface.getInterfaceName(),
|
specifier: String? = iface.getInterfaceName()
|
||||||
): Pair<TestableNetworkAgent, TestableNetworkCallback> {
|
): Pair<TestableNetworkAgent, TestableNetworkCallback> {
|
||||||
val callback = TestableNetworkCallback()
|
val callback = TestableNetworkCallback()
|
||||||
// Ensure this NetworkAgent is never unneeded by filing a request with its specifier.
|
// Ensure this NetworkAgent is never unneeded by filing a request with its specifier.
|
||||||
@@ -236,7 +219,7 @@ class DscpPolicyTest {
|
|||||||
agent: TestableNetworkAgent,
|
agent: TestableNetworkAgent,
|
||||||
callback: TestableNetworkCallback,
|
callback: TestableNetworkCallback,
|
||||||
dscpValue: Int = 0,
|
dscpValue: Int = 0,
|
||||||
dstPort : Int = 0,
|
dstPort: Int = 0
|
||||||
) {
|
) {
|
||||||
val testString = "test string"
|
val testString = "test string"
|
||||||
val testPacket = ByteBuffer.wrap(testString.toByteArray(Charsets.UTF_8))
|
val testPacket = ByteBuffer.wrap(testString.toByteArray(Charsets.UTF_8))
|
||||||
@@ -263,9 +246,9 @@ class DscpPolicyTest {
|
|||||||
|
|
||||||
val ipAddr = ByteArray(4)
|
val ipAddr = ByteArray(4)
|
||||||
buffer.get(ipAddr)
|
buffer.get(ipAddr)
|
||||||
val srcIp = Inet4Address.getByAddress(ipAddr);
|
val srcIp = Inet4Address.getByAddress(ipAddr)
|
||||||
buffer.get(ipAddr)
|
buffer.get(ipAddr)
|
||||||
val dstIp = Inet4Address.getByAddress(ipAddr);
|
val dstIp = Inet4Address.getByAddress(ipAddr)
|
||||||
val packetSrcPort = buffer.getShort().toInt()
|
val packetSrcPort = buffer.getShort().toInt()
|
||||||
val packetDstPort = buffer.getShort().toInt()
|
val packetDstPort = buffer.getShort().toInt()
|
||||||
|
|
||||||
@@ -288,7 +271,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendRemoveDscpPolicy(policyId)
|
agent.sendRemoveDscpPolicy(policyId)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(policyId, it.policyId)
|
assertEquals(policyId, it.policyId)
|
||||||
assertEquals(STATUS_DELETED, it.status)
|
assertEquals(DSCP_POLICY_STATUS_DELETED, it.status)
|
||||||
checkDscpValue(agent, callback, dstPort = portNumber)
|
checkDscpValue(agent, callback, dstPort = portNumber)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -300,7 +283,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy)
|
agent.sendAddDscpPolicy(policy)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(1, it.policyId)
|
assertEquals(1, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
}
|
}
|
||||||
|
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 4444)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 4444)
|
||||||
@@ -308,7 +291,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendRemoveDscpPolicy(1)
|
agent.sendRemoveDscpPolicy(1)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(1, it.policyId)
|
assertEquals(1, it.policyId)
|
||||||
assertEquals(STATUS_DELETED, it.status)
|
assertEquals(DSCP_POLICY_STATUS_DELETED, it.status)
|
||||||
}
|
}
|
||||||
|
|
||||||
val policy2 = DscpPolicy.Builder(1, 4)
|
val policy2 = DscpPolicy.Builder(1, 4)
|
||||||
@@ -317,7 +300,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy2)
|
agent.sendAddDscpPolicy(policy2)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(1, it.policyId)
|
assertEquals(1, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
}
|
}
|
||||||
|
|
||||||
checkDscpValue(agent, callback, dscpValue = 4, dstPort = 5555)
|
checkDscpValue(agent, callback, dscpValue = 4, dstPort = 5555)
|
||||||
@@ -325,7 +308,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendRemoveDscpPolicy(1)
|
agent.sendRemoveDscpPolicy(1)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(1, it.policyId)
|
assertEquals(1, it.policyId)
|
||||||
assertEquals(STATUS_DELETED, it.status)
|
assertEquals(DSCP_POLICY_STATUS_DELETED, it.status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,7 +320,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy)
|
agent.sendAddDscpPolicy(policy)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(1, it.policyId)
|
assertEquals(1, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 1111)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 1111)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,7 +328,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy2)
|
agent.sendAddDscpPolicy(policy2)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(2, it.policyId)
|
assertEquals(2, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 2222)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 2222)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +336,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy3)
|
agent.sendAddDscpPolicy(policy3)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(3, it.policyId)
|
assertEquals(3, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 3333)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 3333)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,7 +353,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy)
|
agent.sendAddDscpPolicy(policy)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(1, it.policyId)
|
assertEquals(1, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 1111)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 1111)
|
||||||
}
|
}
|
||||||
doRemovePolicyTest(agent, callback, 1)
|
doRemovePolicyTest(agent, callback, 1)
|
||||||
@@ -379,7 +362,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy2)
|
agent.sendAddDscpPolicy(policy2)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(2, it.policyId)
|
assertEquals(2, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 2222)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 2222)
|
||||||
}
|
}
|
||||||
doRemovePolicyTest(agent, callback, 2)
|
doRemovePolicyTest(agent, callback, 2)
|
||||||
@@ -388,7 +371,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy3)
|
agent.sendAddDscpPolicy(policy3)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(3, it.policyId)
|
assertEquals(3, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 3333)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 3333)
|
||||||
}
|
}
|
||||||
doRemovePolicyTest(agent, callback, 3)
|
doRemovePolicyTest(agent, callback, 3)
|
||||||
@@ -402,7 +385,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy)
|
agent.sendAddDscpPolicy(policy)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(1, it.policyId)
|
assertEquals(1, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 1111)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 1111)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,7 +393,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy2)
|
agent.sendAddDscpPolicy(policy2)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(2, it.policyId)
|
assertEquals(2, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 2222)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 2222)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -418,7 +401,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy3)
|
agent.sendAddDscpPolicy(policy3)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(3, it.policyId)
|
assertEquals(3, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 3333)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 3333)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,7 +416,7 @@ class DscpPolicyTest {
|
|||||||
(agent, callback) ->
|
(agent, callback) ->
|
||||||
agent.sendRemoveDscpPolicy(3)
|
agent.sendRemoveDscpPolicy(3)
|
||||||
// Is there something to add in TestableNetworkCallback to NOT expect a callback?
|
// Is there something to add in TestableNetworkCallback to NOT expect a callback?
|
||||||
// Or should we send STATUS_DELETED in any case or a different STATUS?
|
// Or should we send DSCP_POLICY_STATUS_DELETED in any case or a different STATUS?
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -443,7 +426,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy)
|
agent.sendAddDscpPolicy(policy)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(1, it.policyId)
|
assertEquals(1, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 1111)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 1111)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,7 +435,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy2)
|
agent.sendAddDscpPolicy(policy2)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(2, it.policyId)
|
assertEquals(2, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 2222)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 2222)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,24 +444,24 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy3)
|
agent.sendAddDscpPolicy(policy3)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(3, it.policyId)
|
assertEquals(3, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 3333)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 3333)
|
||||||
}
|
}
|
||||||
|
|
||||||
agent.sendRemoveAllDscpPolicies()
|
agent.sendRemoveAllDscpPolicies()
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(1, it.policyId)
|
assertEquals(1, it.policyId)
|
||||||
assertEquals(STATUS_DELETED, it.status)
|
assertEquals(DSCP_POLICY_STATUS_DELETED, it.status)
|
||||||
checkDscpValue(agent, callback, dstPort = 1111)
|
checkDscpValue(agent, callback, dstPort = 1111)
|
||||||
}
|
}
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(2, it.policyId)
|
assertEquals(2, it.policyId)
|
||||||
assertEquals(STATUS_DELETED, it.status)
|
assertEquals(DSCP_POLICY_STATUS_DELETED, it.status)
|
||||||
checkDscpValue(agent, callback, dstPort = 2222)
|
checkDscpValue(agent, callback, dstPort = 2222)
|
||||||
}
|
}
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(3, it.policyId)
|
assertEquals(3, it.policyId)
|
||||||
assertEquals(STATUS_DELETED, it.status)
|
assertEquals(DSCP_POLICY_STATUS_DELETED, it.status)
|
||||||
checkDscpValue(agent, callback, dstPort = 3333)
|
checkDscpValue(agent, callback, dstPort = 3333)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -490,7 +473,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy)
|
agent.sendAddDscpPolicy(policy)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(1, it.policyId)
|
assertEquals(1, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 4444)
|
checkDscpValue(agent, callback, dscpValue = 1, dstPort = 4444)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,7 +484,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendAddDscpPolicy(policy2)
|
agent.sendAddDscpPolicy(policy2)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(1, it.policyId)
|
assertEquals(1, it.policyId)
|
||||||
assertEquals(STATUS_SUCCESS, it.status)
|
assertEquals(DSCP_POLICY_STATUS_SUCCESS, it.status)
|
||||||
|
|
||||||
// Sending packet with old policy should fail
|
// Sending packet with old policy should fail
|
||||||
checkDscpValue(agent, callback, dstPort = 4444)
|
checkDscpValue(agent, callback, dstPort = 4444)
|
||||||
@@ -511,7 +494,7 @@ class DscpPolicyTest {
|
|||||||
agent.sendRemoveDscpPolicy(1)
|
agent.sendRemoveDscpPolicy(1)
|
||||||
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
agent.expectCallback<OnDscpPolicyStatusUpdated>().let {
|
||||||
assertEquals(1, it.policyId)
|
assertEquals(1, it.policyId)
|
||||||
assertEquals(STATUS_DELETED, it.status)
|
assertEquals(DSCP_POLICY_STATUS_DELETED, it.status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,14 +503,14 @@ class DscpPolicyTest {
|
|||||||
(agent, callback) ->
|
(agent, callback) ->
|
||||||
// Check that policy with partial parameters is lossless.
|
// Check that policy with partial parameters is lossless.
|
||||||
val policy = DscpPolicy.Builder(1, 1).setDestinationPortRange(Range(4444, 4444)).build()
|
val policy = DscpPolicy.Builder(1, 1).setDestinationPortRange(Range(4444, 4444)).build()
|
||||||
assertParcelingIsLossless(policy);
|
assertParcelingIsLossless(policy)
|
||||||
|
|
||||||
// Check that policy with all parameters is lossless.
|
// Check that policy with all parameters is lossless.
|
||||||
val policy2 = DscpPolicy.Builder(1, 1).setDestinationPortRange(Range(4444, 4444))
|
val policy2 = DscpPolicy.Builder(1, 1).setDestinationPortRange(Range(4444, 4444))
|
||||||
.setSourceAddress(LOCAL_IPV4_ADDRESS)
|
.setSourceAddress(LOCAL_IPV4_ADDRESS)
|
||||||
.setDestinationAddress(TEST_TARGET_IPV4_ADDR)
|
.setDestinationAddress(TEST_TARGET_IPV4_ADDR)
|
||||||
.setProtocol(IPPROTO_UDP).build()
|
.setProtocol(IPPROTO_UDP).build()
|
||||||
assertParcelingIsLossless(policy2);
|
assertParcelingIsLossless(policy2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user