Hugo Benichi | cfbf741 | 2016-06-23 10:41:30 +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 | |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Hugo Benichi | cfbf741 | 2016-06-23 10:41:30 +0900 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | /** |
| 24 | * An event logged when the APF packet socket receives an RA packet. |
| 25 | * {@hide} |
| 26 | */ |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 27 | public final class RaEvent implements IpConnectivityLog.Event { |
Hugo Benichi | cfbf741 | 2016-06-23 10:41:30 +0900 | [diff] [blame] | 28 | |
Hugo Benichi | 6ccd51a | 2016-07-04 09:22:30 +0900 | [diff] [blame] | 29 | public static final long NO_LIFETIME = -1L; |
| 30 | |
Hugo Benichi | cfbf741 | 2016-06-23 10:41:30 +0900 | [diff] [blame] | 31 | // Lifetime in seconds of options found in a single RA packet. |
| 32 | // When an option is not set, the value of the associated field is -1; |
| 33 | public final long routerLifetime; |
| 34 | public final long prefixValidLifetime; |
| 35 | public final long prefixPreferredLifetime; |
| 36 | public final long routeInfoLifetime; |
| 37 | public final long rdnssLifetime; |
| 38 | public final long dnsslLifetime; |
| 39 | |
Hugo Benichi | cfbf741 | 2016-06-23 10:41:30 +0900 | [diff] [blame] | 40 | public RaEvent(long routerLifetime, long prefixValidLifetime, long prefixPreferredLifetime, |
| 41 | long routeInfoLifetime, long rdnssLifetime, long dnsslLifetime) { |
| 42 | this.routerLifetime = routerLifetime; |
| 43 | this.prefixValidLifetime = prefixValidLifetime; |
| 44 | this.prefixPreferredLifetime = prefixPreferredLifetime; |
| 45 | this.routeInfoLifetime = routeInfoLifetime; |
| 46 | this.rdnssLifetime = rdnssLifetime; |
| 47 | this.dnsslLifetime = dnsslLifetime; |
| 48 | } |
| 49 | |
| 50 | private RaEvent(Parcel in) { |
| 51 | routerLifetime = in.readLong(); |
| 52 | prefixValidLifetime = in.readLong(); |
| 53 | prefixPreferredLifetime = in.readLong(); |
| 54 | routeInfoLifetime = in.readLong(); |
| 55 | rdnssLifetime = in.readLong(); |
| 56 | dnsslLifetime = in.readLong(); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public void writeToParcel(Parcel out, int flags) { |
| 61 | out.writeLong(routerLifetime); |
| 62 | out.writeLong(prefixValidLifetime); |
| 63 | out.writeLong(prefixPreferredLifetime); |
| 64 | out.writeLong(routeInfoLifetime); |
| 65 | out.writeLong(rdnssLifetime); |
| 66 | out.writeLong(dnsslLifetime); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public int describeContents() { |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public String toString() { |
| 76 | return new StringBuilder("RaEvent(lifetimes: ") |
| 77 | .append(String.format("router=%ds, ", routerLifetime)) |
| 78 | .append(String.format("prefix_valid=%ds, ", prefixValidLifetime)) |
| 79 | .append(String.format("prefix_preferred=%ds, ", prefixPreferredLifetime)) |
| 80 | .append(String.format("route_info=%ds, ", routeInfoLifetime)) |
| 81 | .append(String.format("rdnss=%ds, ", rdnssLifetime)) |
| 82 | .append(String.format("dnssl=%ds)", dnsslLifetime)) |
| 83 | .toString(); |
| 84 | } |
| 85 | |
| 86 | public static final Parcelable.Creator<RaEvent> CREATOR = new Parcelable.Creator<RaEvent>() { |
| 87 | public RaEvent createFromParcel(Parcel in) { |
| 88 | return new RaEvent(in); |
| 89 | } |
| 90 | |
| 91 | public RaEvent[] newArray(int size) { |
| 92 | return new RaEvent[size]; |
| 93 | } |
| 94 | }; |
Hugo Benichi | 6ccd51a | 2016-07-04 09:22:30 +0900 | [diff] [blame] | 95 | |
Hugo Benichi | 6ccd51a | 2016-07-04 09:22:30 +0900 | [diff] [blame] | 96 | public static class Builder { |
| 97 | |
| 98 | long routerLifetime = NO_LIFETIME; |
| 99 | long prefixValidLifetime = NO_LIFETIME; |
| 100 | long prefixPreferredLifetime = NO_LIFETIME; |
| 101 | long routeInfoLifetime = NO_LIFETIME; |
| 102 | long rdnssLifetime = NO_LIFETIME; |
| 103 | long dnsslLifetime = NO_LIFETIME; |
| 104 | |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 105 | @UnsupportedAppUsage |
Hugo Benichi | 6ccd51a | 2016-07-04 09:22:30 +0900 | [diff] [blame] | 106 | public Builder() { |
| 107 | } |
| 108 | |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 109 | @UnsupportedAppUsage |
Hugo Benichi | 6ccd51a | 2016-07-04 09:22:30 +0900 | [diff] [blame] | 110 | public RaEvent build() { |
| 111 | return new RaEvent(routerLifetime, prefixValidLifetime, prefixPreferredLifetime, |
| 112 | routeInfoLifetime, rdnssLifetime, dnsslLifetime); |
| 113 | } |
| 114 | |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 115 | @UnsupportedAppUsage |
Hugo Benichi | 6ccd51a | 2016-07-04 09:22:30 +0900 | [diff] [blame] | 116 | public Builder updateRouterLifetime(long lifetime) { |
| 117 | routerLifetime = updateLifetime(routerLifetime, lifetime); |
| 118 | return this; |
| 119 | } |
| 120 | |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 121 | @UnsupportedAppUsage |
Hugo Benichi | 6ccd51a | 2016-07-04 09:22:30 +0900 | [diff] [blame] | 122 | public Builder updatePrefixValidLifetime(long lifetime) { |
| 123 | prefixValidLifetime = updateLifetime(prefixValidLifetime, lifetime); |
| 124 | return this; |
| 125 | } |
| 126 | |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 127 | @UnsupportedAppUsage |
Hugo Benichi | 6ccd51a | 2016-07-04 09:22:30 +0900 | [diff] [blame] | 128 | public Builder updatePrefixPreferredLifetime(long lifetime) { |
| 129 | prefixPreferredLifetime = updateLifetime(prefixPreferredLifetime, lifetime); |
| 130 | return this; |
| 131 | } |
| 132 | |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 133 | @UnsupportedAppUsage |
Hugo Benichi | 6ccd51a | 2016-07-04 09:22:30 +0900 | [diff] [blame] | 134 | public Builder updateRouteInfoLifetime(long lifetime) { |
| 135 | routeInfoLifetime = updateLifetime(routeInfoLifetime, lifetime); |
| 136 | return this; |
| 137 | } |
| 138 | |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 139 | @UnsupportedAppUsage |
Hugo Benichi | 6ccd51a | 2016-07-04 09:22:30 +0900 | [diff] [blame] | 140 | public Builder updateRdnssLifetime(long lifetime) { |
| 141 | rdnssLifetime = updateLifetime(rdnssLifetime, lifetime); |
| 142 | return this; |
| 143 | } |
| 144 | |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 145 | @UnsupportedAppUsage |
Hugo Benichi | 6ccd51a | 2016-07-04 09:22:30 +0900 | [diff] [blame] | 146 | public Builder updateDnsslLifetime(long lifetime) { |
| 147 | dnsslLifetime = updateLifetime(dnsslLifetime, lifetime); |
| 148 | return this; |
| 149 | } |
| 150 | |
| 151 | private long updateLifetime(long currentLifetime, long newLifetime) { |
| 152 | if (currentLifetime == RaEvent.NO_LIFETIME) { |
| 153 | return newLifetime; |
| 154 | } |
| 155 | return Math.min(currentLifetime, newLifetime); |
| 156 | } |
| 157 | } |
Hugo Benichi | cfbf741 | 2016-06-23 10:41:30 +0900 | [diff] [blame] | 158 | } |