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

am: 42e608527a

Change-Id: I4303badea7760c6cd9a1b63db1df8a3766a638f2
This commit is contained in:
Hugo Benichi
2016-07-07 13:11:01 +00:00
committed by android-build-merger
3 changed files with 48 additions and 14 deletions

View File

@@ -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 {

View File

@@ -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 {
public static final int PROBE = 1 << 8;
public static final int NUD_FAILED = 2 << 8;
public static final int PROVISIONING_LOST = 3 << 8;
// 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 {

View File

@@ -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
@@ -416,7 +416,15 @@ public class IpReachabilityMonitor {
}
private void logEvent(int probeType, int errorCode) {
int eventType = probeType | (errorCode & 0xff );
int eventType = probeType | (errorCode & 0xff);
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));
}