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

Commit 219d9ba4 authored by Hugo Benichi's avatar Hugo Benichi Committed by android-build-merger
Browse files

Merge \\"IpConn metrics: distinguish NUD_FAILED answers\\" into nyc-mr1-dev am: 42e60852

am: 99b36c8b

Change-Id: Iade155a1941674edf642e99bd506d1676b67ab42
parents d1349217 99b36c8b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public final class ApfProgramEvent implements Parcelable {
        for (int bit = set.nextSetBit(0); bit >= 0; bit = set.nextSetBit(bit+1)) {
            names.add(Decoder.constants.get(bit));
        }
        return TextUtils.join(", ", names);
        return TextUtils.join("|", names);
    }

    final static class Decoder {
+32 −6
Original line number Diff line number Diff line
@@ -24,21 +24,31 @@ import android.util.SparseArray;
import com.android.internal.util.MessageUtils;

/**
 * An event recorded when IpReachabilityMonitor sends a neighbor probe or receives
 * a neighbor probe result.
 * {@hide}
 */
@SystemApi
public final class IpReachabilityEvent implements Parcelable {

    // Event types.
    /** A probe forced by IpReachabilityMonitor. */
    public static final int PROBE                     = 1 << 8;
    /** Neighbor unreachable after a forced probe. */
    public static final int NUD_FAILED                = 2 << 8;
    /** Neighbor unreachable after a forced probe, IP provisioning is also lost. */
    public static final int PROVISIONING_LOST         = 3 << 8;
    /** {@hide} Neighbor unreachable notification from kernel. */
    public static final int NUD_FAILED_ORGANIC        = 4 << 8;
    /** {@hide} Neighbor unreachable notification from kernel, IP provisioning is also lost. */
    public static final int PROVISIONING_LOST_ORGANIC = 5 << 8;

    public final String ifName;
    // eventType byte format (MSB to LSB):
    // byte 0: unused
    // byte 1: unused
    // byte 2: type of event: PROBE, NUD_FAILED, PROVISIONING_LOST
    // byte 3: kernel errno from RTNetlink or IpReachabilityMonitor
    // byte 3: when byte 2 == PROBE, errno code from RTNetlink or IpReachabilityMonitor.
    public final int eventType;

    /** {@hide} */
@@ -52,11 +62,13 @@ public final class IpReachabilityEvent implements Parcelable {
        this.eventType = in.readInt();
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeString(ifName);
        out.writeInt(eventType);
    }

    @Override
    public int describeContents() {
        return 0;
    }
@@ -81,10 +93,24 @@ public final class IpReachabilityEvent implements Parcelable {
    public static void logProvisioningLost(String ifName) {
    }

    /**
     * Returns the NUD failure event type code corresponding to the given conditions.
     * {@hide}
     */
    public static int nudFailureEventType(boolean isFromProbe, boolean isProvisioningLost) {
        if (isFromProbe) {
            return isProvisioningLost ? PROVISIONING_LOST : NUD_FAILED;
        } else {
            return isProvisioningLost ? PROVISIONING_LOST_ORGANIC : NUD_FAILED_ORGANIC;
        }
    }

    @Override
    public String toString() {
        return String.format("IpReachabilityEvent(%s, %s)", ifName,
                Decoder.constants.get(eventType));
        int hi = eventType & 0xff00;
        int lo = eventType & 0x00ff;
        String eventName = Decoder.constants.get(hi);
        return String.format("IpReachabilityEvent(%s, %s:%02x)", ifName, eventName, lo);
    }

    final static class Decoder {
+15 −7
Original line number Diff line number Diff line
@@ -129,7 +129,6 @@ import java.util.Set;
 *          state it may be best for the link to disconnect completely and
 *          reconnect afresh.
 *
 *
 * @hide
 */
public class IpReachabilityMonitor {
@@ -163,6 +162,8 @@ public class IpReachabilityMonitor {
    private int mIpWatchListVersion;
    @GuardedBy("mLock")
    private boolean mRunning;
    // Time in milliseconds of the last forced probe request.
    private volatile long mLastProbeTimeMs;

    /**
     * Make the kernel perform neighbor reachability detection (IPv4 ARP or IPv6 ND)
@@ -339,7 +340,7 @@ public class IpReachabilityMonitor {

    private void handleNeighborLost(String msg) {
        InetAddress ip = null;
        ProvisioningChange delta;
        final ProvisioningChange delta;
        synchronized (mLock) {
            LinkProperties whatIfLp = new LinkProperties(mLinkProperties);

@@ -368,10 +369,8 @@ public class IpReachabilityMonitor {
                // an InetAddress argument.
                mCallback.notifyLost(ip, logMsg);
            }
            logEvent(IpReachabilityEvent.PROVISIONING_LOST, 0);
        } else {
            logEvent(IpReachabilityEvent.NUD_FAILED, 0);
        }
        logNudFailed(delta);
    }

    public void probeAll() {
@@ -397,9 +396,10 @@ public class IpReachabilityMonitor {
            final int returnValue = probeNeighbor(mInterfaceIndex, target);
            logEvent(IpReachabilityEvent.PROBE, returnValue);
        }
        mLastProbeTimeMs = SystemClock.elapsedRealtime();
    }

    private long getProbeWakeLockDuration() {
    private static long getProbeWakeLockDuration() {
        // Ideally, this would be computed by examining the values of:
        //
        //     /proc/sys/net/ipv[46]/neigh/<ifname>/ucast_solicit
@@ -420,6 +420,14 @@ public class IpReachabilityMonitor {
        mMetricsLog.log(new IpReachabilityEvent(mInterfaceName, eventType));
    }

    private void logNudFailed(ProvisioningChange delta) {
        long duration = SystemClock.elapsedRealtime() - mLastProbeTimeMs;
        boolean isFromProbe = (duration < getProbeWakeLockDuration());
        boolean isProvisioningLost = (delta == ProvisioningChange.LOST_PROVISIONING);
        int eventType = IpReachabilityEvent.nudFailureEventType(isFromProbe, isProvisioningLost);
        mMetricsLog.log(new IpReachabilityEvent(mInterfaceName, eventType));
    }

    // TODO: simplify the number of objects by making this extend Thread.
    private final class NetlinkSocketObserver implements Runnable {
        private NetlinkSocket mSocket;