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

Commit fb198f87 authored by Xiao Ma's avatar Xiao Ma
Browse files

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

The legacy NUD failure metrics doesn't record provisioning failures due
to multicast resolicits finding that the MAC address has changed, per
current code implemenation, this event will map to NUD_FAILED_ORGANIC,
it's incorrect apparently. Fix this by converting the legacy constants
to NudEventType in strict one-to-one correspondence.

Bug: 162944199
Test: atest NetworkStackTests
Change-Id: I3d8baf4e75a0fb5ff3af87b37cd75d53980e42c2
parent 3f31b636
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;
        }
    }
}