diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2016-06-30 14:03:20 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-06-30 14:03:22 +0000 |
| commit | f5e3481951dcea77f857b75f505d6ceeb823f84e (patch) | |
| tree | fb0c91ad0e1ae8ef0de5744735f988a6bf08378a /core/java/android | |
| parent | 089e99ee4d8d01f95c86cbc859cc2c4a9dccbfc8 (diff) | |
| parent | cfbf7414a14cf91d1b5c83154aab54c32d6be76a (diff) | |
Merge changes Ia28652e0,Id2eaafdc,I9c4c8286 into nyc-mr1-dev
* changes:
Record events for RA option lifetimes
Log RA listening statistics
Log events at APF program generation
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/net/metrics/ApfProgramEvent.java | 137 | ||||
| -rw-r--r-- | core/java/android/net/metrics/ApfStats.java | 103 | ||||
| -rw-r--r-- | core/java/android/net/metrics/IpManagerEvent.java | 1 | ||||
| -rw-r--r-- | core/java/android/net/metrics/RaEvent.java | 95 | ||||
| -rw-r--r-- | core/java/android/net/metrics/ValidationProbeEvent.java | 1 |
5 files changed, 337 insertions, 0 deletions
diff --git a/core/java/android/net/metrics/ApfProgramEvent.java b/core/java/android/net/metrics/ApfProgramEvent.java new file mode 100644 index 000000000000..3cd058cb6dc5 --- /dev/null +++ b/core/java/android/net/metrics/ApfProgramEvent.java @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.metrics; + +import android.annotation.SystemApi; +import android.os.Parcel; +import android.os.Parcelable; +import android.util.SparseArray; + +import java.util.Arrays; +import java.util.stream.Collectors; + +import com.android.internal.util.MessageUtils; + +/** + * An event logged when there is a change or event that requires updating the + * the APF program in place with a new APF program. + * {@hide} + */ +@SystemApi +public final class ApfProgramEvent implements Parcelable { + + // Bitflag constants describing what an Apf program filters. + // Bits are indexeds from LSB to MSB, starting at index 0. + // TODO: use @IntDef + public static final int FLAG_MULTICAST_FILTER_ON = 0; + public static final int FLAG_HAS_IPV4_ADDRESS = 1; + + public final long lifetime; // Lifetime of the program in seconds + public final int filteredRas; // Number of RAs filtered by the APF program + public final int currentRas; // Total number of current RAs at generation time + public final int programLength; // Length of the APF program in bytes + public final int flags; // Bitfield compound of FLAG_* constants + + /** {@hide} */ + public ApfProgramEvent( + long lifetime, int filteredRas, int currentRas, int programLength, int flags) { + this.lifetime = lifetime; + this.filteredRas = filteredRas; + this.currentRas = currentRas; + this.programLength = programLength; + this.flags = flags; + } + + private ApfProgramEvent(Parcel in) { + this.lifetime = in.readLong(); + this.filteredRas = in.readInt(); + this.currentRas = in.readInt(); + this.programLength = in.readInt(); + this.flags = in.readInt(); + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeLong(lifetime); + out.writeInt(filteredRas); + out.writeInt(currentRas); + out.writeInt(programLength); + out.writeInt(flags); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public String toString() { + String lifetimeString = (lifetime < Long.MAX_VALUE) ? lifetime + "s" : "forever"; + return String.format("ApfProgramEvent(%d/%d RAs %dB %s %s)", + filteredRas, currentRas, programLength, lifetimeString, namesOf(flags)); + } + + public static final Parcelable.Creator<ApfProgramEvent> CREATOR + = new Parcelable.Creator<ApfProgramEvent>() { + public ApfProgramEvent createFromParcel(Parcel in) { + return new ApfProgramEvent(in); + } + + public ApfProgramEvent[] newArray(int size) { + return new ApfProgramEvent[size]; + } + }; + + /** {@hide} */ + public static int flagsFor(boolean hasIPv4, boolean multicastFilterOn) { + int bitfield = 0; + if (hasIPv4) { + bitfield |= (1 << FLAG_HAS_IPV4_ADDRESS); + } + if (multicastFilterOn) { + bitfield |= (1 << FLAG_MULTICAST_FILTER_ON); + } + return bitfield; + } + + // TODO: consider using java.util.BitSet + private static int[] bitflagsOf(int bitfield) { + int[] flags = new int[Integer.bitCount(bitfield)]; + int i = 0; + int bitflag = 0; + while (bitfield != 0) { + if ((bitfield & 1) != 0) { + flags[i++] = bitflag; + } + bitflag++; + bitfield = bitfield >>> 1; + } + return flags; + } + + private static String namesOf(int bitfields) { + return Arrays.stream(bitflagsOf(bitfields)) + .mapToObj(i -> Decoder.constants.get(i)) + .collect(Collectors.joining(", ")); + } + + final static class Decoder { + static final SparseArray<String> constants = + MessageUtils.findMessageNames( + new Class[]{ApfProgramEvent.class}, new String[]{"FLAG_"}); + } +} diff --git a/core/java/android/net/metrics/ApfStats.java b/core/java/android/net/metrics/ApfStats.java new file mode 100644 index 000000000000..8451e539a7f6 --- /dev/null +++ b/core/java/android/net/metrics/ApfStats.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.metrics; + +import android.annotation.SystemApi; +import android.os.Parcel; +import android.os.Parcelable; + +/** + * An event logged for an interface with APF capabilities when its IpManager state machine exits. + * {@hide} + */ +@SystemApi +public final class ApfStats implements Parcelable { + + public final long durationMs; // time interval in milliseconds these stastistics covers + public final int receivedRas; // number of received RAs + public final int matchingRas; // number of received RAs matching a known RA + public final int droppedRas; // number of received RAs ignored due to the MAX_RAS limit + public final int zeroLifetimeRas; // number of received RAs with a minimum lifetime of 0 + public final int parseErrors; // number of received RAs that could not be parsed + public final int programUpdates; // number of APF program updates + public final int maxProgramSize; // maximum APF program size advertised by hardware + + /** {@hide} */ + public ApfStats(long durationMs, int receivedRas, int matchingRas, int droppedRas, + int zeroLifetimeRas, int parseErrors, int programUpdates, int maxProgramSize) { + this.durationMs = durationMs; + this.receivedRas = receivedRas; + this.matchingRas = matchingRas; + this.droppedRas = droppedRas; + this.zeroLifetimeRas = zeroLifetimeRas; + this.parseErrors = parseErrors; + this.programUpdates = programUpdates; + this.maxProgramSize = maxProgramSize; + } + + private ApfStats(Parcel in) { + this.durationMs = in.readLong(); + this.receivedRas = in.readInt(); + this.matchingRas = in.readInt(); + this.droppedRas = in.readInt(); + this.zeroLifetimeRas = in.readInt(); + this.parseErrors = in.readInt(); + this.programUpdates = in.readInt(); + this.maxProgramSize = in.readInt(); + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeLong(durationMs); + out.writeInt(receivedRas); + out.writeInt(matchingRas); + out.writeInt(droppedRas); + out.writeInt(zeroLifetimeRas); + out.writeInt(parseErrors); + out.writeInt(programUpdates); + out.writeInt(maxProgramSize); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public String toString() { + return new StringBuilder("ApfStats(") + .append(String.format("%dms ", durationMs)) + .append(String.format("%dB RA: {", maxProgramSize)) + .append(String.format("%d received, ", receivedRas)) + .append(String.format("%d matching, ", matchingRas)) + .append(String.format("%d dropped, ", droppedRas)) + .append(String.format("%d zero lifetime, ", zeroLifetimeRas)) + .append(String.format("%d parse errors, ", parseErrors)) + .append(String.format("%d program updates})", programUpdates)) + .toString(); + } + + public static final Parcelable.Creator<ApfStats> CREATOR = new Parcelable.Creator<ApfStats>() { + public ApfStats createFromParcel(Parcel in) { + return new ApfStats(in); + } + + public ApfStats[] newArray(int size) { + return new ApfStats[size]; + } + }; +} diff --git a/core/java/android/net/metrics/IpManagerEvent.java b/core/java/android/net/metrics/IpManagerEvent.java index a39061748ac3..8949fae2545f 100644 --- a/core/java/android/net/metrics/IpManagerEvent.java +++ b/core/java/android/net/metrics/IpManagerEvent.java @@ -29,6 +29,7 @@ import com.android.internal.util.MessageUtils; @SystemApi public final class IpManagerEvent implements Parcelable { + // TODO: use @IntDef public static final int PROVISIONING_OK = 1; public static final int PROVISIONING_FAIL = 2; public static final int COMPLETE_LIFECYCLE = 3; diff --git a/core/java/android/net/metrics/RaEvent.java b/core/java/android/net/metrics/RaEvent.java new file mode 100644 index 000000000000..69013c0de637 --- /dev/null +++ b/core/java/android/net/metrics/RaEvent.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.metrics; + +import android.annotation.SystemApi; +import android.os.Parcel; +import android.os.Parcelable; + +/** + * An event logged when the APF packet socket receives an RA packet. + * {@hide} + */ +@SystemApi +public final class RaEvent implements Parcelable { + + // Lifetime in seconds of options found in a single RA packet. + // When an option is not set, the value of the associated field is -1; + public final long routerLifetime; + public final long prefixValidLifetime; + public final long prefixPreferredLifetime; + public final long routeInfoLifetime; + public final long rdnssLifetime; + public final long dnsslLifetime; + + /** {@hide} */ + public RaEvent(long routerLifetime, long prefixValidLifetime, long prefixPreferredLifetime, + long routeInfoLifetime, long rdnssLifetime, long dnsslLifetime) { + this.routerLifetime = routerLifetime; + this.prefixValidLifetime = prefixValidLifetime; + this.prefixPreferredLifetime = prefixPreferredLifetime; + this.routeInfoLifetime = routeInfoLifetime; + this.rdnssLifetime = rdnssLifetime; + this.dnsslLifetime = dnsslLifetime; + } + + private RaEvent(Parcel in) { + routerLifetime = in.readLong(); + prefixValidLifetime = in.readLong(); + prefixPreferredLifetime = in.readLong(); + routeInfoLifetime = in.readLong(); + rdnssLifetime = in.readLong(); + dnsslLifetime = in.readLong(); + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeLong(routerLifetime); + out.writeLong(prefixValidLifetime); + out.writeLong(prefixPreferredLifetime); + out.writeLong(routeInfoLifetime); + out.writeLong(rdnssLifetime); + out.writeLong(dnsslLifetime); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public String toString() { + return new StringBuilder("RaEvent(lifetimes: ") + .append(String.format("router=%ds, ", routerLifetime)) + .append(String.format("prefix_valid=%ds, ", prefixValidLifetime)) + .append(String.format("prefix_preferred=%ds, ", prefixPreferredLifetime)) + .append(String.format("route_info=%ds, ", routeInfoLifetime)) + .append(String.format("rdnss=%ds, ", rdnssLifetime)) + .append(String.format("dnssl=%ds)", dnsslLifetime)) + .toString(); + } + + public static final Parcelable.Creator<RaEvent> CREATOR = new Parcelable.Creator<RaEvent>() { + public RaEvent createFromParcel(Parcel in) { + return new RaEvent(in); + } + + public RaEvent[] newArray(int size) { + return new RaEvent[size]; + } + }; +} diff --git a/core/java/android/net/metrics/ValidationProbeEvent.java b/core/java/android/net/metrics/ValidationProbeEvent.java index d5ad0f6c25a9..c2d259fd216b 100644 --- a/core/java/android/net/metrics/ValidationProbeEvent.java +++ b/core/java/android/net/metrics/ValidationProbeEvent.java @@ -29,6 +29,7 @@ import com.android.internal.util.MessageUtils; @SystemApi public final class ValidationProbeEvent implements Parcelable { + // TODO: use @IntDef public static final int PROBE_DNS = 0; public static final int PROBE_HTTP = 1; public static final int PROBE_HTTPS = 2; |
