Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3402e84c authored by Yan Yan's avatar Yan Yan
Browse files

Re-evaluate IPsec packet loss on LP/NC change

Bug: 323238888
Test: atest FrameworksVcnTests(new tests)
Change-Id: I83f2da42fe0ffed5d4403429e968510c7eeabec1
parent 356e0e16
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -209,6 +209,18 @@ public class IpSecPacketLossDetector extends NetworkMetricMonitor {
        mPollIpSecStateIntervalMs = getPollIpSecStateIntervalMs(carrierConfig);
    }

    @Override
    public void onLinkPropertiesOrCapabilitiesChanged() {
        if (!isStarted()) return;

        reschedulePolling();
    }

    private void reschedulePolling() {
        mHandler.removeCallbacksAndEqualMessages(mCancellationToken);
        mHandler.postDelayed(new PollIpSecStateRunnable(), mCancellationToken, 0L);
    }

    @Override
    protected void start() {
        super.start();
+5 −0
Original line number Diff line number Diff line
@@ -186,6 +186,11 @@ public abstract class NetworkMetricMonitor implements AutoCloseable {
        // Subclasses MUST override it if they care
    }

    /** Called when LinkProperties or NetworkCapabilities have changed */
    public void onLinkPropertiesOrCapabilitiesChanged() {
        // Subclasses MUST override it if they care
    }

    public boolean isValidationFailed() {
        return mIsValidationFailed;
    }
+13 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.net.IpSecTransform;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.vcn.Flags;
import android.net.vcn.VcnManager;
import android.net.vcn.VcnUnderlyingNetworkTemplate;
import android.os.Handler;
@@ -295,6 +296,12 @@ public class UnderlyingNetworkEvaluator {

        updatePriorityClass(
                underlyingNetworkTemplates, subscriptionGroup, lastSnapshot, carrierConfig);

        if (Flags.evaluateIpsecLossOnLpNcChange()) {
            for (NetworkMetricMonitor monitor : mMetricMonitors) {
                monitor.onLinkPropertiesOrCapabilitiesChanged();
            }
        }
    }

    /** Set the LinkProperties */
@@ -308,6 +315,12 @@ public class UnderlyingNetworkEvaluator {

        updatePriorityClass(
                underlyingNetworkTemplates, subscriptionGroup, lastSnapshot, carrierConfig);

        if (Flags.evaluateIpsecLossOnLpNcChange()) {
            for (NetworkMetricMonitor monitor : mMetricMonitors) {
                monitor.onLinkPropertiesOrCapabilitiesChanged();
            }
        }
    }

    /** Set whether the network is blocked */
+28 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@@ -417,4 +418,31 @@ public class IpSecPacketLossDetectorTest extends NetworkEvaluationTestBase {
        checkGetPacketLossRate(oldState, 20000, 14000, 4096, 19);
        checkGetPacketLossRate(oldState, 20000, 14000, 3000, 10);
    }

    // Verify the polling event is scheduled with expected delays
    private void verifyPollEventDelayAndScheduleNext(long expectedDelayMs) {
        if (expectedDelayMs > 0) {
            mTestLooper.dispatchAll();
            verify(mIpSecTransform, never()).requestIpSecTransformState(any(), any());
            mTestLooper.moveTimeForward(expectedDelayMs);
        }

        mTestLooper.dispatchAll();
        verify(mIpSecTransform).requestIpSecTransformState(any(), any());
        reset(mIpSecTransform);
    }

    @Test
    public void testOnLinkPropertiesOrCapabilitiesChange() throws Exception {
        // Start the monitor; verify the 1st poll is scheduled without delay
        startMonitorAndCaptureStateReceiver();
        verifyPollEventDelayAndScheduleNext(0 /* expectedDelayMs */);

        // Verify the 2nd poll is rescheduled without delay
        mIpSecPacketLossDetector.onLinkPropertiesOrCapabilitiesChanged();
        verifyPollEventDelayAndScheduleNext(0 /* expectedDelayMs */);

        // Verify the 3rd poll is scheduled with configured delay
        verifyPollEventDelayAndScheduleNext(POLL_IPSEC_STATE_INTERVAL_MS);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -122,6 +122,7 @@ public abstract class NetworkEvaluationTestBase {
        MockitoAnnotations.initMocks(this);

        mSetFlagsRule.enableFlags(Flags.FLAG_VALIDATE_NETWORK_ON_IPSEC_LOSS);
        mSetFlagsRule.enableFlags(Flags.FLAG_EVALUATE_IPSEC_LOSS_ON_LP_NC_CHANGE);

        when(mNetwork.getNetId()).thenReturn(-1);

Loading