ApfStats.java revision 95cb226c1a4ff47531da65ef2617ade0dea5c9b8
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
17package android.net.metrics;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22/**
23 * An event logged for an interface with APF capabilities when its IpManager state machine exits.
24 * {@hide}
25 */
26public final class ApfStats implements Parcelable {
27
28    public final long durationMs;     // time interval in milliseconds these stastistics covers
29    public final int receivedRas;     // number of received RAs
30    public final int matchingRas;     // number of received RAs matching a known RA
31    public final int droppedRas;      // number of received RAs ignored due to the MAX_RAS limit
32    public final int zeroLifetimeRas; // number of received RAs with a minimum lifetime of 0
33    public final int parseErrors;     // number of received RAs that could not be parsed
34    public final int programUpdates;  // number of APF program updates
35    public final int maxProgramSize;  // maximum APF program size advertised by hardware
36
37    public ApfStats(long durationMs, int receivedRas, int matchingRas, int droppedRas,
38            int zeroLifetimeRas, int parseErrors, int programUpdates, int maxProgramSize) {
39        this.durationMs = durationMs;
40        this.receivedRas = receivedRas;
41        this.matchingRas = matchingRas;
42        this.droppedRas = droppedRas;
43        this.zeroLifetimeRas = zeroLifetimeRas;
44        this.parseErrors = parseErrors;
45        this.programUpdates = programUpdates;
46        this.maxProgramSize = maxProgramSize;
47    }
48
49    private ApfStats(Parcel in) {
50        this.durationMs = in.readLong();
51        this.receivedRas = in.readInt();
52        this.matchingRas = in.readInt();
53        this.droppedRas = in.readInt();
54        this.zeroLifetimeRas = in.readInt();
55        this.parseErrors = in.readInt();
56        this.programUpdates = in.readInt();
57        this.maxProgramSize = in.readInt();
58    }
59
60    @Override
61    public void writeToParcel(Parcel out, int flags) {
62        out.writeLong(durationMs);
63        out.writeInt(receivedRas);
64        out.writeInt(matchingRas);
65        out.writeInt(droppedRas);
66        out.writeInt(zeroLifetimeRas);
67        out.writeInt(parseErrors);
68        out.writeInt(programUpdates);
69        out.writeInt(maxProgramSize);
70    }
71
72    @Override
73    public int describeContents() {
74        return 0;
75    }
76
77    @Override
78    public String toString() {
79        return new StringBuilder("ApfStats(")
80                .append(String.format("%dms ", durationMs))
81                .append(String.format("%dB RA: {", maxProgramSize))
82                .append(String.format("%d received, ", receivedRas))
83                .append(String.format("%d matching, ", matchingRas))
84                .append(String.format("%d dropped, ", droppedRas))
85                .append(String.format("%d zero lifetime, ", zeroLifetimeRas))
86                .append(String.format("%d parse errors, ", parseErrors))
87                .append(String.format("%d program updates})", programUpdates))
88                .toString();
89    }
90
91    public static final Parcelable.Creator<ApfStats> CREATOR = new Parcelable.Creator<ApfStats>() {
92        public ApfStats createFromParcel(Parcel in) {
93            return new ApfStats(in);
94        }
95
96        public ApfStats[] newArray(int size) {
97            return new ApfStats[size];
98        }
99    };
100}
101