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