blob: e1c8888deff736af416f55dca4f5961d56ef32c9 [file] [log] [blame]
Hugo Benichi647c86d2016-06-07 15:35:16 +09001/*
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
17package android.net.metrics;
18
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090019import android.annotation.SystemApi;
20import android.annotation.TestApi;
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010021import android.annotation.UnsupportedAppUsage;
Hugo Benichi647c86d2016-06-07 15:35:16 +090022import android.os.Parcel;
23import android.os.Parcelable;
24
25/**
Erik Kline8d1fe542018-03-12 23:18:58 +090026 * An event logged for an interface with APF capabilities when its IpClient state machine exits.
Hugo Benichi647c86d2016-06-07 15:35:16 +090027 * {@hide}
28 */
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090029@SystemApi
30@TestApi
31public final class ApfStats implements IpConnectivityLog.Event {
Hugo Benichi647c86d2016-06-07 15:35:16 +090032
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090033 /**
34 * time interval in milliseconds these stastistics covers.
35 * @hide
36 */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010037 @UnsupportedAppUsage
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090038 public final long durationMs;
39 /**
40 * number of received RAs.
41 * @hide
42 */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010043 @UnsupportedAppUsage
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090044 public final int receivedRas;
45 /**
46 * number of received RAs matching a known RA.
47 * @hide
48 */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010049 @UnsupportedAppUsage
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090050 public final int matchingRas;
51 /**
52 * number of received RAs ignored due to the MAX_RAS limit.
53 * @hide
54 */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010055 @UnsupportedAppUsage
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090056 public final int droppedRas;
57 /**
58 * number of received RAs with a minimum lifetime of 0.
59 * @hide
60 */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010061 @UnsupportedAppUsage
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090062 public final int zeroLifetimeRas;
63 /**
64 * number of received RAs that could not be parsed.
65 * @hide
66 */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010067 @UnsupportedAppUsage
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090068 public final int parseErrors;
69 /**
70 * number of APF program updates from receiving RAs.
71 * @hide
72 */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010073 @UnsupportedAppUsage
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090074 public final int programUpdates;
75 /**
76 * total number of APF program updates.
77 * @hide
78 */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010079 @UnsupportedAppUsage
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090080 public final int programUpdatesAll;
81 /**
82 * number of APF program updates from allowing multicast traffic.
83 * @hide
84 */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010085 @UnsupportedAppUsage
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090086 public final int programUpdatesAllowingMulticast;
87 /**
88 * maximum APF program size advertised by hardware.
89 * @hide
90 */
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010091 @UnsupportedAppUsage
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090092 public final int maxProgramSize;
Hugo Benichi647c86d2016-06-07 15:35:16 +090093
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 Benichi22d9b2d2017-02-22 13:02:27 +0900102 this.programUpdatesAll = in.readInt();
103 this.programUpdatesAllowingMulticast = in.readInt();
Hugo Benichi647c86d2016-06-07 15:35:16 +0900104 this.maxProgramSize = in.readInt();
105 }
106
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +0900107 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 Benichi647c86d2016-06-07 15:35:16 +0900231 @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 Benichi22d9b2d2017-02-22 13:02:27 +0900240 out.writeInt(programUpdatesAll);
241 out.writeInt(programUpdatesAllowingMulticast);
Hugo Benichi647c86d2016-06-07 15:35:16 +0900242 out.writeInt(maxProgramSize);
243 }
244
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +0900245 /** @hide */
Hugo Benichi647c86d2016-06-07 15:35:16 +0900246 @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 Benichi22d9b2d2017-02-22 13:02:27 +0900260 .append(String.format("%d parse errors}, ", parseErrors))
261 .append(String.format("updates: {all: %d, RAs: %d, allow multicast: %d})",
262 programUpdatesAll, programUpdates, programUpdatesAllowingMulticast))
Hugo Benichi647c86d2016-06-07 15:35:16 +0900263 .toString();
264 }
265
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +0900266 /** @hide */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700267 public static final @android.annotation.NonNull Parcelable.Creator<ApfStats> CREATOR = new Parcelable.Creator<ApfStats>() {
Hugo Benichi647c86d2016-06-07 15:35:16 +0900268 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}