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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
/*
* 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.NonNull;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.os.Parcel;
import android.os.Parcelable;
/**
* An event logged when the APF packet socket receives an RA packet.
* {@hide}
*/
@SystemApi
@TestApi
public final class RaEvent implements IpConnectivityLog.Event {
private 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;
/** @hide */
public final long routerLifetime;
/** @hide */
public final long prefixValidLifetime;
/** @hide */
public final long prefixPreferredLifetime;
/** @hide */
public final long routeInfoLifetime;
/** @hide */
public final long rdnssLifetime;
/** @hide */
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;
}
/** @hide */
private RaEvent(Parcel in) {
routerLifetime = in.readLong();
prefixValidLifetime = in.readLong();
prefixPreferredLifetime = in.readLong();
routeInfoLifetime = in.readLong();
rdnssLifetime = in.readLong();
dnsslLifetime = in.readLong();
}
/** @hide */
@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);
}
/** @hide */
@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();
}
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj.getClass().equals(RaEvent.class))) return false;
final RaEvent other = (RaEvent) obj;
return routerLifetime == other.routerLifetime
&& prefixValidLifetime == other.prefixValidLifetime
&& prefixPreferredLifetime == other.prefixPreferredLifetime
&& routeInfoLifetime == other.routeInfoLifetime
&& rdnssLifetime == other.rdnssLifetime
&& dnsslLifetime == other.dnsslLifetime;
}
/** @hide */
public static final @android.annotation.NonNull 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 final 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 @NonNull RaEvent build() {
return new RaEvent(routerLifetime, prefixValidLifetime, prefixPreferredLifetime,
routeInfoLifetime, rdnssLifetime, dnsslLifetime);
}
public @NonNull Builder updateRouterLifetime(long lifetime) {
routerLifetime = updateLifetime(routerLifetime, lifetime);
return this;
}
public @NonNull Builder updatePrefixValidLifetime(long lifetime) {
prefixValidLifetime = updateLifetime(prefixValidLifetime, lifetime);
return this;
}
public @NonNull Builder updatePrefixPreferredLifetime(long lifetime) {
prefixPreferredLifetime = updateLifetime(prefixPreferredLifetime, lifetime);
return this;
}
public @NonNull Builder updateRouteInfoLifetime(long lifetime) {
routeInfoLifetime = updateLifetime(routeInfoLifetime, lifetime);
return this;
}
public @NonNull Builder updateRdnssLifetime(long lifetime) {
rdnssLifetime = updateLifetime(rdnssLifetime, lifetime);
return this;
}
public @NonNull 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);
}
}
}
|