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

Commit a0ec7ccd authored by Xiao Ma's avatar Xiao Ma Committed by Automerger Merge Worker
Browse files

Fix the bug on converting new NUD failure metrics to legacy one. am: fb198f87

Original change: https://android-review.googlesource.com/c/platform/packages/modules/NetworkStack/+/1803421

Change-Id: I39251bceffaa42ed096de61779c8ad2208125e75
parents 9756aebe fb198f87
Loading
Loading
Loading
Loading
+26 −14
Original line number Diff line number Diff line
@@ -156,6 +156,8 @@ public class IpReachabilityMonitor {
    protected static final int NUD_MCAST_RESOLICIT_NUM = 3;
    private static final int INVALID_NUD_MCAST_RESOLICIT_NUM = -1;

    private static final int INVALID_LEGACY_NUD_FAILURE_TYPE = -1;

    public interface Callback {
        /**
         * This callback function must execute as quickly as possible as it is
@@ -448,7 +450,7 @@ public class IpReachabilityMonitor {
                (mLinkProperties.isIpv4Provisioned() && !whatIfLp.isIpv4Provisioned())
                || (mLinkProperties.isIpv6Provisioned() && !whatIfLp.isIpv6Provisioned());
        final NudEventType type = getNudFailureEventType(isFromProbe(),
                isProbedNudFailureDueToRoam(), lostProvisioning);
                isNudFailureDueToRoam(), lostProvisioning);

        if (lostProvisioning) {
            final String logMsg = "FAILURE: LOST_PROVISIONING, " + event;
@@ -577,14 +579,16 @@ public class IpReachabilityMonitor {
        return duration < getProbeWakeLockDuration();
    }

    private boolean isProbedNudFailureDueToRoam() {
    private boolean isNudFailureDueToRoam() {
        if (!isFromProbe()) return false;

        // Check to which probe expiry the curren timestamp gets close when NUD failure event
        // happens, theoretically that indicates which probe event(due to roam or CMD_CONFIRM)
        // was triggered eariler.
        //
        // Note that this would be incorrect if the probe or confirm was so long ago that the
        // probe duration has already expired. That cannot happen because isFromProbe would return
        // false, and this method is only called on NUD failures due to probes.
        // false.
        final long probeExpiryAfterRoam = mLastProbeDueToRoamMs + getProbeWakeLockDuration();
        final long probeExpiryAfterConfirm =
                mLastProbeDueToConfirmMs + getProbeWakeLockDuration();
@@ -599,16 +603,14 @@ public class IpReachabilityMonitor {
    }

    private void logNudFailed(final NeighborEvent event, final NudEventType type) {
        logNeighborLostEvent(event, type);

        // The legacy metrics only record whether the failure came from a probe and whether
        // the network is still provisioned. They do not record provisioning failures due to
        // multicast resolicits finding that the MAC address has changed.
        final boolean lostProvisioning =
                ((type == NudEventType.NUD_POST_ROAMING_FAILED_CRITICAL)
                || (type == NudEventType.NUD_CONFIRM_FAILED_CRITICAL)
                || (type == NudEventType.NUD_ORGANIC_FAILED_CRITICAL));
        final int eventType = nudFailureEventType(isFromProbe(), lostProvisioning);
        final int eventType = legacyNudFailureType(type);
        if (eventType == INVALID_LEGACY_NUD_FAILURE_TYPE) return;
        mMetricsLog.log(mInterfaceParams.name, new IpReachabilityEvent(eventType));
        logNeighborLostEvent(event, type);
    }

    /**
@@ -658,11 +660,21 @@ public class IpReachabilityMonitor {
    /**
     * Returns the NUD failure event type code corresponding to the given conditions.
     */
    private static int nudFailureEventType(boolean isFromProbe, boolean isProvisioningLost) {
        if (isFromProbe) {
            return isProvisioningLost ? PROVISIONING_LOST : NUD_FAILED;
        } else {
            return isProvisioningLost ? PROVISIONING_LOST_ORGANIC : NUD_FAILED_ORGANIC;
    private static int legacyNudFailureType(final NudEventType type) {
        switch (type) {
            case NUD_POST_ROAMING_FAILED:
            case NUD_CONFIRM_FAILED:
                return NUD_FAILED;
            case NUD_POST_ROAMING_FAILED_CRITICAL:
            case NUD_CONFIRM_FAILED_CRITICAL:
                return PROVISIONING_LOST;
            case NUD_ORGANIC_FAILED:
                return NUD_FAILED_ORGANIC;
            case NUD_ORGANIC_FAILED_CRITICAL:
                return PROVISIONING_LOST_ORGANIC;
            default:
                // Do not log legacy event
                return INVALID_LEGACY_NUD_FAILURE_TYPE;
        }
    }
}