1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
/*
* 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.os.Parcel;
import android.os.Parcelable;
/**
* An event logged when the APF packet socket receives an RA packet.
* {@hide}
*/
public final class RaEvent implements Parcelable {
public static final long NO_LIFETIME = -1L;
// 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;
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];
}
};
public static class Builder {
long routerLifetime = NO_LIFETIME;
long prefixValidLifetime = NO_LIFETIME;
long prefixPreferredLifetime = NO_LIFETIME;
long routeInfoLifetime = NO_LIFETIME;
long rdnssLifetime = NO_LIFETIME;
long dnsslLifetime = NO_LIFETIME;
public Builder() {
}
public RaEvent build() {
return new RaEvent(routerLifetime, prefixValidLifetime, prefixPreferredLifetime,
routeInfoLifetime, rdnssLifetime, dnsslLifetime);
}
public Builder updateRouterLifetime(long lifetime) {
routerLifetime = updateLifetime(routerLifetime, lifetime);
return this;
}
public Builder updatePrefixValidLifetime(long lifetime) {
prefixValidLifetime = updateLifetime(prefixValidLifetime, lifetime);
return this;
}
public Builder updatePrefixPreferredLifetime(long lifetime) {
prefixPreferredLifetime = updateLifetime(prefixPreferredLifetime, lifetime);
return this;
}
public Builder updateRouteInfoLifetime(long lifetime) {
routeInfoLifetime = updateLifetime(routeInfoLifetime, lifetime);
return this;
}
public Builder updateRdnssLifetime(long lifetime) {
rdnssLifetime = updateLifetime(rdnssLifetime, lifetime);
return this;
}
public Builder updateDnsslLifetime(long lifetime) {
dnsslLifetime = updateLifetime(dnsslLifetime, lifetime);
return this;
}
private long updateLifetime(long currentLifetime, long newLifetime) {
if (currentLifetime == RaEvent.NO_LIFETIME) {
return newLifetime;
}
return Math.min(currentLifetime, newLifetime);
}
}
}
|