Hugo Benichi | 647c86d | 2016-06-07 15:35:16 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.net.metrics; |
| 18 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
| 20 | import android.annotation.TestApi; |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 21 | import android.annotation.UnsupportedAppUsage; |
Hugo Benichi | 647c86d | 2016-06-07 15:35:16 +0900 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
| 24 | |
| 25 | /** |
Erik Kline | 8d1fe54 | 2018-03-12 23:18:58 +0900 | [diff] [blame] | 26 | * An event logged for an interface with APF capabilities when its IpClient state machine exits. |
Hugo Benichi | 647c86d | 2016-06-07 15:35:16 +0900 | [diff] [blame] | 27 | * {@hide} |
| 28 | */ |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 29 | @SystemApi |
| 30 | @TestApi |
| 31 | public final class ApfStats implements IpConnectivityLog.Event { |
Hugo Benichi | 647c86d | 2016-06-07 15:35:16 +0900 | [diff] [blame] | 32 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 33 | /** |
| 34 | * time interval in milliseconds these stastistics covers. |
| 35 | * @hide |
| 36 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 37 | @UnsupportedAppUsage |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 38 | public final long durationMs; |
| 39 | /** |
| 40 | * number of received RAs. |
| 41 | * @hide |
| 42 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 43 | @UnsupportedAppUsage |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 44 | public final int receivedRas; |
| 45 | /** |
| 46 | * number of received RAs matching a known RA. |
| 47 | * @hide |
| 48 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 49 | @UnsupportedAppUsage |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 50 | public final int matchingRas; |
| 51 | /** |
| 52 | * number of received RAs ignored due to the MAX_RAS limit. |
| 53 | * @hide |
| 54 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 55 | @UnsupportedAppUsage |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 56 | public final int droppedRas; |
| 57 | /** |
| 58 | * number of received RAs with a minimum lifetime of 0. |
| 59 | * @hide |
| 60 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 61 | @UnsupportedAppUsage |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 62 | public final int zeroLifetimeRas; |
| 63 | /** |
| 64 | * number of received RAs that could not be parsed. |
| 65 | * @hide |
| 66 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 67 | @UnsupportedAppUsage |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 68 | public final int parseErrors; |
| 69 | /** |
| 70 | * number of APF program updates from receiving RAs. |
| 71 | * @hide |
| 72 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 73 | @UnsupportedAppUsage |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 74 | public final int programUpdates; |
| 75 | /** |
| 76 | * total number of APF program updates. |
| 77 | * @hide |
| 78 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 79 | @UnsupportedAppUsage |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 80 | public final int programUpdatesAll; |
| 81 | /** |
| 82 | * number of APF program updates from allowing multicast traffic. |
| 83 | * @hide |
| 84 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 85 | @UnsupportedAppUsage |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 86 | public final int programUpdatesAllowingMulticast; |
| 87 | /** |
| 88 | * maximum APF program size advertised by hardware. |
| 89 | * @hide |
| 90 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 91 | @UnsupportedAppUsage |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 92 | public final int maxProgramSize; |
Hugo Benichi | 647c86d | 2016-06-07 15:35:16 +0900 | [diff] [blame] | 93 | |
| 94 | private ApfStats(Parcel in) { |
| 95 | this.durationMs = in.readLong(); |
| 96 | this.receivedRas = in.readInt(); |
| 97 | this.matchingRas = in.readInt(); |
| 98 | this.droppedRas = in.readInt(); |
| 99 | this.zeroLifetimeRas = in.readInt(); |
| 100 | this.parseErrors = in.readInt(); |
| 101 | this.programUpdates = in.readInt(); |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 102 | this.programUpdatesAll = in.readInt(); |
| 103 | this.programUpdatesAllowingMulticast = in.readInt(); |
Hugo Benichi | 647c86d | 2016-06-07 15:35:16 +0900 | [diff] [blame] | 104 | this.maxProgramSize = in.readInt(); |
| 105 | } |
| 106 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 107 | private ApfStats(long durationMs, int receivedRas, int matchingRas, int droppedRas, |
| 108 | int zeroLifetimeRas, int parseErrors, int programUpdates, int programUpdatesAll, |
| 109 | int programUpdatesAllowingMulticast, int maxProgramSize) { |
| 110 | this.durationMs = durationMs; |
| 111 | this.receivedRas = receivedRas; |
| 112 | this.matchingRas = matchingRas; |
| 113 | this.droppedRas = droppedRas; |
| 114 | this.zeroLifetimeRas = zeroLifetimeRas; |
| 115 | this.parseErrors = parseErrors; |
| 116 | this.programUpdates = programUpdates; |
| 117 | this.programUpdatesAll = programUpdatesAll; |
| 118 | this.programUpdatesAllowingMulticast = programUpdatesAllowingMulticast; |
| 119 | this.maxProgramSize = maxProgramSize; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Utility to create an instance of {@link ApfStats}. |
| 124 | * @hide |
| 125 | */ |
| 126 | @SystemApi |
| 127 | @TestApi |
| 128 | public static class Builder { |
| 129 | private long mDurationMs; |
| 130 | private int mReceivedRas; |
| 131 | private int mMatchingRas; |
| 132 | private int mDroppedRas; |
| 133 | private int mZeroLifetimeRas; |
| 134 | private int mParseErrors; |
| 135 | private int mProgramUpdates; |
| 136 | private int mProgramUpdatesAll; |
| 137 | private int mProgramUpdatesAllowingMulticast; |
| 138 | private int mMaxProgramSize; |
| 139 | |
| 140 | /** |
| 141 | * Set the time interval in milliseconds these statistics covers. |
| 142 | */ |
| 143 | public Builder setDurationMs(long durationMs) { |
| 144 | mDurationMs = durationMs; |
| 145 | return this; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Set the number of received RAs. |
| 150 | */ |
| 151 | public Builder setReceivedRas(int receivedRas) { |
| 152 | mReceivedRas = receivedRas; |
| 153 | return this; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Set the number of received RAs matching a known RA. |
| 158 | */ |
| 159 | public Builder setMatchingRas(int matchingRas) { |
| 160 | mMatchingRas = matchingRas; |
| 161 | return this; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Set the number of received RAs ignored due to the MAX_RAS limit. |
| 166 | */ |
| 167 | public Builder setDroppedRas(int droppedRas) { |
| 168 | mDroppedRas = droppedRas; |
| 169 | return this; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Set the number of received RAs with a minimum lifetime of 0. |
| 174 | */ |
| 175 | public Builder setZeroLifetimeRas(int zeroLifetimeRas) { |
| 176 | mZeroLifetimeRas = zeroLifetimeRas; |
| 177 | return this; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Set the number of received RAs that could not be parsed. |
| 182 | */ |
| 183 | public Builder setParseErrors(int parseErrors) { |
| 184 | mParseErrors = parseErrors; |
| 185 | return this; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Set the number of APF program updates from receiving RAs. |
| 190 | */ |
| 191 | public Builder setProgramUpdates(int programUpdates) { |
| 192 | mProgramUpdates = programUpdates; |
| 193 | return this; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Set the total number of APF program updates. |
| 198 | */ |
| 199 | public Builder setProgramUpdatesAll(int programUpdatesAll) { |
| 200 | mProgramUpdatesAll = programUpdatesAll; |
| 201 | return this; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Set the number of APF program updates from allowing multicast traffic. |
| 206 | */ |
| 207 | public Builder setProgramUpdatesAllowingMulticast(int programUpdatesAllowingMulticast) { |
| 208 | mProgramUpdatesAllowingMulticast = programUpdatesAllowingMulticast; |
| 209 | return this; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Set the maximum APF program size advertised by hardware. |
| 214 | */ |
| 215 | public Builder setMaxProgramSize(int maxProgramSize) { |
| 216 | mMaxProgramSize = maxProgramSize; |
| 217 | return this; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Create a new {@link ApfStats}. |
| 222 | */ |
| 223 | public ApfStats build() { |
| 224 | return new ApfStats(mDurationMs, mReceivedRas, mMatchingRas, mDroppedRas, |
| 225 | mZeroLifetimeRas, mParseErrors, mProgramUpdates, mProgramUpdatesAll, |
| 226 | mProgramUpdatesAllowingMulticast, mMaxProgramSize); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /** @hide */ |
Hugo Benichi | 647c86d | 2016-06-07 15:35:16 +0900 | [diff] [blame] | 231 | @Override |
| 232 | public void writeToParcel(Parcel out, int flags) { |
| 233 | out.writeLong(durationMs); |
| 234 | out.writeInt(receivedRas); |
| 235 | out.writeInt(matchingRas); |
| 236 | out.writeInt(droppedRas); |
| 237 | out.writeInt(zeroLifetimeRas); |
| 238 | out.writeInt(parseErrors); |
| 239 | out.writeInt(programUpdates); |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 240 | out.writeInt(programUpdatesAll); |
| 241 | out.writeInt(programUpdatesAllowingMulticast); |
Hugo Benichi | 647c86d | 2016-06-07 15:35:16 +0900 | [diff] [blame] | 242 | out.writeInt(maxProgramSize); |
| 243 | } |
| 244 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 245 | /** @hide */ |
Hugo Benichi | 647c86d | 2016-06-07 15:35:16 +0900 | [diff] [blame] | 246 | @Override |
| 247 | public int describeContents() { |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public String toString() { |
| 253 | return new StringBuilder("ApfStats(") |
| 254 | .append(String.format("%dms ", durationMs)) |
| 255 | .append(String.format("%dB RA: {", maxProgramSize)) |
| 256 | .append(String.format("%d received, ", receivedRas)) |
| 257 | .append(String.format("%d matching, ", matchingRas)) |
| 258 | .append(String.format("%d dropped, ", droppedRas)) |
| 259 | .append(String.format("%d zero lifetime, ", zeroLifetimeRas)) |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 260 | .append(String.format("%d parse errors}, ", parseErrors)) |
| 261 | .append(String.format("updates: {all: %d, RAs: %d, allow multicast: %d})", |
| 262 | programUpdatesAll, programUpdates, programUpdatesAllowingMulticast)) |
Hugo Benichi | 647c86d | 2016-06-07 15:35:16 +0900 | [diff] [blame] | 263 | .toString(); |
| 264 | } |
| 265 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 266 | /** @hide */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 267 | public static final @android.annotation.NonNull Parcelable.Creator<ApfStats> CREATOR = new Parcelable.Creator<ApfStats>() { |
Hugo Benichi | 647c86d | 2016-06-07 15:35:16 +0900 | [diff] [blame] | 268 | public ApfStats createFromParcel(Parcel in) { |
| 269 | return new ApfStats(in); |
| 270 | } |
| 271 | |
| 272 | public ApfStats[] newArray(int size) { |
| 273 | return new ApfStats[size]; |
| 274 | } |
| 275 | }; |
| 276 | } |