Loading core/java/android/net/vcn/flags.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -46,3 +46,13 @@ flag{ purpose: PURPOSE_BUGFIX } } flag{ name: "allow_disable_ipsec_loss_detector" namespace: "vcn" description: "Allow disabling IPsec packet loss detector" bug: "336638836" metadata { purpose: PURPOSE_BUGFIX } } No newline at end of file services/core/java/com/android/server/vcn/routeselection/IpSecPacketLossDetector.java +22 −1 Original line number Diff line number Diff line Loading @@ -115,6 +115,10 @@ public class IpSecPacketLossDetector extends NetworkMetricMonitor { // validation failure. private static final int IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_DEFAULT = 12; /** Carriers can disable the detector by setting the threshold to -1 */ @VisibleForTesting(visibility = Visibility.PRIVATE) static final int IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_DISABLE_DETECTOR = -1; private static final int POLL_IPSEC_STATE_INTERVAL_SECONDS_DEFAULT = 20; // By default, there's no maximum limit enforced Loading Loading @@ -271,8 +275,11 @@ public class IpSecPacketLossDetector extends NetworkMetricMonitor { // When multiple parallel inbound transforms are created, NetworkMetricMonitor will be // enabled on the last one as a sample mInboundTransform = inboundTransform; if (!Flags.allowDisableIpsecLossDetector() || canStart()) { start(); } } @Override public void setCarrierConfig(@Nullable PersistableBundleWrapper carrierConfig) { Loading @@ -284,6 +291,14 @@ public class IpSecPacketLossDetector extends NetworkMetricMonitor { mPacketLossRatePercentThreshold = getPacketLossRatePercentThreshold(carrierConfig); mMaxSeqNumIncreasePerSecond = getMaxSeqNumIncreasePerSecond(carrierConfig); } if (Flags.allowDisableIpsecLossDetector() && canStart() != isStarted()) { if (canStart()) { start(); } else { stop(); } } } @Override Loading @@ -298,6 +313,12 @@ public class IpSecPacketLossDetector extends NetworkMetricMonitor { mHandler.postDelayed(new PollIpSecStateRunnable(), mCancellationToken, 0L); } private boolean canStart() { return mInboundTransform != null && mPacketLossRatePercentThreshold != IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_DISABLE_DETECTOR; } @Override protected void start() { super.start(); Loading tests/vcn/java/com/android/server/vcn/routeselection/IpSecPacketLossDetectorTest.java +53 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static android.net.vcn.VcnManager.VCN_NETWORK_SELECTION_IPSEC_PACKET_LOSS import static android.net.vcn.VcnManager.VCN_NETWORK_SELECTION_MAX_SEQ_NUM_INCREASE_PER_SECOND_KEY; import static android.net.vcn.VcnManager.VCN_NETWORK_SELECTION_POLL_IPSEC_STATE_INTERVAL_SECONDS_KEY; import static com.android.server.vcn.routeselection.IpSecPacketLossDetector.IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_DISABLE_DETECTOR; import static com.android.server.vcn.routeselection.IpSecPacketLossDetector.MIN_VALID_EXPECTED_RX_PACKET_NUM; import static com.android.server.vcn.routeselection.IpSecPacketLossDetector.getMaxSeqNumIncreasePerSecond; import static com.android.server.vcn.util.PersistableBundleUtils.PersistableBundleWrapper; Loading Loading @@ -584,4 +585,56 @@ public class IpSecPacketLossDetectorTest extends NetworkEvaluationTestBase { MAX_SEQ_NUM_INCREASE_DEFAULT_DISABLED, getMaxSeqNumIncreasePerSecond(mCarrierConfig)); } private IpSecPacketLossDetector newDetectorAndSetTransform(int threshold) throws Exception { when(mCarrierConfig.getInt( eq(VCN_NETWORK_SELECTION_IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_KEY), anyInt())) .thenReturn(threshold); final IpSecPacketLossDetector detector = new IpSecPacketLossDetector( mVcnContext, mNetwork, mCarrierConfig, mMetricMonitorCallback, mDependencies); detector.setIsSelectedUnderlyingNetwork(true /* setIsSelected */); detector.setInboundTransformInternal(mIpSecTransform); return detector; } @Test public void testDisableAndEnableDetectorWithCarrierConfig() throws Exception { final IpSecPacketLossDetector detector = newDetectorAndSetTransform(IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_DISABLE_DETECTOR); assertFalse(detector.isStarted()); when(mCarrierConfig.getInt( eq(VCN_NETWORK_SELECTION_IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_KEY), anyInt())) .thenReturn(IPSEC_PACKET_LOSS_PERCENT_THRESHOLD); detector.setCarrierConfig(mCarrierConfig); assertTrue(detector.isStarted()); } @Test public void testEnableAndDisableDetectorWithCarrierConfig() throws Exception { final IpSecPacketLossDetector detector = newDetectorAndSetTransform(IPSEC_PACKET_LOSS_PERCENT_THRESHOLD); assertTrue(detector.isStarted()); when(mCarrierConfig.getInt( eq(VCN_NETWORK_SELECTION_IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_KEY), anyInt())) .thenReturn(IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_DISABLE_DETECTOR); detector.setCarrierConfig(mCarrierConfig); assertFalse(detector.isStarted()); } } tests/vcn/java/com/android/server/vcn/routeselection/NetworkEvaluationTestBase.java +1 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,7 @@ public abstract class NetworkEvaluationTestBase { mSetFlagsRule.enableFlags(Flags.FLAG_VALIDATE_NETWORK_ON_IPSEC_LOSS); mSetFlagsRule.enableFlags(Flags.FLAG_EVALUATE_IPSEC_LOSS_ON_LP_NC_CHANGE); mSetFlagsRule.enableFlags(Flags.FLAG_HANDLE_SEQ_NUM_LEAP); mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_DISABLE_IPSEC_LOSS_DETECTOR); when(mNetwork.getNetId()).thenReturn(-1); Loading Loading
core/java/android/net/vcn/flags.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -46,3 +46,13 @@ flag{ purpose: PURPOSE_BUGFIX } } flag{ name: "allow_disable_ipsec_loss_detector" namespace: "vcn" description: "Allow disabling IPsec packet loss detector" bug: "336638836" metadata { purpose: PURPOSE_BUGFIX } } No newline at end of file
services/core/java/com/android/server/vcn/routeselection/IpSecPacketLossDetector.java +22 −1 Original line number Diff line number Diff line Loading @@ -115,6 +115,10 @@ public class IpSecPacketLossDetector extends NetworkMetricMonitor { // validation failure. private static final int IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_DEFAULT = 12; /** Carriers can disable the detector by setting the threshold to -1 */ @VisibleForTesting(visibility = Visibility.PRIVATE) static final int IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_DISABLE_DETECTOR = -1; private static final int POLL_IPSEC_STATE_INTERVAL_SECONDS_DEFAULT = 20; // By default, there's no maximum limit enforced Loading Loading @@ -271,8 +275,11 @@ public class IpSecPacketLossDetector extends NetworkMetricMonitor { // When multiple parallel inbound transforms are created, NetworkMetricMonitor will be // enabled on the last one as a sample mInboundTransform = inboundTransform; if (!Flags.allowDisableIpsecLossDetector() || canStart()) { start(); } } @Override public void setCarrierConfig(@Nullable PersistableBundleWrapper carrierConfig) { Loading @@ -284,6 +291,14 @@ public class IpSecPacketLossDetector extends NetworkMetricMonitor { mPacketLossRatePercentThreshold = getPacketLossRatePercentThreshold(carrierConfig); mMaxSeqNumIncreasePerSecond = getMaxSeqNumIncreasePerSecond(carrierConfig); } if (Flags.allowDisableIpsecLossDetector() && canStart() != isStarted()) { if (canStart()) { start(); } else { stop(); } } } @Override Loading @@ -298,6 +313,12 @@ public class IpSecPacketLossDetector extends NetworkMetricMonitor { mHandler.postDelayed(new PollIpSecStateRunnable(), mCancellationToken, 0L); } private boolean canStart() { return mInboundTransform != null && mPacketLossRatePercentThreshold != IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_DISABLE_DETECTOR; } @Override protected void start() { super.start(); Loading
tests/vcn/java/com/android/server/vcn/routeselection/IpSecPacketLossDetectorTest.java +53 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static android.net.vcn.VcnManager.VCN_NETWORK_SELECTION_IPSEC_PACKET_LOSS import static android.net.vcn.VcnManager.VCN_NETWORK_SELECTION_MAX_SEQ_NUM_INCREASE_PER_SECOND_KEY; import static android.net.vcn.VcnManager.VCN_NETWORK_SELECTION_POLL_IPSEC_STATE_INTERVAL_SECONDS_KEY; import static com.android.server.vcn.routeselection.IpSecPacketLossDetector.IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_DISABLE_DETECTOR; import static com.android.server.vcn.routeselection.IpSecPacketLossDetector.MIN_VALID_EXPECTED_RX_PACKET_NUM; import static com.android.server.vcn.routeselection.IpSecPacketLossDetector.getMaxSeqNumIncreasePerSecond; import static com.android.server.vcn.util.PersistableBundleUtils.PersistableBundleWrapper; Loading Loading @@ -584,4 +585,56 @@ public class IpSecPacketLossDetectorTest extends NetworkEvaluationTestBase { MAX_SEQ_NUM_INCREASE_DEFAULT_DISABLED, getMaxSeqNumIncreasePerSecond(mCarrierConfig)); } private IpSecPacketLossDetector newDetectorAndSetTransform(int threshold) throws Exception { when(mCarrierConfig.getInt( eq(VCN_NETWORK_SELECTION_IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_KEY), anyInt())) .thenReturn(threshold); final IpSecPacketLossDetector detector = new IpSecPacketLossDetector( mVcnContext, mNetwork, mCarrierConfig, mMetricMonitorCallback, mDependencies); detector.setIsSelectedUnderlyingNetwork(true /* setIsSelected */); detector.setInboundTransformInternal(mIpSecTransform); return detector; } @Test public void testDisableAndEnableDetectorWithCarrierConfig() throws Exception { final IpSecPacketLossDetector detector = newDetectorAndSetTransform(IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_DISABLE_DETECTOR); assertFalse(detector.isStarted()); when(mCarrierConfig.getInt( eq(VCN_NETWORK_SELECTION_IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_KEY), anyInt())) .thenReturn(IPSEC_PACKET_LOSS_PERCENT_THRESHOLD); detector.setCarrierConfig(mCarrierConfig); assertTrue(detector.isStarted()); } @Test public void testEnableAndDisableDetectorWithCarrierConfig() throws Exception { final IpSecPacketLossDetector detector = newDetectorAndSetTransform(IPSEC_PACKET_LOSS_PERCENT_THRESHOLD); assertTrue(detector.isStarted()); when(mCarrierConfig.getInt( eq(VCN_NETWORK_SELECTION_IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_KEY), anyInt())) .thenReturn(IPSEC_PACKET_LOSS_PERCENT_THRESHOLD_DISABLE_DETECTOR); detector.setCarrierConfig(mCarrierConfig); assertFalse(detector.isStarted()); } }
tests/vcn/java/com/android/server/vcn/routeselection/NetworkEvaluationTestBase.java +1 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,7 @@ public abstract class NetworkEvaluationTestBase { mSetFlagsRule.enableFlags(Flags.FLAG_VALIDATE_NETWORK_ON_IPSEC_LOSS); mSetFlagsRule.enableFlags(Flags.FLAG_EVALUATE_IPSEC_LOSS_ON_LP_NC_CHANGE); mSetFlagsRule.enableFlags(Flags.FLAG_HANDLE_SEQ_NUM_LEAP); mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_DISABLE_IPSEC_LOSS_DETECTOR); when(mNetwork.getNetId()).thenReturn(-1); Loading