Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +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 | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
| 20 | import android.annotation.TestApi; |
Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +0900 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 23 | import android.util.SparseArray; |
| 24 | |
| 25 | import com.android.internal.util.MessageUtils; |
Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +0900 | [diff] [blame] | 26 | |
| 27 | /** |
Hugo Benichi | 0d1c65b | 2016-06-22 17:01:43 +0900 | [diff] [blame] | 28 | * An event recorded when IpReachabilityMonitor sends a neighbor probe or receives |
| 29 | * a neighbor probe result. |
Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +0900 | [diff] [blame] | 30 | * {@hide} |
| 31 | */ |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 32 | @SystemApi |
| 33 | @TestApi |
| 34 | public final class IpReachabilityEvent implements IpConnectivityLog.Event { |
Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +0900 | [diff] [blame] | 35 | |
Hugo Benichi | 0d1c65b | 2016-06-22 17:01:43 +0900 | [diff] [blame] | 36 | // Event types. |
| 37 | /** A probe forced by IpReachabilityMonitor. */ |
| 38 | public static final int PROBE = 1 << 8; |
| 39 | /** Neighbor unreachable after a forced probe. */ |
| 40 | public static final int NUD_FAILED = 2 << 8; |
| 41 | /** Neighbor unreachable after a forced probe, IP provisioning is also lost. */ |
| 42 | public static final int PROVISIONING_LOST = 3 << 8; |
Hugo Benichi | 95cb226 | 2017-01-11 10:11:26 +0900 | [diff] [blame] | 43 | /** Neighbor unreachable notification from kernel. */ |
Hugo Benichi | 0d1c65b | 2016-06-22 17:01:43 +0900 | [diff] [blame] | 44 | public static final int NUD_FAILED_ORGANIC = 4 << 8; |
Hugo Benichi | 95cb226 | 2017-01-11 10:11:26 +0900 | [diff] [blame] | 45 | /** Neighbor unreachable notification from kernel, IP provisioning is also lost. */ |
Hugo Benichi | 0d1c65b | 2016-06-22 17:01:43 +0900 | [diff] [blame] | 46 | public static final int PROVISIONING_LOST_ORGANIC = 5 << 8; |
Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +0900 | [diff] [blame] | 47 | |
Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +0900 | [diff] [blame] | 48 | // eventType byte format (MSB to LSB): |
| 49 | // byte 0: unused |
| 50 | // byte 1: unused |
| 51 | // byte 2: type of event: PROBE, NUD_FAILED, PROVISIONING_LOST |
Hugo Benichi | 0d1c65b | 2016-06-22 17:01:43 +0900 | [diff] [blame] | 52 | // byte 3: when byte 2 == PROBE, errno code from RTNetlink or IpReachabilityMonitor. |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 53 | /** @hide */ |
Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +0900 | [diff] [blame] | 54 | public final int eventType; |
| 55 | |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 56 | public IpReachabilityEvent(int eventType) { |
Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +0900 | [diff] [blame] | 57 | this.eventType = eventType; |
| 58 | } |
| 59 | |
| 60 | private IpReachabilityEvent(Parcel in) { |
Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +0900 | [diff] [blame] | 61 | this.eventType = in.readInt(); |
| 62 | } |
| 63 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 64 | /** @hide */ |
Hugo Benichi | 0d1c65b | 2016-06-22 17:01:43 +0900 | [diff] [blame] | 65 | @Override |
Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +0900 | [diff] [blame] | 66 | public void writeToParcel(Parcel out, int flags) { |
Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +0900 | [diff] [blame] | 67 | out.writeInt(eventType); |
| 68 | } |
| 69 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 70 | /** @hide */ |
Hugo Benichi | 0d1c65b | 2016-06-22 17:01:43 +0900 | [diff] [blame] | 71 | @Override |
Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +0900 | [diff] [blame] | 72 | public int describeContents() { |
| 73 | return 0; |
| 74 | } |
| 75 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 76 | /** @hide */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 77 | public static final @android.annotation.NonNull Parcelable.Creator<IpReachabilityEvent> CREATOR |
Hugo Benichi | 25bf8f5 | 2016-04-19 09:52:39 +0900 | [diff] [blame] | 78 | = new Parcelable.Creator<IpReachabilityEvent>() { |
| 79 | public IpReachabilityEvent createFromParcel(Parcel in) { |
| 80 | return new IpReachabilityEvent(in); |
| 81 | } |
| 82 | |
| 83 | public IpReachabilityEvent[] newArray(int size) { |
| 84 | return new IpReachabilityEvent[size]; |
| 85 | } |
| 86 | }; |
| 87 | |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 88 | @Override |
| 89 | public String toString() { |
Hugo Benichi | 0d1c65b | 2016-06-22 17:01:43 +0900 | [diff] [blame] | 90 | int hi = eventType & 0xff00; |
| 91 | int lo = eventType & 0x00ff; |
| 92 | String eventName = Decoder.constants.get(hi); |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 93 | return String.format("IpReachabilityEvent(%s:%02x)", eventName, lo); |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | final static class Decoder { |
| 97 | static final SparseArray<String> constants = |
| 98 | MessageUtils.findMessageNames(new Class[]{IpReachabilityEvent.class}, |
| 99 | new String[]{"PROBE", "PROVISIONING_", "NUD_"}); |
| 100 | } |
Hugo Benichi | cfddd68 | 2016-05-31 16:28:06 +0900 | [diff] [blame] | 101 | } |